From 4eed40b1608f98ae5f4c965d6106a62a71f194a7 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Mon, 22 Apr 2024 23:00:29 +0300 Subject: [PATCH] feat: remove arithmetization code and add arithmetization dependency (still has compile errors) --- .github/workflows/release.yml | 4 +- CHANGELOG.md | 166 +- acceptance-tests/build.gradle | 4 +- .../linea/blockcapture/BlockCapturer.java | 138 - .../blockcapture/reapers/AddressReaper.java | 53 - .../linea/blockcapture/reapers/Reaper.java | 101 - .../blockcapture/reapers/StorageReaper.java | 63 - .../snapshots/AccessListEntrySnapshot.java | 26 - .../snapshots/AccountSnapshot.java | 34 - .../snapshots/BlockHeaderSnapshot.java | 94 - .../blockcapture/snapshots/BlockSnapshot.java | 30 - .../snapshots/ConflationSnapshot.java | 29 - .../snapshots/StorageSnapshot.java | 35 - .../snapshots/TransactionSnapshot.java | 122 - .../linea/corset/CorsetValidator.java | 162 - .../linea/zktracer/ColumnHeader.java | 41 - .../ConflationAwareOperationTracer.java | 35 - .../net/consensys/linea/zktracer/ZkTrace.java | 46 - .../consensys/linea/zktracer/ZkTracer.java | 244 - .../linea/zktracer/bytestheta/BaseBytes.java | 148 - .../linea/zktracer/bytestheta/BaseTheta.java | 133 - .../linea/zktracer/bytestheta/BytesArray.java | 124 - .../zktracer/bytestheta/HighLowBytes.java | 35 - .../zktracer/container/ModuleOperation.java | 35 - .../zktracer/container/StackedContainer.java | 28 - .../container/stacked/list/CountedList.java | 118 - .../container/stacked/list/StackedList.java | 390 - .../container/stacked/set/StackedSet.java | 170 - .../zktracer/json/BigIntegerSerializer.java | 47 - .../linea/zktracer/json/JsonConverter.java | 119 - .../json/NumericBooleanSerializer.java | 39 - .../linea/zktracer/module/Module.java | 83 - .../linea/zktracer/module/ModuleTrace.java | 20 - .../consensys/linea/zktracer/module/Util.java | 193 - .../linea/zktracer/module/UtilCalculator.java | 67 - .../linea/zktracer/module/add/Add.java | 75 - .../zktracer/module/add/AddOperation.java | 140 - .../linea/zktracer/module/add/Adder.java | 49 - .../linea/zktracer/module/add/Trace.java | 453 -- .../linea/zktracer/module/bin/Bin.java | 87 - .../zktracer/module/bin/BinOperation.java | 228 - .../linea/zktracer/module/bin/Trace.java | 998 --- .../linea/zktracer/module/ec_data/EcData.java | 126 - .../module/ec_data/EcDataOperation.java | 352 - .../linea/zktracer/module/ec_data/Trace.java | 1046 --- .../linea/zktracer/module/euc/Euc.java | 78 - .../zktracer/module/euc/EucOperation.java | 83 - .../linea/zktracer/module/euc/Trace.java | 368 - .../module/ext/BigIntegerConverter.java | 82 - .../linea/zktracer/module/ext/Ext.java | 110 - .../zktracer/module/ext/ExtOperation.java | 287 - .../linea/zktracer/module/ext/Trace.java | 3026 -------- .../ext/calculator/AbstractExtCalculator.java | 167 - .../ext/calculator/BytesHCalculator.java | 106 - .../ext/calculator/BytesICalculator.java | 118 - .../ext/calculator/CmpFlagsCalculator.java | 45 - .../ext/calculator/DeltaCalculator.java | 54 - .../ext/calculator/OverflowJCalculator.java | 93 - .../addmod/AddModBytesJCalculator.java | 52 - .../addmod/AddModBytesQCalculator.java | 83 - .../calculator/addmod/AddModCalculator.java | 69 - .../addmod/AddModOverflowResCalculator.java | 81 - .../mulmod/MulModBytesJCalculator.java | 50 - .../mulmod/MulModBytesQCalculator.java | 63 - .../calculator/mulmod/MulModCalculator.java | 83 - .../mulmod/MulModOverflowResCalculator.java | 109 - .../module/hub/AbortingConditions.java | 100 - .../zktracer/module/hub/AccountSnapshot.java | 46 - .../linea/zktracer/module/hub/BlockInfo.java | 42 - .../linea/zktracer/module/hub/Bytecode.java | 95 - .../module/hub/DeploymentExceptions.java | 63 - .../zktracer/module/hub/DeploymentInfo.java | 55 - .../linea/zktracer/module/hub/Exceptions.java | 410 - .../module/hub/FailureConditions.java | 66 - .../linea/zktracer/module/hub/Hub.java | 1293 ---- .../module/hub/PlatformController.java | 70 - .../linea/zktracer/module/hub/Signals.java | 285 - .../linea/zktracer/module/hub/State.java | 152 - .../zktracer/module/hub/StorageInfo.java | 39 - .../linea/zktracer/module/hub/Trace.java | 6621 ----------------- .../linea/zktracer/module/hub/TxInfo.java | 110 - .../linea/zktracer/module/hub/TxState.java | 24 - .../linea/zktracer/module/hub/TxTrace.java | 127 - .../module/hub/defer/DeferRegistry.java | 97 - .../module/hub/defer/NextContextDefer.java | 23 - .../module/hub/defer/PostExecDefer.java | 24 - .../hub/defer/PostTransactionDefer.java | 35 - .../defer/SkippedPostTransactionDefer.java | 91 - .../module/hub/fragment/AccountFragment.java | 117 - .../module/hub/fragment/CommonFragment.java | 122 - .../module/hub/fragment/ContextFragment.java | 62 - .../module/hub/fragment/ScenarioFragment.java | 98 - .../module/hub/fragment/StackFragment.java | 268 - .../module/hub/fragment/StorageFragment.java | 65 - .../module/hub/fragment/SubSection.java | 22 - .../module/hub/fragment/TraceFragment.java | 43 - .../module/hub/fragment/TraceSubFragment.java | 22 - .../hub/fragment/TransactionFragment.java | 106 - .../hub/fragment/misc/MiscFragment.java | 94 - .../misc/subfragment/ExpSubFragment.java | 35 - .../misc/subfragment/MmuSubFragment.java | 106 - .../misc/subfragment/MxpSubFragment.java | 77 - .../misc/subfragment/PrecinfoSubFragment.java | 27 - .../misc/subfragment/StpSubFragment.java | 27 - .../oob/CalldataloadSubFragment.java | 44 - .../misc/subfragment/oob/JumpSubFragment.java | 76 - .../module/hub/memory/MemorySpan.java | 45 - .../hub/section/AbortedCallSection.java | 26 - .../module/hub/section/AccountSection.java | 28 - .../module/hub/section/ContextLogSection.java | 28 - .../module/hub/section/CopySection.java | 28 - .../module/hub/section/CreateSection.java | 89 - .../module/hub/section/EndTransaction.java | 28 - .../module/hub/section/JumpSection.java | 28 - .../module/hub/section/KeccakSection.java | 26 - .../module/hub/section/NoCodeCallSection.java | 124 - .../module/hub/section/StackOnlySection.java | 28 - .../zktracer/module/hub/section/StackRam.java | 28 - .../module/hub/section/StorageSection.java | 28 - .../module/hub/section/TraceSection.java | 320 - .../hub/section/TransactionSection.java | 28 - .../module/hub/section/TxSkippedSection.java | 28 - .../module/hub/section/WarmupSection.java | 34 - .../hub/section/WithCodeCallSection.java | 153 - .../PrecompileScenarioTraceSubsection.java | 28 - .../linea/zktracer/module/limits/Keccak.java | 153 - .../linea/zktracer/module/limits/L2Block.java | 150 - .../zktracer/module/limits/L2L1Logs.java | 48 - .../limits/precompiles/Blake2fRounds.java | 107 - .../precompiles/EcAddEffectiveCall.java | 85 - .../precompiles/EcMulEffectiveCall.java | 85 - .../EcPairingCallEffectiveCall.java | 105 - .../limits/precompiles/EcPairingLimit.java | 18 - .../precompiles/EcPairingMillerLoop.java | 61 - .../precompiles/EcRecoverEffectiveCall.java | 115 - .../precompiles/ModexpEffectiveCall.java | 206 - .../limits/precompiles/Rip160Blocks.java | 111 - .../limits/precompiles/Sha256Blocks.java | 110 - .../zktracer/module/logData/LogData.java | 136 - .../zktracer/module/logData/LogDataTrace.java | 51 - .../linea/zktracer/module/logData/Trace.java | 276 - .../zktracer/module/logInfo/LogInfo.java | 231 - .../zktracer/module/logInfo/LogInfoTrace.java | 51 - .../linea/zktracer/module/logInfo/Trace.java | 713 -- .../linea/zktracer/module/mmio/Mmio.java | 44 - .../linea/zktracer/module/mmu/Contexts.java | 30 - .../module/mmu/InstructionContext.java | 23 - .../linea/zktracer/module/mmu/LimbByte.java | 32 - .../linea/zktracer/module/mmu/MicroData.java | 290 - .../module/mmu/MicroDataProcessor.java | 96 - .../linea/zktracer/module/mmu/Mmu.java | 246 - .../module/mmu/MmuPreComputation.java | 37 - .../linea/zktracer/module/mmu/MmuTrace.java | 80 - .../linea/zktracer/module/mmu/Offsets.java | 30 - .../linea/zktracer/module/mmu/Pointers.java | 32 - .../zktracer/module/mmu/PreComputations.java | 51 - .../linea/zktracer/module/mmu/ReadPad.java | 80 - .../linea/zktracer/module/mmu/Trace.java | 1891 ----- .../module/mmu/Type1PreComputation.java | 108 - .../module/mmu/Type2PreComputation.java | 229 - .../module/mmu/Type3PreComputation.java | 149 - .../module/mmu/Type4PreComputation.java | 661 -- .../module/mmu/Type5PreComputation.java | 223 - .../linea/zktracer/module/mod/Mod.java | 103 - .../zktracer/module/mod/ModOperation.java | 300 - .../linea/zktracer/module/mod/Trace.java | 1626 ---- .../module/modexpdata/ModexpData.java | 68 - .../modexpdata/ModexpDataOperation.java | 120 - .../zktracer/module/modexpdata/Trace.java | 268 - .../linea/zktracer/module/mul/Mul.java | 88 - .../zktracer/module/mul/MulOperation.java | 503 -- .../linea/zktracer/module/mul/Regime.java | 24 - .../linea/zktracer/module/mul/Trace.java | 1353 ---- .../linea/zktracer/module/mxp/Chunk.java | 18 - .../linea/zktracer/module/mxp/Mxp.java | 82 - .../linea/zktracer/module/mxp/MxpData.java | 560 -- .../linea/zktracer/module/mxp/Trace.java | 1377 ---- .../zktracer/module/rlp/addr/RlpAddr.java | 301 - .../module/rlp/addr/RlpAddrChunk.java | 53 - .../linea/zktracer/module/rlp/addr/Trace.java | 739 -- .../linea/zktracer/module/rlp/txn/RlpTxn.java | 1216 --- .../zktracer/module/rlp/txn/RlpTxnChunk.java | 171 - .../module/rlp/txn/RlpTxnColumnsValue.java | 98 - .../linea/zktracer/module/rlp/txn/Trace.java | 1546 ---- .../zktracer/module/rlp/txn/TxnrlpTrace.java | 35 - .../zktracer/module/rlp/txrcpt/RlpTxrcpt.java | 789 -- .../module/rlp/txrcpt/RlpTxrcptChunk.java | 72 - .../module/rlp/txrcpt/RlpTxrcptColumns.java | 92 - .../module/rlp/txrcpt/RlpTxrcptTrace.java | 51 - .../zktracer/module/rlp/txrcpt/Trace.java | 1173 --- .../rlputils/ByteCountAndPowerOutput.java | 21 - .../zktracer/module/rlputils/Pattern.java | 108 - .../linea/zktracer/module/rom/Rom.java | 65 - .../linea/zktracer/module/rom/Trace.java | 665 -- .../zktracer/module/romLex/RomChunk.java | 177 - .../linea/zktracer/module/romLex/RomLex.java | 318 - .../linea/zktracer/module/romLex/Trace.java | 302 - .../linea/zktracer/module/shf/ByteChunks.java | 36 - .../linea/zktracer/module/shf/Res.java | 48 - .../linea/zktracer/module/shf/Shb.java | 52 - .../linea/zktracer/module/shf/Shf.java | 74 - .../zktracer/module/shf/ShfOperation.java | 208 - .../linea/zktracer/module/shf/ShfTrace.java | 31 - .../linea/zktracer/module/shf/Shifter.java | 58 - .../linea/zktracer/module/shf/Trace.java | 1369 ---- .../linea/zktracer/module/stp/Stp.java | 221 - .../linea/zktracer/module/stp/StpChunk.java | 297 - .../linea/zktracer/module/stp/Trace.java | 803 -- .../zktracer/module/tables/bin/BinRt.java | 132 - .../zktracer/module/tables/bin/Trace.java | 163 - .../InstructionDecoder.java | 180 - .../tables/instructionDecoder/Trace.java | 2023 ----- .../zktracer/module/tables/shf/ShfRt.java | 72 - .../zktracer/module/tables/shf/Trace.java | 211 - .../linea/zktracer/module/trm/Trace.java | 403 - .../linea/zktracer/module/trm/Trm.java | 115 - .../zktracer/module/trm/TrmOperation.java | 70 - .../linea/zktracer/module/trm/TrmTrace.java | 31 - .../module/txn_data/BlockSnapshot.java | 100 - .../linea/zktracer/module/txn_data/Trace.java | 1182 --- .../module/txn_data/TransactionSnapshot.java | 259 - .../zktracer/module/txn_data/TxnData.java | 538 -- .../linea/zktracer/module/wcp/Trace.java | 990 --- .../linea/zktracer/module/wcp/Wcp.java | 118 - .../zktracer/module/wcp/WcpOperation.java | 242 - .../linea/zktracer/opcode/DataLocation.java | 31 - .../zktracer/opcode/InstructionFamily.java | 45 - .../linea/zktracer/opcode/OpCode.java | 230 - .../linea/zktracer/opcode/OpCodeData.java | 92 - .../linea/zktracer/opcode/OpCodes.java | 96 - .../linea/zktracer/opcode/RamSettings.java | 31 - .../linea/zktracer/opcode/gas/Billing.java | 80 - .../opcode/gas/BillingDeserializer.java | 100 - .../zktracer/opcode/gas/BillingRate.java | 23 - .../zktracer/opcode/gas/GasConstants.java | 86 - .../linea/zktracer/opcode/gas/MxpType.java | 26 - .../opcode/gas/projector/AccountAccess.java | 49 - .../zktracer/opcode/gas/projector/Base.java | 23 - .../opcode/gas/projector/BlockHash.java | 23 - .../zktracer/opcode/gas/projector/Call.java | 132 - .../zktracer/opcode/gas/projector/Create.java | 63 - .../opcode/gas/projector/Create2.java | 73 - .../opcode/gas/projector/DataCopy.java | 63 - .../zktracer/opcode/gas/projector/Exp.java | 40 - .../opcode/gas/projector/ExtCodeCopy.java | 66 - .../opcode/gas/projector/GasProjection.java | 114 - .../opcode/gas/projector/GasProjector.java | 253 - .../zktracer/opcode/gas/projector/High.java | 23 - .../opcode/gas/projector/JumpDest.java | 23 - .../zktracer/opcode/gas/projector/Log.java | 75 - .../zktracer/opcode/gas/projector/Low.java | 23 - .../opcode/gas/projector/MLoadStore.java | 48 - .../opcode/gas/projector/MStore8.java | 47 - .../zktracer/opcode/gas/projector/Mid.java | 23 - .../zktracer/opcode/gas/projector/Return.java | 60 - .../zktracer/opcode/gas/projector/Revert.java | 45 - .../zktracer/opcode/gas/projector/SLoad.java | 45 - .../zktracer/opcode/gas/projector/SStore.java | 91 - .../opcode/gas/projector/SelfDestruct.java | 79 - .../zktracer/opcode/gas/projector/Sha3.java | 63 - .../opcode/gas/projector/VeryLow.java | 23 - .../zktracer/opcode/gas/projector/Zero.java | 23 - .../linea/zktracer/opcode/stack/Pattern.java | 33 - .../zktracer/opcode/stack/StackSettings.java | 52 - .../zktracer/runtime/callstack/CallFrame.java | 244 - .../runtime/callstack/CallFrameType.java | 58 - .../zktracer/runtime/callstack/CallStack.java | 241 - .../linea/zktracer/runtime/stack/Action.java | 22 - .../runtime/stack/ConflationInfo.java | 33 - .../runtime/stack/IndexedStackOperation.java | 35 - .../linea/zktracer/runtime/stack/Stack.java | 371 - .../zktracer/runtime/stack/StackContext.java | 90 - .../zktracer/runtime/stack/StackLine.java | 113 - .../runtime/stack/StackOperation.java | 91 - .../linea/zktracer/runtime/stack/Status.java | 26 - .../linea/zktracer/types/AddressUtils.java | 77 - .../zktracer/types/ArrayWrappingBytes.java | 171 - .../zktracer/types/ArrayWrappingBytes16.java | 57 - .../linea/zktracer/types/BitDecOutput.java | 20 - .../linea/zktracer/types/Bytes16.java | 278 - .../linea/zktracer/types/BytesValues.java | 85 - .../linea/zktracer/types/Checks.java | 41 - .../linea/zktracer/types/Containers.java | 34 - .../linea/zktracer/types/Conversions.java | 93 - .../zktracer/types/DelegatingBytes16.java | 41 - .../types/DelegatingMutableBytes16.java | 44 - .../consensys/linea/zktracer/types/EWord.java | 197 - .../linea/zktracer/types/MemoryPoint.java | 54 - .../linea/zktracer/types/MemoryRange.java | 58 - .../types/MutableArrayWrappingBytes.java | 113 - .../types/MutableArrayWrappingBytes16.java | 38 - .../linea/zktracer/types/MutableBytes16.java | 111 - .../linea/zktracer/types/UnsignedByte.java | 143 - .../consensys/linea/zktracer/types/Utils.java | 86 - .../src/main/resources/opcodes.yml | 1669 ----- .../linea/zktracer/ReplaysTests.java | 75 - .../linea/zktracer/ZkTracerTest.java | 29 - .../zktracer/bytestheta/BaseThetaTest.java | 147 - .../zktracer/containers/StackedListTests.java | 100 - .../zktracer/containers/StackedSetTests.java | 71 - .../linea/zktracer/module/EcDataTest.java | 41 - .../linea/zktracer/module/add/addTest.java | 106 - .../linea/zktracer/module/bin/BinTest.java | 60 - .../module/ext/TestDuplicatedOperations.java | 53 - .../module/hub/CallEmptyNoStopTest.java | 96 - .../linea/zktracer/module/hub/OtherTests.java | 44 - .../zktracer/module/hub/TestTwoPlusTwo.java | 52 - .../linea/zktracer/module/mod/ModTest.java | 54 - .../zktracer/module/mod/ModTracerTest.java | 48 - .../linea/zktracer/module/mxp/MxpTest.java | 594 -- .../zktracer/module/mxp/MxpTracerTest.java | 77 - .../module/precompiles/precTests.java | 21 - .../module/rlpAddr/TestRlpAddress.java | 163 - .../module/rlpCommon/rlpRandEdgeCase.java | 68 - .../module/rlp_txrcpt/RandomTxrcptTests.java | 137 - .../module/rlptxn/TestRandomTxns.java | 187 - .../zktracer/module/shf/ShfRtTracerTest.java | 131 - .../linea/zktracer/module/stp/StpTest.java | 286 - .../zktracer/module/trm/TrmDataTest.java | 40 - .../zktracer/module/trm/TrmTracerTest.java | 138 - .../zktracer/module/wcp/wcpEdgeCaseTest.java | 78 - .../zktracer/testing/BytecodeCompiler.java | 259 - .../zktracer/testing/BytecodeRunner.java | 90 - .../zktracer/testing/DynamicTestCase.java | 32 - .../linea/zktracer/testing/DynamicTests.java | 190 - .../linea/zktracer/testing/EvmExtension.java | 31 - .../linea/zktracer/testing/ExampleTxTest.java | 62 - .../linea/zktracer/testing/ModuleTests.java | 38 - .../linea/zktracer/testing/OpcodeCall.java | 23 - .../linea/zktracer/testing/ToyAccount.java | 172 - .../zktracer/testing/ToyBlockValues.java | 89 - .../testing/ToyExecutionEnvironment.java | 279 - .../zktracer/testing/ToyTransaction.java | 93 - .../linea/zktracer/testing/ToyWorld.java | 192 - gradle.properties | 2 +- gradle/dependency-management.gradle | 15 +- native/compress/compress-jni/go.mod | 2 +- reference-tests/build.gradle | 104 - .../linea/BlockchainReferenceTestTools.java | 169 - .../consensys/linea/CorsetBlockProcessor.java | 200 - .../net/consensys/linea/EvmExtension.java | 31 - .../linea/GeneralStateReferenceTestTools.java | 235 - .../net/consensys/linea/generated/.gitkeep | 0 .../src/test/resources/ethereum-tests | 1 - .../BlockchainReferenceTest.java.template | 56 - .../GeneralStateReferenceTest.java.template | 55 - {arithmetization => sequencer}/LICENSE | 0 {arithmetization => sequencer}/build.gradle | 1 + .../linea/AbstractLineaRequiredPlugin.java | 0 .../AbstractLineaSharedOptionsPlugin.java | 0 .../TransactionProfitabilityCalculator.java | 0 .../config/LineaL1L2BridgeCliOptions.java | 0 .../config/LineaL1L2BridgeConfiguration.java | 0 .../config/LineaProfitabilityCliOptions.java | 0 .../LineaProfitabilityConfiguration.java | 0 .../linea/config/LineaRpcCliOptions.java | 0 .../linea/config/LineaRpcConfiguration.java | 0 .../linea/config/LineaTracerCliOptions.java | 0 .../config/LineaTracerConfiguration.java | 0 ...neaTransactionPoolValidatorCliOptions.java | 0 ...TransactionPoolValidatorConfiguration.java | 0 .../LineaTransactionSelectorCliOptions.java | 0 ...LineaTransactionSelectorConfiguration.java | 0 .../config/converters/AddressConverter.java | 0 .../config/converters/BytesConverter.java | 0 .../linea/config/converters/WeiConverter.java | 0 .../continoustracing/ContinuousTracer.java | 0 .../ContinuousTracingBlockAddedListener.java | 0 .../ContinuousTracingCliOptions.java | 0 .../ContinuousTracingConfiguration.java | 0 .../ContinuousTracingPlugin.java | 0 .../SlackNotificationService.java | 0 .../continoustracing/TraceFailureHandler.java | 2 +- .../exception/InvalidBlockTraceException.java | 0 .../InvalidTraceHandlerException.java | 0 .../exception/TraceVerificationException.java | 0 .../ModuleLimitsValidationResult.java | 2 +- .../modulelimit/ModuleLineCountValidator.java | 2 +- .../consensys/linea/rpc/capture/Capture.java | 0 .../capture/CaptureEndpointServicePlugin.java | 0 .../linea/rpc/capture/CaptureParams.java | 0 .../linea/rpc/capture/CaptureToFile.java | 0 .../linea/rpc/counters/Counters.java | 0 .../CountersEndpointServicePlugin.java | 0 .../rpc/counters/CountersRequestParams.java | 0 .../rpc/counters/GenerateCountersV0.java | 0 .../rpc/linea/LineaEndpointServicePlugin.java | 2 +- .../linea/rpc/linea/LineaEstimateGas.java | 8 +- .../GenerateConflatedTracesV0.java | 0 .../linea/rpc/tracegeneration/TraceFile.java | 0 .../tracegeneration/TraceRequestParams.java | 0 .../TracesEndpointServicePlugin.java | 0 .../linea/sequencer/TracerAggregator.java | 0 .../LineaTransactionPoolValidatorFactory.java | 12 +- .../LineaTransactionPoolValidatorPlugin.java | 7 +- .../validators/AllowedAddressValidator.java | 2 +- .../validators/CalldataValidator.java | 2 +- .../validators/GasLimitValidator.java | 2 +- .../validators/ProfitabilityValidator.java | 2 +- .../validators/SimulationValidator.java | 15 +- .../LineaTransactionSelectionResult.java | 2 +- .../LineaTransactionSelectorFactory.java | 4 +- .../LineaTransactionSelectorPlugin.java | 7 +- .../selectors/LineaTransactionSelector.java | 2 +- .../MaxBlockCallDataTransactionSelector.java | 6 +- .../MaxBlockGasTransactionSelector.java | 9 +- .../ProfitableTransactionSelector.java | 15 +- .../TraceLineLimitTransactionSelector.java | 16 +- .../src/main/resources/spillings.toml | 0 .../ContinuousTracerTest.java | 0 .../AllowedAddressValidatorTest.java | 2 +- .../validators/CalldataValidatorTest.java | 2 +- .../validators/GasLimitValidatorTest.java | 2 +- .../ProfitabilityValidatorTest.java | 2 +- .../validators/SimulationValidatorTest.java | 4 +- ...ckCallDataSizeTransactionSelectorTest.java | 3 +- .../MaxBlockGasTransactionSelectorTest.java | 5 +- .../ProfitableTransactionSelectorTest.java | 9 +- .../TestTransactionEvaluationContext.java | 0 ...TraceLineLimitTransactionSelectorTest.java | 7 +- .../contracts/ec_data/EcDataBigTest.sol | 0 .../src/test/resources/contracts/mxp/A.sol | 0 .../src/test/resources/contracts/mxp/B.sol | 0 .../src/test/resources/contracts/mxp/C.sol | 0 .../src/test/resources/contracts/mxp/D.sol | 0 .../contracts/mxp/MemoryOperations1.sol | 0 .../contracts/mxp/MemoryOperations2.sol | 0 .../mxp/compiledContracts/A.bin-runtime | 0 .../mxp/compiledContracts/B.bin-runtime | 0 .../mxp/compiledContracts/C.bin-runtime | 0 .../mxp/compiledContracts/D.bin-runtime | 0 .../MemoryOperations1.bin-runtime | 0 .../MemoryOperations2.bin-runtime | 0 .../src/test/resources/log4j2.xml | 2 +- .../replays/start-vs-prepare-tx.json.gz | Bin .../test/resources/sequencer/line-limits.toml | 0 .../specs/add/trace-add-0x01-0x02.json | 0 .../specs/add/trace-add-0xff-0xff.json | 0 .../specs/mod/trace-mod-0x01-0x02.json | 0 settings.gradle | 5 +- 440 files changed, 182 insertions(+), 68539 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/blockcapture/BlockCapturer.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/AddressReaper.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/Reaper.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/StorageReaper.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/AccessListEntrySnapshot.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/AccountSnapshot.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/BlockHeaderSnapshot.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/BlockSnapshot.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/ConflationSnapshot.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/StorageSnapshot.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/TransactionSnapshot.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/corset/CorsetValidator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/ColumnHeader.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/ConflationAwareOperationTracer.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTrace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseBytes.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseTheta.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BytesArray.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/HighLowBytes.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/container/ModuleOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/container/StackedContainer.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/CountedList.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/StackedList.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/set/StackedSet.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/json/BigIntegerSerializer.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/json/JsonConverter.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/json/NumericBooleanSerializer.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ModuleTrace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/Util.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/UtilCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Add.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/AddOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Adder.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/Bin.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/BinOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/EcData.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/EcDataOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Euc.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/EucOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/BigIntegerConverter.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/Ext.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/ExtOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/AbstractExtCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/BytesHCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/BytesICalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/CmpFlagsCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/DeltaCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/OverflowJCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModBytesJCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModBytesQCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModOverflowResCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModBytesJCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModBytesQCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModOverflowResCalculator.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AbortingConditions.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/BlockInfo.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Bytecode.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/DeploymentExceptions.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/DeploymentInfo.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Exceptions.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/FailureConditions.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/PlatformController.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Signals.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/StorageInfo.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxInfo.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxState.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/NextContextDefer.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostExecDefer.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostTransactionDefer.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ScenarioFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StorageFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/SubSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceSubFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/MiscFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/ExpSubFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/MmuSubFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/MxpSubFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/PrecinfoSubFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/StpSubFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/oob/CalldataloadSubFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/oob/JumpSubFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/memory/MemorySpan.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AbortedCallSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java delete 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/EndTransaction.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackOnlySection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TraceSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/WarmupSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/WithCodeCallSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/subsection/PrecompileScenarioTraceSubsection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/L2Block.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/L2L1Logs.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fRounds.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddEffectiveCall.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulEffectiveCall.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingCallEffectiveCall.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingLimit.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoop.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverEffectiveCall.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160Blocks.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/LogData.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/LogDataTrace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/LogInfo.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/LogInfoTrace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/Mmio.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Contexts.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/InstructionContext.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/LimbByte.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MicroData.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MicroDataProcessor.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuPreComputation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuTrace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Offsets.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Pointers.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/PreComputations.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/ReadPad.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type1PreComputation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type2PreComputation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type3PreComputation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type4PreComputation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type5PreComputation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/Mod.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/ModOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/ModexpData.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/ModexpDataOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Mul.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/MulOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Regime.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Chunk.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Mxp.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpData.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddr.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddrChunk.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxn.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxnChunk.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxnColumnsValue.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/TxnrlpTrace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcpt.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptChunk.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptColumns.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptTrace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlputils/ByteCountAndPowerOutput.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlputils/Pattern.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Rom.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/RomChunk.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/RomLex.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ByteChunks.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Res.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shb.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shf.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ShfOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ShfTrace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shifter.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpChunk.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/bin/BinRt.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/bin/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/shf/ShfRt.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/shf/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/TrmOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/TrmTrace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/BlockSnapshot.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/Trace.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/Wcp.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/WcpOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/DataLocation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/InstructionFamily.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCode.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodeData.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodes.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/RamSettings.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/Billing.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/BillingDeserializer.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/BillingRate.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/GasConstants.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/MxpType.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/AccountAccess.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Base.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/BlockHash.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create2.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/DataCopy.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Exp.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/ExtCodeCopy.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/GasProjection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/GasProjector.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/High.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/JumpDest.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Log.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Low.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/MLoadStore.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/MStore8.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Mid.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Return.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Revert.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SLoad.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SStore.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SelfDestruct.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Sha3.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/VeryLow.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Zero.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/stack/Pattern.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/stack/StackSettings.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrameType.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Action.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/ConflationInfo.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/IndexedStackOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Stack.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackContext.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackLine.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Status.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/ArrayWrappingBytes.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/ArrayWrappingBytes16.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/BitDecOutput.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/Bytes16.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/BytesValues.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/Checks.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/Containers.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/DelegatingBytes16.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/DelegatingMutableBytes16.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/EWord.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemoryPoint.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemoryRange.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableArrayWrappingBytes.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableArrayWrappingBytes16.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableBytes16.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/UnsignedByte.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java delete mode 100644 arithmetization/src/main/resources/opcodes.yml delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/ReplaysTests.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/bytestheta/BaseThetaTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/containers/StackedListTests.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/containers/StackedSetTests.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/EcDataTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/add/addTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/ext/TestDuplicatedOperations.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/CallEmptyNoStopTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/OtherTests.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TestTwoPlusTwo.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTracerTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTracerTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/precompiles/precTests.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpAddr/TestRlpAddress.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpCommon/rlpRandEdgeCase.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlp_txrcpt/RandomTxrcptTests.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxn/TestRandomTxns.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/shf/ShfRtTracerTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/stp/StpTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmDataTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/wcp/wcpEdgeCaseTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeCompiler.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeRunner.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTestCase.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTests.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/EvmExtension.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ExampleTxTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ModuleTests.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/OpcodeCall.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyAccount.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyBlockValues.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyTransaction.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyWorld.java delete mode 100644 reference-tests/build.gradle delete mode 100644 reference-tests/src/test/java/net/consensys/linea/BlockchainReferenceTestTools.java delete mode 100644 reference-tests/src/test/java/net/consensys/linea/CorsetBlockProcessor.java delete mode 100644 reference-tests/src/test/java/net/consensys/linea/EvmExtension.java delete mode 100644 reference-tests/src/test/java/net/consensys/linea/GeneralStateReferenceTestTools.java delete mode 100644 reference-tests/src/test/java/net/consensys/linea/generated/.gitkeep delete mode 160000 reference-tests/src/test/resources/ethereum-tests delete mode 100644 reference-tests/src/test/resources/templates/BlockchainReferenceTest.java.template delete mode 100644 reference-tests/src/test/resources/templates/GeneralStateReferenceTest.java.template rename {arithmetization => sequencer}/LICENSE (100%) rename {arithmetization => sequencer}/build.gradle (97%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/AbstractLineaSharedOptionsPlugin.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/bl/TransactionProfitabilityCalculator.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaL1L2BridgeCliOptions.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaL1L2BridgeConfiguration.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaProfitabilityCliOptions.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaProfitabilityConfiguration.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaRpcCliOptions.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaRpcConfiguration.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaTracerCliOptions.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaTracerConfiguration.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaTransactionPoolValidatorCliOptions.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaTransactionPoolValidatorConfiguration.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaTransactionSelectorCliOptions.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/LineaTransactionSelectorConfiguration.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/converters/AddressConverter.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/converters/BytesConverter.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/config/converters/WeiConverter.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/continoustracing/ContinuousTracer.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingBlockAddedListener.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingCliOptions.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingConfiguration.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingPlugin.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/continoustracing/SlackNotificationService.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/continoustracing/TraceFailureHandler.java (97%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/continoustracing/exception/InvalidBlockTraceException.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/continoustracing/exception/InvalidTraceHandlerException.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/continoustracing/exception/TraceVerificationException.java (100%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/modulelimit/ModuleLimitsValidationResult.java (98%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/modulelimit/ModuleLineCountValidator.java (99%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/capture/Capture.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/capture/CaptureEndpointServicePlugin.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/capture/CaptureParams.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/capture/CaptureToFile.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/counters/Counters.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/counters/CountersEndpointServicePlugin.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/counters/CountersRequestParams.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/counters/GenerateCountersV0.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/linea/LineaEndpointServicePlugin.java (97%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/linea/LineaEstimateGas.java (98%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/tracegeneration/GenerateConflatedTracesV0.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceFile.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceRequestParams.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/rpc/tracegeneration/TracesEndpointServicePlugin.java (100%) rename {arithmetization => sequencer}/src/main/java/net/consensys/linea/sequencer/TracerAggregator.java (100%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txpoolvalidation/LineaTransactionPoolValidatorFactory.java (88%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java (95%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txpoolvalidation/validators/AllowedAddressValidator.java (98%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txpoolvalidation/validators/CalldataValidator.java (96%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txpoolvalidation/validators/GasLimitValidator.java (96%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txpoolvalidation/validators/ProfitabilityValidator.java (97%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txpoolvalidation/validators/SimulationValidator.java (89%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txselection/LineaTransactionSelectionResult.java (98%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txselection/LineaTransactionSelectorFactory.java (94%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txselection/LineaTransactionSelectorPlugin.java (91%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txselection/selectors/LineaTransactionSelector.java (99%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txselection/selectors/MaxBlockCallDataTransactionSelector.java (95%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txselection/selectors/MaxBlockGasTransactionSelector.java (89%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txselection/selectors/ProfitableTransactionSelector.java (90%) rename {arithmetization/src/main/java/net/consensys/linea/sequencer => sequencer/src/main/java/net/consensys/linea}/txselection/selectors/TraceLineLimitTransactionSelector.java (93%) rename {arithmetization => sequencer}/src/main/resources/spillings.toml (100%) rename {arithmetization => sequencer}/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java (100%) rename {arithmetization/src/test/java/net/consensys/linea/sequencer => sequencer/src/test/java/net/consensys/linea}/txpoolvalidation/validators/AllowedAddressValidatorTest.java (98%) rename {arithmetization/src/test/java/net/consensys/linea/sequencer => sequencer/src/test/java/net/consensys/linea}/txpoolvalidation/validators/CalldataValidatorTest.java (97%) rename {arithmetization/src/test/java/net/consensys/linea/sequencer => sequencer/src/test/java/net/consensys/linea}/txpoolvalidation/validators/GasLimitValidatorTest.java (97%) rename {arithmetization/src/test/java/net/consensys/linea/sequencer => sequencer/src/test/java/net/consensys/linea}/txpoolvalidation/validators/ProfitabilityValidatorTest.java (99%) rename {arithmetization/src/test/java/net/consensys/linea/sequencer => sequencer/src/test/java/net/consensys/linea}/txpoolvalidation/validators/SimulationValidatorTest.java (97%) rename {arithmetization/src/test/java/net/consensys/linea/sequencer => sequencer/src/test/java/net/consensys/linea}/txselection/selectors/MaxBlockCallDataSizeTransactionSelectorTest.java (96%) rename {arithmetization/src/test/java/net/consensys/linea/sequencer => sequencer/src/test/java/net/consensys/linea}/txselection/selectors/MaxBlockGasTransactionSelectorTest.java (94%) rename {arithmetization/src/test/java/net/consensys/linea/sequencer => sequencer/src/test/java/net/consensys/linea}/txselection/selectors/ProfitableTransactionSelectorTest.java (97%) rename {arithmetization/src/test/java/net/consensys/linea/sequencer => sequencer/src/test/java/net/consensys/linea}/txselection/selectors/TestTransactionEvaluationContext.java (100%) rename {arithmetization/src/test/java/net/consensys/linea/sequencer => sequencer/src/test/java/net/consensys/linea}/txselection/selectors/TraceLineLimitTransactionSelectorTest.java (96%) rename {arithmetization => sequencer}/src/test/resources/contracts/ec_data/EcDataBigTest.sol (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/A.sol (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/B.sol (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/C.sol (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/D.sol (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/MemoryOperations1.sol (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/MemoryOperations2.sol (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/compiledContracts/A.bin-runtime (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/compiledContracts/B.bin-runtime (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/compiledContracts/C.bin-runtime (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/compiledContracts/D.bin-runtime (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/compiledContracts/MemoryOperations1.bin-runtime (100%) rename {arithmetization => sequencer}/src/test/resources/contracts/mxp/compiledContracts/MemoryOperations2.bin-runtime (100%) rename {arithmetization => sequencer}/src/test/resources/log4j2.xml (89%) rename {arithmetization => sequencer}/src/test/resources/replays/start-vs-prepare-tx.json.gz (100%) rename {arithmetization => sequencer}/src/test/resources/sequencer/line-limits.toml (100%) rename {arithmetization => sequencer}/src/test/resources/specs/add/trace-add-0x01-0x02.json (100%) rename {arithmetization => sequencer}/src/test/resources/specs/add/trace-add-0xff-0xff.json (100%) rename {arithmetization => sequencer}/src/test/resources/specs/mod/trace-mod-0x01-0x02.json (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 95f007e13..1426c7871 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,6 +50,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./arithmetization/build/libs/besu-sequencer-plugins-${{ steps.get_version.outputs.VERSION }}.jar - asset_name: besu-sequencer-plugins-${{ steps.get_version.outputs.VERSION }}.jar + asset_path: ./arithmetization/build/libs/linea-sequencer-${{ steps.get_version.outputs.VERSION }}.jar + asset_name: linea-sequencer-${{ steps.get_version.outputs.VERSION }}.jar asset_content_type: application/octet-stream diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c0403294..5a29a26e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,132 +1,132 @@ # Changelog ## 0.1.4-test24 -Test pre-release 24 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* Improve linea_estimateGas error response [#650](https://github.com/Consensys/besu-sequencer-plugins/pull/650) -* On Windows also build Linux native lib so it can run on WSL [#651](https://github.com/Consensys/besu-sequencer-plugins/pull/651) +Test pre-release 24 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* Improve linea_estimateGas error response [#650](https://github.com/Consensys/linea-sequencer/pull/650) +* On Windows also build Linux native lib so it can run on WSL [#651](https://github.com/Consensys/linea-sequencer/pull/651) ## 0.1.4-test23 -Test pre-release 23 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* linea_estimateGas compatibility mode multiplier https://github.com/Consensys/besu-sequencer-plugins/pull/646 +Test pre-release 23 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* linea_estimateGas compatibility mode multiplier https://github.com/Consensys/linea-sequencer/pull/646 ## 0.1.4-test22 -Test pre-release 22 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* linea_estimateGas compatibility switch https://github.com/Consensys/besu-sequencer-plugins/pull/634 -* Update profitability formula with gas price adjustment option https://github.com/Consensys/besu-sequencer-plugins/pull/638 -* Update code to latest plugin API https://github.com/Consensys/besu-sequencer-plugins/pull/640 -* Txpool profitability check https://github.com/Consensys/besu-sequencer-plugins/pull/603 -* Fix price adjustment in profitability formula https://github.com/Consensys/besu-sequencer-plugins/pull/642 +Test pre-release 22 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* linea_estimateGas compatibility switch https://github.com/Consensys/linea-sequencer/pull/634 +* Update profitability formula with gas price adjustment option https://github.com/Consensys/linea-sequencer/pull/638 +* Update code to latest plugin API https://github.com/Consensys/linea-sequencer/pull/640 +* Txpool profitability check https://github.com/Consensys/linea-sequencer/pull/603 +* Fix price adjustment in profitability formula https://github.com/Consensys/linea-sequencer/pull/642 ## 0.1.4-test21 -Test pre-release 21 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* fix: capture SSTORE-touched storage slots for correct gas computations [#606](https://github.com/Consensys/besu-sequencer-plugins/pull/606) -* build: make the build script portable, explicit dependency on Go & GCC, test libcompress build [#621](https://github.com/Consensys/besu-sequencer-plugins/pull/621) -* Update after the refactor of transaction selection service [#626](https://github.com/Consensys/besu-sequencer-plugins/pull/626) -* Use the right classloader to load the native library [#628](https://github.com/Consensys/besu-sequencer-plugins/pull/628) +Test pre-release 21 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* fix: capture SSTORE-touched storage slots for correct gas computations [#606](https://github.com/Consensys/linea-sequencer/pull/606) +* build: make the build script portable, explicit dependency on Go & GCC, test libcompress build [#621](https://github.com/Consensys/linea-sequencer/pull/621) +* Update after the refactor of transaction selection service [#626](https://github.com/Consensys/linea-sequencer/pull/626) +* Use the right classloader to load the native library [#628](https://github.com/Consensys/linea-sequencer/pull/628) ## 0.1.4-test20 -Test pre-release 20 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* Get L2L1 settings from CLI options [#591](https://github.com/Consensys/besu-sequencer-plugins/pull/591) -* feat: add a replay capture script [#600](https://github.com/Consensys/besu-sequencer-plugins/pull/600) -* move compress native into plugin repo [#604](https://github.com/Consensys/besu-sequencer-plugins/pull/604) -* Add compression [#605](https://github.com/Consensys/besu-sequencer-plugins/pull/605) -* Update for the new bad block manager [#607](https://github.com/Consensys/besu-sequencer-plugins/pull/607) +Test pre-release 20 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* Get L2L1 settings from CLI options [#591](https://github.com/Consensys/linea-sequencer/pull/591) +* feat: add a replay capture script [#600](https://github.com/Consensys/linea-sequencer/pull/600) +* move compress native into plugin repo [#604](https://github.com/Consensys/linea-sequencer/pull/604) +* Add compression [#605](https://github.com/Consensys/linea-sequencer/pull/605) +* Update for the new bad block manager [#607](https://github.com/Consensys/linea-sequencer/pull/607) ## 0.1.4-test19 -Test pre-release 19 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* Avoid returning an estimated priority fee that is less than the min gas price [#598](https://github.com/Consensys/besu-sequencer-plugins/pull/598) +Test pre-release 19 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* Avoid returning an estimated priority fee that is less than the min gas price [#598](https://github.com/Consensys/linea-sequencer/pull/598) ## 0.1.4-test18 -Test pre-release 18 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* fix: check that spilling and limits file contain all counted modules [#592](https://github.com/Consensys/besu-sequencer-plugins/pull/592) +Test pre-release 18 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* fix: check that spilling and limits file contain all counted modules [#592](https://github.com/Consensys/linea-sequencer/pull/592) ## 0.1.4-test18-RC3 -Test pre-release 18-RC3 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* Use compressed tx size also when selecting txs from block creation [#590](https://github.com/Consensys/besu-sequencer-plugins/pull/590) +Test pre-release 18-RC3 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* Use compressed tx size also when selecting txs from block creation [#590](https://github.com/Consensys/linea-sequencer/pull/590) ## 0.1.4-test18-RC2 -Test pre-release 18-RC2 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* Fix linea_estimateGas reports Internal error when value or gas price is missing [#587](https://github.com/Consensys/besu-sequencer-plugins/pull/587) +Test pre-release 18-RC2 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* Fix linea_estimateGas reports Internal error when value or gas price is missing [#587](https://github.com/Consensys/linea-sequencer/pull/587) ## 0.1.4-test18-RC1 -Test pre-release 18-RC1 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* Linea estimate gas endpoint [#585](https://github.com/Consensys/besu-sequencer-plugins/pull/585) +Test pre-release 18-RC1 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* Linea estimate gas endpoint [#585](https://github.com/Consensys/linea-sequencer/pull/585) ## 0.1.4-test17 -Test pre-release 17 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* tests: drop huge random tests [#563](https://github.com/Consensys/besu-sequencer-plugins/pull/563) -* feat(modexp-data): implement MODEXP_DATA module [#547](https://github.com/Consensys/besu-sequencer-plugins/pull/547) -* feat: mechanics to capture conflations & replay them as test cases [#561](https://github.com/Consensys/besu-sequencer-plugins/pull/561) -* perf(EUC): one less column [#570](https://github.com/Consensys/besu-sequencer-plugins/pull/570) -* docs: Add basic plugins doc [#509](https://github.com/Consensys/besu-sequencer-plugins/pull/509) -* Check upfront profitability + Unprofitable txs cache and retry limit [#565](https://github.com/Consensys/besu-sequencer-plugins/pull/565) -* Avoid reprocessing txs that go over line count limit [#571](https://github.com/Consensys/besu-sequencer-plugins/pull/571) +Test pre-release 17 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* tests: drop huge random tests [#563](https://github.com/Consensys/linea-sequencer/pull/563) +* feat(modexp-data): implement MODEXP_DATA module [#547](https://github.com/Consensys/linea-sequencer/pull/547) +* feat: mechanics to capture conflations & replay them as test cases [#561](https://github.com/Consensys/linea-sequencer/pull/561) +* perf(EUC): one less column [#570](https://github.com/Consensys/linea-sequencer/pull/570) +* docs: Add basic plugins doc [#509](https://github.com/Consensys/linea-sequencer/pull/509) +* Check upfront profitability + Unprofitable txs cache and retry limit [#565](https://github.com/Consensys/linea-sequencer/pull/565) +* Avoid reprocessing txs that go over line count limit [#571](https://github.com/Consensys/linea-sequencer/pull/571) ## 0.1.4-test16 -Test pre-release 16 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) +Test pre-release 16 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) * fix: bug-compatibility with Geth * fix: PubHash 16 factor -Full changeset https://github.com/Consensys/besu-sequencer-plugins/compare/v0.1.4-test15...v0.1.4-test16 +Full changeset https://github.com/Consensys/linea-sequencer/compare/v0.1.4-test15...v0.1.4-test16 ## 0.1.4-test15 release rebase off of main -* add option to adjust the tx size used to calculate the profitability of a tx during block creation(#562)[https://github.com/Consensys/besu-sequencer-plugins/pull/562] +* add option to adjust the tx size used to calculate the profitability of a tx during block creation(#562)[https://github.com/Consensys/linea-sequencer/pull/562] ## 0.1.4-test14 release rebase off of main -Test pre-release 14 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* Fix log of line counts in case of block limit reached + minor changes [#555](https://github.com/ConsenSys/besu-sequencer-plugins/pull/555) -* build: update Corset to 9.3.0 [#554](https://github.com/ConsenSys/besu-sequencer-plugins/pull/554) +Test pre-release 14 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* Fix log of line counts in case of block limit reached + minor changes [#555](https://github.com/ConsenSys/linea-sequencer/pull/555) +* build: update Corset to 9.3.0 [#554](https://github.com/ConsenSys/linea-sequencer/pull/554) ## 0.1.4-test13 -Test pre-release 13 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* fix stackedSet [c3f226775f24508b93a758e4226a51ae386d76a5](https://github.com/Consensys/besu-sequencer-plugins/commit/c3f226775f24508b93a758e4226a51ae386d76a5) +Test pre-release 13 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* fix stackedSet [c3f226775f24508b93a758e4226a51ae386d76a5](https://github.com/Consensys/linea-sequencer/commit/c3f226775f24508b93a758e4226a51ae386d76a5) ## 0.1.4-test12 -Test pre-release 12 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) +Test pre-release 12 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) * fix: stacked set multiple insertions in a single transaction (#548) ## 0.1.4-test11 -Test pre-release 11 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) +Test pre-release 11 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) * same as 0.1.4-test10 ## 0.1.4-test10 -Test pre-release 10 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) +Test pre-release 10 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) * fix: semantics of LinkedList (#544) * refactor: add @EqualsAndHashCode annotations and remove corresponding methods (#541) ## 0.1.4-test9 -Test pre-release 9 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) +Test pre-release 9 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) * Bump Linea Besu to 24.1.1-SNAPSHOT ## 0.1.4-test8 -Test pre-release 8 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* Add profitable transaction selector [#530](https://github.com/Consensys/besu-sequencer-plugins/pull/530) -* temp: geth-compatibily hacks [820918a](https://github.com/Consensys/besu-sequencer-plugins/commit/820918a39e8d394e73b8de85a46391ffe7d314b1) +Test pre-release 8 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* Add profitable transaction selector [#530](https://github.com/Consensys/linea-sequencer/pull/530) +* temp: geth-compatibily hacks [820918a](https://github.com/Consensys/linea-sequencer/commit/820918a39e8d394e73b8de85a46391ffe7d314b1) ## 0.1.4-test7 -Test pre-release 7 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* fix: invalid SStore gas computation [#532](https://github.com/Consensys/besu-sequencer-plugins/pull/532) +Test pre-release 7 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* fix: invalid SStore gas computation [#532](https://github.com/Consensys/linea-sequencer/pull/532) ## 0.1.4-test6 -Test pre-release 6, fix: [make precompile counters work](https://github.com/Consensys/besu-sequencer-plugins/commit/10f03ead5207746f253703a328f13988ed9b9305) +Test pre-release 6, fix: [make precompile counters work](https://github.com/Consensys/linea-sequencer/commit/10f03ead5207746f253703a328f13988ed9b9305) * feat: implement fake hashdata/info [Franklin Delehelle] * temp: geth-compatibily hacks [Franklin Delehelle] -* refactor: group RLPs modules, use retro-compatible module keys [#508](https://github.com/ConsenSys/besu-sequencer-plugins/pull/508) -* [MINOR] Add javadoc [#507](https://github.com/ConsenSys/besu-sequencer-plugins/pull/507) -* style: update name of prec limits to avoid confusion with old geth name [#506](https://github.com/ConsenSys/besu-sequencer-plugins/pull/506) -* perf: cache tx-specific line counter [#497](https://github.com/ConsenSys/besu-sequencer-plugins/pull/497) -* fix: continuous tracing plugin start check [#500](https://github.com/ConsenSys/besu-sequencer-plugins/pull/500) -* fix: lookup txndata <-> wcp [#488](https://github.com/ConsenSys/besu-sequencer-plugins/pull/488) -* fix(romLex): wrong stack arg for extcodecopy address [#498](https://github.com/ConsenSys/besu-sequencer-plugins/pull/498) +* refactor: group RLPs modules, use retro-compatible module keys [#508](https://github.com/ConsenSys/linea-sequencer/pull/508) +* [MINOR] Add javadoc [#507](https://github.com/ConsenSys/linea-sequencer/pull/507) +* style: update name of prec limits to avoid confusion with old geth name [#506](https://github.com/ConsenSys/linea-sequencer/pull/506) +* perf: cache tx-specific line counter [#497](https://github.com/ConsenSys/linea-sequencer/pull/497) +* fix: continuous tracing plugin start check [#500](https://github.com/ConsenSys/linea-sequencer/pull/500) +* fix: lookup txndata <-> wcp [#488](https://github.com/ConsenSys/linea-sequencer/pull/488) +* fix(romLex): wrong stack arg for extcodecopy address [#498](https://github.com/ConsenSys/linea-sequencer/pull/498) ## 0.1.4-test3 -Test pre-release 3 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) -* Log ZkTracer counters for every produced block [#485](https://github.com/ConsenSys/besu-sequencer-plugins/pull/485) -* fix: overflow for modexp arg [#489](https://github.com/ConsenSys/besu-sequencer-plugins/pull/489) -* bin reimplementation [#473](https://github.com/ConsenSys/besu-sequencer-plugins/pull/473) -* applyMavenExclusions=false [#477](https://github.com/ConsenSys/besu-sequencer-plugins/pull/477) +Test pre-release 3 from [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) +* Log ZkTracer counters for every produced block [#485](https://github.com/ConsenSys/linea-sequencer/pull/485) +* fix: overflow for modexp arg [#489](https://github.com/ConsenSys/linea-sequencer/pull/489) +* bin reimplementation [#473](https://github.com/ConsenSys/linea-sequencer/pull/473) +* applyMavenExclusions=false [#477](https://github.com/ConsenSys/linea-sequencer/pull/477) ## 0.1.4-test2 Testing pre-release from branch test-release/v0.1.4-test2 @@ -137,29 +137,29 @@ Testing pre-release from branch test-release/v0.1.4-test2 ## 0.1.4-test Temporary line counting release for testnet. -* count stack temporary impl: make loginfo counts closer to Geth [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) +* count stack temporary impl: make loginfo counts closer to Geth [temp/issue-248/count-stack-only](https://github.com/Consensys/linea-sequencer/tree/temp/issue-248/count-stack-only) -- -* fix: `Bytes.toUnsignedInteger` [#484](https://github.com/ConsenSys/besu-sequencer-plugins/pull/484) -* perf: delay computations at trace time [#483](https://github.com/ConsenSys/besu-sequencer-plugins/pull/483) +* fix: `Bytes.toUnsignedInteger` [#484](https://github.com/ConsenSys/linea-sequencer/pull/484) +* perf: delay computations at trace time [#483](https://github.com/ConsenSys/linea-sequencer/pull/483) ## 0.1.3 -- perf: improve `StackedSet` performances [#466](https://github.com/ConsenSys/besu-sequencer-plugins/pull/466) -- feat: implement L1 block & Keccak limits [#445](https://github.com/ConsenSys/besu-sequencer-plugins/pull/445) -- feat: partially implement EC_DATA [#475](https://github.com/ConsenSys/besu-sequencer-plugins/pull/475) -- fix: ensure trace files are always deleted [#462](https://github.com/ConsenSys/besu-sequencer-plugins/pull/462) +- perf: improve `StackedSet` performances [#466](https://github.com/ConsenSys/linea-sequencer/pull/466) +- feat: implement L1 block & Keccak limits [#445](https://github.com/ConsenSys/linea-sequencer/pull/445) +- feat: partially implement EC_DATA [#475](https://github.com/ConsenSys/linea-sequencer/pull/475) +- fix: ensure trace files are always deleted [#462](https://github.com/ConsenSys/linea-sequencer/pull/462) ## 0.1.2 Release 8 for 23.10.4-SNAPSHOT of linea-besu -- changed default file name to toml [#476](https://github.com/ConsenSys/besu-sequencer-plugins/pull/476) -- feat: implement `BIN` counting [#471](https://github.com/ConsenSys/besu-sequencer-plugins/pull/471) -- Upgrade Linea Besu to 23.10.4-SNAPSHOT [#469](https://github.com/ConsenSys/besu-sequencer-plugins/pull/469) -- fix: incorrect address comparison [#470](https://github.com/ConsenSys/besu-sequencer-plugins/pull/470) -- fix: line count discrepancy [#468](https://github.com/ConsenSys/besu-sequencer-plugins/pull/468) +- changed default file name to toml [#476](https://github.com/ConsenSys/linea-sequencer/pull/476) +- feat: implement `BIN` counting [#471](https://github.com/ConsenSys/linea-sequencer/pull/471) +- Upgrade Linea Besu to 23.10.4-SNAPSHOT [#469](https://github.com/ConsenSys/linea-sequencer/pull/469) +- fix: incorrect address comparison [#470](https://github.com/ConsenSys/linea-sequencer/pull/470) +- fix: line count discrepancy [#468](https://github.com/ConsenSys/linea-sequencer/pull/468) ## 0.1.1 Release for 23.10.3-SNAPSHOT of linea-besu ## 0.1.0 -- Initial build of besu-sequencer-plugins +- Initial build of linea-sequencer - uses 23.10.3-SNAPSHOT as linea-besu version diff --git a/acceptance-tests/build.gradle b/acceptance-tests/build.gradle index 2373e4ff9..2107ff056 100644 --- a/acceptance-tests/build.gradle +++ b/acceptance-tests/build.gradle @@ -55,8 +55,10 @@ tasks.register('acceptanceTests', Test) { } dependencies { - testImplementation project(":arithmetization") + // testImplementation project(":arithmetization") + testImplementation 'net.consensys.linea.zktracer:arithmetization' testImplementation project(":native:compress") + testImplementation project(":sequencer") testImplementation "${besuArtifactGroup}.internal:dsl:$besuVersion" testImplementation "${besuArtifactGroup}:besu-datatypes:$besuVersion" testImplementation "${besuArtifactGroup}.internal:eth:$besuVersion" diff --git a/arithmetization/src/main/java/net/consensys/linea/blockcapture/BlockCapturer.java b/arithmetization/src/main/java/net/consensys/linea/blockcapture/BlockCapturer.java deleted file mode 100644 index 24ea5ea57..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/blockcapture/BlockCapturer.java +++ /dev/null @@ -1,138 +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.blockcapture; - -import java.util.List; - -import com.google.gson.Gson; -import net.consensys.linea.blockcapture.reapers.Reaper; -import net.consensys.linea.zktracer.ConflationAwareOperationTracer; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; -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.internal.Words; -import org.hyperledger.besu.evm.log.Log; -import org.hyperledger.besu.evm.worldstate.WorldUpdater; -import org.hyperledger.besu.evm.worldstate.WorldView; -import org.hyperledger.besu.plugin.data.BlockBody; -import org.hyperledger.besu.plugin.data.BlockHeader; - -public class BlockCapturer implements ConflationAwareOperationTracer { - /** - * The {@link Reaper} will collect all the data that will need to be mimicked to replay the block. - */ - private final Reaper reaper = new Reaper(); - /** - * This keeps a pointer to the initial state (i.e. ) to be used at the end of tracing to store the - * minimal required information to replay the conflation. - */ - private WorldUpdater worldUpdater; - - /** - * Must be called **before** any tracing activity. - * - * @param worldUpdater the state of the world before the conflation is applied - */ - public void setWorld(WorldUpdater worldUpdater) { - this.worldUpdater = worldUpdater; - } - - @Override - public void traceStartConflation(long numBlocksInConflation) {} - - @Override - public void traceEndConflation() {} - - @Override - public void traceStartBlock(BlockHeader blockHeader, BlockBody blockBody) { - this.reaper.enterBlock(blockHeader, blockBody); - } - - @Override - public void traceStartTransaction(WorldView worldView, Transaction transaction) { - this.reaper.enterTransaction(transaction); - } - - @Override - public void traceEndTransaction( - WorldView worldView, - Transaction tx, - boolean status, - Bytes output, - List logs, - long gasUsed, - long timeNs) { - this.reaper.exitTransaction(status); - } - - /** - * This method only bothers with instruction putatively accessing the state as it was at the - * beginning of the conflation. - * - * @param frame the frame - */ - @Override - public void tracePreExecution(MessageFrame frame) { - final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); - - switch (opCode) { - // These access contracts potentially existing before the conflation played out. - case EXTCODESIZE, EXTCODECOPY, EXTCODEHASH -> { - if (frame.stackSize() > 0) { - final Address target = Words.toAddress(frame.getStackItem(0)); - this.reaper.touchAddress(target); - } - } - - // SLOAD may access storage cells whose value was set before the conflation execution. - case SLOAD -> { - if (frame.stackSize() > 0) { - final Account account = frame.getWorldUpdater().get(frame.getRecipientAddress()); - final Address address = account.getAddress(); - final UInt256 key = UInt256.fromBytes(frame.getStackItem(0)); - this.reaper.touchStorage(address, key); - } - } - - // SSTORE needs to know the previous storage value for correct gas computation - case SSTORE -> { - if (frame.stackSize() > 1) { - final Account account = frame.getWorldUpdater().get(frame.getRecipientAddress()); - final Address address = account.getAddress(); - final UInt256 key = UInt256.fromBytes(frame.getStackItem(0)); - this.reaper.touchStorage(address, key); - } - } - - // These access contracts potentially existing before the conflation played out. - case CALL, CALLCODE, DELEGATECALL, STATICCALL -> { - if (frame.stackSize() > 1) { - final Address target = Words.toAddress(frame.getStackItem(1)); - this.reaper.touchAddress(target); - } - } - } - } - - public String toJson() { - Gson gson = new Gson(); - return gson.toJson(this.reaper.collapse(this.worldUpdater)); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/AddressReaper.java b/arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/AddressReaper.java deleted file mode 100644 index 9c6637b0f..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/AddressReaper.java +++ /dev/null @@ -1,53 +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.blockcapture.reapers; - -import java.util.ArrayDeque; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; - -import org.hyperledger.besu.datatypes.Address; - -public class AddressReaper { - private final ArrayDeque> reaped = new ArrayDeque<>(); - - public AddressReaper() { - // “Bedrock” address set for block-level gathering. - this.reaped.addLast(new HashSet<>()); - } - - public void enterTransaction() { - this.reaped.addLast(new HashSet<>()); - } - - public void exitTransaction(boolean success) { - if (!success) { - this.reaped.removeLast(); - } - } - - public void touch(final Address... addresses) { - for (Address address : addresses) { - this.reaped.peekLast().add(address); - } - } - - public Set
collapse() { - return this.reaped.stream().flatMap(Collection::stream).collect(Collectors.toSet()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/Reaper.java b/arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/Reaper.java deleted file mode 100644 index fe458d56c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/Reaper.java +++ /dev/null @@ -1,101 +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.blockcapture.reapers; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import net.consensys.linea.blockcapture.snapshots.AccountSnapshot; -import net.consensys.linea.blockcapture.snapshots.BlockSnapshot; -import net.consensys.linea.blockcapture.snapshots.ConflationSnapshot; -import net.consensys.linea.blockcapture.snapshots.StorageSnapshot; -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldUpdater; -import org.hyperledger.besu.plugin.data.BlockBody; -import org.hyperledger.besu.plugin.data.BlockHeader; - -/** - * The Reaper collect all the information from the state that will be accessed during the execution - * of a conflation. - * - *

This data can than be collapsed into a “replay” ({@link ConflationSnapshot}), i.e. the minimal - * required information to replay a conflation as if it were executed on the blockchain. - */ -public class Reaper { - /** Collect the reads from the state */ - private final StorageReaper storage = new StorageReaper(); - /** Collect the addresses read from the state */ - private final AddressReaper addresses = new AddressReaper(); - /** Collect the blocks within a conflation */ - private final List blocks = new ArrayList<>(); - - public void enterBlock(final BlockHeader header, final BlockBody body) { - this.blocks.add( - BlockSnapshot.of((org.hyperledger.besu.ethereum.core.BlockHeader) header, body)); - this.addresses.touch(header.getCoinbase()); - } - - public void enterTransaction(Transaction tx) { - this.storage.enterTransaction(); - this.addresses.enterTransaction(); - - this.touchAddress(tx.getSender()); - tx.getTo().ifPresent(this::touchAddress); - } - - public void exitTransaction(boolean success) { - this.storage.exitTransaction(success); - this.addresses.exitTransaction(success); - } - - public void touchAddress(final Address address) { - this.addresses.touch(address); - } - - public void touchStorage(final Address address, final UInt256 key) { - this.storage.touch(address, key); - } - - /** - * Uniquify and solidify the accumulated data, then return a {@link ConflationSnapshot}, which - * contains the smallest dataset required to exactly replay the conflation within a test framework - * without requiring access to the whole state. - * - * @param world the state before the conflation execution - * @return a minimal set of information required to replay the conflation within a test framework - */ - public ConflationSnapshot collapse(final WorldUpdater world) { - final List initialAccounts = - this.addresses.collapse().stream() - .flatMap(a -> AccountSnapshot.from(a, world).stream()) - .toList(); - - final List initialStorage = new ArrayList<>(); - for (Map.Entry> e : this.storage.collapse().entrySet()) { - final Address address = e.getKey(); - - e.getValue().stream() - .flatMap(key -> StorageSnapshot.from(address, key, world).stream()) - .forEach(initialStorage::add); - } - - return new ConflationSnapshot(this.blocks, initialAccounts, initialStorage); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/StorageReaper.java b/arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/StorageReaper.java deleted file mode 100644 index 13e50f8ee..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/blockcapture/reapers/StorageReaper.java +++ /dev/null @@ -1,63 +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.blockcapture.reapers; - -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.datatypes.Address; - -/** - * This object gathers all non-reversed accesses to storage values during the execution of a - * conflation, then collapse them into a single mapping of the initial values in these slots. - */ -public class StorageReaper { - private final Deque>> transientStates = new ArrayDeque<>(); - - public void enterTransaction() { - this.transientStates.addLast(new HashMap<>()); - } - - public void exitTransaction(boolean success) { - if (!success) { - this.transientStates.removeLast(); - } - } - - public void touch(final Address address, final UInt256 key) { - this.transientStates.peekLast().computeIfAbsent(address, k -> new HashSet<>()).add(key); - } - - public Map> collapse() { - final Map> r = new HashMap<>(); - - for (var txEntry : this.transientStates) { - for (Map.Entry> addressKeys : txEntry.entrySet()) { - final Address address = addressKeys.getKey(); - - // Use computeIfAbsent instead of put, as we only want to capture the **first** read. - r.computeIfAbsent(address, k -> new HashSet<>()).addAll(addressKeys.getValue()); - } - } - - return r; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/AccessListEntrySnapshot.java b/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/AccessListEntrySnapshot.java deleted file mode 100644 index edd26f254..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/AccessListEntrySnapshot.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.blockcapture.snapshots; - -import java.util.List; - -import org.hyperledger.besu.datatypes.AccessListEntry; - -public record AccessListEntrySnapshot(String address, List storageKeys) { - public static AccessListEntrySnapshot from(AccessListEntry e) { - return new AccessListEntrySnapshot(e.getAddressString(), e.getStorageKeysString()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/AccountSnapshot.java deleted file mode 100644 index f05d0be74..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/AccountSnapshot.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.blockcapture.snapshots; - -import java.util.Optional; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.worldstate.WorldUpdater; - -public record AccountSnapshot(String address, long nonce, String balance, String code) { - public static Optional from(Address address, WorldUpdater world) { - return Optional.ofNullable(world.get(address)) - .map( - account -> - new AccountSnapshot( - address.toHexString(), - account.getNonce(), - account.getBalance().toHexString(), - account.getCode().toHexString())); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/BlockHeaderSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/BlockHeaderSnapshot.java deleted file mode 100644 index 2bfd29271..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/BlockHeaderSnapshot.java +++ /dev/null @@ -1,94 +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.blockcapture.snapshots; - -import java.util.Optional; - -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.datatypes.Quantity; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; -import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; -import org.hyperledger.besu.evm.log.LogsBloomFilter; - -public record BlockHeaderSnapshot( - String parentHash, - String ommersHash, - String coinbase, - String stateRoot, - String transactionRoot, - String receiptsRoot, - String logsBloom, - String difficulty, - long number, - long gasLimit, - long gasUsed, - long timestamp, - String extraData, - String mixHashOrPrevRandao, - long nonce, - Optional baseFee) { - public static BlockHeaderSnapshot from(BlockHeader header) { - return new BlockHeaderSnapshot( - header.getParentHash().toHexString(), - header.getOmmersHash().toHexString(), - header.getCoinbase().toHexString(), - header.getStateRoot().toHexString(), - header.getTransactionsRoot().toHexString(), - header.getReceiptsRoot().toHexString(), - header.getLogsBloom().toHexString(), - header.getDifficulty().toHexString(), - header.getNumber(), - header.getGasLimit(), - header.getGasUsed(), - header.getTimestamp(), - header.getExtraData().toHexString(), - header.getMixHashOrPrevRandao().toHexString(), - header.getNonce(), - header.getBaseFee().map(Quantity::toHexString)); - } - - public BlockHeader toBlockHeader() { - final BlockHeaderBuilder builder = - BlockHeaderBuilder.create() - .parentHash(Hash.fromHexString(this.parentHash)) - .ommersHash(Hash.fromHexString(this.ommersHash)) - .coinbase(Address.fromHexString(this.coinbase)) - .stateRoot(Hash.fromHexString(this.stateRoot)) - .transactionsRoot(Hash.fromHexString(this.transactionRoot)) - .receiptsRoot(Hash.fromHexString(this.receiptsRoot)) - .logsBloom(LogsBloomFilter.fromHexString(this.logsBloom)) - .difficulty(Difficulty.fromHexString(this.difficulty)) - .number(this.number) - .gasLimit(this.gasLimit) - .gasUsed(this.gasUsed) - .timestamp(this.timestamp) - .extraData(Bytes.fromHexString(this.extraData)) - .mixHash(Hash.fromHexString(this.mixHashOrPrevRandao)) - .prevRandao(Bytes32.fromHexString(this.mixHashOrPrevRandao)) - .nonce(this.nonce) - .blockHeaderFunctions(new MainnetBlockHeaderFunctions()); - - this.baseFee.ifPresent(baseFee -> builder.baseFee(Wei.fromHexString(baseFee))); - - return builder.buildBlockHeader(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/BlockSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/BlockSnapshot.java deleted file mode 100644 index 2bfc69303..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/BlockSnapshot.java +++ /dev/null @@ -1,30 +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.blockcapture.snapshots; - -import java.util.List; - -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.plugin.data.BlockBody; - -public record BlockSnapshot(BlockHeaderSnapshot header, List txs) { - public static BlockSnapshot of(final BlockHeader header, final BlockBody body) { - return new BlockSnapshot( - BlockHeaderSnapshot.from(header), - body.getTransactions().stream().map(t -> TransactionSnapshot.of((Transaction) t)).toList()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/ConflationSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/ConflationSnapshot.java deleted file mode 100644 index c7162766e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/ConflationSnapshot.java +++ /dev/null @@ -1,29 +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.blockcapture.snapshots; - -import java.util.List; - -/** - * Contain the minimal set of information to replay a conflation as a unit test without requiring - * access to the whole state. - * - * @param blocks the blocks within the conflation - * @param accounts the accounts whose state will be read during the conflation execution - * @param storage storage cells that will be accessed during the conflation execution - */ -public record ConflationSnapshot( - List blocks, List accounts, List storage) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/StorageSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/StorageSnapshot.java deleted file mode 100644 index 9ab10db78..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/StorageSnapshot.java +++ /dev/null @@ -1,35 +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.blockcapture.snapshots; - -import java.util.Optional; - -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.worldstate.WorldUpdater; - -public record StorageSnapshot(String address, String key, String value) { - public static Optional from( - Address address, UInt256 key, final WorldUpdater world) { - return Optional.ofNullable(world.get(address)) - .map( - account -> - new StorageSnapshot( - address.toHexString(), - key.toHexString(), - account.getStorageValue(key).toHexString())); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/TransactionSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/TransactionSnapshot.java deleted file mode 100644 index 3e999411f..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/blockcapture/snapshots/TransactionSnapshot.java +++ /dev/null @@ -1,122 +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.blockcapture.snapshots; - -import static org.hyperledger.besu.ethereum.core.Transaction.REPLAY_PROTECTED_V_BASE; -import static org.hyperledger.besu.ethereum.core.Transaction.REPLAY_PROTECTED_V_MIN; -import static org.hyperledger.besu.ethereum.core.Transaction.REPLAY_UNPROTECTED_V_BASE; - -import java.math.BigInteger; -import java.util.List; -import java.util.Optional; - -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.DelegatingBytes; -import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; -import org.hyperledger.besu.datatypes.AccessListEntry; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Quantity; -import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.evm.internal.Words; - -public record TransactionSnapshot( - String r, - String s, - String v, - TransactionType type, - String sender, - Optional to, - long nonce, - String value, - String payload, - Optional gasPrice, - Optional maxPriorityFeePerGas, - Optional maxFeePerGas, - Optional maxFeePerBlobGas, - long gasLimit, - BigInteger chainId, - Optional> accessList) { - public static final BigInteger CHAIN_ID = BigInteger.valueOf(1337); - - public static TransactionSnapshot of(Transaction tx) { - return new TransactionSnapshot( - tx.getS().toString(16), - tx.getR().toString(16), - tx.getType() == TransactionType.FRONTIER - ? tx.getV().toString(16) - : tx.getYParity().toString(16), - tx.getType(), - tx.getSender().toHexString(), - tx.getTo().map(DelegatingBytes::toHexString), - tx.getNonce(), - tx.getValue().toHexString(), - tx.getPayload().toHexString(), - tx.getGasPrice().map(Quantity::toHexString), - tx.getMaxPriorityFeePerGas().map(Quantity::toHexString), - tx.getMaxFeePerGas().map(Quantity::toHexString), - tx.getMaxFeePerBlobGas().map(Quantity::toHexString), - tx.getGasLimit(), - tx.getChainId().orElse(CHAIN_ID), - tx.getAccessList().map(l -> l.stream().map(AccessListEntrySnapshot::from).toList())); - } - - public Transaction toTransaction() { - BigInteger r = Bytes.fromHexStringLenient(this.r).toUnsignedBigInteger(); - BigInteger s = Bytes.fromHexStringLenient(this.s).toUnsignedBigInteger(); - BigInteger v = Bytes.fromHexStringLenient(this.v).toUnsignedBigInteger(); - - if (this.type == TransactionType.FRONTIER) { - if (v.compareTo(REPLAY_PROTECTED_V_MIN) > 0) { - v = v.subtract(REPLAY_PROTECTED_V_BASE).subtract(chainId.multiply(BigInteger.TWO)); - } else { - v = v.subtract(REPLAY_UNPROTECTED_V_BASE); - } - } - - final var tx = - Transaction.builder() - .type(this.type) - .sender(Address.fromHexString(this.sender)) - .nonce(this.nonce) - .value(Wei.fromHexString(this.value)) - .payload(Bytes.fromHexString(this.payload)) - .chainId(this.chainId) - .gasLimit(this.gasLimit) - .signature( - SignatureAlgorithmFactory.getInstance().createSignature(r, s, v.byteValueExact())); - - this.to.ifPresent(to -> tx.to(Words.toAddress(Bytes.fromHexString(to)))); - this.gasPrice.ifPresent(gasPrice -> tx.gasPrice(Wei.fromHexString(gasPrice))); - this.maxPriorityFeePerGas.ifPresent( - maxPriorityFeePerGas -> tx.maxPriorityFeePerGas(Wei.fromHexString(maxPriorityFeePerGas))); - this.maxFeePerGas.ifPresent(maxFeePerGas -> tx.maxFeePerGas(Wei.fromHexString(maxFeePerGas))); - this.maxFeePerBlobGas.ifPresent( - maxFeePerBlobGas -> tx.maxFeePerBlobGas(Wei.fromHexString(maxFeePerBlobGas))); - this.accessList.ifPresent( - l -> - tx.accessList( - l.stream() - .map( - e -> - AccessListEntry.createAccessListEntry( - Address.fromHexString(e.address()), e.storageKeys())) - .toList())); - - return tx.build(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/corset/CorsetValidator.java b/arithmetization/src/main/java/net/consensys/linea/corset/CorsetValidator.java deleted file mode 100644 index 98ace1d3e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/corset/CorsetValidator.java +++ /dev/null @@ -1,162 +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.corset; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.IOUtils; - -@Slf4j -public class CorsetValidator { - public record Result(boolean isValid, File traceFile, String corsetOutput) {} - - private static final String ZK_EVM_RELATIVE_PATH = "/zkevm-constraints/zkevm.bin"; - - private String defaultZkEvm = null; - private String corsetBin; - - public CorsetValidator() { - initCorset(); - initDefaultZkEvm(); - } - - public Result validate(final Path filename) throws RuntimeException { - return validate(filename, defaultZkEvm); - } - - public Result validate(final Path filename, final String zkEvmBin) throws RuntimeException { - final Process corsetValidationProcess; - try { - corsetValidationProcess = - new ProcessBuilder( - corsetBin, - "check", - "-T", - filename.toAbsolutePath().toString(), - "-q", - "-r", - "-d", - "-s", - "-t", - Optional.ofNullable(System.getenv("CORSET_THREADS")).orElse("2"), - zkEvmBin) - .redirectInput(ProcessBuilder.Redirect.INHERIT) - .redirectErrorStream(true) - .start(); - } catch (IOException e) { - log.error("Corset validation has thrown an exception: %s".formatted(e.getMessage())); - throw new RuntimeException(e); - } - - final String corsetOutput; - try { - corsetOutput = - IOUtils.toString(corsetValidationProcess.getInputStream(), Charset.defaultCharset()); - } catch (IOException e) { - log.error( - "Error while catching output corsetValidationProcess: %s".formatted(e.getMessage())); - throw new RuntimeException(e); - } - - try { - corsetValidationProcess.waitFor(5, TimeUnit.SECONDS); - } catch (InterruptedException e) { - log.error("Timeout while validating trace file: %s".formatted(e.getMessage())); - throw new RuntimeException(e); - } - - if (corsetValidationProcess.exitValue() != 0) { - log.error("Validation failed: %s".formatted(corsetOutput)); - return new Result(false, filename.toFile(), corsetOutput); - } - - return new Result(true, filename.toFile(), corsetOutput); - } - - private void initCorset() { - final Process whichCorsetProcess; - - try { - whichCorsetProcess = Runtime.getRuntime().exec(new String[] {"which", "corset"}); - } catch (IOException e) { - log.error("Error while searching for corset: %s".formatted(e.getMessage())); - throw new RuntimeException(e); - } - - final String whichCorsetProcessOutput; - try { - whichCorsetProcessOutput = - IOUtils.toString(whichCorsetProcess.getInputStream(), Charset.defaultCharset()); - } catch (IOException e) { - log.error("Error while catching output whichCorsetProcess: %s".formatted(e.getMessage())); - throw new RuntimeException(e); - } - - try { - whichCorsetProcess.waitFor(5, TimeUnit.SECONDS); - } catch (InterruptedException e) { - log.error("Timeout while searching for corset: %s".formatted(e.getMessage())); - throw new RuntimeException(e); - } - - if (whichCorsetProcess.exitValue() == 0) { - corsetBin = whichCorsetProcessOutput.trim(); - return; - } - - log.warn("Could not find corset executable: %s".formatted(whichCorsetProcessOutput)); - - final String homePath = System.getenv("HOME"); - corsetBin = homePath + "/.cargo/bin/corset"; - log.warn("Trying to use default corset path: %s".formatted(corsetBin)); - - if (!Files.isExecutable(Path.of(corsetBin))) { - throw new RuntimeException("Corset is not executable: %s".formatted(corsetBin)); - } - } - - private void initDefaultZkEvm() { - final String currentDir; - - try { - currentDir = Path.of(".").toRealPath().toString(); - } catch (final IOException e) { - log.error("Error while getting current directory: %s".formatted(e.getMessage())); - throw new RuntimeException(e); - } - - final String zkEvmBinInCurrentDir = currentDir + ZK_EVM_RELATIVE_PATH; - if (new File(zkEvmBinInCurrentDir).exists()) { - defaultZkEvm = zkEvmBinInCurrentDir; - return; - } - - final String zkEvmBinInDirAbove = currentDir + "/.." + ZK_EVM_RELATIVE_PATH; - if (new File(zkEvmBinInDirAbove).exists()) { - defaultZkEvm = zkEvmBinInDirAbove; - return; - } - - log.warn("Could not find default path for zkevm.bin"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ColumnHeader.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ColumnHeader.java deleted file mode 100644 index 5271ef900..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ColumnHeader.java +++ /dev/null @@ -1,41 +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; - -import com.google.common.base.Preconditions; - -public record ColumnHeader(String name, int bytesPerElement, int length) { - public int dataSize() { - return this.length() * this.bytesPerElement(); - } - - public int headerSize() { - return 2 - + // i16: name size - this.name.length() // [u8]: name bytes - + 1 // bytes per element - + 4; // element count - } - - public long cumulatedSize() { - return this.headerSize() + this.dataSize(); - } - - public static ColumnHeader make(String name, int bytesPerElement, int length) { - Preconditions.checkArgument(name.length() < Short.MAX_VALUE, "column name is too long"); - return new ColumnHeader(name, bytesPerElement, length); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ConflationAwareOperationTracer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ConflationAwareOperationTracer.java deleted file mode 100644 index b9141d692..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ConflationAwareOperationTracer.java +++ /dev/null @@ -1,35 +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; - -import org.hyperledger.besu.plugin.services.tracer.BlockAwareOperationTracer; - -/** - * An extended operation tracer that can trace the start and end of a number of blocks in - * conflation. - */ -public interface ConflationAwareOperationTracer extends BlockAwareOperationTracer { - - /** - * Trace the start of conflation for a number of blocks. - * - * @param numBlocksInConflation blocks in conflation - */ - void traceStartConflation(final long numBlocksInConflation); - - /** Trace the end of conflation for a number of blocks. */ - void traceEndConflation(); -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTrace.java deleted file mode 100644 index ae0358852..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTrace.java +++ /dev/null @@ -1,46 +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; - -import java.math.BigInteger; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.SneakyThrows; -import net.consensys.linea.zktracer.json.BigIntegerSerializer; -import net.consensys.linea.zktracer.json.JsonConverter; -import net.consensys.linea.zktracer.json.NumericBooleanSerializer; - -@JsonPropertyOrder({"BlockRlp", "ParentRootHash", "TxNumber", "Pc", "Op", "shf", "shfRT"}) -public record ZkTrace(@JsonAnyGetter Map traceResults) { - - private static final JsonConverter JSON_CONVERTER = - JsonConverter.builder() - .addCustomSerializer(Boolean.class, new NumericBooleanSerializer()) - .addCustomSerializer(BigInteger.class, new BigIntegerSerializer()) - .build(); - - /** - * Converts traces to a JSON string. - * - * @return a trace as a JSON string - */ - @SneakyThrows - public String toJson() { - return JSON_CONVERTER.toJson(new ZkTrace(traceResults)); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java deleted file mode 100644 index 747a18032..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java +++ /dev/null @@ -1,244 +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; - -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.config.LineaL1L2BridgeConfiguration; -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.opcode.OpCodes; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.toml.Toml; -import org.apache.tuweni.toml.TomlTable; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.datatypes.PendingTransaction; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.gascalculator.GasCalculator; -import org.hyperledger.besu.evm.gascalculator.LondonGasCalculator; -import org.hyperledger.besu.evm.log.Log; -import org.hyperledger.besu.evm.operation.Operation; -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; - -@Slf4j -public class ZkTracer implements ConflationAwareOperationTracer { - /** The {@link GasCalculator} used in this version of the arithmetization */ - public static final GasCalculator gasCalculator = new LondonGasCalculator(); - - @Getter private final Hub hub; - private final Map spillings = new HashMap<>(); - private Hash hashOfLastTransactionTraced = Hash.EMPTY; - - public ZkTracer() { - this(LineaL1L2BridgeConfiguration.EMPTY); - } - - public ZkTracer(final LineaL1L2BridgeConfiguration bridgeConfiguration) { - this.hub = new Hub(bridgeConfiguration.contract(), bridgeConfiguration.topic()); - - // Load opcodes configured in src/main/resources/opcodes.yml. - OpCodes.load(); - - // Load spillings configured in src/main/resources/spillings.toml. - try { - final TomlTable table = - Toml.parse(getClass().getClassLoader().getResourceAsStream("spillings.toml")) - .getTable("spillings"); - table.toMap().keySet().forEach(k -> spillings.put(k, Math.toIntExact(table.getLong(k)))); - - for (Module m : this.hub.getModulesToCount()) { - if (!this.spillings.containsKey(m.moduleKey())) { - throw new IllegalStateException( - "Spilling for module " + m.moduleKey() + " not defined in spillings.toml"); - } - } - } catch (final Exception e) { - throw new RuntimeException(e); - } - } - - public Path writeToTmpFile() { - try { - final Path traceFile = Files.createTempFile(null, ".lt"); - this.writeToFile(traceFile); - return traceFile; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public Path writeToTmpFile(final Path rootDir) { - try { - final Path traceFile = Files.createTempFile(rootDir, null, ".lt"); - this.writeToFile(traceFile); - return traceFile; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public void writeToFile(final Path filename) { - final List modules = this.hub.getModulesToTrace(); - final List traceMap = - modules.stream().flatMap(m -> m.columnsHeaders().stream()).toList(); - final int headerSize = traceMap.stream().mapToInt(ColumnHeader::headerSize).sum() + 4; - - try (RandomAccessFile file = new RandomAccessFile(filename.toString(), "rw")) { - file.setLength(traceMap.stream().mapToLong(ColumnHeader::cumulatedSize).sum()); - MappedByteBuffer header = - file.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, headerSize); - - header.putInt(traceMap.size()); - for (ColumnHeader h : traceMap) { - final String name = h.name(); - header.putShort((short) name.length()); - header.put(name.getBytes()); - header.put((byte) h.bytesPerElement()); - header.putInt(h.length()); - } - long offset = headerSize; - for (Module m : modules) { - List buffers = new ArrayList<>(); - for (ColumnHeader columnHeader : m.columnsHeaders()) { - final int columnLength = columnHeader.dataSize(); - buffers.add(file.getChannel().map(FileChannel.MapMode.READ_WRITE, offset, columnLength)); - offset += columnLength; - } - m.commit(buffers); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void traceStartConflation(final long numBlocksInConflation) { - hub.traceStartConflation(numBlocksInConflation); - } - - @Override - public void traceEndConflation() { - this.hub.traceEndConflation(); - } - - @Override - public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) { - this.hub.traceStartBlock(processableBlockHeader); - } - - @Override - public void traceStartBlock(final BlockHeader blockHeader, final BlockBody blockBody) { - this.hub.traceStartBlock(blockHeader); - } - - @Override - public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) { - this.hub.traceEndBlock(blockHeader, blockBody); - } - - @Override - public void tracePrepareTransaction(WorldView worldView, Transaction transaction) { - hashOfLastTransactionTraced = transaction.getHash(); - this.hub.traceStartTx(worldView, transaction); - } - - @Override - public void traceEndTransaction( - WorldView worldView, - Transaction tx, - boolean status, - Bytes output, - List logs, - long gasUsed, - long timeNs) { - this.hub.traceEndTx(worldView, tx, status, output, logs, gasUsed); - } - - @Override - public void tracePreExecution(final MessageFrame frame) { - if (frame.getCode().getSize() > 0) { - this.hub.tracePreOpcode(frame); - } - } - - @Override - public void tracePostExecution(MessageFrame frame, Operation.OperationResult operationResult) { - if (frame.getCode().getSize() > 0) { - this.hub.tracePostExecution(frame, operationResult); - } - } - - @Override - public void traceContextEnter(MessageFrame frame) { - // We only want to trigger on creation of new contexts, not on re-entry in - // existing contexts - if (frame.getState() == MessageFrame.State.NOT_STARTED) { - this.hub.traceContextEnter(frame); - } - } - - @Override - public void traceContextReEnter(MessageFrame frame) { - this.hub.traceContextReEnter(frame); - } - - @Override - public void traceContextExit(MessageFrame frame) { - this.hub.traceContextExit(frame); - } - - /** When called, erase all tracing related to the last included transaction. */ - public void popTransaction(final PendingTransaction pendingTransaction) { - if (hashOfLastTransactionTraced.equals(pendingTransaction.getTransaction().getHash())) { - hub.popTransaction(); - } - } - - public Map getModulesLineCount() { - final HashMap modulesLineCount = new HashMap<>(); - hub.getModulesToCount() - .forEach( - m -> - modulesLineCount.put( - m.moduleKey(), - m.lineCount() - + Optional.ofNullable(this.spillings.get(m.moduleKey())) - .orElseThrow( - () -> - new IllegalStateException( - "Module " - + m.moduleKey() - + " not found in spillings.toml")))); - modulesLineCount.put("BLOCK_TX", hub.cumulatedTxCount()); - return modulesLineCount; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseBytes.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseBytes.java deleted file mode 100644 index 8d8e4c767..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseBytes.java +++ /dev/null @@ -1,148 +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.bytestheta; - -import lombok.EqualsAndHashCode; -import net.consensys.linea.zktracer.types.Bytes16; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.bytes.MutableBytes32; - -/** - * The `BaseBytes` class provides a base implementation for manipulating 256-bit (32-byte) blocks of - * data. - */ -@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) -public class BaseBytes implements HighLowBytes { - /** The size in bytes of the high and low sections of the 256-bit block. */ - private static final int LOW_HIGH_SIZE = 16; - /** - * The mutable `Bytes32` object that stores the 256-bit block of data. Equals and hashCode must - * only be computed on the numeric value wrapped by this class, so that sets of operations - * parameterized by these values hash correctly. - */ - @EqualsAndHashCode.Include protected MutableBytes32 bytes32; - - /** - * This static factory method returns a new instance of the `BaseBytes` class, initialized with - * the given `arg` parameter. - * - * @param arg The `Bytes32` parameter used to initialize the new `BaseBytes` instance. - * @return A new instance of the `BaseBytes` class, initialized with the given `arg` parameter. - */ - public static BaseBytes fromBytes32(Bytes32 arg) { - return new BaseBytes(arg); - } - - /** - * The constructor for the `BaseBytes` class. It takes a parameter of type `Bytes32` called `arg`, - * which is used to initialize the object. - * - * @param arg The `Bytes32` parameter used to initialize the object. - */ - protected BaseBytes(final Bytes32 arg) { - bytes32 = arg.mutableCopy(); - } - - /** - * Returns a new `Bytes16` object that is the high section (first 16 bytes) of the bytes32` - * instance variable. - * - * @return a wrapped {@link Bytes16} instance. - */ - @Override - public Bytes16 getHigh() { - return Bytes16.wrap(bytes32.slice(0, LOW_HIGH_SIZE)); - } - - /** - * Returns a new `Bytes16` object that is the low section (last 16 bytes) of the `bytes32` - * instance variable. - * - * @return a wrapped {@link Bytes16} instance. - */ - @Override - public Bytes16 getLow() { - return Bytes16.wrap(bytes32.slice(LOW_HIGH_SIZE)); - } - - /** - * Returns the byte at the specified `index` in the `bytes32` instance variable. - * - * @param index The index of the byte to be returned. - * @return The byte at the specified index in the `bytes32` instance variable. - */ - public byte getByte(int index) { - return bytes32.get(index); - } - - /** - * Returns the `Bytes32` object that stores the 256-bit block of data. - * - * @return The `Bytes32` object that stores the 256-bit block of data. - */ - public Bytes32 getBytes32() { - return bytes32; - } - - /** - * Returns `true` if the `bytes32` instance variable contains all zeros, and `false` otherwise. - * - * @return `true` if the `bytes32` instance variable contains all zeros, and `false` otherwise. - */ - public boolean isZero() { - return bytes32.isZero(); - } - - /** - * Add operation on an instance of {@link UnsignedByte}. - * - * @param other right hand side of and operation. - * @return the result of add operation as an instance of {@link UnsignedByte}. - */ - public BaseBytes and(final BaseBytes other) { - return new BaseBytes(bytes32.and(other.bytes32)); - } - - /** - * Or operation on an instance of {@link UnsignedByte}. - * - * @param other right hand side of or operation. - * @return the result of or operation as an instance of {@link UnsignedByte}. - */ - public BaseBytes or(final BaseBytes other) { - return new BaseBytes(bytes32.or(other.bytes32)); - } - - /** - * Xor operation on an instance of {@link UnsignedByte}. - * - * @param other right hand side of xor operation. - * @return the result of xor operation as an instance of {@link UnsignedByte}. - */ - public BaseBytes xor(final BaseBytes other) { - return new BaseBytes(bytes32.xor(other.bytes32)); - } - - /** - * Not operation on an instance of {@link UnsignedByte}. - * - * @return the result of not operation as an instance of {@link UnsignedByte}. - */ - public BaseBytes not() { - return new BaseBytes(bytes32.not()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseTheta.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseTheta.java deleted file mode 100644 index 8307c0907..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseTheta.java +++ /dev/null @@ -1,133 +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.bytestheta; - -import net.consensys.linea.zktracer.types.Bytes16; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; - -/** - * Represents a BaseTheta data structure, which is an extension of BytesArray, with support for high - * and low bytes' manipulation. It is organized as an array of 4 Bytes instances, each containing 8 - * bytes of a Bytes32 input. - */ -public class BaseTheta extends BytesArray implements HighLowBytes { - - /** - * Constructs a new BaseTheta instance by slicing a given Bytes32 into 4 Bytes instances. - * - * @param arg A Bytes32 input. - */ - public BaseTheta(final Bytes32 arg) { - super(arg); - - for (int k = 0; k < 4; k++) { - Bytes bytes = arg.slice(8 * k, 8); - set((3 - k), bytes); - } - } - - /** - * Creates a new BaseTheta instance from a given Bytes32 input. - * - * @param arg A Bytes32 input. - * @return A new BaseTheta instance. - */ - public static BaseTheta fromBytes32(Bytes32 arg) { - return new BaseTheta(arg); - } - - /** - * Returns a Bytes32 instance representing the concatenated bytes in the BaseTheta. - * - * @return A Bytes32 instance. - */ - public Bytes32 getBytes32() { - return Bytes32.wrap( - Bytes.concatenate(bytesArray[0], bytesArray[1], bytesArray[2], bytesArray[3])); - } - - /** - * Returns a new `Bytes16` object that is the concatenation of the third and second 64-bit - * sections of the `bytes32` instance variable. - * - * @return A new `Bytes16` object that is the concatenation of the third and second 64-bit - * sections of the `bytes32` instance variable. - */ - @Override - public Bytes16 getHigh() { - return Bytes16.wrap(Bytes.concatenate(bytesArray[3], bytesArray[2])); - } - - /** - * Returns a new `Bytes16` object that is the concatenation of the first and second 64-bit - * sections of the `bytes32` instance variable. - * - * @return A new `Bytes16` object that is the concatenation of the first and second 64-bit - * sections of the `bytes32` instance variable. - */ - @Override - public Bytes16 getLow() { - return Bytes16.wrap(Bytes.concatenate(bytesArray[1], bytesArray[0])); - } - - /** - * Returns the byte at the specified position within the specified Bytes instance in the array. - * - * @param i The index of the Bytes instance. - * @param j The index of the byte within the Bytes instance. - * @return The byte at the specified position. - */ - public byte get(final int i, final int j) { - return bytesArray[i].get(j); - } - - /** - * Returns a range of bytes from a specified Bytes instance within the array. - * - * @param i The index of the Bytes instance. - * @param start The start index of the range (inclusive). - * @param length The length of the range. - * @return A new Bytes instance containing the specified range of bytes. - */ - public Bytes getRange(final int i, final int start, final int length) { - return bytesArray[i].slice(start, length); - } - - /** - * Sets the byte at the specified position within the specified Bytes instance in the array. - * - * @param i The index of the Bytes instance. - * @param j The index of the byte within the Bytes instance. - * @param b The byte to be set. - */ - public void set(int i, int j, byte b) { - bytesArray[i].set(j, b); - } - - // set the whole chunk of bytes at the given index. - // assumes index is one of 0,1,2,3 - // assumes length of bytes is 8 - public void setChunk(int index, Bytes bytes) { - set(index, bytes); - } - - @Override - public String toString() { - return "hi=%s, lo=%s\n 0 1 2 3\n %s %s %s %s " - .formatted(getHigh(), getLow(), get(0), get(1), get(2), get(3)); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BytesArray.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BytesArray.java deleted file mode 100644 index c2f3d218b..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BytesArray.java +++ /dev/null @@ -1,124 +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.bytestheta; - -import static com.google.common.base.Preconditions.checkArgument; - -import java.util.Arrays; - -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.bytes.MutableBytes; - -/** Represents an array of mutable byte arrays. */ -public class BytesArray { - - /** The internal array of MutableBytes. */ - final MutableBytes[] bytesArray; - - /** - * Constructs a BytesArray from a given two-dimensional byte array. - * - * @param bytes a two-dimensional byte array - */ - public BytesArray(final byte[][] bytes) { - int arraySize = bytes.length; - bytesArray = new MutableBytes[arraySize]; - - for (int i = 0; i < arraySize; i++) { - bytesArray[i] = MutableBytes.wrap(bytes[i]); - } - } - - /** - * Constructs a BytesArray with a specified size and initializes it with zeros. - * - * @param size the size of the BytesArray - */ - public BytesArray(int size) { - bytesArray = new MutableBytes[size]; - Arrays.fill(bytesArray, MutableBytes.of(0, 0, 0, 0, 0, 0, 0, 0)); - } - - /** - * Returns the size of the BytesArray. - * - * @return the size of the BytesArray - */ - public int size() { - return bytesArray.length; - } - - /** - * Constructs a BytesArray from a given Bytes32 object. - * - * @param bytes32 a Bytes32 object - */ - public BytesArray(Bytes32 bytes32) { - bytesArray = new MutableBytes[4]; - - for (int i = 0; i < 4; i++) { - bytesArray[i] = MutableBytes.wrap(bytes32.slice(i * 8, 8).toArray()); - } - } - - /** - * Retrieves a MutableBytes object at the specified index. - * - * @param index the index of the MutableBytes object - * @return the MutableBytes object at the specified index - */ - public MutableBytes get(int index) { - return bytesArray[index]; - } - - /** - * Sets a new Bytes value at the specified index. - * - * @param index the index of the MutableBytes object to be replaced - * @param bytes the new Bytes value - */ - public void set(int index, Bytes bytes) { - checkArgument(bytes.size() == 8); - bytesArray[index] = MutableBytes.wrap(bytes.toArray()); - } - - /** - * Returns the internal array of MutableBytes objects. - * - * @return the internal array of MutableBytes objects - */ - public Bytes[] getBytesArray() { - return bytesArray; - } - - /** - * Retrieves a range of Bytes objects from the specified start index to the end index. - * - * @param start the start index of the range - * @param end the end index of the range - * @return an array of Bytes objects in the specified range - */ - public Bytes[] getBytesRange(final int start, final int end) { - int rangeSize = end - start + 1; - Bytes[] bytes = new Bytes[rangeSize]; - for (int i = 0; i < rangeSize; i++) { - bytes[i] = get(start + i); - } - - return bytes; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/HighLowBytes.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/HighLowBytes.java deleted file mode 100644 index 5f75a91cd..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/HighLowBytes.java +++ /dev/null @@ -1,35 +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.bytestheta; - -import org.apache.tuweni.bytes.Bytes; - -/** Provides high and low parts of a {@link Bytes} object. */ -public interface HighLowBytes { - /** - * Returns the high part of the bytes object. - * - * @return the high part of the bytes object - */ - Bytes getHigh(); - - /** - * Returns the low part of the bytes object. - * - * @return the low part of the bytes object - */ - Bytes getLow(); -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/ModuleOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/ModuleOperation.java deleted file mode 100644 index d2efc5a20..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/ModuleOperation.java +++ /dev/null @@ -1,35 +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.container; - -/** - * Represents an atomic operation within a module. This class is used to automatically cache the - * line counts of these operations for each transaction. - */ -public abstract class ModuleOperation { - /** the number of lines this operation will generate within its module trace */ - private int lineCount = -1; - - protected abstract int computeLineCount(); - - public int lineCount() { - if (this.lineCount == -1) { - this.lineCount = this.computeLineCount(); - } - - return this.lineCount; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/StackedContainer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/StackedContainer.java deleted file mode 100644 index edf3fd245..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/StackedContainer.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.container; - -/** - * A stacked container must behave as the container it emulates, all the while being able to enter - * nested modification contexts, that can be transparently reverted. - */ -public interface StackedContainer { - /** Enter a new modification context. */ - void enter(); - - /** Erase the modifications brought while in the latest modification context. */ - void pop(); -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/CountedList.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/CountedList.java deleted file mode 100644 index 315a3cb5d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/CountedList.java +++ /dev/null @@ -1,118 +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.container.stacked.list; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; - -import net.consensys.linea.zktracer.container.ModuleOperation; - -class CountedList extends ArrayList { - boolean countDirty = true; - int count = 0; - - public CountedList() { - super(); - } - - public CountedList(int initialCapacity) { - super(initialCapacity); - } - - @Override - public boolean add(E e) { - this.countDirty = true; - return super.add(e); - } - - @Override - public E set(int index, E element) { - this.countDirty = true; - return super.set(index, element); - } - - @Override - public E remove(int index) { - this.countDirty = true; - return super.remove(index); - } - - @Override - public boolean remove(Object o) { - this.countDirty = true; - return super.remove(o); - } - - @Override - public boolean addAll(Collection c) { - this.countDirty = true; - return super.addAll(c); - } - - @Override - public boolean addAll(int index, Collection c) { - this.countDirty = true; - return super.addAll(index, c); - } - - @Override - protected void removeRange(int fromIndex, int toIndex) { - this.countDirty = true; - super.removeRange(fromIndex, toIndex); - } - - @Override - public boolean removeAll(Collection c) { - this.countDirty = true; - return super.removeAll(c); - } - - @Override - public boolean retainAll(Collection c) { - this.countDirty = true; - return super.retainAll(c); - } - - @Override - public boolean removeIf(Predicate filter) { - this.countDirty = true; - return super.removeIf(filter); - } - - @Override - public void replaceAll(UnaryOperator operator) { - this.countDirty = true; - super.replaceAll(operator); - } - - public E getLast() { - return this.get(this.size() - 1); - } - - int lineCount() { - if (this.countDirty) { - this.count = 0; - for (ModuleOperation op : this) { - this.count += op.lineCount(); - } - this.countDirty = false; - } - - return this.count; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/StackedList.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/StackedList.java deleted file mode 100644 index 4028202d8..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/list/StackedList.java +++ /dev/null @@ -1,390 +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.container.stacked.list; - -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import java.util.NoSuchElementException; - -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.container.StackedContainer; -import org.jetbrains.annotations.NotNull; - -/** - * Implements a system of nested lists behaving as a single one, where the current context - * modification can transparently be dropped. - * - * @param the type of elements stored in the list - */ -public class StackedList implements List, StackedContainer { - - private final LinkedList> lists = new LinkedList<>(); - /** The cached number of elements in this container */ - private int totalSize; - - @Override - public String toString() { - StringBuilder r = new StringBuilder(); - r.append("[["); - for (var l : this.lists) { - r.append(l.toString()); - } - r.append("]]"); - return r.toString(); - } - - @Override - public void enter() { - this.lists.addLast(new CountedList<>()); - } - - public void enter(int initialCapacity) { - this.lists.addLast(new CountedList<>(initialCapacity)); - } - - public E getLast() { - return this.lists.getLast().getLast(); - } - - @Override - public void pop() { - if (this.lists.isEmpty()) { - throw new RuntimeException("asymmetric pop"); - } - this.totalSize -= this.lists.removeLast().size(); - } - - @Override - public int size() { - return this.totalSize; - } - - public int lineCount() { - int sum = 0; - // Deliberate use of old-style for loops out of performances concerns - for (int i = 0; i < this.lists.size(); i++) { - sum += this.lists.get(i).lineCount(); - } - return sum; - } - - @Override - public boolean isEmpty() { - return this.totalSize == 0; - } - - @Override - public boolean contains(Object o) { - for (CountedList l : this.lists) { - if (l.contains(o)) { - return true; - } - } - - return false; - } - - @NotNull - @Override - public Iterator iterator() { - return new StackedListIterator<>(this); - } - - @NotNull - @Override - public Object[] toArray() { - throw new UnsupportedOperationException("toArray is not supported"); - } - - @NotNull - @Override - public T[] toArray(@NotNull T[] a) { - throw new UnsupportedOperationException("toArray is not supported"); - } - - @Override - public boolean add(E e) { - this.totalSize++; - return this.lists.getLast().add(e); - } - - @Override - public boolean remove(Object o) { - throw new UnsupportedOperationException("remove not supported"); - } - - @Override - public boolean containsAll(@NotNull Collection c) { - for (var x : c) { - if (!this.contains(x)) { - return false; - } - } - return true; - } - - @Override - public boolean addAll(@NotNull Collection c) { - boolean r = false; - for (var x : c) { - r |= this.add(x); - } - return r; - } - - @Override - public boolean addAll(int index, @NotNull Collection c) { - throw new UnsupportedOperationException("addAll(int) not supported"); - } - - @Override - public boolean removeAll(@NotNull Collection c) { - boolean r = false; - for (var x : c) { - r |= this.remove(x); - } - return r; - } - - @Override - public boolean retainAll(@NotNull Collection c) { - throw new UnsupportedOperationException("retainAll not supported"); - } - - @Override - public void clear() { - this.lists.clear(); - this.totalSize = 0; - } - - @Override - public E get(int i) { - for (CountedList list : this.lists) { - if (i >= list.size()) { - i -= list.size(); - } else { - return list.get(i); - } - } - return null; - } - - @Override - public E set(int index, E element) { - throw new UnsupportedOperationException("set not supported"); - } - - @Override - public void add(int index, E element) { - throw new UnsupportedOperationException("add(int) not supported"); - } - - @Override - public E remove(int index) { - throw new UnsupportedOperationException("remove not supported"); - } - - @Override - public int indexOf(Object o) { - int i = 0; - for (List l : this.lists) { - final int ii = l.indexOf(o); - if (ii != -1) { - return i + ii; - } - i += l.size(); - } - return -1; - } - - @Override - public int lastIndexOf(Object o) { - throw new UnsupportedOperationException("lastIndexOf not supported"); - } - - @NotNull - @Override - public ListIterator listIterator() { - return new StackedListIterator<>(this); - } - - @NotNull - @Override - public ListIterator listIterator(int index) { - throw new UnsupportedOperationException("listIterator(int) not supported"); - } - - @NotNull - @Override - public List subList(int fromIndex, int toIndex) { - throw new UnsupportedOperationException("subList not supported"); - } - - private static class StackedListIterator - implements Iterator, ListIterator { - private final StackedList sl; - /** Position of the iterator in the list of lists */ - private int head = 0; - /** Position of the iterator within the current list, i.e. this.sl.lists[head] */ - private int offset = -1; - - StackedListIterator(StackedList lists) { - this.sl = lists; - } - - private List list() { - if (sl.lists.isEmpty()) { - return List.of(); - } - return this.sl.lists.get(this.head); - } - - private List list(int i) { - return this.sl.lists.get(i); - } - - F read() { - return this.sl.lists.get(head).get(this.offset); - } - - int toIndex() { - int idx = 0; - for (int i = 0; i < this.head; i++) { - idx += this.list(i).size(); - } - return idx + this.offset; - } - - boolean done() { - return this.head >= this.sl.lists.size() - 1 && this.offset >= this.list().size(); - } - - @Override - public boolean hasNext() { - // First check if the current list is done for - if (offset < this.list().size() - 1) { - return true; - } - // Then check for a next non-empty list - for (int i = this.head + 1; i < this.sl.lists.size(); i++) { - if (!this.list(i).isEmpty()) { - return true; - } - } - // We're empty - return false; - } - - @Override - public F next() { - // If we are not yet at the end of the current list, return the natural next element - if (offset < this.list().size() - 1) { - this.offset++; - return this.read(); - } - - this.head++; - // Otherwise, jump to the next non-empty list if we can - for (int i = head; i < this.sl.lists.size(); i++) { - if (!this.list(i).isEmpty()) { - this.head = i; - this.offset = 0; - return this.read(); - } - } - - this.head = this.sl.lists.size() - 1; - this.offset = this.list().size() - 1; - throw new NoSuchElementException(); - } - - @Override - public boolean hasPrevious() { - if (offset > 0) { - return true; - } - - if (head > 0) { - for (int i = head - 1; i >= 0; i--) { - if (!this.list(i).isEmpty()) { - return true; - } - } - } - - return false; - } - - @Override - public F previous() { - // If we are not yet at the very beginning of the current list, return the natural previous - // element - if (offset > 0) { - this.offset--; - return this.read(); - } - - // Otherwise, jump to the previous non-empty list if we can - for (int i = head - 1; i >= 0; i--) { - if (!this.list(i).isEmpty()) { - this.head = i; - this.offset = this.list().size() - 1; - return this.read(); - } - } - - this.head = 0; - this.offset = 0; - return null; - } - - @Override - public int nextIndex() { - final int idx = this.toIndex(); - if (this.done()) { - return idx; - } - return idx + 1; - } - - @Override - public int previousIndex() { - final int idx = this.toIndex(); - if (idx > 0) { - return idx - 1; - } - return 0; - } - - @Override - public void remove() { - throw new UnsupportedOperationException("remove not supported"); - } - - @Override - public void set(F e) { - this.sl.lists.get(head).set(this.offset, e); - } - - @Override - public void add(F f) { - throw new UnsupportedOperationException("add not supported"); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/set/StackedSet.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/set/StackedSet.java deleted file mode 100644 index 095e0a18c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/set/StackedSet.java +++ /dev/null @@ -1,170 +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.container.stacked.set; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Deque; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.container.StackedContainer; -import org.jetbrains.annotations.NotNull; - -/** - * Implements a system of nested sets behaving as a single one, where the current context - * modification can transparently be dropped. - * - * @param the type of elements stored in the set - */ -public class StackedSet implements StackedContainer, java.util.Set { - private final Deque> sets = new ArrayDeque<>(); - private final Map occurrences = new HashMap<>(); - - @Override - public void enter() { - this.sets.addLast(new HashSet<>()); - } - - @Override - public void pop() { - Set lastSet = this.sets.removeLast(); - for (E e : lastSet) { - occurrences.computeIfPresent( - e, - (k, count) -> { - if (count > 0) { - return count - 1; - } else { - throw new IllegalStateException("asymmetric element removal !"); - } - }); - } - } - - @Override - public int size() { - int size = 0; - for (Integer count : occurrences.values()) { - if (count != 0) { - size++; - } - } - return size; - } - - public int lineCount() { - int sum = 0; - for (Map.Entry entry : occurrences.entrySet()) { - if (entry.getValue() > 0) { - sum += entry.getKey().lineCount(); - } - } - return sum; - } - - @Override - public boolean isEmpty() { - throw new UnsupportedOperationException("empty not supported"); - } - - @Override - public boolean contains(Object o) { - return occurrences.containsKey(o) && occurrences.get(o) > 0; - } - - @NotNull - @Override - public Iterator iterator() { - final List list = new ArrayList<>(); - for (Map.Entry entry : occurrences.entrySet()) { - if (entry.getValue() > 0) { - list.add(entry.getKey()); - } - } - return list.iterator(); - } - - @NotNull - @Override - public Object[] toArray() { - return occurrences.entrySet().stream() - .filter(entry -> entry.getValue() > 0) - .map(Map.Entry::getKey) - .toArray(); - } - - @NotNull - @Override - public T[] toArray(@NotNull T[] a) { - throw new UnsupportedOperationException("toArray not supported"); - } - - @Override - public boolean add(E e) { - final boolean isNew = this.sets.peekLast().add(e); - if (isNew) { - occurrences.put(e, occurrences.getOrDefault(e, 0) + 1); - } - return isNew; - } - - @Override - public boolean remove(Object o) { - throw new UnsupportedOperationException("remove not supported"); - } - - @Override - public boolean containsAll(@NotNull Collection c) { - for (var x : c) { - if (!this.contains(x)) { - return false; - } - } - return true; - } - - @Override - public boolean addAll(@NotNull Collection c) { - boolean r = false; - for (var x : c) { - r |= this.add(x); - } - return r; - } - - @Override - public boolean retainAll(@NotNull Collection c) { - throw new UnsupportedOperationException("retainAll not supported"); - } - - @Override - public boolean removeAll(@NotNull Collection c) { - throw new UnsupportedOperationException("removeAll not supported"); - } - - @Override - public void clear() { - this.sets.clear(); - this.occurrences.clear(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/json/BigIntegerSerializer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/json/BigIntegerSerializer.java deleted file mode 100644 index da1a40b2c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/json/BigIntegerSerializer.java +++ /dev/null @@ -1,47 +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.json; - -import java.io.IOException; -import java.math.BigInteger; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; - -/** Custom JSON serializer for {@link BigInteger} type. */ -public class BigIntegerSerializer extends StdSerializer { - private static final BigInteger INTEGER_MAX = BigInteger.valueOf(Integer.MAX_VALUE); - - public BigIntegerSerializer() { - this(null); - } - - public BigIntegerSerializer(final Class t) { - super(t); - } - - @Override - public void serialize( - final BigInteger value, final JsonGenerator gen, final SerializerProvider provider) - throws IOException { - if (value.compareTo(INTEGER_MAX) > 0) { - gen.writeString(value.toString()); - } else { - gen.writeNumber(value.intValue()); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/json/JsonConverter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/json/JsonConverter.java deleted file mode 100644 index 8804bb31f..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/json/JsonConverter.java +++ /dev/null @@ -1,119 +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.json; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import lombok.Getter; - -/** A wrapper class handling Jackson's {@link ObjectMapper} configuration. */ -public class JsonConverter { - - @Getter private final ObjectMapper objectMapper; - - private final boolean prettyPrintEnabled; - - private JsonConverter(Builder builder) { - this.objectMapper = builder.objectMapper; - this.prettyPrintEnabled = builder.prettyPrintEnabled; - } - - /** - * Serializes an object to a JSON string. - * - * @param object the object to be serialized - * @return a JSON string representing the object's data - * @throws JsonProcessingException n case of a serialization failure - */ - public String toJson(Object object) throws JsonProcessingException { - if (prettyPrintEnabled) { - return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(object); - } - - return objectMapper.writeValueAsString(object); - } - - /** - * Deserializes a JSON string to a specified type. - * - * @param jsonString JSON string to be deserialized - * @param clazz class type of the type for deserialization - * @param the deserialization type - * @return an instance of the deserialized type - * @throws JsonProcessingException in case of a deserialization failure - */ - public T fromJson(String jsonString, Class clazz) throws JsonProcessingException { - return objectMapper.readValue(jsonString, clazz); - } - - /** - * A factory for the {@link Builder} instance. - * - * @return an instance of {@link Builder}. - */ - public static Builder builder() { - return new Builder(); - } - - /** A builder for {@link JsonConverter}. */ - public static class Builder { - private ObjectMapper objectMapper; - private final SimpleModule module; - private boolean prettyPrintEnabled; - - private Builder() { - this.objectMapper = new ObjectMapper(); - this.module = new SimpleModule(); - } - - /** - * Configures a custom jackson serializer for a specific type. - * - * @param type the class type targeted for custom serialization - * @param serializer the serializer implementation handling the specified type - * @param the type targeted for custom serialization - * @return the current instance of the builder - */ - public Builder addCustomSerializer(Class type, JsonSerializer serializer) { - module.addSerializer(type, serializer); - return this; - } - - public Builder enableYaml() { - objectMapper = new ObjectMapper(new YAMLFactory()); - return this; - } - - public Builder enablePrettyPrint() { - this.prettyPrintEnabled = true; - return this; - } - - /** - * Builds an instance of {@link JsonConverter}. - * - * @return an instance of {@link JsonConverter}. - */ - public JsonConverter build() { - objectMapper.registerModule(module); - - return new JsonConverter(this); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/json/NumericBooleanSerializer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/json/NumericBooleanSerializer.java deleted file mode 100644 index 8d87c6ae8..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/json/NumericBooleanSerializer.java +++ /dev/null @@ -1,39 +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.json; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; - -public class NumericBooleanSerializer extends StdSerializer { - public NumericBooleanSerializer() { - this(null); - } - - public NumericBooleanSerializer(Class t) { - super(t); - } - - @Override - public void serialize(Boolean value, JsonGenerator gen, SerializerProvider provider) - throws IOException { - // converts the boolean to a numeric representation - gen.writeNumber(value ? 1 : 0); - } -} 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 deleted file mode 100644 index e7dfb1d43..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java +++ /dev/null @@ -1,83 +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; - -import java.nio.MappedByteBuffer; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -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.operation.Operation; -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; - -public interface Module { - String moduleKey(); - - default void traceStartConflation(final long blockCount) {} - - default void traceEndConflation() {} - - default void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) {} - - default void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) {} - - default void traceStartTx(WorldView worldView, Transaction tx) {} - - default void traceEndTx( - WorldView worldView, - Transaction tx, - boolean isSuccessful, - Bytes output, - List logs, - long gasUsed) {} - - default void traceContextEnter(MessageFrame frame) {} - - default void traceContextExit(MessageFrame frame) {} - - default void tracePreOpcode(MessageFrame frame) {} - - default void tracePostOp(MessageFrame frame) {} - - /** - * Called at the eve of a new transaction; intended to create a new modification context for the - * stacked state of the module. - */ - void enterTransaction(); - - /** Called when a transaction execution is cancelled; should revert the state of the module. */ - void popTransaction(); - - int lineCount(); - - default void tracePreExecution( - final MessageFrame frame, final Operation.OperationResult operationResult) {} - - default void tracePostExecution( - final MessageFrame frame, final Operation.OperationResult operationResult) {} - - List columnsHeaders(); - - default void commit(List buffers) { - throw new UnsupportedOperationException(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ModuleTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ModuleTrace.java deleted file mode 100644 index 65b609f45..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ModuleTrace.java +++ /dev/null @@ -1,20 +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; - -public interface ModuleTrace { - int length(); -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Util.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Util.java deleted file mode 100644 index 4a78d9c33..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Util.java +++ /dev/null @@ -1,193 +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; - -import static com.google.common.base.Preconditions.checkArgument; -import static net.consensys.linea.zktracer.types.Utils.rightPadTo; - -import java.math.BigInteger; - -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.datatypes.TransactionType; - -/** Utility class that provides various helper methods. */ -public class Util { - - /** - * Converts the bits of an unsigned byte into an array of Booleans. - * - * @param b The unsigned byte to be converted. - * @return A Boolean array containing the bits of the input byte. - */ - public static Boolean[] byteBits(final UnsignedByte b) { - final Boolean[] bits = new Boolean[8]; - for (int i = 0; i < 8; i++) { - bits[7 - i] = b.shiftRight(i).mod(2).toInteger() == 1; - } - return bits; - } - - /** - * Checks if the shifted UInt256 argument overflows a given maximum value, and throws an exception - * with an error message if it does. - * - * @param arg The UInt256 argument to be checked. - * @param maxVal The maximum value the shifted argument should not exceed. - * @param err The error message to be included in the exception. - * @return The overflow value if it doesn't exceed the maximum value. - */ - public static long getOverflow(UInt256 arg, long maxVal, String err) { - UInt256 shiftedArg = arg.shiftRight(128); - - if (!shiftedArg.fitsLong()) { - throw new RuntimeException("getOverflow expects a small high part"); - } - long overflow = shiftedArg.toUnsignedBigInteger().longValue(); - if (overflow > maxVal) { - throw new RuntimeException(err); - } - return overflow; - } - - /** - * Checks if the k'th bit of a given long value is 1. - * - * @param x The long value to be checked. - * @param k The index of the bit to be checked. - * @return True if the k'th bit of x is 1, otherwise false. - */ - public static boolean getBit(long x, int k) { - return (x >> k) % 2 == 1; - } - - /** - * Converts a boolean value to an integer (1 for true and 0 for false). - * - * @param bool The boolean value to be converted. - * @return An integer representing the input boolean value. - */ - public static int boolToInt(boolean bool) { - return bool ? 1 : 0; - } - - /** - * Converts a 64-bit unsigned integer into an 8-byte array. - * - * @param x The 64-bit unsigned integer to be converted. - * @return An 8-byte array representing the input value. - */ - public static byte[] uInt64ToBytes(long x) { - byte[] xBytes = new byte[8]; - for (int k = 0; k < 8; k++) { - xBytes[7 - k] = (byte) (x % 256); - x >>= 8; - } - return xBytes; - } - - /** - * Checks if a given BigInteger value is a valid UInt256. - * - * @param number The BigInteger value to be checked. - * @return True if the input value is a valid UInt256, otherwise false. - */ - public static boolean isUInt256(BigInteger number) { - return number.bitLength() <= 256; - } - - /** - * Multiplies the elements of two byte array ranges and returns the sum of their UInt256 products. - * - * @param range1 The first byte array range. - * @param range2 The second byte array range. - * @return The UInt256 sum of the products of the elements in the two input ranges. - */ - public static UInt256 multiplyRange(Bytes[] range1, Bytes[] range2) { - checkArgument(range1.length == range2.length); - UInt256 sum = UInt256.ZERO; - for (int i = 0; i < range1.length; i++) { - UInt256 prod = - UInt256.fromBytes(range1[i]).multiply(UInt256.fromBytes(range2[range2.length - i - 1])); - sum = sum.add(prod); - } - return sum; - } - - /** - * Converts a boolean value to a byte (1 for true and 0 for false). - * - * @param b The boolean value to be converted. - * @return A byte representing the input boolean value. - */ - public static byte boolToByte(boolean b) { - return (byte) (b ? 1 : 0); - } - - /** - * Returns the maximum of two BigInteger values. - * - * @param x the first BigInteger to compare - * @param y the second BigInteger to compare - * @return the maximum of x and y. If x is less than y, it returns y, otherwise it returns x. - */ - public static BigInteger max(final BigInteger x, final BigInteger y) { - if (x.compareTo(y) < 0) { - return y; - } - return x; - } - - /** - * Return the type of transaction as an int - * - * @param txType - * @return transaction type - */ - public static int getTxTypeAsInt(TransactionType txType) { - return switch (txType) { - case FRONTIER -> 0; - case ACCESS_LIST -> 1; - case EIP1559 -> 2; - case BLOB -> 3; - default -> throw new RuntimeException("Transaction type not supported:" + txType); - }; - } - - /** - * Return the - * - * @param size Bytes of - * @param data, right-padded with 0's if needed, starting from - * @param positionStart - */ - public static Bytes slice(Bytes data, int positionStart, int size) { - - final int dataSize = data.size(); - Bytes output = Bytes.repeat((byte) 0x0, size); - - if (dataSize >= positionStart) { - if (dataSize >= (positionStart + size)) { - output = data.slice(positionStart, size); - } else { - final int nbPresentBytes = dataSize - positionStart; - output = rightPadTo(data.slice(positionStart, nbPresentBytes), size); - } - } - return output; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/UtilCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/UtilCalculator.java deleted file mode 100644 index 4b4cbbc92..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/UtilCalculator.java +++ /dev/null @@ -1,67 +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; - -import java.math.BigInteger; - -import net.consensys.linea.zktracer.bytestheta.BaseTheta; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; - -public class UtilCalculator { - /** - * Calculates the product of arg1 and arg2, both of type Bytes32, and returns the result as a - * BigInteger. - * - * @param arg1 The first Bytes32 argument. - * @param arg2 The second Bytes32 argument. - * @return The product of arg1 and arg2 as a BigInteger. - */ - public static BigInteger calculateProduct(Bytes32 arg1, Bytes32 arg2) { - BigInteger arg1UInt = arg1.toUnsignedBigInteger(); - BigInteger arg2UInt = arg2.toUnsignedBigInteger(); - - // Compute the product of the two unsigned BigIntegers. - return arg1UInt.multiply(arg2UInt); - } - - /** - * Calculates the quotient of the given BigInteger divided by arg3, a Bytes32 argument. Returns - * the result as a BigInteger. - * - * @param prod The BigInteger to divide. - * @param arg3 The third Bytes32 argument. - * @return The quotient of the given BigInteger and arg3 as a BigInteger. - */ - public static BigInteger calculateQuotient(BigInteger prod, Bytes32 arg3) { - return prod.divide(arg3.toUnsignedBigInteger()); - } - - /** - * Converts a given BigInteger to a BaseTheta representation. - * - * @param quotBigInteger The BigInteger to convert. - * @return The given BigInteger as a BaseTheta representation. - */ - public static BaseTheta convertToBaseTheta(BigInteger quotBigInteger) { - return new BaseTheta(UInt256.valueOf(quotBigInteger)); - } - - public static UInt256 calculateSum(Bytes32 arg1, Bytes32 arg2) { - // Compute the sum of the two unsigned BigIntegers. - return UInt256.fromBytes(arg1).add(UInt256.fromBytes(arg2)); - } -} 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 deleted file mode 100644 index 66bf1d97a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Add.java +++ /dev/null @@ -1,75 +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.add; - -import java.nio.MappedByteBuffer; -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.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; -import org.hyperledger.besu.evm.frame.MessageFrame; - -/** 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<>(); - - @Override - public String moduleKey() { - return "ADD"; - } - - @Override - public void enterTransaction() { - this.chunks.enter(); - } - - @Override - public void popTransaction() { - this.chunks.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - this.chunks.add(new AddOperation(hub.opCode(), frame.getStackItem(0), frame.getStackItem(1))); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - int stamp = 0; - for (AddOperation op : this.chunks) { - stamp++; - op.trace(stamp, trace); - } - } - - @Override - public int lineCount() { - return this.chunks.lineCount(); - } -} 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 deleted file mode 100644 index 7e0c3536d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/AddOperation.java +++ /dev/null @@ -1,140 +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.add; - -import lombok.EqualsAndHashCode; -import net.consensys.linea.zktracer.bytestheta.BaseBytes; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.Bytes16; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; - -@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) -public final class AddOperation extends ModuleOperation { - private static final UInt256 TWO_TO_THE_128 = UInt256.ONE.shiftLeft(128); - private static final int LLARGE = 16; - - @EqualsAndHashCode.Include private final OpCode opCode; - @EqualsAndHashCode.Include private final Bytes32 arg1; - @EqualsAndHashCode.Include private final Bytes32 arg2; - private final BaseBytes res; - public final int ctMax; - - /** - * Returns the appropriate state of the overflow bit depending on the position within the cycle. - * - * @param counter current position within the tracing cycle - * @param overflowHi putative overflow bit of the high part - * @param overflowLo putative overflow bit of the high part - * @return the overflow bit to trace - */ - private boolean overflowBit( - final int counter, final boolean overflowHi, final boolean overflowLo) { - if (counter == this.ctMax - 1) { - return overflowHi; - } - - if (counter == this.ctMax) { - return overflowLo; - } - - return false; - } - - public AddOperation(OpCode opCode, Bytes arg1, Bytes arg2) { - this.opCode = opCode; - this.arg1 = Bytes32.leftPad(arg1); - this.arg2 = Bytes32.leftPad(arg2); - this.res = Adder.addSub(this.opCode, this.arg1, this.arg2); - - this.ctMax = maxCT(); - } - - private int maxCT() { - return Math.max( - 1, - Math.max( - this.res.getHigh().trimLeadingZeros().size(), - this.res.getLow().trimLeadingZeros().size()) - - 1); - } - - void trace(int stamp, Trace trace) { - final Bytes16 arg1Hi = Bytes16.wrap(arg1.slice(0, 16)); - final Bytes16 arg1Lo = Bytes16.wrap(arg1.slice(16)); - final Bytes16 arg2Hi = Bytes16.wrap(arg2.slice(0, 16)); - final Bytes16 arg2Lo = Bytes16.wrap(arg2.slice(16)); - - final int length = this.ctMax + 1; - final int offset = LLARGE - length; - final Bytes resHi = res.getHigh().slice(offset, length); - final Bytes resLo = res.getLow().slice(offset, length); - - final UInt256 arg1Int = UInt256.fromBytes(arg1); - final UInt256 arg2Int = UInt256.fromBytes(arg2); - - // set OverflowHi - boolean overflowHi = false; - - if (opCode == OpCode.ADD) { - final UInt256 resultBytes = arg1Int.add(arg2Int); - if (resultBytes.compareTo(arg1Int) < 0) { - overflowHi = true; - } - } else if (opCode == OpCode.SUB) { - if (arg1Int.compareTo(arg2Int) < 0) { - overflowHi = true; - } - } - - // Set OverFlowLo - Bytes32 addRes; - if (opCode == OpCode.ADD) { - addRes = Bytes32.wrap((UInt256.fromBytes(arg1Lo)).add(UInt256.fromBytes(arg2Lo))); - } else { - addRes = Bytes32.wrap((UInt256.fromBytes(resLo)).add(UInt256.fromBytes(arg2Lo))); - } - - final boolean overflowLo = (addRes.compareTo(TWO_TO_THE_128) >= 0); - for (int ct = 0; ct <= this.ctMax; ct++) { - trace - .acc1(resHi.slice(0, 1 + ct)) - .acc2(resLo.slice(0, 1 + ct)) - .arg1Hi(arg1Hi) - .arg1Lo(arg1Lo) - .arg2Hi(arg2Hi) - .arg2Lo(arg2Lo) - .byte1(UnsignedByte.of(resHi.get(ct))) - .byte2(UnsignedByte.of(resLo.get(ct))) - .ct(UnsignedByte.of(ct)) - .ctMax(UnsignedByte.of(this.ctMax)) - .inst(UnsignedByte.of(opCode.byteValue())) - .overflow(overflowBit(ct, overflowHi, overflowLo)) - .resHi(resHi) - .resLo(resLo) - .stamp(Bytes.ofUnsignedLong(stamp)) - .validateRow(); - } - } - - @Override - protected int computeLineCount() { - return this.ctMax + 1; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Adder.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Adder.java deleted file mode 100644 index 1ab0c745e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Adder.java +++ /dev/null @@ -1,49 +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.add; - -import net.consensys.linea.zktracer.bytestheta.BaseBytes; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; - -/** A module responsible for addition operations. */ -public class Adder { - - /** - * Performs addition or subtraction based on the opcode. - * - * @param opCode accepts {@link OpCode#ADD} or {@link OpCode#SUB}. - * @param arg1 left argument. - * @param arg2 right argument. - * @return {@link BaseBytes} - 256-bit (32-byte) blocks data. - */ - public static BaseBytes addSub(final OpCode opCode, final Bytes32 arg1, final Bytes32 arg2) { - final BaseBytes resBytes = performOperation(opCode, arg1, arg2); - - // ensure result is correct length - return BaseBytes.fromBytes32(resBytes.getBytes32()); - } - - private static BaseBytes performOperation( - final OpCode opCode, final Bytes32 arg1, final Bytes32 arg2) { - return switch (opCode) { - case ADD -> BaseBytes.fromBytes32(UInt256.fromBytes(arg1).add(UInt256.fromBytes(arg2))); - case SUB -> BaseBytes.fromBytes32(UInt256.fromBytes(arg1).subtract(UInt256.fromBytes(arg2))); - default -> throw new IllegalStateException("Modular arithmetic was given wrong opcode"); - }; - } -} 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 deleted file mode 100644 index 04d16e0ab..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java +++ /dev/null @@ -1,453 +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.add; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer acc1; - private final MappedByteBuffer acc2; - private final MappedByteBuffer arg1Hi; - private final MappedByteBuffer arg1Lo; - private final MappedByteBuffer arg2Hi; - private final MappedByteBuffer arg2Lo; - private final MappedByteBuffer byte1; - private final MappedByteBuffer byte2; - private final MappedByteBuffer ct; - private final MappedByteBuffer ctMax; - private final MappedByteBuffer inst; - private final MappedByteBuffer overflow; - private final MappedByteBuffer resHi; - private final MappedByteBuffer resLo; - private final MappedByteBuffer stamp; - - 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.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", 32, length)); - } - - public Trace(List buffers) { - this.acc1 = buffers.get(0); - this.acc2 = buffers.get(1); - this.arg1Hi = buffers.get(2); - this.arg1Lo = buffers.get(3); - this.arg2Hi = buffers.get(4); - this.arg2Lo = buffers.get(5); - this.byte1 = buffers.get(6); - this.byte2 = buffers.get(7); - this.ct = buffers.get(8); - this.ctMax = buffers.get(9); - this.inst = buffers.get(10); - this.overflow = buffers.get(11); - this.resHi = buffers.get(12); - this.resLo = buffers.get(13); - this.stamp = buffers.get(14); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace acc1(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("add.ACC_1 already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc1.put((byte) 0); - } - acc1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc2(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("add.ACC_2 already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc2.put((byte) 0); - } - acc2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg1Hi(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("add.ARG_1_HI already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Hi.put((byte) 0); - } - arg1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg1Lo(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("add.ARG_1_LO already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Lo.put((byte) 0); - } - arg1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg2Hi(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("add.ARG_2_HI already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg2Hi.put((byte) 0); - } - arg2Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg2Lo(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("add.ARG_2_LO already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg2Lo.put((byte) 0); - } - arg2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace byte1(final UnsignedByte b) { - if (filled.get(6)) { - throw new IllegalStateException("add.BYTE_1 already set"); - } else { - filled.set(6); - } - - byte1.put(b.toByte()); - - return this; - } - - public Trace byte2(final UnsignedByte b) { - if (filled.get(7)) { - throw new IllegalStateException("add.BYTE_2 already set"); - } else { - filled.set(7); - } - - byte2.put(b.toByte()); - - return this; - } - - public Trace ct(final UnsignedByte b) { - if (filled.get(8)) { - throw new IllegalStateException("add.CT already set"); - } else { - filled.set(8); - } - - ct.put(b.toByte()); - - return this; - } - - public Trace ctMax(final UnsignedByte b) { - if (filled.get(9)) { - throw new IllegalStateException("add.CT_MAX already set"); - } else { - filled.set(9); - } - - ctMax.put(b.toByte()); - - return this; - } - - public Trace inst(final UnsignedByte b) { - if (filled.get(10)) { - throw new IllegalStateException("add.INST already set"); - } else { - filled.set(10); - } - - inst.put(b.toByte()); - - return this; - } - - public Trace overflow(final Boolean b) { - if (filled.get(11)) { - throw new IllegalStateException("add.OVERFLOW already set"); - } else { - filled.set(11); - } - - overflow.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace resHi(final Bytes b) { - if (filled.get(12)) { - throw new IllegalStateException("add.RES_HI already set"); - } else { - filled.set(12); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resHi.put((byte) 0); - } - resHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace resLo(final Bytes b) { - if (filled.get(13)) { - throw new IllegalStateException("add.RES_LO already set"); - } else { - filled.set(13); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resLo.put((byte) 0); - } - resLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace stamp(final Bytes b) { - if (filled.get(14)) { - throw new IllegalStateException("add.STAMP already set"); - } else { - filled.set(14); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stamp.put((byte) 0); - } - stamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("add.ACC_1 has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("add.ACC_2 has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("add.ARG_1_HI has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("add.ARG_1_LO has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("add.ARG_2_HI has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("add.ARG_2_LO has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("add.BYTE_1 has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("add.BYTE_2 has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("add.CT has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("add.CT_MAX has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("add.INST has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("add.OVERFLOW has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("add.RES_HI has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("add.RES_LO has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("add.STAMP has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - acc1.position(acc1.position() + 32); - } - - if (!filled.get(1)) { - acc2.position(acc2.position() + 32); - } - - if (!filled.get(2)) { - arg1Hi.position(arg1Hi.position() + 32); - } - - if (!filled.get(3)) { - arg1Lo.position(arg1Lo.position() + 32); - } - - if (!filled.get(4)) { - arg2Hi.position(arg2Hi.position() + 32); - } - - if (!filled.get(5)) { - arg2Lo.position(arg2Lo.position() + 32); - } - - if (!filled.get(6)) { - byte1.position(byte1.position() + 1); - } - - if (!filled.get(7)) { - byte2.position(byte2.position() + 1); - } - - if (!filled.get(8)) { - ct.position(ct.position() + 1); - } - - if (!filled.get(9)) { - ctMax.position(ctMax.position() + 1); - } - - if (!filled.get(10)) { - inst.position(inst.position() + 1); - } - - if (!filled.get(11)) { - overflow.position(overflow.position() + 1); - } - - if (!filled.get(12)) { - resHi.position(resHi.position() + 32); - } - - if (!filled.get(13)) { - resLo.position(resLo.position() + 32); - } - - if (!filled.get(14)) { - stamp.position(stamp.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} 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 deleted file mode 100644 index 38da54aab..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/Bin.java +++ /dev/null @@ -1,87 +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.bin; - -import java.nio.MappedByteBuffer; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -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; - } - - @Override - public String moduleKey() { - return "BIN"; - } - - @Override - public void enterTransaction() { - this.chunks.enter(); - } - - @Override - public void popTransaction() { - this.chunks.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = this.hub.opCode(); - final Bytes32 arg1 = Bytes32.leftPad(frame.getStackItem(0)); - final Bytes32 arg2 = - opCode == OpCode.NOT ? Bytes32.ZERO : Bytes32.leftPad(frame.getStackItem(1)); - - this.chunks.add( - new BinOperation(opCode, BaseBytes.fromBytes32(arg1), BaseBytes.fromBytes32(arg2))); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - int stamp = 0; - for (BinOperation op : this.chunks) { - stamp++; - op.traceBinOperation(stamp, trace); - } - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public int lineCount() { - return this.chunks.lineCount(); - } -} 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 deleted file mode 100644 index 748d71189..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/BinOperation.java +++ /dev/null @@ -1,228 +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.bin; - -import static net.consensys.linea.zktracer.types.Utils.bitDecomposition; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Stream; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.bytestheta.BaseBytes; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.Bytes16; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; - -@Getter -@Accessors(fluent = true) -@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; - private List lastEightBits = List.of(false); - private boolean bit4 = false; - private int low4 = 0; - private boolean isSmall = false; - private int pivotThreshold = 0; - private int pivot = 0; - - private boolean isOneLineInstruction() { - return (opCode == OpCode.BYTE || opCode == OpCode.SIGNEXTEND) && !arg1.getHigh().isZero(); - } - - @Override - protected int computeLineCount() { - return this.maxCt(); - } - - private int maxCt() { - return isOneLineInstruction() ? 1 : LIMB_SIZE; - } - - private boolean isSmall() { - return arg1.getBytes32().trimLeadingZeros().bitLength() < 6; - } - - private int getPivotThreshold() { - return switch (opCode) { - case AND, OR, XOR, NOT -> 16; - case BYTE -> low4; - case SIGNEXTEND -> 15 - low4; - default -> throw new IllegalStateException("Bin doesn't support OpCode" + opCode); - }; - } - - private BaseBytes getResult() { - return switch (opCode) { - case AND -> arg1.and(arg2); - case OR -> arg1.or(arg2); - case XOR -> BaseBytes.fromBytes32(arg1.getBytes32().xor(arg2.getBytes32())); - case NOT -> arg1.not(); - case BYTE -> byteResult(); - case SIGNEXTEND -> signExtensionResult(); - default -> throw new IllegalStateException("Bin doesn't support OpCode" + opCode); - }; - } - - private BaseBytes signExtensionResult() { - if (!isSmall) { - return arg2; - } - final int indexLeadingByte = 31 - arg1.getByte(31) & 0xff; - final byte toSet = (byte) (arg2().getByte(indexLeadingByte) < 0 ? 0xff : 0x00); - return BaseBytes.fromBytes32( - Bytes32.leftPad(arg2.getBytes32().slice(indexLeadingByte, 32 - indexLeadingByte), toSet)); - } - - private BaseBytes byteResult() { - final int result = isSmall ? pivot : 0; - return BaseBytes.fromBytes32(Bytes32.leftPad(Bytes.ofUnsignedShort(result))); - } - - private List getLastEightBits() { - final int leastByteOfArg1 = arg1().getByte(31) & 0xff; - return bitDecomposition(leastByteOfArg1, 8).bitDecList(); - } - - private boolean getBit4() { - return getLastEightBits().get(3); - } - - private int getLow4() { - int r = 0; - for (int k = 0; k < 4; k++) { - if (lastEightBits.get(7 - k)) { - r += (int) Math.pow(2, k); - } - } - return r; - } - - private List getBit1() { - return plateau(pivotThreshold); - } - - private List plateau(final int threshold) { - ArrayList output = new ArrayList<>(16); - for (int ct = 0; ct < 16; ct++) { - output.add(ct, ct >= threshold); - } - return output; - } - - private int getPivot() { - switch (opCode) { - case AND, OR, XOR, NOT -> { - return 0; - } - case BYTE -> { - if (low4 == 0) { - return !bit4 ? arg2.getHigh().get(0) & 0xff : arg2.getLow().get(0) & 0xff; - } else { - return !bit4 - ? arg2.getHigh().get(pivotThreshold) & 0xff - : arg2.getLow().get(pivotThreshold) & 0xff; - } - } - case SIGNEXTEND -> { - if (low4 == 15) { - return !bit4 ? arg2.getLow().get(0) & 0xff : arg2.getHigh().get(0) & 0xff; - } else { - return !bit4 - ? arg2.getLow().get(pivotThreshold) & 0xff - : arg2.getHigh().get(pivotThreshold) & 0xff; - } - } - default -> throw new IllegalStateException("Bin doesn't support OpCode" + opCode); - } - } - - private List getFirstEightBits() { - return bitDecomposition(pivot, 8).bitDecList(); - } - - private void compute() { - this.lastEightBits = getLastEightBits(); - this.bit4 = getBit4(); - this.low4 = getLow4(); - this.isSmall = isSmall(); - this.pivotThreshold = getPivotThreshold(); - this.pivot = getPivot(); - } - - public void traceBinOperation(int stamp, Trace trace) { - this.compute(); - - final Bytes16 resHi = this.getResult().getHigh(); - final Bytes16 resLo = this.getResult().getLow(); - final List bit1 = this.getBit1(); - final List bits = - Stream.concat(this.getFirstEightBits().stream(), this.lastEightBits.stream()).toList(); - for (int ct = 0; ct < this.maxCt(); ct++) { - trace - .stamp(Bytes.ofUnsignedInt(stamp)) - .oneLineInstruction(this.maxCt() == 1) - .mli(this.maxCt() != 1) - .counter(UnsignedByte.of(ct)) - .inst(UnsignedByte.of(this.opCode().byteValue())) - .argument1Hi(this.arg1().getHigh()) - .argument1Lo(this.arg1().getLow()) - .argument2Hi(this.arg2().getHigh()) - .argument2Lo(this.arg2().getLow()) - .resultHi(resHi) - .resultLo(resLo) - .isAnd(this.opCode() == OpCode.AND) - .isOr(this.opCode() == OpCode.OR) - .isXor(this.opCode() == OpCode.XOR) - .isNot(this.opCode() == OpCode.NOT) - .isByte(this.opCode() == OpCode.BYTE) - .isSignextend(this.opCode() == OpCode.SIGNEXTEND) - .small(this.isSmall) - .bits(bits.get(ct)) - .bitB4(this.bit4) - .low4(UnsignedByte.of(this.low4)) - .neg(bits.get(0)) - .bit1(bit1.get(ct)) - .pivot(UnsignedByte.of(this.pivot)) - .byte1(UnsignedByte.of(this.arg1().getHigh().get(ct))) - .byte2(UnsignedByte.of(this.arg1().getLow().get(ct))) - .byte3(UnsignedByte.of(this.arg2().getHigh().get(ct))) - .byte4(UnsignedByte.of(this.arg2().getLow().get(ct))) - .byte5(UnsignedByte.of(resHi.get(ct))) - .byte6(UnsignedByte.of(resLo.get(ct))) - .acc1(this.arg1().getHigh().slice(0, ct + 1)) - .acc2(this.arg1().getLow().slice(0, ct + 1)) - .acc3(this.arg2().getHigh().slice(0, ct + 1)) - .acc4(this.arg2().getLow().slice(0, ct + 1)) - .acc5(resHi.slice(0, ct + 1)) - .acc6(resLo.slice(0, ct + 1)) - .xxxByteHi(UnsignedByte.of(resHi.get(ct))) - .xxxByteLo(UnsignedByte.of(resLo.get(ct))) - .validateRow(); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/Trace.java deleted file mode 100644 index 900497e7f..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/Trace.java +++ /dev/null @@ -1,998 +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.bin; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer acc1; - private final MappedByteBuffer acc2; - private final MappedByteBuffer acc3; - private final MappedByteBuffer acc4; - private final MappedByteBuffer acc5; - private final MappedByteBuffer acc6; - private final MappedByteBuffer argument1Hi; - private final MappedByteBuffer argument1Lo; - private final MappedByteBuffer argument2Hi; - private final MappedByteBuffer argument2Lo; - private final MappedByteBuffer bit1; - private final MappedByteBuffer bitB4; - private final MappedByteBuffer bits; - private final MappedByteBuffer byte1; - private final MappedByteBuffer byte2; - private final MappedByteBuffer byte3; - private final MappedByteBuffer byte4; - private final MappedByteBuffer byte5; - private final MappedByteBuffer byte6; - private final MappedByteBuffer counter; - private final MappedByteBuffer inst; - private final MappedByteBuffer isAnd; - private final MappedByteBuffer isByte; - private final MappedByteBuffer isNot; - private final MappedByteBuffer isOr; - private final MappedByteBuffer isSignextend; - private final MappedByteBuffer isXor; - private final MappedByteBuffer low4; - private final MappedByteBuffer mli; - private final MappedByteBuffer neg; - private final MappedByteBuffer oneLineInstruction; - private final MappedByteBuffer pivot; - private final MappedByteBuffer resultHi; - private final MappedByteBuffer resultLo; - private final MappedByteBuffer small; - private final MappedByteBuffer stamp; - private final MappedByteBuffer xxxByteHi; - private final MappedByteBuffer xxxByteLo; - - static List headers(int length) { - return List.of( - new ColumnHeader("bin.ACC_1", 32, length), - new ColumnHeader("bin.ACC_2", 32, length), - new ColumnHeader("bin.ACC_3", 32, length), - new ColumnHeader("bin.ACC_4", 32, length), - new ColumnHeader("bin.ACC_5", 32, length), - new ColumnHeader("bin.ACC_6", 32, length), - new ColumnHeader("bin.ARGUMENT_1_HI", 32, length), - new ColumnHeader("bin.ARGUMENT_1_LO", 32, length), - new ColumnHeader("bin.ARGUMENT_2_HI", 32, length), - new ColumnHeader("bin.ARGUMENT_2_LO", 32, length), - new ColumnHeader("bin.BIT_1", 1, length), - new ColumnHeader("bin.BIT_B_4", 1, length), - new ColumnHeader("bin.BITS", 1, length), - new ColumnHeader("bin.BYTE_1", 1, length), - new ColumnHeader("bin.BYTE_2", 1, length), - new ColumnHeader("bin.BYTE_3", 1, length), - new ColumnHeader("bin.BYTE_4", 1, length), - new ColumnHeader("bin.BYTE_5", 1, length), - new ColumnHeader("bin.BYTE_6", 1, length), - new ColumnHeader("bin.COUNTER", 1, length), - new ColumnHeader("bin.INST", 1, length), - new ColumnHeader("bin.IS_AND", 1, length), - new ColumnHeader("bin.IS_BYTE", 1, length), - new ColumnHeader("bin.IS_NOT", 1, length), - new ColumnHeader("bin.IS_OR", 1, length), - new ColumnHeader("bin.IS_SIGNEXTEND", 1, length), - new ColumnHeader("bin.IS_XOR", 1, length), - new ColumnHeader("bin.LOW_4", 1, length), - new ColumnHeader("bin.MLI", 1, length), - new ColumnHeader("bin.NEG", 1, length), - new ColumnHeader("bin.ONE_LINE_INSTRUCTION", 1, length), - new ColumnHeader("bin.PIVOT", 1, length), - new ColumnHeader("bin.RESULT_HI", 32, length), - new ColumnHeader("bin.RESULT_LO", 32, length), - new ColumnHeader("bin.SMALL", 1, length), - new ColumnHeader("bin.STAMP", 32, length), - new ColumnHeader("bin.XXX_BYTE_HI", 1, length), - new ColumnHeader("bin.XXX_BYTE_LO", 1, length)); - } - - public Trace(List buffers) { - this.acc1 = buffers.get(0); - this.acc2 = buffers.get(1); - this.acc3 = buffers.get(2); - this.acc4 = buffers.get(3); - this.acc5 = buffers.get(4); - this.acc6 = buffers.get(5); - this.argument1Hi = buffers.get(6); - this.argument1Lo = buffers.get(7); - this.argument2Hi = buffers.get(8); - this.argument2Lo = buffers.get(9); - this.bit1 = buffers.get(10); - this.bitB4 = buffers.get(11); - this.bits = buffers.get(12); - this.byte1 = buffers.get(13); - this.byte2 = buffers.get(14); - this.byte3 = buffers.get(15); - this.byte4 = buffers.get(16); - this.byte5 = buffers.get(17); - this.byte6 = buffers.get(18); - this.counter = buffers.get(19); - this.inst = buffers.get(20); - this.isAnd = buffers.get(21); - this.isByte = buffers.get(22); - this.isNot = buffers.get(23); - this.isOr = buffers.get(24); - this.isSignextend = buffers.get(25); - this.isXor = buffers.get(26); - this.low4 = buffers.get(27); - this.mli = buffers.get(28); - this.neg = buffers.get(29); - this.oneLineInstruction = buffers.get(30); - this.pivot = buffers.get(31); - this.resultHi = buffers.get(32); - this.resultLo = buffers.get(33); - this.small = buffers.get(34); - this.stamp = buffers.get(35); - this.xxxByteHi = buffers.get(36); - this.xxxByteLo = buffers.get(37); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace acc1(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("bin.ACC_1 already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc1.put((byte) 0); - } - acc1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc2(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("bin.ACC_2 already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc2.put((byte) 0); - } - acc2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc3(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("bin.ACC_3 already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc3.put((byte) 0); - } - acc3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc4(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("bin.ACC_4 already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc4.put((byte) 0); - } - acc4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc5(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("bin.ACC_5 already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc5.put((byte) 0); - } - acc5.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc6(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("bin.ACC_6 already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc6.put((byte) 0); - } - acc6.put(b.toArrayUnsafe()); - - return this; - } - - public Trace argument1Hi(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("bin.ARGUMENT_1_HI already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - argument1Hi.put((byte) 0); - } - argument1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace argument1Lo(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("bin.ARGUMENT_1_LO already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - argument1Lo.put((byte) 0); - } - argument1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace argument2Hi(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("bin.ARGUMENT_2_HI already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - argument2Hi.put((byte) 0); - } - argument2Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace argument2Lo(final Bytes b) { - if (filled.get(9)) { - throw new IllegalStateException("bin.ARGUMENT_2_LO already set"); - } else { - filled.set(9); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - argument2Lo.put((byte) 0); - } - argument2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace bit1(final Boolean b) { - if (filled.get(11)) { - throw new IllegalStateException("bin.BIT_1 already set"); - } else { - filled.set(11); - } - - bit1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bitB4(final Boolean b) { - if (filled.get(12)) { - throw new IllegalStateException("bin.BIT_B_4 already set"); - } else { - filled.set(12); - } - - bitB4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bits(final Boolean b) { - if (filled.get(10)) { - throw new IllegalStateException("bin.BITS already set"); - } else { - filled.set(10); - } - - bits.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace byte1(final UnsignedByte b) { - if (filled.get(13)) { - throw new IllegalStateException("bin.BYTE_1 already set"); - } else { - filled.set(13); - } - - byte1.put(b.toByte()); - - return this; - } - - public Trace byte2(final UnsignedByte b) { - if (filled.get(14)) { - throw new IllegalStateException("bin.BYTE_2 already set"); - } else { - filled.set(14); - } - - byte2.put(b.toByte()); - - return this; - } - - public Trace byte3(final UnsignedByte b) { - if (filled.get(15)) { - throw new IllegalStateException("bin.BYTE_3 already set"); - } else { - filled.set(15); - } - - byte3.put(b.toByte()); - - return this; - } - - public Trace byte4(final UnsignedByte b) { - if (filled.get(16)) { - throw new IllegalStateException("bin.BYTE_4 already set"); - } else { - filled.set(16); - } - - byte4.put(b.toByte()); - - return this; - } - - public Trace byte5(final UnsignedByte b) { - if (filled.get(17)) { - throw new IllegalStateException("bin.BYTE_5 already set"); - } else { - filled.set(17); - } - - byte5.put(b.toByte()); - - return this; - } - - public Trace byte6(final UnsignedByte b) { - if (filled.get(18)) { - throw new IllegalStateException("bin.BYTE_6 already set"); - } else { - filled.set(18); - } - - byte6.put(b.toByte()); - - return this; - } - - public Trace counter(final UnsignedByte b) { - if (filled.get(19)) { - throw new IllegalStateException("bin.COUNTER already set"); - } else { - filled.set(19); - } - - counter.put(b.toByte()); - - return this; - } - - public Trace inst(final UnsignedByte b) { - if (filled.get(20)) { - throw new IllegalStateException("bin.INST already set"); - } else { - filled.set(20); - } - - inst.put(b.toByte()); - - return this; - } - - public Trace isAnd(final Boolean b) { - if (filled.get(21)) { - throw new IllegalStateException("bin.IS_AND already set"); - } else { - filled.set(21); - } - - isAnd.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isByte(final Boolean b) { - if (filled.get(22)) { - throw new IllegalStateException("bin.IS_BYTE already set"); - } else { - filled.set(22); - } - - isByte.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isNot(final Boolean b) { - if (filled.get(23)) { - throw new IllegalStateException("bin.IS_NOT already set"); - } else { - filled.set(23); - } - - isNot.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isOr(final Boolean b) { - if (filled.get(24)) { - throw new IllegalStateException("bin.IS_OR already set"); - } else { - filled.set(24); - } - - isOr.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isSignextend(final Boolean b) { - if (filled.get(25)) { - throw new IllegalStateException("bin.IS_SIGNEXTEND already set"); - } else { - filled.set(25); - } - - isSignextend.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isXor(final Boolean b) { - if (filled.get(26)) { - throw new IllegalStateException("bin.IS_XOR already set"); - } else { - filled.set(26); - } - - isXor.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace low4(final UnsignedByte b) { - if (filled.get(27)) { - throw new IllegalStateException("bin.LOW_4 already set"); - } else { - filled.set(27); - } - - low4.put(b.toByte()); - - return this; - } - - public Trace mli(final Boolean b) { - if (filled.get(28)) { - throw new IllegalStateException("bin.MLI already set"); - } else { - filled.set(28); - } - - mli.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace neg(final Boolean b) { - if (filled.get(29)) { - throw new IllegalStateException("bin.NEG already set"); - } else { - filled.set(29); - } - - neg.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace oneLineInstruction(final Boolean b) { - if (filled.get(30)) { - throw new IllegalStateException("bin.ONE_LINE_INSTRUCTION already set"); - } else { - filled.set(30); - } - - oneLineInstruction.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pivot(final UnsignedByte b) { - if (filled.get(31)) { - throw new IllegalStateException("bin.PIVOT already set"); - } else { - filled.set(31); - } - - pivot.put(b.toByte()); - - return this; - } - - public Trace resultHi(final Bytes b) { - if (filled.get(32)) { - throw new IllegalStateException("bin.RESULT_HI already set"); - } else { - filled.set(32); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resultHi.put((byte) 0); - } - resultHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace resultLo(final Bytes b) { - if (filled.get(33)) { - throw new IllegalStateException("bin.RESULT_LO already set"); - } else { - filled.set(33); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resultLo.put((byte) 0); - } - resultLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace small(final Boolean b) { - if (filled.get(34)) { - throw new IllegalStateException("bin.SMALL already set"); - } else { - filled.set(34); - } - - small.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace stamp(final Bytes b) { - if (filled.get(35)) { - throw new IllegalStateException("bin.STAMP already set"); - } else { - filled.set(35); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stamp.put((byte) 0); - } - stamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace xxxByteHi(final UnsignedByte b) { - if (filled.get(36)) { - throw new IllegalStateException("bin.XXX_BYTE_HI already set"); - } else { - filled.set(36); - } - - xxxByteHi.put(b.toByte()); - - return this; - } - - public Trace xxxByteLo(final UnsignedByte b) { - if (filled.get(37)) { - throw new IllegalStateException("bin.XXX_BYTE_LO already set"); - } else { - filled.set(37); - } - - xxxByteLo.put(b.toByte()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("bin.ACC_1 has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("bin.ACC_2 has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("bin.ACC_3 has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("bin.ACC_4 has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("bin.ACC_5 has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("bin.ACC_6 has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("bin.ARGUMENT_1_HI has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("bin.ARGUMENT_1_LO has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("bin.ARGUMENT_2_HI has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("bin.ARGUMENT_2_LO has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("bin.BIT_1 has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("bin.BIT_B_4 has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("bin.BITS has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("bin.BYTE_1 has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("bin.BYTE_2 has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("bin.BYTE_3 has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("bin.BYTE_4 has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("bin.BYTE_5 has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("bin.BYTE_6 has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("bin.COUNTER has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("bin.INST has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("bin.IS_AND has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("bin.IS_BYTE has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("bin.IS_NOT has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("bin.IS_OR has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("bin.IS_SIGNEXTEND has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("bin.IS_XOR has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("bin.LOW_4 has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("bin.MLI has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("bin.NEG has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("bin.ONE_LINE_INSTRUCTION has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("bin.PIVOT has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("bin.RESULT_HI has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("bin.RESULT_LO has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("bin.SMALL has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("bin.STAMP has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("bin.XXX_BYTE_HI has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("bin.XXX_BYTE_LO has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - acc1.position(acc1.position() + 32); - } - - if (!filled.get(1)) { - acc2.position(acc2.position() + 32); - } - - if (!filled.get(2)) { - acc3.position(acc3.position() + 32); - } - - if (!filled.get(3)) { - acc4.position(acc4.position() + 32); - } - - if (!filled.get(4)) { - acc5.position(acc5.position() + 32); - } - - if (!filled.get(5)) { - acc6.position(acc6.position() + 32); - } - - if (!filled.get(6)) { - argument1Hi.position(argument1Hi.position() + 32); - } - - if (!filled.get(7)) { - argument1Lo.position(argument1Lo.position() + 32); - } - - if (!filled.get(8)) { - argument2Hi.position(argument2Hi.position() + 32); - } - - if (!filled.get(9)) { - argument2Lo.position(argument2Lo.position() + 32); - } - - if (!filled.get(11)) { - bit1.position(bit1.position() + 1); - } - - if (!filled.get(12)) { - bitB4.position(bitB4.position() + 1); - } - - if (!filled.get(10)) { - bits.position(bits.position() + 1); - } - - if (!filled.get(13)) { - byte1.position(byte1.position() + 1); - } - - if (!filled.get(14)) { - byte2.position(byte2.position() + 1); - } - - if (!filled.get(15)) { - byte3.position(byte3.position() + 1); - } - - if (!filled.get(16)) { - byte4.position(byte4.position() + 1); - } - - if (!filled.get(17)) { - byte5.position(byte5.position() + 1); - } - - if (!filled.get(18)) { - byte6.position(byte6.position() + 1); - } - - if (!filled.get(19)) { - counter.position(counter.position() + 1); - } - - if (!filled.get(20)) { - inst.position(inst.position() + 1); - } - - if (!filled.get(21)) { - isAnd.position(isAnd.position() + 1); - } - - if (!filled.get(22)) { - isByte.position(isByte.position() + 1); - } - - if (!filled.get(23)) { - isNot.position(isNot.position() + 1); - } - - if (!filled.get(24)) { - isOr.position(isOr.position() + 1); - } - - if (!filled.get(25)) { - isSignextend.position(isSignextend.position() + 1); - } - - if (!filled.get(26)) { - isXor.position(isXor.position() + 1); - } - - if (!filled.get(27)) { - low4.position(low4.position() + 1); - } - - if (!filled.get(28)) { - mli.position(mli.position() + 1); - } - - if (!filled.get(29)) { - neg.position(neg.position() + 1); - } - - if (!filled.get(30)) { - oneLineInstruction.position(oneLineInstruction.position() + 1); - } - - if (!filled.get(31)) { - pivot.position(pivot.position() + 1); - } - - if (!filled.get(32)) { - resultHi.position(resultHi.position() + 32); - } - - if (!filled.get(33)) { - resultLo.position(resultLo.position() + 32); - } - - if (!filled.get(34)) { - small.position(small.position() + 1); - } - - if (!filled.get(35)) { - stamp.position(stamp.position() + 32); - } - - if (!filled.get(36)) { - xxxByteHi.position(xxxByteHi.position() + 1); - } - - if (!filled.get(37)) { - xxxByteLo.position(xxxByteLo.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/EcData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/EcData.java deleted file mode 100644 index fc62ce71e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/EcData.java +++ /dev/null @@ -1,126 +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.ec_data; - -import java.nio.MappedByteBuffer; -import java.util.List; -import java.util.Set; - -import lombok.RequiredArgsConstructor; -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.ext.Ext; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.wcp.Wcp; -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 class EcData implements Module { - private static final Set

EC_PRECOMPILES = - Set.of(Address.ECREC, Address.ALTBN128_ADD, Address.ALTBN128_MUL, Address.ALTBN128_PAIRING); - - private final StackedSet operations = new StackedSet<>(); - private final Hub hub; - private final Wcp wcp; - private final Ext ext; - private int previousContextNumber = 0; - - @Override - public String moduleKey() { - return "EC_DATA"; - } - - @Override - public void enterTransaction() { - this.operations.enter(); - } - - @Override - public void popTransaction() { - this.operations.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - // TODO: in the PCH - if (frame.stackSize() < 5) { - return; - } - - switch (opCode) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final Address to = Words.toAddress(frame.getStackItem(1)); - if (!EC_PRECOMPILES.contains(to)) { - return; - } - - long length = 0; - long offset = 0; - switch (opCode) { - case CALL, CALLCODE -> { - length = Words.clampedToLong(frame.getStackItem(4)); - offset = Words.clampedToLong(frame.getStackItem(3)); - } - case DELEGATECALL, STATICCALL -> { - length = Words.clampedToLong(frame.getStackItem(3)); - offset = Words.clampedToLong(frame.getStackItem(2)); - } - } - - if (to.equals(Address.ALTBN128_PAIRING) && (length == 0 || length % 192 != 0)) { - return; - } - - final Bytes input = frame.shadowReadMemory(offset, length); - - this.operations.add( - EcDataOperation.of( - this.wcp, - this.ext, - to, - input, - this.hub.currentFrame().contextNumber(), - this.previousContextNumber)); - this.previousContextNumber = this.hub.currentFrame().contextNumber(); - } - default -> {} - } - } - - @Override - public int lineCount() { - return this.operations.lineCount(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - for (EcDataOperation op : this.operations) { - op.trace(trace); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/EcDataOperation.java deleted file mode 100644 index 80eb5b1ef..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/EcDataOperation.java +++ /dev/null @@ -1,352 +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.ec_data; - -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.experimental.Accessors; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.module.ext.Ext; -import net.consensys.linea.zktracer.module.wcp.Wcp; -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.Address; - -@Accessors(fluent = true) -public class EcDataOperation extends ModuleOperation { - private static final int EC_RECOVER = 1; - private static final int EC_ADD = 6; - private static final int EC_MUL = 7; - private static final int EC_PAIRING = 8; - private static final Set EC_TYPES = Set.of(EC_RECOVER, EC_ADD, EC_MUL, EC_PAIRING); - - private static final EWord P = - EWord.ofHexString("0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47"); - private static final EWord Q = - EWord.ofHexString("0x30644E72E131A029B85045B68181585D2833E84879B9709143E1F593F0000001"); - private static final EWord SECP256_K1N = - EWord.ofHexString("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"); - - private final Wcp wcp; - private final Ext ext; - - private final int contextNumber; - private final int contextNumberDelta; - private final Bytes input; - - private final int ecType; - private final int nRows; - /** -1 if no switch off (i.e. preliminary checks passed) */ - private int hurdleSwitchOffRow; - - private final List comparisons; - private final List equalities; - private final List squares; - private final List cubes; - private final List limbs; - - // WCP interaction - private final List wcpArg1; - private final List wcpArg2; - private final List wcpInst; - private final List wcpRes; - - // EXT interaction - private final List extArg1; - private final List extArg2; - private final List extArg3; - private final List extInst; - private final List extRes; - - // pairing-specific - private int thisIsNotOnG2Index; - private final int nPairings; - - private static int addressToEcType(final Address target) { - if (target.equals(Address.ECREC)) { - return EC_RECOVER; - } else if (target.equals(Address.ALTBN128_ADD)) { - return EC_ADD; - } else if (target.equals(Address.ALTBN128_MUL)) { - return EC_MUL; - } else if (target.equals(Address.ALTBN128_PAIRING)) { - return EC_PAIRING; - } else { - throw new IllegalArgumentException("invalid EC address"); - } - } - - private static int ecTypeToNRows(int ecType, final Bytes input) { - return switch (ecType) { - case EC_RECOVER, EC_ADD -> 8; - case EC_MUL -> 6; - case EC_PAIRING -> input.size() / 16; - default -> throw new IllegalArgumentException("invalid EC type"); - }; - } - - private static boolean isOnG2(Bytes arg) { - return true; // TODO: - } - - private static boolean isInfinity() { - return false; // TODO: - } - - private EcDataOperation( - Wcp wcp, Ext ext, int contextNumber, int previousContextNumber, int ecType, Bytes input) { - Preconditions.checkArgument(EC_TYPES.contains(ecType), "invalid EC type"); - - final int nRows = ecTypeToNRows(ecType, input); - final int minInputLength = ecType == EC_MUL ? 96 : 128; - if (input.size() < minInputLength) { - this.input = leftPadTo(input, minInputLength); - } else { - this.input = input; - } - this.contextNumber = contextNumber; - this.contextNumberDelta = contextNumber - previousContextNumber; - this.ecType = ecType; - this.nRows = nRows; - this.thisIsNotOnG2Index = -1; - if (ecType == EC_PAIRING) { - this.nPairings = input.size() / 192; - } else { - this.nPairings = 0; - } - - this.comparisons = repeat(false, nRows / 2); - this.equalities = repeat(false, nRows); - this.squares = repeat(Bytes.EMPTY, nRows / 2); - this.cubes = repeat(Bytes.EMPTY, nRows / 2); - this.limbs = repeat(Bytes.EMPTY, nRows / 2); - - this.wcpArg1 = repeat(Bytes.EMPTY, nRows); - this.wcpArg2 = repeat(Bytes.EMPTY, nRows); - this.wcpInst = repeat(OpCode.INVALID, nRows); - this.wcpRes = repeat(false, nRows); - - this.extArg1 = repeat(Bytes.EMPTY, nRows); - this.extArg2 = repeat(Bytes.EMPTY, nRows); - this.extArg3 = repeat(Bytes.EMPTY, nRows); - this.extInst = repeat(OpCode.INVALID, nRows); - this.extRes = repeat(Bytes.EMPTY, nRows); - - this.wcp = wcp; - this.ext = ext; - } - - public static EcDataOperation of( - Wcp wcp, - Ext ext, - final Address to, - Bytes input, - int currentContextNumber, - int previousContextNumber) { - final int ecType = addressToEcType(to); - - EcDataOperation r = - new EcDataOperation(wcp, ext, currentContextNumber, previousContextNumber, ecType, input); - switch (ecType) { - case EC_RECOVER -> r.handleRecover(); - case EC_ADD -> r.handleAdd(); - case EC_MUL -> r.handleMul(); - case EC_PAIRING -> r.handlePairing(); - } - return r; - } - - private boolean preliminaryChecksPassed() { - return this.hurdleSwitchOffRow == -1; - } - - private boolean callWcp(int i, OpCode inst, Bytes arg1, Bytes arg2) { - final boolean r = - switch (inst) { - case LT -> this.wcp.callLT(arg1, arg2); - case EQ -> this.wcp.callEQ(arg1, arg2); - default -> throw new IllegalStateException("Unexpected value: " + inst); - }; - - this.wcpArg1.set(i, arg1); - this.wcpArg2.set(i, arg2); - this.wcpInst.set(i, inst); - this.wcpRes.set(i, r); - return r; - } - - private Bytes callExt(int i, OpCode opCode, Bytes arg1, Bytes arg2, Bytes arg3) { - final Bytes result = ext.call(opCode, arg1, arg2, arg3); - this.extArg1.set(i, arg1); - this.extArg2.set(i, arg2); - this.extArg3.set(i, arg3); - this.extInst.set(i, opCode); - this.extRes.set(i, result); - - return result; - } - - private void fillHurdle() { - for (int i = 0; i < this.nRows; i++) { - boolean check = false; - switch (i % 4) { - case 1 -> { - check = true; - } - case 0, 2 -> { - check = this.comparisons.get(i / 2); - } - case 3 -> { - check = this.equalities.get(i); - } - } - if (!check) { - this.hurdleSwitchOffRow = i; - return; - } - } - - this.hurdleSwitchOffRow = -1; - } - - void handleRecover() { - final Bytes v = this.input.slice(32, 32); - final Bytes r = this.input.slice(64, 32); - final Bytes s = this.input.slice(96, 32); - - this.comparisons.set(0, this.callWcp(0, OpCode.LT, r, SECP256_K1N)); // r < secp256k1N - this.comparisons.set(2, this.callWcp(1, OpCode.LT, s, SECP256_K1N)); // s < secp256k1N - this.comparisons.set(1, this.callWcp(2, OpCode.LT, Bytes.EMPTY, r)); // 0 < r - this.comparisons.set(3, this.callWcp(3, OpCode.LT, Bytes.EMPTY, s)); // 0 < s - this.equalities.set(1, this.callWcp(4, OpCode.EQ, v, Bytes.of(27))); // v == 27 - this.equalities.set(2, this.callWcp(5, OpCode.EQ, v, Bytes.of(28))); // v == 28 - this.equalities.set(3, this.equalities.get(1) || this.equalities.get(2)); - this.equalities.set(7, true); - - this.fillHurdle(); - - // Very unlikely edge case: if the ext module is never used elsewhere, we need to insert a - // useless row, in order to trigger the construction of the first empty row, useful for the ext - // lookup. - // Because of the hashmap in the ext module, this useless row will only be inserted one time. - // Tested by TestEcRecoverWithEmptyExt - this.ext.callADDMOD(Bytes.EMPTY, Bytes.EMPTY, Bytes.EMPTY); - } - - private void handlePointOnC1(final Bytes x, final Bytes y, int u, int i) { - this.squares.set( - 6 * i + 2 * u, this.callExt(12 * i + 4 * u, OpCode.MULMOD, x, x, P)); // x² mod p - this.squares.set( - 1 + 2 * u + 6 * i, this.callExt(1 + 4 * u + 12 * i, OpCode.MULMOD, y, y, P)); // y² mod p - this.cubes.set( - 2 * u + 6 * i, - this.callExt( - 2 + 4 * u + 12 * i, OpCode.MULMOD, this.squares.get(2 * u + 6 * i), x, P)); // x³ mod p - this.cubes.set( - 1 + 2 * u + 6 * i, - this.callExt( - 3 + 4 * u + 12 * i, - OpCode.ADDMOD, - this.cubes.get(2 * u + 6 * i), - Bytes.of(3), - P)); // x³ + 3 mod p - - this.comparisons.set(2 * u + 6 * i, this.callWcp(4 * u + 12 * i, OpCode.LT, x, P)); // x < p - this.comparisons.set( - 1 + 2 * u + 6 * i, this.callWcp(1 + 4 * u + 12 * i, OpCode.LT, y, P)); // y < p - - this.equalities.set( - 1 + 4 * u + 12 * i, - this.callWcp( - 2 + 4 * u + 12 * i, - OpCode.EQ, - this.squares.get(1 + 2 * u + 6 * i), - this.cubes.get(1 + 2 * u + 6 * i))); // y² = x³ + 3 - this.equalities.set(2 + 4 * u + 12 * i, x.isZero() && y.isZero()); // (x, y) == (0, 0) - this.equalities.set( - 3 + 4 * u + 12 * i, - this.equalities.get(1 + 4 * u + 12 * i) || this.equalities.get(2 + 4 * u + 12 * i)); - } - - void handleAdd() { - for (int u = 0; u < 2; u++) { - final Bytes x = this.input.slice(64 * u, 32); - final Bytes y = this.input.slice(64 * u + 32, 32); - this.handlePointOnC1(x, y, u, 0); - } - } - - void handleMul() { - final Bytes x = this.input.slice(0, 32); - final Bytes y = this.input.slice(32, 32); - this.handlePointOnC1(x, y, 0, 0); - this.comparisons.set(2, true); - this.fillHurdle(); - } - - void handlePairing() { - for (int i = 0; i < this.nPairings; i++) { - final Bytes x = this.input.slice(i * 192, 32); - final Bytes y = this.input.slice(i * 192 + 32, 32); - final Bytes aIm = this.input.slice(i * 192 + 64, 32); - final Bytes aRe = this.input.slice(i * 192 + 96, 32); - final Bytes bIm = this.input.slice(i * 192 + 128, 32); - final Bytes bRe = this.input.slice(i * 192 + 160, 32); - - this.handlePointOnC1(x, y, 0, i); - - this.comparisons.set(6 * i + 2, this.callWcp(12 * i + 3, OpCode.LT, aIm, P)); - this.comparisons.set(6 * i + 3, this.callWcp(12 * i + 4, OpCode.LT, aRe, P)); - this.comparisons.set(6 * i + 4, this.callWcp(12 * i + 5, OpCode.LT, bIm, P)); - this.comparisons.set(6 * i + 5, this.callWcp(12 * i + 6, OpCode.LT, bRe, P)); - this.equalities.set(12 * i + 7, true); - this.equalities.set(12 * i + 11, true); - } - - this.fillHurdle(); - - if (this.preliminaryChecksPassed()) { - for (int i = 0; i < this.nPairings; i++) { - if (!isOnG2(this.input.slice(192 * i + 64, 192 - 64))) { - this.thisIsNotOnG2Index = i; - break; - } - } - } - } - - private void traceRow(Trace trace, int i) { - trace.stamp(Bytes.ofUnsignedShort(this.contextNumber)); - // TODO: the rest - } - - void trace(Trace trace) { - for (int i = 0; i < this.nRows; i++) { - this.traceRow(trace, i); - } - } - - @Override - protected int computeLineCount() { - return this.nRows; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/Trace.java deleted file mode 100644 index d7d4abfae..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ec_data/Trace.java +++ /dev/null @@ -1,1046 +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.ec_data; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer accDelta; - private final MappedByteBuffer accPairings; - private final MappedByteBuffer allChecksPassed; - private final MappedByteBuffer byteDelta; - private final MappedByteBuffer comparisons; - private final MappedByteBuffer ctMin; - private final MappedByteBuffer cube; - private final MappedByteBuffer ecAdd; - private final MappedByteBuffer ecMul; - private final MappedByteBuffer ecPairing; - private final MappedByteBuffer ecRecover; - private final MappedByteBuffer equalities; - private final MappedByteBuffer extArg1Hi; - private final MappedByteBuffer extArg1Lo; - private final MappedByteBuffer extArg2Hi; - private final MappedByteBuffer extArg2Lo; - private final MappedByteBuffer extArg3Hi; - private final MappedByteBuffer extArg3Lo; - private final MappedByteBuffer extInst; - private final MappedByteBuffer extResHi; - private final MappedByteBuffer extResLo; - private final MappedByteBuffer hurdle; - private final MappedByteBuffer index; - private final MappedByteBuffer limb; - private final MappedByteBuffer preliminaryChecksPassed; - private final MappedByteBuffer somethingWasntOnG2; - private final MappedByteBuffer square; - private final MappedByteBuffer stamp; - private final MappedByteBuffer thisIsNotOnG2; - private final MappedByteBuffer thisIsNotOnG2Acc; - private final MappedByteBuffer totalPairings; - private final MappedByteBuffer type; - private final MappedByteBuffer wcpArg1Hi; - private final MappedByteBuffer wcpArg1Lo; - private final MappedByteBuffer wcpArg2Hi; - private final MappedByteBuffer wcpArg2Lo; - private final MappedByteBuffer wcpInst; - private final MappedByteBuffer wcpRes; - - static List headers(int length) { - return List.of( - new ColumnHeader("ec_data.ACC_DELTA", 32, length), - new ColumnHeader("ec_data.ACC_PAIRINGS", 32, length), - new ColumnHeader("ec_data.ALL_CHECKS_PASSED", 1, length), - new ColumnHeader("ec_data.BYTE_DELTA", 1, length), - new ColumnHeader("ec_data.COMPARISONS", 1, length), - new ColumnHeader("ec_data.CT_MIN", 32, length), - new ColumnHeader("ec_data.CUBE", 32, length), - new ColumnHeader("ec_data.EC_ADD", 1, length), - new ColumnHeader("ec_data.EC_MUL", 1, length), - new ColumnHeader("ec_data.EC_PAIRING", 1, length), - new ColumnHeader("ec_data.EC_RECOVER", 1, length), - new ColumnHeader("ec_data.EQUALITIES", 1, length), - new ColumnHeader("ec_data.EXT_ARG1_HI", 32, length), - new ColumnHeader("ec_data.EXT_ARG1_LO", 32, length), - new ColumnHeader("ec_data.EXT_ARG2_HI", 32, length), - new ColumnHeader("ec_data.EXT_ARG2_LO", 32, length), - new ColumnHeader("ec_data.EXT_ARG3_HI", 32, length), - new ColumnHeader("ec_data.EXT_ARG3_LO", 32, length), - new ColumnHeader("ec_data.EXT_INST", 32, length), - new ColumnHeader("ec_data.EXT_RES_HI", 32, length), - new ColumnHeader("ec_data.EXT_RES_LO", 32, length), - new ColumnHeader("ec_data.HURDLE", 1, length), - new ColumnHeader("ec_data.INDEX", 32, length), - new ColumnHeader("ec_data.LIMB", 32, length), - new ColumnHeader("ec_data.PRELIMINARY_CHECKS_PASSED", 1, length), - new ColumnHeader("ec_data.SOMETHING_WASNT_ON_G2", 1, length), - new ColumnHeader("ec_data.SQUARE", 32, length), - new ColumnHeader("ec_data.STAMP", 32, length), - new ColumnHeader("ec_data.THIS_IS_NOT_ON_G2", 1, length), - new ColumnHeader("ec_data.THIS_IS_NOT_ON_G2_ACC", 1, length), - new ColumnHeader("ec_data.TOTAL_PAIRINGS", 32, length), - new ColumnHeader("ec_data.TYPE", 32, length), - new ColumnHeader("ec_data.WCP_ARG1_HI", 32, length), - new ColumnHeader("ec_data.WCP_ARG1_LO", 32, length), - new ColumnHeader("ec_data.WCP_ARG2_HI", 32, length), - new ColumnHeader("ec_data.WCP_ARG2_LO", 32, length), - new ColumnHeader("ec_data.WCP_INST", 32, length), - new ColumnHeader("ec_data.WCP_RES", 32, length)); - } - - public Trace(List buffers) { - this.accDelta = buffers.get(0); - this.accPairings = buffers.get(1); - this.allChecksPassed = buffers.get(2); - this.byteDelta = buffers.get(3); - this.comparisons = buffers.get(4); - this.ctMin = buffers.get(5); - this.cube = buffers.get(6); - this.ecAdd = buffers.get(7); - this.ecMul = buffers.get(8); - this.ecPairing = buffers.get(9); - this.ecRecover = buffers.get(10); - this.equalities = buffers.get(11); - this.extArg1Hi = buffers.get(12); - this.extArg1Lo = buffers.get(13); - this.extArg2Hi = buffers.get(14); - this.extArg2Lo = buffers.get(15); - this.extArg3Hi = buffers.get(16); - this.extArg3Lo = buffers.get(17); - this.extInst = buffers.get(18); - this.extResHi = buffers.get(19); - this.extResLo = buffers.get(20); - this.hurdle = buffers.get(21); - this.index = buffers.get(22); - this.limb = buffers.get(23); - this.preliminaryChecksPassed = buffers.get(24); - this.somethingWasntOnG2 = buffers.get(25); - this.square = buffers.get(26); - this.stamp = buffers.get(27); - this.thisIsNotOnG2 = buffers.get(28); - this.thisIsNotOnG2Acc = buffers.get(29); - this.totalPairings = buffers.get(30); - this.type = buffers.get(31); - this.wcpArg1Hi = buffers.get(32); - this.wcpArg1Lo = buffers.get(33); - this.wcpArg2Hi = buffers.get(34); - this.wcpArg2Lo = buffers.get(35); - this.wcpInst = buffers.get(36); - this.wcpRes = buffers.get(37); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace accDelta(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("ec_data.ACC_DELTA already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accDelta.put((byte) 0); - } - accDelta.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accPairings(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("ec_data.ACC_PAIRINGS already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accPairings.put((byte) 0); - } - accPairings.put(b.toArrayUnsafe()); - - return this; - } - - public Trace allChecksPassed(final Boolean b) { - if (filled.get(2)) { - throw new IllegalStateException("ec_data.ALL_CHECKS_PASSED already set"); - } else { - filled.set(2); - } - - allChecksPassed.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace byteDelta(final UnsignedByte b) { - if (filled.get(3)) { - throw new IllegalStateException("ec_data.BYTE_DELTA already set"); - } else { - filled.set(3); - } - - byteDelta.put(b.toByte()); - - return this; - } - - public Trace comparisons(final Boolean b) { - if (filled.get(4)) { - throw new IllegalStateException("ec_data.COMPARISONS already set"); - } else { - filled.set(4); - } - - comparisons.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ctMin(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("ec_data.CT_MIN already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - ctMin.put((byte) 0); - } - ctMin.put(b.toArrayUnsafe()); - - return this; - } - - public Trace cube(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("ec_data.CUBE already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - cube.put((byte) 0); - } - cube.put(b.toArrayUnsafe()); - - return this; - } - - public Trace ecAdd(final Boolean b) { - if (filled.get(7)) { - throw new IllegalStateException("ec_data.EC_ADD already set"); - } else { - filled.set(7); - } - - ecAdd.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ecMul(final Boolean b) { - if (filled.get(8)) { - throw new IllegalStateException("ec_data.EC_MUL already set"); - } else { - filled.set(8); - } - - ecMul.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ecPairing(final Boolean b) { - if (filled.get(9)) { - throw new IllegalStateException("ec_data.EC_PAIRING already set"); - } else { - filled.set(9); - } - - ecPairing.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ecRecover(final Boolean b) { - if (filled.get(10)) { - throw new IllegalStateException("ec_data.EC_RECOVER already set"); - } else { - filled.set(10); - } - - ecRecover.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace equalities(final Boolean b) { - if (filled.get(11)) { - throw new IllegalStateException("ec_data.EQUALITIES already set"); - } else { - filled.set(11); - } - - equalities.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace extArg1Hi(final Bytes b) { - if (filled.get(12)) { - throw new IllegalStateException("ec_data.EXT_ARG1_HI already set"); - } else { - filled.set(12); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - extArg1Hi.put((byte) 0); - } - extArg1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace extArg1Lo(final Bytes b) { - if (filled.get(13)) { - throw new IllegalStateException("ec_data.EXT_ARG1_LO already set"); - } else { - filled.set(13); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - extArg1Lo.put((byte) 0); - } - extArg1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace extArg2Hi(final Bytes b) { - if (filled.get(14)) { - throw new IllegalStateException("ec_data.EXT_ARG2_HI already set"); - } else { - filled.set(14); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - extArg2Hi.put((byte) 0); - } - extArg2Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace extArg2Lo(final Bytes b) { - if (filled.get(15)) { - throw new IllegalStateException("ec_data.EXT_ARG2_LO already set"); - } else { - filled.set(15); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - extArg2Lo.put((byte) 0); - } - extArg2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace extArg3Hi(final Bytes b) { - if (filled.get(16)) { - throw new IllegalStateException("ec_data.EXT_ARG3_HI already set"); - } else { - filled.set(16); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - extArg3Hi.put((byte) 0); - } - extArg3Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace extArg3Lo(final Bytes b) { - if (filled.get(17)) { - throw new IllegalStateException("ec_data.EXT_ARG3_LO already set"); - } else { - filled.set(17); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - extArg3Lo.put((byte) 0); - } - extArg3Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace extInst(final Bytes b) { - if (filled.get(18)) { - throw new IllegalStateException("ec_data.EXT_INST already set"); - } else { - filled.set(18); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - extInst.put((byte) 0); - } - extInst.put(b.toArrayUnsafe()); - - return this; - } - - public Trace extResHi(final Bytes b) { - if (filled.get(19)) { - throw new IllegalStateException("ec_data.EXT_RES_HI already set"); - } else { - filled.set(19); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - extResHi.put((byte) 0); - } - extResHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace extResLo(final Bytes b) { - if (filled.get(20)) { - throw new IllegalStateException("ec_data.EXT_RES_LO already set"); - } else { - filled.set(20); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - extResLo.put((byte) 0); - } - extResLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace hurdle(final Boolean b) { - if (filled.get(21)) { - throw new IllegalStateException("ec_data.HURDLE already set"); - } else { - filled.set(21); - } - - hurdle.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace index(final Bytes b) { - if (filled.get(22)) { - throw new IllegalStateException("ec_data.INDEX already set"); - } else { - filled.set(22); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - index.put((byte) 0); - } - index.put(b.toArrayUnsafe()); - - return this; - } - - public Trace limb(final Bytes b) { - if (filled.get(23)) { - throw new IllegalStateException("ec_data.LIMB already set"); - } else { - filled.set(23); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - limb.put((byte) 0); - } - limb.put(b.toArrayUnsafe()); - - return this; - } - - public Trace preliminaryChecksPassed(final Boolean b) { - if (filled.get(24)) { - throw new IllegalStateException("ec_data.PRELIMINARY_CHECKS_PASSED already set"); - } else { - filled.set(24); - } - - preliminaryChecksPassed.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace somethingWasntOnG2(final Boolean b) { - if (filled.get(25)) { - throw new IllegalStateException("ec_data.SOMETHING_WASNT_ON_G2 already set"); - } else { - filled.set(25); - } - - somethingWasntOnG2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace square(final Bytes b) { - if (filled.get(26)) { - throw new IllegalStateException("ec_data.SQUARE already set"); - } else { - filled.set(26); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - square.put((byte) 0); - } - square.put(b.toArrayUnsafe()); - - return this; - } - - public Trace stamp(final Bytes b) { - if (filled.get(27)) { - throw new IllegalStateException("ec_data.STAMP already set"); - } else { - filled.set(27); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stamp.put((byte) 0); - } - stamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace thisIsNotOnG2(final Boolean b) { - if (filled.get(28)) { - throw new IllegalStateException("ec_data.THIS_IS_NOT_ON_G2 already set"); - } else { - filled.set(28); - } - - thisIsNotOnG2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace thisIsNotOnG2Acc(final Boolean b) { - if (filled.get(29)) { - throw new IllegalStateException("ec_data.THIS_IS_NOT_ON_G2_ACC already set"); - } else { - filled.set(29); - } - - thisIsNotOnG2Acc.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace totalPairings(final Bytes b) { - if (filled.get(30)) { - throw new IllegalStateException("ec_data.TOTAL_PAIRINGS already set"); - } else { - filled.set(30); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - totalPairings.put((byte) 0); - } - totalPairings.put(b.toArrayUnsafe()); - - return this; - } - - public Trace type(final Bytes b) { - if (filled.get(31)) { - throw new IllegalStateException("ec_data.TYPE already set"); - } else { - filled.set(31); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - type.put((byte) 0); - } - type.put(b.toArrayUnsafe()); - - return this; - } - - public Trace wcpArg1Hi(final Bytes b) { - if (filled.get(32)) { - throw new IllegalStateException("ec_data.WCP_ARG1_HI already set"); - } else { - filled.set(32); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - wcpArg1Hi.put((byte) 0); - } - wcpArg1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace wcpArg1Lo(final Bytes b) { - if (filled.get(33)) { - throw new IllegalStateException("ec_data.WCP_ARG1_LO already set"); - } else { - filled.set(33); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - wcpArg1Lo.put((byte) 0); - } - wcpArg1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace wcpArg2Hi(final Bytes b) { - if (filled.get(34)) { - throw new IllegalStateException("ec_data.WCP_ARG2_HI already set"); - } else { - filled.set(34); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - wcpArg2Hi.put((byte) 0); - } - wcpArg2Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace wcpArg2Lo(final Bytes b) { - if (filled.get(35)) { - throw new IllegalStateException("ec_data.WCP_ARG2_LO already set"); - } else { - filled.set(35); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - wcpArg2Lo.put((byte) 0); - } - wcpArg2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace wcpInst(final Bytes b) { - if (filled.get(36)) { - throw new IllegalStateException("ec_data.WCP_INST already set"); - } else { - filled.set(36); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - wcpInst.put((byte) 0); - } - wcpInst.put(b.toArrayUnsafe()); - - return this; - } - - public Trace wcpRes(final Bytes b) { - if (filled.get(37)) { - throw new IllegalStateException("ec_data.WCP_RES already set"); - } else { - filled.set(37); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - wcpRes.put((byte) 0); - } - wcpRes.put(b.toArrayUnsafe()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("ec_data.ACC_DELTA has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("ec_data.ACC_PAIRINGS has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("ec_data.ALL_CHECKS_PASSED has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("ec_data.BYTE_DELTA has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("ec_data.COMPARISONS has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("ec_data.CT_MIN has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("ec_data.CUBE has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("ec_data.EC_ADD has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("ec_data.EC_MUL has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("ec_data.EC_PAIRING has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("ec_data.EC_RECOVER has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("ec_data.EQUALITIES has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("ec_data.EXT_ARG1_HI has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("ec_data.EXT_ARG1_LO has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("ec_data.EXT_ARG2_HI has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("ec_data.EXT_ARG2_LO has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("ec_data.EXT_ARG3_HI has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("ec_data.EXT_ARG3_LO has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("ec_data.EXT_INST has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("ec_data.EXT_RES_HI has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("ec_data.EXT_RES_LO has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("ec_data.HURDLE has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("ec_data.INDEX has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("ec_data.LIMB has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("ec_data.PRELIMINARY_CHECKS_PASSED has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("ec_data.SOMETHING_WASNT_ON_G2 has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("ec_data.SQUARE has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("ec_data.STAMP has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("ec_data.THIS_IS_NOT_ON_G2 has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("ec_data.THIS_IS_NOT_ON_G2_ACC has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("ec_data.TOTAL_PAIRINGS has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("ec_data.TYPE has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("ec_data.WCP_ARG1_HI has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("ec_data.WCP_ARG1_LO has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("ec_data.WCP_ARG2_HI has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("ec_data.WCP_ARG2_LO has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("ec_data.WCP_INST has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("ec_data.WCP_RES has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - accDelta.position(accDelta.position() + 32); - } - - if (!filled.get(1)) { - accPairings.position(accPairings.position() + 32); - } - - if (!filled.get(2)) { - allChecksPassed.position(allChecksPassed.position() + 1); - } - - if (!filled.get(3)) { - byteDelta.position(byteDelta.position() + 1); - } - - if (!filled.get(4)) { - comparisons.position(comparisons.position() + 1); - } - - if (!filled.get(5)) { - ctMin.position(ctMin.position() + 32); - } - - if (!filled.get(6)) { - cube.position(cube.position() + 32); - } - - if (!filled.get(7)) { - ecAdd.position(ecAdd.position() + 1); - } - - if (!filled.get(8)) { - ecMul.position(ecMul.position() + 1); - } - - if (!filled.get(9)) { - ecPairing.position(ecPairing.position() + 1); - } - - if (!filled.get(10)) { - ecRecover.position(ecRecover.position() + 1); - } - - if (!filled.get(11)) { - equalities.position(equalities.position() + 1); - } - - if (!filled.get(12)) { - extArg1Hi.position(extArg1Hi.position() + 32); - } - - if (!filled.get(13)) { - extArg1Lo.position(extArg1Lo.position() + 32); - } - - if (!filled.get(14)) { - extArg2Hi.position(extArg2Hi.position() + 32); - } - - if (!filled.get(15)) { - extArg2Lo.position(extArg2Lo.position() + 32); - } - - if (!filled.get(16)) { - extArg3Hi.position(extArg3Hi.position() + 32); - } - - if (!filled.get(17)) { - extArg3Lo.position(extArg3Lo.position() + 32); - } - - if (!filled.get(18)) { - extInst.position(extInst.position() + 32); - } - - if (!filled.get(19)) { - extResHi.position(extResHi.position() + 32); - } - - if (!filled.get(20)) { - extResLo.position(extResLo.position() + 32); - } - - if (!filled.get(21)) { - hurdle.position(hurdle.position() + 1); - } - - if (!filled.get(22)) { - index.position(index.position() + 32); - } - - if (!filled.get(23)) { - limb.position(limb.position() + 32); - } - - if (!filled.get(24)) { - preliminaryChecksPassed.position(preliminaryChecksPassed.position() + 1); - } - - if (!filled.get(25)) { - somethingWasntOnG2.position(somethingWasntOnG2.position() + 1); - } - - if (!filled.get(26)) { - square.position(square.position() + 32); - } - - if (!filled.get(27)) { - stamp.position(stamp.position() + 32); - } - - if (!filled.get(28)) { - thisIsNotOnG2.position(thisIsNotOnG2.position() + 1); - } - - if (!filled.get(29)) { - thisIsNotOnG2Acc.position(thisIsNotOnG2Acc.position() + 1); - } - - if (!filled.get(30)) { - totalPairings.position(totalPairings.position() + 32); - } - - if (!filled.get(31)) { - type.position(type.position() + 32); - } - - if (!filled.get(32)) { - wcpArg1Hi.position(wcpArg1Hi.position() + 32); - } - - if (!filled.get(33)) { - wcpArg1Lo.position(wcpArg1Lo.position() + 32); - } - - if (!filled.get(34)) { - wcpArg2Hi.position(wcpArg2Hi.position() + 32); - } - - if (!filled.get(35)) { - wcpArg2Lo.position(wcpArg2Lo.position() + 32); - } - - if (!filled.get(36)) { - wcpInst.position(wcpInst.position() + 32); - } - - if (!filled.get(37)) { - wcpRes.position(wcpRes.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Euc.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Euc.java deleted file mode 100644 index 926e4256d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Euc.java +++ /dev/null @@ -1,78 +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.euc; - -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -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.module.Module; -import net.consensys.linea.zktracer.module.wcp.Wcp; -import org.apache.tuweni.bytes.Bytes; - -@RequiredArgsConstructor -public class Euc implements Module { - private final Wcp wcp; - private final StackedSet operations = new StackedSet<>(); - - @Override - public String moduleKey() { - return "EUC"; - } - - @Override - public void enterTransaction() { - this.operations.enter(); - } - - @Override - public void popTransaction() { - this.operations.pop(); - } - - @Override - public int lineCount() { - return this.operations.lineCount(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - for (EucOperation eucOperation : this.operations) { - eucOperation.trace(trace); - } - } - - public void callEUC(Bytes dividend, Bytes divisor) { - final BigInteger dividendBI = dividend.toUnsignedBigInteger(); - final BigInteger divisorBI = divisor.toUnsignedBigInteger(); - final Bytes quotient = bigIntegerToBytes(dividendBI.divide(divisorBI)); - final Bytes remainder = bigIntegerToBytes(dividendBI.remainder(divisorBI)); - - this.operations.add(new EucOperation(dividend, divisor, quotient, remainder)); - this.wcp.callLT(remainder, divisor); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/EucOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/EucOperation.java deleted file mode 100644 index 512b25b67..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/EucOperation.java +++ /dev/null @@ -1,83 +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.euc; - -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Utils.leftPadTo; - -import java.math.BigInteger; - -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -public class EucOperation extends ModuleOperation { - private final Bytes dividend; - private final Bytes divisor; - private final Bytes remainder; - private final Bytes quotient; - private final int ctMax; - - public EucOperation( - final Bytes dividend, final Bytes divisor, final Bytes quotient, final Bytes remainder) { - if (divisor.isZero()) { - throw new IllegalArgumentException("EUC module doesn't accept 0 for divisor"); - } - final Bytes dividendTrim = dividend.trimLeadingZeros(); - final Bytes divisorTrim = divisor.trimLeadingZeros(); - this.ctMax = Math.max(dividendTrim.size(), divisorTrim.size()) - 1; - if (ctMax >= 8) { - throw new IllegalStateException("Max ByteSize of input is 8 for EUC, received" + ctMax + 1); - } - this.dividend = dividendTrim; - this.divisor = divisorTrim; - this.quotient = quotient; - this.remainder = remainder; - } - - void trace(Trace trace) { - final Bytes dividend = leftPadTo(this.dividend, this.ctMax + 1); - final Bytes divisor = leftPadTo(this.divisor, this.ctMax + 1); - final Bytes quotient = leftPadTo(this.quotient, this.ctMax + 1); - final Bytes remainder = leftPadTo(this.remainder, this.ctMax + 1); - final Bytes ceil = - remainder.isZero() - ? divisor - : bigIntegerToBytes(divisor.toUnsignedBigInteger().add(BigInteger.ONE)); - - for (int ct = 0; ct <= ctMax; ct++) { - trace - .iomf(true) - .ct(UnsignedByte.of(ct)) - .ctMax(UnsignedByte.of(ctMax)) - .done(ct == ctMax) - .dividend(dividend) - .divisor(divisor) - .quotient(quotient) - .remainder(remainder) - .ceil(ceil) - .divisorByte(UnsignedByte.of(divisor.get(ct))) - .quotientByte(UnsignedByte.of(quotient.get(ct))) - .remainderByte(UnsignedByte.of(remainder.get(ct))) - .validateRow(); - } - } - - @Override - protected int computeLineCount() { - return this.ctMax + 1; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Trace.java deleted file mode 100644 index ca1dbe226..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Trace.java +++ /dev/null @@ -1,368 +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.euc; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer ceil; - private final MappedByteBuffer ct; - private final MappedByteBuffer ctMax; - private final MappedByteBuffer dividend; - private final MappedByteBuffer divisor; - private final MappedByteBuffer divisorByte; - private final MappedByteBuffer done; - private final MappedByteBuffer iomf; - private final MappedByteBuffer quotient; - private final MappedByteBuffer quotientByte; - private final MappedByteBuffer remainder; - private final MappedByteBuffer remainderByte; - - static List headers(int length) { - return List.of( - new ColumnHeader("euc.CEIL", 8, length), - new ColumnHeader("euc.CT", 1, length), - new ColumnHeader("euc.CT_MAX", 1, length), - new ColumnHeader("euc.DIVIDEND", 8, length), - new ColumnHeader("euc.DIVISOR", 8, length), - new ColumnHeader("euc.DIVISOR_BYTE", 1, length), - new ColumnHeader("euc.DONE", 1, length), - new ColumnHeader("euc.IOMF", 1, length), - new ColumnHeader("euc.QUOTIENT", 8, length), - new ColumnHeader("euc.QUOTIENT_BYTE", 1, length), - new ColumnHeader("euc.REMAINDER", 8, length), - new ColumnHeader("euc.REMAINDER_BYTE", 1, length)); - } - - public Trace(List buffers) { - this.ceil = buffers.get(0); - this.ct = buffers.get(1); - this.ctMax = buffers.get(2); - this.dividend = buffers.get(3); - this.divisor = buffers.get(4); - this.divisorByte = buffers.get(5); - this.done = buffers.get(6); - this.iomf = buffers.get(7); - this.quotient = buffers.get(8); - this.quotientByte = buffers.get(9); - this.remainder = buffers.get(10); - this.remainderByte = buffers.get(11); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace ceil(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("euc.CEIL already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - ceil.put((byte) 0); - } - ceil.put(b.toArrayUnsafe()); - - return this; - } - - public Trace ct(final UnsignedByte b) { - if (filled.get(1)) { - throw new IllegalStateException("euc.CT already set"); - } else { - filled.set(1); - } - - ct.put(b.toByte()); - - return this; - } - - public Trace ctMax(final UnsignedByte b) { - if (filled.get(2)) { - throw new IllegalStateException("euc.CT_MAX already set"); - } else { - filled.set(2); - } - - ctMax.put(b.toByte()); - - return this; - } - - public Trace dividend(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("euc.DIVIDEND already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - dividend.put((byte) 0); - } - dividend.put(b.toArrayUnsafe()); - - return this; - } - - public Trace divisor(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("euc.DIVISOR already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - divisor.put((byte) 0); - } - divisor.put(b.toArrayUnsafe()); - - return this; - } - - public Trace divisorByte(final UnsignedByte b) { - if (filled.get(5)) { - throw new IllegalStateException("euc.DIVISOR_BYTE already set"); - } else { - filled.set(5); - } - - divisorByte.put(b.toByte()); - - return this; - } - - public Trace done(final Boolean b) { - if (filled.get(6)) { - throw new IllegalStateException("euc.DONE already set"); - } else { - filled.set(6); - } - - done.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace iomf(final Boolean b) { - if (filled.get(7)) { - throw new IllegalStateException("euc.IOMF already set"); - } else { - filled.set(7); - } - - iomf.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace quotient(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("euc.QUOTIENT already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - quotient.put((byte) 0); - } - quotient.put(b.toArrayUnsafe()); - - return this; - } - - public Trace quotientByte(final UnsignedByte b) { - if (filled.get(9)) { - throw new IllegalStateException("euc.QUOTIENT_BYTE already set"); - } else { - filled.set(9); - } - - quotientByte.put(b.toByte()); - - return this; - } - - public Trace remainder(final Bytes b) { - if (filled.get(10)) { - throw new IllegalStateException("euc.REMAINDER already set"); - } else { - filled.set(10); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - remainder.put((byte) 0); - } - remainder.put(b.toArrayUnsafe()); - - return this; - } - - public Trace remainderByte(final UnsignedByte b) { - if (filled.get(11)) { - throw new IllegalStateException("euc.REMAINDER_BYTE already set"); - } else { - filled.set(11); - } - - remainderByte.put(b.toByte()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("euc.CEIL has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("euc.CT has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("euc.CT_MAX has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("euc.DIVIDEND has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("euc.DIVISOR has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("euc.DIVISOR_BYTE has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("euc.DONE has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("euc.IOMF has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("euc.QUOTIENT has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("euc.QUOTIENT_BYTE has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("euc.REMAINDER has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("euc.REMAINDER_BYTE has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - ceil.position(ceil.position() + 8); - } - - if (!filled.get(1)) { - ct.position(ct.position() + 1); - } - - if (!filled.get(2)) { - ctMax.position(ctMax.position() + 1); - } - - if (!filled.get(3)) { - dividend.position(dividend.position() + 8); - } - - if (!filled.get(4)) { - divisor.position(divisor.position() + 8); - } - - if (!filled.get(5)) { - divisorByte.position(divisorByte.position() + 1); - } - - if (!filled.get(6)) { - done.position(done.position() + 1); - } - - if (!filled.get(7)) { - iomf.position(iomf.position() + 1); - } - - if (!filled.get(8)) { - quotient.position(quotient.position() + 8); - } - - if (!filled.get(9)) { - quotientByte.position(quotientByte.position() + 1); - } - - if (!filled.get(10)) { - remainder.position(remainder.position() + 8); - } - - if (!filled.get(11)) { - remainderByte.position(remainderByte.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/BigIntegerConverter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/BigIntegerConverter.java deleted file mode 100644 index 8ed31c4ca..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/BigIntegerConverter.java +++ /dev/null @@ -1,82 +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.ext; - -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.util.Arrays; - -/** Supports operations of {@link BigInteger} conversions. */ -public class BigIntegerConverter { - - /** - * Converts {@link BigInteger} to a long array. - * - * @param bigInteger a {@link BigInteger} - * @return a long array consisting of decomposed {@link BigInteger} bytes. - */ - public static long[] toLongArray(BigInteger bigInteger) { - // Convert the BigInteger to a byte array - byte[] inputBytes = bigInteger.toByteArray(); - - // If inputBytes.length is greater than 64 (512 bits), use only the least significant 64 bytes - if (inputBytes.length > 64) { - inputBytes = Arrays.copyOfRange(inputBytes, inputBytes.length - 64, inputBytes.length); - } - - // Pad the inputBytes to 64 bytes (512 bits) - byte[] byteArray = new byte[64]; - int start = byteArray.length - inputBytes.length; - System.arraycopy(inputBytes, 0, byteArray, start, inputBytes.length); - - // Convert the byte array to an array of 8 longs - long[] longArray = new long[8]; - ByteBuffer buffer = ByteBuffer.wrap(byteArray); - for (int i = 0; i < 8; i++) { - longArray[7 - i] = buffer.getLong(i * 8); - } - - return longArray; - } - - /** - * Converts an array of longs to a {@link BigInteger}. - * - * @param longArray an array of longs. - * @return a {@link BigInteger} number. - */ - public static BigInteger fromLongArray(long[] longArray) { - // Convert the array of 8 longs to a byte array - ByteBuffer buffer = ByteBuffer.allocate(64); - for (int i = 0; i < longArray.length; i++) { - buffer.putLong(56 - (i * 8), longArray[i]); - } - byte[] byteArray = buffer.array(); - - // Remove any leading zeros from the byte array - int i = 0; - while (i < byteArray.length && byteArray[i] == 0) { - i++; - } - if (i == byteArray.length) { - return BigInteger.ZERO; - } - byte[] trimmedByteArray = Arrays.copyOfRange(byteArray, i, byteArray.length); - - // Convert the byte array to a BigInteger - return new BigInteger(trimmedByteArray); - } -} 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 deleted file mode 100644 index 6f8f3779c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/Ext.java +++ /dev/null @@ -1,110 +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.ext; - -import java.nio.MappedByteBuffer; -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.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.opcode.OpCode; -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 { - private final Hub hub; - - /** A set of the operations to trace */ - private final StackedSet operations = new StackedSet<>(); - - @Override - public String moduleKey() { - return "EXT"; - } - - @Override - public void traceStartTx(WorldView worldView, Transaction tx) { - this.operations.enter(); - } - - @Override - public void enterTransaction() { - this.operations.enter(); - } - - @Override - public void popTransaction() { - this.operations.pop(); - } - - @Override - public void tracePreOpcode(final MessageFrame frame) { - final OpCodeData opCode = hub.opCodeData(); - this.operations.add( - new ExtOperation( - opCode.mnemonic(), - Bytes32.leftPad(frame.getStackItem(0)), - Bytes32.leftPad(frame.getStackItem(1)), - Bytes32.leftPad(frame.getStackItem(2)))); - } - - public Bytes call(OpCode opCode, Bytes _arg1, Bytes _arg2, Bytes _arg3) { - final Bytes32 arg1 = Bytes32.leftPad(_arg1); - final Bytes32 arg2 = Bytes32.leftPad(_arg2); - final Bytes32 arg3 = Bytes32.leftPad(_arg3); - final ExtOperation op = new ExtOperation(opCode, arg1, arg2, arg3); - final Bytes result = op.compute(); - this.operations.add(op); - return result; - } - - public Bytes callADDMOD(Bytes _arg1, Bytes _arg2, Bytes _arg3) { - return this.call(OpCode.ADDMOD, _arg1, _arg2, _arg3); - } - - public Bytes callMULMOD(Bytes _arg1, Bytes _arg2, Bytes _arg3) { - return this.call(OpCode.MULMOD, _arg1, _arg2, _arg3); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - int stamp = 0; - for (ExtOperation operation : this.operations) { - stamp++; - operation.trace(trace, stamp); - } - } - - @Override - public int lineCount() { - return this.operations.lineCount(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/ExtOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/ExtOperation.java deleted file mode 100644 index 6ed6d2e67..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/ExtOperation.java +++ /dev/null @@ -1,287 +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.ext; - -import static net.consensys.linea.zktracer.module.Util.boolToInt; - -import lombok.EqualsAndHashCode; -import net.consensys.linea.zktracer.bytestheta.BaseBytes; -import net.consensys.linea.zktracer.bytestheta.BaseTheta; -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.module.ext.calculator.AbstractExtCalculator; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; - -@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) -public class ExtOperation extends ModuleOperation { - private static final int MMEDIUM = 8; - - @EqualsAndHashCode.Include private final OpCode opCode; - @EqualsAndHashCode.Include private final BaseBytes arg1; - @EqualsAndHashCode.Include private final BaseBytes arg2; - @EqualsAndHashCode.Include private final BaseBytes arg3; - private final boolean isOneLineInstruction; - - private BaseTheta result; - private BaseTheta aBytes; - private BaseTheta bBytes; - private BaseTheta cBytes; - private BaseTheta deltaBytes; - private BytesArray hBytes; - private BaseTheta rBytes; - private BytesArray iBytes; - private BytesArray jBytes; - private BytesArray qBytes; - private boolean[] cmp = new boolean[8]; - boolean[] overflowH = new boolean[8]; - boolean[] overflowJ = new boolean[8]; - boolean[] overflowRes = new boolean[8]; - boolean[] overflowI = new boolean[8]; - - public ExtOperation(OpCode opCode, Bytes32 arg1, Bytes32 arg2, Bytes32 arg3) { - this.opCode = opCode; - this.arg1 = BaseBytes.fromBytes32(arg1.copy()); - this.arg2 = BaseBytes.fromBytes32(arg2.copy()); - this.arg3 = BaseBytes.fromBytes32(arg3.copy()); - this.isOneLineInstruction = isOneLineInstruction(); - } - - public UInt256 compute() { - AbstractExtCalculator computer = AbstractExtCalculator.create(this.opCode); - return computer.computeResult( - this.arg1.getBytes32(), this.arg2.getBytes32(), this.arg3.getBytes32()); - } - - public void setup() { - this.aBytes = BaseTheta.fromBytes32(this.arg1.getBytes32()); - this.bBytes = BaseTheta.fromBytes32(this.arg2.getBytes32()); - this.cBytes = BaseTheta.fromBytes32(this.arg3.getBytes32()); - this.iBytes = new BytesArray(7); - this.jBytes = new BytesArray(8); - this.qBytes = new BytesArray(8); - this.deltaBytes = BaseTheta.fromBytes32(Bytes32.ZERO); - this.hBytes = new BytesArray(6); - - AbstractExtCalculator computer = AbstractExtCalculator.create(this.opCode); - - final UInt256 result = this.compute(); - this.result = BaseTheta.fromBytes32(result); - this.rBytes = BaseTheta.fromBytes32(result); - - if (!this.isOneLineInstruction) { - cmp = computer.computeComparisonFlags(cBytes, rBytes); - deltaBytes = computer.computeDeltas(cBytes, rBytes); - jBytes = computer.computeJs(this.arg1.getBytes32(), this.arg2.getBytes32()); - qBytes = - computer.computeQs( - this.arg1.getBytes32(), this.arg2.getBytes32(), this.arg3.getBytes32()); - overflowH = computer.computeHs(aBytes, bBytes, hBytes); - overflowI = computer.computeIs(qBytes, cBytes, iBytes); - overflowJ = computer.computeOverflowJ(qBytes, cBytes, rBytes, iBytes, getSigma(), getTau()); - overflowRes = - computer.computeOverflowRes( - this.arg1, this.arg2, aBytes, bBytes, hBytes, getAlpha(), getBeta()); - } - } - - public boolean getBit1() { - return this.opCode == OpCode.MULMOD && this.arg1.isZero(); - } - - public boolean getBit2() { - return this.opCode == OpCode.MULMOD && this.arg2.isZero(); - } - - public boolean getBit3() { - return UInt256.ONE.compareTo(UInt256.fromBytes(this.arg3.getBytes32())) >= 0; - } - - /** Returns true if any of the bit1, bit2, or bit3 flags are set. */ - private boolean isOneLineInstruction() { - return getBit1() || getBit2() || getBit3(); - } - - private int maxCt() { - if (this.isOneLineInstruction) { - return 1; - } - - return MMEDIUM; - } - - @Override - protected int computeLineCount() { - return this.maxCt(); - } - - private UInt256 getSigma() { - return UInt256.valueOf(boolToInt(overflowI[0])); - } - - private UInt256 getAlpha() { - return UInt256.valueOf(boolToInt(overflowH[0])); - } - - private UInt256 getBeta() { - return UInt256.valueOf(boolToInt(overflowH[1]) + 2L * boolToInt(overflowH[2])); - } - - private UInt256 getTau() { - return UInt256.valueOf(boolToInt(overflowI[1]) + 2L * boolToInt(overflowI[2])); - } - - void trace(Trace trace, int stamp) { - this.setup(); - - for (int i = 0; i < this.maxCt(); i++) { - final int accLength = i + 1; - trace - // Byte A and Acc A - .byteA0(UnsignedByte.of(this.aBytes.get(0).get(i))) - .byteA1(UnsignedByte.of(this.aBytes.get(1).get(i))) - .byteA2(UnsignedByte.of(this.aBytes.get(2).get(i))) - .byteA3(UnsignedByte.of(this.aBytes.get(3).get(i))) - .accA0(this.aBytes.get(0).slice(0, accLength)) - .accA1(this.aBytes.get(1).slice(0, accLength)) - .accA2(this.aBytes.get(2).slice(0, accLength)) - .accA3(this.aBytes.get(3).slice(0, accLength)) - // Byte B and Acc B - .byteB0(UnsignedByte.of(this.bBytes.get(0).get(i))) - .byteB1(UnsignedByte.of(this.bBytes.get(1).get(i))) - .byteB2(UnsignedByte.of(this.bBytes.get(2).get(i))) - .byteB3(UnsignedByte.of(this.bBytes.get(3).get(i))) - .accB0(this.bBytes.get(0).slice(0, accLength)) - .accB1(this.bBytes.get(1).slice(0, accLength)) - .accB2(this.bBytes.get(2).slice(0, accLength)) - .accB3(this.bBytes.get(3).slice(0, accLength)) - // Byte C and Acc C - .byteC0(UnsignedByte.of(this.cBytes.get(0).get(i))) - .byteC1(UnsignedByte.of(this.cBytes.get(1).get(i))) - .byteC2(UnsignedByte.of(this.cBytes.get(2).get(i))) - .byteC3(UnsignedByte.of(this.cBytes.get(3).get(i))) - .accC0(this.cBytes.get(0).slice(0, accLength)) - .accC1(this.cBytes.get(1).slice(0, accLength)) - .accC2(this.cBytes.get(2).slice(0, accLength)) - .accC3(this.cBytes.get(3).slice(0, accLength)) - // Byte Delta and Acc Delta - .byteDelta0(UnsignedByte.of(this.deltaBytes.get(0).get(i))) - .byteDelta1(UnsignedByte.of(this.deltaBytes.get(1).get(i))) - .byteDelta2(UnsignedByte.of(this.deltaBytes.get(2).get(i))) - .byteDelta3(UnsignedByte.of(this.deltaBytes.get(3).get(i))) - .accDelta0(this.deltaBytes.get(0).slice(0, accLength)) - .accDelta1(this.deltaBytes.get(1).slice(0, accLength)) - .accDelta2(this.deltaBytes.get(2).slice(0, accLength)) - .accDelta3(this.deltaBytes.get(3).slice(0, accLength)) - // Byte H and Acc H - .byteH0(UnsignedByte.of(this.hBytes.get(0).get(i))) - .byteH1(UnsignedByte.of(this.hBytes.get(1).get(i))) - .byteH2(UnsignedByte.of(this.hBytes.get(2).get(i))) - .byteH3(UnsignedByte.of(this.hBytes.get(3).get(i))) - .byteH4(UnsignedByte.of(this.hBytes.get(4).get(i))) - .byteH5(UnsignedByte.of(this.hBytes.get(5).get(i))) - .accH0(this.hBytes.get(0).slice(0, accLength)) - .accH1(this.hBytes.get(1).slice(0, accLength)) - .accH2(this.hBytes.get(2).slice(0, accLength)) - .accH3(this.hBytes.get(3).slice(0, accLength)) - .accH4(this.hBytes.get(4).slice(0, accLength)) - .accH5(this.hBytes.get(5).slice(0, accLength)) - // Byte I and Acc I - .byteI0(UnsignedByte.of(this.iBytes.get(0).get(i))) - .byteI1(UnsignedByte.of(this.iBytes.get(1).get(i))) - .byteI2(UnsignedByte.of(this.iBytes.get(2).get(i))) - .byteI3(UnsignedByte.of(this.iBytes.get(3).get(i))) - .byteI4(UnsignedByte.of(this.iBytes.get(4).get(i))) - .byteI5(UnsignedByte.of(this.iBytes.get(5).get(i))) - .byteI6(UnsignedByte.of(this.iBytes.get(6).get(i))) - .accI0(this.iBytes.get(0).slice(0, accLength)) - .accI1(this.iBytes.get(1).slice(0, accLength)) - .accI2(this.iBytes.get(2).slice(0, accLength)) - .accI3(this.iBytes.get(3).slice(0, accLength)) - .accI4(this.iBytes.get(4).slice(0, accLength)) - .accI5(this.iBytes.get(5).slice(0, accLength)) - .accI6(this.iBytes.get(6).slice(0, accLength)) - // Byte J and Acc J - .byteJ0(UnsignedByte.of(this.jBytes.get(0).get(i))) - .byteJ1(UnsignedByte.of(this.jBytes.get(1).get(i))) - .byteJ2(UnsignedByte.of(this.jBytes.get(2).get(i))) - .byteJ3(UnsignedByte.of(this.jBytes.get(3).get(i))) - .byteJ4(UnsignedByte.of(this.jBytes.get(4).get(i))) - .byteJ5(UnsignedByte.of(this.jBytes.get(5).get(i))) - .byteJ6(UnsignedByte.of(this.jBytes.get(6).get(i))) - .byteJ7(UnsignedByte.of(this.jBytes.get(7).get(i))) - .accJ0(this.jBytes.get(0).slice(0, accLength)) - .accJ1(this.jBytes.get(1).slice(0, accLength)) - .accJ2(this.jBytes.get(2).slice(0, accLength)) - .accJ3(this.jBytes.get(3).slice(0, accLength)) - .accJ4(this.jBytes.get(4).slice(0, accLength)) - .accJ5(this.jBytes.get(5).slice(0, accLength)) - .accJ6(this.jBytes.get(6).slice(0, accLength)) - .accJ7(this.jBytes.get(7).slice(0, accLength)) - // Byte Q and Acc Q - .byteQ0(UnsignedByte.of(this.qBytes.get(0).get(i))) - .byteQ1(UnsignedByte.of(this.qBytes.get(1).get(i))) - .byteQ2(UnsignedByte.of(this.qBytes.get(2).get(i))) - .byteQ3(UnsignedByte.of(this.qBytes.get(3).get(i))) - .byteQ4(UnsignedByte.of(this.qBytes.get(4).get(i))) - .byteQ5(UnsignedByte.of(this.qBytes.get(5).get(i))) - .byteQ6(UnsignedByte.of(this.qBytes.get(6).get(i))) - .byteQ7(UnsignedByte.of(this.qBytes.get(7).get(i))) - .accQ0(this.qBytes.get(0).slice(0, accLength)) - .accQ1(this.qBytes.get(1).slice(0, accLength)) - .accQ2(this.qBytes.get(2).slice(0, accLength)) - .accQ3(this.qBytes.get(3).slice(0, accLength)) - .accQ4(this.qBytes.get(4).slice(0, accLength)) - .accQ5(this.qBytes.get(5).slice(0, accLength)) - .accQ6(this.qBytes.get(6).slice(0, accLength)) - .accQ7(this.qBytes.get(7).slice(0, accLength)) - // Byte R and Acc R - .byteR0(UnsignedByte.of(this.rBytes.get(0).get(i))) - .byteR1(UnsignedByte.of(this.rBytes.get(1).get(i))) - .byteR2(UnsignedByte.of(this.rBytes.get(2).get(i))) - .byteR3(UnsignedByte.of(this.rBytes.get(3).get(i))) - .accR0(this.rBytes.get(0).slice(0, accLength)) - .accR1(this.rBytes.get(1).slice(0, accLength)) - .accR2(this.rBytes.get(2).slice(0, accLength)) - .accR3(this.rBytes.get(3).slice(0, accLength)) - // other - .arg1Hi(this.arg1.getHigh()) - .arg1Lo(this.arg1.getLow()) - .arg2Hi(this.arg2.getHigh()) - .arg2Lo(this.arg2.getLow()) - .arg3Hi(this.arg3.getHigh()) - .arg3Lo(this.arg3.getLow()) - .resHi(this.result.getHigh()) - .resLo(this.result.getLow()) - .cmp(this.cmp[i]) - .ofH(this.overflowH[i]) - .ofJ(this.overflowJ[i]) - .ofI(this.overflowI[i]) - .ofRes(this.overflowRes[i]) - .ct(Bytes.of(i)) - .inst(Bytes.of(this.opCode.byteValue())) - .oli(this.isOneLineInstruction) - .bit1(this.getBit1()) - .bit2(this.getBit2()) - .bit3(this.getBit3()) - .stamp(Bytes.ofUnsignedLong(stamp)) - .validateRow(); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/Trace.java deleted file mode 100644 index e9ff1d731..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/Trace.java +++ /dev/null @@ -1,3026 +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.ext; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer accA0; - private final MappedByteBuffer accA1; - private final MappedByteBuffer accA2; - private final MappedByteBuffer accA3; - private final MappedByteBuffer accB0; - private final MappedByteBuffer accB1; - private final MappedByteBuffer accB2; - private final MappedByteBuffer accB3; - private final MappedByteBuffer accC0; - private final MappedByteBuffer accC1; - private final MappedByteBuffer accC2; - private final MappedByteBuffer accC3; - private final MappedByteBuffer accDelta0; - private final MappedByteBuffer accDelta1; - private final MappedByteBuffer accDelta2; - private final MappedByteBuffer accDelta3; - private final MappedByteBuffer accH0; - private final MappedByteBuffer accH1; - private final MappedByteBuffer accH2; - private final MappedByteBuffer accH3; - private final MappedByteBuffer accH4; - private final MappedByteBuffer accH5; - private final MappedByteBuffer accI0; - private final MappedByteBuffer accI1; - private final MappedByteBuffer accI2; - private final MappedByteBuffer accI3; - private final MappedByteBuffer accI4; - private final MappedByteBuffer accI5; - private final MappedByteBuffer accI6; - private final MappedByteBuffer accJ0; - private final MappedByteBuffer accJ1; - private final MappedByteBuffer accJ2; - private final MappedByteBuffer accJ3; - private final MappedByteBuffer accJ4; - private final MappedByteBuffer accJ5; - private final MappedByteBuffer accJ6; - private final MappedByteBuffer accJ7; - private final MappedByteBuffer accQ0; - private final MappedByteBuffer accQ1; - private final MappedByteBuffer accQ2; - private final MappedByteBuffer accQ3; - private final MappedByteBuffer accQ4; - private final MappedByteBuffer accQ5; - private final MappedByteBuffer accQ6; - private final MappedByteBuffer accQ7; - private final MappedByteBuffer accR0; - private final MappedByteBuffer accR1; - private final MappedByteBuffer accR2; - private final MappedByteBuffer accR3; - private final MappedByteBuffer arg1Hi; - private final MappedByteBuffer arg1Lo; - private final MappedByteBuffer arg2Hi; - private final MappedByteBuffer arg2Lo; - private final MappedByteBuffer arg3Hi; - private final MappedByteBuffer arg3Lo; - private final MappedByteBuffer bit1; - private final MappedByteBuffer bit2; - private final MappedByteBuffer bit3; - private final MappedByteBuffer byteA0; - private final MappedByteBuffer byteA1; - private final MappedByteBuffer byteA2; - private final MappedByteBuffer byteA3; - private final MappedByteBuffer byteB0; - private final MappedByteBuffer byteB1; - private final MappedByteBuffer byteB2; - private final MappedByteBuffer byteB3; - private final MappedByteBuffer byteC0; - private final MappedByteBuffer byteC1; - private final MappedByteBuffer byteC2; - private final MappedByteBuffer byteC3; - private final MappedByteBuffer byteDelta0; - private final MappedByteBuffer byteDelta1; - private final MappedByteBuffer byteDelta2; - private final MappedByteBuffer byteDelta3; - private final MappedByteBuffer byteH0; - private final MappedByteBuffer byteH1; - private final MappedByteBuffer byteH2; - private final MappedByteBuffer byteH3; - private final MappedByteBuffer byteH4; - private final MappedByteBuffer byteH5; - private final MappedByteBuffer byteI0; - private final MappedByteBuffer byteI1; - private final MappedByteBuffer byteI2; - private final MappedByteBuffer byteI3; - private final MappedByteBuffer byteI4; - private final MappedByteBuffer byteI5; - private final MappedByteBuffer byteI6; - private final MappedByteBuffer byteJ0; - private final MappedByteBuffer byteJ1; - private final MappedByteBuffer byteJ2; - private final MappedByteBuffer byteJ3; - private final MappedByteBuffer byteJ4; - private final MappedByteBuffer byteJ5; - private final MappedByteBuffer byteJ6; - private final MappedByteBuffer byteJ7; - private final MappedByteBuffer byteQ0; - private final MappedByteBuffer byteQ1; - private final MappedByteBuffer byteQ2; - private final MappedByteBuffer byteQ3; - private final MappedByteBuffer byteQ4; - private final MappedByteBuffer byteQ5; - private final MappedByteBuffer byteQ6; - private final MappedByteBuffer byteQ7; - private final MappedByteBuffer byteR0; - private final MappedByteBuffer byteR1; - private final MappedByteBuffer byteR2; - private final MappedByteBuffer byteR3; - private final MappedByteBuffer cmp; - private final MappedByteBuffer ct; - private final MappedByteBuffer inst; - private final MappedByteBuffer ofH; - private final MappedByteBuffer ofI; - private final MappedByteBuffer ofJ; - private final MappedByteBuffer ofRes; - private final MappedByteBuffer oli; - private final MappedByteBuffer resHi; - private final MappedByteBuffer resLo; - private final MappedByteBuffer stamp; - - static List headers(int length) { - return List.of( - new ColumnHeader("ext.ACC_A_0", 32, length), - new ColumnHeader("ext.ACC_A_1", 32, length), - new ColumnHeader("ext.ACC_A_2", 32, length), - new ColumnHeader("ext.ACC_A_3", 32, length), - new ColumnHeader("ext.ACC_B_0", 32, length), - new ColumnHeader("ext.ACC_B_1", 32, length), - new ColumnHeader("ext.ACC_B_2", 32, length), - new ColumnHeader("ext.ACC_B_3", 32, length), - new ColumnHeader("ext.ACC_C_0", 32, length), - new ColumnHeader("ext.ACC_C_1", 32, length), - new ColumnHeader("ext.ACC_C_2", 32, length), - new ColumnHeader("ext.ACC_C_3", 32, length), - new ColumnHeader("ext.ACC_DELTA_0", 32, length), - new ColumnHeader("ext.ACC_DELTA_1", 32, length), - new ColumnHeader("ext.ACC_DELTA_2", 32, length), - new ColumnHeader("ext.ACC_DELTA_3", 32, length), - new ColumnHeader("ext.ACC_H_0", 32, length), - new ColumnHeader("ext.ACC_H_1", 32, length), - new ColumnHeader("ext.ACC_H_2", 32, length), - new ColumnHeader("ext.ACC_H_3", 32, length), - new ColumnHeader("ext.ACC_H_4", 32, length), - new ColumnHeader("ext.ACC_H_5", 32, length), - new ColumnHeader("ext.ACC_I_0", 32, length), - new ColumnHeader("ext.ACC_I_1", 32, length), - new ColumnHeader("ext.ACC_I_2", 32, length), - new ColumnHeader("ext.ACC_I_3", 32, length), - new ColumnHeader("ext.ACC_I_4", 32, length), - new ColumnHeader("ext.ACC_I_5", 32, length), - new ColumnHeader("ext.ACC_I_6", 32, length), - new ColumnHeader("ext.ACC_J_0", 32, length), - new ColumnHeader("ext.ACC_J_1", 32, length), - new ColumnHeader("ext.ACC_J_2", 32, length), - new ColumnHeader("ext.ACC_J_3", 32, length), - new ColumnHeader("ext.ACC_J_4", 32, length), - new ColumnHeader("ext.ACC_J_5", 32, length), - new ColumnHeader("ext.ACC_J_6", 32, length), - new ColumnHeader("ext.ACC_J_7", 32, length), - new ColumnHeader("ext.ACC_Q_0", 32, length), - new ColumnHeader("ext.ACC_Q_1", 32, length), - new ColumnHeader("ext.ACC_Q_2", 32, length), - new ColumnHeader("ext.ACC_Q_3", 32, length), - new ColumnHeader("ext.ACC_Q_4", 32, length), - new ColumnHeader("ext.ACC_Q_5", 32, length), - new ColumnHeader("ext.ACC_Q_6", 32, length), - new ColumnHeader("ext.ACC_Q_7", 32, length), - new ColumnHeader("ext.ACC_R_0", 32, length), - new ColumnHeader("ext.ACC_R_1", 32, length), - new ColumnHeader("ext.ACC_R_2", 32, length), - new ColumnHeader("ext.ACC_R_3", 32, length), - new ColumnHeader("ext.ARG_1_HI", 32, length), - new ColumnHeader("ext.ARG_1_LO", 32, length), - new ColumnHeader("ext.ARG_2_HI", 32, length), - new ColumnHeader("ext.ARG_2_LO", 32, length), - new ColumnHeader("ext.ARG_3_HI", 32, length), - new ColumnHeader("ext.ARG_3_LO", 32, length), - new ColumnHeader("ext.BIT_1", 1, length), - new ColumnHeader("ext.BIT_2", 1, length), - new ColumnHeader("ext.BIT_3", 1, length), - new ColumnHeader("ext.BYTE_A_0", 1, length), - new ColumnHeader("ext.BYTE_A_1", 1, length), - new ColumnHeader("ext.BYTE_A_2", 1, length), - new ColumnHeader("ext.BYTE_A_3", 1, length), - new ColumnHeader("ext.BYTE_B_0", 1, length), - new ColumnHeader("ext.BYTE_B_1", 1, length), - new ColumnHeader("ext.BYTE_B_2", 1, length), - new ColumnHeader("ext.BYTE_B_3", 1, length), - new ColumnHeader("ext.BYTE_C_0", 1, length), - new ColumnHeader("ext.BYTE_C_1", 1, length), - new ColumnHeader("ext.BYTE_C_2", 1, length), - new ColumnHeader("ext.BYTE_C_3", 1, length), - new ColumnHeader("ext.BYTE_DELTA_0", 1, length), - new ColumnHeader("ext.BYTE_DELTA_1", 1, length), - new ColumnHeader("ext.BYTE_DELTA_2", 1, length), - new ColumnHeader("ext.BYTE_DELTA_3", 1, length), - new ColumnHeader("ext.BYTE_H_0", 1, length), - new ColumnHeader("ext.BYTE_H_1", 1, length), - new ColumnHeader("ext.BYTE_H_2", 1, length), - new ColumnHeader("ext.BYTE_H_3", 1, length), - new ColumnHeader("ext.BYTE_H_4", 1, length), - new ColumnHeader("ext.BYTE_H_5", 1, length), - new ColumnHeader("ext.BYTE_I_0", 1, length), - new ColumnHeader("ext.BYTE_I_1", 1, length), - new ColumnHeader("ext.BYTE_I_2", 1, length), - new ColumnHeader("ext.BYTE_I_3", 1, length), - new ColumnHeader("ext.BYTE_I_4", 1, length), - new ColumnHeader("ext.BYTE_I_5", 1, length), - new ColumnHeader("ext.BYTE_I_6", 1, length), - new ColumnHeader("ext.BYTE_J_0", 1, length), - new ColumnHeader("ext.BYTE_J_1", 1, length), - new ColumnHeader("ext.BYTE_J_2", 1, length), - new ColumnHeader("ext.BYTE_J_3", 1, length), - new ColumnHeader("ext.BYTE_J_4", 1, length), - new ColumnHeader("ext.BYTE_J_5", 1, length), - new ColumnHeader("ext.BYTE_J_6", 1, length), - new ColumnHeader("ext.BYTE_J_7", 1, length), - new ColumnHeader("ext.BYTE_Q_0", 1, length), - new ColumnHeader("ext.BYTE_Q_1", 1, length), - new ColumnHeader("ext.BYTE_Q_2", 1, length), - new ColumnHeader("ext.BYTE_Q_3", 1, length), - new ColumnHeader("ext.BYTE_Q_4", 1, length), - new ColumnHeader("ext.BYTE_Q_5", 1, length), - new ColumnHeader("ext.BYTE_Q_6", 1, length), - new ColumnHeader("ext.BYTE_Q_7", 1, length), - new ColumnHeader("ext.BYTE_R_0", 1, length), - new ColumnHeader("ext.BYTE_R_1", 1, length), - new ColumnHeader("ext.BYTE_R_2", 1, length), - new ColumnHeader("ext.BYTE_R_3", 1, length), - new ColumnHeader("ext.CMP", 1, length), - new ColumnHeader("ext.CT", 32, length), - new ColumnHeader("ext.INST", 32, length), - new ColumnHeader("ext.OF_H", 1, length), - new ColumnHeader("ext.OF_I", 1, length), - new ColumnHeader("ext.OF_J", 1, length), - new ColumnHeader("ext.OF_RES", 1, length), - new ColumnHeader("ext.OLI", 1, length), - new ColumnHeader("ext.RES_HI", 32, length), - new ColumnHeader("ext.RES_LO", 32, length), - new ColumnHeader("ext.STAMP", 32, length)); - } - - public Trace(List buffers) { - this.accA0 = buffers.get(0); - this.accA1 = buffers.get(1); - this.accA2 = buffers.get(2); - this.accA3 = buffers.get(3); - this.accB0 = buffers.get(4); - this.accB1 = buffers.get(5); - this.accB2 = buffers.get(6); - this.accB3 = buffers.get(7); - this.accC0 = buffers.get(8); - this.accC1 = buffers.get(9); - this.accC2 = buffers.get(10); - this.accC3 = buffers.get(11); - this.accDelta0 = buffers.get(12); - this.accDelta1 = buffers.get(13); - this.accDelta2 = buffers.get(14); - this.accDelta3 = buffers.get(15); - this.accH0 = buffers.get(16); - this.accH1 = buffers.get(17); - this.accH2 = buffers.get(18); - this.accH3 = buffers.get(19); - this.accH4 = buffers.get(20); - this.accH5 = buffers.get(21); - this.accI0 = buffers.get(22); - this.accI1 = buffers.get(23); - this.accI2 = buffers.get(24); - this.accI3 = buffers.get(25); - this.accI4 = buffers.get(26); - this.accI5 = buffers.get(27); - this.accI6 = buffers.get(28); - this.accJ0 = buffers.get(29); - this.accJ1 = buffers.get(30); - this.accJ2 = buffers.get(31); - this.accJ3 = buffers.get(32); - this.accJ4 = buffers.get(33); - this.accJ5 = buffers.get(34); - this.accJ6 = buffers.get(35); - this.accJ7 = buffers.get(36); - this.accQ0 = buffers.get(37); - this.accQ1 = buffers.get(38); - this.accQ2 = buffers.get(39); - this.accQ3 = buffers.get(40); - this.accQ4 = buffers.get(41); - this.accQ5 = buffers.get(42); - this.accQ6 = buffers.get(43); - this.accQ7 = buffers.get(44); - this.accR0 = buffers.get(45); - this.accR1 = buffers.get(46); - this.accR2 = buffers.get(47); - this.accR3 = buffers.get(48); - this.arg1Hi = buffers.get(49); - this.arg1Lo = buffers.get(50); - this.arg2Hi = buffers.get(51); - this.arg2Lo = buffers.get(52); - this.arg3Hi = buffers.get(53); - this.arg3Lo = buffers.get(54); - this.bit1 = buffers.get(55); - this.bit2 = buffers.get(56); - this.bit3 = buffers.get(57); - this.byteA0 = buffers.get(58); - this.byteA1 = buffers.get(59); - this.byteA2 = buffers.get(60); - this.byteA3 = buffers.get(61); - this.byteB0 = buffers.get(62); - this.byteB1 = buffers.get(63); - this.byteB2 = buffers.get(64); - this.byteB3 = buffers.get(65); - this.byteC0 = buffers.get(66); - this.byteC1 = buffers.get(67); - this.byteC2 = buffers.get(68); - this.byteC3 = buffers.get(69); - this.byteDelta0 = buffers.get(70); - this.byteDelta1 = buffers.get(71); - this.byteDelta2 = buffers.get(72); - this.byteDelta3 = buffers.get(73); - this.byteH0 = buffers.get(74); - this.byteH1 = buffers.get(75); - this.byteH2 = buffers.get(76); - this.byteH3 = buffers.get(77); - this.byteH4 = buffers.get(78); - this.byteH5 = buffers.get(79); - this.byteI0 = buffers.get(80); - this.byteI1 = buffers.get(81); - this.byteI2 = buffers.get(82); - this.byteI3 = buffers.get(83); - this.byteI4 = buffers.get(84); - this.byteI5 = buffers.get(85); - this.byteI6 = buffers.get(86); - this.byteJ0 = buffers.get(87); - this.byteJ1 = buffers.get(88); - this.byteJ2 = buffers.get(89); - this.byteJ3 = buffers.get(90); - this.byteJ4 = buffers.get(91); - this.byteJ5 = buffers.get(92); - this.byteJ6 = buffers.get(93); - this.byteJ7 = buffers.get(94); - this.byteQ0 = buffers.get(95); - this.byteQ1 = buffers.get(96); - this.byteQ2 = buffers.get(97); - this.byteQ3 = buffers.get(98); - this.byteQ4 = buffers.get(99); - this.byteQ5 = buffers.get(100); - this.byteQ6 = buffers.get(101); - this.byteQ7 = buffers.get(102); - this.byteR0 = buffers.get(103); - this.byteR1 = buffers.get(104); - this.byteR2 = buffers.get(105); - this.byteR3 = buffers.get(106); - this.cmp = buffers.get(107); - this.ct = buffers.get(108); - this.inst = buffers.get(109); - this.ofH = buffers.get(110); - this.ofI = buffers.get(111); - this.ofJ = buffers.get(112); - this.ofRes = buffers.get(113); - this.oli = buffers.get(114); - this.resHi = buffers.get(115); - this.resLo = buffers.get(116); - this.stamp = buffers.get(117); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace accA0(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("ext.ACC_A_0 already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accA0.put((byte) 0); - } - accA0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accA1(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("ext.ACC_A_1 already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accA1.put((byte) 0); - } - accA1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accA2(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("ext.ACC_A_2 already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accA2.put((byte) 0); - } - accA2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accA3(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("ext.ACC_A_3 already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accA3.put((byte) 0); - } - accA3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB0(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("ext.ACC_B_0 already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB0.put((byte) 0); - } - accB0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB1(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("ext.ACC_B_1 already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB1.put((byte) 0); - } - accB1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB2(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("ext.ACC_B_2 already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB2.put((byte) 0); - } - accB2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB3(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("ext.ACC_B_3 already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB3.put((byte) 0); - } - accB3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accC0(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("ext.ACC_C_0 already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accC0.put((byte) 0); - } - accC0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accC1(final Bytes b) { - if (filled.get(9)) { - throw new IllegalStateException("ext.ACC_C_1 already set"); - } else { - filled.set(9); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accC1.put((byte) 0); - } - accC1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accC2(final Bytes b) { - if (filled.get(10)) { - throw new IllegalStateException("ext.ACC_C_2 already set"); - } else { - filled.set(10); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accC2.put((byte) 0); - } - accC2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accC3(final Bytes b) { - if (filled.get(11)) { - throw new IllegalStateException("ext.ACC_C_3 already set"); - } else { - filled.set(11); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accC3.put((byte) 0); - } - accC3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accDelta0(final Bytes b) { - if (filled.get(12)) { - throw new IllegalStateException("ext.ACC_DELTA_0 already set"); - } else { - filled.set(12); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accDelta0.put((byte) 0); - } - accDelta0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accDelta1(final Bytes b) { - if (filled.get(13)) { - throw new IllegalStateException("ext.ACC_DELTA_1 already set"); - } else { - filled.set(13); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accDelta1.put((byte) 0); - } - accDelta1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accDelta2(final Bytes b) { - if (filled.get(14)) { - throw new IllegalStateException("ext.ACC_DELTA_2 already set"); - } else { - filled.set(14); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accDelta2.put((byte) 0); - } - accDelta2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accDelta3(final Bytes b) { - if (filled.get(15)) { - throw new IllegalStateException("ext.ACC_DELTA_3 already set"); - } else { - filled.set(15); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accDelta3.put((byte) 0); - } - accDelta3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH0(final Bytes b) { - if (filled.get(16)) { - throw new IllegalStateException("ext.ACC_H_0 already set"); - } else { - filled.set(16); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH0.put((byte) 0); - } - accH0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH1(final Bytes b) { - if (filled.get(17)) { - throw new IllegalStateException("ext.ACC_H_1 already set"); - } else { - filled.set(17); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH1.put((byte) 0); - } - accH1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH2(final Bytes b) { - if (filled.get(18)) { - throw new IllegalStateException("ext.ACC_H_2 already set"); - } else { - filled.set(18); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH2.put((byte) 0); - } - accH2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH3(final Bytes b) { - if (filled.get(19)) { - throw new IllegalStateException("ext.ACC_H_3 already set"); - } else { - filled.set(19); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH3.put((byte) 0); - } - accH3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH4(final Bytes b) { - if (filled.get(20)) { - throw new IllegalStateException("ext.ACC_H_4 already set"); - } else { - filled.set(20); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH4.put((byte) 0); - } - accH4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH5(final Bytes b) { - if (filled.get(21)) { - throw new IllegalStateException("ext.ACC_H_5 already set"); - } else { - filled.set(21); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH5.put((byte) 0); - } - accH5.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accI0(final Bytes b) { - if (filled.get(22)) { - throw new IllegalStateException("ext.ACC_I_0 already set"); - } else { - filled.set(22); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accI0.put((byte) 0); - } - accI0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accI1(final Bytes b) { - if (filled.get(23)) { - throw new IllegalStateException("ext.ACC_I_1 already set"); - } else { - filled.set(23); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accI1.put((byte) 0); - } - accI1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accI2(final Bytes b) { - if (filled.get(24)) { - throw new IllegalStateException("ext.ACC_I_2 already set"); - } else { - filled.set(24); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accI2.put((byte) 0); - } - accI2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accI3(final Bytes b) { - if (filled.get(25)) { - throw new IllegalStateException("ext.ACC_I_3 already set"); - } else { - filled.set(25); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accI3.put((byte) 0); - } - accI3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accI4(final Bytes b) { - if (filled.get(26)) { - throw new IllegalStateException("ext.ACC_I_4 already set"); - } else { - filled.set(26); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accI4.put((byte) 0); - } - accI4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accI5(final Bytes b) { - if (filled.get(27)) { - throw new IllegalStateException("ext.ACC_I_5 already set"); - } else { - filled.set(27); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accI5.put((byte) 0); - } - accI5.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accI6(final Bytes b) { - if (filled.get(28)) { - throw new IllegalStateException("ext.ACC_I_6 already set"); - } else { - filled.set(28); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accI6.put((byte) 0); - } - accI6.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accJ0(final Bytes b) { - if (filled.get(29)) { - throw new IllegalStateException("ext.ACC_J_0 already set"); - } else { - filled.set(29); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accJ0.put((byte) 0); - } - accJ0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accJ1(final Bytes b) { - if (filled.get(30)) { - throw new IllegalStateException("ext.ACC_J_1 already set"); - } else { - filled.set(30); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accJ1.put((byte) 0); - } - accJ1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accJ2(final Bytes b) { - if (filled.get(31)) { - throw new IllegalStateException("ext.ACC_J_2 already set"); - } else { - filled.set(31); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accJ2.put((byte) 0); - } - accJ2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accJ3(final Bytes b) { - if (filled.get(32)) { - throw new IllegalStateException("ext.ACC_J_3 already set"); - } else { - filled.set(32); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accJ3.put((byte) 0); - } - accJ3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accJ4(final Bytes b) { - if (filled.get(33)) { - throw new IllegalStateException("ext.ACC_J_4 already set"); - } else { - filled.set(33); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accJ4.put((byte) 0); - } - accJ4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accJ5(final Bytes b) { - if (filled.get(34)) { - throw new IllegalStateException("ext.ACC_J_5 already set"); - } else { - filled.set(34); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accJ5.put((byte) 0); - } - accJ5.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accJ6(final Bytes b) { - if (filled.get(35)) { - throw new IllegalStateException("ext.ACC_J_6 already set"); - } else { - filled.set(35); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accJ6.put((byte) 0); - } - accJ6.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accJ7(final Bytes b) { - if (filled.get(36)) { - throw new IllegalStateException("ext.ACC_J_7 already set"); - } else { - filled.set(36); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accJ7.put((byte) 0); - } - accJ7.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ0(final Bytes b) { - if (filled.get(37)) { - throw new IllegalStateException("ext.ACC_Q_0 already set"); - } else { - filled.set(37); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ0.put((byte) 0); - } - accQ0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ1(final Bytes b) { - if (filled.get(38)) { - throw new IllegalStateException("ext.ACC_Q_1 already set"); - } else { - filled.set(38); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ1.put((byte) 0); - } - accQ1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ2(final Bytes b) { - if (filled.get(39)) { - throw new IllegalStateException("ext.ACC_Q_2 already set"); - } else { - filled.set(39); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ2.put((byte) 0); - } - accQ2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ3(final Bytes b) { - if (filled.get(40)) { - throw new IllegalStateException("ext.ACC_Q_3 already set"); - } else { - filled.set(40); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ3.put((byte) 0); - } - accQ3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ4(final Bytes b) { - if (filled.get(41)) { - throw new IllegalStateException("ext.ACC_Q_4 already set"); - } else { - filled.set(41); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ4.put((byte) 0); - } - accQ4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ5(final Bytes b) { - if (filled.get(42)) { - throw new IllegalStateException("ext.ACC_Q_5 already set"); - } else { - filled.set(42); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ5.put((byte) 0); - } - accQ5.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ6(final Bytes b) { - if (filled.get(43)) { - throw new IllegalStateException("ext.ACC_Q_6 already set"); - } else { - filled.set(43); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ6.put((byte) 0); - } - accQ6.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ7(final Bytes b) { - if (filled.get(44)) { - throw new IllegalStateException("ext.ACC_Q_7 already set"); - } else { - filled.set(44); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ7.put((byte) 0); - } - accQ7.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accR0(final Bytes b) { - if (filled.get(45)) { - throw new IllegalStateException("ext.ACC_R_0 already set"); - } else { - filled.set(45); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accR0.put((byte) 0); - } - accR0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accR1(final Bytes b) { - if (filled.get(46)) { - throw new IllegalStateException("ext.ACC_R_1 already set"); - } else { - filled.set(46); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accR1.put((byte) 0); - } - accR1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accR2(final Bytes b) { - if (filled.get(47)) { - throw new IllegalStateException("ext.ACC_R_2 already set"); - } else { - filled.set(47); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accR2.put((byte) 0); - } - accR2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accR3(final Bytes b) { - if (filled.get(48)) { - throw new IllegalStateException("ext.ACC_R_3 already set"); - } else { - filled.set(48); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accR3.put((byte) 0); - } - accR3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg1Hi(final Bytes b) { - if (filled.get(49)) { - throw new IllegalStateException("ext.ARG_1_HI already set"); - } else { - filled.set(49); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Hi.put((byte) 0); - } - arg1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg1Lo(final Bytes b) { - if (filled.get(50)) { - throw new IllegalStateException("ext.ARG_1_LO already set"); - } else { - filled.set(50); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Lo.put((byte) 0); - } - arg1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg2Hi(final Bytes b) { - if (filled.get(51)) { - throw new IllegalStateException("ext.ARG_2_HI already set"); - } else { - filled.set(51); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg2Hi.put((byte) 0); - } - arg2Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg2Lo(final Bytes b) { - if (filled.get(52)) { - throw new IllegalStateException("ext.ARG_2_LO already set"); - } else { - filled.set(52); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg2Lo.put((byte) 0); - } - arg2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg3Hi(final Bytes b) { - if (filled.get(53)) { - throw new IllegalStateException("ext.ARG_3_HI already set"); - } else { - filled.set(53); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg3Hi.put((byte) 0); - } - arg3Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg3Lo(final Bytes b) { - if (filled.get(54)) { - throw new IllegalStateException("ext.ARG_3_LO already set"); - } else { - filled.set(54); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg3Lo.put((byte) 0); - } - arg3Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace bit1(final Boolean b) { - if (filled.get(55)) { - throw new IllegalStateException("ext.BIT_1 already set"); - } else { - filled.set(55); - } - - bit1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit2(final Boolean b) { - if (filled.get(56)) { - throw new IllegalStateException("ext.BIT_2 already set"); - } else { - filled.set(56); - } - - bit2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit3(final Boolean b) { - if (filled.get(57)) { - throw new IllegalStateException("ext.BIT_3 already set"); - } else { - filled.set(57); - } - - bit3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace byteA0(final UnsignedByte b) { - if (filled.get(58)) { - throw new IllegalStateException("ext.BYTE_A_0 already set"); - } else { - filled.set(58); - } - - byteA0.put(b.toByte()); - - return this; - } - - public Trace byteA1(final UnsignedByte b) { - if (filled.get(59)) { - throw new IllegalStateException("ext.BYTE_A_1 already set"); - } else { - filled.set(59); - } - - byteA1.put(b.toByte()); - - return this; - } - - public Trace byteA2(final UnsignedByte b) { - if (filled.get(60)) { - throw new IllegalStateException("ext.BYTE_A_2 already set"); - } else { - filled.set(60); - } - - byteA2.put(b.toByte()); - - return this; - } - - public Trace byteA3(final UnsignedByte b) { - if (filled.get(61)) { - throw new IllegalStateException("ext.BYTE_A_3 already set"); - } else { - filled.set(61); - } - - byteA3.put(b.toByte()); - - return this; - } - - public Trace byteB0(final UnsignedByte b) { - if (filled.get(62)) { - throw new IllegalStateException("ext.BYTE_B_0 already set"); - } else { - filled.set(62); - } - - byteB0.put(b.toByte()); - - return this; - } - - public Trace byteB1(final UnsignedByte b) { - if (filled.get(63)) { - throw new IllegalStateException("ext.BYTE_B_1 already set"); - } else { - filled.set(63); - } - - byteB1.put(b.toByte()); - - return this; - } - - public Trace byteB2(final UnsignedByte b) { - if (filled.get(64)) { - throw new IllegalStateException("ext.BYTE_B_2 already set"); - } else { - filled.set(64); - } - - byteB2.put(b.toByte()); - - return this; - } - - public Trace byteB3(final UnsignedByte b) { - if (filled.get(65)) { - throw new IllegalStateException("ext.BYTE_B_3 already set"); - } else { - filled.set(65); - } - - byteB3.put(b.toByte()); - - return this; - } - - public Trace byteC0(final UnsignedByte b) { - if (filled.get(66)) { - throw new IllegalStateException("ext.BYTE_C_0 already set"); - } else { - filled.set(66); - } - - byteC0.put(b.toByte()); - - return this; - } - - public Trace byteC1(final UnsignedByte b) { - if (filled.get(67)) { - throw new IllegalStateException("ext.BYTE_C_1 already set"); - } else { - filled.set(67); - } - - byteC1.put(b.toByte()); - - return this; - } - - public Trace byteC2(final UnsignedByte b) { - if (filled.get(68)) { - throw new IllegalStateException("ext.BYTE_C_2 already set"); - } else { - filled.set(68); - } - - byteC2.put(b.toByte()); - - return this; - } - - public Trace byteC3(final UnsignedByte b) { - if (filled.get(69)) { - throw new IllegalStateException("ext.BYTE_C_3 already set"); - } else { - filled.set(69); - } - - byteC3.put(b.toByte()); - - return this; - } - - public Trace byteDelta0(final UnsignedByte b) { - if (filled.get(70)) { - throw new IllegalStateException("ext.BYTE_DELTA_0 already set"); - } else { - filled.set(70); - } - - byteDelta0.put(b.toByte()); - - return this; - } - - public Trace byteDelta1(final UnsignedByte b) { - if (filled.get(71)) { - throw new IllegalStateException("ext.BYTE_DELTA_1 already set"); - } else { - filled.set(71); - } - - byteDelta1.put(b.toByte()); - - return this; - } - - public Trace byteDelta2(final UnsignedByte b) { - if (filled.get(72)) { - throw new IllegalStateException("ext.BYTE_DELTA_2 already set"); - } else { - filled.set(72); - } - - byteDelta2.put(b.toByte()); - - return this; - } - - public Trace byteDelta3(final UnsignedByte b) { - if (filled.get(73)) { - throw new IllegalStateException("ext.BYTE_DELTA_3 already set"); - } else { - filled.set(73); - } - - byteDelta3.put(b.toByte()); - - return this; - } - - public Trace byteH0(final UnsignedByte b) { - if (filled.get(74)) { - throw new IllegalStateException("ext.BYTE_H_0 already set"); - } else { - filled.set(74); - } - - byteH0.put(b.toByte()); - - return this; - } - - public Trace byteH1(final UnsignedByte b) { - if (filled.get(75)) { - throw new IllegalStateException("ext.BYTE_H_1 already set"); - } else { - filled.set(75); - } - - byteH1.put(b.toByte()); - - return this; - } - - public Trace byteH2(final UnsignedByte b) { - if (filled.get(76)) { - throw new IllegalStateException("ext.BYTE_H_2 already set"); - } else { - filled.set(76); - } - - byteH2.put(b.toByte()); - - return this; - } - - public Trace byteH3(final UnsignedByte b) { - if (filled.get(77)) { - throw new IllegalStateException("ext.BYTE_H_3 already set"); - } else { - filled.set(77); - } - - byteH3.put(b.toByte()); - - return this; - } - - public Trace byteH4(final UnsignedByte b) { - if (filled.get(78)) { - throw new IllegalStateException("ext.BYTE_H_4 already set"); - } else { - filled.set(78); - } - - byteH4.put(b.toByte()); - - return this; - } - - public Trace byteH5(final UnsignedByte b) { - if (filled.get(79)) { - throw new IllegalStateException("ext.BYTE_H_5 already set"); - } else { - filled.set(79); - } - - byteH5.put(b.toByte()); - - return this; - } - - public Trace byteI0(final UnsignedByte b) { - if (filled.get(80)) { - throw new IllegalStateException("ext.BYTE_I_0 already set"); - } else { - filled.set(80); - } - - byteI0.put(b.toByte()); - - return this; - } - - public Trace byteI1(final UnsignedByte b) { - if (filled.get(81)) { - throw new IllegalStateException("ext.BYTE_I_1 already set"); - } else { - filled.set(81); - } - - byteI1.put(b.toByte()); - - return this; - } - - public Trace byteI2(final UnsignedByte b) { - if (filled.get(82)) { - throw new IllegalStateException("ext.BYTE_I_2 already set"); - } else { - filled.set(82); - } - - byteI2.put(b.toByte()); - - return this; - } - - public Trace byteI3(final UnsignedByte b) { - if (filled.get(83)) { - throw new IllegalStateException("ext.BYTE_I_3 already set"); - } else { - filled.set(83); - } - - byteI3.put(b.toByte()); - - return this; - } - - public Trace byteI4(final UnsignedByte b) { - if (filled.get(84)) { - throw new IllegalStateException("ext.BYTE_I_4 already set"); - } else { - filled.set(84); - } - - byteI4.put(b.toByte()); - - return this; - } - - public Trace byteI5(final UnsignedByte b) { - if (filled.get(85)) { - throw new IllegalStateException("ext.BYTE_I_5 already set"); - } else { - filled.set(85); - } - - byteI5.put(b.toByte()); - - return this; - } - - public Trace byteI6(final UnsignedByte b) { - if (filled.get(86)) { - throw new IllegalStateException("ext.BYTE_I_6 already set"); - } else { - filled.set(86); - } - - byteI6.put(b.toByte()); - - return this; - } - - public Trace byteJ0(final UnsignedByte b) { - if (filled.get(87)) { - throw new IllegalStateException("ext.BYTE_J_0 already set"); - } else { - filled.set(87); - } - - byteJ0.put(b.toByte()); - - return this; - } - - public Trace byteJ1(final UnsignedByte b) { - if (filled.get(88)) { - throw new IllegalStateException("ext.BYTE_J_1 already set"); - } else { - filled.set(88); - } - - byteJ1.put(b.toByte()); - - return this; - } - - public Trace byteJ2(final UnsignedByte b) { - if (filled.get(89)) { - throw new IllegalStateException("ext.BYTE_J_2 already set"); - } else { - filled.set(89); - } - - byteJ2.put(b.toByte()); - - return this; - } - - public Trace byteJ3(final UnsignedByte b) { - if (filled.get(90)) { - throw new IllegalStateException("ext.BYTE_J_3 already set"); - } else { - filled.set(90); - } - - byteJ3.put(b.toByte()); - - return this; - } - - public Trace byteJ4(final UnsignedByte b) { - if (filled.get(91)) { - throw new IllegalStateException("ext.BYTE_J_4 already set"); - } else { - filled.set(91); - } - - byteJ4.put(b.toByte()); - - return this; - } - - public Trace byteJ5(final UnsignedByte b) { - if (filled.get(92)) { - throw new IllegalStateException("ext.BYTE_J_5 already set"); - } else { - filled.set(92); - } - - byteJ5.put(b.toByte()); - - return this; - } - - public Trace byteJ6(final UnsignedByte b) { - if (filled.get(93)) { - throw new IllegalStateException("ext.BYTE_J_6 already set"); - } else { - filled.set(93); - } - - byteJ6.put(b.toByte()); - - return this; - } - - public Trace byteJ7(final UnsignedByte b) { - if (filled.get(94)) { - throw new IllegalStateException("ext.BYTE_J_7 already set"); - } else { - filled.set(94); - } - - byteJ7.put(b.toByte()); - - return this; - } - - public Trace byteQ0(final UnsignedByte b) { - if (filled.get(95)) { - throw new IllegalStateException("ext.BYTE_Q_0 already set"); - } else { - filled.set(95); - } - - byteQ0.put(b.toByte()); - - return this; - } - - public Trace byteQ1(final UnsignedByte b) { - if (filled.get(96)) { - throw new IllegalStateException("ext.BYTE_Q_1 already set"); - } else { - filled.set(96); - } - - byteQ1.put(b.toByte()); - - return this; - } - - public Trace byteQ2(final UnsignedByte b) { - if (filled.get(97)) { - throw new IllegalStateException("ext.BYTE_Q_2 already set"); - } else { - filled.set(97); - } - - byteQ2.put(b.toByte()); - - return this; - } - - public Trace byteQ3(final UnsignedByte b) { - if (filled.get(98)) { - throw new IllegalStateException("ext.BYTE_Q_3 already set"); - } else { - filled.set(98); - } - - byteQ3.put(b.toByte()); - - return this; - } - - public Trace byteQ4(final UnsignedByte b) { - if (filled.get(99)) { - throw new IllegalStateException("ext.BYTE_Q_4 already set"); - } else { - filled.set(99); - } - - byteQ4.put(b.toByte()); - - return this; - } - - public Trace byteQ5(final UnsignedByte b) { - if (filled.get(100)) { - throw new IllegalStateException("ext.BYTE_Q_5 already set"); - } else { - filled.set(100); - } - - byteQ5.put(b.toByte()); - - return this; - } - - public Trace byteQ6(final UnsignedByte b) { - if (filled.get(101)) { - throw new IllegalStateException("ext.BYTE_Q_6 already set"); - } else { - filled.set(101); - } - - byteQ6.put(b.toByte()); - - return this; - } - - public Trace byteQ7(final UnsignedByte b) { - if (filled.get(102)) { - throw new IllegalStateException("ext.BYTE_Q_7 already set"); - } else { - filled.set(102); - } - - byteQ7.put(b.toByte()); - - return this; - } - - public Trace byteR0(final UnsignedByte b) { - if (filled.get(103)) { - throw new IllegalStateException("ext.BYTE_R_0 already set"); - } else { - filled.set(103); - } - - byteR0.put(b.toByte()); - - return this; - } - - public Trace byteR1(final UnsignedByte b) { - if (filled.get(104)) { - throw new IllegalStateException("ext.BYTE_R_1 already set"); - } else { - filled.set(104); - } - - byteR1.put(b.toByte()); - - return this; - } - - public Trace byteR2(final UnsignedByte b) { - if (filled.get(105)) { - throw new IllegalStateException("ext.BYTE_R_2 already set"); - } else { - filled.set(105); - } - - byteR2.put(b.toByte()); - - return this; - } - - public Trace byteR3(final UnsignedByte b) { - if (filled.get(106)) { - throw new IllegalStateException("ext.BYTE_R_3 already set"); - } else { - filled.set(106); - } - - byteR3.put(b.toByte()); - - return this; - } - - public Trace cmp(final Boolean b) { - if (filled.get(107)) { - throw new IllegalStateException("ext.CMP already set"); - } else { - filled.set(107); - } - - cmp.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ct(final Bytes b) { - if (filled.get(108)) { - throw new IllegalStateException("ext.CT already set"); - } else { - filled.set(108); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - ct.put((byte) 0); - } - ct.put(b.toArrayUnsafe()); - - return this; - } - - public Trace inst(final Bytes b) { - if (filled.get(109)) { - throw new IllegalStateException("ext.INST already set"); - } else { - filled.set(109); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - inst.put((byte) 0); - } - inst.put(b.toArrayUnsafe()); - - return this; - } - - public Trace ofH(final Boolean b) { - if (filled.get(110)) { - throw new IllegalStateException("ext.OF_H already set"); - } else { - filled.set(110); - } - - ofH.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ofI(final Boolean b) { - if (filled.get(111)) { - throw new IllegalStateException("ext.OF_I already set"); - } else { - filled.set(111); - } - - ofI.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ofJ(final Boolean b) { - if (filled.get(112)) { - throw new IllegalStateException("ext.OF_J already set"); - } else { - filled.set(112); - } - - ofJ.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ofRes(final Boolean b) { - if (filled.get(113)) { - throw new IllegalStateException("ext.OF_RES already set"); - } else { - filled.set(113); - } - - ofRes.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace oli(final Boolean b) { - if (filled.get(114)) { - throw new IllegalStateException("ext.OLI already set"); - } else { - filled.set(114); - } - - oli.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace resHi(final Bytes b) { - if (filled.get(115)) { - throw new IllegalStateException("ext.RES_HI already set"); - } else { - filled.set(115); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resHi.put((byte) 0); - } - resHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace resLo(final Bytes b) { - if (filled.get(116)) { - throw new IllegalStateException("ext.RES_LO already set"); - } else { - filled.set(116); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resLo.put((byte) 0); - } - resLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace stamp(final Bytes b) { - if (filled.get(117)) { - throw new IllegalStateException("ext.STAMP already set"); - } else { - filled.set(117); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stamp.put((byte) 0); - } - stamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("ext.ACC_A_0 has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("ext.ACC_A_1 has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("ext.ACC_A_2 has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("ext.ACC_A_3 has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("ext.ACC_B_0 has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("ext.ACC_B_1 has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("ext.ACC_B_2 has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("ext.ACC_B_3 has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("ext.ACC_C_0 has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("ext.ACC_C_1 has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("ext.ACC_C_2 has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("ext.ACC_C_3 has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("ext.ACC_DELTA_0 has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("ext.ACC_DELTA_1 has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("ext.ACC_DELTA_2 has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("ext.ACC_DELTA_3 has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("ext.ACC_H_0 has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("ext.ACC_H_1 has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("ext.ACC_H_2 has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("ext.ACC_H_3 has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("ext.ACC_H_4 has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("ext.ACC_H_5 has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("ext.ACC_I_0 has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("ext.ACC_I_1 has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("ext.ACC_I_2 has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("ext.ACC_I_3 has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("ext.ACC_I_4 has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("ext.ACC_I_5 has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("ext.ACC_I_6 has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("ext.ACC_J_0 has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("ext.ACC_J_1 has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("ext.ACC_J_2 has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("ext.ACC_J_3 has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("ext.ACC_J_4 has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("ext.ACC_J_5 has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("ext.ACC_J_6 has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("ext.ACC_J_7 has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("ext.ACC_Q_0 has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("ext.ACC_Q_1 has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("ext.ACC_Q_2 has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("ext.ACC_Q_3 has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("ext.ACC_Q_4 has not been filled"); - } - - if (!filled.get(42)) { - throw new IllegalStateException("ext.ACC_Q_5 has not been filled"); - } - - if (!filled.get(43)) { - throw new IllegalStateException("ext.ACC_Q_6 has not been filled"); - } - - if (!filled.get(44)) { - throw new IllegalStateException("ext.ACC_Q_7 has not been filled"); - } - - if (!filled.get(45)) { - throw new IllegalStateException("ext.ACC_R_0 has not been filled"); - } - - if (!filled.get(46)) { - throw new IllegalStateException("ext.ACC_R_1 has not been filled"); - } - - if (!filled.get(47)) { - throw new IllegalStateException("ext.ACC_R_2 has not been filled"); - } - - if (!filled.get(48)) { - throw new IllegalStateException("ext.ACC_R_3 has not been filled"); - } - - if (!filled.get(49)) { - throw new IllegalStateException("ext.ARG_1_HI has not been filled"); - } - - if (!filled.get(50)) { - throw new IllegalStateException("ext.ARG_1_LO has not been filled"); - } - - if (!filled.get(51)) { - throw new IllegalStateException("ext.ARG_2_HI has not been filled"); - } - - if (!filled.get(52)) { - throw new IllegalStateException("ext.ARG_2_LO has not been filled"); - } - - if (!filled.get(53)) { - throw new IllegalStateException("ext.ARG_3_HI has not been filled"); - } - - if (!filled.get(54)) { - throw new IllegalStateException("ext.ARG_3_LO has not been filled"); - } - - if (!filled.get(55)) { - throw new IllegalStateException("ext.BIT_1 has not been filled"); - } - - if (!filled.get(56)) { - throw new IllegalStateException("ext.BIT_2 has not been filled"); - } - - if (!filled.get(57)) { - throw new IllegalStateException("ext.BIT_3 has not been filled"); - } - - if (!filled.get(58)) { - throw new IllegalStateException("ext.BYTE_A_0 has not been filled"); - } - - if (!filled.get(59)) { - throw new IllegalStateException("ext.BYTE_A_1 has not been filled"); - } - - if (!filled.get(60)) { - throw new IllegalStateException("ext.BYTE_A_2 has not been filled"); - } - - if (!filled.get(61)) { - throw new IllegalStateException("ext.BYTE_A_3 has not been filled"); - } - - if (!filled.get(62)) { - throw new IllegalStateException("ext.BYTE_B_0 has not been filled"); - } - - if (!filled.get(63)) { - throw new IllegalStateException("ext.BYTE_B_1 has not been filled"); - } - - if (!filled.get(64)) { - throw new IllegalStateException("ext.BYTE_B_2 has not been filled"); - } - - if (!filled.get(65)) { - throw new IllegalStateException("ext.BYTE_B_3 has not been filled"); - } - - if (!filled.get(66)) { - throw new IllegalStateException("ext.BYTE_C_0 has not been filled"); - } - - if (!filled.get(67)) { - throw new IllegalStateException("ext.BYTE_C_1 has not been filled"); - } - - if (!filled.get(68)) { - throw new IllegalStateException("ext.BYTE_C_2 has not been filled"); - } - - if (!filled.get(69)) { - throw new IllegalStateException("ext.BYTE_C_3 has not been filled"); - } - - if (!filled.get(70)) { - throw new IllegalStateException("ext.BYTE_DELTA_0 has not been filled"); - } - - if (!filled.get(71)) { - throw new IllegalStateException("ext.BYTE_DELTA_1 has not been filled"); - } - - if (!filled.get(72)) { - throw new IllegalStateException("ext.BYTE_DELTA_2 has not been filled"); - } - - if (!filled.get(73)) { - throw new IllegalStateException("ext.BYTE_DELTA_3 has not been filled"); - } - - if (!filled.get(74)) { - throw new IllegalStateException("ext.BYTE_H_0 has not been filled"); - } - - if (!filled.get(75)) { - throw new IllegalStateException("ext.BYTE_H_1 has not been filled"); - } - - if (!filled.get(76)) { - throw new IllegalStateException("ext.BYTE_H_2 has not been filled"); - } - - if (!filled.get(77)) { - throw new IllegalStateException("ext.BYTE_H_3 has not been filled"); - } - - if (!filled.get(78)) { - throw new IllegalStateException("ext.BYTE_H_4 has not been filled"); - } - - if (!filled.get(79)) { - throw new IllegalStateException("ext.BYTE_H_5 has not been filled"); - } - - if (!filled.get(80)) { - throw new IllegalStateException("ext.BYTE_I_0 has not been filled"); - } - - if (!filled.get(81)) { - throw new IllegalStateException("ext.BYTE_I_1 has not been filled"); - } - - if (!filled.get(82)) { - throw new IllegalStateException("ext.BYTE_I_2 has not been filled"); - } - - if (!filled.get(83)) { - throw new IllegalStateException("ext.BYTE_I_3 has not been filled"); - } - - if (!filled.get(84)) { - throw new IllegalStateException("ext.BYTE_I_4 has not been filled"); - } - - if (!filled.get(85)) { - throw new IllegalStateException("ext.BYTE_I_5 has not been filled"); - } - - if (!filled.get(86)) { - throw new IllegalStateException("ext.BYTE_I_6 has not been filled"); - } - - if (!filled.get(87)) { - throw new IllegalStateException("ext.BYTE_J_0 has not been filled"); - } - - if (!filled.get(88)) { - throw new IllegalStateException("ext.BYTE_J_1 has not been filled"); - } - - if (!filled.get(89)) { - throw new IllegalStateException("ext.BYTE_J_2 has not been filled"); - } - - if (!filled.get(90)) { - throw new IllegalStateException("ext.BYTE_J_3 has not been filled"); - } - - if (!filled.get(91)) { - throw new IllegalStateException("ext.BYTE_J_4 has not been filled"); - } - - if (!filled.get(92)) { - throw new IllegalStateException("ext.BYTE_J_5 has not been filled"); - } - - if (!filled.get(93)) { - throw new IllegalStateException("ext.BYTE_J_6 has not been filled"); - } - - if (!filled.get(94)) { - throw new IllegalStateException("ext.BYTE_J_7 has not been filled"); - } - - if (!filled.get(95)) { - throw new IllegalStateException("ext.BYTE_Q_0 has not been filled"); - } - - if (!filled.get(96)) { - throw new IllegalStateException("ext.BYTE_Q_1 has not been filled"); - } - - if (!filled.get(97)) { - throw new IllegalStateException("ext.BYTE_Q_2 has not been filled"); - } - - if (!filled.get(98)) { - throw new IllegalStateException("ext.BYTE_Q_3 has not been filled"); - } - - if (!filled.get(99)) { - throw new IllegalStateException("ext.BYTE_Q_4 has not been filled"); - } - - if (!filled.get(100)) { - throw new IllegalStateException("ext.BYTE_Q_5 has not been filled"); - } - - if (!filled.get(101)) { - throw new IllegalStateException("ext.BYTE_Q_6 has not been filled"); - } - - if (!filled.get(102)) { - throw new IllegalStateException("ext.BYTE_Q_7 has not been filled"); - } - - if (!filled.get(103)) { - throw new IllegalStateException("ext.BYTE_R_0 has not been filled"); - } - - if (!filled.get(104)) { - throw new IllegalStateException("ext.BYTE_R_1 has not been filled"); - } - - if (!filled.get(105)) { - throw new IllegalStateException("ext.BYTE_R_2 has not been filled"); - } - - if (!filled.get(106)) { - throw new IllegalStateException("ext.BYTE_R_3 has not been filled"); - } - - if (!filled.get(107)) { - throw new IllegalStateException("ext.CMP has not been filled"); - } - - if (!filled.get(108)) { - throw new IllegalStateException("ext.CT has not been filled"); - } - - if (!filled.get(109)) { - throw new IllegalStateException("ext.INST has not been filled"); - } - - if (!filled.get(110)) { - throw new IllegalStateException("ext.OF_H has not been filled"); - } - - if (!filled.get(111)) { - throw new IllegalStateException("ext.OF_I has not been filled"); - } - - if (!filled.get(112)) { - throw new IllegalStateException("ext.OF_J has not been filled"); - } - - if (!filled.get(113)) { - throw new IllegalStateException("ext.OF_RES has not been filled"); - } - - if (!filled.get(114)) { - throw new IllegalStateException("ext.OLI has not been filled"); - } - - if (!filled.get(115)) { - throw new IllegalStateException("ext.RES_HI has not been filled"); - } - - if (!filled.get(116)) { - throw new IllegalStateException("ext.RES_LO has not been filled"); - } - - if (!filled.get(117)) { - throw new IllegalStateException("ext.STAMP has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - accA0.position(accA0.position() + 32); - } - - if (!filled.get(1)) { - accA1.position(accA1.position() + 32); - } - - if (!filled.get(2)) { - accA2.position(accA2.position() + 32); - } - - if (!filled.get(3)) { - accA3.position(accA3.position() + 32); - } - - if (!filled.get(4)) { - accB0.position(accB0.position() + 32); - } - - if (!filled.get(5)) { - accB1.position(accB1.position() + 32); - } - - if (!filled.get(6)) { - accB2.position(accB2.position() + 32); - } - - if (!filled.get(7)) { - accB3.position(accB3.position() + 32); - } - - if (!filled.get(8)) { - accC0.position(accC0.position() + 32); - } - - if (!filled.get(9)) { - accC1.position(accC1.position() + 32); - } - - if (!filled.get(10)) { - accC2.position(accC2.position() + 32); - } - - if (!filled.get(11)) { - accC3.position(accC3.position() + 32); - } - - if (!filled.get(12)) { - accDelta0.position(accDelta0.position() + 32); - } - - if (!filled.get(13)) { - accDelta1.position(accDelta1.position() + 32); - } - - if (!filled.get(14)) { - accDelta2.position(accDelta2.position() + 32); - } - - if (!filled.get(15)) { - accDelta3.position(accDelta3.position() + 32); - } - - if (!filled.get(16)) { - accH0.position(accH0.position() + 32); - } - - if (!filled.get(17)) { - accH1.position(accH1.position() + 32); - } - - if (!filled.get(18)) { - accH2.position(accH2.position() + 32); - } - - if (!filled.get(19)) { - accH3.position(accH3.position() + 32); - } - - if (!filled.get(20)) { - accH4.position(accH4.position() + 32); - } - - if (!filled.get(21)) { - accH5.position(accH5.position() + 32); - } - - if (!filled.get(22)) { - accI0.position(accI0.position() + 32); - } - - if (!filled.get(23)) { - accI1.position(accI1.position() + 32); - } - - if (!filled.get(24)) { - accI2.position(accI2.position() + 32); - } - - if (!filled.get(25)) { - accI3.position(accI3.position() + 32); - } - - if (!filled.get(26)) { - accI4.position(accI4.position() + 32); - } - - if (!filled.get(27)) { - accI5.position(accI5.position() + 32); - } - - if (!filled.get(28)) { - accI6.position(accI6.position() + 32); - } - - if (!filled.get(29)) { - accJ0.position(accJ0.position() + 32); - } - - if (!filled.get(30)) { - accJ1.position(accJ1.position() + 32); - } - - if (!filled.get(31)) { - accJ2.position(accJ2.position() + 32); - } - - if (!filled.get(32)) { - accJ3.position(accJ3.position() + 32); - } - - if (!filled.get(33)) { - accJ4.position(accJ4.position() + 32); - } - - if (!filled.get(34)) { - accJ5.position(accJ5.position() + 32); - } - - if (!filled.get(35)) { - accJ6.position(accJ6.position() + 32); - } - - if (!filled.get(36)) { - accJ7.position(accJ7.position() + 32); - } - - if (!filled.get(37)) { - accQ0.position(accQ0.position() + 32); - } - - if (!filled.get(38)) { - accQ1.position(accQ1.position() + 32); - } - - if (!filled.get(39)) { - accQ2.position(accQ2.position() + 32); - } - - if (!filled.get(40)) { - accQ3.position(accQ3.position() + 32); - } - - if (!filled.get(41)) { - accQ4.position(accQ4.position() + 32); - } - - if (!filled.get(42)) { - accQ5.position(accQ5.position() + 32); - } - - if (!filled.get(43)) { - accQ6.position(accQ6.position() + 32); - } - - if (!filled.get(44)) { - accQ7.position(accQ7.position() + 32); - } - - if (!filled.get(45)) { - accR0.position(accR0.position() + 32); - } - - if (!filled.get(46)) { - accR1.position(accR1.position() + 32); - } - - if (!filled.get(47)) { - accR2.position(accR2.position() + 32); - } - - if (!filled.get(48)) { - accR3.position(accR3.position() + 32); - } - - if (!filled.get(49)) { - arg1Hi.position(arg1Hi.position() + 32); - } - - if (!filled.get(50)) { - arg1Lo.position(arg1Lo.position() + 32); - } - - if (!filled.get(51)) { - arg2Hi.position(arg2Hi.position() + 32); - } - - if (!filled.get(52)) { - arg2Lo.position(arg2Lo.position() + 32); - } - - if (!filled.get(53)) { - arg3Hi.position(arg3Hi.position() + 32); - } - - if (!filled.get(54)) { - arg3Lo.position(arg3Lo.position() + 32); - } - - if (!filled.get(55)) { - bit1.position(bit1.position() + 1); - } - - if (!filled.get(56)) { - bit2.position(bit2.position() + 1); - } - - if (!filled.get(57)) { - bit3.position(bit3.position() + 1); - } - - if (!filled.get(58)) { - byteA0.position(byteA0.position() + 1); - } - - if (!filled.get(59)) { - byteA1.position(byteA1.position() + 1); - } - - if (!filled.get(60)) { - byteA2.position(byteA2.position() + 1); - } - - if (!filled.get(61)) { - byteA3.position(byteA3.position() + 1); - } - - if (!filled.get(62)) { - byteB0.position(byteB0.position() + 1); - } - - if (!filled.get(63)) { - byteB1.position(byteB1.position() + 1); - } - - if (!filled.get(64)) { - byteB2.position(byteB2.position() + 1); - } - - if (!filled.get(65)) { - byteB3.position(byteB3.position() + 1); - } - - if (!filled.get(66)) { - byteC0.position(byteC0.position() + 1); - } - - if (!filled.get(67)) { - byteC1.position(byteC1.position() + 1); - } - - if (!filled.get(68)) { - byteC2.position(byteC2.position() + 1); - } - - if (!filled.get(69)) { - byteC3.position(byteC3.position() + 1); - } - - if (!filled.get(70)) { - byteDelta0.position(byteDelta0.position() + 1); - } - - if (!filled.get(71)) { - byteDelta1.position(byteDelta1.position() + 1); - } - - if (!filled.get(72)) { - byteDelta2.position(byteDelta2.position() + 1); - } - - if (!filled.get(73)) { - byteDelta3.position(byteDelta3.position() + 1); - } - - if (!filled.get(74)) { - byteH0.position(byteH0.position() + 1); - } - - if (!filled.get(75)) { - byteH1.position(byteH1.position() + 1); - } - - if (!filled.get(76)) { - byteH2.position(byteH2.position() + 1); - } - - if (!filled.get(77)) { - byteH3.position(byteH3.position() + 1); - } - - if (!filled.get(78)) { - byteH4.position(byteH4.position() + 1); - } - - if (!filled.get(79)) { - byteH5.position(byteH5.position() + 1); - } - - if (!filled.get(80)) { - byteI0.position(byteI0.position() + 1); - } - - if (!filled.get(81)) { - byteI1.position(byteI1.position() + 1); - } - - if (!filled.get(82)) { - byteI2.position(byteI2.position() + 1); - } - - if (!filled.get(83)) { - byteI3.position(byteI3.position() + 1); - } - - if (!filled.get(84)) { - byteI4.position(byteI4.position() + 1); - } - - if (!filled.get(85)) { - byteI5.position(byteI5.position() + 1); - } - - if (!filled.get(86)) { - byteI6.position(byteI6.position() + 1); - } - - if (!filled.get(87)) { - byteJ0.position(byteJ0.position() + 1); - } - - if (!filled.get(88)) { - byteJ1.position(byteJ1.position() + 1); - } - - if (!filled.get(89)) { - byteJ2.position(byteJ2.position() + 1); - } - - if (!filled.get(90)) { - byteJ3.position(byteJ3.position() + 1); - } - - if (!filled.get(91)) { - byteJ4.position(byteJ4.position() + 1); - } - - if (!filled.get(92)) { - byteJ5.position(byteJ5.position() + 1); - } - - if (!filled.get(93)) { - byteJ6.position(byteJ6.position() + 1); - } - - if (!filled.get(94)) { - byteJ7.position(byteJ7.position() + 1); - } - - if (!filled.get(95)) { - byteQ0.position(byteQ0.position() + 1); - } - - if (!filled.get(96)) { - byteQ1.position(byteQ1.position() + 1); - } - - if (!filled.get(97)) { - byteQ2.position(byteQ2.position() + 1); - } - - if (!filled.get(98)) { - byteQ3.position(byteQ3.position() + 1); - } - - if (!filled.get(99)) { - byteQ4.position(byteQ4.position() + 1); - } - - if (!filled.get(100)) { - byteQ5.position(byteQ5.position() + 1); - } - - if (!filled.get(101)) { - byteQ6.position(byteQ6.position() + 1); - } - - if (!filled.get(102)) { - byteQ7.position(byteQ7.position() + 1); - } - - if (!filled.get(103)) { - byteR0.position(byteR0.position() + 1); - } - - if (!filled.get(104)) { - byteR1.position(byteR1.position() + 1); - } - - if (!filled.get(105)) { - byteR2.position(byteR2.position() + 1); - } - - if (!filled.get(106)) { - byteR3.position(byteR3.position() + 1); - } - - if (!filled.get(107)) { - cmp.position(cmp.position() + 1); - } - - if (!filled.get(108)) { - ct.position(ct.position() + 32); - } - - if (!filled.get(109)) { - inst.position(inst.position() + 32); - } - - if (!filled.get(110)) { - ofH.position(ofH.position() + 1); - } - - if (!filled.get(111)) { - ofI.position(ofI.position() + 1); - } - - if (!filled.get(112)) { - ofJ.position(ofJ.position() + 1); - } - - if (!filled.get(113)) { - ofRes.position(ofRes.position() + 1); - } - - if (!filled.get(114)) { - oli.position(oli.position() + 1); - } - - if (!filled.get(115)) { - resHi.position(resHi.position() + 32); - } - - if (!filled.get(116)) { - resLo.position(resLo.position() + 32); - } - - if (!filled.get(117)) { - stamp.position(stamp.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/AbstractExtCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/AbstractExtCalculator.java deleted file mode 100644 index 25dded5db..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/AbstractExtCalculator.java +++ /dev/null @@ -1,167 +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.ext.calculator; - -import net.consensys.linea.zktracer.bytestheta.BaseBytes; -import net.consensys.linea.zktracer.bytestheta.BaseTheta; -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import net.consensys.linea.zktracer.module.ext.calculator.addmod.AddModCalculator; -import net.consensys.linea.zktracer.module.ext.calculator.mulmod.MulModCalculator; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * An abstract class representing a calculator for performing extended modular arithmetic - * operations. It provides methods for computing the result of an extended modular arithmetic - * operation, computing various intermediate variables such as comparison flags, deltas, h-values, - * i-values, and j-values, as well as creating an instance of a calculator based on a given OpCode. - */ -public abstract class AbstractExtCalculator { - - /** - * Computes the result of an extended modular arithmetic operation for the given arguments. - * - * @param arg1 the first argument. - * @param arg2 the second argument. - * @param arg3 the third argument. - * @return the result of the extended modular arithmetic operation. - */ - public abstract UInt256 computeResult(Bytes32 arg1, Bytes32 arg2, Bytes32 arg3); - - /** - * Computes the Js array for the given arguments. - * - * @param arg1 the first argument. - * @param arg2 the second argument. - * @return the Js array. - */ - public abstract BytesArray computeJs(Bytes32 arg1, Bytes32 arg2); - - /** - * Computes the Qs array for the given arguments. - * - * @param arg1 the first argument. - * @param arg2 the second argument. - * @param arg3 the third argument. - * @return the Qs array. - */ - public abstract BytesArray computeQs(Bytes32 arg1, Bytes32 arg2, Bytes32 arg3); - - /** - * Computes the overflow result for the given arguments. - * - * @param arg1 the arg1 value. - * @param arg2 the arg2 value. - * @param aBytes the aBytes value. - * @param bBytes the bBytes value. - * @param hBytes the hBytes value. - * @param alpha the alpha value. - * @param beta the beta value. - * @return the overflow result. - */ - public abstract boolean[] computeOverflowRes( - final BaseBytes arg1, - final BaseBytes arg2, - final BytesArray aBytes, - final BytesArray bBytes, - final BytesArray hBytes, - final UInt256 alpha, - final UInt256 beta); - - /** - * Computes the comparison flags for the given arguments. - * - * @param cBytes the cBytes value. - * @param rBytes the rBytes value. - * @return the comparison flags. - */ - public boolean[] computeComparisonFlags(BytesArray cBytes, BytesArray rBytes) { - return CmpFlagsCalculator.computeComparisonFlags(cBytes, rBytes); - } - - /** - * Computes the delta values for the given arguments. - * - * @param cBytes the cBytes value. - * @param rBytes the rBytes value. - * @return the delta values. - */ - public BaseTheta computeDeltas(BytesArray cBytes, BytesArray rBytes) { - return DeltaCalculator.computeDeltas(cBytes, rBytes); - } - - /** - * Sets the Hs array and returns the overflow values for the given arguments. - * - * @param aBytes the aBytes value. - * @param bBytes the bBytes value. - * @param hBytes the hBytes value. - * @return the Hs array. - */ - public boolean[] computeHs(BytesArray aBytes, BytesArray bBytes, BytesArray hBytes) { - return BytesHCalculator.computeHsAndOverflowH(aBytes, bBytes, hBytes); - } - - /** - * Sets the Is array and returns the overflow values for the given arguments. - * - * @param qBytes the qBytes value. - * @param cBytes the cBytes value. - * @param iBytes the iBytes value. - * @return the Is array. - */ - public boolean[] computeIs(BytesArray qBytes, BytesArray cBytes, BytesArray iBytes) { - return BytesICalculator.computeIsAndOverflowI(qBytes, cBytes, iBytes); - } - - /** - * Computes the and returns the overflow values for the given arguments. - * - * @param qBytes the qBytes value. - * @param cBytes the cBytes value. - * @param rBytes the rBytes value. - * @param iBytes the iBytes value. - * @param sigma the sigma value. - * @param tau the tau value. - * @return the overflow result. - */ - public boolean[] computeOverflowJ( - BytesArray qBytes, - BytesArray cBytes, - BytesArray rBytes, - BytesArray iBytes, - UInt256 sigma, - UInt256 tau) { - return OverflowJCalculator.computeOverflowJ(qBytes, cBytes, rBytes, iBytes, sigma, tau); - } - - /** - * Creates a new instance of a calculator based on the given OpCode. - * - * @param opCode the OpCode for which to create a calculator instance. - * @return a new instance of a calculator. - * @throws RuntimeException if the OpCode is not compatible with this calculator. - */ - public static AbstractExtCalculator create(OpCode opCode) { - return switch (opCode) { - case MULMOD -> new MulModCalculator(); - case ADDMOD -> new AddModCalculator(); - default -> throw new RuntimeException( - "Incompatible instruction for extended modular arithmetic module"); - }; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/BytesHCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/BytesHCalculator.java deleted file mode 100644 index ec68014ec..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/BytesHCalculator.java +++ /dev/null @@ -1,106 +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.ext.calculator; - -import static net.consensys.linea.zktracer.module.Util.getBit; -import static net.consensys.linea.zktracer.module.Util.getOverflow; -import static net.consensys.linea.zktracer.module.Util.multiplyRange; - -import net.consensys.linea.zktracer.bytestheta.BaseTheta; -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * A utility class for computing the Hs and overflow values for extended modular arithmetic - * operations. - */ -public class BytesHCalculator { - - /** - * Sets the Hs array and returns the overflow values for the given arguments. - * - * @param aBytes the aBytes value. - * @param bBytes the bBytes value. - * @param hBytes the hBytes value. - * @return the overflow values. - */ - static boolean[] computeHsAndOverflowH(BytesArray aBytes, BytesArray bBytes, BytesArray hBytes) { - boolean[] overflow = new boolean[8]; - - // Calculate alpha - long alpha = calculateAlpha(aBytes, bBytes, hBytes); - overflow[0] = getBit(alpha, 0); - - // Calculate Beta - long beta = calculateBeta(aBytes, bBytes, hBytes); - overflow[1] = getBit(beta, 0); - overflow[2] = getBit(beta, 1); - - // Calculate gamma - long gamma = calculateGamma(aBytes, bBytes, hBytes); - overflow[3] = getBit(gamma, 0); - - return overflow; - } - - /** - * Calculates the alpha value for the given aBytes, bBytes, and hBytes values. - * - * @param aBytes the aBytes value. - * @param bBytes the bBytes value. - * @param hBytes the hBytes value. - * @return the alpha value. - */ - private static long calculateAlpha(BytesArray aBytes, BytesArray bBytes, BytesArray hBytes) { - UInt256 sum = multiplyRange(aBytes.getBytesRange(0, 1), bBytes.getBytesRange(0, 1)); - var truc = BaseTheta.fromBytes32(sum); - hBytes.set(0, truc.get(0)); - hBytes.set(1, truc.get(1)); - return getOverflow(sum, 1, "alpha OOB"); - } - - /** - * Calculates the beta value for the given aBytes, bBytes, and hBytes values. - * - * @param aBytes the aBytes value. - * @param bBytes the bBytes value. - * @param hBytes the hBytes value. - * @return the beta value. - */ - private static long calculateBeta(BytesArray aBytes, BytesArray bBytes, BytesArray hBytes) { - UInt256 sum = multiplyRange(aBytes.getBytesRange(0, 3), bBytes.getBytesRange(0, 3)); - var truc = BaseTheta.fromBytes32(sum); - hBytes.set(2, truc.get(0)); - hBytes.set(3, truc.get(1)); - return getOverflow(sum, 3, "beta OOB"); - } - - /** - * Calculates the gamma value for the given aBytes, bBytes, and hBytes values. - * - * @param aBytes the aBytes value. - * @param bBytes the bBytes value. - * @param hBytes the hBytes value. - * @return the gamma value. - */ - private static long calculateGamma(BytesArray aBytes, BytesArray bBytes, BytesArray hBytes) { - UInt256 sum = multiplyRange(aBytes.getBytesRange(2, 3), bBytes.getBytesRange(2, 3)); - var truc = BaseTheta.fromBytes32(sum); - hBytes.set(4, truc.get(0)); - hBytes.set(5, truc.get(1)); - return getOverflow(sum, 1, "gamma OOB"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/BytesICalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/BytesICalculator.java deleted file mode 100644 index ee98e5745..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/BytesICalculator.java +++ /dev/null @@ -1,118 +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.ext.calculator; - -import static net.consensys.linea.zktracer.module.Util.getBit; -import static net.consensys.linea.zktracer.module.Util.getOverflow; -import static net.consensys.linea.zktracer.module.Util.multiplyRange; - -import net.consensys.linea.zktracer.bytestheta.BaseTheta; -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * A utility class for computing the Is and overflow values for extended modular arithmetic - * operations. - */ -public class BytesICalculator { - /** - * Computes the Is array and overflow values for the given arguments. - * - * @param qBytes the aBytes value. - * @param cBytes the bBytes value. - * @param iBytes the hBytes value. - * @return the overflow values. - */ - static boolean[] computeIsAndOverflowI(BytesArray qBytes, BytesArray cBytes, BytesArray iBytes) { - boolean[] overflowI = new boolean[8]; - - setLastByte(qBytes, cBytes, iBytes); - - long sigma = calculateSigma(qBytes, cBytes, iBytes); - overflowI[0] = getBit(sigma, 0); - - long tau = calculateTau(qBytes, cBytes, iBytes); - overflowI[1] = getBit(tau, 0); - overflowI[2] = getBit(tau, 1); - - long rho = calculateRho(qBytes, cBytes, iBytes); - overflowI[3] = getBit(rho, 0); - overflowI[4] = getBit(rho, 1); - - return overflowI; - } - - /** - * Calculates the value of sigma for the given set of BytesArrays. - * - * @param qBytes the qBytes value. - * @param cBytes the cBytes value. - * @param iBytes the iBytes value. - */ - private static long calculateSigma(BytesArray qBytes, BytesArray cBytes, BytesArray iBytes) { - UInt256 sumSigma = multiplyRange(qBytes.getBytesRange(0, 1), cBytes.getBytesRange(0, 1)); - BaseTheta thetaSigma = BaseTheta.fromBytes32(sumSigma); - iBytes.set(0, thetaSigma.get(0)); - iBytes.set(1, thetaSigma.get(1)); - return getOverflow(sumSigma, 1, "sigma OOB"); - } - - /** - * Calculates the value of tau for the given set of BytesArrays. - * - * @param qBytes the qBytes value. - * @param cBytes the cBytes value. - * @param iBytes the iBytes value. - * @return The computed value of tau - */ - private static long calculateTau(BytesArray qBytes, BytesArray cBytes, BytesArray iBytes) { - UInt256 sumTau = multiplyRange(qBytes.getBytesRange(0, 3), cBytes.getBytesRange(0, 3)); - BaseTheta thetaTau = BaseTheta.fromBytes32(sumTau); - iBytes.set(2, thetaTau.get(0)); - iBytes.set(3, thetaTau.get(1)); - return getOverflow(UInt256.fromBytes(sumTau), 3, "tau OOB"); - } - - /** - * Calculates the value of rho for the given set of BytesArrays. - * - * @param qBytes the qBytes value. - * @param cBytes the cBytes value. - * @param iBytes the iBytes value. - * @return The computed value of rho - */ - private static long calculateRho(BytesArray qBytes, BytesArray cBytes, BytesArray iBytes) { - - UInt256 sumRho = multiplyRange(qBytes.getBytesRange(2, 5), cBytes.getBytesRange(0, 3)); - BaseTheta thetaRho = BaseTheta.fromBytes32(sumRho); - iBytes.set(4, thetaRho.get(0)); - iBytes.set(5, thetaRho.get(1)); - return getOverflow(sumRho, 3, "rho OOB"); - } - - /** - * Set the value of the last byte for the given set of BytesArrays. - * - * @param qBytes the qBytes value. - * @param cBytes the cBytes value. - * @param iBytes the iBytes value. - */ - private static void setLastByte(BytesArray qBytes, BytesArray cBytes, BytesArray iBytes) { - UInt256 lastSum = multiplyRange(qBytes.getBytesRange(4, 7), cBytes.getBytesRange(0, 3)); - BaseTheta lastTheta = BaseTheta.fromBytes32(lastSum); - iBytes.set(6, lastTheta.get(0)); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/CmpFlagsCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/CmpFlagsCalculator.java deleted file mode 100644 index f7750a742..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/CmpFlagsCalculator.java +++ /dev/null @@ -1,45 +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.ext.calculator; - -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import org.apache.tuweni.units.bigints.UInt256; - -/** A utility class for computing comparison flags for extended modular arithmetic operations. */ -public class CmpFlagsCalculator { - - /** - * Computes the comparison flags for the given cBytes and rBytes values. - * - * @param cBytes the cBytes value. - * @param rBytes the rBytes value. - * @return the comparison flags. - */ - static boolean[] computeComparisonFlags(BytesArray cBytes, BytesArray rBytes) { - boolean[] cmp = new boolean[8]; - for (int i = 0; i < 4; i++) { - UInt256 c = UInt256.fromBytes(cBytes.get(i)); - UInt256 r = UInt256.fromBytes(rBytes.get(i)); - boolean cGreaterThanR = c.compareTo(r) > 0; - if (cGreaterThanR) { - cmp[i] = true; - } else { - cmp[4 + i] = c.equals(r); - } - } - return cmp; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/DeltaCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/DeltaCalculator.java deleted file mode 100644 index 35eb1165a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/DeltaCalculator.java +++ /dev/null @@ -1,54 +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.ext.calculator; - -import net.consensys.linea.zktracer.bytestheta.BaseTheta; -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; - -/** A utility class for computing delta values for extended modular arithmetic operations. */ -public class DeltaCalculator { - /** - * Computes the delta values for the given cBytes and rBytes values. - * - * @param cBytes the cBytes value. - * @param rBytes the rBytes value. - * @return the delta values. - */ - public static BaseTheta computeDeltas(BytesArray cBytes, BytesArray rBytes) { - BaseTheta deltaBytes = BaseTheta.fromBytes32(Bytes32.ZERO); - - for (int i = 0; i < 4; i++) { - UInt256 c = UInt256.fromBytes(cBytes.get(i)); - UInt256 r = UInt256.fromBytes(rBytes.get(i)); - UInt256 delta; - - boolean cGreaterThanR = c.compareTo(r) > 0; - if (cGreaterThanR) { - delta = c.subtract(r).subtract(UInt256.ONE); - } else { - delta = r.subtract(c); - } - - // Convert the delta value to a byte array and store it in the ith element of deltaBytes - BaseTheta truc = (BaseTheta.fromBytes32(delta)); - deltaBytes.set(i, truc.get(0)); - } - - return deltaBytes; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/OverflowJCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/OverflowJCalculator.java deleted file mode 100644 index 611522cf3..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/OverflowJCalculator.java +++ /dev/null @@ -1,93 +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.ext.calculator; - -import static net.consensys.linea.zktracer.module.Util.getBit; -import static net.consensys.linea.zktracer.module.Util.getOverflow; -import static net.consensys.linea.zktracer.module.Util.multiplyRange; - -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import org.apache.tuweni.units.bigints.UInt256; - -public class OverflowJCalculator { - - static boolean[] computeOverflowJ( - BytesArray qBytes, - BytesArray cBytes, - BytesArray rBytes, - BytesArray iBytes, - UInt256 sigma, - UInt256 tau) { - boolean[] overflow = new boolean[8]; - - long phi = calculatePhi(qBytes, cBytes, rBytes, iBytes); - overflow[0] = getBit(phi, 0); - overflow[1] = getBit(phi, 1); - - long psi = calculatePsi(phi, qBytes, cBytes, rBytes, iBytes, sigma); - overflow[2] = getBit(psi, 0); - overflow[3] = getBit(psi, 1); - overflow[4] = getBit(psi, 2); - - long chi = calculateChi(psi, qBytes, cBytes, iBytes, tau); - overflow[5] = getBit(chi, 0); - overflow[6] = getBit(chi, 1); - overflow[7] = getBit(chi, 2); - - return overflow; - } - - private static long calculatePhi( - BytesArray qBytes, BytesArray cBytes, BytesArray rBytes, BytesArray iBytes) { - UInt256 prodPhi = multiplyRange(qBytes.getBytesRange(0, 0), cBytes.getBytesRange(0, 0)); - UInt256 sumPhi = - prodPhi.add(UInt256.valueOf(iBytes.get(0).toUnsignedBigInteger().shiftLeft(64))); - sumPhi = sumPhi.add((UInt256.valueOf(rBytes.get(1).toUnsignedBigInteger().shiftLeft(64)))); - sumPhi = sumPhi.add(UInt256.fromBytes(rBytes.get(0))); - return getOverflow(sumPhi, 2, "phi out of range"); - } - - private static long calculatePsi( - long phi, - BytesArray qBytes, - BytesArray cBytes, - BytesArray rBytes, - BytesArray iBytes, - UInt256 sigma) { - - var sumPsi = UInt256.valueOf(phi); - sumPsi = sumPsi.add(UInt256.fromBytes(iBytes.get(1))); - sumPsi = sumPsi.add(UInt256.valueOf(sigma.toUnsignedBigInteger().shiftLeft(64))); - var prodPsi = multiplyRange(cBytes.getBytesRange(0, 2), qBytes.getBytesRange(0, 2)); - sumPsi = sumPsi.add(UInt256.fromBytes(prodPsi)); - sumPsi = sumPsi.add(UInt256.valueOf(iBytes.get(2).toUnsignedBigInteger().shiftLeft(64))); - sumPsi = sumPsi.add(UInt256.valueOf(rBytes.get(3).toUnsignedBigInteger().shiftLeft(64))); - sumPsi = sumPsi.add(UInt256.fromBytes(rBytes.get(2))); - return getOverflow(UInt256.fromBytes(sumPsi.toBytes()), 4, "psi out of range"); - } - - private static long calculateChi( - long psi, BytesArray qBytes, BytesArray cBytes, BytesArray iBytes, UInt256 tau) { - - var sumChi = UInt256.valueOf(psi); - sumChi = sumChi.add(UInt256.fromBytes(iBytes.get(3))); - sumChi = sumChi.add(UInt256.valueOf(tau.toUnsignedBigInteger().shiftLeft(64))); - var prodChi = multiplyRange(cBytes.getBytesRange(0, 3), qBytes.getBytesRange(1, 4)); - sumChi = sumChi.add(prodChi); - sumChi = sumChi.add(UInt256.valueOf(iBytes.get(4).toUnsignedBigInteger().shiftLeft(64))); - return getOverflow(sumChi, 4, "chi out of range"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModBytesJCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModBytesJCalculator.java deleted file mode 100644 index 8cb3ea2aa..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModBytesJCalculator.java +++ /dev/null @@ -1,52 +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.ext.calculator.addmod; - -import static net.consensys.linea.zktracer.module.Util.uInt64ToBytes; - -import net.consensys.linea.zktracer.bytestheta.BaseTheta; -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * Provides functionality to compute Js by adding two Bytes objects and converting the result into a - * byte array matrix. - */ -public class AddModBytesJCalculator { - /** - * Computes the Js by adding two Bytes objects, converting the result into a byte array matrix. - * - * @param arg1 the first Bytes object to be added - * @param arg2 the second Bytes object to be added - * @return a BytesArray object containing the computed Js as a byte array matrix - */ - public static BytesArray computeJs(Bytes arg1, Bytes arg2) { - byte[][] jBytes = new byte[8][8]; - UInt256 sum = UInt256.fromBytes(arg1).add(UInt256.fromBytes(arg2)); - BaseTheta sumBaseTheta = BaseTheta.fromBytes32(sum); - - for (int k = 0; k < 4; k++) { - jBytes[k] = sumBaseTheta.get(k).toArray(); - } - - if (UInt256.fromBytes(arg1).compareTo(sum) > 0) { - jBytes[4] = uInt64ToBytes(1); - } - - return new BytesArray(jBytes); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModBytesQCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModBytesQCalculator.java deleted file mode 100644 index 0a4c9cca8..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModBytesQCalculator.java +++ /dev/null @@ -1,83 +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.ext.calculator.addmod; - -import static net.consensys.linea.zktracer.module.Util.uInt64ToBytes; -import static net.consensys.linea.zktracer.module.ext.BigIntegerConverter.fromLongArray; - -import java.math.BigInteger; - -import net.consensys.linea.zktracer.bytestheta.BaseTheta; -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import net.consensys.linea.zktracer.module.UtilCalculator; -import net.consensys.linea.zktracer.module.ext.BigIntegerConverter; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * A calculator for computing the Q values for an AddMod operation in bytes format. Q values are - * calculated based on the given arguments arg1, arg2 and arg3. If the sum of arg1 and arg2 is less - * than or equal to arg3, then q values are calculated as the quotient of the sum and arg3 converted - * to base theta. If the sum of arg1 and arg2 is greater than arg3, then q values are calculated by - * dividing the sum and arg3 in BigInteger format with overflow, and converting the quotient to - * bytes format. - */ -public class AddModBytesQCalculator { - - /** - * Computes Q values for an AddMod operation based on the given arguments. - * - * @param arg1 the first argument in bytes32 format - * @param arg2 the second argument in bytes32 format - * @param arg3 the third argument in bytes32 format - * @return the calculated Q values in bytes format as a BytesArray - */ - public static BytesArray computeQs(Bytes32 arg1, Bytes32 arg2, Bytes32 arg3) { - byte[][] qBytes = new byte[8][8]; - UInt256 sum = UtilCalculator.calculateSum(arg1, arg2); - - // Addition does not overflow - if (UInt256.fromBytes(arg1).compareTo(sum) <= 0) { - BigInteger quotBigInteger = - UtilCalculator.calculateQuotient(sum.toUnsignedBigInteger(), arg3); - BaseTheta quotBaseTheta = UtilCalculator.convertToBaseTheta(quotBigInteger); - - for (int k = 0; k < 4; k++) { - qBytes[k] = quotBaseTheta.get(k).toArray(); - } - } else { - BigInteger bigIntegerOverflow = convertToBigIntegerWithOverflow(sum); - BigInteger[] divAndRemainder = - bigIntegerOverflow.divideAndRemainder(arg3.toUnsignedBigInteger()); - long[] quot = BigIntegerConverter.toLongArray(divAndRemainder[0]); - for (int k = 0; k < quot.length; k++) { - qBytes[k] = uInt64ToBytes(quot[k]); - } - } - - return new BytesArray(qBytes); - } - - private static BigInteger convertToBigIntegerWithOverflow(UInt256 sum) { - long[] sumUInt64 = new long[5]; - for (int k = 0; k < 4; k++) { - sumUInt64[k] = sum.toUnsignedBigInteger().shiftRight(k * 64).longValue(); - } - sumUInt64[4] = 1L; - - return fromLongArray(sumUInt64); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModCalculator.java deleted file mode 100644 index 99d483615..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModCalculator.java +++ /dev/null @@ -1,69 +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.ext.calculator.addmod; - -import net.consensys.linea.zktracer.bytestheta.BaseBytes; -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import net.consensys.linea.zktracer.module.ext.calculator.AbstractExtCalculator; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; - -/** Calculator for performing extended modular arithmetic operations. */ -public class AddModCalculator extends AbstractExtCalculator { - - @Override - public UInt256 computeResult(final Bytes32 arg1, final Bytes32 arg2, final Bytes32 arg3) { - if (arg3.isZero()) { - return UInt256.ZERO; - } - - return UInt256.fromBytes(arg1).addMod(UInt256.fromBytes(arg2), UInt256.fromBytes(arg3)); - } - - @Override - public BytesArray computeJs(final Bytes32 arg1, final Bytes32 arg2) { - return AddModBytesJCalculator.computeJs(arg1, arg2); - } - - @Override - public BytesArray computeQs(final Bytes32 arg1, final Bytes32 arg2, final Bytes32 arg3) { - return AddModBytesQCalculator.computeQs(arg1, arg2, arg3); - } - - /** - * Computes the overflow result for the given arguments. - * - * @param arg1 the arg1 value. - * @param arg2 the arg2 value. - * @param aBytes the aBytes value. - * @param bBytes the bBytes value. - * @param hBytes the hBytes value. - * @param alpha the alpha value. - * @param beta the beta value. - * @return the overflow result. - */ - @Override - public boolean[] computeOverflowRes( - final BaseBytes arg1, - final BaseBytes arg2, - final BytesArray aBytes, - final BytesArray bBytes, - final BytesArray hBytes, - final UInt256 alpha, - final UInt256 beta) { - return AddModOverflowResCalculator.calculateOverflow(arg1, arg2); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModOverflowResCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModOverflowResCalculator.java deleted file mode 100644 index f9f0ac5c1..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/addmod/AddModOverflowResCalculator.java +++ /dev/null @@ -1,81 +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.ext.calculator.addmod; - -import static net.consensys.linea.zktracer.module.Util.getBit; -import static net.consensys.linea.zktracer.module.Util.getOverflow; - -import net.consensys.linea.zktracer.bytestheta.BaseBytes; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * A utility class to calculate overflow values for the AddMod operation. The class provides methods - * for calculating overflow values for two input arguments of the AddMod operation. The calculation - * involves calculating the sum of the two input arguments and determining if the sum overflows the - * bit size of the operands. The method returns a boolean array of size 2 that contains the overflow - * values for lambda and mu respectively. - */ -public class AddModOverflowResCalculator { - /** - * Calculates the overflow values of the result for two input arguments of the AddMod operation. - * - * @param arg1 the first input argument of the AddMod operation. - * @param arg2 the second input argument of the AddMod operation. - * @return a boolean array of size 2 that contains the overflow values for lambda and mu - * respectively. - */ - static boolean[] calculateOverflow(BaseBytes arg1, BaseBytes arg2) { - boolean[] overflowRes = new boolean[8]; - - long lambda = calculateLambda(arg1, arg2); - - long mu = calculateMu(lambda, arg1, arg2); - - overflowRes[0] = getBit(lambda, 0); - overflowRes[1] = getBit(mu, 0); - - return overflowRes; - } - - /** - * Calculates the lambda value. - * - * @param arg1 the first input argument of the AddMod operation. - * @param arg2 the second input argument of the AddMod operation. - * @return the lambda value. - */ - private static long calculateLambda(BaseBytes arg1, BaseBytes arg2) { - UInt256 sum = UInt256.fromBytes(arg1.getLow()).add(UInt256.fromBytes(arg2.getLow())); - - return getOverflow(sum, 1, "lambda out of range (ADDMOD)"); - } - - /** - * Calculates the mu value. - * - * @param lambda the lambda value. - * @param arg1 the first input argument of the AddMod operation. - * @param arg2 the second input argument of the AddMod operation. - * @return the mu value. - */ - private static long calculateMu(long lambda, BaseBytes arg1, BaseBytes arg2) { - UInt256 sum = UInt256.valueOf(lambda); - sum = sum.add(UInt256.fromBytes(arg1.getHigh())); - sum = sum.add(UInt256.fromBytes(arg2.getHigh())); - - return getOverflow(sum, 3, "mu out of range (ADDMOD)"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModBytesJCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModBytesJCalculator.java deleted file mode 100644 index 9857b4e4a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModBytesJCalculator.java +++ /dev/null @@ -1,50 +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.ext.calculator.mulmod; - -import static net.consensys.linea.zktracer.module.Util.uInt64ToBytes; - -import java.math.BigInteger; - -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import net.consensys.linea.zktracer.module.ext.BigIntegerConverter; -import org.apache.tuweni.bytes.Bytes32; - -public class MulModBytesJCalculator { - /** - * Computes the product of two Bytes32 arguments and returns the result as a BytesArray. - * - * @param arg1 The first Bytes32 argument. - * @param arg2 The second Bytes32 argument. - * @return The product of the two arguments as a BytesArray. - */ - public static BytesArray computeJs(Bytes32 arg1, Bytes32 arg2) { - byte[][] jBytes = new byte[8][8]; - - BigInteger arg1UInt = arg1.toUnsignedBigInteger(); - BigInteger arg2UInt = arg2.toUnsignedBigInteger(); - // Compute the product of the two unsigned BigIntegers. - BigInteger prod = arg1UInt.multiply(arg2UInt); - - long[] prodArray = BigIntegerConverter.toLongArray(prod); - // Iterate through the long array and convert each element to a byte array. - for (int k = 0; k < prodArray.length; k++) { - jBytes[k] = uInt64ToBytes(prodArray[k]); - } - - return new BytesArray(jBytes); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModBytesQCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModBytesQCalculator.java deleted file mode 100644 index 3177d550f..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModBytesQCalculator.java +++ /dev/null @@ -1,63 +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.ext.calculator.mulmod; - -import static net.consensys.linea.zktracer.module.Util.isUInt256; -import static net.consensys.linea.zktracer.module.Util.uInt64ToBytes; - -import java.math.BigInteger; - -import net.consensys.linea.zktracer.bytestheta.BaseTheta; -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import net.consensys.linea.zktracer.module.UtilCalculator; -import net.consensys.linea.zktracer.module.ext.BigIntegerConverter; -import org.apache.tuweni.bytes.Bytes32; - -public class MulModBytesQCalculator { - /** - * Computes the quotient of the product of arg1 and arg2 divided by arg3, all of Bytes32 type, and - * returns the result as a BytesArray. (arg1 * arg2 ) / arg3 - * - * @param arg1 The first Bytes32 argument. - * @param arg2 The second Bytes32 argument. - * @param arg3 The third Bytes32 argument. - * @return The quotient of the product of arg1 and arg2 divided by arg3 as a BytesArray. - */ - public static BytesArray computeQs(Bytes32 arg1, Bytes32 arg2, Bytes32 arg3) { - byte[][] qBytes = new byte[8][8]; - - BigInteger prod = UtilCalculator.calculateProduct(arg1, arg2); - - if (isUInt256(prod)) { - BigInteger quotBigInteger = UtilCalculator.calculateQuotient(prod, arg3); - BaseTheta quotBaseTheta = UtilCalculator.convertToBaseTheta(quotBigInteger); - - for (int i = 0; i < 4; i++) { - // Copy the BaseTheta byte arrays into the result byte array. - qBytes[i] = quotBaseTheta.get(i).toArray(); - } - } else { - // Divide the product by arg3 and convert the quotient to a byte array. - BigInteger[] divAndRemainder = prod.divideAndRemainder(arg3.toUnsignedBigInteger()); - long[] quot = BigIntegerConverter.toLongArray(divAndRemainder[0]); - for (int k = 0; k < quot.length; k++) { - qBytes[k] = uInt64ToBytes(quot[k]); - } - } - // Return the result as a BytesArray. - return new BytesArray(qBytes); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModCalculator.java deleted file mode 100644 index d05ed95e7..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModCalculator.java +++ /dev/null @@ -1,83 +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.ext.calculator.mulmod; - -import net.consensys.linea.zktracer.bytestheta.BaseBytes; -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import net.consensys.linea.zktracer.module.ext.calculator.AbstractExtCalculator; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; - -public class MulModCalculator extends AbstractExtCalculator { - @Override - public UInt256 computeResult(Bytes32 arg1, Bytes32 arg2, Bytes32 modulo) { - if (modulo.isZero()) { - return UInt256.ZERO; - } - - return UInt256.fromBytes(arg1).multiplyMod(UInt256.fromBytes(arg2), UInt256.fromBytes(modulo)); - } - - /** - * Computes the product of two Bytes32 arguments and returns the result as a BytesArray. - * - * @param arg1 The first Bytes32 argument. - * @param arg2 The second Bytes32 argument. - * @return The product of the two arguments as a BytesArray. - */ - @Override - public BytesArray computeJs(Bytes32 arg1, Bytes32 arg2) { - return MulModBytesJCalculator.computeJs(arg1, arg2); - } - - /** - * Computes the quotient of the product of arg1 and arg2 divided by arg3, all of Bytes32 type, and - * returns the result as a BytesArray. - * - * @param arg1 The first Bytes32 argument. - * @param arg2 The second Bytes32 argument. - * @param arg3 The third Bytes32 argument. - * @return The quotient of the product of arg1 and arg2 divided by arg3 as a BytesArray. - */ - @Override - public BytesArray computeQs(Bytes32 arg1, Bytes32 arg2, Bytes32 arg3) { - return MulModBytesQCalculator.computeQs(arg1, arg2, arg3); - } - - /** - * Computes the overflow result for the given arguments. - * - * @param arg1 the arg1 value. - * @param arg2 the arg2 value. - * @param aBytes the aBytes value. - * @param bBytes the bBytes value. - * @param hBytes the hBytes value. - * @param alpha the alpha value. - * @param beta the beta value. - * @return the overflow result. - */ - @Override - public boolean[] computeOverflowRes( - BaseBytes arg1, - BaseBytes arg2, - BytesArray aBytes, - BytesArray bBytes, - BytesArray hBytes, - UInt256 alpha, - UInt256 beta) { - return MulModOverflowResCalculator.calculateOverflow(aBytes, bBytes, hBytes, alpha, beta); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModOverflowResCalculator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModOverflowResCalculator.java deleted file mode 100644 index 5ad3e004c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/calculator/mulmod/MulModOverflowResCalculator.java +++ /dev/null @@ -1,109 +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.ext.calculator.mulmod; - -import static net.consensys.linea.zktracer.module.Util.getBit; -import static net.consensys.linea.zktracer.module.Util.getOverflow; -import static net.consensys.linea.zktracer.module.Util.multiplyRange; - -import net.consensys.linea.zktracer.bytestheta.BytesArray; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * A utility class for computing the Result overflow value for extended modular arithmetic - * operations. (MulMod) - */ -public class MulModOverflowResCalculator { - static boolean[] calculateOverflow( - BytesArray aBytes, BytesArray bBytes, BytesArray hBytes, UInt256 alpha, UInt256 beta) { - - boolean[] overflowRes = new boolean[8]; - // Calculate lambda - long lambda = calculateLambda(aBytes, bBytes, hBytes); - - // Calculate mu - long mu = calculateMu(lambda, aBytes, bBytes, hBytes, alpha); - // Store results in the boolean array - overflowRes[0] = getBit(lambda, 0); - overflowRes[1] = getBit(mu, 0); - overflowRes[2] = getBit(mu, 1); - - // Calculate nu - long nu = calculateNu(mu, aBytes, bBytes, hBytes, beta); - // Store results in the boolean array - overflowRes[3] = getBit(nu, 0); - overflowRes[4] = getBit(nu, 1); - - // Return the boolean array containing the overflow results - return overflowRes; - } - - /** - * Calculates lambda based on input parameters. - * - * @param aBytes the first input parameter as a BaseTheta object - * @param bBytes the second input parameter as a BaseTheta object - * @param hBytes the third input parameter as a BytesArray object - * @return the calculated lambda value as a long - */ - private static long calculateLambda(BytesArray aBytes, BytesArray bBytes, BytesArray hBytes) { - var sum = multiplyRange(aBytes.getBytesRange(0, 0), bBytes.getBytesRange(0, 0)); - sum = sum.add(UInt256.valueOf(hBytes.get(0).toUnsignedBigInteger().shiftLeft(64))); - return getOverflow(sum, 1, "lambda out of range (MULMOD)"); - } - - /** - * Calculates mu based on input parameters. - * - * @param lambda the lambda value as a long - * @param aBytes the first input parameter as a BaseTheta object - * @param bBytes the second input parameter as a BaseTheta object - * @param hBytes the third input parameter as a BytesArray object - * @param alpha the fourth input parameter as a UInt256 object - * @return the calculated mu value as a long - */ - private static long calculateMu( - long lambda, BytesArray aBytes, BytesArray bBytes, BytesArray hBytes, UInt256 alpha) { - var sum = UInt256.valueOf(lambda); - sum = sum.add(UInt256.fromBytes(hBytes.get(1))); - sum = sum.add(UInt256.valueOf(alpha.toUnsignedBigInteger().shiftLeft(64))); - sum = sum.add((UInt256.fromBytes(aBytes.get(2)).multiply(UInt256.fromBytes(bBytes.get(0))))); - sum = sum.add((UInt256.fromBytes(aBytes.get(1)).multiply(UInt256.fromBytes(bBytes.get(1))))); - sum = sum.add((UInt256.fromBytes(aBytes.get(0)).multiply(UInt256.fromBytes(bBytes.get(2))))); - sum = sum.add(UInt256.valueOf(hBytes.get(2).toUnsignedBigInteger().shiftLeft(64))); - return getOverflow(sum, 3, "mu out of range (MULMOD)"); - } - - /** - * Calculates nu based on input parameters. - * - * @param mu the mu value as a long - * @param aBytes the first input parameter as a BaseTheta object - * @param bBytes the second input parameter as a BaseTheta object - * @param hBytes the third input parameter as a BytesArray object - * @param beta the fifth input parameter as a UInt256 object - * @return the calculated nu value as a long - */ - private static long calculateNu( - long mu, BytesArray aBytes, BytesArray bBytes, BytesArray hBytes, UInt256 beta) { - var sum = UInt256.valueOf(mu); - sum = sum.add(UInt256.fromBytes(hBytes.get(3))); - sum = sum.add(UInt256.valueOf(beta.toUnsignedBigInteger().shiftLeft(64))); - sum = sum.add(multiplyRange(bBytes.getBytesRange(1, 3), aBytes.getBytesRange(1, 3))); - sum = sum.add(UInt256.valueOf(hBytes.get(4).toUnsignedBigInteger().shiftLeft(64))); - return getOverflow(sum, 3, "nu out of range (MULMOD)"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AbortingConditions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AbortingConditions.java deleted file mode 100644 index 46b2075ea..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AbortingConditions.java +++ /dev/null @@ -1,100 +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 lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; - -/** Records the aborting conditions that may happen during a CALL or a CREATE. */ -@Getter -@NoArgsConstructor -@Accessors(fluent = true) -public final class AbortingConditions { - private boolean callStackOverflow; - private boolean balanceTooLow; - - /** - * @param callStackOverflow too many nested contexts - * @param balanceTooLow trying to give more ETH than the caller has - */ - public AbortingConditions(boolean callStackOverflow, boolean balanceTooLow) { - this.callStackOverflow = callStackOverflow; - this.balanceTooLow = balanceTooLow; - } - - public static AbortingConditions of(Hub hub) { - AbortingConditions r = new AbortingConditions(); - r.prepare(hub); - return r; - } - - public void reset() { - this.callStackOverflow = false; - this.balanceTooLow = false; - } - - public void prepare(Hub hub) { - this.callStackOverflow = hub.callStack().wouldOverflow(); - if (this.callStackOverflow) { - return; - } - - this.balanceTooLow = - switch (hub.currentFrame().opCode()) { - case CALL, CALLCODE -> { - if (hub.pch().exceptions().none()) { - final Address myAddress = hub.currentFrame().address(); - final Wei myBalance = - hub.messageFrame().getWorldUpdater().get(myAddress).getBalance(); - final Wei value = Wei.of(UInt256.fromBytes(hub.messageFrame().getStackItem(2))); - - yield value.greaterThan(myBalance); - } else { - yield false; - } - } - case CREATE, CREATE2 -> { - if (hub.pch().exceptions().none()) { - final Address myAddress = hub.currentFrame().address(); - final Wei myBalance = - hub.messageFrame().getWorldUpdater().get(myAddress).getBalance(); - final Wei value = Wei.of(UInt256.fromBytes(hub.messageFrame().getStackItem(0))); - - yield value.greaterThan(myBalance); - } else { - yield false; - } - } - default -> false; - }; - } - - public AbortingConditions snapshot() { - return new AbortingConditions(this.callStackOverflow, this.balanceTooLow); - } - - public boolean none() { - return !this.any(); - } - - public boolean any() { - return this.callStackOverflow || this.balanceTooLow; - } -} 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 deleted file mode 100644 index fb53ee23d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ /dev/null @@ -1,46 +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 org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.account.Account; - -public record AccountSnapshot( - Address address, - long nonce, - Wei balance, - boolean warm, - Bytecode code, - int deploymentNumber, - boolean deploymentStatus) { - public static AccountSnapshot fromAccount( - Account account, boolean warm, int deploymentNumber, boolean deploymentStatus) { - if (account == null) { - return new AccountSnapshot( - Address.ZERO, 0, Wei.ZERO, warm, Bytecode.EMPTY, deploymentNumber, deploymentStatus); - } - - return new AccountSnapshot( - account.getAddress(), - account.getNonce(), - account.getBalance().copy(), - warm, - new Bytecode(account.getCode().copy()), - deploymentNumber, - deploymentStatus); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/BlockInfo.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/BlockInfo.java deleted file mode 100644 index e0cae1415..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/BlockInfo.java +++ /dev/null @@ -1,42 +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 lombok.Getter; -import lombok.experimental.Accessors; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.plugin.data.ProcessableBlockHeader; - -/** Stores block-specific information. */ -@Accessors(fluent = true) -@Getter -public class BlockInfo { - int blockNumber = 0; - Address minerAddress; - Wei baseFee; - - /** - * Update block-specific information on new block entrance. - * - * @param processableBlockHeader the processable block header - */ - public void update(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/module/hub/Bytecode.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Bytecode.java deleted file mode 100644 index 341d73dd7..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Bytecode.java +++ /dev/null @@ -1,95 +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 java.util.Objects; - -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.evm.Code; - -/** This class is intended to store a bytecode and its memoized hash. */ -public final class Bytecode { - /** The empty bytecode. */ - public static Bytecode EMPTY = new Bytecode(Bytes.EMPTY); - - /** The bytecode. */ - private final Bytes bytecode; - /** The bytecode hash; is null by default and computed & memoized on the fly when required. */ - private Hash hash; - - /** - * Create an instance from {@link Bytes}. - * - * @param bytes the bytecode - */ - public Bytecode(Bytes bytes) { - this.bytecode = Objects.requireNonNullElse(bytes, Bytes.EMPTY); - } - - /** - * Create an instance from Besu {@link Code}. - * - * @param code the bytecode - */ - public Bytecode(Code code) { - this.bytecode = code.getBytes(); - this.hash = code.getCodeHash(); - } - - /** - * Get the size of the bytecode, in bytes. - * - * @return the bytecode size - */ - public int getSize() { - return this.bytecode.size(); - } - - /** - * Expose the wrapped bytecode as {@link Bytes}. - * - * @return the bytecode - */ - public Bytes getBytes() { - return this.bytecode; - } - - /** - * Returns whether the bytecode is empty or not. - * - * @return true if the bytecode is empty - */ - public boolean isEmpty() { - return this.bytecode.isEmpty(); - } - - /** - * Compute the bytecode hash if required, then return it. - * - * @return the bytecode hash - */ - public Hash getCodeHash() { - if (this.hash == null) { - if (this.bytecode.isEmpty()) { - this.hash = Hash.EMPTY; - } else { - this.hash = Hash.hash(this.bytecode); - } - } - return this.hash; - } -} 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 deleted file mode 100644 index 2de9fe2d4..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/DeploymentExceptions.java +++ /dev/null @@ -1,63 +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.runtime.callstack.CallFrame; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.frame.MessageFrame; - -/** - * Encode the exceptions that can be raised at the end of the execution of a call frame. - * - * @param invalidCodePrefix trying to deploy a contract starting with 0xEF - * @param codeSizeOverflow trying to deploy a contract larger than 24KB - */ -public record DeploymentExceptions(boolean invalidCodePrefix, boolean codeSizeOverflow) { - private static final byte EIP_3541_MARKER = (byte) 0xEF; - private static final int MAX_CODE_SIZE = 24576; - - private static boolean isInvalidCodePrefix(MessageFrame frame) { - final Bytes deployedCode = frame.getOutputData(); - return !deployedCode.isEmpty() && (deployedCode.get(0) == EIP_3541_MARKER); - } - - private static boolean isCodeSizeOverflow(MessageFrame frame) { - final Bytes deployedCode = frame.getOutputData(); - - return deployedCode.size() > MAX_CODE_SIZE; - } - - public static DeploymentExceptions empty() { - return new DeploymentExceptions(false, false); - } - - public static DeploymentExceptions fromFrame( - final CallFrame callFrame, final MessageFrame frame) { - if (callFrame.underDeployment()) { - return new DeploymentExceptions(isInvalidCodePrefix(frame), isCodeSizeOverflow(frame)); - } else { - return new DeploymentExceptions(false, false); - } - } - - public boolean any() { - return this.invalidCodePrefix || this.codeSizeOverflow; - } - - public boolean none() { - return !this.any(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/DeploymentInfo.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/DeploymentInfo.java deleted file mode 100644 index 1b9899638..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/DeploymentInfo.java +++ /dev/null @@ -1,55 +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 java.util.HashMap; -import java.util.Map; - -import org.hyperledger.besu.datatypes.Address; - -/** Stores information relative to contract deployment. */ -public class DeploymentInfo { - private final Map deploymentNumber = new HashMap<>(); - private final Map isDeploying = new HashMap<>(); - - /** - * Returns the deployment number of the given address; sets it to zero if it is the first - * deployment of this address. - * - * @param address the address to get information for - * @return the deployment number for this address - */ - public final int number(Address address) { - return this.deploymentNumber.getOrDefault(address, 0); - } - - void deploy(Address address) { - this.deploymentNumber.put(address, this.number(address) + 1); - this.markDeploying(address); - } - - public final boolean isDeploying(Address address) { - return this.isDeploying.getOrDefault(address, false); - } - - public final void markDeploying(Address address) { - this.isDeploying.put(address, true); - } - - public final void unmarkDeploying(Address address) { - this.isDeploying.put(address, false); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Exceptions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Exceptions.java deleted file mode 100644 index 7e3472a31..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Exceptions.java +++ /dev/null @@ -1,410 +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 lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; -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; -import org.hyperledger.besu.evm.internal.Words; - -/** Encode the exceptions that may be triggered byt the execution of an instruction. */ -@Getter -@RequiredArgsConstructor -@Accessors(fluent = true) -public final class Exceptions { - private static final byte EIP_3541_MARKER = (byte) 0xEF; - public static final int MAX_CODE_SIZE = 24576; - - private final Hub hub; - - private boolean invalidOpcode; - private boolean stackUnderflow; - private boolean stackOverflow; - private boolean outOfMemoryExpansion; - private boolean outOfGas; - private boolean returnDataCopyFault; - private boolean jumpFault; - private boolean staticFault; - private boolean outOfSStore; - private boolean invalidCodePrefix; - private boolean codeSizeOverflow; - - /** - * @param invalidOpcode unknown opcode - * @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 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 - */ - public Exceptions( - boolean invalidOpcode, - boolean stackUnderflow, - boolean stackOverflow, - boolean outOfMemoryExpansion, - boolean outOfGas, - boolean returnDataCopyFault, - boolean jumpFault, - boolean staticFault, - boolean outOfSStore, - boolean invalidCodePrefix, - boolean codeSizeOverflow) { - this.hub = null; - this.invalidOpcode = invalidOpcode; - this.stackUnderflow = stackUnderflow; - this.stackOverflow = stackOverflow; - this.outOfMemoryExpansion = outOfMemoryExpansion; - this.outOfGas = outOfGas; - this.returnDataCopyFault = returnDataCopyFault; - this.jumpFault = jumpFault; - this.staticFault = staticFault; - this.outOfSStore = outOfSStore; - this.invalidCodePrefix = invalidCodePrefix; - this.codeSizeOverflow = codeSizeOverflow; - } - - @Override - public String toString() { - if (this.invalidOpcode) { - return "Invalid opcode"; - } - if (this.stackUnderflow) { - return "Stack underflow"; - } - if (this.stackOverflow) { - return "Stack overflow"; - } - if (this.outOfMemoryExpansion) { - return "Out of MXP"; - } - if (this.outOfGas) { - return "Out of gas"; - } - if (this.returnDataCopyFault) { - return "RDC fault"; - } - if (this.jumpFault) { - return "JMP fault"; - } - if (this.staticFault) { - return "Static fault"; - } - if (this.outOfSStore) { - return "Out of SSTORE"; - } - if (this.invalidCodePrefix) { - return "Invalid code prefix"; - } - if (this.codeSizeOverflow) { - return "Code size overflow"; - } - return "No exception"; - } - - public void reset() { - this.invalidOpcode = false; - this.stackUnderflow = false; - this.stackOverflow = false; - this.outOfMemoryExpansion = false; - this.outOfGas = false; - this.returnDataCopyFault = false; - this.jumpFault = false; - this.staticFault = false; - this.outOfSStore = false; - this.invalidCodePrefix = false; - this.codeSizeOverflow = false; - } - - public boolean stackException() { - return this.stackUnderflow() || this.stackOverflow(); - } - /** - * @return true if no stack exception has been raised - */ - public boolean noStackException() { - return !this.stackException(); - } - - /** - * Creates a snapshot (a copy) of the given Exceptions object. - * - * @return a new Exceptions - */ - public Exceptions snapshot() { - return new Exceptions( - invalidOpcode, - stackUnderflow, - stackOverflow, - outOfMemoryExpansion, - outOfGas, - returnDataCopyFault, - jumpFault, - staticFault, - outOfSStore, - invalidCodePrefix, - codeSizeOverflow); - } - - /** - * @return true if any exception flag has been raised - */ - public boolean any() { - return this.invalidOpcode - || this.stackUnderflow - || this.stackOverflow - || this.outOfMemoryExpansion - || this.outOfGas - || this.returnDataCopyFault - || this.jumpFault - || this.staticFault - || this.outOfSStore - || this.invalidCodePrefix - || this.codeSizeOverflow; - } - - /** - * @return true if no exception flag has been raised - */ - public boolean none() { - return !this.any(); - } - - private static boolean isInvalidOpcode(final OpCode opCode) { - return opCode == OpCode.INVALID; - } - - private static boolean isStackUnderflow(final MessageFrame frame, OpCodeData opCodeData) { - return frame.stackSize() < opCodeData.stackSettings().nbRemoved(); - } - - private static boolean isStackOverflow(final MessageFrame frame, OpCodeData opCodeData) { - return frame.stackSize() - + opCodeData.stackSettings().nbAdded() - - opCodeData.stackSettings().nbRemoved() - > 1024; - } - - private static boolean isMemoryExpansionFault( - MessageFrame frame, OpCode opCode, GasProjector gp) { - return gp.of(frame, opCode).largestOffset() > 0xffffffffL; - } - - private static boolean isOutOfGas(MessageFrame frame, OpCode opCode, GasProjector gp) { - final long required = gp.of(frame, opCode).total(); - return required > frame.getRemainingGas(); - } - - private static boolean isReturnDataCopyFault(final MessageFrame frame, final OpCode opCode) { - if (opCode == OpCode.RETURNDATACOPY) { - long returnDataSize = frame.getReturnData().size(); - long askedOffset = Words.clampedToLong(frame.getStackItem(1)); - long askedSize = Words.clampedToLong(frame.getStackItem(2)); - - return Words.clampedAdd(askedOffset, askedSize) > returnDataSize; - } - - return false; - } - - private static boolean isJumpFault(final MessageFrame frame, OpCode opCode) { - if (opCode == OpCode.JUMP || opCode == OpCode.JUMPI) { - final long target = Words.clampedToLong(frame.getStackItem(0)); - final boolean invalidDestination = frame.getCode().isJumpDestInvalid((int) target); - - switch (opCode) { - case JUMP -> { - return invalidDestination; - } - case JUMPI -> { - long condition = Words.clampedToLong(frame.getStackItem(1)); - return (condition != 0) && invalidDestination; - } - default -> { - return false; - } - } - } - - return false; - } - - private static boolean isStaticFault(final MessageFrame frame, OpCodeData opCodeData) { - if (frame.isStatic() && opCodeData.mnemonic() == OpCode.CALL && frame.stackSize() > 2) { - final long value = Words.clampedToLong(frame.getStackItem(2)); - if (value > 0) { - return true; - } - } - - return frame.isStatic() && opCodeData.stackSettings().forbiddenInStatic(); - } - - private static boolean isOutOfSStore(MessageFrame frame, OpCode opCode) { - return opCode == OpCode.SSTORE && frame.getRemainingGas() <= GasConstants.G_CALL_STIPEND.cost(); - } - - private static boolean isInvalidCodePrefix(MessageFrame frame) { - if (frame.getType() != MessageFrame.Type.CONTRACT_CREATION) { - return false; - } - - final Bytes deployedCode = frame.getOutputData(); - return !deployedCode.isEmpty() && (deployedCode.get(0) == EIP_3541_MARKER); - } - - private static boolean isCodeSizeOverflow(MessageFrame frame) { - if (frame.getType() != MessageFrame.Type.CONTRACT_CREATION) { - return false; - } - - // TODO: don't get it from getOutputData, but only when OPCODE == RETURN && read in memory - final Bytes deployedCode = frame.getOutputData(); - return deployedCode.size() > MAX_CODE_SIZE; - } - - public static Exceptions fromOutOfGas() { - return new Exceptions( - false, false, false, false, true, false, false, false, false, false, false); - } - - /** - * Compute all the first exception that may have happened in the current frame. Wlthout multiple - * exceptions may be triggered, the one minimizing the quantity of trace lines is generated. - * - * @param frame the context from which to compute the putative exceptions - */ - public void prepare(final MessageFrame frame, GasProjector gp) { - OpCode opCode = hub.opCode(); - OpCodeData opCodeData = hub.opCodeData(); - - this.reset(); - - this.invalidOpcode = isInvalidOpcode(opCode); - if (this.invalidOpcode) { - return; - } - - this.stackUnderflow = isStackUnderflow(frame, opCodeData); - if (this.stackUnderflow) { - return; - } - - this.stackOverflow = isStackOverflow(frame, opCodeData); - if (this.stackOverflow) { - return; - } - - this.staticFault = isStaticFault(frame, opCodeData); - if (this.staticFault) { - return; - } - - this.codeSizeOverflow = isCodeSizeOverflow(frame); - if (this.codeSizeOverflow) { - return; - } - - switch (opCode) { - case CALLDATACOPY, - CODECOPY, - EXTCODECOPY, - LOG0, - LOG1, - LOG2, - LOG3, - LOG4, - SHA3, - CREATE, - CREATE2, - CALL, - DELEGATECALL, - STATICCALL, - CALLCODE, - RETURN, - REVERT, - CALLDATALOAD, - MLOAD, - MSTORE, - MSTORE8 -> { - this.outOfMemoryExpansion = isMemoryExpansionFault(frame, opCode, gp); - if (this.outOfMemoryExpansion) { - return; - } - - this.outOfGas = isOutOfGas(frame, opCode, gp); - if (this.outOfGas) { - return; - } - } - case RETURNDATACOPY -> { - this.returnDataCopyFault = isReturnDataCopyFault(frame, opCode); - if (this.returnDataCopyFault) { - return; - } - - this.outOfMemoryExpansion = isMemoryExpansionFault(frame, opCode, gp); - if (this.outOfMemoryExpansion) { - return; - } - - this.outOfGas = isOutOfGas(frame, opCode, gp); - if (this.outOfGas) { - return; - } - } - case STOP -> {} - case JUMP, JUMPI -> { - this.outOfGas = isOutOfGas(frame, opCode, gp); - if (this.outOfGas) { - return; - } - - this.jumpFault = isJumpFault(frame, opCode); - if (this.jumpFault) { - return; - } - } - case SSTORE -> { - this.outOfSStore = isOutOfSStore(frame, opCode); - if (this.outOfSStore) { - return; - } - - this.outOfGas = isOutOfGas(frame, opCode, gp); - if (this.outOfGas) { - return; - } - } - default -> { - this.outOfGas = isOutOfGas(frame, opCode, gp); - if (this.outOfGas) { - return; - } - } - } - - this.invalidCodePrefix = isInvalidCodePrefix(frame); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/FailureConditions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/FailureConditions.java deleted file mode 100644 index de57f530e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/FailureConditions.java +++ /dev/null @@ -1,66 +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 java.util.Optional; - -import lombok.RequiredArgsConstructor; -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; -import org.hyperledger.besu.evm.frame.MessageFrame; - -@RequiredArgsConstructor -public final class FailureConditions { - private final Hub hub; - private boolean deploymentAddressHasNonZeroNonce; - private boolean deploymentAddressHasNonEmptyCode; - - 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 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; - } - - public boolean none() { - return !any(); - } -} 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 deleted file mode 100644 index 8e29850d9..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ /dev/null @@ -1,1293 +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 static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; - -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.stream.Stream; - -import lombok.Getter; -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.add.Add; -import net.consensys.linea.zktracer.module.bin.Bin; -import net.consensys.linea.zktracer.module.ec_data.EcData; -import net.consensys.linea.zktracer.module.euc.Euc; -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.misc.MiscFragment; -import net.consensys.linea.zktracer.module.hub.section.*; -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.Blake2fRounds; -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.EcPairingCallEffectiveCall; -import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingMillerLoop; -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.Rip160Blocks; -import net.consensys.linea.zktracer.module.limits.precompiles.Sha256Blocks; -import net.consensys.linea.zktracer.module.logData.LogData; -import net.consensys.linea.zktracer.module.logInfo.LogInfo; -import net.consensys.linea.zktracer.module.mmu.Mmu; -import net.consensys.linea.zktracer.module.mod.Mod; -import net.consensys.linea.zktracer.module.mul.Mul; -import net.consensys.linea.zktracer.module.mxp.Mxp; -import net.consensys.linea.zktracer.module.rlp.addr.RlpAddr; -import net.consensys.linea.zktracer.module.rlp.txn.RlpTxn; -import net.consensys.linea.zktracer.module.rlp.txrcpt.RlpTxrcpt; -import net.consensys.linea.zktracer.module.rom.Rom; -import net.consensys.linea.zktracer.module.romLex.RomLex; -import net.consensys.linea.zktracer.module.shf.Shf; -import net.consensys.linea.zktracer.module.stp.Stp; -import net.consensys.linea.zktracer.module.tables.bin.BinRt; -import net.consensys.linea.zktracer.module.tables.instructionDecoder.InstructionDecoder; -import net.consensys.linea.zktracer.module.tables.shf.ShfRt; -import net.consensys.linea.zktracer.module.trm.Trm; -import net.consensys.linea.zktracer.module.txn_data.TxnData; -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.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.ConflationInfo; -import net.consensys.linea.zktracer.runtime.stack.StackContext; -import net.consensys.linea.zktracer.runtime.stack.StackLine; -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.AccessListEntry; -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; -import org.hyperledger.besu.evm.log.Log; -import org.hyperledger.besu.evm.log.LogTopic; -import org.hyperledger.besu.evm.operation.Operation; -import org.hyperledger.besu.evm.worldstate.WorldView; -import org.hyperledger.besu.plugin.data.ProcessableBlockHeader; - -@Slf4j -@Accessors(fluent = true) -public class Hub implements Module { - private static final int TAU = 8; - - public static Optional maybeStackItem(MessageFrame frame, int idx) { - if (frame.stackSize() > idx) { - return Optional.of(frame.getStackItem(idx)); - } else { - return Optional.empty(); - } - } - - public static final GasProjector gp = new GasProjector(); - - // Revertible state of the hub - @Getter private final State state = new State(); - - // Long-lived states - @Getter ConflationInfo conflation = new ConflationInfo(); - @Getter BlockInfo block = new BlockInfo(); - @Getter TxInfo tx = new TxInfo(); - @Getter CallStack callStack = new CallStack(); - private final DeferRegistry defers = new DeferRegistry(); - - // These attributes are transient (opcode-specific) and do not need to be - // reversed. - @Getter private final PlatformController pch; - - 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 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 addTraceSection(TraceSection section) { - section.seal(this); - this.state.currentTxTrace().add(section); - } - - private final Module add = new Add(this); - private final Module bin = new Bin(this); - private final Ext ext = new Ext(this); - private final EcData ecData; - private final Euc euc; - private final Mod mod = new Mod(); - private final Module mul = new Mul(this); - private final Module shf = new Shf(); - private final Wcp wcp = new Wcp(this); - private final RlpTxn rlpTxn; - private final Module mxp; - private final Mmu mmu; - private final RlpTxrcpt rlpTxrcpt = new RlpTxrcpt(); - private final LogInfo logInfo = new LogInfo(rlpTxrcpt); - private final LogData logData = new LogData(rlpTxrcpt); - private final RlpAddr rlpAddr = new RlpAddr(this); - private final Rom rom; - private final RomLex romLex; - private final TxnData txnData; - private final Trm trm = new Trm(); - private final ModexpEffectiveCall modexp; - private final Stp stp = new Stp(this, wcp, mod); - private final L2Block l2Block; - - private final List modules; - /* 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 List refTableModules; - - public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { - this.l2Block = new L2Block(l2l1ContractAddress, LogTopic.of(l2l1Topic)); - this.pch = new PlatformController(this); - this.mmu = new Mmu(this.callStack); - this.mxp = new Mxp(this); - this.romLex = new RomLex(this); - this.rom = new Rom(this.romLex); - this.rlpTxn = new RlpTxn(this.romLex); - this.txnData = new TxnData(this, this.romLex, this.wcp); - this.ecData = new EcData(this, this.wcp, this.ext); - this.euc = new Euc(this.wcp); - - final EcRecoverEffectiveCall ecRec = new EcRecoverEffectiveCall(this); - this.modexp = new ModexpEffectiveCall(this); - final EcPairingCallEffectiveCall ecpairingCall = new EcPairingCallEffectiveCall(this); - this.precompileLimitModules = - List.of( - new Sha256Blocks(this), - ecRec, - new Rip160Blocks(this), - this.modexp, - new EcAddEffectiveCall(this), - new EcMulEffectiveCall(this), - ecpairingCall, - new EcPairingMillerLoop(ecpairingCall), - new Blake2fRounds(this), - // Block level limits - this.l2Block, - new Keccak(this, ecRec, this.l2Block), - new L2L1Logs(this.l2Block)); - - this.refTableModules = List.of(new BinRt(), new InstructionDecoder(), new ShfRt()); - - this.modules = - Stream.concat( - Stream.of( - this.romLex, // WARN: must be called first - this.add, - this.bin, - this.ecData, - this.euc, - this.ext, - this.logData, - this.logInfo, - this.mod, - this.mul, - this.mxp, - this.rlpAddr, - this.rlpTxn, - this.rlpTxrcpt, - this.rom, - this.shf, - this.stp, - this.trm, - this.txnData, - this.wcp), - this.precompileLimitModules.stream()) - .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.romLex, - this.add, - this.bin, - this.ext, - // this.ecData, // TODO: not yet - this.euc, - this.logData, - this.logInfo, - this.mod, - this.modexp.data(), - this.mul, - this.mxp, - this.rlpAddr, - this.rlpTxn, - this.rlpTxrcpt, - this.rom, - this.shf, - this.stp, - this.txnData, - this.wcp)) - .toList(); - } - - public List getModulesToCount() { - return Stream.concat( - Stream.of( - this, - this.romLex, - this.bin, - this.add, - this.ext, - this.ecData, - this.euc, - this.logData, - this.logInfo, - this.mod, - this.mmu, - this.mul, - this.mxp, - this.rlpAddr, - this.rlpTxn, - this.rlpTxrcpt, - this.rom, - this.shf, - this.trm, - this.txnData, - this.wcp), - this.precompileLimitModules.stream()) - .toList(); - } - - @Override - public String moduleKey() { - return "HUB"; - } - - public static boolean isValidPrecompileCall(MessageFrame frame, final OpCode opCode) { - return switch (opCode) { - case CALL, CALLCODE, STATICCALL, DELEGATECALL -> { - if (frame.stackSize() < 2) { - yield false; // invalid stack for a *CALL - } - - Address targetAddress = Words.toAddress(frame.getStackItem(1)); - yield isPrecompile(targetAddress); - } - default -> false; - }; - } - - /** - * 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.stamps().stampHub(); - boolean isDeployment = this.tx.transaction().getTo().isEmpty(); - - // - // 3 sections -- account changes - // - // From account information - Address fromAddress = this.tx.transaction().getSender(); - AccountSnapshot oldFromAccount = - AccountSnapshot.fromAccount( - world.get(fromAddress), - false, - this.conflation.deploymentInfo().number(fromAddress), - false); - - // To account information - Address toAddress = effectiveToAddress(this.tx.transaction()); - if (isDeployment) { - this.conflation().deploymentInfo().deploy(toAddress); - } - boolean toIsWarm = - (fromAddress == toAddress) - || isPrecompile(toAddress); // should never happen – no TX to PC allowed - AccountSnapshot oldToAccount = - AccountSnapshot.fromAccount( - world.get(toAddress), - toIsWarm, - this.conflation.deploymentInfo().number(toAddress), - false); - - // Miner account information - boolean minerIsWarm = - (this.block.minerAddress == fromAddress) - || (this.block.minerAddress == toAddress) - || isPrecompile(this.block.minerAddress); - AccountSnapshot oldMinerAccount = - AccountSnapshot.fromAccount( - world.get(this.block.minerAddress), - minerIsWarm, - this.conflation.deploymentInfo().number(this.block.minerAddress), - false); - - // Putatively updateCallerReturndata deployment number - this.defers.postTx( - new SkippedPostTransactionDefer( - oldFromAccount, oldToAccount, oldMinerAccount, this.tx.gasPrice(), this.block.baseFee)); - } - - /** - * Traces the warm-up information of a transaction - * - * @param world a view onto the state - */ - void processStateWarm(WorldView world) { - this.state.stamps().stampHub(); - this.tx - .transaction() - .getAccessList() - .ifPresent( - preWarmed -> { - if (!preWarmed.isEmpty()) { - Set

seenAddresses = new HashSet<>(); - Map> seenKeys = new HashMap<>(); - List fragments = new ArrayList<>(); - - for (AccessListEntry entry : preWarmed) { - Address address = entry.address(); - AccountSnapshot snapshot = - AccountSnapshot.fromAccount( - world.get(address), seenAddresses.contains(address), 0, false); - fragments.add(new AccountFragment(snapshot, snapshot, false, 0, false)); - seenAddresses.add(address); - - List keys = entry.storageKeys(); - for (Bytes32 key_ : keys) { - UInt256 key = UInt256.fromBytes(key_); - EWord value = - Optional.ofNullable(world.get(address)) - .map(account -> EWord.of(account.getStorageValue(key))) - .orElse(EWord.ZERO); - fragments.add( - new StorageFragment( - address, - this.conflation.deploymentInfo().number(address), - EWord.of(key), - value, - value, - value, - seenKeys.computeIfAbsent(address, x -> new HashSet<>()).contains(key), - true)); - seenKeys.get(address).add(key); - } - } - - this.addTraceSection(new WarmupSection(this, fragments)); - } - }); - this.tx.state(TxState.TX_INIT); - } - - /** - * Trace the preamble of a transaction - * - * @param world a view onto the state - */ - void processStateInit(WorldView world) { - this.state.stamps().stampHub(); - final boolean isDeployment = this.tx.transaction().getTo().isEmpty(); - final Address toAddress = effectiveToAddress(this.tx.transaction()); - if (isDeployment) { - this.conflation().deploymentInfo().deploy(toAddress); - } - this.tx.state(TxState.TX_EXEC); - } - - public CallFrame currentFrame() { - if (this.callStack().isEmpty()) { - return CallFrame.EMPTY; - } - return this.callStack.current(); - } - - public MessageFrame messageFrame() { - return this.callStack.current().frame(); - } - - public long getRemainingGas() { - return 0; // TODO: - } - - private void handleStack(MessageFrame frame) { - this.currentFrame() - .stack() - .processInstruction(frame, this.currentFrame(), TAU * this.state.stamps().hub()); - } - - void triggerModules(MessageFrame frame) { - for (Module precompileLimit : this.precompileLimitModules) { - precompileLimit.tracePreOpcode(frame); - } - - this.ecData.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().mmu()) { - this.mmu.tracePreOpcode(frame); - } - - if (this.pch.signals().mxp()) { - this.mxp.tracePreOpcode(frame); - } - if (this.pch.signals().oob()) { - // TODO: this.oob.tracePreOpcode(frame); - } - if (this.pch.signals().stp()) { - this.stp.tracePreOpcode(frame); - } - if (this.pch.signals().exp()) { - this.modexp.tracePreOpcode(frame); - } - if (this.pch.signals().trm()) { - this.trm.tracePreOpcode(frame); - } - if (this.pch.signals().hashInfo()) { - // TODO: this.hashInfo.tracePreOpcode(frame); - } - } - - void processStateExec(MessageFrame frame) { - this.currentFrame().frame(frame); - this.state.stamps().stampHub(); - this.pch.setup(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()) { - this.traceOperation(frame); - } else { - this.addTraceSection(new StackOnlySection(this)); - // TODO: ‶return″ context line - } - this.state.stamps().stampSubmodules(this.pch()); - } - - void processStateFinal(WorldView worldView, Transaction tx, boolean isSuccess) { - this.state.stamps().stampHub(); - - Address fromAddress = this.tx.transaction().getSender(); - Account fromAccount = worldView.get(fromAddress); - AccountSnapshot fromSnapshot = - AccountSnapshot.fromAccount( - fromAccount, - true, - this.conflation.deploymentInfo().number(fromAddress), - this.conflation.deploymentInfo().isDeploying(fromAddress)); - - Account minerAccount = worldView.get(this.block.minerAddress); - AccountSnapshot minerSnapshot = - AccountSnapshot.fromAccount( - minerAccount, - true, - this.conflation.deploymentInfo().number(this.block.minerAddress), - this.conflation.deploymentInfo().isDeploying(this.block.minerAddress)); - - if (isSuccess) { - // if no revert: 2 account rows (sender, coinbase) + 1 tx row - this.addTraceSection( - new EndTransaction( - this, - new AccountFragment(fromSnapshot, fromSnapshot, false, 0, false), - new AccountFragment(minerSnapshot, minerSnapshot, false, 0, false), - TransactionFragment.prepare( - this.conflation.number(), - this.block.minerAddress, - tx, - true, - this.tx.gasPrice(), - this.block.baseFee, - this.tx.initialGas()))); - } 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 - Address toAddress = this.tx.transaction().getSender(); - Account toAccount = worldView.get(toAddress); - AccountSnapshot toSnapshot = - AccountSnapshot.fromAccount( - toAccount, - true, - this.conflation.deploymentInfo().number(toAddress), - this.conflation.deploymentInfo().isDeploying(toAddress)); - this.addTraceSection( - new EndTransaction( - this, - new AccountFragment(fromSnapshot, fromSnapshot, false, 0, false), - new AccountFragment(minerSnapshot, minerSnapshot, false, 0, false), - new AccountFragment(fromSnapshot, fromSnapshot, false, 0, false), - new AccountFragment(toSnapshot, toSnapshot, false, 0, false))); - } - } - - /** - * Compute the effective address of a transaction target, i.e. the specified target if explicitly - * set, or the to-be-deployed address otherwise. - * - * @return the effective target address of tx - */ - public static Address effectiveToAddress(Transaction tx) { - return tx.getTo() - .map(x -> (Address) x) - .orElse(Address.contractAddress(tx.getSender(), tx.getNonce())); - } - - @Override - public void enterTransaction() { - this.state.enter(); - this.tx.enter(); - - for (Module m : this.modules) { - m.enterTransaction(); - } - } - - @Override - public void traceStartTx(final WorldView world, final Transaction tx) { - this.pch.reset(); - this.tx.update(tx); - - this.enterTransaction(); - - if (this.tx.shouldSkip(world)) { - this.tx.state(TxState.TX_SKIP); - this.processStateSkip(world); - } else { - this.tx.state(TxState.TX_WARM); - this.processStateWarm(world); - this.processStateInit(world); - } - - for (Module m : this.modules) { - m.traceStartTx(world, tx); - } - } - - @Override - public void popTransaction() { - this.tx.pop(); - this.state.pop(); - for (Module m : this.modules) { - m.popTransaction(); - } - } - - @Override - public void traceEndTx( - WorldView world, - Transaction tx, - boolean isSuccessful, - Bytes output, - List logs, - long gasUsed) { - if (this.tx.state() != TxState.TX_SKIP) { - this.tx.state(TxState.TX_FINAL); - } - this.tx.status(!isSuccessful); - - if (this.tx.state() != TxState.TX_SKIP) { - this.processStateFinal(world, tx, isSuccessful); - } - - this.defers.runPostTx(this, world, tx); - - this.state.currentTxTrace().postTxRetcon(this); - - for (Module m : this.modules) { - m.traceEndTx(world, tx, isSuccessful, output, logs, gasUsed); - } - } - - 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.getLines().size(); i++) { - StackLine line = pending.getLines().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.getLines().get(i).specific()) - .stackOps() - .get(line.resultColumn() - 1) - .setValue(result); - } - } - - if (this.pch.exceptions().none()) { - for (TraceSection.TraceLine line : section.getLines()) { - if (line.specific() instanceof StackFragment stackFragment) { - stackFragment.feedHashedValue(frame); - } - } - } - } - - @Override - public void traceContextEnter(MessageFrame frame) { - this.pch.reset(); - - if (frame.getDepth() == 0) { - // Bedrock... - final Address toAddress = effectiveToAddress(this.tx.transaction()); - final boolean isDeployment = this.tx.transaction().getTo().isEmpty(); - this.callStack.newBedrock( - this.state.stamps().hub(), - this.tx.transaction().getSender(), - toAddress, - isDeployment ? CallFrameType.INIT_CODE : CallFrameType.STANDARD, - new Bytecode( - toAddress == null - ? this.tx.transaction().getData().orElse(Bytes.EMPTY) - : Optional.ofNullable(frame.getWorldUpdater().get(toAddress)) - .map(AccountState::getCode) - .orElse(Bytes.EMPTY)), // TODO: see with Olivier - Wei.of(this.tx.transaction().getValue().getAsBigInteger()), - this.tx.transaction().getGasLimit(), - this.tx.transaction().getData().orElse(Bytes.EMPTY), - this.conflation.deploymentInfo().number(toAddress), - toAddress.isEmpty() ? 0 : this.conflation.deploymentInfo().number(toAddress), - this.conflation.deploymentInfo().isDeploying(toAddress)); - } else { - // ...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; - if (isDeployment) { - this.conflation.deploymentInfo().markDeploying(codeAddress); - } - final int codeDeploymentNumber = this.conflation.deploymentInfo().number(codeAddress); - this.callStack.enter( - this.state.stamps().hub(), - frame.getRecipientAddress(), // TODO: check for all call types that it is correct - frame.getContractAddress(), - new Bytecode(frame.getCode().getBytes()), - frameType, - frame.getValue(), - frame.getRemainingGas(), - frame.getInputData(), - this.conflation.deploymentInfo().number(codeAddress), - codeDeploymentNumber, - isDeployment); - - this.defers.runNextContext(this, frame); - - for (Module m : this.modules) { - m.traceContextEnter(frame); - } - } - } - - public void traceContextReEnter(MessageFrame frame) { - if (this.currentFrame().needsUnlatchingAtReEntry() != null) { - this.unlatchStack(frame, this.currentFrame().needsUnlatchingAtReEntry()); - this.currentFrame().needsUnlatchingAtReEntry(null); - } - } - - @Override - public void traceContextExit(MessageFrame frame) { - if (frame.getDepth() > 0) { - conflation.deploymentInfo().unmarkDeploying(this.currentFrame().codeAddress()); - - DeploymentExceptions contextExceptions = - DeploymentExceptions.fromFrame(this.currentFrame(), frame); - this.currentTraceSection().setContextExceptions(contextExceptions); - if (contextExceptions.any()) { - this.callStack.revert(this.state.stamps().hub()); - } - - this.callStack.exit(frame.getOutputData()); - - for (Module m : this.modules) { - m.traceContextExit(frame); - } - } - } - - @Override - public void tracePreOpcode(final MessageFrame frame) { - if (this.tx.state() == TxState.TX_SKIP) { - return; - } - this.processStateExec(frame); - } - - public void tracePostExecution(MessageFrame frame, Operation.OperationResult operationResult) { - if (this.tx.state() == TxState.TX_SKIP) { - return; - } - - if (this.currentFrame().opCode().isCreate() && operationResult.getHaltReason() == null) { - this.handleCreate(Words.toAddress(frame.getStackItem(0))); - } - - this.defers.runPostExec(this, frame, operationResult); - this.romLex.tracePostExecution(frame, operationResult); - - if (this.currentFrame().needsUnlatchingAtReEntry() == null) { - this.unlatchStack(frame); - } - - switch (this.opCodeData().instructionFamily()) { - case ADD -> { - if (this.pch.exceptions().noStackException()) { - this.add.tracePostOp(frame); - } - } - case MOD -> { - if (this.pch.exceptions().noStackException()) { - this.mod.tracePostOp(frame); - } - } - case MUL -> { - if (this.pch.exceptions().noStackException()) { - this.mul.tracePostOp(frame); - } - } - case EXT -> { - if (this.pch.exceptions().noStackException()) { - this.ext.tracePostOp(frame); - } - } - case WCP -> { - if (this.pch.exceptions().noStackException()) { - this.wcp.tracePostOp(frame); - } - } - case BIN -> {} - case SHF -> { - if (this.pch.exceptions().noStackException()) { - this.shf.tracePostOp(frame); - } - } - case KEC -> {} - case CONTEXT -> {} - case ACCOUNT -> {} - case COPY -> {} - case TRANSACTION -> {} - case BATCH -> {} - case STACK_RAM -> { - if (this.pch.exceptions().noStackException()) { - this.mxp.tracePostOp(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 -> {} - } - } - - private void handleCreate(Address target) { - this.conflation.deploymentInfo().deploy(target); - } - - @Override - public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) { - this.block.update(processableBlockHeader); - for (Module m : this.modules) { - m.traceStartBlock(processableBlockHeader); - } - } - - @Override - public void traceStartConflation(long blockCount) { - this.conflation.update(); - for (Module m : this.modules) { - m.traceStartConflation(blockCount); - } - } - - @Override - public void traceEndConflation() { - this.state.postConflationRetcon(this); - for (Module m : this.modules) { - m.traceEndConflation(); - } - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - this.state.commit(trace); - } - - public long refundedGas() { - return this.state.currentTxTrace().refundedGas(); - } - - public long remainingGas() { - return 0; // TODO: - } - - @Override - public int lineCount() { - return this.state.lineCount(); - } - - public int cumulatedTxCount() { - return this.state.txCount(); - } - - void traceOperation(MessageFrame frame) { - boolean updateReturnData = - this.opCodeData().isHalt() - || this.opCodeData().isInvalid() - || this.pch().exceptions().any() - || isValidPrecompileCall(frame, this.currentFrame().opCode()); - - switch (this.opCodeData().instructionFamily()) { - case ADD, - MOD, - MUL, - SHF, - BIN, - WCP, - EXT, - BATCH, - MACHINE_STATE, - PUSH_POP, - DUP, - SWAP, - HALT, - INVALID -> this.addTraceSection(new StackOnlySection(this)); - case KEC -> { - this.addTraceSection( - new KeccakSection(this, this.currentFrame(), new MiscFragment(this, frame))); - } - case CONTEXT, LOG -> this.addTraceSection( - new ContextLogSection( - this, new ContextFragment(this.callStack, this.currentFrame(), updateReturnData))); - case ACCOUNT -> { - TraceSection accountSection = new AccountSection(this); - if (this.opCodeData().stackSettings().flag1()) { - accountSection.addChunk( - this, - this.currentFrame(), - new ContextFragment(this.callStack, this.currentFrame(), updateReturnData)); - } - - Address targetAddress = - switch (this.currentFrame().opCode()) { - case BALANCE, EXTCODESIZE, EXTCODEHASH -> Words.toAddress(frame.getStackItem(0)); - default -> Address.wrap(this.currentFrame().address()); - }; - Account targetAccount = frame.getWorldUpdater().get(targetAddress); - AccountSnapshot accountSnapshot = - AccountSnapshot.fromAccount( - targetAccount, - frame.isAddressWarm(targetAddress), - this.conflation.deploymentInfo().number(targetAddress), - this.conflation.deploymentInfo().isDeploying(targetAddress)); - accountSection.addChunk( - this, - this.currentFrame(), - new AccountFragment(accountSnapshot, accountSnapshot, false, 0, false)); - - this.addTraceSection(accountSection); - } - case COPY -> { // TODO: call RomLex - TraceSection copySection = new CopySection(this); - if (this.opCodeData().stackSettings().flag1()) { - Address targetAddress = - switch (this.currentFrame().opCode()) { - case CODECOPY -> this.currentFrame().codeAddress(); - case EXTCODECOPY -> Words.toAddress(frame.getStackItem(0)); - default -> throw new IllegalStateException("unexpected opcode"); - }; - Account targetAccount = frame.getWorldUpdater().get(targetAddress); - AccountSnapshot accountSnapshot = - AccountSnapshot.fromAccount( - targetAccount, - frame.isAddressWarm(targetAddress), - this.conflation.deploymentInfo().number(targetAddress), - this.conflation.deploymentInfo().isDeploying(targetAddress)); - - copySection.addChunk( - this, - this.currentFrame(), - new AccountFragment(accountSnapshot, accountSnapshot, false, 0, false)); - } else { - copySection.addChunk( - this, - this.currentFrame(), - new ContextFragment(this.callStack, this.currentFrame(), updateReturnData)); - } - this.addTraceSection(copySection); - } - case TRANSACTION -> this.addTraceSection( - new TransactionSection( - this, - TransactionFragment.prepare( - this.conflation.number(), - frame.getMiningBeneficiary(), - this.tx.transaction(), - true, - frame.getGasPrice(), - frame.getBlockValues().getBaseFee().orElse(Wei.ZERO), - this.tx.initialGas()))); - case STACK_RAM -> { - switch (this.currentFrame().opCode()) { - case CALLDATALOAD -> { - final long readOffset = Words.clampedToLong(frame.getStackItem(0)); - final boolean isOob = readOffset > this.currentFrame().callData().size(); - - final MiscFragment miscFragment = new MiscFragment(this, frame); - this.defers.postExec(miscFragment); - - this.addTraceSection( - new StackRam( - this, - miscFragment, - new ContextFragment(this.callStack(), this.currentFrame(), false))); - } - case MLOAD, MSTORE, MSTORE8 -> { - this.addTraceSection(new StackRam(this, new MiscFragment(this, frame))); - } - default -> throw new IllegalStateException("unexpected STACK_RAM opcode"); - } - } - case STORAGE -> { - Address address = this.currentFrame().address(); - EWord key = EWord.of(frame.getStackItem(0)); - switch (this.currentFrame().opCode()) { - case SSTORE -> { - EWord valNext = EWord.of(frame.getStackItem(0)); - this.addTraceSection( - new StorageSection( - this, - new ContextFragment(this.callStack, this.currentFrame(), updateReturnData), - new StorageFragment( - address, - this.currentFrame().accountDeploymentNumber(), - key, - this.tx.storage().getOriginalValueOrUpdate(address, key, valNext), - EWord.of(frame.getTransientStorageValue(address, key)), - valNext, - frame.isStorageWarm(address, key), - true))); - } - case SLOAD -> { - EWord valCurrent = EWord.of(frame.getTransientStorageValue(address, key)); - this.addTraceSection( - new StorageSection( - this, - new ContextFragment(this.callStack, this.currentFrame(), updateReturnData), - new StorageFragment( - address, - this.currentFrame().accountDeploymentNumber(), - key, - this.tx.storage().getOriginalValueOrUpdate(address, key), - valCurrent, - valCurrent, - frame.isStorageWarm(address, key), - true))); - } - default -> throw new IllegalStateException("invalid operation in family STORAGE"); - } - } - case CREATE -> { - Address myAddress = this.currentFrame().address(); - Account myAccount = frame.getWorldUpdater().get(myAddress); - AccountSnapshot myAccountSnapshot = - AccountSnapshot.fromAccount( - myAccount, - frame.isAddressWarm(myAddress), - this.conflation.deploymentInfo().number(myAddress), - this.conflation.deploymentInfo().isDeploying(myAddress)); - - Address createdAddress = this.currentFrame().address(); - Account createdAccount = frame.getWorldUpdater().get(createdAddress); - AccountSnapshot createdAccountSnapshot = - AccountSnapshot.fromAccount( - createdAccount, - frame.isAddressWarm(createdAddress), - this.conflation.deploymentInfo().number(createdAddress), - this.conflation.deploymentInfo().isDeploying(createdAddress)); - - CreateSection createSection = - new CreateSection(this, myAccountSnapshot, createdAccountSnapshot); - // Will be traced in one (and only one!) of these depending on the success of - // the operation - this.defers.postExec(createSection); - this.defers.nextContext(createSection, currentFrame().id()); - this.addTraceSection(createSection); - this.currentFrame().needsUnlatchingAtReEntry(createSection); - } - - case CALL -> { - final Address myAddress = this.currentFrame().address(); - final Account myAccount = frame.getWorldUpdater().get(myAddress); - final AccountSnapshot myAccountSnapshot = - AccountSnapshot.fromAccount( - myAccount, - frame.isAddressWarm(myAddress), - this.conflation.deploymentInfo().number(myAddress), - this.conflation.deploymentInfo().isDeploying(myAddress)); - - final Address calledAddress = Words.toAddress(frame.getStackItem(1)); - final Account calledAccount = frame.getWorldUpdater().get(calledAddress); - final boolean hasCode = - Optional.ofNullable(calledAccount).map(AccountState::hasCode).orElse(false); - - final AccountSnapshot calledAccountSnapshot = - AccountSnapshot.fromAccount( - calledAccount, - frame.isAddressWarm(myAddress), - this.conflation.deploymentInfo().number(myAddress), - this.conflation.deploymentInfo().isDeploying(myAddress)); - - boolean targetIsPrecompile = isPrecompile(calledAddress); - - if (this.pch().exceptions().any()) { - if (this.pch().exceptions().staticFault()) { - this.addTraceSection( - new AbortedCallSection( - this, - this.currentFrame(), - new ContextFragment(this.callStack, this.currentFrame(), false), - new ContextFragment(this.callStack, this.callStack().parent(), true))); - } else if (this.pch().exceptions().outOfMemoryExpansion()) { - this.pch().signals().wantMxp(); - this.addTraceSection( - new AbortedCallSection( - this, - this.currentFrame(), - new MiscFragment(this, frame), - new ContextFragment(this.callStack, this.callStack().parent(), true))); - } else if (this.pch().exceptions().outOfGas()) { - this.pch().signals().wantMxp().wantStipend(); - this.addTraceSection( - new AbortedCallSection( - this, - this.currentFrame(), - new MiscFragment(this, frame), - new AccountFragment(calledAccountSnapshot, calledAccountSnapshot), - new ContextFragment(this.callStack, this.callStack().parent(), true))); - } - } else { - this.pch().signals().wantMxp().wantOob().wantStipend(); - if (this.pch.aborts().any()) { - TraceSection abortedSection = - new AbortedCallSection( - this, - this.currentFrame(), - new ScenarioFragment( - targetIsPrecompile, - hasCode, - true, - this.currentFrame().id(), - this.callStack().futureId()), - new ContextFragment(this.callStack, this.currentFrame(), false), - new MiscFragment(this, frame), - new AccountFragment(myAccountSnapshot, myAccountSnapshot), - new AccountFragment(calledAccountSnapshot, calledAccountSnapshot), - new ContextFragment(this.callStack, this.currentFrame(), true)); - this.addTraceSection(abortedSection); - } else { - final MiscFragment miscFragment = new MiscFragment(this, frame); - - if (hasCode) { - final WithCodeCallSection section = - new WithCodeCallSection( - this, myAccountSnapshot, calledAccountSnapshot, miscFragment); - this.defers.postExec(section); - this.defers.nextContext(section, currentFrame().id()); - this.defers.postTx(section); - this.addTraceSection(section); - this.currentFrame().needsUnlatchingAtReEntry(section); - } else { - final NoCodeCallSection section = - new NoCodeCallSection( - this, - targetIsPrecompile, - myAccountSnapshot, - calledAccountSnapshot, - miscFragment); - this.defers.postExec(section); - this.defers.postTx(section); - this.addTraceSection(section); - this.currentFrame() - .needsUnlatchingAtReEntry( - section); // TODO: not sure there -- will we switch context? - } - } - } - } - - case JUMP -> { - AccountSnapshot codeAccountSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(this.currentFrame().codeAddress()), - true, - this.conflation.deploymentInfo().number(this.currentFrame().codeAddress()), - this.currentFrame().underDeployment()); - - JumpSection jumpSection = - new JumpSection( - this, - new ContextFragment(this.callStack, this.currentFrame(), updateReturnData), - new AccountFragment(codeAccountSnapshot, codeAccountSnapshot, false, 0, false), - new MiscFragment(this, frame)); - - this.addTraceSection(jumpSection); - } - } - - // In all cases, add a context fragment if an exception occurred - if (this.pch().exceptions().any()) { - this.currentTraceSection() - .addChunk( - this, - this.currentFrame(), - new ContextFragment(this.callStack(), this.currentFrame(), true)); - } - } - - public List makeStackChunks(CallFrame f) { - List r = new ArrayList<>(); - if (f.pending().getLines().isEmpty()) { - for (int i = 0; i < (this.opCodeData().stackSettings().twoLinesInstruction() ? 2 : 1); i++) { - r.add( - StackFragment.prepare( - this.currentFrame().stack().snapshot(), - new StackLine().asStackOperations(), - this.pch.exceptions().snapshot(), - this.pch.aborts().snapshot(), - gp.of(f.frame(), f.opCode()), - f.underDeployment())); - } - } else { - for (StackLine line : f.pending().getLines()) { - r.add( - StackFragment.prepare( - f.stack().snapshot(), - line.asStackOperations(), - this.pch.exceptions().snapshot(), - this.pch.aborts().snapshot(), - gp.of(f.frame(), f.opCode()), - f.underDeployment())); - } - } - return r; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/PlatformController.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/PlatformController.java deleted file mode 100644 index cf8e9c0c3..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/PlatformController.java +++ /dev/null @@ -1,70 +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 lombok.Getter; -import lombok.experimental.Accessors; -import org.hyperledger.besu.evm.frame.MessageFrame; - -/** - * The platform controller handles inter-modules communications, exceptions, and aborts. It provides - * a centralized way of accessing this information from other modules. - */ -@Accessors(fluent = true) -public class PlatformController { - private final Hub hub; - /** What other modules should be triggered for the current operation */ - @Getter private final Signals signals; - /** 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 FailureConditions failures; - - public PlatformController(final Hub hub) { - this.hub = hub; - this.exceptions = new Exceptions(hub); - this.aborts = new AbortingConditions(); - this.signals = new Signals(this); - this.failures = new FailureConditions(hub); - } - - /** Reset all information */ - public void reset() { - this.signals.reset(); - this.exceptions.reset(); - this.aborts.reset(); - this.failures.reset(); - } - - /** - * Fill all the values of the controller from the information pertaining to the execution of the - * current operation. - * - * @param frame the current execution context - */ - void setup(MessageFrame frame) { - this.reset(); - - this.exceptions.prepare(frame, Hub.gp); - if (this.exceptions.none()) { - this.aborts.prepare(hub); - this.failures.prepare(frame); - } - this.signals.prepare(frame, this, this.hub); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Signals.java deleted file mode 100644 index 7c16b12ad..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Signals.java +++ /dev/null @@ -1,285 +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 java.util.Optional; -import java.util.Set; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.opcode.InstructionFamily; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.account.AccountState; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -/** - * Encodes the signals triggering other components. - * - *

When a component is requested, also checks that it may actually be triggered in the current - * context. - */ -@Accessors(fluent = true) -@RequiredArgsConstructor -public class Signals { - private final Set AUTOMATIC_GAS_MODULE_TRIGGER = - Set.of( - InstructionFamily.CREATE, - InstructionFamily.CALL, - InstructionFamily.HALT, - InstructionFamily.INVALID); - - @Getter private boolean add; - @Getter private boolean bin; - @Getter private boolean mul; - @Getter private boolean ext; - @Getter private boolean mod; - @Getter private boolean wcp; - @Getter private boolean shf; - - @Getter private boolean gas; - @Getter private boolean mmu; - @Getter private boolean mxp; - @Getter private boolean oob; - @Getter private boolean stp; - @Getter private boolean exp; - @Getter private boolean trm; - @Getter private boolean hashInfo; - @Getter private boolean logInfo; - @Getter private boolean romLex; - @Getter private boolean rlpAddr; - - private final PlatformController platformController; - - public void reset() { - this.add = false; - this.bin = false; - this.mul = false; - this.ext = false; - this.mod = false; - this.wcp = false; - this.shf = false; - - this.gas = false; - this.mmu = false; - this.mxp = false; - this.oob = false; - this.stp = false; - this.exp = false; - this.trm = false; - this.hashInfo = false; - this.romLex = false; - this.rlpAddr = false; - } - - public Signals snapshot() { - Signals r = new Signals(null); - r.add = this.add; - r.bin = this.bin; - r.mul = this.mul; - r.ext = this.ext; - r.mod = this.mod; - r.wcp = this.wcp; - r.shf = this.shf; - - r.gas = this.gas; - r.mmu = this.mmu; - r.mxp = this.mxp; - r.oob = this.oob; - r.stp = this.stp; - r.exp = this.exp; - r.trm = this.trm; - r.hashInfo = this.hashInfo; - r.romLex = this.romLex; - r.rlpAddr = this.rlpAddr; - - return r; - } - - public Signals wantMmu() { - this.mmu = true; - return this; - } - - public Signals wantMxp() { - this.mxp = true; - return this; - } - - public Signals wantStipend() { - this.stp = true; - return this; - } - - public Signals wantOob() { - this.oob = true; - return this; - } - - /** - * Setup all the signalling required to trigger modules for the execution of the current - * operation. - * - * @param frame the currently executing frame - * @param platformController the parent controller - * @param hub the execution context - */ - public void prepare(MessageFrame frame, PlatformController platformController, Hub hub) { - final OpCode opCode = hub.opCode(); - final Exceptions ex = platformController.exceptions(); - - // this.gas coincides with CONTEXT_MAY_CHANGE - this.gas = - ex.any() - || this.AUTOMATIC_GAS_MODULE_TRIGGER.contains(hub.opCodeData().instructionFamily()); - - if (ex.stackException()) { - return; - } - - switch (opCode) { - case CALLDATACOPY, CODECOPY -> { - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGas() || ex.none(); - this.mmu = ex.none() && !frame.getStackItem(1).isZero(); - } - - case RETURNDATACOPY -> { - this.oob = ex.none() || ex.returnDataCopyFault(); - this.mxp = ex.none() || ex.outOfMemoryExpansion() || ex.outOfGas(); - this.mmu = ex.none() && !frame.getStackItem(1).isZero(); - } - - case EXTCODECOPY -> { - boolean nonzeroSize = !frame.getStackItem(2).isZero(); - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGas() || ex.none(); - this.trm = ex.outOfGas() || ex.none(); - this.mmu = ex.none() && nonzeroSize; - - Address address = Words.toAddress(frame.getStackItem(0)); - final boolean targetAddressHasCode = - Optional.ofNullable(frame.getWorldUpdater().get(address)) - .map(AccountState::hasCode) - .orElse(false); - - this.romLex = ex.none() && nonzeroSize && targetAddressHasCode; - } - - case LOG0, LOG1, LOG2, LOG3, LOG4 -> { - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGas() || ex.none(); - this.mmu = ex.none() && !frame.getStackItem(1).isZero(); // TODO: retcon to false if REVERT - // logInfo and logData are triggered via rlpRcpt at the end of the tx - } - - case CALL, DELEGATECALL, STATICCALL, CALLCODE -> { - this.mxp = !ex.staticFault(); - this.stp = ex.outOfGas() || ex.none(); - this.oob = ex.none(); - this.trm = ex.outOfGas() || ex.none(); - - final boolean triggersAbortingCondition = - ex.none() && this.platformController.aborts().any(); - - final Address target = Words.toAddress(frame.getStackItem(1)); - final boolean targetAddressHasNonEmptyCode = - Optional.ofNullable(frame.getWorldUpdater().get(target)) - .map(AccountState::hasCode) - .orElse(false); - - this.romLex = ex.none() && !triggersAbortingCondition && targetAddressHasNonEmptyCode; - } - - case CREATE, CREATE2 -> { - boolean triggersAbortingCondition = ex.none() && this.platformController.aborts().any(); - - boolean triggersFailureCondition = false; - if (ex.none() && this.platformController.aborts().none()) { - triggersFailureCondition = this.platformController.failures().any(); - } - - final boolean nonzeroSize = !frame.getStackItem(2).isZero(); - final boolean isCreate2 = opCode == OpCode.CREATE2; - - this.mxp = !ex.staticFault(); - this.stp = ex.outOfGas() || ex.none(); - this.oob = ex.none(); - this.rlpAddr = ex.none() && !triggersAbortingCondition; - this.hashInfo = ex.none() && !triggersAbortingCondition && nonzeroSize && isCreate2; - this.romLex = - ex.none() && !triggersAbortingCondition && nonzeroSize && !triggersFailureCondition; - this.mmu = this.hashInfo || this.romLex; - } - - case REVERT -> { - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGas() || ex.none(); - this.mmu = - ex.none() - && !frame.getStackItem(1).isZero() - && hub.currentFrame().returnDataTarget().length() > 0; - } - - 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 = - ex.outOfMemoryExpansion() || ex.outOfGas() || ex.invalidCodePrefix() || ex.none(); - this.oob = isDeployment && (ex.codeSizeOverflow() || ex.none()); - this.mmu = - (isDeployment && ex.invalidCodePrefix()) - || (isDeployment && ex.none() && sizeNonZero) - || (!isDeployment - && ex.none() - && sizeNonZero - && hub.currentFrame().returnDataTarget().length() > 0); - this.romLex = this.hashInfo = isDeployment && ex.none() && sizeNonZero; - } - - case EXP -> { - this.exp = true; - this.mul = !ex.outOfGas(); - } - - // 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 SHA3 -> { - this.mxp = true; - this.hashInfo = ex.none() && !frame.getStackItem(0).isZero(); - this.mmu = this.hashInfo; - } - case BALANCE, EXTCODESIZE, EXTCODEHASH, SELFDESTRUCT -> this.trm = true; - case MLOAD, MSTORE, MSTORE8 -> { - this.mxp = true; - this.mmu = !ex.any(); - } - case CALLDATALOAD -> { - this.oob = true; - this.mmu = frame.getInputData().size() > Words.clampedToLong(frame.getStackItem(0)); - } - case SLOAD -> {} - case SSTORE, JUMP, JUMPI -> this.oob = true; - case MSIZE -> this.mxp = ex.none(); - } - } -} 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 deleted file mode 100644 index 8b5da7c82..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java +++ /dev/null @@ -1,152 +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 java.util.ArrayDeque; -import java.util.Deque; -import java.util.Iterator; - -import lombok.Getter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.container.StackedContainer; - -public class State implements StackedContainer { - private final Deque state = new ArrayDeque<>(50); - - State() {} - - private TxState current() { - return this.state.peek(); - } - - TxState.Stamps stamps() { - return this.current().stamps; - } - - /** - * @return the current transaction trace elements - */ - TxTrace currentTxTrace() { - return this.current().txTrace; - } - - void postConflationRetcon(Hub hub) { - for (TxState txState : this.state) { - txState.txTrace.postConflationRetcon(hub, null /* TODO WorldView */); - } - } - - /** - * Concretize the traces of all the accumulated transactions. - * - * @param hubTrace the trace builder to write to - * @return the trace builder - */ - Trace commit(Trace hubTrace) { - for (Iterator it = this.state.descendingIterator(); it.hasNext(); ) { - final TxState txState = it.next(); - txState.txTrace().commit(hubTrace); - } - return hubTrace; - } - - int txCount() { - return this.state.size(); - } - - /** - * @return the cumulated line numbers for all currently traced transactions - */ - int lineCount() { - int sum = 0; - for (TxState s : this.state) { - sum += s.txTrace.lineCount(); - } - return sum; - } - - @Override - public void enter() { - if (this.state.isEmpty()) { - this.state.push(new TxState()); - } else { - this.state.push(this.current().spinOff()); - } - } - - @Override - public void pop() { - this.state.pop(); - } - - /** Describes the Hub state during a given transaction. */ - @Accessors(fluent = true) - @Getter - static class TxState { - Stamps stamps; - TxTrace txTrace; - - TxState() { - this.stamps = new Stamps(); - this.txTrace = new TxTrace(); - } - - public TxState(Stamps stamps) { - this.stamps = stamps; - this.txTrace = new TxTrace(); - } - - TxState spinOff() { - return new TxState(this.stamps.spinOff()); - } - - /** Stores all the stamps associated to the tracing of a transaction. */ - @Accessors(fluent = true) - @Getter - static class Stamps { - private int hub = 0; - private int mmu = 0; - private int mxp = 0; - private int hashInfo = 0; - - public Stamps() {} - - public Stamps(int hubStamp, int mmuStamp, int mxpStamp, int hashInfoStamp) { - this.hub = hubStamp; - this.mmu = mmuStamp; - this.mxp = mxpStamp; - this.hashInfo = hashInfoStamp; - } - - Stamps spinOff() { - return new Stamps(this.hub, this.mmu, this.mxp, this.hashInfo); - } - - void stampHub() { - this.hub++; - } - - void stampSubmodules(final PlatformController platformController) { - if (platformController.signals().mmu()) { - this.mmu++; - } - if (platformController.signals().mxp()) { - this.mxp++; - } - } - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/StorageInfo.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/StorageInfo.java deleted file mode 100644 index bc01e647c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/StorageInfo.java +++ /dev/null @@ -1,39 +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 java.util.HashMap; -import java.util.Map; - -import net.consensys.linea.zktracer.types.EWord; -import org.hyperledger.besu.datatypes.Address; - -public class StorageInfo { - final Map> originalStorageValues = new HashMap<>(); - - public EWord getOriginalValueOrUpdate(Address address, EWord key, EWord value) { - EWord r = - this.originalStorageValues.getOrDefault(address, new HashMap<>()).putIfAbsent(key, value); - if (r == null) { - return value; - } - return r; - } - - public EWord getOriginalValueOrUpdate(Address address, EWord key) { - return this.getOriginalValueOrUpdate(address, key, EWord.ZERO); - } -} 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 deleted file mode 100644 index 8ef6b01db..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ /dev/null @@ -1,6621 +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 java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - static final int N_FAILURE = 4; - static final int N_SUCCESS = 4; - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer absoluteTransactionNumber; - private final MappedByteBuffer - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee; - private final MappedByteBuffer - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize; - private final MappedByteBuffer - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo; - private final MappedByteBuffer - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi; - private final MappedByteBuffer batchNumber; - private final MappedByteBuffer callerContextNumber; - private final MappedByteBuffer codeAddressHi; - private final MappedByteBuffer codeAddressLo; - private final MappedByteBuffer codeDeploymentNumber; - private final MappedByteBuffer codeDeploymentStatus; - private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo; - private final MappedByteBuffer - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi; - private final MappedByteBuffer - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice; - private final MappedByteBuffer - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit; - private final MappedByteBuffer - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal; - private final MappedByteBuffer - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount; - private final MappedByteBuffer contextGetsRevertedFlag; - private final MappedByteBuffer contextMayChangeFlag; - private final MappedByteBuffer contextNumber; - private final MappedByteBuffer contextNumberNew; - private final MappedByteBuffer contextRevertStamp; - private final MappedByteBuffer contextSelfRevertsFlag; - private final MappedByteBuffer contextWillRevertFlag; - private final MappedByteBuffer counterNsr; - private final MappedByteBuffer counterTli; - private final MappedByteBuffer - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas; - private final MappedByteBuffer - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize; - private final MappedByteBuffer - depStatusNewXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValCurrIsZeroXorStatusCode; - private final MappedByteBuffer - depStatusXorExpFlagXorCallAbortXorAddFlagXorValCurrIsOrigXorIsEip1559; - private final MappedByteBuffer - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance; - private final MappedByteBuffer - deploymentStatusInftyXorUpdateXorCcsrFlagXorBlake2FXorAccFlagXorValCurrChangesXorIsDeployment; - private final MappedByteBuffer domStamp; - private final MappedByteBuffer exceptionAhoyFlag; - private final MappedByteBuffer - existsNewXorMxpDeploysXorCallPrcFailureCallerWillRevertXorCallFlagXorValNextIsOrig; - private final MappedByteBuffer - existsXorMmuInfoXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValNextIsCurrXorTxnRequiresEvmExecution; - private final MappedByteBuffer gasActual; - private final MappedByteBuffer gasCost; - private final MappedByteBuffer gasExpected; - private final MappedByteBuffer gasNext; - private final MappedByteBuffer gasRefund; - private final MappedByteBuffer gasRefundNew; - private final MappedByteBuffer - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValOrigIsZero; - private final MappedByteBuffer - hasCodeXorMxpFlagXorCallPrcFailureCallerWontRevertXorConFlagXorValNextIsZero; - private final MappedByteBuffer hashInfoStamp; - private final MappedByteBuffer hubStamp; - private final MappedByteBuffer hubStampTransactionEnd; - private final MappedByteBuffer - isBlake2FXorOobEvent1XorCallPrcSuccessCallerWontRevertXorCreateFlagXorWarm; - private final MappedByteBuffer - isEcaddXorOobEvent2XorCallSmcFailureCallerWillRevertXorDecodedFlag1XorWarmNew; - private final MappedByteBuffer isEcmulXorOobFlagXorCallSmcFailureCallerWontRevertXorDecodedFlag2; - private final MappedByteBuffer - isEcpairingXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecodedFlag3; - private final MappedByteBuffer - isEcrecoverXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecodedFlag4; - private final MappedByteBuffer isIdentityXorStpOogxXorCodedepositXorDupFlag; - private final MappedByteBuffer isModexpXorStpWarmXorCodedepositInvalidCodePrefixXorExtFlag; - private final MappedByteBuffer isPrecompileXorCodedepositValidCodePrefixXorHaltFlag; - private final MappedByteBuffer isRipemd160XorEcaddXorHashInfoFlag; - private final MappedByteBuffer isSha2256XorEcmulXorInvalidFlag; - private final MappedByteBuffer mmuStamp; - private final MappedByteBuffer mxpSize1LoXorStackItemValueLo2; - private final MappedByteBuffer mxpSize2HiXorStackItemValueLo3; - private final MappedByteBuffer mxpSize2LoXorStackItemValueLo4; - private final MappedByteBuffer mxpStamp; - private final MappedByteBuffer mxpWordsXorStaticGas; - private final MappedByteBuffer nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce; - private final MappedByteBuffer nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas; - private final MappedByteBuffer numberOfNonStackRows; - private final MappedByteBuffer oobInst; - private final MappedByteBuffer oobOutgoingData1; - private final MappedByteBuffer oobOutgoingData2; - private final MappedByteBuffer oobOutgoingData3; - private final MappedByteBuffer oobOutgoingData4; - private final MappedByteBuffer oobOutgoingData5; - private final MappedByteBuffer oobOutgoingData6; - private final MappedByteBuffer peekAtAccount; - private final MappedByteBuffer peekAtContext; - private final MappedByteBuffer peekAtMiscellaneous; - private final MappedByteBuffer peekAtScenario; - private final MappedByteBuffer peekAtStack; - private final MappedByteBuffer peekAtStorage; - private final MappedByteBuffer peekAtTransaction; - private final MappedByteBuffer programCounter; - private final MappedByteBuffer programCounterNew; - private final MappedByteBuffer pushpopFlag; - private final MappedByteBuffer rdcx; - private final MappedByteBuffer ripemd160XorKecFlag; - private final MappedByteBuffer - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi; - private final MappedByteBuffer - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo; - private final MappedByteBuffer rlpaddrFlagXorEcpairingXorInvprex; - private final MappedByteBuffer - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue; - private final MappedByteBuffer rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1; - private final MappedByteBuffer rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2; - private final MappedByteBuffer - rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3; - private final MappedByteBuffer rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4; - private final MappedByteBuffer scnFailure1XorLogFlag; - private final MappedByteBuffer scnFailure2XorMachineStateFlag; - private final MappedByteBuffer scnFailure3XorMaxcsx; - private final MappedByteBuffer scnFailure4XorModFlag; - private final MappedByteBuffer scnSuccess1XorMulFlag; - private final MappedByteBuffer scnSuccess2XorMxpx; - private final MappedByteBuffer scnSuccess3XorMxpFlag; - private final MappedByteBuffer scnSuccess4XorOobFlag; - private final MappedByteBuffer selfdestructXorOogx; - private final MappedByteBuffer sha2256XorOpcx; - private final MappedByteBuffer shfFlag; - private final MappedByteBuffer sox; - private final MappedByteBuffer sstorex; - private final MappedByteBuffer stackItemPop1; - private final MappedByteBuffer stackItemPop2; - private final MappedByteBuffer stackItemPop3; - private final MappedByteBuffer stackItemPop4; - private final MappedByteBuffer stackramFlag; - private final MappedByteBuffer staticFlag; - private final MappedByteBuffer staticx; - private final MappedByteBuffer stoFlag; - private final MappedByteBuffer stpGasHi; - private final MappedByteBuffer stpGasLo; - private final MappedByteBuffer stpGasOopkt; - private final MappedByteBuffer stpGasStpd; - private final MappedByteBuffer stpInst; - private final MappedByteBuffer stpValHi; - private final MappedByteBuffer stpValLo; - private final MappedByteBuffer subStamp; - private final MappedByteBuffer sux; - private final MappedByteBuffer swapFlag; - private final MappedByteBuffer transactionReverts; - private final MappedByteBuffer trmFlag; - private final MappedByteBuffer trmFlagXorEcrecoverXorJumpx; - private final MappedByteBuffer trmRawAddrHiXorMxpSize1HiXorStackItemValueLo1; - private final MappedByteBuffer twoLineInstruction; - private final MappedByteBuffer txExec; - private final MappedByteBuffer txFinl; - private final MappedByteBuffer txInit; - private final MappedByteBuffer txSkip; - private final MappedByteBuffer txWarm; - private final MappedByteBuffer txnFlag; - private final MappedByteBuffer warmNewXorModexpXorJumpFlag; - private final MappedByteBuffer warmXorIdentityXorJumpDestinationVettingRequired; - private final MappedByteBuffer wcpFlag; - - static List headers(int length) { - return List.of( - new ColumnHeader("hub_v2.ABSOLUTE_TRANSACTION_NUMBER", 32, length), - new ColumnHeader( - "hub_v2.ADDR_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_HASH_INFO___KEC_HI_xor_ADDRESS_HI_xor_BASEFEE", - 32, - length), - new ColumnHeader( - "hub_v2.ADDR_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP___DYNCOST_xor_HASH_INFO___KEC_LO_xor_ADDRESS_LO_xor_CALL_DATA_SIZE", - 32, - length), - new ColumnHeader( - "hub_v2.BALANCE_NEW_xor_BYTE_CODE_ADDRESS_HI_xor_EXP___EXPONENT_LO_xor_HEIGHT_xor_STORAGE_KEY_HI_xor_COINBASE_ADDRESS_LO", - 32, - length), - new ColumnHeader( - "hub_v2.BALANCE_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP___EXPONENT_HI_xor_HASH_INFO___SIZE_xor_DEPLOYMENT_NUMBER_xor_COINBASE_ADDRESS_HI", - 32, - length), - new ColumnHeader("hub_v2.BATCH_NUMBER", 32, length), - new ColumnHeader("hub_v2.CALLER_CONTEXT_NUMBER", 32, length), - new ColumnHeader("hub_v2.CODE_ADDRESS_HI", 32, length), - new ColumnHeader("hub_v2.CODE_ADDRESS_LO", 32, length), - new ColumnHeader("hub_v2.CODE_DEPLOYMENT_NUMBER", 32, length), - new ColumnHeader("hub_v2.CODE_DEPLOYMENT_STATUS", 1, length), - new ColumnHeader("hub_v2.CODE_FRAGMENT_INDEX", 32, length), - new ColumnHeader( - "hub_v2.CODE_HASH_HI_NEW_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU___INST_xor_HEIGHT_OVER_xor_VAL_CURR_HI_xor_FROM_ADDRESS_LO", - 32, - length), - new ColumnHeader( - "hub_v2.CODE_HASH_HI_xor_BYTE_CODE_ADDRESS_LO_xor_MMU___EXO_SUM_xor_HEIGHT_NEW_xor_STORAGE_KEY_LO_xor_FROM_ADDRESS_HI", - 32, - length), - new ColumnHeader( - "hub_v2.CODE_HASH_LO_NEW_xor_CALLER_ADDRESS_HI_xor_MMU___OFFSET_2_HI_xor_INST_xor_VAL_NEXT_HI_xor_GAS_PRICE", - 32, - length), - new ColumnHeader( - "hub_v2.CODE_HASH_LO_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU___OFFSET_1_LO_xor_HEIGHT_UNDER_xor_VAL_CURR_LO_xor_GAS_LIMIT", - 32, - length), - new ColumnHeader( - "hub_v2.CODE_SIZE_NEW_xor_CALLER_CONTEXT_NUMBER_xor_MMU___PARAM_1_xor_PUSH_VALUE_LO_xor_VAL_ORIG_HI_xor_GAS_REFUND_COUNTER_FINAL", - 32, - length), - new ColumnHeader( - "hub_v2.CODE_SIZE_xor_CALLER_ADDRESS_LO_xor_MMU___OFFSET_2_LO_xor_PUSH_VALUE_HI_xor_VAL_NEXT_LO_xor_GAS_REFUND_AMOUNT", - 32, - length), - new ColumnHeader("hub_v2.CONTEXT_GETS_REVERTED_FLAG", 1, length), - new ColumnHeader("hub_v2.CONTEXT_MAY_CHANGE_FLAG", 1, length), - new ColumnHeader("hub_v2.CONTEXT_NUMBER", 32, length), - new ColumnHeader("hub_v2.CONTEXT_NUMBER_NEW", 32, length), - new ColumnHeader("hub_v2.CONTEXT_REVERT_STAMP", 32, length), - new ColumnHeader("hub_v2.CONTEXT_SELF_REVERTS_FLAG", 1, length), - new ColumnHeader("hub_v2.CONTEXT_WILL_REVERT_FLAG", 1, length), - new ColumnHeader("hub_v2.COUNTER_NSR", 32, length), - new ColumnHeader("hub_v2.COUNTER_TLI", 1, length), - new ColumnHeader( - "hub_v2.DEP_NUM_NEW_xor_CALL_STACK_DEPTH_xor_MMU___REF_SIZE_xor_STACK_ITEM_HEIGHT_3_xor_INIT_GAS", - 32, - length), - new ColumnHeader( - "hub_v2.DEP_NUM_xor_CALL_DATA_SIZE_xor_MMU___REF_OFFSET_xor_STACK_ITEM_HEIGHT_2_xor_INIT_CODE_SIZE", - 32, - length), - new ColumnHeader( - "hub_v2.DEP_STATUS_NEW_xor_MMU___FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_VAL_CURR_IS_ZERO_xor_STATUS_CODE", - 1, - length), - new ColumnHeader( - "hub_v2.DEP_STATUS_xor_EXP___FLAG_xor_CALL_ABORT_xor_ADD_FLAG_xor_VAL_CURR_IS_ORIG_xor_IS_EIP1559", - 1, - length), - new ColumnHeader( - "hub_v2.DEPLOYMENT_NUMBER_INFTY_xor_CALL_DATA_OFFSET_xor_MMU___PARAM_2_xor_STACK_ITEM_HEIGHT_1_xor_VAL_ORIG_LO_xor_INITIAL_BALANCE", - 32, - length), - new ColumnHeader( - "hub_v2.DEPLOYMENT_STATUS_INFTY_xor_UPDATE_xor_CCSR_FLAG_xor_BLAKE2f_xor_ACC_FLAG_xor_VAL_CURR_CHANGES_xor_IS_DEPLOYMENT", - 1, - length), - new ColumnHeader("hub_v2.DOM_STAMP", 32, length), - new ColumnHeader("hub_v2.EXCEPTION_AHOY_FLAG", 1, length), - new ColumnHeader( - "hub_v2.EXISTS_NEW_xor_MXP___DEPLOYS_xor_CALL_PRC_FAILURE_CALLER_WILL_REVERT_xor_CALL_FLAG_xor_VAL_NEXT_IS_ORIG", - 1, - length), - new ColumnHeader( - "hub_v2.EXISTS_xor_MMU___INFO_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BTC_FLAG_xor_VAL_NEXT_IS_CURR_xor_TXN_REQUIRES_EVM_EXECUTION", - 1, - length), - new ColumnHeader("hub_v2.GAS_ACTUAL", 32, length), - new ColumnHeader("hub_v2.GAS_COST", 32, length), - new ColumnHeader("hub_v2.GAS_EXPECTED", 32, length), - new ColumnHeader("hub_v2.GAS_NEXT", 32, length), - new ColumnHeader("hub_v2.GAS_REFUND", 32, length), - new ColumnHeader("hub_v2.GAS_REFUND_NEW", 32, length), - new ColumnHeader( - "hub_v2.HAS_CODE_NEW_xor_MXP___MXPX_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_VAL_ORIG_IS_ZERO", - 1, - length), - new ColumnHeader( - "hub_v2.HAS_CODE_xor_MXP___FLAG_xor_CALL_PRC_FAILURE_CALLER_WONT_REVERT_xor_CON_FLAG_xor_VAL_NEXT_IS_ZERO", - 1, - length), - new ColumnHeader("hub_v2.HASH_INFO_STAMP", 32, length), - new ColumnHeader("hub_v2.HUB_STAMP", 32, length), - new ColumnHeader("hub_v2.HUB_STAMP_TRANSACTION_END", 32, length), - new ColumnHeader( - "hub_v2.IS_BLAKE2f_xor_OOB___EVENT_1_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_WARM", - 1, - length), - new ColumnHeader( - "hub_v2.IS_ECADD_xor_OOB___EVENT_2_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DECODED_FLAG_1_xor_WARM_NEW", - 1, - length), - new ColumnHeader( - "hub_v2.IS_ECMUL_xor_OOB___FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DECODED_FLAG_2", - 1, - length), - new ColumnHeader( - "hub_v2.IS_ECPAIRING_xor_STP___EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DECODED_FLAG_3", - 1, - length), - new ColumnHeader( - "hub_v2.IS_ECRECOVER_xor_STP___FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DECODED_FLAG_4", - 1, - length), - new ColumnHeader( - "hub_v2.IS_IDENTITY_xor_STP___OOGX_xor_CODEDEPOSIT_xor_DUP_FLAG", 1, length), - new ColumnHeader( - "hub_v2.IS_MODEXP_xor_STP___WARM_xor_CODEDEPOSIT_INVALID_CODE_PREFIX_xor_EXT_FLAG", - 1, - length), - new ColumnHeader( - "hub_v2.IS_PRECOMPILE_xor_CODEDEPOSIT_VALID_CODE_PREFIX_xor_HALT_FLAG", 1, length), - new ColumnHeader("hub_v2.IS_RIPEMD-160_xor_ECADD_xor_HASH_INFO_FLAG", 1, length), - new ColumnHeader("hub_v2.IS_SHA2-256_xor_ECMUL_xor_INVALID_FLAG", 1, length), - new ColumnHeader("hub_v2.MMU_STAMP", 32, length), - new ColumnHeader("hub_v2.MXP___SIZE_1_LO_xor_STACK_ITEM_VALUE_LO_2", 32, length), - new ColumnHeader("hub_v2.MXP___SIZE_2_HI_xor_STACK_ITEM_VALUE_LO_3", 32, length), - new ColumnHeader("hub_v2.MXP___SIZE_2_LO_xor_STACK_ITEM_VALUE_LO_4", 32, length), - new ColumnHeader("hub_v2.MXP_STAMP", 32, length), - new ColumnHeader("hub_v2.MXP___WORDS_xor_STATIC_GAS", 32, length), - new ColumnHeader( - "hub_v2.NONCE_NEW_xor_CONTEXT_NUMBER_xor_MMU___STACK_VAL_HI_xor_STACK_ITEM_STAMP_1_xor_NONCE", - 32, - length), - new ColumnHeader( - "hub_v2.NONCE_xor_CALL_VALUE_xor_MMU___SIZE_xor_STACK_ITEM_HEIGHT_4_xor_LEFTOVER_GAS", - 32, - length), - new ColumnHeader("hub_v2.NUMBER_OF_NON_STACK_ROWS", 32, length), - new ColumnHeader("hub_v2.OOB___INST", 32, length), - new ColumnHeader("hub_v2.OOB___OUTGOING_DATA_1", 32, length), - new ColumnHeader("hub_v2.OOB___OUTGOING_DATA_2", 32, length), - new ColumnHeader("hub_v2.OOB___OUTGOING_DATA_3", 32, length), - new ColumnHeader("hub_v2.OOB___OUTGOING_DATA_4", 32, length), - new ColumnHeader("hub_v2.OOB___OUTGOING_DATA_5", 32, length), - new ColumnHeader("hub_v2.OOB___OUTGOING_DATA_6", 32, length), - new ColumnHeader("hub_v2.PEEK_AT_ACCOUNT", 1, length), - new ColumnHeader("hub_v2.PEEK_AT_CONTEXT", 1, length), - new ColumnHeader("hub_v2.PEEK_AT_MISCELLANEOUS", 1, length), - new ColumnHeader("hub_v2.PEEK_AT_SCENARIO", 1, length), - new ColumnHeader("hub_v2.PEEK_AT_STACK", 1, length), - new ColumnHeader("hub_v2.PEEK_AT_STORAGE", 1, length), - new ColumnHeader("hub_v2.PEEK_AT_TRANSACTION", 1, length), - new ColumnHeader("hub_v2.PROGRAM_COUNTER", 32, length), - new ColumnHeader("hub_v2.PROGRAM_COUNTER_NEW", 32, length), - new ColumnHeader("hub_v2.PUSHPOP_FLAG", 1, length), - new ColumnHeader("hub_v2.RDCX", 1, length), - new ColumnHeader("hub_v2.RIPEMD-160_xor_KEC_FLAG", 1, length), - new ColumnHeader( - "hub_v2.RLPADDR___DEP_ADDR_HI_xor_IS_STATIC_xor_MMU___STACK_VAL_LO_xor_STACK_ITEM_STAMP_2_xor_TO_ADDRESS_HI", - 32, - length), - new ColumnHeader( - "hub_v2.RLPADDR___DEP_ADDR_LO_xor_RETURNER_CONTEXT_NUMBER_xor_MXP___GAS_MXP_xor_STACK_ITEM_STAMP_3_xor_TO_ADDRESS_LO", - 32, - length), - new ColumnHeader("hub_v2.RLPADDR___FLAG_xor_ECPAIRING_xor_INVPREX", 1, length), - new ColumnHeader( - "hub_v2.RLPADDR___KEC_HI_xor_RETURNER_IS_PRECOMPILE_xor_MXP___INST_xor_STACK_ITEM_STAMP_4_xor_VALUE", - 32, - length), - new ColumnHeader( - "hub_v2.RLPADDR___KEC_LO_xor_RETURN_AT_OFFSET_xor_MXP___OFFSET_1_HI_xor_STACK_ITEM_VALUE_HI_1", - 32, - length), - new ColumnHeader( - "hub_v2.RLPADDR___RECIPE_xor_RETURN_AT_SIZE_xor_MXP___OFFSET_1_LO_xor_STACK_ITEM_VALUE_HI_2", - 32, - length), - new ColumnHeader( - "hub_v2.RLPADDR___SALT_HI_xor_RETURN_DATA_OFFSET_xor_MXP___OFFSET_2_HI_xor_STACK_ITEM_VALUE_HI_3", - 32, - length), - new ColumnHeader( - "hub_v2.RLPADDR___SALT_LO_xor_RETURN_DATA_SIZE_xor_MXP___OFFSET_2_LO_xor_STACK_ITEM_VALUE_HI_4", - 32, - length), - new ColumnHeader("hub_v2.SCN_FAILURE_1_xor_LOG_FLAG", 1, length), - new ColumnHeader("hub_v2.SCN_FAILURE_2_xor_MACHINE_STATE_FLAG", 1, length), - new ColumnHeader("hub_v2.SCN_FAILURE_3_xor_MAXCSX", 1, length), - new ColumnHeader("hub_v2.SCN_FAILURE_4_xor_MOD_FLAG", 1, length), - new ColumnHeader("hub_v2.SCN_SUCCESS_1_xor_MUL_FLAG", 1, length), - new ColumnHeader("hub_v2.SCN_SUCCESS_2_xor_MXPX", 1, length), - new ColumnHeader("hub_v2.SCN_SUCCESS_3_xor_MXP_FLAG", 1, length), - new ColumnHeader("hub_v2.SCN_SUCCESS_4_xor_OOB_FLAG", 1, length), - new ColumnHeader("hub_v2.SELFDESTRUCT_xor_OOGX", 1, length), - new ColumnHeader("hub_v2.SHA2-256_xor_OPCX", 1, length), - new ColumnHeader("hub_v2.SHF_FLAG", 1, length), - new ColumnHeader("hub_v2.SOX", 1, length), - new ColumnHeader("hub_v2.SSTOREX", 1, length), - new ColumnHeader("hub_v2.STACK_ITEM_POP_1", 1, length), - new ColumnHeader("hub_v2.STACK_ITEM_POP_2", 1, length), - new ColumnHeader("hub_v2.STACK_ITEM_POP_3", 1, length), - new ColumnHeader("hub_v2.STACK_ITEM_POP_4", 1, length), - new ColumnHeader("hub_v2.STACKRAM_FLAG", 1, length), - new ColumnHeader("hub_v2.STATIC_FLAG", 1, length), - new ColumnHeader("hub_v2.STATICX", 1, length), - new ColumnHeader("hub_v2.STO_FLAG", 1, length), - new ColumnHeader("hub_v2.STP___GAS_HI", 32, length), - new ColumnHeader("hub_v2.STP___GAS_LO", 32, length), - new ColumnHeader("hub_v2.STP___GAS_OOPKT", 32, length), - new ColumnHeader("hub_v2.STP___GAS_STPD", 32, length), - new ColumnHeader("hub_v2.STP___INST", 32, length), - new ColumnHeader("hub_v2.STP___VAL_HI", 32, length), - new ColumnHeader("hub_v2.STP___VAL_LO", 32, length), - new ColumnHeader("hub_v2.SUB_STAMP", 32, length), - new ColumnHeader("hub_v2.SUX", 1, length), - new ColumnHeader("hub_v2.SWAP_FLAG", 1, length), - new ColumnHeader("hub_v2.TRANSACTION_REVERTS", 1, length), - new ColumnHeader("hub_v2.TRM_FLAG", 1, length), - new ColumnHeader("hub_v2.TRM___FLAG_xor_ECRECOVER_xor_JUMPX", 1, length), - new ColumnHeader( - "hub_v2.TRM___RAW_ADDR_HI_xor_MXP___SIZE_1_HI_xor_STACK_ITEM_VALUE_LO_1", 32, length), - new ColumnHeader("hub_v2.TWO_LINE_INSTRUCTION", 1, length), - new ColumnHeader("hub_v2.TX_EXEC", 1, length), - new ColumnHeader("hub_v2.TX_FINL", 1, length), - new ColumnHeader("hub_v2.TX_INIT", 1, length), - new ColumnHeader("hub_v2.TX_SKIP", 1, length), - new ColumnHeader("hub_v2.TX_WARM", 1, length), - new ColumnHeader("hub_v2.TXN_FLAG", 1, length), - new ColumnHeader("hub_v2.WARM_NEW_xor_MODEXP_xor_JUMP_FLAG", 1, length), - new ColumnHeader( - "hub_v2.WARM_xor_IDENTITY_xor_JUMP_DESTINATION_VETTING_REQUIRED", 1, length), - new ColumnHeader("hub_v2.WCP_FLAG", 1, length)); - } - - public Trace(List buffers) { - this.absoluteTransactionNumber = buffers.get(0); - this.addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee = - buffers.get(1); - this.addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize = - buffers.get(2); - this - .balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo = - buffers.get(3); - this - .balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi = - buffers.get(4); - this.batchNumber = buffers.get(5); - this.callerContextNumber = buffers.get(6); - this.codeAddressHi = buffers.get(7); - this.codeAddressLo = buffers.get(8); - this.codeDeploymentNumber = buffers.get(9); - this.codeDeploymentStatus = buffers.get(10); - this.codeFragmentIndex = buffers.get(11); - this - .codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo = - buffers.get(12); - this.codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi = - buffers.get(13); - this.codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice = - buffers.get(14); - this.codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit = - buffers.get(15); - this - .codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal = - buffers.get(16); - this.codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount = - buffers.get(17); - this.contextGetsRevertedFlag = buffers.get(18); - this.contextMayChangeFlag = buffers.get(19); - this.contextNumber = buffers.get(20); - this.contextNumberNew = buffers.get(21); - this.contextRevertStamp = buffers.get(22); - this.contextSelfRevertsFlag = buffers.get(23); - this.contextWillRevertFlag = buffers.get(24); - this.counterNsr = buffers.get(25); - this.counterTli = buffers.get(26); - this.depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas = buffers.get(27); - this.depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize = buffers.get(28); - this - .depStatusNewXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValCurrIsZeroXorStatusCode = - buffers.get(29); - this.depStatusXorExpFlagXorCallAbortXorAddFlagXorValCurrIsOrigXorIsEip1559 = buffers.get(30); - this - .deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance = - buffers.get(31); - this - .deploymentStatusInftyXorUpdateXorCcsrFlagXorBlake2FXorAccFlagXorValCurrChangesXorIsDeployment = - buffers.get(32); - this.domStamp = buffers.get(33); - this.exceptionAhoyFlag = buffers.get(34); - this.existsNewXorMxpDeploysXorCallPrcFailureCallerWillRevertXorCallFlagXorValNextIsOrig = - buffers.get(35); - this - .existsXorMmuInfoXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValNextIsCurrXorTxnRequiresEvmExecution = - buffers.get(36); - this.gasActual = buffers.get(37); - this.gasCost = buffers.get(38); - this.gasExpected = buffers.get(39); - this.gasNext = buffers.get(40); - this.gasRefund = buffers.get(41); - this.gasRefundNew = buffers.get(42); - this.hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValOrigIsZero = - buffers.get(43); - this.hasCodeXorMxpFlagXorCallPrcFailureCallerWontRevertXorConFlagXorValNextIsZero = - buffers.get(44); - this.hashInfoStamp = buffers.get(45); - this.hubStamp = buffers.get(46); - this.hubStampTransactionEnd = buffers.get(47); - this.isBlake2FXorOobEvent1XorCallPrcSuccessCallerWontRevertXorCreateFlagXorWarm = - buffers.get(48); - this.isEcaddXorOobEvent2XorCallSmcFailureCallerWillRevertXorDecodedFlag1XorWarmNew = - buffers.get(49); - this.isEcmulXorOobFlagXorCallSmcFailureCallerWontRevertXorDecodedFlag2 = buffers.get(50); - this.isEcpairingXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecodedFlag3 = buffers.get(51); - this.isEcrecoverXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecodedFlag4 = buffers.get(52); - this.isIdentityXorStpOogxXorCodedepositXorDupFlag = buffers.get(53); - this.isModexpXorStpWarmXorCodedepositInvalidCodePrefixXorExtFlag = buffers.get(54); - this.isPrecompileXorCodedepositValidCodePrefixXorHaltFlag = buffers.get(55); - this.isRipemd160XorEcaddXorHashInfoFlag = buffers.get(56); - this.isSha2256XorEcmulXorInvalidFlag = buffers.get(57); - this.mmuStamp = buffers.get(58); - this.mxpSize1LoXorStackItemValueLo2 = buffers.get(59); - this.mxpSize2HiXorStackItemValueLo3 = buffers.get(60); - this.mxpSize2LoXorStackItemValueLo4 = buffers.get(61); - this.mxpStamp = buffers.get(62); - this.mxpWordsXorStaticGas = buffers.get(63); - this.nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce = buffers.get(64); - this.nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas = buffers.get(65); - this.numberOfNonStackRows = buffers.get(66); - this.oobInst = buffers.get(67); - this.oobOutgoingData1 = buffers.get(68); - this.oobOutgoingData2 = buffers.get(69); - this.oobOutgoingData3 = buffers.get(70); - this.oobOutgoingData4 = buffers.get(71); - this.oobOutgoingData5 = buffers.get(72); - this.oobOutgoingData6 = buffers.get(73); - this.peekAtAccount = buffers.get(74); - this.peekAtContext = buffers.get(75); - this.peekAtMiscellaneous = buffers.get(76); - this.peekAtScenario = buffers.get(77); - this.peekAtStack = buffers.get(78); - this.peekAtStorage = buffers.get(79); - this.peekAtTransaction = buffers.get(80); - this.programCounter = buffers.get(81); - this.programCounterNew = buffers.get(82); - this.pushpopFlag = buffers.get(83); - this.rdcx = buffers.get(84); - this.ripemd160XorKecFlag = buffers.get(85); - this.rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi = - buffers.get(86); - this.rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo = - buffers.get(87); - this.rlpaddrFlagXorEcpairingXorInvprex = buffers.get(88); - this.rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue = buffers.get(89); - this.rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1 = buffers.get(90); - this.rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2 = buffers.get(91); - this.rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3 = buffers.get(92); - this.rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4 = buffers.get(93); - this.scnFailure1XorLogFlag = buffers.get(94); - this.scnFailure2XorMachineStateFlag = buffers.get(95); - this.scnFailure3XorMaxcsx = buffers.get(96); - this.scnFailure4XorModFlag = buffers.get(97); - this.scnSuccess1XorMulFlag = buffers.get(98); - this.scnSuccess2XorMxpx = buffers.get(99); - this.scnSuccess3XorMxpFlag = buffers.get(100); - this.scnSuccess4XorOobFlag = buffers.get(101); - this.selfdestructXorOogx = buffers.get(102); - this.sha2256XorOpcx = buffers.get(103); - this.shfFlag = buffers.get(104); - this.sox = buffers.get(105); - this.sstorex = buffers.get(106); - this.stackItemPop1 = buffers.get(107); - this.stackItemPop2 = buffers.get(108); - this.stackItemPop3 = buffers.get(109); - this.stackItemPop4 = buffers.get(110); - this.stackramFlag = buffers.get(111); - this.staticFlag = buffers.get(112); - this.staticx = buffers.get(113); - this.stoFlag = buffers.get(114); - this.stpGasHi = buffers.get(115); - this.stpGasLo = buffers.get(116); - this.stpGasOopkt = buffers.get(117); - this.stpGasStpd = buffers.get(118); - this.stpInst = buffers.get(119); - this.stpValHi = buffers.get(120); - this.stpValLo = buffers.get(121); - this.subStamp = buffers.get(122); - this.sux = buffers.get(123); - this.swapFlag = buffers.get(124); - this.transactionReverts = buffers.get(125); - this.trmFlag = buffers.get(126); - this.trmFlagXorEcrecoverXorJumpx = buffers.get(127); - this.trmRawAddrHiXorMxpSize1HiXorStackItemValueLo1 = buffers.get(128); - this.twoLineInstruction = buffers.get(129); - this.txExec = buffers.get(130); - this.txFinl = buffers.get(131); - this.txInit = buffers.get(132); - this.txSkip = buffers.get(133); - this.txWarm = buffers.get(134); - this.txnFlag = buffers.get(135); - this.warmNewXorModexpXorJumpFlag = buffers.get(136); - this.warmXorIdentityXorJumpDestinationVettingRequired = buffers.get(137); - this.wcpFlag = buffers.get(138); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace absoluteTransactionNumber(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("hub_v2.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()); - - return this; - } - - public Trace batchNumber(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("hub_v2.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()); - - return this; - } - - public Trace callerContextNumber(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("hub_v2.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()); - - return this; - } - - public Trace codeAddressHi(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("hub_v2.CODE_ADDRESS_HI already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeAddressHi.put((byte) 0); - } - codeAddressHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace codeAddressLo(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("hub_v2.CODE_ADDRESS_LO already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeAddressLo.put((byte) 0); - } - codeAddressLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace codeDeploymentNumber(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("hub_v2.CODE_DEPLOYMENT_NUMBER already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeDeploymentNumber.put((byte) 0); - } - codeDeploymentNumber.put(b.toArrayUnsafe()); - - return this; - } - - public Trace codeDeploymentStatus(final Boolean b) { - if (filled.get(6)) { - throw new IllegalStateException("hub_v2.CODE_DEPLOYMENT_STATUS already set"); - } else { - filled.set(6); - } - - codeDeploymentStatus.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace codeFragmentIndex(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("hub_v2.CODE_FRAGMENT_INDEX already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeFragmentIndex.put((byte) 0); - } - codeFragmentIndex.put(b.toArrayUnsafe()); - - return this; - } - - public Trace contextGetsRevertedFlag(final Boolean b) { - if (filled.get(8)) { - throw new IllegalStateException("hub_v2.CONTEXT_GETS_REVERTED_FLAG already set"); - } else { - filled.set(8); - } - - contextGetsRevertedFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace contextMayChangeFlag(final Boolean b) { - if (filled.get(9)) { - throw new IllegalStateException("hub_v2.CONTEXT_MAY_CHANGE_FLAG already set"); - } else { - filled.set(9); - } - - contextMayChangeFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace contextNumber(final Bytes b) { - if (filled.get(10)) { - throw new IllegalStateException("hub_v2.CONTEXT_NUMBER already set"); - } else { - filled.set(10); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - contextNumber.put((byte) 0); - } - contextNumber.put(b.toArrayUnsafe()); - - return this; - } - - public Trace contextNumberNew(final Bytes b) { - if (filled.get(11)) { - throw new IllegalStateException("hub_v2.CONTEXT_NUMBER_NEW already set"); - } else { - filled.set(11); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - contextNumberNew.put((byte) 0); - } - contextNumberNew.put(b.toArrayUnsafe()); - - return this; - } - - public Trace contextRevertStamp(final Bytes b) { - if (filled.get(12)) { - throw new IllegalStateException("hub_v2.CONTEXT_REVERT_STAMP already set"); - } else { - filled.set(12); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - contextRevertStamp.put((byte) 0); - } - contextRevertStamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace contextSelfRevertsFlag(final Boolean b) { - if (filled.get(13)) { - throw new IllegalStateException("hub_v2.CONTEXT_SELF_REVERTS_FLAG already set"); - } else { - filled.set(13); - } - - contextSelfRevertsFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace contextWillRevertFlag(final Boolean b) { - if (filled.get(14)) { - throw new IllegalStateException("hub_v2.CONTEXT_WILL_REVERT_FLAG already set"); - } else { - filled.set(14); - } - - contextWillRevertFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace counterNsr(final Bytes b) { - if (filled.get(15)) { - throw new IllegalStateException("hub_v2.COUNTER_NSR already set"); - } else { - filled.set(15); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - counterNsr.put((byte) 0); - } - counterNsr.put(b.toArrayUnsafe()); - - return this; - } - - public Trace counterTli(final Boolean b) { - if (filled.get(16)) { - throw new IllegalStateException("hub_v2.COUNTER_TLI already set"); - } else { - filled.set(16); - } - - counterTli.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace domStamp(final Bytes b) { - if (filled.get(17)) { - throw new IllegalStateException("hub_v2.DOM_STAMP already set"); - } else { - filled.set(17); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - domStamp.put((byte) 0); - } - domStamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace exceptionAhoyFlag(final Boolean b) { - if (filled.get(18)) { - throw new IllegalStateException("hub_v2.EXCEPTION_AHOY_FLAG already set"); - } else { - filled.set(18); - } - - exceptionAhoyFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace gasActual(final Bytes b) { - if (filled.get(19)) { - throw new IllegalStateException("hub_v2.GAS_ACTUAL already set"); - } else { - filled.set(19); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasActual.put((byte) 0); - } - gasActual.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasCost(final Bytes b) { - if (filled.get(20)) { - throw new IllegalStateException("hub_v2.GAS_COST already set"); - } else { - filled.set(20); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasCost.put((byte) 0); - } - gasCost.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasExpected(final Bytes b) { - if (filled.get(21)) { - throw new IllegalStateException("hub_v2.GAS_EXPECTED already set"); - } else { - filled.set(21); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasExpected.put((byte) 0); - } - gasExpected.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasNext(final Bytes b) { - if (filled.get(22)) { - throw new IllegalStateException("hub_v2.GAS_NEXT already set"); - } else { - filled.set(22); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasNext.put((byte) 0); - } - gasNext.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasRefund(final Bytes b) { - if (filled.get(23)) { - throw new IllegalStateException("hub_v2.GAS_REFUND already set"); - } else { - filled.set(23); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasRefund.put((byte) 0); - } - gasRefund.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasRefundNew(final Bytes b) { - if (filled.get(24)) { - throw new IllegalStateException("hub_v2.GAS_REFUND_NEW already set"); - } else { - filled.set(24); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasRefundNew.put((byte) 0); - } - gasRefundNew.put(b.toArrayUnsafe()); - - return this; - } - - public Trace hashInfoStamp(final Bytes b) { - if (filled.get(25)) { - throw new IllegalStateException("hub_v2.HASH_INFO_STAMP already set"); - } else { - filled.set(25); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - hashInfoStamp.put((byte) 0); - } - hashInfoStamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace hubStamp(final Bytes b) { - if (filled.get(26)) { - throw new IllegalStateException("hub_v2.HUB_STAMP already set"); - } else { - filled.set(26); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - hubStamp.put((byte) 0); - } - hubStamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace hubStampTransactionEnd(final Bytes b) { - if (filled.get(27)) { - throw new IllegalStateException("hub_v2.HUB_STAMP_TRANSACTION_END already set"); - } else { - filled.set(27); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - hubStampTransactionEnd.put((byte) 0); - } - hubStampTransactionEnd.put(b.toArrayUnsafe()); - - return this; - } - - public Trace mmuStamp(final Bytes b) { - if (filled.get(28)) { - throw new IllegalStateException("hub_v2.MMU_STAMP already set"); - } else { - filled.set(28); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mmuStamp.put((byte) 0); - } - mmuStamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace mxpStamp(final Bytes b) { - if (filled.get(29)) { - throw new IllegalStateException("hub_v2.MXP_STAMP already set"); - } else { - filled.set(29); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mxpStamp.put((byte) 0); - } - mxpStamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace numberOfNonStackRows(final Bytes b) { - if (filled.get(30)) { - throw new IllegalStateException("hub_v2.NUMBER_OF_NON_STACK_ROWS already set"); - } else { - filled.set(30); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - numberOfNonStackRows.put((byte) 0); - } - numberOfNonStackRows.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountAddrHi(final Bytes b) { - if (filled.get(98)) { - throw new IllegalStateException("hub_v2.account/ADDR_HI already set"); - } else { - filled.set(98); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put((byte) 0); - } - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountAddrLo(final Bytes b) { - if (filled.get(99)) { - throw new IllegalStateException("hub_v2.account/ADDR_LO already set"); - } else { - filled.set(99); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - (byte) 0); - } - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountBalance(final Bytes b) { - if (filled.get(100)) { - throw new IllegalStateException("hub_v2.account/BALANCE already set"); - } else { - filled.set(100); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) 0); - } - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountBalanceNew(final Bytes b) { - if (filled.get(101)) { - throw new IllegalStateException("hub_v2.account/BALANCE_NEW already set"); - } else { - filled.set(101); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo - .put((byte) 0); - } - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountCodeHashHi(final Bytes b) { - if (filled.get(102)) { - throw new IllegalStateException("hub_v2.account/CODE_HASH_HI already set"); - } else { - filled.set(102); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - (byte) 0); - } - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountCodeHashHiNew(final Bytes b) { - if (filled.get(103)) { - throw new IllegalStateException("hub_v2.account/CODE_HASH_HI_NEW already set"); - } else { - filled.set(103); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo - .put((byte) 0); - } - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountCodeHashLo(final Bytes b) { - if (filled.get(104)) { - throw new IllegalStateException("hub_v2.account/CODE_HASH_LO already set"); - } else { - filled.set(104); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - (byte) 0); - } - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountCodeHashLoNew(final Bytes b) { - if (filled.get(105)) { - throw new IllegalStateException("hub_v2.account/CODE_HASH_LO_NEW already set"); - } else { - filled.set(105); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put((byte) 0); - } - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountCodeSize(final Bytes b) { - if (filled.get(106)) { - throw new IllegalStateException("hub_v2.account/CODE_SIZE already set"); - } else { - filled.set(106); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - (byte) 0); - } - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountCodeSizeNew(final Bytes b) { - if (filled.get(107)) { - throw new IllegalStateException("hub_v2.account/CODE_SIZE_NEW already set"); - } else { - filled.set(107); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put((byte) 0); - } - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountDepNum(final Bytes b) { - if (filled.get(109)) { - throw new IllegalStateException("hub_v2.account/DEP_NUM already set"); - } else { - filled.set(109); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.put((byte) 0); - } - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountDepNumNew(final Bytes b) { - if (filled.get(110)) { - throw new IllegalStateException("hub_v2.account/DEP_NUM_NEW already set"); - } else { - filled.set(110); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.put((byte) 0); - } - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountDepStatus(final Boolean b) { - if (filled.get(49)) { - throw new IllegalStateException("hub_v2.account/DEP_STATUS already set"); - } else { - filled.set(49); - } - - depStatusXorExpFlagXorCallAbortXorAddFlagXorValCurrIsOrigXorIsEip1559.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountDepStatusNew(final Boolean b) { - if (filled.get(50)) { - throw new IllegalStateException("hub_v2.account/DEP_STATUS_NEW already set"); - } else { - filled.set(50); - } - - depStatusNewXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValCurrIsZeroXorStatusCode - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountDeploymentNumberInfty(final Bytes b) { - if (filled.get(108)) { - throw new IllegalStateException("hub_v2.account/DEPLOYMENT_NUMBER_INFTY already set"); - } else { - filled.set(108); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put((byte) 0); - } - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountDeploymentStatusInfty(final Boolean b) { - if (filled.get(48)) { - throw new IllegalStateException("hub_v2.account/DEPLOYMENT_STATUS_INFTY already set"); - } else { - filled.set(48); - } - - deploymentStatusInftyXorUpdateXorCcsrFlagXorBlake2FXorAccFlagXorValCurrChangesXorIsDeployment - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountExists(final Boolean b) { - if (filled.get(51)) { - throw new IllegalStateException("hub_v2.account/EXISTS already set"); - } else { - filled.set(51); - } - - existsXorMmuInfoXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValNextIsCurrXorTxnRequiresEvmExecution - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountExistsNew(final Boolean b) { - if (filled.get(52)) { - throw new IllegalStateException("hub_v2.account/EXISTS_NEW already set"); - } else { - filled.set(52); - } - - existsNewXorMxpDeploysXorCallPrcFailureCallerWillRevertXorCallFlagXorValNextIsOrig.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountHasCode(final Boolean b) { - if (filled.get(53)) { - throw new IllegalStateException("hub_v2.account/HAS_CODE already set"); - } else { - filled.set(53); - } - - hasCodeXorMxpFlagXorCallPrcFailureCallerWontRevertXorConFlagXorValNextIsZero.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountHasCodeNew(final Boolean b) { - if (filled.get(54)) { - throw new IllegalStateException("hub_v2.account/HAS_CODE_NEW already set"); - } else { - filled.set(54); - } - - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValOrigIsZero.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountIsBlake2F(final Boolean b) { - if (filled.get(55)) { - throw new IllegalStateException("hub_v2.account/IS_BLAKE2f already set"); - } else { - filled.set(55); - } - - isBlake2FXorOobEvent1XorCallPrcSuccessCallerWontRevertXorCreateFlagXorWarm.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountIsEcadd(final Boolean b) { - if (filled.get(56)) { - throw new IllegalStateException("hub_v2.account/IS_ECADD already set"); - } else { - filled.set(56); - } - - isEcaddXorOobEvent2XorCallSmcFailureCallerWillRevertXorDecodedFlag1XorWarmNew.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountIsEcmul(final Boolean b) { - if (filled.get(57)) { - throw new IllegalStateException("hub_v2.account/IS_ECMUL already set"); - } else { - filled.set(57); - } - - isEcmulXorOobFlagXorCallSmcFailureCallerWontRevertXorDecodedFlag2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountIsEcpairing(final Boolean b) { - if (filled.get(58)) { - throw new IllegalStateException("hub_v2.account/IS_ECPAIRING already set"); - } else { - filled.set(58); - } - - isEcpairingXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecodedFlag3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountIsEcrecover(final Boolean b) { - if (filled.get(59)) { - throw new IllegalStateException("hub_v2.account/IS_ECRECOVER already set"); - } else { - filled.set(59); - } - - isEcrecoverXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecodedFlag4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountIsIdentity(final Boolean b) { - if (filled.get(60)) { - throw new IllegalStateException("hub_v2.account/IS_IDENTITY already set"); - } else { - filled.set(60); - } - - isIdentityXorStpOogxXorCodedepositXorDupFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountIsModexp(final Boolean b) { - if (filled.get(61)) { - throw new IllegalStateException("hub_v2.account/IS_MODEXP already set"); - } else { - filled.set(61); - } - - isModexpXorStpWarmXorCodedepositInvalidCodePrefixXorExtFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountIsPrecompile(final Boolean b) { - if (filled.get(62)) { - throw new IllegalStateException("hub_v2.account/IS_PRECOMPILE already set"); - } else { - filled.set(62); - } - - isPrecompileXorCodedepositValidCodePrefixXorHaltFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountIsRipemd160(final Boolean b) { - if (filled.get(63)) { - throw new IllegalStateException("hub_v2.account/IS_RIPEMD-160 already set"); - } else { - filled.set(63); - } - - isRipemd160XorEcaddXorHashInfoFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountIsSha2256(final Boolean b) { - if (filled.get(64)) { - throw new IllegalStateException("hub_v2.account/IS_SHA2-256 already set"); - } else { - filled.set(64); - } - - isSha2256XorEcmulXorInvalidFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountNonce(final Bytes b) { - if (filled.get(111)) { - throw new IllegalStateException("hub_v2.account/NONCE already set"); - } else { - filled.set(111); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.put((byte) 0); - } - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountNonceNew(final Bytes b) { - if (filled.get(112)) { - throw new IllegalStateException("hub_v2.account/NONCE_NEW already set"); - } else { - filled.set(112); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.put((byte) 0); - } - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountRlpaddrDepAddrHi(final Bytes b) { - if (filled.get(113)) { - throw new IllegalStateException("hub_v2.account/RLPADDR___DEP_ADDR_HI already set"); - } else { - filled.set(113); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.put((byte) 0); - } - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountRlpaddrDepAddrLo(final Bytes b) { - if (filled.get(114)) { - throw new IllegalStateException("hub_v2.account/RLPADDR___DEP_ADDR_LO already set"); - } else { - filled.set(114); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo.put( - (byte) 0); - } - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountRlpaddrFlag(final Boolean b) { - if (filled.get(65)) { - throw new IllegalStateException("hub_v2.account/RLPADDR___FLAG already set"); - } else { - filled.set(65); - } - - rlpaddrFlagXorEcpairingXorInvprex.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountRlpaddrKecHi(final Bytes b) { - if (filled.get(115)) { - throw new IllegalStateException("hub_v2.account/RLPADDR___KEC_HI already set"); - } else { - filled.set(115); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.put((byte) 0); - } - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountRlpaddrKecLo(final Bytes b) { - if (filled.get(116)) { - throw new IllegalStateException("hub_v2.account/RLPADDR___KEC_LO already set"); - } else { - filled.set(116); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1.put((byte) 0); - } - rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountRlpaddrRecipe(final Bytes b) { - if (filled.get(117)) { - throw new IllegalStateException("hub_v2.account/RLPADDR___RECIPE already set"); - } else { - filled.set(117); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2.put((byte) 0); - } - rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountRlpaddrSaltHi(final Bytes b) { - if (filled.get(118)) { - throw new IllegalStateException("hub_v2.account/RLPADDR___SALT_HI already set"); - } else { - filled.set(118); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3.put((byte) 0); - } - rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountRlpaddrSaltLo(final Bytes b) { - if (filled.get(119)) { - throw new IllegalStateException("hub_v2.account/RLPADDR___SALT_LO already set"); - } else { - filled.set(119); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4.put((byte) 0); - } - rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountTrmFlag(final Boolean b) { - if (filled.get(66)) { - throw new IllegalStateException("hub_v2.account/TRM___FLAG already set"); - } else { - filled.set(66); - } - - trmFlagXorEcrecoverXorJumpx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountTrmRawAddrHi(final Bytes b) { - if (filled.get(120)) { - throw new IllegalStateException("hub_v2.account/TRM___RAW_ADDR_HI already set"); - } else { - filled.set(120); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - trmRawAddrHiXorMxpSize1HiXorStackItemValueLo1.put((byte) 0); - } - trmRawAddrHiXorMxpSize1HiXorStackItemValueLo1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pAccountWarm(final Boolean b) { - if (filled.get(67)) { - throw new IllegalStateException("hub_v2.account/WARM already set"); - } else { - filled.set(67); - } - - warmXorIdentityXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pAccountWarmNew(final Boolean b) { - if (filled.get(68)) { - throw new IllegalStateException("hub_v2.account/WARM_NEW already set"); - } else { - filled.set(68); - } - - warmNewXorModexpXorJumpFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pContextAccountAddressHi(final Bytes b) { - if (filled.get(98)) { - throw new IllegalStateException("hub_v2.context/ACCOUNT_ADDRESS_HI already set"); - } else { - filled.set(98); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put((byte) 0); - } - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pContextAccountAddressLo(final Bytes b) { - if (filled.get(99)) { - throw new IllegalStateException("hub_v2.context/ACCOUNT_ADDRESS_LO already set"); - } else { - filled.set(99); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - (byte) 0); - } - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pContextAccountDeploymentNumber(final Bytes b) { - if (filled.get(100)) { - throw new IllegalStateException("hub_v2.context/ACCOUNT_DEPLOYMENT_NUMBER already set"); - } else { - filled.set(100); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) 0); - } - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextByteCodeAddressHi(final Bytes b) { - if (filled.get(101)) { - throw new IllegalStateException("hub_v2.context/BYTE_CODE_ADDRESS_HI already set"); - } else { - filled.set(101); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo - .put((byte) 0); - } - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pContextByteCodeAddressLo(final Bytes b) { - if (filled.get(102)) { - throw new IllegalStateException("hub_v2.context/BYTE_CODE_ADDRESS_LO already set"); - } else { - filled.set(102); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - (byte) 0); - } - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pContextByteCodeDeploymentNumber(final Bytes b) { - if (filled.get(103)) { - throw new IllegalStateException("hub_v2.context/BYTE_CODE_DEPLOYMENT_NUMBER already set"); - } else { - filled.set(103); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo - .put((byte) 0); - } - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pContextByteCodeDeploymentStatus(final Bytes b) { - if (filled.get(104)) { - throw new IllegalStateException("hub_v2.context/BYTE_CODE_DEPLOYMENT_STATUS already set"); - } else { - filled.set(104); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - (byte) 0); - } - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pContextCallDataOffset(final Bytes b) { - if (filled.get(108)) { - throw new IllegalStateException("hub_v2.context/CALL_DATA_OFFSET already set"); - } else { - filled.set(108); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put((byte) 0); - } - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextCallDataSize(final Bytes b) { - if (filled.get(109)) { - throw new IllegalStateException("hub_v2.context/CALL_DATA_SIZE already set"); - } else { - filled.set(109); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.put((byte) 0); - } - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextCallStackDepth(final Bytes b) { - if (filled.get(110)) { - throw new IllegalStateException("hub_v2.context/CALL_STACK_DEPTH already set"); - } else { - filled.set(110); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.put((byte) 0); - } - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextCallValue(final Bytes b) { - if (filled.get(111)) { - throw new IllegalStateException("hub_v2.context/CALL_VALUE already set"); - } else { - filled.set(111); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.put((byte) 0); - } - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextCallerAddressHi(final Bytes b) { - if (filled.get(105)) { - throw new IllegalStateException("hub_v2.context/CALLER_ADDRESS_HI already set"); - } else { - filled.set(105); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put((byte) 0); - } - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pContextCallerAddressLo(final Bytes b) { - if (filled.get(106)) { - throw new IllegalStateException("hub_v2.context/CALLER_ADDRESS_LO already set"); - } else { - filled.set(106); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - (byte) 0); - } - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pContextCallerContextNumber(final Bytes b) { - if (filled.get(107)) { - throw new IllegalStateException("hub_v2.context/CALLER_CONTEXT_NUMBER already set"); - } else { - filled.set(107); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put((byte) 0); - } - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextContextNumber(final Bytes b) { - if (filled.get(112)) { - throw new IllegalStateException("hub_v2.context/CONTEXT_NUMBER already set"); - } else { - filled.set(112); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.put((byte) 0); - } - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextIsStatic(final Bytes b) { - if (filled.get(113)) { - throw new IllegalStateException("hub_v2.context/IS_STATIC already set"); - } else { - filled.set(113); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.put((byte) 0); - } - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pContextReturnAtOffset(final Bytes b) { - if (filled.get(116)) { - throw new IllegalStateException("hub_v2.context/RETURN_AT_OFFSET already set"); - } else { - filled.set(116); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1.put((byte) 0); - } - rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextReturnAtSize(final Bytes b) { - if (filled.get(117)) { - throw new IllegalStateException("hub_v2.context/RETURN_AT_SIZE already set"); - } else { - filled.set(117); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2.put((byte) 0); - } - rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextReturnDataOffset(final Bytes b) { - if (filled.get(118)) { - throw new IllegalStateException("hub_v2.context/RETURN_DATA_OFFSET already set"); - } else { - filled.set(118); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3.put((byte) 0); - } - rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextReturnDataSize(final Bytes b) { - if (filled.get(119)) { - throw new IllegalStateException("hub_v2.context/RETURN_DATA_SIZE already set"); - } else { - filled.set(119); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4.put((byte) 0); - } - rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextReturnerContextNumber(final Bytes b) { - if (filled.get(114)) { - throw new IllegalStateException("hub_v2.context/RETURNER_CONTEXT_NUMBER already set"); - } else { - filled.set(114); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo.put( - (byte) 0); - } - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pContextReturnerIsPrecompile(final Bytes b) { - if (filled.get(115)) { - throw new IllegalStateException("hub_v2.context/RETURNER_IS_PRECOMPILE already set"); - } else { - filled.set(115); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.put((byte) 0); - } - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pContextUpdate(final Boolean b) { - if (filled.get(48)) { - throw new IllegalStateException("hub_v2.context/UPDATE already set"); - } else { - filled.set(48); - } - - deploymentStatusInftyXorUpdateXorCcsrFlagXorBlake2FXorAccFlagXorValCurrChangesXorIsDeployment - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousCcrsStamp(final Bytes b) { - if (filled.get(98)) { - throw new IllegalStateException("hub_v2.miscellaneous/CCRS_STAMP already set"); - } else { - filled.set(98); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put((byte) 0); - } - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousCcsrFlag(final Boolean b) { - if (filled.get(48)) { - throw new IllegalStateException("hub_v2.miscellaneous/CCSR_FLAG already set"); - } else { - filled.set(48); - } - - deploymentStatusInftyXorUpdateXorCcsrFlagXorBlake2FXorAccFlagXorValCurrChangesXorIsDeployment - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousExpDyncost(final Bytes b) { - if (filled.get(99)) { - throw new IllegalStateException("hub_v2.miscellaneous/EXP___DYNCOST already set"); - } else { - filled.set(99); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - (byte) 0); - } - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousExpExponentHi(final Bytes b) { - if (filled.get(100)) { - throw new IllegalStateException("hub_v2.miscellaneous/EXP___EXPONENT_HI already set"); - } else { - filled.set(100); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) 0); - } - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousExpExponentLo(final Bytes b) { - if (filled.get(101)) { - throw new IllegalStateException("hub_v2.miscellaneous/EXP___EXPONENT_LO already set"); - } else { - filled.set(101); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo - .put((byte) 0); - } - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousExpFlag(final Boolean b) { - if (filled.get(49)) { - throw new IllegalStateException("hub_v2.miscellaneous/EXP___FLAG already set"); - } else { - filled.set(49); - } - - depStatusXorExpFlagXorCallAbortXorAddFlagXorValCurrIsOrigXorIsEip1559.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousMmuExoSum(final Bytes b) { - if (filled.get(102)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___EXO_SUM already set"); - } else { - filled.set(102); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - (byte) 0); - } - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMmuFlag(final Boolean b) { - if (filled.get(50)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___FLAG already set"); - } else { - filled.set(50); - } - - depStatusNewXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValCurrIsZeroXorStatusCode - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousMmuInfo(final Boolean b) { - if (filled.get(51)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___INFO already set"); - } else { - filled.set(51); - } - - existsXorMmuInfoXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValNextIsCurrXorTxnRequiresEvmExecution - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousMmuInst(final Bytes b) { - if (filled.get(103)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___INST already set"); - } else { - filled.set(103); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo - .put((byte) 0); - } - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMmuOffset1Lo(final Bytes b) { - if (filled.get(104)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___OFFSET_1_LO already set"); - } else { - filled.set(104); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - (byte) 0); - } - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMmuOffset2Hi(final Bytes b) { - if (filled.get(105)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___OFFSET_2_HI already set"); - } else { - filled.set(105); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put((byte) 0); - } - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMmuOffset2Lo(final Bytes b) { - if (filled.get(106)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___OFFSET_2_LO already set"); - } else { - filled.set(106); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - (byte) 0); - } - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMmuParam1(final Bytes b) { - if (filled.get(107)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___PARAM_1 already set"); - } else { - filled.set(107); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put((byte) 0); - } - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMmuParam2(final Bytes b) { - if (filled.get(108)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___PARAM_2 already set"); - } else { - filled.set(108); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put((byte) 0); - } - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMmuRefOffset(final Bytes b) { - if (filled.get(109)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___REF_OFFSET already set"); - } else { - filled.set(109); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.put((byte) 0); - } - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMmuRefSize(final Bytes b) { - if (filled.get(110)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___REF_SIZE already set"); - } else { - filled.set(110); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.put((byte) 0); - } - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMmuSize(final Bytes b) { - if (filled.get(111)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___SIZE already set"); - } else { - filled.set(111); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.put((byte) 0); - } - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMmuStackValHi(final Bytes b) { - if (filled.get(112)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___STACK_VAL_HI already set"); - } else { - filled.set(112); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.put((byte) 0); - } - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMmuStackValLo(final Bytes b) { - if (filled.get(113)) { - throw new IllegalStateException("hub_v2.miscellaneous/MMU___STACK_VAL_LO already set"); - } else { - filled.set(113); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.put((byte) 0); - } - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMxpDeploys(final Boolean b) { - if (filled.get(52)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___DEPLOYS already set"); - } else { - filled.set(52); - } - - existsNewXorMxpDeploysXorCallPrcFailureCallerWillRevertXorCallFlagXorValNextIsOrig.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousMxpFlag(final Boolean b) { - if (filled.get(53)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___FLAG already set"); - } else { - filled.set(53); - } - - hasCodeXorMxpFlagXorCallPrcFailureCallerWontRevertXorConFlagXorValNextIsZero.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousMxpGasMxp(final Bytes b) { - if (filled.get(114)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___GAS_MXP already set"); - } else { - filled.set(114); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo.put( - (byte) 0); - } - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMxpInst(final Bytes b) { - if (filled.get(115)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___INST already set"); - } else { - filled.set(115); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.put((byte) 0); - } - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMxpMxpx(final Boolean b) { - if (filled.get(54)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___MXPX already set"); - } else { - filled.set(54); - } - - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValOrigIsZero.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousMxpOffset1Hi(final Bytes b) { - if (filled.get(116)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___OFFSET_1_HI already set"); - } else { - filled.set(116); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1.put((byte) 0); - } - rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMxpOffset1Lo(final Bytes b) { - if (filled.get(117)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___OFFSET_1_LO already set"); - } else { - filled.set(117); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2.put((byte) 0); - } - rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMxpOffset2Hi(final Bytes b) { - if (filled.get(118)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___OFFSET_2_HI already set"); - } else { - filled.set(118); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3.put((byte) 0); - } - rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMxpOffset2Lo(final Bytes b) { - if (filled.get(119)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___OFFSET_2_LO already set"); - } else { - filled.set(119); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4.put((byte) 0); - } - rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMxpSize1Hi(final Bytes b) { - if (filled.get(120)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___SIZE_1_HI already set"); - } else { - filled.set(120); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - trmRawAddrHiXorMxpSize1HiXorStackItemValueLo1.put((byte) 0); - } - trmRawAddrHiXorMxpSize1HiXorStackItemValueLo1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMxpSize1Lo(final Bytes b) { - if (filled.get(121)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___SIZE_1_LO already set"); - } else { - filled.set(121); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mxpSize1LoXorStackItemValueLo2.put((byte) 0); - } - mxpSize1LoXorStackItemValueLo2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMxpSize2Hi(final Bytes b) { - if (filled.get(122)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___SIZE_2_HI already set"); - } else { - filled.set(122); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mxpSize2HiXorStackItemValueLo3.put((byte) 0); - } - mxpSize2HiXorStackItemValueLo3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMxpSize2Lo(final Bytes b) { - if (filled.get(123)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___SIZE_2_LO already set"); - } else { - filled.set(123); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mxpSize2LoXorStackItemValueLo4.put((byte) 0); - } - mxpSize2LoXorStackItemValueLo4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousMxpWords(final Bytes b) { - if (filled.get(124)) { - throw new IllegalStateException("hub_v2.miscellaneous/MXP___WORDS already set"); - } else { - filled.set(124); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mxpWordsXorStaticGas.put((byte) 0); - } - mxpWordsXorStaticGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousOobEvent1(final Boolean b) { - if (filled.get(55)) { - throw new IllegalStateException("hub_v2.miscellaneous/OOB___EVENT_1 already set"); - } else { - filled.set(55); - } - - isBlake2FXorOobEvent1XorCallPrcSuccessCallerWontRevertXorCreateFlagXorWarm.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousOobEvent2(final Boolean b) { - if (filled.get(56)) { - throw new IllegalStateException("hub_v2.miscellaneous/OOB___EVENT_2 already set"); - } else { - filled.set(56); - } - - isEcaddXorOobEvent2XorCallSmcFailureCallerWillRevertXorDecodedFlag1XorWarmNew.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousOobFlag(final Boolean b) { - if (filled.get(57)) { - throw new IllegalStateException("hub_v2.miscellaneous/OOB___FLAG already set"); - } else { - filled.set(57); - } - - isEcmulXorOobFlagXorCallSmcFailureCallerWontRevertXorDecodedFlag2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousOobInst(final Bytes b) { - if (filled.get(125)) { - throw new IllegalStateException("hub_v2.miscellaneous/OOB___INST already set"); - } else { - filled.set(125); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - oobInst.put((byte) 0); - } - oobInst.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousOobOutgoingData1(final Bytes b) { - if (filled.get(126)) { - throw new IllegalStateException("hub_v2.miscellaneous/OOB___OUTGOING_DATA_1 already set"); - } else { - filled.set(126); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - oobOutgoingData1.put((byte) 0); - } - oobOutgoingData1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousOobOutgoingData2(final Bytes b) { - if (filled.get(127)) { - throw new IllegalStateException("hub_v2.miscellaneous/OOB___OUTGOING_DATA_2 already set"); - } else { - filled.set(127); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - oobOutgoingData2.put((byte) 0); - } - oobOutgoingData2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousOobOutgoingData3(final Bytes b) { - if (filled.get(128)) { - throw new IllegalStateException("hub_v2.miscellaneous/OOB___OUTGOING_DATA_3 already set"); - } else { - filled.set(128); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - oobOutgoingData3.put((byte) 0); - } - oobOutgoingData3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousOobOutgoingData4(final Bytes b) { - if (filled.get(129)) { - throw new IllegalStateException("hub_v2.miscellaneous/OOB___OUTGOING_DATA_4 already set"); - } else { - filled.set(129); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - oobOutgoingData4.put((byte) 0); - } - oobOutgoingData4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousOobOutgoingData5(final Bytes b) { - if (filled.get(130)) { - throw new IllegalStateException("hub_v2.miscellaneous/OOB___OUTGOING_DATA_5 already set"); - } else { - filled.set(130); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - oobOutgoingData5.put((byte) 0); - } - oobOutgoingData5.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousOobOutgoingData6(final Bytes b) { - if (filled.get(131)) { - throw new IllegalStateException("hub_v2.miscellaneous/OOB___OUTGOING_DATA_6 already set"); - } else { - filled.set(131); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - oobOutgoingData6.put((byte) 0); - } - oobOutgoingData6.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousStpExists(final Boolean b) { - if (filled.get(58)) { - throw new IllegalStateException("hub_v2.miscellaneous/STP___EXISTS already set"); - } else { - filled.set(58); - } - - isEcpairingXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecodedFlag3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousStpFlag(final Boolean b) { - if (filled.get(59)) { - throw new IllegalStateException("hub_v2.miscellaneous/STP___FLAG already set"); - } else { - filled.set(59); - } - - isEcrecoverXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecodedFlag4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousStpGasHi(final Bytes b) { - if (filled.get(132)) { - throw new IllegalStateException("hub_v2.miscellaneous/STP___GAS_HI already set"); - } else { - filled.set(132); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stpGasHi.put((byte) 0); - } - stpGasHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousStpGasLo(final Bytes b) { - if (filled.get(133)) { - throw new IllegalStateException("hub_v2.miscellaneous/STP___GAS_LO already set"); - } else { - filled.set(133); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stpGasLo.put((byte) 0); - } - stpGasLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousStpGasOopkt(final Bytes b) { - if (filled.get(134)) { - throw new IllegalStateException("hub_v2.miscellaneous/STP___GAS_OOPKT already set"); - } else { - filled.set(134); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stpGasOopkt.put((byte) 0); - } - stpGasOopkt.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousStpGasStpd(final Bytes b) { - if (filled.get(135)) { - throw new IllegalStateException("hub_v2.miscellaneous/STP___GAS_STPD already set"); - } else { - filled.set(135); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stpGasStpd.put((byte) 0); - } - stpGasStpd.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousStpInst(final Bytes b) { - if (filled.get(136)) { - throw new IllegalStateException("hub_v2.miscellaneous/STP___INST already set"); - } else { - filled.set(136); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stpInst.put((byte) 0); - } - stpInst.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousStpOogx(final Boolean b) { - if (filled.get(60)) { - throw new IllegalStateException("hub_v2.miscellaneous/STP___OOGX already set"); - } else { - filled.set(60); - } - - isIdentityXorStpOogxXorCodedepositXorDupFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pMiscellaneousStpValHi(final Bytes b) { - if (filled.get(137)) { - throw new IllegalStateException("hub_v2.miscellaneous/STP___VAL_HI already set"); - } else { - filled.set(137); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stpValHi.put((byte) 0); - } - stpValHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousStpValLo(final Bytes b) { - if (filled.get(138)) { - throw new IllegalStateException("hub_v2.miscellaneous/STP___VAL_LO already set"); - } else { - filled.set(138); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stpValLo.put((byte) 0); - } - stpValLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pMiscellaneousStpWarm(final Boolean b) { - if (filled.get(61)) { - throw new IllegalStateException("hub_v2.miscellaneous/STP___WARM already set"); - } else { - filled.set(61); - } - - isModexpXorStpWarmXorCodedepositInvalidCodePrefixXorExtFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioBlake2F(final Boolean b) { - if (filled.get(48)) { - throw new IllegalStateException("hub_v2.scenario/BLAKE2f already set"); - } else { - filled.set(48); - } - - deploymentStatusInftyXorUpdateXorCcsrFlagXorBlake2FXorAccFlagXorValCurrChangesXorIsDeployment - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCallAbort(final Boolean b) { - if (filled.get(49)) { - throw new IllegalStateException("hub_v2.scenario/CALL_ABORT already set"); - } else { - filled.set(49); - } - - depStatusXorExpFlagXorCallAbortXorAddFlagXorValCurrIsOrigXorIsEip1559.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCallEoaSuccessCallerWillRevert(final Boolean b) { - if (filled.get(50)) { - throw new IllegalStateException( - "hub_v2.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); - } else { - filled.set(50); - } - - depStatusNewXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValCurrIsZeroXorStatusCode - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCallEoaSuccessCallerWontRevert(final Boolean b) { - if (filled.get(51)) { - throw new IllegalStateException( - "hub_v2.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); - } else { - filled.set(51); - } - - existsXorMmuInfoXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValNextIsCurrXorTxnRequiresEvmExecution - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCallPrcFailureCallerWillRevert(final Boolean b) { - if (filled.get(52)) { - throw new IllegalStateException( - "hub_v2.scenario/CALL_PRC_FAILURE_CALLER_WILL_REVERT already set"); - } else { - filled.set(52); - } - - existsNewXorMxpDeploysXorCallPrcFailureCallerWillRevertXorCallFlagXorValNextIsOrig.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCallPrcFailureCallerWontRevert(final Boolean b) { - if (filled.get(53)) { - throw new IllegalStateException( - "hub_v2.scenario/CALL_PRC_FAILURE_CALLER_WONT_REVERT already set"); - } else { - filled.set(53); - } - - hasCodeXorMxpFlagXorCallPrcFailureCallerWontRevertXorConFlagXorValNextIsZero.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCallPrcSuccessCallerWillRevert(final Boolean b) { - if (filled.get(54)) { - throw new IllegalStateException( - "hub_v2.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); - } else { - filled.set(54); - } - - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValOrigIsZero.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCallPrcSuccessCallerWontRevert(final Boolean b) { - if (filled.get(55)) { - throw new IllegalStateException( - "hub_v2.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); - } else { - filled.set(55); - } - - isBlake2FXorOobEvent1XorCallPrcSuccessCallerWontRevertXorCreateFlagXorWarm.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCallSmcFailureCallerWillRevert(final Boolean b) { - if (filled.get(56)) { - throw new IllegalStateException( - "hub_v2.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); - } else { - filled.set(56); - } - - isEcaddXorOobEvent2XorCallSmcFailureCallerWillRevertXorDecodedFlag1XorWarmNew.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCallSmcFailureCallerWontRevert(final Boolean b) { - if (filled.get(57)) { - throw new IllegalStateException( - "hub_v2.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); - } else { - filled.set(57); - } - - isEcmulXorOobFlagXorCallSmcFailureCallerWontRevertXorDecodedFlag2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCallSmcSuccessCallerWillRevert(final Boolean b) { - if (filled.get(58)) { - throw new IllegalStateException( - "hub_v2.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); - } else { - filled.set(58); - } - - isEcpairingXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecodedFlag3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { - if (filled.get(59)) { - throw new IllegalStateException( - "hub_v2.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); - } else { - filled.set(59); - } - - isEcrecoverXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecodedFlag4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCodedeposit(final Boolean b) { - if (filled.get(60)) { - throw new IllegalStateException("hub_v2.scenario/CODEDEPOSIT already set"); - } else { - filled.set(60); - } - - isIdentityXorStpOogxXorCodedepositXorDupFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCodedepositInvalidCodePrefix(final Boolean b) { - if (filled.get(61)) { - throw new IllegalStateException( - "hub_v2.scenario/CODEDEPOSIT_INVALID_CODE_PREFIX already set"); - } else { - filled.set(61); - } - - isModexpXorStpWarmXorCodedepositInvalidCodePrefixXorExtFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioCodedepositValidCodePrefix(final Boolean b) { - if (filled.get(62)) { - throw new IllegalStateException("hub_v2.scenario/CODEDEPOSIT_VALID_CODE_PREFIX already set"); - } else { - filled.set(62); - } - - isPrecompileXorCodedepositValidCodePrefixXorHaltFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioEcadd(final Boolean b) { - if (filled.get(63)) { - throw new IllegalStateException("hub_v2.scenario/ECADD already set"); - } else { - filled.set(63); - } - - isRipemd160XorEcaddXorHashInfoFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioEcmul(final Boolean b) { - if (filled.get(64)) { - throw new IllegalStateException("hub_v2.scenario/ECMUL already set"); - } else { - filled.set(64); - } - - isSha2256XorEcmulXorInvalidFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioEcpairing(final Boolean b) { - if (filled.get(65)) { - throw new IllegalStateException("hub_v2.scenario/ECPAIRING already set"); - } else { - filled.set(65); - } - - rlpaddrFlagXorEcpairingXorInvprex.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioEcrecover(final Boolean b) { - if (filled.get(66)) { - throw new IllegalStateException("hub_v2.scenario/ECRECOVER already set"); - } else { - filled.set(66); - } - - trmFlagXorEcrecoverXorJumpx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioIdentity(final Boolean b) { - if (filled.get(67)) { - throw new IllegalStateException("hub_v2.scenario/IDENTITY already set"); - } else { - filled.set(67); - } - - warmXorIdentityXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioModexp(final Boolean b) { - if (filled.get(68)) { - throw new IllegalStateException("hub_v2.scenario/MODEXP already set"); - } else { - filled.set(68); - } - - warmNewXorModexpXorJumpFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioRipemd160(final Boolean b) { - if (filled.get(69)) { - throw new IllegalStateException("hub_v2.scenario/RIPEMD-160 already set"); - } else { - filled.set(69); - } - - ripemd160XorKecFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioScnFailure1(final Boolean b) { - if (filled.get(70)) { - throw new IllegalStateException("hub_v2.scenario/SCN_FAILURE_1 already set"); - } else { - filled.set(70); - } - - scnFailure1XorLogFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioScnFailure2(final Boolean b) { - if (filled.get(71)) { - throw new IllegalStateException("hub_v2.scenario/SCN_FAILURE_2 already set"); - } else { - filled.set(71); - } - - scnFailure2XorMachineStateFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioScnFailure3(final Boolean b) { - if (filled.get(72)) { - throw new IllegalStateException("hub_v2.scenario/SCN_FAILURE_3 already set"); - } else { - filled.set(72); - } - - scnFailure3XorMaxcsx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioScnFailure4(final Boolean b) { - if (filled.get(73)) { - throw new IllegalStateException("hub_v2.scenario/SCN_FAILURE_4 already set"); - } else { - filled.set(73); - } - - scnFailure4XorModFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioScnSuccess1(final Boolean b) { - if (filled.get(74)) { - throw new IllegalStateException("hub_v2.scenario/SCN_SUCCESS_1 already set"); - } else { - filled.set(74); - } - - scnSuccess1XorMulFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioScnSuccess2(final Boolean b) { - if (filled.get(75)) { - throw new IllegalStateException("hub_v2.scenario/SCN_SUCCESS_2 already set"); - } else { - filled.set(75); - } - - scnSuccess2XorMxpx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioScnSuccess3(final Boolean b) { - if (filled.get(76)) { - throw new IllegalStateException("hub_v2.scenario/SCN_SUCCESS_3 already set"); - } else { - filled.set(76); - } - - scnSuccess3XorMxpFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioScnSuccess4(final Boolean b) { - if (filled.get(77)) { - throw new IllegalStateException("hub_v2.scenario/SCN_SUCCESS_4 already set"); - } else { - filled.set(77); - } - - scnSuccess4XorOobFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioSelfdestruct(final Boolean b) { - if (filled.get(78)) { - throw new IllegalStateException("hub_v2.scenario/SELFDESTRUCT already set"); - } else { - filled.set(78); - } - - selfdestructXorOogx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pScenarioSha2256(final Boolean b) { - if (filled.get(79)) { - throw new IllegalStateException("hub_v2.scenario/SHA2-256 already set"); - } else { - filled.set(79); - } - - sha2256XorOpcx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackAccFlag(final Boolean b) { - if (filled.get(48)) { - throw new IllegalStateException("hub_v2.stack/ACC_FLAG already set"); - } else { - filled.set(48); - } - - deploymentStatusInftyXorUpdateXorCcsrFlagXorBlake2FXorAccFlagXorValCurrChangesXorIsDeployment - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackAddFlag(final Boolean b) { - if (filled.get(49)) { - throw new IllegalStateException("hub_v2.stack/ADD_FLAG already set"); - } else { - filled.set(49); - } - - depStatusXorExpFlagXorCallAbortXorAddFlagXorValCurrIsOrigXorIsEip1559.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackBinFlag(final Boolean b) { - if (filled.get(50)) { - throw new IllegalStateException("hub_v2.stack/BIN_FLAG already set"); - } else { - filled.set(50); - } - - depStatusNewXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValCurrIsZeroXorStatusCode - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackBtcFlag(final Boolean b) { - if (filled.get(51)) { - throw new IllegalStateException("hub_v2.stack/BTC_FLAG already set"); - } else { - filled.set(51); - } - - existsXorMmuInfoXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValNextIsCurrXorTxnRequiresEvmExecution - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackCallFlag(final Boolean b) { - if (filled.get(52)) { - throw new IllegalStateException("hub_v2.stack/CALL_FLAG already set"); - } else { - filled.set(52); - } - - existsNewXorMxpDeploysXorCallPrcFailureCallerWillRevertXorCallFlagXorValNextIsOrig.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackConFlag(final Boolean b) { - if (filled.get(53)) { - throw new IllegalStateException("hub_v2.stack/CON_FLAG already set"); - } else { - filled.set(53); - } - - hasCodeXorMxpFlagXorCallPrcFailureCallerWontRevertXorConFlagXorValNextIsZero.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackCopyFlag(final Boolean b) { - if (filled.get(54)) { - throw new IllegalStateException("hub_v2.stack/COPY_FLAG already set"); - } else { - filled.set(54); - } - - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValOrigIsZero.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackCreateFlag(final Boolean b) { - if (filled.get(55)) { - throw new IllegalStateException("hub_v2.stack/CREATE_FLAG already set"); - } else { - filled.set(55); - } - - isBlake2FXorOobEvent1XorCallPrcSuccessCallerWontRevertXorCreateFlagXorWarm.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackDecodedFlag1(final Boolean b) { - if (filled.get(56)) { - throw new IllegalStateException("hub_v2.stack/DECODED_FLAG_1 already set"); - } else { - filled.set(56); - } - - isEcaddXorOobEvent2XorCallSmcFailureCallerWillRevertXorDecodedFlag1XorWarmNew.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackDecodedFlag2(final Boolean b) { - if (filled.get(57)) { - throw new IllegalStateException("hub_v2.stack/DECODED_FLAG_2 already set"); - } else { - filled.set(57); - } - - isEcmulXorOobFlagXorCallSmcFailureCallerWontRevertXorDecodedFlag2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackDecodedFlag3(final Boolean b) { - if (filled.get(58)) { - throw new IllegalStateException("hub_v2.stack/DECODED_FLAG_3 already set"); - } else { - filled.set(58); - } - - isEcpairingXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecodedFlag3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackDecodedFlag4(final Boolean b) { - if (filled.get(59)) { - throw new IllegalStateException("hub_v2.stack/DECODED_FLAG_4 already set"); - } else { - filled.set(59); - } - - isEcrecoverXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecodedFlag4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackDupFlag(final Boolean b) { - if (filled.get(60)) { - throw new IllegalStateException("hub_v2.stack/DUP_FLAG already set"); - } else { - filled.set(60); - } - - isIdentityXorStpOogxXorCodedepositXorDupFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackExtFlag(final Boolean b) { - if (filled.get(61)) { - throw new IllegalStateException("hub_v2.stack/EXT_FLAG already set"); - } else { - filled.set(61); - } - - isModexpXorStpWarmXorCodedepositInvalidCodePrefixXorExtFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackHaltFlag(final Boolean b) { - if (filled.get(62)) { - throw new IllegalStateException("hub_v2.stack/HALT_FLAG already set"); - } else { - filled.set(62); - } - - isPrecompileXorCodedepositValidCodePrefixXorHaltFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackHashInfoFlag(final Boolean b) { - if (filled.get(63)) { - throw new IllegalStateException("hub_v2.stack/HASH_INFO_FLAG already set"); - } else { - filled.set(63); - } - - isRipemd160XorEcaddXorHashInfoFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackHashInfoKecHi(final Bytes b) { - if (filled.get(98)) { - throw new IllegalStateException("hub_v2.stack/HASH_INFO___KEC_HI already set"); - } else { - filled.set(98); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put((byte) 0); - } - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStackHashInfoKecLo(final Bytes b) { - if (filled.get(99)) { - throw new IllegalStateException("hub_v2.stack/HASH_INFO___KEC_LO already set"); - } else { - filled.set(99); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - (byte) 0); - } - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStackHashInfoSize(final Bytes b) { - if (filled.get(100)) { - throw new IllegalStateException("hub_v2.stack/HASH_INFO___SIZE already set"); - } else { - filled.set(100); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) 0); - } - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackHeight(final Bytes b) { - if (filled.get(101)) { - throw new IllegalStateException("hub_v2.stack/HEIGHT already set"); - } else { - filled.set(101); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo - .put((byte) 0); - } - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStackHeightNew(final Bytes b) { - if (filled.get(102)) { - throw new IllegalStateException("hub_v2.stack/HEIGHT_NEW already set"); - } else { - filled.set(102); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - (byte) 0); - } - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStackHeightOver(final Bytes b) { - if (filled.get(103)) { - throw new IllegalStateException("hub_v2.stack/HEIGHT_OVER already set"); - } else { - filled.set(103); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo - .put((byte) 0); - } - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStackHeightUnder(final Bytes b) { - if (filled.get(104)) { - throw new IllegalStateException("hub_v2.stack/HEIGHT_UNDER already set"); - } else { - filled.set(104); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - (byte) 0); - } - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStackInst(final Bytes b) { - if (filled.get(105)) { - throw new IllegalStateException("hub_v2.stack/INST already set"); - } else { - filled.set(105); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put((byte) 0); - } - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStackInvalidFlag(final Boolean b) { - if (filled.get(64)) { - throw new IllegalStateException("hub_v2.stack/INVALID_FLAG already set"); - } else { - filled.set(64); - } - - isSha2256XorEcmulXorInvalidFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackInvprex(final Boolean b) { - if (filled.get(65)) { - throw new IllegalStateException("hub_v2.stack/INVPREX already set"); - } else { - filled.set(65); - } - - rlpaddrFlagXorEcpairingXorInvprex.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackJumpDestinationVettingRequired(final Boolean b) { - if (filled.get(67)) { - throw new IllegalStateException("hub_v2.stack/JUMP_DESTINATION_VETTING_REQUIRED already set"); - } else { - filled.set(67); - } - - warmXorIdentityXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackJumpFlag(final Boolean b) { - if (filled.get(68)) { - throw new IllegalStateException("hub_v2.stack/JUMP_FLAG already set"); - } else { - filled.set(68); - } - - warmNewXorModexpXorJumpFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackJumpx(final Boolean b) { - if (filled.get(66)) { - throw new IllegalStateException("hub_v2.stack/JUMPX already set"); - } else { - filled.set(66); - } - - trmFlagXorEcrecoverXorJumpx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackKecFlag(final Boolean b) { - if (filled.get(69)) { - throw new IllegalStateException("hub_v2.stack/KEC_FLAG already set"); - } else { - filled.set(69); - } - - ripemd160XorKecFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackLogFlag(final Boolean b) { - if (filled.get(70)) { - throw new IllegalStateException("hub_v2.stack/LOG_FLAG already set"); - } else { - filled.set(70); - } - - scnFailure1XorLogFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackMachineStateFlag(final Boolean b) { - if (filled.get(71)) { - throw new IllegalStateException("hub_v2.stack/MACHINE_STATE_FLAG already set"); - } else { - filled.set(71); - } - - scnFailure2XorMachineStateFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackMaxcsx(final Boolean b) { - if (filled.get(72)) { - throw new IllegalStateException("hub_v2.stack/MAXCSX already set"); - } else { - filled.set(72); - } - - scnFailure3XorMaxcsx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackModFlag(final Boolean b) { - if (filled.get(73)) { - throw new IllegalStateException("hub_v2.stack/MOD_FLAG already set"); - } else { - filled.set(73); - } - - scnFailure4XorModFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackMulFlag(final Boolean b) { - if (filled.get(74)) { - throw new IllegalStateException("hub_v2.stack/MUL_FLAG already set"); - } else { - filled.set(74); - } - - scnSuccess1XorMulFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackMxpFlag(final Boolean b) { - if (filled.get(76)) { - throw new IllegalStateException("hub_v2.stack/MXP_FLAG already set"); - } else { - filled.set(76); - } - - scnSuccess3XorMxpFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackMxpx(final Boolean b) { - if (filled.get(75)) { - throw new IllegalStateException("hub_v2.stack/MXPX already set"); - } else { - filled.set(75); - } - - scnSuccess2XorMxpx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackOobFlag(final Boolean b) { - if (filled.get(77)) { - throw new IllegalStateException("hub_v2.stack/OOB_FLAG already set"); - } else { - filled.set(77); - } - - scnSuccess4XorOobFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackOogx(final Boolean b) { - if (filled.get(78)) { - throw new IllegalStateException("hub_v2.stack/OOGX already set"); - } else { - filled.set(78); - } - - selfdestructXorOogx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackOpcx(final Boolean b) { - if (filled.get(79)) { - throw new IllegalStateException("hub_v2.stack/OPCX already set"); - } else { - filled.set(79); - } - - sha2256XorOpcx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackPushValueHi(final Bytes b) { - if (filled.get(106)) { - throw new IllegalStateException("hub_v2.stack/PUSH_VALUE_HI already set"); - } else { - filled.set(106); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - (byte) 0); - } - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStackPushValueLo(final Bytes b) { - if (filled.get(107)) { - throw new IllegalStateException("hub_v2.stack/PUSH_VALUE_LO already set"); - } else { - filled.set(107); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put((byte) 0); - } - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackPushpopFlag(final Boolean b) { - if (filled.get(80)) { - throw new IllegalStateException("hub_v2.stack/PUSHPOP_FLAG already set"); - } else { - filled.set(80); - } - - pushpopFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackRdcx(final Boolean b) { - if (filled.get(81)) { - throw new IllegalStateException("hub_v2.stack/RDCX already set"); - } else { - filled.set(81); - } - - rdcx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackShfFlag(final Boolean b) { - if (filled.get(82)) { - throw new IllegalStateException("hub_v2.stack/SHF_FLAG already set"); - } else { - filled.set(82); - } - - shfFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackSox(final Boolean b) { - if (filled.get(83)) { - throw new IllegalStateException("hub_v2.stack/SOX already set"); - } else { - filled.set(83); - } - - sox.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackSstorex(final Boolean b) { - if (filled.get(84)) { - throw new IllegalStateException("hub_v2.stack/SSTOREX already set"); - } else { - filled.set(84); - } - - sstorex.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackStackItemHeight1(final Bytes b) { - if (filled.get(108)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_HEIGHT_1 already set"); - } else { - filled.set(108); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put((byte) 0); - } - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemHeight2(final Bytes b) { - if (filled.get(109)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_HEIGHT_2 already set"); - } else { - filled.set(109); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.put((byte) 0); - } - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemHeight3(final Bytes b) { - if (filled.get(110)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_HEIGHT_3 already set"); - } else { - filled.set(110); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.put((byte) 0); - } - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemHeight4(final Bytes b) { - if (filled.get(111)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_HEIGHT_4 already set"); - } else { - filled.set(111); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.put((byte) 0); - } - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemPop1(final Boolean b) { - if (filled.get(86)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_POP_1 already set"); - } else { - filled.set(86); - } - - stackItemPop1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackStackItemPop2(final Boolean b) { - if (filled.get(87)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_POP_2 already set"); - } else { - filled.set(87); - } - - stackItemPop2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackStackItemPop3(final Boolean b) { - if (filled.get(88)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_POP_3 already set"); - } else { - filled.set(88); - } - - stackItemPop3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackStackItemPop4(final Boolean b) { - if (filled.get(89)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_POP_4 already set"); - } else { - filled.set(89); - } - - stackItemPop4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackStackItemStamp1(final Bytes b) { - if (filled.get(112)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_STAMP_1 already set"); - } else { - filled.set(112); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.put((byte) 0); - } - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemStamp2(final Bytes b) { - if (filled.get(113)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_STAMP_2 already set"); - } else { - filled.set(113); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.put((byte) 0); - } - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemStamp3(final Bytes b) { - if (filled.get(114)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_STAMP_3 already set"); - } else { - filled.set(114); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo.put( - (byte) 0); - } - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemStamp4(final Bytes b) { - if (filled.get(115)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_STAMP_4 already set"); - } else { - filled.set(115); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.put((byte) 0); - } - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemValueHi1(final Bytes b) { - if (filled.get(116)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_VALUE_HI_1 already set"); - } else { - filled.set(116); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1.put((byte) 0); - } - rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemValueHi2(final Bytes b) { - if (filled.get(117)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_VALUE_HI_2 already set"); - } else { - filled.set(117); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2.put((byte) 0); - } - rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemValueHi3(final Bytes b) { - if (filled.get(118)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_VALUE_HI_3 already set"); - } else { - filled.set(118); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3.put((byte) 0); - } - rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemValueHi4(final Bytes b) { - if (filled.get(119)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_VALUE_HI_4 already set"); - } else { - filled.set(119); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4.put((byte) 0); - } - rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemValueLo1(final Bytes b) { - if (filled.get(120)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_VALUE_LO_1 already set"); - } else { - filled.set(120); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - trmRawAddrHiXorMxpSize1HiXorStackItemValueLo1.put((byte) 0); - } - trmRawAddrHiXorMxpSize1HiXorStackItemValueLo1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemValueLo2(final Bytes b) { - if (filled.get(121)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_VALUE_LO_2 already set"); - } else { - filled.set(121); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mxpSize1LoXorStackItemValueLo2.put((byte) 0); - } - mxpSize1LoXorStackItemValueLo2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemValueLo3(final Bytes b) { - if (filled.get(122)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_VALUE_LO_3 already set"); - } else { - filled.set(122); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mxpSize2HiXorStackItemValueLo3.put((byte) 0); - } - mxpSize2HiXorStackItemValueLo3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackItemValueLo4(final Bytes b) { - if (filled.get(123)) { - throw new IllegalStateException("hub_v2.stack/STACK_ITEM_VALUE_LO_4 already set"); - } else { - filled.set(123); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mxpSize2LoXorStackItemValueLo4.put((byte) 0); - } - mxpSize2LoXorStackItemValueLo4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStackramFlag(final Boolean b) { - if (filled.get(85)) { - throw new IllegalStateException("hub_v2.stack/STACKRAM_FLAG already set"); - } else { - filled.set(85); - } - - stackramFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackStaticFlag(final Boolean b) { - if (filled.get(91)) { - throw new IllegalStateException("hub_v2.stack/STATIC_FLAG already set"); - } else { - filled.set(91); - } - - staticFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackStaticGas(final Bytes b) { - if (filled.get(124)) { - throw new IllegalStateException("hub_v2.stack/STATIC_GAS already set"); - } else { - filled.set(124); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mxpWordsXorStaticGas.put((byte) 0); - } - mxpWordsXorStaticGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStackStaticx(final Boolean b) { - if (filled.get(90)) { - throw new IllegalStateException("hub_v2.stack/STATICX already set"); - } else { - filled.set(90); - } - - staticx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackStoFlag(final Boolean b) { - if (filled.get(92)) { - throw new IllegalStateException("hub_v2.stack/STO_FLAG already set"); - } else { - filled.set(92); - } - - stoFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackSux(final Boolean b) { - if (filled.get(93)) { - throw new IllegalStateException("hub_v2.stack/SUX already set"); - } else { - filled.set(93); - } - - sux.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackSwapFlag(final Boolean b) { - if (filled.get(94)) { - throw new IllegalStateException("hub_v2.stack/SWAP_FLAG already set"); - } else { - filled.set(94); - } - - swapFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackTrmFlag(final Boolean b) { - if (filled.get(95)) { - throw new IllegalStateException("hub_v2.stack/TRM_FLAG already set"); - } else { - filled.set(95); - } - - trmFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackTxnFlag(final Boolean b) { - if (filled.get(96)) { - throw new IllegalStateException("hub_v2.stack/TXN_FLAG already set"); - } else { - filled.set(96); - } - - txnFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStackWcpFlag(final Boolean b) { - if (filled.get(97)) { - throw new IllegalStateException("hub_v2.stack/WCP_FLAG already set"); - } else { - filled.set(97); - } - - wcpFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStorageAddressHi(final Bytes b) { - if (filled.get(98)) { - throw new IllegalStateException("hub_v2.storage/ADDRESS_HI already set"); - } else { - filled.set(98); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put((byte) 0); - } - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStorageAddressLo(final Bytes b) { - if (filled.get(99)) { - throw new IllegalStateException("hub_v2.storage/ADDRESS_LO already set"); - } else { - filled.set(99); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - (byte) 0); - } - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStorageDeploymentNumber(final Bytes b) { - if (filled.get(100)) { - throw new IllegalStateException("hub_v2.storage/DEPLOYMENT_NUMBER already set"); - } else { - filled.set(100); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) 0); - } - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStorageStorageKeyHi(final Bytes b) { - if (filled.get(101)) { - throw new IllegalStateException("hub_v2.storage/STORAGE_KEY_HI already set"); - } else { - filled.set(101); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo - .put((byte) 0); - } - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStorageStorageKeyLo(final Bytes b) { - if (filled.get(102)) { - throw new IllegalStateException("hub_v2.storage/STORAGE_KEY_LO already set"); - } else { - filled.set(102); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - (byte) 0); - } - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStorageValCurrChanges(final Boolean b) { - if (filled.get(48)) { - throw new IllegalStateException("hub_v2.storage/VAL_CURR_CHANGES already set"); - } else { - filled.set(48); - } - - deploymentStatusInftyXorUpdateXorCcsrFlagXorBlake2FXorAccFlagXorValCurrChangesXorIsDeployment - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStorageValCurrHi(final Bytes b) { - if (filled.get(103)) { - throw new IllegalStateException("hub_v2.storage/VAL_CURR_HI already set"); - } else { - filled.set(103); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo - .put((byte) 0); - } - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStorageValCurrIsOrig(final Boolean b) { - if (filled.get(49)) { - throw new IllegalStateException("hub_v2.storage/VAL_CURR_IS_ORIG already set"); - } else { - filled.set(49); - } - - depStatusXorExpFlagXorCallAbortXorAddFlagXorValCurrIsOrigXorIsEip1559.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStorageValCurrIsZero(final Boolean b) { - if (filled.get(50)) { - throw new IllegalStateException("hub_v2.storage/VAL_CURR_IS_ZERO already set"); - } else { - filled.set(50); - } - - depStatusNewXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValCurrIsZeroXorStatusCode - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStorageValCurrLo(final Bytes b) { - if (filled.get(104)) { - throw new IllegalStateException("hub_v2.storage/VAL_CURR_LO already set"); - } else { - filled.set(104); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - (byte) 0); - } - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStorageValNextHi(final Bytes b) { - if (filled.get(105)) { - throw new IllegalStateException("hub_v2.storage/VAL_NEXT_HI already set"); - } else { - filled.set(105); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put((byte) 0); - } - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStorageValNextIsCurr(final Boolean b) { - if (filled.get(51)) { - throw new IllegalStateException("hub_v2.storage/VAL_NEXT_IS_CURR already set"); - } else { - filled.set(51); - } - - existsXorMmuInfoXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValNextIsCurrXorTxnRequiresEvmExecution - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStorageValNextIsOrig(final Boolean b) { - if (filled.get(52)) { - throw new IllegalStateException("hub_v2.storage/VAL_NEXT_IS_ORIG already set"); - } else { - filled.set(52); - } - - existsNewXorMxpDeploysXorCallPrcFailureCallerWillRevertXorCallFlagXorValNextIsOrig.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStorageValNextIsZero(final Boolean b) { - if (filled.get(53)) { - throw new IllegalStateException("hub_v2.storage/VAL_NEXT_IS_ZERO already set"); - } else { - filled.set(53); - } - - hasCodeXorMxpFlagXorCallPrcFailureCallerWontRevertXorConFlagXorValNextIsZero.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStorageValNextLo(final Bytes b) { - if (filled.get(106)) { - throw new IllegalStateException("hub_v2.storage/VAL_NEXT_LO already set"); - } else { - filled.set(106); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - (byte) 0); - } - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStorageValOrigHi(final Bytes b) { - if (filled.get(107)) { - throw new IllegalStateException("hub_v2.storage/VAL_ORIG_HI already set"); - } else { - filled.set(107); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put((byte) 0); - } - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStorageValOrigIsZero(final Boolean b) { - if (filled.get(54)) { - throw new IllegalStateException("hub_v2.storage/VAL_ORIG_IS_ZERO already set"); - } else { - filled.set(54); - } - - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValOrigIsZero.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStorageValOrigLo(final Bytes b) { - if (filled.get(108)) { - throw new IllegalStateException("hub_v2.storage/VAL_ORIG_LO already set"); - } else { - filled.set(108); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put((byte) 0); - } - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pStorageWarm(final Boolean b) { - if (filled.get(55)) { - throw new IllegalStateException("hub_v2.storage/WARM already set"); - } else { - filled.set(55); - } - - isBlake2FXorOobEvent1XorCallPrcSuccessCallerWontRevertXorCreateFlagXorWarm.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pStorageWarmNew(final Boolean b) { - if (filled.get(56)) { - throw new IllegalStateException("hub_v2.storage/WARM_NEW already set"); - } else { - filled.set(56); - } - - isEcaddXorOobEvent2XorCallSmcFailureCallerWillRevertXorDecodedFlag1XorWarmNew.put( - (byte) (b ? 1 : 0)); - - return this; - } - - public Trace pTransactionBasefee(final Bytes b) { - if (filled.get(98)) { - throw new IllegalStateException("hub_v2.transaction/BASEFEE already set"); - } else { - filled.set(98); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put((byte) 0); - } - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionCallDataSize(final Bytes b) { - if (filled.get(99)) { - throw new IllegalStateException("hub_v2.transaction/CALL_DATA_SIZE already set"); - } else { - filled.set(99); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - (byte) 0); - } - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionCoinbaseAddressHi(final Bytes b) { - if (filled.get(100)) { - throw new IllegalStateException("hub_v2.transaction/COINBASE_ADDRESS_HI already set"); - } else { - filled.set(100); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) 0); - } - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionCoinbaseAddressLo(final Bytes b) { - if (filled.get(101)) { - throw new IllegalStateException("hub_v2.transaction/COINBASE_ADDRESS_LO already set"); - } else { - filled.set(101); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo - .put((byte) 0); - } - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionFromAddressHi(final Bytes b) { - if (filled.get(102)) { - throw new IllegalStateException("hub_v2.transaction/FROM_ADDRESS_HI already set"); - } else { - filled.set(102); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - (byte) 0); - } - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionFromAddressLo(final Bytes b) { - if (filled.get(103)) { - throw new IllegalStateException("hub_v2.transaction/FROM_ADDRESS_LO already set"); - } else { - filled.set(103); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo - .put((byte) 0); - } - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionGasLimit(final Bytes b) { - if (filled.get(104)) { - throw new IllegalStateException("hub_v2.transaction/GAS_LIMIT already set"); - } else { - filled.set(104); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - (byte) 0); - } - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionGasPrice(final Bytes b) { - if (filled.get(105)) { - throw new IllegalStateException("hub_v2.transaction/GAS_PRICE already set"); - } else { - filled.set(105); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put((byte) 0); - } - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionGasRefundAmount(final Bytes b) { - if (filled.get(106)) { - throw new IllegalStateException("hub_v2.transaction/GAS_REFUND_AMOUNT already set"); - } else { - filled.set(106); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - (byte) 0); - } - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionGasRefundCounterFinal(final Bytes b) { - if (filled.get(107)) { - throw new IllegalStateException("hub_v2.transaction/GAS_REFUND_COUNTER_FINAL already set"); - } else { - filled.set(107); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put((byte) 0); - } - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionInitCodeSize(final Bytes b) { - if (filled.get(109)) { - throw new IllegalStateException("hub_v2.transaction/INIT_CODE_SIZE already set"); - } else { - filled.set(109); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.put((byte) 0); - } - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionInitGas(final Bytes b) { - if (filled.get(110)) { - throw new IllegalStateException("hub_v2.transaction/INIT_GAS already set"); - } else { - filled.set(110); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.put((byte) 0); - } - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionInitialBalance(final Bytes b) { - if (filled.get(108)) { - throw new IllegalStateException("hub_v2.transaction/INITIAL_BALANCE already set"); - } else { - filled.set(108); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put((byte) 0); - } - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionIsDeployment(final Boolean b) { - if (filled.get(48)) { - throw new IllegalStateException("hub_v2.transaction/IS_DEPLOYMENT already set"); - } else { - filled.set(48); - } - - deploymentStatusInftyXorUpdateXorCcsrFlagXorBlake2FXorAccFlagXorValCurrChangesXorIsDeployment - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pTransactionIsEip1559(final Boolean b) { - if (filled.get(49)) { - throw new IllegalStateException("hub_v2.transaction/IS_EIP1559 already set"); - } else { - filled.set(49); - } - - depStatusXorExpFlagXorCallAbortXorAddFlagXorValCurrIsOrigXorIsEip1559.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pTransactionLeftoverGas(final Bytes b) { - if (filled.get(111)) { - throw new IllegalStateException("hub_v2.transaction/LEFTOVER_GAS already set"); - } else { - filled.set(111); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.put((byte) 0); - } - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionNonce(final Bytes b) { - if (filled.get(112)) { - throw new IllegalStateException("hub_v2.transaction/NONCE already set"); - } else { - filled.set(112); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.put((byte) 0); - } - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionStatusCode(final Boolean b) { - if (filled.get(50)) { - throw new IllegalStateException("hub_v2.transaction/STATUS_CODE already set"); - } else { - filled.set(50); - } - - depStatusNewXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValCurrIsZeroXorStatusCode - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pTransactionToAddressHi(final Bytes b) { - if (filled.get(113)) { - throw new IllegalStateException("hub_v2.transaction/TO_ADDRESS_HI already set"); - } else { - filled.set(113); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.put((byte) 0); - } - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionToAddressLo(final Bytes b) { - if (filled.get(114)) { - throw new IllegalStateException("hub_v2.transaction/TO_ADDRESS_LO already set"); - } else { - filled.set(114); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo.put( - (byte) 0); - } - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pTransactionTxnRequiresEvmExecution(final Boolean b) { - if (filled.get(51)) { - throw new IllegalStateException("hub_v2.transaction/TXN_REQUIRES_EVM_EXECUTION already set"); - } else { - filled.set(51); - } - - existsXorMmuInfoXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValNextIsCurrXorTxnRequiresEvmExecution - .put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pTransactionValue(final Bytes b) { - if (filled.get(115)) { - throw new IllegalStateException("hub_v2.transaction/VALUE already set"); - } else { - filled.set(115); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.put((byte) 0); - } - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.put(b.toArrayUnsafe()); - - return this; - } - - public Trace peekAtAccount(final Boolean b) { - if (filled.get(31)) { - throw new IllegalStateException("hub_v2.PEEK_AT_ACCOUNT already set"); - } else { - filled.set(31); - } - - peekAtAccount.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace peekAtContext(final Boolean b) { - if (filled.get(32)) { - throw new IllegalStateException("hub_v2.PEEK_AT_CONTEXT already set"); - } else { - filled.set(32); - } - - peekAtContext.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace peekAtMiscellaneous(final Boolean b) { - if (filled.get(33)) { - throw new IllegalStateException("hub_v2.PEEK_AT_MISCELLANEOUS already set"); - } else { - filled.set(33); - } - - peekAtMiscellaneous.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace peekAtScenario(final Boolean b) { - if (filled.get(34)) { - throw new IllegalStateException("hub_v2.PEEK_AT_SCENARIO already set"); - } else { - filled.set(34); - } - - peekAtScenario.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace peekAtStack(final Boolean b) { - if (filled.get(35)) { - throw new IllegalStateException("hub_v2.PEEK_AT_STACK already set"); - } else { - filled.set(35); - } - - peekAtStack.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace peekAtStorage(final Boolean b) { - if (filled.get(36)) { - throw new IllegalStateException("hub_v2.PEEK_AT_STORAGE already set"); - } else { - filled.set(36); - } - - peekAtStorage.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace peekAtTransaction(final Boolean b) { - if (filled.get(37)) { - throw new IllegalStateException("hub_v2.PEEK_AT_TRANSACTION already set"); - } else { - filled.set(37); - } - - peekAtTransaction.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace programCounter(final Bytes b) { - if (filled.get(38)) { - throw new IllegalStateException("hub_v2.PROGRAM_COUNTER already set"); - } else { - filled.set(38); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - programCounter.put((byte) 0); - } - programCounter.put(b.toArrayUnsafe()); - - return this; - } - - public Trace programCounterNew(final Bytes b) { - if (filled.get(39)) { - throw new IllegalStateException("hub_v2.PROGRAM_COUNTER_NEW already set"); - } else { - filled.set(39); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - programCounterNew.put((byte) 0); - } - programCounterNew.put(b.toArrayUnsafe()); - - return this; - } - - public Trace subStamp(final Bytes b) { - if (filled.get(40)) { - throw new IllegalStateException("hub_v2.SUB_STAMP already set"); - } else { - filled.set(40); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - subStamp.put((byte) 0); - } - subStamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace transactionReverts(final Boolean b) { - if (filled.get(41)) { - throw new IllegalStateException("hub_v2.TRANSACTION_REVERTS already set"); - } else { - filled.set(41); - } - - transactionReverts.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace twoLineInstruction(final Boolean b) { - if (filled.get(42)) { - throw new IllegalStateException("hub_v2.TWO_LINE_INSTRUCTION already set"); - } else { - filled.set(42); - } - - twoLineInstruction.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace txExec(final Boolean b) { - if (filled.get(43)) { - throw new IllegalStateException("hub_v2.TX_EXEC already set"); - } else { - filled.set(43); - } - - txExec.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace txFinl(final Boolean b) { - if (filled.get(44)) { - throw new IllegalStateException("hub_v2.TX_FINL already set"); - } else { - filled.set(44); - } - - txFinl.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace txInit(final Boolean b) { - if (filled.get(45)) { - throw new IllegalStateException("hub_v2.TX_INIT already set"); - } else { - filled.set(45); - } - - txInit.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace txSkip(final Boolean b) { - if (filled.get(46)) { - throw new IllegalStateException("hub_v2.TX_SKIP already set"); - } else { - filled.set(46); - } - - txSkip.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace txWarm(final Boolean b) { - if (filled.get(47)) { - throw new IllegalStateException("hub_v2.TX_WARM already set"); - } else { - filled.set(47); - } - - txWarm.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("hub_v2.ABSOLUTE_TRANSACTION_NUMBER has not been filled"); - } - - if (!filled.get(98)) { - throw new IllegalStateException( - "hub_v2.ADDR_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_HASH_INFO___KEC_HI_xor_ADDRESS_HI_xor_BASEFEE has not been filled"); - } - - if (!filled.get(99)) { - throw new IllegalStateException( - "hub_v2.ADDR_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP___DYNCOST_xor_HASH_INFO___KEC_LO_xor_ADDRESS_LO_xor_CALL_DATA_SIZE has not been filled"); - } - - if (!filled.get(101)) { - throw new IllegalStateException( - "hub_v2.BALANCE_NEW_xor_BYTE_CODE_ADDRESS_HI_xor_EXP___EXPONENT_LO_xor_HEIGHT_xor_STORAGE_KEY_HI_xor_COINBASE_ADDRESS_LO has not been filled"); - } - - if (!filled.get(100)) { - throw new IllegalStateException( - "hub_v2.BALANCE_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP___EXPONENT_HI_xor_HASH_INFO___SIZE_xor_DEPLOYMENT_NUMBER_xor_COINBASE_ADDRESS_HI has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("hub_v2.BATCH_NUMBER has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("hub_v2.CALLER_CONTEXT_NUMBER has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("hub_v2.CODE_ADDRESS_HI has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("hub_v2.CODE_ADDRESS_LO has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("hub_v2.CODE_DEPLOYMENT_NUMBER has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("hub_v2.CODE_DEPLOYMENT_STATUS has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("hub_v2.CODE_FRAGMENT_INDEX has not been filled"); - } - - if (!filled.get(103)) { - throw new IllegalStateException( - "hub_v2.CODE_HASH_HI_NEW_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU___INST_xor_HEIGHT_OVER_xor_VAL_CURR_HI_xor_FROM_ADDRESS_LO has not been filled"); - } - - if (!filled.get(102)) { - throw new IllegalStateException( - "hub_v2.CODE_HASH_HI_xor_BYTE_CODE_ADDRESS_LO_xor_MMU___EXO_SUM_xor_HEIGHT_NEW_xor_STORAGE_KEY_LO_xor_FROM_ADDRESS_HI has not been filled"); - } - - if (!filled.get(105)) { - throw new IllegalStateException( - "hub_v2.CODE_HASH_LO_NEW_xor_CALLER_ADDRESS_HI_xor_MMU___OFFSET_2_HI_xor_INST_xor_VAL_NEXT_HI_xor_GAS_PRICE has not been filled"); - } - - if (!filled.get(104)) { - throw new IllegalStateException( - "hub_v2.CODE_HASH_LO_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU___OFFSET_1_LO_xor_HEIGHT_UNDER_xor_VAL_CURR_LO_xor_GAS_LIMIT has not been filled"); - } - - if (!filled.get(107)) { - throw new IllegalStateException( - "hub_v2.CODE_SIZE_NEW_xor_CALLER_CONTEXT_NUMBER_xor_MMU___PARAM_1_xor_PUSH_VALUE_LO_xor_VAL_ORIG_HI_xor_GAS_REFUND_COUNTER_FINAL has not been filled"); - } - - if (!filled.get(106)) { - throw new IllegalStateException( - "hub_v2.CODE_SIZE_xor_CALLER_ADDRESS_LO_xor_MMU___OFFSET_2_LO_xor_PUSH_VALUE_HI_xor_VAL_NEXT_LO_xor_GAS_REFUND_AMOUNT has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("hub_v2.CONTEXT_GETS_REVERTED_FLAG has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("hub_v2.CONTEXT_MAY_CHANGE_FLAG has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("hub_v2.CONTEXT_NUMBER has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("hub_v2.CONTEXT_NUMBER_NEW has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("hub_v2.CONTEXT_REVERT_STAMP has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("hub_v2.CONTEXT_SELF_REVERTS_FLAG has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("hub_v2.CONTEXT_WILL_REVERT_FLAG has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("hub_v2.COUNTER_NSR has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("hub_v2.COUNTER_TLI has not been filled"); - } - - if (!filled.get(110)) { - throw new IllegalStateException( - "hub_v2.DEP_NUM_NEW_xor_CALL_STACK_DEPTH_xor_MMU___REF_SIZE_xor_STACK_ITEM_HEIGHT_3_xor_INIT_GAS has not been filled"); - } - - if (!filled.get(109)) { - throw new IllegalStateException( - "hub_v2.DEP_NUM_xor_CALL_DATA_SIZE_xor_MMU___REF_OFFSET_xor_STACK_ITEM_HEIGHT_2_xor_INIT_CODE_SIZE has not been filled"); - } - - if (!filled.get(50)) { - throw new IllegalStateException( - "hub_v2.DEP_STATUS_NEW_xor_MMU___FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_VAL_CURR_IS_ZERO_xor_STATUS_CODE has not been filled"); - } - - if (!filled.get(49)) { - throw new IllegalStateException( - "hub_v2.DEP_STATUS_xor_EXP___FLAG_xor_CALL_ABORT_xor_ADD_FLAG_xor_VAL_CURR_IS_ORIG_xor_IS_EIP1559 has not been filled"); - } - - if (!filled.get(108)) { - throw new IllegalStateException( - "hub_v2.DEPLOYMENT_NUMBER_INFTY_xor_CALL_DATA_OFFSET_xor_MMU___PARAM_2_xor_STACK_ITEM_HEIGHT_1_xor_VAL_ORIG_LO_xor_INITIAL_BALANCE has not been filled"); - } - - if (!filled.get(48)) { - throw new IllegalStateException( - "hub_v2.DEPLOYMENT_STATUS_INFTY_xor_UPDATE_xor_CCSR_FLAG_xor_BLAKE2f_xor_ACC_FLAG_xor_VAL_CURR_CHANGES_xor_IS_DEPLOYMENT has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("hub_v2.DOM_STAMP has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("hub_v2.EXCEPTION_AHOY_FLAG has not been filled"); - } - - if (!filled.get(52)) { - throw new IllegalStateException( - "hub_v2.EXISTS_NEW_xor_MXP___DEPLOYS_xor_CALL_PRC_FAILURE_CALLER_WILL_REVERT_xor_CALL_FLAG_xor_VAL_NEXT_IS_ORIG has not been filled"); - } - - if (!filled.get(51)) { - throw new IllegalStateException( - "hub_v2.EXISTS_xor_MMU___INFO_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BTC_FLAG_xor_VAL_NEXT_IS_CURR_xor_TXN_REQUIRES_EVM_EXECUTION has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("hub_v2.GAS_ACTUAL has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("hub_v2.GAS_COST has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("hub_v2.GAS_EXPECTED has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("hub_v2.GAS_NEXT has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("hub_v2.GAS_REFUND has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("hub_v2.GAS_REFUND_NEW has not been filled"); - } - - if (!filled.get(54)) { - throw new IllegalStateException( - "hub_v2.HAS_CODE_NEW_xor_MXP___MXPX_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_VAL_ORIG_IS_ZERO has not been filled"); - } - - if (!filled.get(53)) { - throw new IllegalStateException( - "hub_v2.HAS_CODE_xor_MXP___FLAG_xor_CALL_PRC_FAILURE_CALLER_WONT_REVERT_xor_CON_FLAG_xor_VAL_NEXT_IS_ZERO has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("hub_v2.HASH_INFO_STAMP has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("hub_v2.HUB_STAMP has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("hub_v2.HUB_STAMP_TRANSACTION_END has not been filled"); - } - - if (!filled.get(55)) { - throw new IllegalStateException( - "hub_v2.IS_BLAKE2f_xor_OOB___EVENT_1_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_WARM has not been filled"); - } - - if (!filled.get(56)) { - throw new IllegalStateException( - "hub_v2.IS_ECADD_xor_OOB___EVENT_2_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DECODED_FLAG_1_xor_WARM_NEW has not been filled"); - } - - if (!filled.get(57)) { - throw new IllegalStateException( - "hub_v2.IS_ECMUL_xor_OOB___FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DECODED_FLAG_2 has not been filled"); - } - - if (!filled.get(58)) { - throw new IllegalStateException( - "hub_v2.IS_ECPAIRING_xor_STP___EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DECODED_FLAG_3 has not been filled"); - } - - if (!filled.get(59)) { - throw new IllegalStateException( - "hub_v2.IS_ECRECOVER_xor_STP___FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DECODED_FLAG_4 has not been filled"); - } - - if (!filled.get(60)) { - throw new IllegalStateException( - "hub_v2.IS_IDENTITY_xor_STP___OOGX_xor_CODEDEPOSIT_xor_DUP_FLAG has not been filled"); - } - - if (!filled.get(61)) { - throw new IllegalStateException( - "hub_v2.IS_MODEXP_xor_STP___WARM_xor_CODEDEPOSIT_INVALID_CODE_PREFIX_xor_EXT_FLAG has not been filled"); - } - - if (!filled.get(62)) { - throw new IllegalStateException( - "hub_v2.IS_PRECOMPILE_xor_CODEDEPOSIT_VALID_CODE_PREFIX_xor_HALT_FLAG has not been filled"); - } - - if (!filled.get(63)) { - throw new IllegalStateException( - "hub_v2.IS_RIPEMD-160_xor_ECADD_xor_HASH_INFO_FLAG has not been filled"); - } - - if (!filled.get(64)) { - throw new IllegalStateException( - "hub_v2.IS_SHA2-256_xor_ECMUL_xor_INVALID_FLAG has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("hub_v2.MMU_STAMP has not been filled"); - } - - if (!filled.get(121)) { - throw new IllegalStateException( - "hub_v2.MXP___SIZE_1_LO_xor_STACK_ITEM_VALUE_LO_2 has not been filled"); - } - - if (!filled.get(122)) { - throw new IllegalStateException( - "hub_v2.MXP___SIZE_2_HI_xor_STACK_ITEM_VALUE_LO_3 has not been filled"); - } - - if (!filled.get(123)) { - throw new IllegalStateException( - "hub_v2.MXP___SIZE_2_LO_xor_STACK_ITEM_VALUE_LO_4 has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("hub_v2.MXP_STAMP has not been filled"); - } - - if (!filled.get(124)) { - throw new IllegalStateException("hub_v2.MXP___WORDS_xor_STATIC_GAS has not been filled"); - } - - if (!filled.get(112)) { - throw new IllegalStateException( - "hub_v2.NONCE_NEW_xor_CONTEXT_NUMBER_xor_MMU___STACK_VAL_HI_xor_STACK_ITEM_STAMP_1_xor_NONCE has not been filled"); - } - - if (!filled.get(111)) { - throw new IllegalStateException( - "hub_v2.NONCE_xor_CALL_VALUE_xor_MMU___SIZE_xor_STACK_ITEM_HEIGHT_4_xor_LEFTOVER_GAS has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("hub_v2.NUMBER_OF_NON_STACK_ROWS has not been filled"); - } - - if (!filled.get(125)) { - throw new IllegalStateException("hub_v2.OOB___INST has not been filled"); - } - - if (!filled.get(126)) { - throw new IllegalStateException("hub_v2.OOB___OUTGOING_DATA_1 has not been filled"); - } - - if (!filled.get(127)) { - throw new IllegalStateException("hub_v2.OOB___OUTGOING_DATA_2 has not been filled"); - } - - if (!filled.get(128)) { - throw new IllegalStateException("hub_v2.OOB___OUTGOING_DATA_3 has not been filled"); - } - - if (!filled.get(129)) { - throw new IllegalStateException("hub_v2.OOB___OUTGOING_DATA_4 has not been filled"); - } - - if (!filled.get(130)) { - throw new IllegalStateException("hub_v2.OOB___OUTGOING_DATA_5 has not been filled"); - } - - if (!filled.get(131)) { - throw new IllegalStateException("hub_v2.OOB___OUTGOING_DATA_6 has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("hub_v2.PEEK_AT_ACCOUNT has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("hub_v2.PEEK_AT_CONTEXT has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("hub_v2.PEEK_AT_MISCELLANEOUS has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("hub_v2.PEEK_AT_SCENARIO has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("hub_v2.PEEK_AT_STACK has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("hub_v2.PEEK_AT_STORAGE has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("hub_v2.PEEK_AT_TRANSACTION has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("hub_v2.PROGRAM_COUNTER has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("hub_v2.PROGRAM_COUNTER_NEW has not been filled"); - } - - if (!filled.get(80)) { - throw new IllegalStateException("hub_v2.PUSHPOP_FLAG has not been filled"); - } - - if (!filled.get(81)) { - throw new IllegalStateException("hub_v2.RDCX has not been filled"); - } - - if (!filled.get(69)) { - throw new IllegalStateException("hub_v2.RIPEMD-160_xor_KEC_FLAG has not been filled"); - } - - if (!filled.get(113)) { - throw new IllegalStateException( - "hub_v2.RLPADDR___DEP_ADDR_HI_xor_IS_STATIC_xor_MMU___STACK_VAL_LO_xor_STACK_ITEM_STAMP_2_xor_TO_ADDRESS_HI has not been filled"); - } - - if (!filled.get(114)) { - throw new IllegalStateException( - "hub_v2.RLPADDR___DEP_ADDR_LO_xor_RETURNER_CONTEXT_NUMBER_xor_MXP___GAS_MXP_xor_STACK_ITEM_STAMP_3_xor_TO_ADDRESS_LO has not been filled"); - } - - if (!filled.get(65)) { - throw new IllegalStateException( - "hub_v2.RLPADDR___FLAG_xor_ECPAIRING_xor_INVPREX has not been filled"); - } - - if (!filled.get(115)) { - throw new IllegalStateException( - "hub_v2.RLPADDR___KEC_HI_xor_RETURNER_IS_PRECOMPILE_xor_MXP___INST_xor_STACK_ITEM_STAMP_4_xor_VALUE has not been filled"); - } - - if (!filled.get(116)) { - throw new IllegalStateException( - "hub_v2.RLPADDR___KEC_LO_xor_RETURN_AT_OFFSET_xor_MXP___OFFSET_1_HI_xor_STACK_ITEM_VALUE_HI_1 has not been filled"); - } - - if (!filled.get(117)) { - throw new IllegalStateException( - "hub_v2.RLPADDR___RECIPE_xor_RETURN_AT_SIZE_xor_MXP___OFFSET_1_LO_xor_STACK_ITEM_VALUE_HI_2 has not been filled"); - } - - if (!filled.get(118)) { - throw new IllegalStateException( - "hub_v2.RLPADDR___SALT_HI_xor_RETURN_DATA_OFFSET_xor_MXP___OFFSET_2_HI_xor_STACK_ITEM_VALUE_HI_3 has not been filled"); - } - - if (!filled.get(119)) { - throw new IllegalStateException( - "hub_v2.RLPADDR___SALT_LO_xor_RETURN_DATA_SIZE_xor_MXP___OFFSET_2_LO_xor_STACK_ITEM_VALUE_HI_4 has not been filled"); - } - - if (!filled.get(70)) { - throw new IllegalStateException("hub_v2.SCN_FAILURE_1_xor_LOG_FLAG has not been filled"); - } - - if (!filled.get(71)) { - throw new IllegalStateException( - "hub_v2.SCN_FAILURE_2_xor_MACHINE_STATE_FLAG has not been filled"); - } - - if (!filled.get(72)) { - throw new IllegalStateException("hub_v2.SCN_FAILURE_3_xor_MAXCSX has not been filled"); - } - - if (!filled.get(73)) { - throw new IllegalStateException("hub_v2.SCN_FAILURE_4_xor_MOD_FLAG has not been filled"); - } - - if (!filled.get(74)) { - throw new IllegalStateException("hub_v2.SCN_SUCCESS_1_xor_MUL_FLAG has not been filled"); - } - - if (!filled.get(75)) { - throw new IllegalStateException("hub_v2.SCN_SUCCESS_2_xor_MXPX has not been filled"); - } - - if (!filled.get(76)) { - throw new IllegalStateException("hub_v2.SCN_SUCCESS_3_xor_MXP_FLAG has not been filled"); - } - - if (!filled.get(77)) { - throw new IllegalStateException("hub_v2.SCN_SUCCESS_4_xor_OOB_FLAG has not been filled"); - } - - if (!filled.get(78)) { - throw new IllegalStateException("hub_v2.SELFDESTRUCT_xor_OOGX has not been filled"); - } - - if (!filled.get(79)) { - throw new IllegalStateException("hub_v2.SHA2-256_xor_OPCX has not been filled"); - } - - if (!filled.get(82)) { - throw new IllegalStateException("hub_v2.SHF_FLAG has not been filled"); - } - - if (!filled.get(83)) { - throw new IllegalStateException("hub_v2.SOX has not been filled"); - } - - if (!filled.get(84)) { - throw new IllegalStateException("hub_v2.SSTOREX has not been filled"); - } - - if (!filled.get(86)) { - throw new IllegalStateException("hub_v2.STACK_ITEM_POP_1 has not been filled"); - } - - if (!filled.get(87)) { - throw new IllegalStateException("hub_v2.STACK_ITEM_POP_2 has not been filled"); - } - - if (!filled.get(88)) { - throw new IllegalStateException("hub_v2.STACK_ITEM_POP_3 has not been filled"); - } - - if (!filled.get(89)) { - throw new IllegalStateException("hub_v2.STACK_ITEM_POP_4 has not been filled"); - } - - if (!filled.get(85)) { - throw new IllegalStateException("hub_v2.STACKRAM_FLAG has not been filled"); - } - - if (!filled.get(91)) { - throw new IllegalStateException("hub_v2.STATIC_FLAG has not been filled"); - } - - if (!filled.get(90)) { - throw new IllegalStateException("hub_v2.STATICX has not been filled"); - } - - if (!filled.get(92)) { - throw new IllegalStateException("hub_v2.STO_FLAG has not been filled"); - } - - if (!filled.get(132)) { - throw new IllegalStateException("hub_v2.STP___GAS_HI has not been filled"); - } - - if (!filled.get(133)) { - throw new IllegalStateException("hub_v2.STP___GAS_LO has not been filled"); - } - - if (!filled.get(134)) { - throw new IllegalStateException("hub_v2.STP___GAS_OOPKT has not been filled"); - } - - if (!filled.get(135)) { - throw new IllegalStateException("hub_v2.STP___GAS_STPD has not been filled"); - } - - if (!filled.get(136)) { - throw new IllegalStateException("hub_v2.STP___INST has not been filled"); - } - - if (!filled.get(137)) { - throw new IllegalStateException("hub_v2.STP___VAL_HI has not been filled"); - } - - if (!filled.get(138)) { - throw new IllegalStateException("hub_v2.STP___VAL_LO has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("hub_v2.SUB_STAMP has not been filled"); - } - - if (!filled.get(93)) { - throw new IllegalStateException("hub_v2.SUX has not been filled"); - } - - if (!filled.get(94)) { - throw new IllegalStateException("hub_v2.SWAP_FLAG has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("hub_v2.TRANSACTION_REVERTS has not been filled"); - } - - if (!filled.get(95)) { - throw new IllegalStateException("hub_v2.TRM_FLAG has not been filled"); - } - - if (!filled.get(66)) { - throw new IllegalStateException( - "hub_v2.TRM___FLAG_xor_ECRECOVER_xor_JUMPX has not been filled"); - } - - if (!filled.get(120)) { - throw new IllegalStateException( - "hub_v2.TRM___RAW_ADDR_HI_xor_MXP___SIZE_1_HI_xor_STACK_ITEM_VALUE_LO_1 has not been filled"); - } - - if (!filled.get(42)) { - throw new IllegalStateException("hub_v2.TWO_LINE_INSTRUCTION has not been filled"); - } - - if (!filled.get(43)) { - throw new IllegalStateException("hub_v2.TX_EXEC has not been filled"); - } - - if (!filled.get(44)) { - throw new IllegalStateException("hub_v2.TX_FINL has not been filled"); - } - - if (!filled.get(45)) { - throw new IllegalStateException("hub_v2.TX_INIT has not been filled"); - } - - if (!filled.get(46)) { - throw new IllegalStateException("hub_v2.TX_SKIP has not been filled"); - } - - if (!filled.get(47)) { - throw new IllegalStateException("hub_v2.TX_WARM has not been filled"); - } - - if (!filled.get(96)) { - throw new IllegalStateException("hub_v2.TXN_FLAG has not been filled"); - } - - if (!filled.get(68)) { - throw new IllegalStateException( - "hub_v2.WARM_NEW_xor_MODEXP_xor_JUMP_FLAG has not been filled"); - } - - if (!filled.get(67)) { - throw new IllegalStateException( - "hub_v2.WARM_xor_IDENTITY_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); - } - - if (!filled.get(97)) { - throw new IllegalStateException("hub_v2.WCP_FLAG has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - absoluteTransactionNumber.position(absoluteTransactionNumber.position() + 32); - } - - if (!filled.get(98)) { - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.position( - addrHiXorAccountAddressHiXorCcrsStampXorHashInfoKecHiXorAddressHiXorBasefee.position() - + 32); - } - - if (!filled.get(99)) { - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize.position( - addrLoXorAccountAddressLoXorExpDyncostXorHashInfoKecLoXorAddressLoXorCallDataSize - .position() - + 32); - } - - if (!filled.get(101)) { - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo - .position( - balanceNewXorByteCodeAddressHiXorExpExponentLoXorHeightXorStorageKeyHiXorCoinbaseAddressLo - .position() - + 32); - } - - if (!filled.get(100)) { - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .position( - balanceXorAccountDeploymentNumberXorExpExponentHiXorHashInfoSizeXorDeploymentNumberXorCoinbaseAddressHi - .position() - + 32); - } - - if (!filled.get(1)) { - batchNumber.position(batchNumber.position() + 32); - } - - if (!filled.get(2)) { - callerContextNumber.position(callerContextNumber.position() + 32); - } - - if (!filled.get(3)) { - codeAddressHi.position(codeAddressHi.position() + 32); - } - - if (!filled.get(4)) { - codeAddressLo.position(codeAddressLo.position() + 32); - } - - if (!filled.get(5)) { - codeDeploymentNumber.position(codeDeploymentNumber.position() + 32); - } - - if (!filled.get(6)) { - codeDeploymentStatus.position(codeDeploymentStatus.position() + 1); - } - - if (!filled.get(7)) { - codeFragmentIndex.position(codeFragmentIndex.position() + 32); - } - - if (!filled.get(103)) { - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo - .position( - codeHashHiNewXorByteCodeDeploymentNumberXorMmuInstXorHeightOverXorValCurrHiXorFromAddressLo - .position() - + 32); - } - - if (!filled.get(102)) { - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi - .position( - codeHashHiXorByteCodeAddressLoXorMmuExoSumXorHeightNewXorStorageKeyLoXorFromAddressHi - .position() - + 32); - } - - if (!filled.get(105)) { - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.position( - codeHashLoNewXorCallerAddressHiXorMmuOffset2HiXorInstXorValNextHiXorGasPrice.position() - + 32); - } - - if (!filled.get(104)) { - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit - .position( - codeHashLoXorByteCodeDeploymentStatusXorMmuOffset1LoXorHeightUnderXorValCurrLoXorGasLimit - .position() - + 32); - } - - if (!filled.get(107)) { - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .position( - codeSizeNewXorCallerContextNumberXorMmuParam1XorPushValueLoXorValOrigHiXorGasRefundCounterFinal - .position() - + 32); - } - - if (!filled.get(106)) { - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount - .position( - codeSizeXorCallerAddressLoXorMmuOffset2LoXorPushValueHiXorValNextLoXorGasRefundAmount - .position() - + 32); - } - - if (!filled.get(8)) { - contextGetsRevertedFlag.position(contextGetsRevertedFlag.position() + 1); - } - - if (!filled.get(9)) { - contextMayChangeFlag.position(contextMayChangeFlag.position() + 1); - } - - if (!filled.get(10)) { - contextNumber.position(contextNumber.position() + 32); - } - - if (!filled.get(11)) { - contextNumberNew.position(contextNumberNew.position() + 32); - } - - if (!filled.get(12)) { - contextRevertStamp.position(contextRevertStamp.position() + 32); - } - - if (!filled.get(13)) { - contextSelfRevertsFlag.position(contextSelfRevertsFlag.position() + 1); - } - - if (!filled.get(14)) { - contextWillRevertFlag.position(contextWillRevertFlag.position() + 1); - } - - if (!filled.get(15)) { - counterNsr.position(counterNsr.position() + 32); - } - - if (!filled.get(16)) { - counterTli.position(counterTli.position() + 1); - } - - if (!filled.get(110)) { - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.position( - depNumNewXorCallStackDepthXorMmuRefSizeXorStackItemHeight3XorInitGas.position() + 32); - } - - if (!filled.get(109)) { - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.position( - depNumXorCallDataSizeXorMmuRefOffsetXorStackItemHeight2XorInitCodeSize.position() + 32); - } - - if (!filled.get(50)) { - depStatusNewXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValCurrIsZeroXorStatusCode - .position( - depStatusNewXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValCurrIsZeroXorStatusCode - .position() - + 1); - } - - if (!filled.get(49)) { - depStatusXorExpFlagXorCallAbortXorAddFlagXorValCurrIsOrigXorIsEip1559.position( - depStatusXorExpFlagXorCallAbortXorAddFlagXorValCurrIsOrigXorIsEip1559.position() + 1); - } - - if (!filled.get(108)) { - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .position( - deploymentNumberInftyXorCallDataOffsetXorMmuParam2XorStackItemHeight1XorValOrigLoXorInitialBalance - .position() - + 32); - } - - if (!filled.get(48)) { - deploymentStatusInftyXorUpdateXorCcsrFlagXorBlake2FXorAccFlagXorValCurrChangesXorIsDeployment - .position( - deploymentStatusInftyXorUpdateXorCcsrFlagXorBlake2FXorAccFlagXorValCurrChangesXorIsDeployment - .position() - + 1); - } - - if (!filled.get(17)) { - domStamp.position(domStamp.position() + 32); - } - - if (!filled.get(18)) { - exceptionAhoyFlag.position(exceptionAhoyFlag.position() + 1); - } - - if (!filled.get(52)) { - existsNewXorMxpDeploysXorCallPrcFailureCallerWillRevertXorCallFlagXorValNextIsOrig.position( - existsNewXorMxpDeploysXorCallPrcFailureCallerWillRevertXorCallFlagXorValNextIsOrig - .position() - + 1); - } - - if (!filled.get(51)) { - existsXorMmuInfoXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValNextIsCurrXorTxnRequiresEvmExecution - .position( - existsXorMmuInfoXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValNextIsCurrXorTxnRequiresEvmExecution - .position() - + 1); - } - - if (!filled.get(19)) { - gasActual.position(gasActual.position() + 32); - } - - if (!filled.get(20)) { - gasCost.position(gasCost.position() + 32); - } - - if (!filled.get(21)) { - gasExpected.position(gasExpected.position() + 32); - } - - if (!filled.get(22)) { - gasNext.position(gasNext.position() + 32); - } - - if (!filled.get(23)) { - gasRefund.position(gasRefund.position() + 32); - } - - if (!filled.get(24)) { - gasRefundNew.position(gasRefundNew.position() + 32); - } - - if (!filled.get(54)) { - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValOrigIsZero.position( - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValOrigIsZero - .position() - + 1); - } - - if (!filled.get(53)) { - hasCodeXorMxpFlagXorCallPrcFailureCallerWontRevertXorConFlagXorValNextIsZero.position( - hasCodeXorMxpFlagXorCallPrcFailureCallerWontRevertXorConFlagXorValNextIsZero.position() - + 1); - } - - if (!filled.get(25)) { - hashInfoStamp.position(hashInfoStamp.position() + 32); - } - - if (!filled.get(26)) { - hubStamp.position(hubStamp.position() + 32); - } - - if (!filled.get(27)) { - hubStampTransactionEnd.position(hubStampTransactionEnd.position() + 32); - } - - if (!filled.get(55)) { - isBlake2FXorOobEvent1XorCallPrcSuccessCallerWontRevertXorCreateFlagXorWarm.position( - isBlake2FXorOobEvent1XorCallPrcSuccessCallerWontRevertXorCreateFlagXorWarm.position() - + 1); - } - - if (!filled.get(56)) { - isEcaddXorOobEvent2XorCallSmcFailureCallerWillRevertXorDecodedFlag1XorWarmNew.position( - isEcaddXorOobEvent2XorCallSmcFailureCallerWillRevertXorDecodedFlag1XorWarmNew.position() - + 1); - } - - if (!filled.get(57)) { - isEcmulXorOobFlagXorCallSmcFailureCallerWontRevertXorDecodedFlag2.position( - isEcmulXorOobFlagXorCallSmcFailureCallerWontRevertXorDecodedFlag2.position() + 1); - } - - if (!filled.get(58)) { - isEcpairingXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecodedFlag3.position( - isEcpairingXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecodedFlag3.position() + 1); - } - - if (!filled.get(59)) { - isEcrecoverXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecodedFlag4.position( - isEcrecoverXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecodedFlag4.position() + 1); - } - - if (!filled.get(60)) { - isIdentityXorStpOogxXorCodedepositXorDupFlag.position( - isIdentityXorStpOogxXorCodedepositXorDupFlag.position() + 1); - } - - if (!filled.get(61)) { - isModexpXorStpWarmXorCodedepositInvalidCodePrefixXorExtFlag.position( - isModexpXorStpWarmXorCodedepositInvalidCodePrefixXorExtFlag.position() + 1); - } - - if (!filled.get(62)) { - isPrecompileXorCodedepositValidCodePrefixXorHaltFlag.position( - isPrecompileXorCodedepositValidCodePrefixXorHaltFlag.position() + 1); - } - - if (!filled.get(63)) { - isRipemd160XorEcaddXorHashInfoFlag.position( - isRipemd160XorEcaddXorHashInfoFlag.position() + 1); - } - - if (!filled.get(64)) { - isSha2256XorEcmulXorInvalidFlag.position(isSha2256XorEcmulXorInvalidFlag.position() + 1); - } - - if (!filled.get(28)) { - mmuStamp.position(mmuStamp.position() + 32); - } - - if (!filled.get(121)) { - mxpSize1LoXorStackItemValueLo2.position(mxpSize1LoXorStackItemValueLo2.position() + 32); - } - - if (!filled.get(122)) { - mxpSize2HiXorStackItemValueLo3.position(mxpSize2HiXorStackItemValueLo3.position() + 32); - } - - if (!filled.get(123)) { - mxpSize2LoXorStackItemValueLo4.position(mxpSize2LoXorStackItemValueLo4.position() + 32); - } - - if (!filled.get(29)) { - mxpStamp.position(mxpStamp.position() + 32); - } - - if (!filled.get(124)) { - mxpWordsXorStaticGas.position(mxpWordsXorStaticGas.position() + 32); - } - - if (!filled.get(112)) { - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.position( - nonceNewXorContextNumberXorMmuStackValHiXorStackItemStamp1XorNonce.position() + 32); - } - - if (!filled.get(111)) { - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.position( - nonceXorCallValueXorMmuSizeXorStackItemHeight4XorLeftoverGas.position() + 32); - } - - if (!filled.get(30)) { - numberOfNonStackRows.position(numberOfNonStackRows.position() + 32); - } - - if (!filled.get(125)) { - oobInst.position(oobInst.position() + 32); - } - - if (!filled.get(126)) { - oobOutgoingData1.position(oobOutgoingData1.position() + 32); - } - - if (!filled.get(127)) { - oobOutgoingData2.position(oobOutgoingData2.position() + 32); - } - - if (!filled.get(128)) { - oobOutgoingData3.position(oobOutgoingData3.position() + 32); - } - - if (!filled.get(129)) { - oobOutgoingData4.position(oobOutgoingData4.position() + 32); - } - - if (!filled.get(130)) { - oobOutgoingData5.position(oobOutgoingData5.position() + 32); - } - - if (!filled.get(131)) { - oobOutgoingData6.position(oobOutgoingData6.position() + 32); - } - - if (!filled.get(31)) { - peekAtAccount.position(peekAtAccount.position() + 1); - } - - if (!filled.get(32)) { - peekAtContext.position(peekAtContext.position() + 1); - } - - if (!filled.get(33)) { - peekAtMiscellaneous.position(peekAtMiscellaneous.position() + 1); - } - - if (!filled.get(34)) { - peekAtScenario.position(peekAtScenario.position() + 1); - } - - if (!filled.get(35)) { - peekAtStack.position(peekAtStack.position() + 1); - } - - if (!filled.get(36)) { - peekAtStorage.position(peekAtStorage.position() + 1); - } - - if (!filled.get(37)) { - peekAtTransaction.position(peekAtTransaction.position() + 1); - } - - if (!filled.get(38)) { - programCounter.position(programCounter.position() + 32); - } - - if (!filled.get(39)) { - programCounterNew.position(programCounterNew.position() + 32); - } - - if (!filled.get(80)) { - pushpopFlag.position(pushpopFlag.position() + 1); - } - - if (!filled.get(81)) { - rdcx.position(rdcx.position() + 1); - } - - if (!filled.get(69)) { - ripemd160XorKecFlag.position(ripemd160XorKecFlag.position() + 1); - } - - if (!filled.get(113)) { - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.position( - rlpaddrDepAddrHiXorIsStaticXorMmuStackValLoXorStackItemStamp2XorToAddressHi.position() - + 32); - } - - if (!filled.get(114)) { - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo.position( - rlpaddrDepAddrLoXorReturnerContextNumberXorMxpGasMxpXorStackItemStamp3XorToAddressLo - .position() - + 32); - } - - if (!filled.get(65)) { - rlpaddrFlagXorEcpairingXorInvprex.position(rlpaddrFlagXorEcpairingXorInvprex.position() + 1); - } - - if (!filled.get(115)) { - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.position( - rlpaddrKecHiXorReturnerIsPrecompileXorMxpInstXorStackItemStamp4XorValue.position() + 32); - } - - if (!filled.get(116)) { - rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1.position( - rlpaddrKecLoXorReturnAtOffsetXorMxpOffset1HiXorStackItemValueHi1.position() + 32); - } - - if (!filled.get(117)) { - rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2.position( - rlpaddrRecipeXorReturnAtSizeXorMxpOffset1LoXorStackItemValueHi2.position() + 32); - } - - if (!filled.get(118)) { - rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3.position( - rlpaddrSaltHiXorReturnDataOffsetXorMxpOffset2HiXorStackItemValueHi3.position() + 32); - } - - if (!filled.get(119)) { - rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4.position( - rlpaddrSaltLoXorReturnDataSizeXorMxpOffset2LoXorStackItemValueHi4.position() + 32); - } - - if (!filled.get(70)) { - scnFailure1XorLogFlag.position(scnFailure1XorLogFlag.position() + 1); - } - - if (!filled.get(71)) { - scnFailure2XorMachineStateFlag.position(scnFailure2XorMachineStateFlag.position() + 1); - } - - if (!filled.get(72)) { - scnFailure3XorMaxcsx.position(scnFailure3XorMaxcsx.position() + 1); - } - - if (!filled.get(73)) { - scnFailure4XorModFlag.position(scnFailure4XorModFlag.position() + 1); - } - - if (!filled.get(74)) { - scnSuccess1XorMulFlag.position(scnSuccess1XorMulFlag.position() + 1); - } - - if (!filled.get(75)) { - scnSuccess2XorMxpx.position(scnSuccess2XorMxpx.position() + 1); - } - - if (!filled.get(76)) { - scnSuccess3XorMxpFlag.position(scnSuccess3XorMxpFlag.position() + 1); - } - - if (!filled.get(77)) { - scnSuccess4XorOobFlag.position(scnSuccess4XorOobFlag.position() + 1); - } - - if (!filled.get(78)) { - selfdestructXorOogx.position(selfdestructXorOogx.position() + 1); - } - - if (!filled.get(79)) { - sha2256XorOpcx.position(sha2256XorOpcx.position() + 1); - } - - if (!filled.get(82)) { - shfFlag.position(shfFlag.position() + 1); - } - - if (!filled.get(83)) { - sox.position(sox.position() + 1); - } - - if (!filled.get(84)) { - sstorex.position(sstorex.position() + 1); - } - - if (!filled.get(86)) { - stackItemPop1.position(stackItemPop1.position() + 1); - } - - if (!filled.get(87)) { - stackItemPop2.position(stackItemPop2.position() + 1); - } - - if (!filled.get(88)) { - stackItemPop3.position(stackItemPop3.position() + 1); - } - - if (!filled.get(89)) { - stackItemPop4.position(stackItemPop4.position() + 1); - } - - if (!filled.get(85)) { - stackramFlag.position(stackramFlag.position() + 1); - } - - if (!filled.get(91)) { - staticFlag.position(staticFlag.position() + 1); - } - - if (!filled.get(90)) { - staticx.position(staticx.position() + 1); - } - - if (!filled.get(92)) { - stoFlag.position(stoFlag.position() + 1); - } - - if (!filled.get(132)) { - stpGasHi.position(stpGasHi.position() + 32); - } - - if (!filled.get(133)) { - stpGasLo.position(stpGasLo.position() + 32); - } - - if (!filled.get(134)) { - stpGasOopkt.position(stpGasOopkt.position() + 32); - } - - if (!filled.get(135)) { - stpGasStpd.position(stpGasStpd.position() + 32); - } - - if (!filled.get(136)) { - stpInst.position(stpInst.position() + 32); - } - - if (!filled.get(137)) { - stpValHi.position(stpValHi.position() + 32); - } - - if (!filled.get(138)) { - stpValLo.position(stpValLo.position() + 32); - } - - if (!filled.get(40)) { - subStamp.position(subStamp.position() + 32); - } - - if (!filled.get(93)) { - sux.position(sux.position() + 1); - } - - if (!filled.get(94)) { - swapFlag.position(swapFlag.position() + 1); - } - - if (!filled.get(41)) { - transactionReverts.position(transactionReverts.position() + 1); - } - - if (!filled.get(95)) { - trmFlag.position(trmFlag.position() + 1); - } - - if (!filled.get(66)) { - trmFlagXorEcrecoverXorJumpx.position(trmFlagXorEcrecoverXorJumpx.position() + 1); - } - - if (!filled.get(120)) { - trmRawAddrHiXorMxpSize1HiXorStackItemValueLo1.position( - trmRawAddrHiXorMxpSize1HiXorStackItemValueLo1.position() + 32); - } - - if (!filled.get(42)) { - twoLineInstruction.position(twoLineInstruction.position() + 1); - } - - if (!filled.get(43)) { - txExec.position(txExec.position() + 1); - } - - if (!filled.get(44)) { - txFinl.position(txFinl.position() + 1); - } - - if (!filled.get(45)) { - txInit.position(txInit.position() + 1); - } - - if (!filled.get(46)) { - txSkip.position(txSkip.position() + 1); - } - - if (!filled.get(47)) { - txWarm.position(txWarm.position() + 1); - } - - if (!filled.get(96)) { - txnFlag.position(txnFlag.position() + 1); - } - - if (!filled.get(68)) { - warmNewXorModexpXorJumpFlag.position(warmNewXorModexpXorJumpFlag.position() + 1); - } - - if (!filled.get(67)) { - warmXorIdentityXorJumpDestinationVettingRequired.position( - warmXorIdentityXorJumpDestinationVettingRequired.position() + 1); - } - - if (!filled.get(97)) { - wcpFlag.position(wcpFlag.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxInfo.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxInfo.java deleted file mode 100644 index f25dc08b3..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxInfo.java +++ /dev/null @@ -1,110 +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 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 org.hyperledger.besu.datatypes.Quantity; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.gascalculator.GasCalculator; -import org.hyperledger.besu.evm.worldstate.WorldView; - -/** Stores transaction-specific information. */ -@Accessors(fluent = true) -@Getter -public class TxInfo implements StackedContainer { - private static final GasCalculator gc = ZkTracer.gasCalculator; - - private int preExecNumber = 0; - - private int number = 0; - private Transaction transaction; - @Setter private TxState state; - @Setter private Boolean status; - private long initialGas; - StorageInfo 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; - } - - 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() - - gc.transactionIntrinsicGasCost(tx.getPayload(), isDeployment) - - tx.getAccessList().map(gc::accessListGasCost).orElse(0L); - } - - /** - * Update transaction-specific information on new transaction start. - * - * @param tx the new transaction - */ - 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 StorageInfo(); - 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/hub/TxState.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxState.java deleted file mode 100644 index c93184814..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxState.java +++ /dev/null @@ -1,24 +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; - -public enum TxState { - TX_EXEC, - TX_FINAL, - TX_INIT, - TX_SKIP, - TX_WARM, -} 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 deleted file mode 100644 index 2745fc4cb..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ /dev/null @@ -1,127 +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 java.util.ArrayList; -import java.util.List; - -import lombok.Getter; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import org.hyperledger.besu.evm.worldstate.WorldView; - -/** - * Stores all the trace sections associated to the same transaction, stored in chronological order - * of creation. - */ -public class TxTrace { - /** The {@link TraceSection} of which this transaction trace is made of */ - @Getter private final List trace = new ArrayList<>(); - /** A cache for the line count of this transaction */ - private int cachedLineCount = 0; - - public int size() { - return this.trace.size(); - } - - /** - * Returns the latest trace section, i.e. the most recent. - * - * @return the most recent trace section - */ - public TraceSection currentSection() { - return this.trace.get(this.size() - 1); - } - - public TraceSection getSection(int i) { - return this.trace.get(i); - } - - /** - * @return whether this trace is empty - */ - public boolean isEmpty() { - return this.trace.isEmpty(); - } - - /** - * Add a {@link TraceSection} to this transaction trace. - * - * @param section the section to append - */ - public void add(TraceSection section) { - this.trace.add(section); - } - - public long refundedGas() { - long refundedGas = 0; - for (TraceSection section : this.trace) { - if (!section.hasReverted()) { - refundedGas += section.refundDelta(); - } - } - return refundedGas; - } - - /** - * Run the action required at the end of the transaction to finish this trace. - * - * @param hub the exection context - */ - public void postTxRetcon(Hub hub) { - long leftoverGas = hub.getRemainingGas(); - long refundedGas = this.refundedGas(); - for (TraceSection section : this.trace) { - section.postTxRetcon(hub, leftoverGas, refundedGas); - section.setFinalGasRefundCounter(refundedGas); - } - } - - /** - * Run the action required at the end of the conflation to finish this trace. - * - * @param hub the exection context - */ - public void postConflationRetcon(Hub hub, WorldView world) { - for (TraceSection section : this.trace) { - section.postConflationRetcon(hub, world); - } - } - - /** - * Generate the final numeric trace from the accumulated information. - * - * @param hubTrace where to materialize the trace - */ - public void commit(Trace hubTrace) { - for (TraceSection opSection : this.trace) { - for (TraceSection.TraceLine line : opSection.getLines()) { - line.trace(hubTrace); - } - } - } - - /** - * @return the line count in this transaction trace - */ - public int lineCount() { - if (this.cachedLineCount == 0) { - for (TraceSection s : trace) { - this.cachedLineCount += s.getLines().size(); - } - } - return this.cachedLineCount; - } -} 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 deleted file mode 100644 index c27851da4..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ /dev/null @@ -1,97 +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.defer; - -import java.util.ArrayList; -import java.util.List; - -import net.consensys.linea.zktracer.module.hub.Hub; -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.WorldView; - -/** - * Stores different categories of actions whose execution must be deferred later in the normal - * transaction execution process. - */ -public class DeferRegistry { - /** A list of actions deferred until the end of the current transaction */ - private final List txDefers = new ArrayList<>(); - /** 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> contextReentry = new ArrayList<>(); - - /** 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)); - } - - /** Schedule an action to be executed after the completion of the current opcode. */ - public void postExec(PostExecDefer latch) { - this.postExecDefers.add(latch); - } - - /** Schedule an action to be executed at the end of the current transaction. */ - public void postTx(PostTransactionDefer defer) { - this.txDefers.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 runNextContext(Hub hub, MessageFrame frame) { - for (Pair defer : this.contextReentry) { - if (hub.currentFrame().parentFrame() == defer.getLeft()) { - defer.getRight().runNextContext(hub, frame); - } - } - this.contextReentry.clear(); - } - - /** - * Trigger the execution of the actions deferred to the end of the transaction. - * - * @param hub the {@link Hub} context - * @param world a {@link WorldView} on the state - * @param tx the current {@link Transaction} - */ - public void runPostTx(Hub hub, WorldView world, Transaction tx) { - for (PostTransactionDefer defer : this.txDefers) { - defer.runPostTx(hub, world, tx); - } - this.txDefers.clear(); - } - - /** - * Trigger the execution of the actions deferred to the end of the current instruction execution. - * - * @param hub the {@link Hub} context - * @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) { - for (PostExecDefer defer : this.postExecDefers) { - defer.runPostExec(hub, frame, result); - } - this.postExecDefers.clear(); - } -} 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 deleted file mode 100644 index addd0a30e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/NextContextDefer.java +++ /dev/null @@ -1,23 +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.defer; - -import net.consensys.linea.zktracer.module.hub.Hub; -import org.hyperledger.besu.evm.frame.MessageFrame; - -public interface NextContextDefer { - void runNextContext(Hub hub, MessageFrame frame); -} 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 deleted file mode 100644 index 1e034548b..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostExecDefer.java +++ /dev/null @@ -1,24 +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.defer; - -import net.consensys.linea.zktracer.module.hub.Hub; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.operation.Operation; - -public interface PostExecDefer { - void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult operationResult); -} 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 deleted file mode 100644 index e1b2d54f1..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostTransactionDefer.java +++ /dev/null @@ -1,35 +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.defer; - -import net.consensys.linea.zktracer.module.hub.Hub; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldView; - -/** - * A TransactionDefer represents an object, whose execution will be deferred until after the current - * transaction has been executed. - */ -public interface PostTransactionDefer { - /** - * This method will be triggered as soon as the current transaction has finished its execution. - * - * @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 - */ - void runPostTx(Hub hub, WorldView state, Transaction tx); -} 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 deleted file mode 100644 index cfe5aecf3..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java +++ /dev/null @@ -1,91 +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.defer; - -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -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.TransactionFragment; -import net.consensys.linea.zktracer.module.hub.section.TxSkippedSection; -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 { - @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx) { - Address fromAddress = this.oldFromAccount.address(); - Address toAddress = this.oldToAccount.address(); - Address minerAddress = this.oldMinerAccount.address(); - hub.conflation().deploymentInfo().unmarkDeploying(toAddress); - - AccountSnapshot newFromAccount = - AccountSnapshot.fromAccount( - state.get(fromAddress), - true, - hub.conflation().deploymentInfo().number(fromAddress), - false); - - AccountSnapshot newToAccount = - AccountSnapshot.fromAccount( - state.get(toAddress), true, hub.conflation().deploymentInfo().number(toAddress), false); - - AccountSnapshot newMinerAccount = - AccountSnapshot.fromAccount( - state.get(minerAddress), - true, - hub.conflation().deploymentInfo().number(minerAddress), - false); - - // Append the final chunk to the hub chunks - hub.addTraceSection( - new TxSkippedSection( - hub, - // 3 lines -- account changes - // From - new AccountFragment(oldFromAccount, newFromAccount, false, 0, false), - // To - new AccountFragment(oldToAccount, newToAccount, false, 0, false), - // Miner - new AccountFragment(oldMinerAccount, newMinerAccount, false, 0, false), - - // 1 line -- transaction data - TransactionFragment.prepare( - hub.conflation().number(), - minerAddress, - tx, - false, - gasPrice, - baseFee, - hub.tx().initialGas()))); - } -} 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 deleted file mode 100644 index 98d9f04f7..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.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.fragment; - -import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; - -import com.google.common.base.Preconditions; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Hub; -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; -import org.hyperledger.besu.datatypes.Hash; - -@Accessors(fluent = true) -public final class AccountFragment implements TraceFragment { - @Getter private final Address who; - private final AccountSnapshot oldState; - private final AccountSnapshot newState; - private final boolean debit; - private final long cost; - private final boolean createAddress; - @Setter private int deploymentNumberInfnty; - @Setter private boolean existsInfinity; - - public AccountFragment(AccountSnapshot oldState, AccountSnapshot newState) { - this(oldState, newState, false, 0, false); - } - - public AccountFragment( - AccountSnapshot oldState, - AccountSnapshot newState, - boolean debit, - long cost, - boolean createAddress) { - Preconditions.checkArgument(oldState.address().equals(newState.address())); - - this.who = oldState.address(); - this.oldState = oldState; - this.newState = newState; - this.debit = debit; - this.cost = cost; - this.createAddress = createAddress; - this.deploymentNumberInfnty = 0; // will be retconned on conflation end - this.existsInfinity = false; // will be retconned on conflation end - } - - @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()); - - return trace - .peekAtAccount(true) - .pAccountAddrHi(eWho.hi()) - .pAccountAddrLo(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())) - .pAccountCodeHashHi(eCodeHash.hi()) - .pAccountCodeHashLo(eCodeHash.lo()) - .pAccountCodeHashHiNew(eCodeHashNew.hi()) - .pAccountCodeHashLoNew(eCodeHashNew.lo()) - .pAccountHasCode(oldState.code().getCodeHash() != Hash.EMPTY) - .pAccountHasCodeNew(newState.code().getCodeHash() != Hash.EMPTY) - .pAccountExists( - oldState.nonce() > 0 - || oldState.code().getCodeHash() != Hash.EMPTY - || !oldState.balance().isZero()) - .pAccountExistsNew( - newState.nonce() > 0 - || newState.code().getCodeHash() != Hash.EMPTY - || !newState.balance().isZero()) - .pAccountWarm(oldState.warm()) - .pAccountWarmNew(newState.warm()) - .pAccountDepNum(Bytes.ofUnsignedInt(oldState.deploymentNumber())) - .pAccountDepNumNew(Bytes.ofUnsignedInt(newState.deploymentNumber())) - .pAccountDepStatus(oldState.deploymentStatus()) - .pAccountDepStatusNew(newState.deploymentStatus()) - // .pAccountDebit(debit) - // .pAccountCost(cost) - // .pAccountCreateAddress(createAddress) - .pAccountDeploymentNumberInfty(Bytes.ofUnsignedInt(deploymentNumberInfnty)) - // .pAccountExistsInfty(existsInfinity) - ; - } - - @Override - public void postConflationRetcon(Hub hub /* TODO WorldState state */) { - this.deploymentNumberInfnty = hub.conflation().deploymentInfo().number(this.who); - this.existsInfinity = - false; // TODO should be account != null; see with Besu team if we can get a view on - // the state in traceEndConflation - } -} 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 deleted file mode 100644 index a715947b0..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ /dev/null @@ -1,122 +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 lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.Exceptions; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.TxState; -import net.consensys.linea.zktracer.opcode.InstructionFamily; -import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; - -@Accessors(fluent = true, chain = false) -@AllArgsConstructor -public final class CommonFragment implements TraceFragment { - private final int txNumber; - private final int batchNumber; - private final TxState txState; - private final int stamp; - @Setter private int txEndStamp; - @Getter @Setter private boolean txReverts; - private final InstructionFamily instructionFamily; - private final Exceptions exceptions; - private final int callFrameId; - @Getter private final int contextNumber; - @Setter private int newContextNumber; - private final int revertStamp; - private boolean getsReverted; - private boolean selfReverts; - @Getter private final int pc; - @Setter private int newPc; - private final EWord codeAddress; - private int codeDeploymentNumber; - private final boolean codeDeploymentStatus; - private final int callerContextNumber; - private final long gasExpected; - private final long gasActual; - private final long gasCost; - 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 int numberOfNonStackRows; - @Getter @Setter private int nonStackRowsCounter; - - @Override - public Trace trace(Trace trace) { - return trace - .absoluteTransactionNumber(Bytes.ofUnsignedInt(this.txNumber)) - .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(txEndStamp)) - .transactionReverts(txReverts) - .contextMayChangeFlag( - (instructionFamily == InstructionFamily.CALL - || instructionFamily == InstructionFamily.CREATE - || instructionFamily == InstructionFamily.HALT - || instructionFamily == InstructionFamily.INVALID) - || exceptions.any()) - .exceptionAhoyFlag(exceptions.any()) - - // Context data - .contextNumber(Bytes.ofUnsignedInt(contextNumber)) - .contextNumberNew(Bytes.ofUnsignedInt(newContextNumber)) - .contextRevertStamp(Bytes.ofUnsignedInt(revertStamp)) - .contextWillRevertFlag(getsReverted || selfReverts) - .contextGetsRevertedFlag(getsReverted) - .contextSelfRevertsFlag(selfReverts) - .programCounter(Bytes.ofUnsignedInt(pc)) - .programCounterNew(Bytes.ofUnsignedInt(newPc)) - - // Bytecode metadata - .codeAddressHi(codeAddress.hi()) - .codeAddressLo(codeAddress.lo()) - .codeDeploymentNumber(Bytes.ofUnsignedInt(codeDeploymentNumber)) - .codeDeploymentStatus(codeDeploymentStatus) - .callerContextNumber(Bytes.ofUnsignedInt(callerContextNumber)) - .gasExpected(Bytes.ofUnsignedLong(gasExpected)) - .gasActual(Bytes.ofUnsignedLong(gasActual)) - .gasCost(Bytes.ofUnsignedLong(gasCost)) - .gasNext(Bytes.ofUnsignedLong(gasNext)) - .gasRefund(Bytes.ofUnsignedLong(gasRefund)) - .twoLineInstruction(twoLinesInstruction) - .counterTli(twoLinesInstructionCounter) - .numberOfNonStackRows(Bytes.ofUnsignedShort(numberOfNonStackRows)) - .counterNsr(Bytes.ofUnsignedShort(nonStackRowsCounter)); - } - - @Override - public void postTxRetcon(Hub hub) { - CallFrame frame = hub.callStack().get(this.callFrameId); - - this.txEndStamp = hub.stamp(); - this.txReverts = hub.tx().status(); - this.selfReverts = frame.selfRevertsAt() > 0; - this.getsReverted = frame.getsRevertedAt() > 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 deleted file mode 100644 index 048ababb2..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ /dev/null @@ -1,62 +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 net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.runtime.callstack.CallStack; -import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; - -public record ContextFragment( - CallStack callStack, CallFrame callFrame, boolean updateCallerReturndata) - implements TraceFragment { - @Override - public Trace trace(Trace trace) { - EWord eAddress = callFrame.addressAsEWord(); - EWord eCodeAddress = callFrame.codeAddressAsEWord(); - - CallFrame parent = callStack.getParentOf(callFrame.id()); - EWord parentAddress = parent.addressAsEWord(); - - return trace - .peekAtContext(true) - .pContextContextNumber(Bytes.ofUnsignedInt(callFrame.contextNumber())) - .pContextCallStackDepth(Bytes.ofUnsignedInt(callFrame.depth())) - .pContextIsStatic(callFrame.type().isStatic() ? Bytes.of(1) : Bytes.EMPTY) - .pContextAccountAddressHi(eAddress.hi()) - .pContextAccountAddressLo(eAddress.lo()) - .pContextByteCodeAddressHi(eCodeAddress.hi()) - .pContextByteCodeAddressLo(eCodeAddress.lo()) - .pContextAccountDeploymentNumber(Bytes.ofUnsignedInt(callFrame.accountDeploymentNumber())) - .pContextByteCodeDeploymentNumber(Bytes.ofUnsignedInt(callFrame.codeDeploymentNumber())) - .pContextByteCodeDeploymentStatus(callFrame.underDeployment() ? Bytes.of(1) : Bytes.EMPTY) - .pContextCallerContextNumber(Bytes.ofUnsignedInt(parent.contextNumber())) - .pContextCallerAddressHi(parentAddress.hi()) - .pContextCallerAddressLo(parentAddress.lo()) - .pContextCallValue(callFrame.value()) - .pContextCallDataOffset(Bytes.ofUnsignedLong(callFrame.callDataPointer().offset())) - .pContextCallDataSize(Bytes.ofUnsignedLong(callFrame.callDataPointer().length())) - .pContextReturnAtOffset(Bytes.ofUnsignedLong(callFrame.returnDataTarget().offset())) - .pContextReturnAtSize(Bytes.ofUnsignedLong(callFrame.returnDataTarget().length())) - .pContextUpdate(updateCallerReturndata) - .pContextReturnerContextNumber( - Bytes.ofUnsignedInt( - callFrame.lastCallee().map(c -> callStack.get(c).contextNumber()).orElse(0))) - .pContextReturnDataOffset(Bytes.ofUnsignedLong(callFrame.returnDataPointer().offset())) - .pContextReturnDataSize(Bytes.ofUnsignedLong(callFrame.returnDataPointer().length())); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ScenarioFragment.java deleted file mode 100644 index 16020ab52..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ScenarioFragment.java +++ /dev/null @@ -1,98 +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 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 org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldView; - -/** This machine generates lines */ -public class ScenarioFragment implements TraceFragment, PostTransactionDefer { - private final boolean targetIsPrecompile; - private final boolean targetHasCode; - private final boolean abort; - private final int callerId; - private final int calleeId; - private boolean callerReverts = false; - private boolean calleeSelfReverts = false; - - public ScenarioFragment( - boolean targetIsPrecompile, - boolean targetHasCode, - boolean abort, - int callerId, - int calleeId) { - this.targetIsPrecompile = targetIsPrecompile; - this.targetHasCode = targetHasCode; - this.abort = abort; - this.callerId = callerId; - this.calleeId = calleeId; - } - - @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx) { - this.callerReverts = hub.callStack().get(callerId).hasReverted(); - this.calleeSelfReverts = hub.callStack().get(calleeId).hasReverted(); - } - - @Override - public Trace trace(Trace trace) { - return trace - .peekAtScenario(true) - .pScenarioScnFailure1(false) - .pScenarioScnFailure2(false) - .pScenarioScnFailure3(false) - .pScenarioScnFailure4(false) - .pScenarioScnSuccess1(false) - .pScenarioScnSuccess2(false) - .pScenarioScnSuccess3(false) - .pScenarioScnSuccess4(false) - .pScenarioCallAbort(abort) - .pScenarioCallEoaSuccessCallerWillRevert( - !abort && !targetIsPrecompile && !targetHasCode && callerReverts) - .pScenarioCallEoaSuccessCallerWontRevert( - !abort && !targetIsPrecompile && !targetHasCode && !callerReverts) - .pScenarioCallSmcSuccessCallerWillRevert( - !abort && targetHasCode && callerReverts && !calleeSelfReverts) - .pScenarioCallSmcSuccessCallerWontRevert( - !abort && targetHasCode && !callerReverts && !calleeSelfReverts) - .pScenarioCallSmcFailureCallerWillRevert( - !abort && targetHasCode && callerReverts && calleeSelfReverts) - .pScenarioCallSmcFailureCallerWontRevert( - !abort && targetHasCode && !callerReverts && calleeSelfReverts) - .pScenarioCallPrcSuccessCallerWillRevert( - !abort && targetIsPrecompile && callerReverts && !calleeSelfReverts) - .pScenarioCallPrcSuccessCallerWontRevert( - !abort && targetIsPrecompile && !callerReverts && !calleeSelfReverts) - .pScenarioCallPrcFailureCallerWillRevert( - !abort && targetIsPrecompile && callerReverts && calleeSelfReverts) - .pScenarioCallPrcFailureCallerWontRevert( - !abort && targetIsPrecompile && !callerReverts && calleeSelfReverts) - .pScenarioBlake2F(false) - .pScenarioCodedeposit(false) - .pScenarioEcadd(false) - .pScenarioEcmul(false) - .pScenarioEcpairing(false) - .pScenarioEcrecover(false) - .pScenarioIdentity(false) - .pScenarioModexp(false) - .pScenarioRipemd160(false) - .pScenarioSha2256(false) - .pScenarioSelfdestruct(false); - } -} 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 deleted file mode 100644 index 3310cacb5..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ /dev/null @@ -1,268 +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 java.util.List; -import java.util.Optional; -import java.util.function.Function; - -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.AbortingConditions; -import net.consensys.linea.zktracer.module.hub.DeploymentExceptions; -import net.consensys.linea.zktracer.module.hub.Exceptions; -import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.opcode.InstructionFamily; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.MxpType; -import net.consensys.linea.zktracer.opcode.gas.projector.GasProjection; -import net.consensys.linea.zktracer.runtime.stack.Action; -import net.consensys.linea.zktracer.runtime.stack.Stack; -import net.consensys.linea.zktracer.runtime.stack.StackOperation; -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.evm.account.AccountState; -import org.hyperledger.besu.evm.frame.MessageFrame; - -@Accessors(fluent = true) -public final class StackFragment implements TraceFragment { - private final Stack stack; - @Getter private final List stackOps; - private final Exceptions exceptions; - @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 StackFragment( - Stack stack, - List stackOps, - Exceptions exceptions, - AbortingConditions aborts, - DeploymentExceptions contextExceptions, - GasProjection gp, - boolean isDeploying) { - this.stack = stack; - this.stackOps = stackOps; - this.exceptions = exceptions; - this.contextExceptions = contextExceptions; - this.opCode = stack.getCurrentOpcodeData().mnemonic(); - this.hashInfoFlag = - switch (this.opCode) { - case SHA3 -> exceptions.none() && gp.messageSize() > 0; - case RETURN -> exceptions.none() && gp.messageSize() > 0 && isDeploying; - case CREATE2 -> exceptions.none() - && contextExceptions.none() - && aborts.none() - && gp.messageSize() > 0; - default -> false; - }; - this.hashInfoSize = this.hashInfoFlag ? gp.messageSize() : 0; - this.staticGas = gp.staticGas(); - } - - public static StackFragment prepare( - final Stack stack, - final List stackOperations, - final Exceptions exceptions, - final AbortingConditions aborts, - final GasProjection gp, - boolean isDeploying) { - return new StackFragment( - stack, stackOperations, exceptions, aborts, DeploymentExceptions.empty(), gp, isDeploying); - } - - public void feedHashedValue(MessageFrame frame) { - if (hashInfoFlag) { - switch (this.opCode) { - case SHA3 -> this.hashInfoKeccak = EWord.of(frame.getStackItem(0)); - case RETURN -> this.hashInfoKeccak = EWord.ZERO; // TODO: fixme - 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)); - } - } - default -> throw new IllegalStateException("unexpected opcode"); - } - } - } - - @Override - public Trace trace(Trace trace) { - final List> valHiTracers = - List.of( - trace::pStackStackItemValueHi1, - trace::pStackStackItemValueHi2, - trace::pStackStackItemValueHi3, - trace::pStackStackItemValueHi4); - - final List> valLoTracers = - List.of( - trace::pStackStackItemValueLo1, - trace::pStackStackItemValueLo2, - trace::pStackStackItemValueLo3, - trace::pStackStackItemValueLo4); - - final List> popTracers = - List.of( - trace::pStackStackItemPop1, - trace::pStackStackItemPop2, - trace::pStackStackItemPop3, - trace::pStackStackItemPop4); - - final List> heightTracers = - List.of( - trace::pStackStackItemHeight1, - trace::pStackStackItemHeight2, - trace::pStackStackItemHeight3, - trace::pStackStackItemHeight4); - - final List> stampTracers = - List.of( - trace::pStackStackItemStamp1, - trace::pStackStackItemStamp2, - trace::pStackStackItemStamp3, - trace::pStackStackItemStamp4); - - final int alpha = this.stack.getCurrentOpcodeData().stackSettings().alpha(); - final int delta = this.stack.getCurrentOpcodeData().stackSettings().delta(); - - var heightUnder = stack.getHeight() - delta; - var heightOver = 0; - - if (!stack.isUnderflow()) { - if (!(alpha == 1 && delta == 0 && stack.getHeight() == Stack.MAX_STACK_SIZE)) { - var overflow = stack.isOverflow() ? 1 : 0; - heightOver = (2 * overflow - 1) * (heightUnder + alpha - Stack.MAX_STACK_SIZE) - overflow; - } - } else { - heightUnder = -heightUnder - 1; - } - - var it = stackOps.listIterator(); - while (it.hasNext()) { - var i = it.nextIndex(); - var op = it.next(); - final EWord eword = EWord.of(op.value()); - - heightTracers.get(i).apply(Bytes.ofUnsignedShort(op.height())); - valLoTracers.get(i).apply(eword.lo()); - valHiTracers.get(i).apply(eword.hi()); - popTracers.get(i).apply(op.action() == Action.POP); - stampTracers.get(i).apply(Bytes.ofUnsignedLong(op.stackStamp())); - } - - return trace - .peekAtStack(true) - // Stack height - .pStackHeight(Bytes.ofUnsignedShort(stack.getHeight())) - .pStackHeightNew(Bytes.ofUnsignedShort(stack.getHeightNew())) - .pStackHeightUnder(Bytes.ofUnsignedShort(heightUnder)) - .pStackHeightOver(Bytes.ofUnsignedShort(heightOver)) - // Instruction details - .pStackInst(Bytes.of(this.stack.getCurrentOpcodeData().value())) - .pStackStaticGas(Bytes.ofUnsignedInt(staticGas)) - .pStackDecodedFlag1(this.stack.getCurrentOpcodeData().stackSettings().flag1()) - .pStackDecodedFlag2(this.stack.getCurrentOpcodeData().stackSettings().flag2()) - .pStackDecodedFlag3(this.stack.getCurrentOpcodeData().stackSettings().flag3()) - .pStackDecodedFlag4(this.stack.getCurrentOpcodeData().stackSettings().flag4()) - // Exception flag - .pStackOpcx(exceptions.invalidOpcode()) - .pStackSux(exceptions.stackUnderflow()) - .pStackSox(exceptions.stackOverflow()) - .pStackOogx(exceptions.outOfGas()) - .pStackMxpx(exceptions.outOfMemoryExpansion()) - .pStackRdcx(exceptions.returnDataCopyFault()) - .pStackJumpx(exceptions.jumpFault()) - .pStackStaticx(exceptions.staticFault()) - .pStackSstorex(exceptions.outOfSStore()) - .pStackInvprex(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)) - .pStackTrmFlag( - this.stack.getCurrentOpcodeData().stackSettings().addressTrimmingInstruction()) - .pStackStaticFlag(this.stack.getCurrentOpcodeData().stackSettings().forbiddenInStatic()) - .pStackOobFlag(this.stack.getCurrentOpcodeData().stackSettings().oobFlag()) - // Hash data - .pStackHashInfoSize(Bytes.ofUnsignedInt(hashInfoSize)) - .pStackHashInfoKecHi(this.hashInfoKeccak.hi()) - .pStackHashInfoKecLo(this.hashInfoKeccak.lo()) - .pStackHashInfoFlag(this.hashInfoFlag); - } -} 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 deleted file mode 100644 index 3ae4039c0..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StorageFragment.java +++ /dev/null @@ -1,65 +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 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; - -/** - * @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 - public Trace trace(Trace trace) { - final EWord eAddress = EWord.of(address); - - return trace - .peekAtStorage(true) - .pStorageAddressHi(eAddress.hi()) - .pStorageAddressLo(eAddress.lo()) - .pStorageDeploymentNumber(Bytes.ofUnsignedInt(deploymentNumber)) - .pStorageStorageKeyHi(key.hi()) - .pStorageStorageKeyLo(key.lo()) - .pStorageValOrigHi(valOrig.hi()) - .pStorageValOrigLo(valOrig.lo()) - .pStorageValCurrHi(valCurr.hi()) - .pStorageValCurrLo(valCurr.lo()) - .pStorageValNextHi(valNext.hi()) - .pStorageValNextLo(valNext.lo()) - .pStorageWarm(oldWarmth) - .pStorageWarmNew(newWarmth) - .pStorageValOrigIsZero(valOrig.isZero()) - .pStorageValCurrIsZero(valCurr.isZero()) - .pStorageValNextIsZero(valNext.isZero()) - .pStorageValNextIsOrig(valNext == valOrig) - .pStorageValNextIsCurr(valNext == valOrig); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/SubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/SubSection.java deleted file mode 100644 index 02eff46d2..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/SubSection.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.fragment; - -import java.util.List; - -public interface SubSection { - List generate(); -} 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 deleted file mode 100644 index f753ba70d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceFragment.java +++ /dev/null @@ -1,43 +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 net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.Trace; - -/** - * A TraceFragment represents a piece of a trace line; either a {@link CommonFragment} present in - * each line, or a perspective-specific fragment. - */ -public interface TraceFragment { - Trace trace(Trace trace); - - /** - * This hook is called by the {@link Hub} at the end of the transaction to retrofit information if - * required. - * - * @param hub a reference to the hub - */ - default void postTxRetcon(Hub hub) {} - - /** - * This hook is called by the {@link Hub} at the end of the conflation to retrofit information if - * required. - * - * @param hub a reference to the hub - */ - default void postConflationRetcon(Hub hub) {} -} 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 deleted file mode 100644 index 59b7527dc..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceSubFragment.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.fragment; - -import net.consensys.linea.zktracer.module.hub.Trace; - -public interface TraceSubFragment { - Trace trace(Trace trace); -} 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 deleted file mode 100644 index 8ea226e9b..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java +++ /dev/null @@ -1,106 +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.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.TxInfo; -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; - -public final class TransactionFragment implements TraceFragment { - 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 final boolean txSuccess; - @Setter private long gasRefundFinalCounter; - @Setter private long gasRefundAmount; - @Setter private long leftoverGas; - private final long initialGas; - - private TransactionFragment( - int batchNumber, - Address minerAddress, - Transaction tx, - boolean evmExecutes, - Wei gasPrice, - Wei baseFee, - boolean txSuccess, - long gasRefundFinalCounter, - long gasRefundAmount, - long initialGas) { - this.batchNumber = batchNumber; - this.minerAddress = minerAddress; - this.tx = tx; - this.evmExecutes = evmExecutes; - this.gasPrice = gasPrice; - this.baseFee = baseFee; - this.txSuccess = txSuccess; - this.gasRefundFinalCounter = gasRefundFinalCounter; - this.gasRefundAmount = gasRefundAmount; - this.initialGas = initialGas; - } - - 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, 0, 0, initialGas); - } - - @Override - public Trace trace(Trace trace) { - final EWord to = EWord.of(Hub.effectiveToAddress(tx)); - final EWord from = EWord.of(tx.getSender()); - final EWord miner = EWord.of(minerAddress); - - return trace - .peekAtTransaction(true) - .pTransactionNonce(Bytes.ofUnsignedLong(tx.getNonce())) - .pTransactionIsDeployment(tx.getTo().isEmpty()) - .pTransactionFromAddressHi(from.hi()) - .pTransactionFromAddressLo(from.lo()) - .pTransactionToAddressHi(to.hi()) - .pTransactionToAddressLo(to.lo()) - .pTransactionGasPrice(gasPrice) - .pTransactionBasefee(baseFee) - .pTransactionInitGas(Bytes.ofUnsignedLong(TxInfo.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))) - .pTransactionTxnRequiresEvmExecution(evmExecutes) - .pTransactionLeftoverGas(Bytes.ofUnsignedLong(leftoverGas)) - .pTransactionGasRefundCounterFinal(Bytes.ofUnsignedLong(gasRefundFinalCounter)) - .pTransactionGasRefundAmount(Bytes.ofUnsignedLong(gasRefundAmount)) - .pTransactionStatusCode(txSuccess); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/MiscFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/MiscFragment.java deleted file mode 100644 index 916ef0171..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/MiscFragment.java +++ /dev/null @@ -1,94 +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.misc; - -import java.util.ArrayList; -import java.util.List; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.Signals; -import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; -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.misc.subfragment.ExpSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.misc.subfragment.MmuSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.misc.subfragment.MxpSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.misc.subfragment.oob.CalldataloadSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.misc.subfragment.oob.JumpSubFragment; -import net.consensys.linea.zktracer.types.EWord; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.operation.Operation; - -public class MiscFragment implements TraceFragment, PostExecDefer { - private final Signals signals; - private final List subFragments = new ArrayList<>(); - - public MiscFragment(Hub hub, MessageFrame frame) { - this.signals = hub.pch().signals().snapshot(); - - // TODO: the rest - if (this.signals.mmu()) { - this.subFragments.add(new MmuSubFragment(hub, frame)); - } - - if (this.signals.mxp()) { - this.subFragments.add(MxpSubFragment.build(hub)); - } - - if (this.signals.oob()) { - switch (hub.currentFrame().opCode()) { - case JUMP, JUMPI -> this.subFragments.add(JumpSubFragment.build(hub, frame)); - case CALLDATALOAD -> this.subFragments.add(CalldataloadSubFragment.build(hub, frame)); - case CALL, DELEGATECALL, STATICCALL, CALLCODE -> {} - case CREATE, CREATE2 -> {} - case SSTORE -> {} - case RETURN -> {} - default -> throw new IllegalArgumentException("unexpected opcode for OoB"); - } - } - - if (this.signals.exp()) { - this.subFragments.add(new ExpSubFragment(EWord.of(frame.getStackItem(1)))); - } - } - - @Override - public Trace trace(Trace trace) { - trace - .peekAtMiscellaneous(true) - .pMiscellaneousMmuFlag(this.signals.mmu()) - .pMiscellaneousMxpFlag(this.signals.mxp()) - .pMiscellaneousOobFlag(this.signals.oob()) - .pMiscellaneousStpFlag(this.signals.stp()) - .pMiscellaneousExpFlag(this.signals.exp()); - - for (TraceSubFragment subFragment : this.subFragments) { - subFragment.trace(trace); - } - - return trace; - } - - @Override - public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { - for (TraceSubFragment f : this.subFragments) { - if (f instanceof MmuSubFragment mmuSubFragment) { - mmuSubFragment.runPostExec(hub, frame, operationResult); - } - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/ExpSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/ExpSubFragment.java deleted file mode 100644 index 9242720c1..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/ExpSubFragment.java +++ /dev/null @@ -1,35 +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.misc.subfragment; - -import static net.consensys.linea.zktracer.opcode.gas.GasConstants.G_EXP_BYTE; - -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 ExpSubFragment(EWord exponent) implements TraceSubFragment { - - @Override - public Trace trace(Trace trace) { - return trace - .pMiscellaneousExpExponentHi(exponent.hi()) - .pMiscellaneousExpExponentLo(this.exponent.lo()) - .pMiscellaneousExpDyncost( - Bytes.ofUnsignedLong((long) G_EXP_BYTE.cost() * exponent.byteLength())); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/MmuSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/MmuSubFragment.java deleted file mode 100644 index f97ca0fcb..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/MmuSubFragment.java +++ /dev/null @@ -1,106 +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.misc.subfragment; - -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; -import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; -import net.consensys.linea.zktracer.opcode.OpCode; -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; -import org.hyperledger.besu.evm.operation.Operation; - -@Slf4j -public class MmuSubFragment implements TraceSubFragment, PostExecDefer { - Bytes stackValue = Bytes.EMPTY; - Bytes offset1 = Bytes.EMPTY; - Bytes offset2 = Bytes.EMPTY; - byte opCode; - int param1 = 0; - int param2 = 0; - int returner = 0; - boolean info = false; - long referenceOffset = 0; - long referenceSize = 0; - int exoSum = 0; - int size = 0; - - public MmuSubFragment(Hub hub, MessageFrame frame) { - final OpCode opCode = hub.currentFrame().opCode(); - - switch (opCode) { - case SHA3 -> { - offset1 = frame.getStackItem(0).copy(); - param1 = 0; // TODO: hash info stamp - size = Words.clampedToInt(Words.clampedToLong(frame.getStackItem(1))); - exoSum = 0; // TODO: - } - case CALLDATALOAD -> { - this.param1 = hub.tx().number(); - this.info = hub.callStack().depth() == 1; - this.referenceOffset = hub.currentFrame().callDataPointer().offset(); - this.referenceSize = hub.currentFrame().callDataPointer().length(); - this.offset1 = frame.getStackItem(0).copy(); - } - case MSTORE, MSTORE8 -> { - this.offset1 = frame.getStackItem(0).copy(); - this.stackValue = frame.getStackItem(1).copy(); - } - case MLOAD -> this.offset1 = frame.getStackItem(0).copy(); - default -> log.info("MMU not yet implemented for this opcode"); - } - - this.opCode = opCode.byteValue(); - } - - @Override - public void runPostExec( - final Hub hub, final MessageFrame frame, final Operation.OperationResult operationResult) { - switch (hub.opCode()) { - case MLOAD, CALLDATALOAD -> { - this.stackValue = frame.getStackItem(0).copy(); - } - default -> {} - } - } - - @Override - public Trace trace(Trace trace) { - final EWord eOffset1 = EWord.of(this.offset1); - final EWord eOffset2 = EWord.of(this.offset2); - final EWord eStackValue = EWord.of(this.stackValue); - - return trace - .pMiscellaneousMmuInst(Bytes.of(this.opCode)) - .pMiscellaneousMmuParam1(Bytes.ofUnsignedInt(this.param1)) - .pMiscellaneousMmuParam2(Bytes.ofUnsignedInt(this.param2)) - // .pMiscellaneousMmuReturner(Bytes.ofUnsignedInt(this.returner)) - .pMiscellaneousMmuInfo(this.info) - .pMiscellaneousMmuRefOffset(Bytes.ofUnsignedLong(this.referenceOffset)) - .pMiscellaneousMmuRefSize(Bytes.ofUnsignedLong(this.referenceSize)) - .pMiscellaneousMmuOffset1Lo(eOffset1.lo()) - .pMiscellaneousMmuOffset2Hi(eOffset2.hi()) - .pMiscellaneousMmuOffset2Lo(eOffset2.lo()) - .pMiscellaneousMmuSize(Bytes.ofUnsignedInt(this.size)) - .pMiscellaneousMmuStackValHi(eStackValue.hi()) - .pMiscellaneousMmuStackValLo(eStackValue.lo()) - .pMiscellaneousMmuExoSum(Bytes.ofUnsignedInt(this.exoSum)); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/MxpSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/MxpSubFragment.java deleted file mode 100644 index 51319dd79..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/MxpSubFragment.java +++ /dev/null @@ -1,77 +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.misc.subfragment; - -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.types.EWord; -import org.apache.tuweni.bytes.Bytes; - -public record MxpSubFragment( - boolean mxpException, - int opCode, - boolean deploys, - int memorySize, - long gasMxp, - EWord offset1, - EWord offset2, - EWord size1, - EWord size2) - implements TraceSubFragment { - public static MxpSubFragment 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; - - return new MxpSubFragment( - hub.pch().exceptions().outOfMemoryExpansion(), - hub.currentFrame().opCodeData().value(), - opCode == OpCode.RETURN && hub.currentFrame().underDeployment(), - hub.currentFrame().frame().memoryWordSize(), - gasMxp, - offset1, - offset2, - size1, - size2); - } - - @Override - public Trace trace(Trace trace) { - return trace - .pMiscellaneousMxpMxpx(this.mxpException) - .pMiscellaneousMxpInst(Bytes.ofUnsignedInt(this.opCode)) - .pMiscellaneousMxpDeploys(this.deploys) - .pMiscellaneousMxpWords(Bytes.ofUnsignedLong(this.memorySize)) - .pMiscellaneousMxpGasMxp(Bytes.ofUnsignedLong(this.gasMxp)) - .pMiscellaneousMxpOffset1Hi(this.offset1.hi()) - .pMiscellaneousMxpOffset1Lo(this.offset1.lo()) - .pMiscellaneousMxpOffset2Hi(this.offset2.hi()) - .pMiscellaneousMxpOffset2Lo(this.offset2.lo()) - .pMiscellaneousMxpSize1Hi(this.size1.hi()) - .pMiscellaneousMxpSize1Lo(this.size1.lo()) - .pMiscellaneousMxpSize2Hi(this.size2.hi()) - .pMiscellaneousMxpSize2Lo(this.size2.lo()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/PrecinfoSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/PrecinfoSubFragment.java deleted file mode 100644 index fedbb81fd..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/PrecinfoSubFragment.java +++ /dev/null @@ -1,27 +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.misc.subfragment; - -import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; -import org.apache.commons.lang3.NotImplementedException; - -public record PrecinfoSubFragment() implements TraceSubFragment { - @Override - public Trace trace(Trace trace) { - throw new NotImplementedException("Soon"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/StpSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/StpSubFragment.java deleted file mode 100644 index facfa2d8d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/StpSubFragment.java +++ /dev/null @@ -1,27 +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.misc.subfragment; - -import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; -import org.apache.commons.lang3.NotImplementedException; - -public record StpSubFragment() implements TraceSubFragment { - @Override - public Trace trace(Trace trace) { - throw new NotImplementedException("Soon"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/oob/CalldataloadSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/oob/CalldataloadSubFragment.java deleted file mode 100644 index 360ec75fe..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/oob/CalldataloadSubFragment.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.fragment.misc.subfragment.oob; - -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.types.EWord; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.frame.MessageFrame; - -public record CalldataloadSubFragment(EWord readOffset, EWord calldataSize) - implements TraceSubFragment { - private static final Bytes CALLDATALOAD = Bytes.of(OpCode.CALLDATALOAD.byteValue()); - - public static CalldataloadSubFragment build(Hub hub, MessageFrame frame) { - return new CalldataloadSubFragment( - EWord.of(frame.getStackItem(0)), EWord.of(hub.currentFrame().callData().size())); - } - - @Override - public Trace trace(Trace trace) { - return trace - .pMiscellaneousOobOutgoingData1(this.readOffset.hi()) - .pMiscellaneousOobOutgoingData2(this.readOffset().lo()) - .pMiscellaneousOobOutgoingData5(this.calldataSize) - .pMiscellaneousOobInst(CALLDATALOAD) - .pMiscellaneousOobEvent1(this.readOffset.greaterOrEqualThan(this.calldataSize)); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/oob/JumpSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/oob/JumpSubFragment.java deleted file mode 100644 index 6a9485d0a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/misc/subfragment/oob/JumpSubFragment.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.fragment.misc.subfragment.oob; - -import java.math.BigInteger; - -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.types.EWord; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public record JumpSubFragment( - EWord targetPc, - EWord jumpCondition, - int codeSize, - OpCode opCode, - boolean event1, - boolean event2) - implements TraceSubFragment { - - public static JumpSubFragment build(Hub hub, MessageFrame frame) { - final OpCode opCode = hub.currentFrame().opCode(); - final long targetPc = Words.clampedToLong(frame.getStackItem(0)); - final boolean invalidDestination = frame.getCode().isJumpDestInvalid((int) targetPc); - - long jumpCondition = 0; - boolean event1; - switch (opCode) { - case JUMP -> event1 = invalidDestination; - case JUMPI -> { - jumpCondition = Words.clampedToLong(frame.getStackItem(1)); - event1 = (jumpCondition != 0) && invalidDestination; - } - default -> throw new IllegalArgumentException("Unexpected opcode"); - } - - return new JumpSubFragment( - EWord.of(BigInteger.valueOf(targetPc)), - EWord.of(BigInteger.valueOf(jumpCondition)), - frame.getWorldUpdater().get(hub.currentFrame().codeAddress()).getCode().size(), - opCode, - event1, - jumpCondition > 0); - } - - @Override - public Trace trace(Trace trace) { - return trace - .pMiscellaneousOobOutgoingData1(this.targetPc.hi()) - .pMiscellaneousOobOutgoingData2(this.targetPc.lo()) - .pMiscellaneousOobOutgoingData3(this.jumpCondition.hi()) - .pMiscellaneousOobOutgoingData4(this.jumpCondition.lo()) - .pMiscellaneousOobOutgoingData5(Bytes.ofUnsignedInt(this.codeSize)) - .pMiscellaneousOobOutgoingData6(Bytes.EMPTY) - .pMiscellaneousOobInst(Bytes.ofUnsignedInt(this.opCode.byteValue())) - .pMiscellaneousOobEvent1(this.event1) - .pMiscellaneousOobEvent2(this.event2); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/memory/MemorySpan.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/memory/MemorySpan.java deleted file mode 100644 index e24f07c64..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/memory/MemorySpan.java +++ /dev/null @@ -1,45 +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.memory; - -/** - * A MemorySpan describes a contiguous region in an account memory. - * - * @param offset the region start - * @param length the region length - */ -public record MemorySpan(long offset, long length) { - - /** - * An alternative way to build a MemorySpan, from a start and an end. - * - * @param start the region start - * @param end the region end - * @return the MemorySpan describing the region running from start to end - */ - static MemorySpan fromStartEnd(long start, long end) { - return new MemorySpan(start, end - start); - } - - /** - * Compute the total length of a memory region. - * - * @return the region length - */ - long end() { - return this.length + this.length; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AbortedCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AbortedCallSection.java deleted file mode 100644 index 942c50d2c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AbortedCallSection.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; - -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; - -public class AbortedCallSection extends TraceSection { - public AbortedCallSection(Hub hub, CallFrame callFrame, TraceFragment... chunks) { - this.addChunksAndStack(hub, callFrame, chunks); - } -} 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 deleted file mode 100644 index 2980575f2..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.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 AccountSection extends TraceSection { - public AccountSection(Hub hub, TraceFragment... chunks) { - this.addChunksAndStack(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 deleted file mode 100644 index 298ff5906..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.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 ContextLogSection extends TraceSection { - public ContextLogSection(Hub hub, TraceFragment... chunks) { - this.addChunksAndStack(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 deleted file mode 100644 index 2bc0753ac..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.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 CopySection extends TraceSection { - public CopySection(Hub hub, TraceFragment... chunks) { - this.addChunksAndStack(hub, chunks); - } - - @Override - public void seal(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 deleted file mode 100644 index 55e307d2b..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ /dev/null @@ -1,89 +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.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.fragment.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -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 CreateSection extends TraceSection - implements PostExecDefer, NextContextDefer, PostTransactionDefer { - private final AccountSnapshot oldCreatorSnapshot; - private final AccountSnapshot oldCreatedSnapshot; - private AccountSnapshot newCreatorSnapshot; - private AccountSnapshot newCreatedSnapshot; - - public CreateSection( - Hub hub, AccountSnapshot oldCreatorSnapshot, AccountSnapshot oldCreatedSnapshot) { - this.oldCreatorSnapshot = oldCreatorSnapshot; - this.oldCreatedSnapshot = oldCreatedSnapshot; - - this.addStack(hub); - } - - @Override - public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { - // The post-exec behaves identically to the new context defer; albeit with different global - // state - this.runNextContext(hub, frame); - } - - @Override - public void runNextContext(Hub hub, MessageFrame frame) { - Address creatorAddress = oldCreatorSnapshot.address(); - this.newCreatorSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(creatorAddress), - true, - hub.conflation().deploymentInfo().number(creatorAddress), - hub.conflation().deploymentInfo().isDeploying(creatorAddress)); - - Address createdAddress = oldCreatedSnapshot.address(); - this.newCreatedSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(createdAddress), - true, - hub.conflation().deploymentInfo().number(createdAddress), - hub.conflation().deploymentInfo().isDeploying(createdAddress)); - } - - @Override - public void seal(Hub hub) {} - - @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx) { - final boolean updateReturnData = false; // TODO: - - this.addChunksWithoutStack( - hub, - new ContextFragment(hub.callStack(), hub.currentFrame(), updateReturnData), - new AccountFragment(oldCreatorSnapshot, newCreatorSnapshot, false, 0, false), - new AccountFragment(oldCreatorSnapshot, newCreatorSnapshot, false, 0, false), - new AccountFragment(oldCreatorSnapshot, newCreatorSnapshot, false, 0, false), - // 2×created account - new AccountFragment(oldCreatedSnapshot, newCreatedSnapshot, false, 0, true), - new AccountFragment(oldCreatedSnapshot, newCreatedSnapshot, false, 0, false)); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/EndTransaction.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/EndTransaction.java deleted file mode 100644 index 64d91c0af..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/EndTransaction.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 EndTransaction extends TraceSection { - public EndTransaction(Hub hub, TraceFragment... fragments) { - this.addChunksWithoutStack(hub, fragments); - } - - @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 deleted file mode 100644 index b8c739e4b..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.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 JumpSection extends TraceSection { - public JumpSection(Hub hub, TraceFragment... chunks) { - this.addChunksAndStack(hub, chunks); - } - - @Override - public void seal(Hub hub) {} -} 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 deleted file mode 100644 index 4db803d27..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.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; - -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; - -public class KeccakSection extends TraceSection { - public KeccakSection(Hub hub, CallFrame callFrame, TraceFragment... chunks) { - this.addChunksAndStack(hub, callFrame, 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/NoCodeCallSection.java deleted file mode 100644 index cdb416b09..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java +++ /dev/null @@ -1,124 +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.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.fragment.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.ScenarioFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.fragment.misc.MiscFragment; -import net.consensys.linea.zktracer.module.hub.subsection.PrecompileScenarioTraceSubsection; -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 NoCodeCallSection extends TraceSection implements PostTransactionDefer, PostExecDefer { - private final boolean targetIsPrecompile; - private final CallFrame callerCallFrame; - private final int calledCallFrameId; - private final AccountSnapshot preCallCallerAccountSnapshot; - private final AccountSnapshot preCallCalledAccountSnapshot; - - private AccountSnapshot postCallCallerAccountSnapshot; - private AccountSnapshot postCallCalledAccountSnapshot; - private final MiscFragment miscFragment; - - public NoCodeCallSection( - Hub hub, - boolean targetIsPrecompile, - AccountSnapshot preCallCallerAccountSnapshot, - AccountSnapshot preCallCalledAccountSnapshot, - MiscFragment miscFragment) { - this.targetIsPrecompile = targetIsPrecompile; - this.preCallCallerAccountSnapshot = preCallCallerAccountSnapshot; - this.preCallCalledAccountSnapshot = preCallCalledAccountSnapshot; - this.callerCallFrame = hub.currentFrame(); - this.calledCallFrameId = hub.callStack().futureId(); - this.miscFragment = miscFragment; - for (var stackChunk : hub.makeStackChunks(hub.currentFrame())) { - this.addChunk(hub, hub.currentFrame(), stackChunk); - } - } - - @Override - 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 Account calledAccount = frame.getWorldUpdater().get(calledAddress); - - this.postCallCallerAccountSnapshot = - AccountSnapshot.fromAccount( - callerAccount, - frame.isAddressWarm(callerAddress), - hub.conflation().deploymentInfo().number(callerAddress), - hub.conflation().deploymentInfo().isDeploying(callerAddress)); - this.postCallCalledAccountSnapshot = - AccountSnapshot.fromAccount( - calledAccount, - frame.isAddressWarm(calledAddress), - hub.conflation().deploymentInfo().number(calledAddress), - hub.conflation().deploymentInfo().isDeploying(calledAddress)); - } - - @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx) { - this.addChunksWithoutStack( - hub, - callerCallFrame, - new ScenarioFragment( - targetIsPrecompile, false, false, this.callerCallFrame.id(), this.calledCallFrameId), - new ContextFragment(hub.callStack(), hub.currentFrame(), false), - this.miscFragment, - new AccountFragment(this.preCallCallerAccountSnapshot, this.postCallCallerAccountSnapshot), - new AccountFragment(this.preCallCalledAccountSnapshot, this.postCallCalledAccountSnapshot)); - - if (callerCallFrame.hasReverted()) { - if (targetIsPrecompile) { - this.addChunksWithoutStack( - hub, - callerCallFrame, - new AccountFragment( - this.postCallCallerAccountSnapshot, this.preCallCallerAccountSnapshot), - new AccountFragment( - this.postCallCalledAccountSnapshot, this.preCallCalledAccountSnapshot)); - for (TraceFragment fragment : new PrecompileScenarioTraceSubsection().generate()) { - this.addChunk(hub, callerCallFrame, fragment); - } - } else { - this.addChunk( - hub, callerCallFrame, new ContextFragment(hub.callStack(), this.callerCallFrame, true)); - } - } else { - if (targetIsPrecompile) { - for (TraceFragment fragment : new PrecompileScenarioTraceSubsection().generate()) { - this.addChunk(hub, callerCallFrame, fragment); - } - } else { - this.addChunk( - hub, callerCallFrame, new ContextFragment(hub.callStack(), this.callerCallFrame, true)); - } - } - } -} 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 deleted file mode 100644 index b862e1517..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackOnlySection.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 StackOnlySection extends TraceSection { - public StackOnlySection(Hub hub, TraceFragment... chunks) { - this.addChunksAndStack(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 deleted file mode 100644 index c00a8335a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.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 StackRam extends TraceSection { - public StackRam(Hub hub, TraceFragment... chunks) { - this.addChunksAndStack(hub, chunks); - } - - @Override - public void seal(Hub 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 deleted file mode 100644 index 0df31d570..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.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 StorageSection extends TraceSection { - public StorageSection(Hub hub, TraceFragment... chunks) { - this.addChunksAndStack(hub, chunks); - } - - @Override - public void seal(Hub 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 deleted file mode 100644 index b8d40c417..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TraceSection.java +++ /dev/null @@ -1,320 +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 java.util.ArrayList; -import java.util.List; - -import com.google.common.base.Preconditions; -import lombok.Getter; -import net.consensys.linea.zktracer.module.hub.DeploymentExceptions; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.Trace; -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.opcode.OpCode; -import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import org.hyperledger.besu.evm.worldstate.WorldView; - -/** A TraceSection gather the trace lines linked to a single operation */ -public abstract class 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 encoded within this chunk in the given trace builder. - * - * @param trace where to trace the line - * @return the trace builder - */ - public Trace trace(Trace trace) { - Preconditions.checkNotNull(common); - Preconditions.checkNotNull(specific); - - common.trace(trace); - specific.trace(trace); - - return trace.fillAndValidateRow(); - } - } - - /** Count the stack lines */ - @Getter private int stackRowsCounter; - /** Count the non-stack lines */ - private int nonStackRowsCounter; - - /** 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 operations. - * - * @return a chunk representing the share columns - */ - private CommonFragment traceCommon(Hub hub, CallFrame callFrame) { - OpCode opCode = callFrame.opCode(); - long refund = 0; - if (hub.pch().exceptions().noStackException()) { - refund = Hub.gp.of(callFrame.frame(), opCode).refund(); - } - - return new CommonFragment( - hub.tx().number(), - hub.conflation().number(), - hub.tx().state(), - hub.stamp(), - 0, // retconned - false, // retconned - hub.opCodeData().instructionFamily(), - hub.pch().exceptions().snapshot(), - callFrame.id(), - callFrame.contextNumber(), - callFrame.contextNumber(), - 0, // retconned - false, // retconned - false, // retconned - callFrame.pc(), - callFrame.pc(), // retconned later on - callFrame.addressAsEWord(), - callFrame.codeDeploymentNumber(), - callFrame.underDeployment(), - callFrame.accountDeploymentNumber(), - 0, - 0, - 0, - 0, - refund, - 0, - hub.opCodeData().stackSettings().twoLinesInstruction(), - this.stackRowsCounter == 1, - 0, // retconned on sealing - this.nonStackRowsCounter); - } - - /** Default creator for an empty section. */ - public TraceSection() {} - - /** - * Add a fragment to the section while pairing it to its common piece. - * - * @param hub the execution context - * @param fragment the fragment to insert - */ - public final void addChunk(Hub hub, CallFrame callFrame, TraceFragment fragment) { - Preconditions.checkArgument(!(fragment instanceof CommonFragment)); - - if (fragment instanceof StackFragment) { - this.stackRowsCounter++; - } else { - this.nonStackRowsCounter++; - } - - this.lines.add(new TraceLine(traceCommon(hub, callFrame), fragment)); - } - - /** - * Add the fragments containing the stack lines. - * - * @param hub the execution context - */ - public final void addStack(Hub hub) { - for (var stackChunk : hub.makeStackChunks(hub.currentFrame())) { - this.addChunk(hub, hub.currentFrame(), stackChunk); - } - } - - /** - * 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 addChunksWithoutStack( - Hub hub, CallFrame callFrame, TraceFragment... fragments) { - for (TraceFragment chunk : fragments) { - this.addChunk(hub, callFrame, chunk); - } - } - - /** - * 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 addChunksWithoutStack(Hub hub, TraceFragment... fragments) { - for (TraceFragment chunk : fragments) { - this.addChunk(hub, hub.currentFrame(), chunk); - } - } - - /** - * 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 fragments the fragments to insert - */ - public final void addChunksAndStack(Hub hub, CallFrame callFrame, TraceFragment... fragments) { - this.addStack(hub); - this.addChunksWithoutStack(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 addChunksAndStack(Hub hub, TraceFragment... fragments) { - this.addStack(hub); - this.addChunksWithoutStack(hub, hub.currentFrame(), fragments); - } - - /** - * Returns the context number associated with the operation encoded by this TraceChunk. - * - * @return the CN - */ - public final int contextNumber() { - return this.lines.get(0).common.contextNumber(); - } - - /** - * Set the new context number associated with the operation encoded by this TraceChunk. - * - * @param contextNumber the new CN - */ - public final void setContextNumber(int contextNumber) { - for (TraceLine chunk : this.lines) { - chunk.common.newContextNumber(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. - * - * @param hub the linked {@link Hub} context - */ - public void seal(Hub hub) { - int nonStackLineNumbers = - (int) this.lines.stream().filter(l -> !(l.specific instanceof StackFragment)).count(); - int nonStackLineCounter = 0; - for (TraceLine chunk : this.lines) { - if (!(chunk.specific instanceof StackFragment)) { - nonStackLineCounter++; - chunk.common.nonStackRowsCounter(nonStackLineCounter); - } - chunk.common.newPc(hub.lastPc()); - chunk.common.newContextNumber(hub.lastContextNumber()); - chunk.common.numberOfNonStackRows(nonStackLineNumbers); - } - } - - /** - * 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(); - } - - /** - * 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(); - } - - /** - * Update this section with the current refunded gas as computed by the hub. - * - * @param refundedGas the refunded gas provided by the hub - */ - public void setFinalGasRefundCounter(long refundedGas) { - for (TraceLine chunk : lines) { - if (chunk.specific instanceof TransactionFragment fragment) { - fragment.setGasRefundFinalCounter(refundedGas); - } - } - } - - /** - * Update the stack fragments of the section with the provided {@link DeploymentExceptions}. - * - * @param contEx the computed exceptions - */ - public void setContextExceptions(DeploymentExceptions contEx) { - for (TraceLine chunk : lines) { - if (chunk.specific instanceof StackFragment fragment) { - fragment.contextExceptions(contEx); - } - } - } - - /** - * This method is called when the transaction is finished to build required information post-hoc. - * - * @param hub the linked {@link Hub} context - */ - public final void postTxRetcon(Hub hub, long leftoverGas, long gasRefund) { - for (TraceLine chunk : lines) { - chunk.common().postTxRetcon(hub); - chunk.common().gasRefund(gasRefund); - chunk.specific().postTxRetcon(hub); - if (chunk.specific instanceof TransactionFragment fragment) { - fragment.setGasRefundAmount(gasRefund); - fragment.setLeftoverGas(leftoverGas); - } - } - } - - /** - * This method is called when the conflation is finished to build required information post-hoc. - * - * @param hub the linked {@link Hub} context - */ - public final void postConflationRetcon(Hub hub, WorldView world) { - for (TraceLine chunk : lines) { - chunk.common().postConflationRetcon(hub); - chunk.specific().postConflationRetcon(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 deleted file mode 100644 index aaa6a81dc..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.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 TransactionSection extends TraceSection { - public TransactionSection(Hub hub, TraceFragment... chunks) { - this.addChunksAndStack(hub, chunks); - } - - @Override - public void seal(Hub hub) {} -} 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 deleted file mode 100644 index 3efcaf631..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.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 TxSkippedSection extends TraceSection { - public TxSkippedSection(Hub hub, TraceFragment... chunks) { - this.addChunksWithoutStack(hub, chunks); - } - - @Override - public void seal(Hub hub) {} -} 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/WarmupSection.java deleted file mode 100644 index 2dd0eba8b..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/WarmupSection.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.module.hub.section; - -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; - -/** - * 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 WarmupSection extends TraceSection { - public WarmupSection(Hub hub, List fragments) { - this.addChunksWithoutStack(hub, fragments.toArray(new TraceFragment[0])); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/WithCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/WithCodeCallSection.java deleted file mode 100644 index 7d064fcea..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/WithCodeCallSection.java +++ /dev/null @@ -1,153 +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.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.fragment.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.ScenarioFragment; -import net.consensys.linea.zktracer.module.hub.fragment.misc.MiscFragment; -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 WithCodeCallSection extends TraceSection - implements PostTransactionDefer, PostExecDefer, NextContextDefer { - private final CallFrame callerCallFrame; - private final int calledCallFrameId; - private final AccountSnapshot preCallCallerAccountSnapshot; - private final AccountSnapshot preCallCalledAccountSnapshot; - - private AccountSnapshot inCallCallerAccountSnapshot; - private AccountSnapshot inCallCalledAccountSnapshot; - - private AccountSnapshot postCallCallerAccountSnapshot; - private AccountSnapshot postCallCalledAccountSnapshot; - - private final MiscFragment miscFragment; - - public WithCodeCallSection( - Hub hub, - AccountSnapshot preCallCallerAccountSnapshot, - AccountSnapshot preCallCalledAccountSnapshot, - MiscFragment miscFragment) { - this.callerCallFrame = hub.currentFrame(); - this.calledCallFrameId = hub.callStack().futureId(); - this.preCallCallerAccountSnapshot = preCallCallerAccountSnapshot; - this.preCallCalledAccountSnapshot = preCallCalledAccountSnapshot; - this.miscFragment = miscFragment; - this.addStack(hub); - } - - @Override - 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 Account calledAccount = frame.getWorldUpdater().get(calledAddress); - - this.postCallCallerAccountSnapshot = - AccountSnapshot.fromAccount( - callerAccount, - frame.isAddressWarm(callerAddress), - hub.conflation().deploymentInfo().number(callerAddress), - hub.conflation().deploymentInfo().isDeploying(callerAddress)); - this.postCallCalledAccountSnapshot = - AccountSnapshot.fromAccount( - calledAccount, - frame.isAddressWarm(calledAddress), - hub.conflation().deploymentInfo().number(calledAddress), - hub.conflation().deploymentInfo().isDeploying(calledAddress)); - } - - @Override - 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 Account calledAccount = frame.getWorldUpdater().get(calledAddress); - - this.inCallCallerAccountSnapshot = - AccountSnapshot.fromAccount( - callerAccount, - frame.isAddressWarm(callerAddress), - hub.conflation().deploymentInfo().number(callerAddress), - hub.conflation().deploymentInfo().isDeploying(callerAddress)); - this.inCallCalledAccountSnapshot = - AccountSnapshot.fromAccount( - calledAccount, - frame.isAddressWarm(calledAddress), - hub.conflation().deploymentInfo().number(calledAddress), - hub.conflation().deploymentInfo().isDeploying(calledAddress)); - } - - @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx) { - final CallFrame calledCallFrame = hub.callStack().get(this.calledCallFrameId); - - this.addChunksWithoutStack( - hub, - callerCallFrame, - new ScenarioFragment(false, true, false, this.callerCallFrame.id(), this.calledCallFrameId), - new ContextFragment(hub.callStack(), hub.currentFrame(), false), - this.miscFragment, - new AccountFragment(this.preCallCallerAccountSnapshot, this.inCallCallerAccountSnapshot), - new AccountFragment(this.preCallCalledAccountSnapshot, this.inCallCalledAccountSnapshot)); - - if (callerCallFrame.hasReverted()) { - if (calledCallFrame.hasReverted()) { - this.addChunksWithoutStack( - hub, - callerCallFrame, - new AccountFragment( - this.inCallCallerAccountSnapshot, this.preCallCallerAccountSnapshot), - new AccountFragment( - this.inCallCalledAccountSnapshot, this.postCallCalledAccountSnapshot), - new AccountFragment( - this.postCallCalledAccountSnapshot, this.preCallCalledAccountSnapshot)); - } else { - this.addChunksWithoutStack( - hub, - callerCallFrame, - new AccountFragment( - this.inCallCallerAccountSnapshot, this.preCallCallerAccountSnapshot), - new AccountFragment( - this.inCallCalledAccountSnapshot, this.preCallCalledAccountSnapshot)); - } - } else { - if (calledCallFrame.hasReverted()) { - this.addChunksWithoutStack( - hub, - callerCallFrame, - new AccountFragment( - this.inCallCallerAccountSnapshot, this.postCallCallerAccountSnapshot), - new AccountFragment( - this.inCallCalledAccountSnapshot, this.postCallCalledAccountSnapshot)); - } - } - - this.addChunksWithoutStack( - hub, callerCallFrame, new ContextFragment(hub.callStack(), hub.currentFrame(), false)); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/subsection/PrecompileScenarioTraceSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/subsection/PrecompileScenarioTraceSubsection.java deleted file mode 100644 index 8350474b1..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/subsection/PrecompileScenarioTraceSubsection.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.subsection; - -import java.util.List; - -import net.consensys.linea.zktracer.module.hub.fragment.SubSection; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; - -public class PrecompileScenarioTraceSubsection implements SubSection { - @Override - public List generate() { - return List.of(); // TODO: - } -} 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 deleted file mode 100644 index d0f214e38..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java +++ /dev/null @@ -1,153 +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; - -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; -import java.util.List; - -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.module.limits.precompiles.EcRecoverEffectiveCall; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -@RequiredArgsConstructor -public class Keccak implements Module { - private static final int ADDRESS_BYTES = 20; - private static final int HASH_BYTES = 32; - 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 final Hub hub; - private final EcRecoverEffectiveCall ecRec; - private final L2Block l2Block; - - private final Deque> deployedCodesizes = new ArrayDeque<>(); - private final Deque> sha3Sizes = new ArrayDeque<>(); - - @Override - public String moduleKey() { - return "BLOCK_KECCAK"; - } - - @Override - public void enterTransaction() { - this.deployedCodesizes.push(new ArrayList<>(5)); - this.sha3Sizes.push(new ArrayList<>(100)); - } - - @Override - public void popTransaction() { - this.deployedCodesizes.pop(); - this.sha3Sizes.pop(); - } - - public static int numKeccak(int x) { - return (x + 136) / 136; - } - - private static int numKeccak(long x) { - final long r = (x + 136) / 136; - Preconditions.checkState(r < Integer.MAX_VALUE, "demented KECCAK"); - return (int) r; - } - - @Override - public void tracePreOpcode(final MessageFrame frame) { - final OpCode opCode = this.hub.opCode(); - - // Capture calls to SHA3 - if (opCode == OpCode.SHA3) { - if (frame.stackSize() > 1) { - final long sha3Size = Words.clampedToLong(frame.getStackItem(1)); - this.sha3Sizes.peek().add(sha3Size); - } - } - - // Capture contract deployment - if (opCode == OpCode.RETURN && hub.currentFrame().underDeployment() && frame.stackSize() > 1) { - final long codeSize = clampedToLong(frame.getStackItem(1)); - this.deployedCodesizes.peek().add(codeSize); - } - } - - @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(); - - // 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() - // 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() - - // From public input computation. This accounts for the hashing of: - // - The block data hash: - // - hashing the list of the transaction hashes - // - hashing the list of the L2L1 messages hashes - // - hashing the list of the from addresses of the transactions - // - hashing the list of the batch reception indices - // - 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 - - // - The top-level structure (with the worst-case assumption, the - // current block is alone in the conflation). This includes: - // - hashing concatenation of the state-root hashes for all blocks +1 - // for the parent state-root hash. - // - hashing the list of the timestamps including the last finalized - // timestamp. - // - hashing the list of the block data hashes. - // - the first block number in the conflation list (formatted over 32 - // 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); - } - - @Override - public List columnsHeaders() { - throw new IllegalStateException("non-tracing module"); - } -} 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 deleted file mode 100644 index 2b384aee0..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/L2Block.java +++ /dev/null @@ -1,150 +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; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; -import java.util.List; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; -import org.apache.tuweni.bytes.Bytes; -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 -public class L2Block implements Module { - private final Address l2l1Address; - private final LogTopic l2l1Topic; - - private static final int ADDRESS_BYTES = 20; - private static final int HASH_BYTES = 32; - private static final int L1_MSG_INDICES_BYTES = 8; - private static final int L1_TIMESTAMPS_BYTES = 8; - private static final int ABI_OFFSET_BYTES = 32; - private static final int ABI_LEN_BYTES = 32; - - /** The byte size of the RLP-encoded transaction of the conflation */ - @Getter private final Deque sizesRlpEncodedTxs = new ArrayDeque<>(); - /** The byte size of the L2->L1 logs messages of the conflation */ - @Getter private final Deque> l2l1LogSizes = new ArrayDeque<>(); - - @Override - public String moduleKey() { - return "BLOCK_L1SIZE"; - } - - @Override - public void enterTransaction() { - this.sizesRlpEncodedTxs.push(0); - this.l2l1LogSizes.push(new ArrayList<>()); - } - - @Override - public void popTransaction() { - this.sizesRlpEncodedTxs.pop(); - this.l2l1LogSizes.pop(); - } - - @Override - public int lineCount() { - final int txCount = this.sizesRlpEncodedTxs.size(); - final int l2L1LogsCount = this.l2l1LogSizes.stream().mapToInt(List::size).sum(); - - // This calculates the data size related to the transaction field of the - // data sent on L1. This field is a double array of byte. Each subarray - // corresponds to an RLP encoded transaction. The abi encoding incurs an - // overhead for each transaction (32 bytes for an offset, and 32 bytes for - // to encode the length of each sub bytes array). This overhead is also - // incurred by the top-level array, hence the +1. - int totalTxsRlpSize = (txCount + 1) * (ABI_OFFSET_BYTES + ABI_LEN_BYTES); - for (int txRlpSize : this.sizesRlpEncodedTxs) { - totalTxsRlpSize += txRlpSize; - } - - // Calculates the data size related to the abi encoding of the list of the - // from addresses. The field is a simple array of bytes20. We need to take - // into account the offset and the length in the ABI encoding. - final int totalFromSize = txCount * ADDRESS_BYTES + ABI_OFFSET_BYTES + ABI_LEN_BYTES; - - // Accumulates the data occupied for the hashes of the L2 to L1 messages - // hashes each of them occupies 32 bytes. Also accounts for the overheads - // of L2 and L1 messages encoding. - final int totalL2L1Logs = HASH_BYTES * l2L1LogsCount + ABI_OFFSET_BYTES + ABI_LEN_BYTES; - - int l1Size = totalTxsRlpSize + totalL2L1Logs + totalFromSize; - - // Account for the overheads of sending the resulting root hash, the - // timestamp and the L1 msg reception. For a sequence of conflated L2 blocks - // , we will need to also need to send the initial timestamp and the parent - // state root hash. Since we cannot forsee, at this point, the number of - // blocks that will be conflated together with this block we make the worst - // assumption that the block will be conflated alone. This corresponds to - // counting twice the root hash and the timestamps. For the L1 messages, we - // unfortunately do not have the data in the tracer yet. For that reason, - // we also make a worst-case assumption that that every transaction is a - // batch reception on layer 2. Finally, since what is sent on L1 is an array - // of L2BlockData, we also make a worst-case assumption that the block will - // be alone in the structure and account for the ABI encoding. - l1Size += - 2 * L1_TIMESTAMPS_BYTES - + // the timestamp - 2 * HASH_BYTES - + // the root hash - L1_MSG_INDICES_BYTES * txCount - + ABI_LEN_BYTES - + ABI_OFFSET_BYTES - + // the L1 messages - ABI_LEN_BYTES - + ABI_OFFSET_BYTES; // abi overheads for the blockdata struct. - - return l1Size; - } - - @Override - public List columnsHeaders() { - throw new IllegalStateException("non-tracing module"); - } - - @Override - public void traceEndTx( - WorldView worldView, - Transaction tx, - boolean isSuccessful, - Bytes output, - List logs, - long gasUsed) { - for (Log log : logs) { - 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()); - } - - public int l2l1LogsCount() { - return this.l2l1LogSizes.stream().mapToInt(List::size).sum(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/L2L1Logs.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/L2L1Logs.java deleted file mode 100644 index 7a6b11d9c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/L2L1Logs.java +++ /dev/null @@ -1,48 +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; - -import java.util.List; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; - -@RequiredArgsConstructor -public class L2L1Logs implements Module { - private final L2Block l2Block; - - @Override - public String moduleKey() { - return "BLOCK_L2L1LOGS"; - } - - @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - return this.l2Block.l2l1LogsCount(); - } - - @Override - public List columnsHeaders() { - return null; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fRounds.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fRounds.java deleted file mode 100644 index 035d74871..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fRounds.java +++ /dev/null @@ -1,107 +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; - -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 org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -@RequiredArgsConstructor -public final class Blake2fRounds implements Module { - final Hub hub; - private final Stack counts = new Stack<>(); - - @Override - public String moduleKey() { - return "PRECOMPILE_BLAKE2F_ROUNDS"; - } - - @Override - public void enterTransaction() { - counts.push(0); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - - switch (opCode) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.BLAKE2B_F_COMPRESSION)) { - long length = 0; - long offset = 0; - switch (opCode) { - case CALL, CALLCODE -> { - length = Words.clampedToLong(frame.getStackItem(4)); - offset = Words.clampedToLong(frame.getStackItem(3)); - } - case DELEGATECALL, STATICCALL -> { - length = Words.clampedToLong(frame.getStackItem(3)); - offset = Words.clampedToLong(frame.getStackItem(2)); - } - } - - final int blake2fDataSize = 213; - if (length == blake2fDataSize) { - final int f = frame.shadowReadMemory(offset, length).get(blake2fDataSize - 1); - if (f == 0 || f == 1) { - final int r = - frame - .shadowReadMemory(offset, length) - .slice(0, 4) - .toInt(); // The number of round is equal to the gas to pay - final long gasPaid = Words.clampedToLong(frame.getStackItem(0)); - if (gasPaid >= r) { - this.counts.push(this.counts.pop() + r); - } - } - } - } - } - default -> {} - } - } - - @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"); - } -} 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 deleted file mode 100644 index 8ddea8297..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddEffectiveCall.java +++ /dev/null @@ -1,85 +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; - -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 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<>(); - - @Override - public String moduleKey() { - return "PRECOMPILE_ECADD_EFFECTIVE_CALL"; - } - - 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(); - - switch (opCode) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.ALTBN128_ADD)) { - final long gasPaid = Words.clampedToLong(frame.getStackItem(0)); - if (gasPaid >= PRECOMPILE_GAS_FEE) { - this.counts.push(this.counts.pop() + 1); - } - } - } - default -> {} - } - } - - @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"); - } -} 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 deleted file mode 100644 index ac45cedc1..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulEffectiveCall.java +++ /dev/null @@ -1,85 +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; - -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 org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -@RequiredArgsConstructor -public final class EcMulEffectiveCall implements Module { - private final Hub hub; - private final Stack counts = new Stack<>(); - - @Override - public String moduleKey() { - return "PRECOMPILE_ECMUL_EFFECTIVE_CALL"; - } - - 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(); - - switch (opCode) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.ALTBN128_MUL)) { - final long gasPaid = Words.clampedToLong(frame.getStackItem(0)); - if (gasPaid >= PRECOMPILE_GAS_FEE) { - this.counts.push(this.counts.pop() + 1); - } - } - } - default -> {} - } - } - - @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"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingCallEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingCallEffectiveCall.java deleted file mode 100644 index 71a8efca7..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingCallEffectiveCall.java +++ /dev/null @@ -1,105 +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; - -import java.nio.MappedByteBuffer; -import java.util.List; -import java.util.Stack; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -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 org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -@Slf4j -@RequiredArgsConstructor -public final class EcPairingCallEffectiveCall implements Module { - private final Hub hub; - @Getter private final Stack counts = new Stack<>(); - private static final int PRECOMPILE_BASE_GAS_FEE = 45000; // cf EIP-1108 - private static final int PRECOMPILE_MILLER_LOOP_GAS_FEE = 34000; // cf EIP-1108 - private static final int ECPAIRING_NB_BYTES_PER_MILLER_LOOP = 192; - - @Override - public String moduleKey() { - return "PRECOMPILE_ECPAIRING_EFFECTIVE_CALL"; - } - - @Override - public void enterTransaction() { - counts.push(new EcPairingLimit(0, 0)); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - - switch (opCode) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.ALTBN128_PAIRING)) { - long length = 0; - switch (opCode) { - case CALL, CALLCODE -> length = Words.clampedToLong(frame.getStackItem(4)); - case DELEGATECALL, STATICCALL -> length = Words.clampedToLong(frame.getStackItem(3)); - } - - final long nMillerLoop = (length / ECPAIRING_NB_BYTES_PER_MILLER_LOOP); - if (nMillerLoop * ECPAIRING_NB_BYTES_PER_MILLER_LOOP != length) { - log.warn("[ECPairing] Argument is not a right size: " + length); - return; - } - - final long gasPaid = Words.clampedToLong(frame.getStackItem(0)); - if (gasPaid >= PRECOMPILE_BASE_GAS_FEE + PRECOMPILE_MILLER_LOOP_GAS_FEE * nMillerLoop) { - final EcPairingLimit lastEcpairingLimit = this.counts.pop(); - this.counts.push( - new EcPairingLimit( - lastEcpairingLimit.nPrecompileCall() + 1, - lastEcpairingLimit.nMillerLoop() + nMillerLoop)); - } - } - } - default -> {} - } - } - - @Override - public int lineCount() { - return this.counts.stream().mapToInt(EcPairingLimit::nPrecompileCall).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"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingLimit.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingLimit.java deleted file mode 100644 index b2af67b2e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingLimit.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 EcPairingLimit(int nPrecompileCall, long nMillerLoop) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoop.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoop.java deleted file mode 100644 index ff0fd622f..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoop.java +++ /dev/null @@ -1,61 +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; - -import java.nio.MappedByteBuffer; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; - -public final class EcPairingMillerLoop implements Module { - private final EcPairingCallEffectiveCall ecpairingCall; - - public EcPairingMillerLoop(EcPairingCallEffectiveCall ecpairingCall) { - this.ecpairingCall = ecpairingCall; - } - - @Override - public String moduleKey() { - return "PRECOMPILE_ECPAIRING_MILLER_LOOP"; - } - - @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - final long r = ecpairingCall.getCounts().stream().mapToLong(EcPairingLimit::nMillerLoop).sum(); - if (r > Integer.MAX_VALUE) { - throw new RuntimeException("Ludicrous EcPairing calls"); - } - - return (int) 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"); - } -} 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 deleted file mode 100644 index 904880f12..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverEffectiveCall.java +++ /dev/null @@ -1,115 +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; - -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 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 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 EcRecoverEffectiveCall implements Module { - private final Hub hub; - private final Stack counts = new Stack<>(); - - @Override - public String moduleKey() { - return "PRECOMPILE_ECRECOVER_EFFECTIVE_CALL"; - } - - 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(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - - switch (opCode) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.ECREC)) { - long length = 0; - long offset = 0; - switch (opCode) { - case CALL, CALLCODE -> { - length = Words.clampedToLong(frame.getStackItem(4)); - offset = Words.clampedToLong(frame.getStackItem(3)); - } - case DELEGATECALL, STATICCALL -> { - length = Words.clampedToLong(frame.getStackItem(3)); - offset = Words.clampedToLong(frame.getStackItem(2)); - } - } - final Bytes inputData = frame.shadowReadMemory(offset, 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(); - final long gasPaid = Words.clampedToLong(frame.getStackItem(0)); - // TODO: exclude case without valid signature - if (gasPaid >= ECRECOVER_GAS_FEE - && (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) { - this.counts.push(this.counts.pop() + 1); - } - } - } - default -> {} - } - } - - @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"); - } -} 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 deleted file mode 100644 index f8590f309..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.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.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 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.module.modexpdata.ModexpData; -import net.consensys.linea.zktracer.module.modexpdata.ModexpDataOperation; -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; - -@Slf4j -@RequiredArgsConstructor -@Accessors(fluent = true) -public class ModexpEffectiveCall implements Module { - private final Hub hub; - - @Getter private final ModexpData data = new ModexpData(); - private final Stack counts = new Stack<>(); - private static final BigInteger PROVER_MAX_INPUT_BIT_SIZE = BigInteger.valueOf(4096); - private static final int EVM_WORD_SIZE = 32; - - private int lastModexpDataCallHubStamp = 0; - - @Override - public String moduleKey() { - return "PRECOMPILE_MODEXP_EFFECTIVE_CALL"; - } - - @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.isAnyOf(OpCode.CALL, OpCode.STATICCALL, OpCode.DELEGATECALL, OpCode.CALLCODE)) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.MODEXP)) { - long length = 0; - long offset = 0; - switch (opCode) { - case CALL, CALLCODE -> { - length = Words.clampedToLong(frame.getStackItem(4)); - offset = Words.clampedToLong(frame.getStackItem(3)); - } - case DELEGATECALL, STATICCALL -> { - length = Words.clampedToLong(frame.getStackItem(3)); - offset = Words.clampedToLong(frame.getStackItem(2)); - } - } - final Bytes inputData = frame.shadowReadMemory(offset, length); - - // Get the Base length - final BigInteger baseLength = slice(inputData, 0, EVM_WORD_SIZE).toUnsignedBigInteger(); - if (isInProverInputBounds(baseLength)) { - log.info( - "Too big argument, base bit length = {} > {}", baseLength, PROVER_MAX_INPUT_BIT_SIZE); - this.counts.pop(); - this.counts.push(Integer.MAX_VALUE); - return; - } - - // Get the Exponent length - final BigInteger expLength = - slice(inputData, EVM_WORD_SIZE, EVM_WORD_SIZE).toUnsignedBigInteger(); - if (isInProverInputBounds(expLength)) { - log.info( - "Too big argument, expComponent bit length = {} > {}", - expLength, - PROVER_MAX_INPUT_BIT_SIZE); - this.counts.pop(); - this.counts.push(Integer.MAX_VALUE); - return; - } - - // Get the Modulo length - final BigInteger modLength = - slice(inputData, 2 * EVM_WORD_SIZE, EVM_WORD_SIZE).toUnsignedBigInteger(); - if (isInProverInputBounds(modLength)) { - log.info( - "Too big argument, modulo bit length = {} > {}", - modLength, - PROVER_MAX_INPUT_BIT_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 * EVM_WORD_SIZE, baseLengthInt); - - // Get the Exponent. - final Bytes expComponent = - slice(inputData, 3 * EVM_WORD_SIZE + baseLengthInt, expLength.intValueExact()); - - // Get the Modulus. - final Bytes modComponent = - slice( - inputData, - 3 * EVM_WORD_SIZE + baseLengthInt + expLengthInt, - modLength.intValueExact()); - - final long gasPaid = Words.clampedToLong(frame.getStackItem(0)); - final long gasPrice = gasPrice(baseLengthInt, expLengthInt, modLengthInt, expComponent); - - // If enough gas, add 1 to the call of the precompile. - if (gasPaid >= gasPrice) { - this.lastModexpDataCallHubStamp = - this.data.call( - new ModexpDataOperation( - hub.stamp(), - lastModexpDataCallHubStamp, - baseComponent, - expComponent, - modComponent)); - this.counts.push(this.counts.pop() + 1); - } - } - } - } - - private long gasPrice(int baseLength, int expLength, int moduloLength, Bytes e) { - final long maxLbLmSquared = - (long) Math.sqrt((double) (Math.max(baseLength, moduloLength) + 7) / 8); - final long secondArg = (maxLbLmSquared * expLengthPrime(expLength, e)) / 3; - - return Math.max(200, secondArg); - } - - private int expLengthPrime(int expLength, Bytes e) { - if (expLength <= 32) { - if (e.toUnsignedBigInteger().equals(BigInteger.ZERO)) { - return 0; - } - return e.toUnsignedBigInteger().bitLength() - 1; - } else if (e.slice(0, EVM_WORD_SIZE).toUnsignedBigInteger().compareTo(BigInteger.ZERO) != 0) { - return 8 * (expLength - 32) - + e.slice(0, EVM_WORD_SIZE).toUnsignedBigInteger().bitLength() - - 1; - } - - return 8 * (expLength - 32); - } - - private boolean isInProverInputBounds(BigInteger modexpComponentLength) { - return modexpComponentLength - .multiply(BigInteger.valueOf(8)) - .compareTo(PROVER_MAX_INPUT_BIT_SIZE) - > 0; - } - - @Override - public int lineCount() { - return this.counts.stream().mapToInt(x -> x).sum(); - } - - @Override - public List columnsHeaders() { - throw new UnsupportedOperationException("should never be called"); - } - - @Override - public void commit(List buffers) { - throw new UnsupportedOperationException("should never be called"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160Blocks.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160Blocks.java deleted file mode 100644 index aa4b5c328..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160Blocks.java +++ /dev/null @@ -1,111 +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; - -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 org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -@RequiredArgsConstructor -public final class Rip160Blocks implements Module { - private final Hub hub; - private final Stack counts = new Stack<>(); - - @Override - public String moduleKey() { - return "PRECOMPILE_RIPEMD_BLOCKS"; - } - - 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; - // If the length is > 2⁶4, we just use the lower 64 bits. - private static final int RIPEMD160_LENGTH_APPEND = 64; - private static final int RIPEMD160_ND_PADDED_ONE = 1; - - @Override - public void enterTransaction() { - counts.push(0); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - - switch (opCode) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.RIPEMD160)) { - long dataByteLength = 0; - switch (opCode) { - case CALL, CALLCODE -> dataByteLength = Words.clampedToLong(frame.getStackItem(4)); - case DELEGATECALL, STATICCALL -> dataByteLength = - Words.clampedToLong(frame.getStackItem(3)); - } - - 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 + 31) / 32; - final long gasPaid = Words.clampedToLong(frame.getStackItem(0)); - final long gasNeeded = PRECOMPILE_BASE_GAS_FEE + PRECOMPILE_GAS_FEE_PER_EWORD * wordCount; - - if (gasPaid >= gasNeeded) { - this.counts.push(this.counts.pop() + blockCount); - } - } - } - default -> {} - } - } - - @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"); - } -} 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 deleted file mode 100644 index 4fba3b508..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java +++ /dev/null @@ -1,110 +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; - -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 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 { - private final Hub hub; - private final Stack counts = new Stack<>(); - - @Override - public String moduleKey() { - return "PRECOMPILE_SHA2_BLOCKS"; - } - - private static final int PRECOMPILE_BASE_GAS_FEE = 60; - private static final int PRECOMPILE_GAS_FEE_PER_EWORD = 12; - private static final int SHA256_BLOCKSIZE = 64 * 8; - // The length of the data to be hashed is 2**64 maximum. - private static final int SHA256_PADDING_LENGTH = 64; - private static final int SHA256_NB_PADDED_ONE = 1; - - @Override - public void enterTransaction() { - counts.push(0); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - - switch (opCode) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.SHA256)) { - long dataByteLength = 0; - switch (opCode) { - case CALL, CALLCODE -> dataByteLength = Words.clampedToLong(frame.getStackItem(4)); - case DELEGATECALL, STATICCALL -> dataByteLength = - Words.clampedToLong(frame.getStackItem(3)); - } - if (dataByteLength == 0) { - return; - } // skip trivial hash TODO: check the prover does skip it - final int blockCount = - (int) - (dataByteLength * 8 - + SHA256_NB_PADDED_ONE - + SHA256_PADDING_LENGTH - + (SHA256_BLOCKSIZE - 1)) - / SHA256_BLOCKSIZE; - - final long wordCount = (dataByteLength + 31) / 32; - final long gasPaid = Words.clampedToLong(frame.getStackItem(0)); - final long gasNeeded = PRECOMPILE_BASE_GAS_FEE + PRECOMPILE_GAS_FEE_PER_EWORD * wordCount; - - if (gasPaid >= gasNeeded) { - this.counts.push(this.counts.pop() + blockCount); - } - } - } - default -> {} - } - } - - @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"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/LogData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/LogData.java deleted file mode 100644 index 3f2c936e3..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/LogData.java +++ /dev/null @@ -1,136 +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.logData; - -import static net.consensys.linea.zktracer.types.Utils.rightPadTo; - -import java.math.BigInteger; -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.module.rlp.txrcpt.RlpTxrcpt; -import net.consensys.linea.zktracer.module.rlp.txrcpt.RlpTxrcptChunk; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.log.Log; - -public class LogData implements Module { - private final RlpTxrcpt rlpTxrcpt; - - public LogData(RlpTxrcpt rlpTxrcpt) { - this.rlpTxrcpt = rlpTxrcpt; - } - - @Override - public String moduleKey() { - return "PUB_LOG"; - } - - @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - int rowSize = 0; - for (RlpTxrcptChunk tx : this.rlpTxrcpt.getChunkList()) { - rowSize += txRowSize(tx); - } - return rowSize; - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - private int txRowSize(RlpTxrcptChunk tx) { - int txRowSize = 0; - if (tx.logs().isEmpty()) { - return 0; - } else { - for (Log log : tx.logs()) { - txRowSize += indexMax(log) + 1; - } - return txRowSize; - } - } - - private int indexMax(Log log) { - return log.getData().isEmpty() ? 0 : (log.getData().size() - 1) / 16; - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - int absLogNumMax = 0; - for (RlpTxrcptChunk tx : this.rlpTxrcpt.chunkList) { - absLogNumMax += tx.logs().size(); - } - - int absLogNum = 0; - for (RlpTxrcptChunk tx : this.rlpTxrcpt.chunkList) { - if (!tx.logs().isEmpty()) { - for (Log log : tx.logs()) { - absLogNum += 1; - if (log.getData().isEmpty()) { - traceLogWoData(absLogNum, absLogNumMax, trace); - } else { - traceLog(log, absLogNum, absLogNumMax, trace); - } - } - } - } - } - - public void traceLogWoData(final int absLogNum, final int absLogNumMax, Trace trace) { - trace - .absLogNumMax(BigInteger.valueOf(absLogNumMax)) - .absLogNum(BigInteger.valueOf(absLogNum)) - .logsData(false) - .sizeTotal(BigInteger.ZERO) - .sizeAcc(BigInteger.ZERO) - .sizeLimb(BigInteger.ZERO) - .limb(BigInteger.ZERO) - .index(BigInteger.ZERO) - .validateRow(); - } - - public void traceLog(final Log log, final int absLogNum, final int absLogNumMax, Trace trace) { - final int indexMax = indexMax(log); - final Bytes dataPadded = rightPadTo(log.getData(), (indexMax + 1) * 16); - final int lastLimbSize = (log.getData().size() % 16 == 0) ? 16 : log.getData().size() % 16; - for (int index = 0; index < indexMax + 1; index++) { - trace - .absLogNumMax(BigInteger.valueOf(absLogNumMax)) - .absLogNum(BigInteger.valueOf(absLogNum)) - .logsData(true) - .sizeTotal(BigInteger.valueOf(log.getData().size())) - .sizeAcc( - index == indexMax - ? BigInteger.valueOf(log.getData().size()) - : BigInteger.valueOf(16 * (index + 1))) - .sizeLimb(index == indexMax ? BigInteger.valueOf(lastLimbSize) : BigInteger.valueOf(16)) - .limb(dataPadded.slice(16 * index, 16).toUnsignedBigInteger()) - .index(BigInteger.valueOf(index)) - .validateRow(); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/LogDataTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/LogDataTrace.java deleted file mode 100644 index 1faef7e8e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/LogDataTrace.java +++ /dev/null @@ -1,51 +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.logData; - -import com.fasterxml.jackson.annotation.JsonProperty; -import net.consensys.linea.zktracer.module.ModuleTrace; - -/** - * WARNING: This code is generated automatically. Any modifications to this code may be overwritten - * and could lead to unexpected behavior. Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -record LogDataTrace(@JsonProperty("Trace") Trace trace) implements ModuleTrace { - static final int CREATE2_SHIFT = 255; - static final int G_TXDATA_NONZERO = 16; - static final int G_TXDATA_ZERO = 4; - static final int INT_LONG = 183; - static final int INT_SHORT = 128; - static final int LIST_LONG = 247; - static final int LIST_SHORT = 192; - static final int LLARGE = 16; - static final int LLARGEMO = 15; - static final int RLPADDR_CONST_RECIPE_1 = 1; - static final int RLPADDR_CONST_RECIPE_2 = 2; - static final int RLPRECEIPT_SUBPHASE_ID_ADDR = 53; - static final int RLPRECEIPT_SUBPHASE_ID_CUMUL_GAS = 3; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_LIMB = 77; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_SIZE = 83; - static final int RLPRECEIPT_SUBPHASE_ID_NO_LOG_ENTRY = 11; - static final int RLPRECEIPT_SUBPHASE_ID_STATUS_CODE = 2; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE = 65; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA = 96; - static final int RLPRECEIPT_SUBPHASE_ID_TYPE = 7; - - @Override - public int length() { - return this.trace.size(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/Trace.java deleted file mode 100644 index 8d5f4ecab..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logData/Trace.java +++ /dev/null @@ -1,276 +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.logData; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - static final int CREATE2_SHIFT = 255; - static final int G_TXDATA_NONZERO = 16; - static final int G_TXDATA_ZERO = 4; - static final int INT_LONG = 183; - static final int INT_SHORT = 128; - static final int LIST_LONG = 247; - static final int LIST_SHORT = 192; - static final int LLARGE = 16; - static final int LLARGEMO = 15; - static final int RLPADDR_CONST_RECIPE_1 = 1; - static final int RLPADDR_CONST_RECIPE_2 = 2; - static final int RLPRECEIPT_SUBPHASE_ID_ADDR = 53; - static final int RLPRECEIPT_SUBPHASE_ID_CUMUL_GAS = 3; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_LIMB = 77; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_SIZE = 83; - static final int RLPRECEIPT_SUBPHASE_ID_NO_LOG_ENTRY = 11; - static final int RLPRECEIPT_SUBPHASE_ID_STATUS_CODE = 2; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE = 65; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA = 96; - static final int RLPRECEIPT_SUBPHASE_ID_TYPE = 7; - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer absLogNum; - private final MappedByteBuffer absLogNumMax; - private final MappedByteBuffer index; - private final MappedByteBuffer limb; - private final MappedByteBuffer logsData; - private final MappedByteBuffer sizeAcc; - private final MappedByteBuffer sizeLimb; - private final MappedByteBuffer sizeTotal; - - static List headers(int length) { - return List.of( - new ColumnHeader("logData.ABS_LOG_NUM", 32, length), - new ColumnHeader("logData.ABS_LOG_NUM_MAX", 32, length), - new ColumnHeader("logData.INDEX", 32, length), - new ColumnHeader("logData.LIMB", 32, length), - new ColumnHeader("logData.LOGS_DATA", 1, length), - new ColumnHeader("logData.SIZE_ACC", 32, length), - new ColumnHeader("logData.SIZE_LIMB", 32, length), - new ColumnHeader("logData.SIZE_TOTAL", 32, length)); - } - - public Trace(List buffers) { - this.absLogNum = buffers.get(0); - this.absLogNumMax = buffers.get(1); - this.index = buffers.get(2); - this.limb = buffers.get(3); - this.logsData = buffers.get(4); - this.sizeAcc = buffers.get(5); - this.sizeLimb = buffers.get(6); - this.sizeTotal = buffers.get(7); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace absLogNum(final BigInteger b) { - if (filled.get(0)) { - throw new IllegalStateException("logData.ABS_LOG_NUM already set"); - } else { - filled.set(0); - } - - absLogNum.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace absLogNumMax(final BigInteger b) { - if (filled.get(1)) { - throw new IllegalStateException("logData.ABS_LOG_NUM_MAX already set"); - } else { - filled.set(1); - } - - absLogNumMax.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace index(final BigInteger b) { - if (filled.get(2)) { - throw new IllegalStateException("logData.INDEX already set"); - } else { - filled.set(2); - } - - index.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace limb(final BigInteger b) { - if (filled.get(3)) { - throw new IllegalStateException("logData.LIMB already set"); - } else { - filled.set(3); - } - - limb.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace logsData(final Boolean b) { - if (filled.get(4)) { - throw new IllegalStateException("logData.LOGS_DATA already set"); - } else { - filled.set(4); - } - - logsData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace sizeAcc(final BigInteger b) { - if (filled.get(5)) { - throw new IllegalStateException("logData.SIZE_ACC already set"); - } else { - filled.set(5); - } - - sizeAcc.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace sizeLimb(final BigInteger b) { - if (filled.get(6)) { - throw new IllegalStateException("logData.SIZE_LIMB already set"); - } else { - filled.set(6); - } - - sizeLimb.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace sizeTotal(final BigInteger b) { - if (filled.get(7)) { - throw new IllegalStateException("logData.SIZE_TOTAL already set"); - } else { - filled.set(7); - } - - sizeTotal.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("logData.ABS_LOG_NUM has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("logData.ABS_LOG_NUM_MAX has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("logData.INDEX has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("logData.LIMB has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("logData.LOGS_DATA has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("logData.SIZE_ACC has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("logData.SIZE_LIMB has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("logData.SIZE_TOTAL has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - absLogNum.position(absLogNum.position() + 32); - } - - if (!filled.get(1)) { - absLogNumMax.position(absLogNumMax.position() + 32); - } - - if (!filled.get(2)) { - index.position(index.position() + 32); - } - - if (!filled.get(3)) { - limb.position(limb.position() + 32); - } - - if (!filled.get(4)) { - logsData.position(logsData.position() + 1); - } - - if (!filled.get(5)) { - sizeAcc.position(sizeAcc.position() + 32); - } - - if (!filled.get(6)) { - sizeLimb.position(sizeLimb.position() + 32); - } - - if (!filled.get(7)) { - sizeTotal.position(sizeTotal.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/LogInfo.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/LogInfo.java deleted file mode 100644 index 3750abc5e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/LogInfo.java +++ /dev/null @@ -1,231 +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.logInfo; - -import java.math.BigInteger; -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.module.rlp.txrcpt.RlpTxrcpt; -import net.consensys.linea.zktracer.module.rlp.txrcpt.RlpTxrcptChunk; -import org.apache.tuweni.bytes.Bytes32; -import org.hyperledger.besu.evm.log.Log; - -public class LogInfo implements Module { - private final RlpTxrcpt rlpTxrcpt; - - public LogInfo(RlpTxrcpt rlpTxrcpt) { - this.rlpTxrcpt = rlpTxrcpt; - } - - private static final int LOG0 = 0xa0; // TODO why I don't get it from the .lisp ? - - @Override - public String moduleKey() { - return "PUB_LOG_INFO"; - } - - @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - int rowSize = 0; - for (RlpTxrcptChunk chunk : this.rlpTxrcpt.getChunkList()) { - rowSize += txRowSize(chunk); - } - return rowSize; - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - int absLogNumMax = 0; - for (RlpTxrcptChunk tx : this.rlpTxrcpt.chunkList) { - absLogNumMax += tx.logs().size(); - } - - int absTxNum = 0; - int absLogNum = 0; - for (RlpTxrcptChunk tx : this.rlpTxrcpt.chunkList) { - absTxNum += 1; - if (tx.logs().isEmpty()) { - traceTxWoLog(absTxNum, absLogNum, absLogNumMax, trace); - } else { - for (Log log : tx.logs()) { - absLogNum += 1; - traceLog(log, absTxNum, absLogNum, absLogNumMax, trace); - } - } - } - } - - private int txRowSize(RlpTxrcptChunk tx) { - int txRowSize = 0; - if (tx.logs().isEmpty()) { - return 1; - } else { - for (Log log : tx.logs()) { - txRowSize += ctMax(log) + 1; - } - return txRowSize; - } - } - - public void traceTxWoLog( - final int absTxNum, final int absLogNum, final int absLogNumMax, Trace trace) { - trace - .absTxnNumMax(BigInteger.valueOf(this.rlpTxrcpt.chunkList.size())) - .absTxnNum(BigInteger.valueOf(absTxNum)) - .txnEmitsLogs(false) - .absLogNumMax(BigInteger.valueOf(absLogNumMax)) - .absLogNum(BigInteger.valueOf(absLogNum)) - .ctMax(BigInteger.ZERO) - .ct(BigInteger.ZERO) - .addrHi(BigInteger.ZERO) - .addrLo(BigInteger.ZERO) - .topicHi1(BigInteger.ZERO) - .topicLo1(BigInteger.ZERO) - .topicHi2(BigInteger.ZERO) - .topicLo2(BigInteger.ZERO) - .topicHi3(BigInteger.ZERO) - .topicLo3(BigInteger.ZERO) - .topicHi4(BigInteger.ZERO) - .topicLo4(BigInteger.ZERO) - .dataSize(BigInteger.ZERO) - .inst(BigInteger.ZERO) - .isLogX0(false) - .isLogX1(false) - .isLogX2(false) - .isLogX3(false) - .isLogX4(false) - .phase(BigInteger.valueOf(LogInfoTrace.RLPRECEIPT_SUBPHASE_ID_NO_LOG_ENTRY)) - .dataHi(BigInteger.ZERO) - .dataLo(BigInteger.ZERO) - .validateRow(); - } - - public void traceLog( - final Log log, final int absTxNum, final int absLogNum, final int absLogNumMax, Trace trace) { - final int ctMax = ctMax(log); - final int nbTopic = log.getTopics().size(); - final Bytes32 topic1 = nbTopic >= 1 ? log.getTopics().get(0) : Bytes32.ZERO; - final Bytes32 topic2 = nbTopic >= 2 ? log.getTopics().get(1) : Bytes32.ZERO; - final Bytes32 topic3 = nbTopic >= 3 ? log.getTopics().get(2) : Bytes32.ZERO; - final Bytes32 topic4 = nbTopic >= 4 ? log.getTopics().get(3) : Bytes32.ZERO; - for (int ct = 0; ct < ctMax + 1; ct++) { - trace - .absTxnNumMax(BigInteger.valueOf(this.rlpTxrcpt.chunkList.size())) - .absTxnNum(BigInteger.valueOf(absTxNum)) - .txnEmitsLogs(true) - .absLogNumMax(BigInteger.valueOf(absLogNumMax)) - .absLogNum(BigInteger.valueOf(absLogNum)) - .ctMax(BigInteger.valueOf(ctMax)) - .ct(BigInteger.valueOf(ct)) - .addrHi(log.getLogger().slice(0, 4).toUnsignedBigInteger()) - .addrLo(log.getLogger().slice(4, 16).toUnsignedBigInteger()) - .topicHi1(topic1.slice(0, 16).toUnsignedBigInteger()) - .topicLo1(topic1.slice(16, 16).toUnsignedBigInteger()) - .topicHi2(topic2.slice(0, 16).toUnsignedBigInteger()) - .topicLo2(topic2.slice(16, 16).toUnsignedBigInteger()) - .topicHi3(topic3.slice(0, 16).toUnsignedBigInteger()) - .topicLo3(topic3.slice(16, 16).toUnsignedBigInteger()) - .topicHi4(topic4.slice(0, 16).toUnsignedBigInteger()) - .topicLo4(topic4.slice(16, 16).toUnsignedBigInteger()) - .dataSize(BigInteger.valueOf(log.getData().size())) - .inst(BigInteger.valueOf(LOG0 + nbTopic)) - .isLogX0(nbTopic == 0) - .isLogX1(nbTopic == 1) - .isLogX2(nbTopic == 2) - .isLogX3(nbTopic == 3) - .isLogX4(nbTopic == 4); - - switch (ct) { - case 0 -> { - trace - .phase(BigInteger.valueOf(LogInfoTrace.RLPRECEIPT_SUBPHASE_ID_DATA_SIZE)) - .dataHi(BigInteger.valueOf(log.getData().size())) - .dataLo(BigInteger.valueOf(nbTopic)) - .validateRow(); - } - case 1 -> { - trace - .phase(BigInteger.valueOf(LogInfoTrace.RLPRECEIPT_SUBPHASE_ID_ADDR)) - .dataHi(log.getLogger().slice(0, 4).toUnsignedBigInteger()) - .dataLo(log.getLogger().slice(4, 16).toUnsignedBigInteger()) - .validateRow(); - } - case 2 -> { - trace - .phase( - BigInteger.valueOf( - LogInfoTrace.RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE - + LogInfoTrace.RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA)) - .dataHi(topic1.slice(0, 16).toUnsignedBigInteger()) - .dataLo(topic1.slice(16, 16).toUnsignedBigInteger()) - .validateRow(); - } - case 3 -> { - trace - .phase( - BigInteger.valueOf( - LogInfoTrace.RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE - + 2 * LogInfoTrace.RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA)) - .dataHi(topic2.slice(0, 16).toUnsignedBigInteger()) - .dataLo(topic2.slice(16, 16).toUnsignedBigInteger()) - .validateRow(); - } - case 4 -> { - trace - .phase( - BigInteger.valueOf( - LogInfoTrace.RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE - + 3 * LogInfoTrace.RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA)) - .dataHi(topic3.slice(0, 16).toUnsignedBigInteger()) - .dataLo(topic3.slice(16, 16).toUnsignedBigInteger()) - .validateRow(); - } - case 5 -> { - trace - .phase( - BigInteger.valueOf( - LogInfoTrace.RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE - + 4 * LogInfoTrace.RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA)) - .dataHi(topic4.slice(0, 16).toUnsignedBigInteger()) - .dataLo(topic4.slice(16, 16).toUnsignedBigInteger()) - .validateRow(); - } - default -> throw new IllegalArgumentException( - "ct = " + ct + " greater than ctMax =" + ctMax); - } - } - } - - private int ctMax(Log log) { - return log.getTopics().size() + 1; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/LogInfoTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/LogInfoTrace.java deleted file mode 100644 index 7f3752129..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/LogInfoTrace.java +++ /dev/null @@ -1,51 +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.logInfo; - -import com.fasterxml.jackson.annotation.JsonProperty; -import net.consensys.linea.zktracer.module.ModuleTrace; - -/** - * WARNING: This code is generated automatically. Any modifications to this code may be overwritten - * and could lead to unexpected behavior. Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -record LogInfoTrace(@JsonProperty("Trace") Trace trace) implements ModuleTrace { - static final int CREATE2_SHIFT = 255; - static final int G_TXDATA_NONZERO = 16; - static final int G_TXDATA_ZERO = 4; - static final int INT_LONG = 183; - static final int INT_SHORT = 128; - static final int LIST_LONG = 247; - static final int LIST_SHORT = 192; - static final int LLARGE = 16; - static final int LLARGEMO = 15; - static final int RLPADDR_CONST_RECIPE_1 = 1; - static final int RLPADDR_CONST_RECIPE_2 = 2; - static final int RLPRECEIPT_SUBPHASE_ID_ADDR = 53; - static final int RLPRECEIPT_SUBPHASE_ID_CUMUL_GAS = 3; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_LIMB = 77; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_SIZE = 83; - static final int RLPRECEIPT_SUBPHASE_ID_NO_LOG_ENTRY = 11; - static final int RLPRECEIPT_SUBPHASE_ID_STATUS_CODE = 2; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE = 65; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA = 96; - static final int RLPRECEIPT_SUBPHASE_ID_TYPE = 7; - - @Override - public int length() { - return this.trace.size(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/Trace.java deleted file mode 100644 index 64dccfb02..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/logInfo/Trace.java +++ /dev/null @@ -1,713 +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.logInfo; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - static final int CREATE2_SHIFT = 255; - static final int G_TXDATA_NONZERO = 16; - static final int G_TXDATA_ZERO = 4; - static final int INT_LONG = 183; - static final int INT_SHORT = 128; - static final int LIST_LONG = 247; - static final int LIST_SHORT = 192; - static final int LLARGE = 16; - static final int LLARGEMO = 15; - static final int RLPADDR_CONST_RECIPE_1 = 1; - static final int RLPADDR_CONST_RECIPE_2 = 2; - static final int RLPRECEIPT_SUBPHASE_ID_ADDR = 53; - static final int RLPRECEIPT_SUBPHASE_ID_CUMUL_GAS = 3; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_LIMB = 77; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_SIZE = 83; - static final int RLPRECEIPT_SUBPHASE_ID_NO_LOG_ENTRY = 11; - static final int RLPRECEIPT_SUBPHASE_ID_STATUS_CODE = 2; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE = 65; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA = 96; - static final int RLPRECEIPT_SUBPHASE_ID_TYPE = 7; - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer absLogNum; - private final MappedByteBuffer absLogNumMax; - private final MappedByteBuffer absTxnNum; - private final MappedByteBuffer absTxnNumMax; - private final MappedByteBuffer addrHi; - private final MappedByteBuffer addrLo; - private final MappedByteBuffer ct; - private final MappedByteBuffer ctMax; - private final MappedByteBuffer dataHi; - private final MappedByteBuffer dataLo; - private final MappedByteBuffer dataSize; - private final MappedByteBuffer inst; - private final MappedByteBuffer isLogX0; - private final MappedByteBuffer isLogX1; - private final MappedByteBuffer isLogX2; - private final MappedByteBuffer isLogX3; - private final MappedByteBuffer isLogX4; - private final MappedByteBuffer phase; - private final MappedByteBuffer topicHi1; - private final MappedByteBuffer topicHi2; - private final MappedByteBuffer topicHi3; - private final MappedByteBuffer topicHi4; - private final MappedByteBuffer topicLo1; - private final MappedByteBuffer topicLo2; - private final MappedByteBuffer topicLo3; - private final MappedByteBuffer topicLo4; - private final MappedByteBuffer txnEmitsLogs; - - static List headers(int length) { - return List.of( - new ColumnHeader("logInfo.ABS_LOG_NUM", 32, length), - new ColumnHeader("logInfo.ABS_LOG_NUM_MAX", 32, length), - new ColumnHeader("logInfo.ABS_TXN_NUM", 32, length), - new ColumnHeader("logInfo.ABS_TXN_NUM_MAX", 32, length), - new ColumnHeader("logInfo.ADDR_HI", 32, length), - new ColumnHeader("logInfo.ADDR_LO", 32, length), - new ColumnHeader("logInfo.CT", 32, length), - new ColumnHeader("logInfo.CT_MAX", 32, length), - new ColumnHeader("logInfo.DATA_HI", 32, length), - new ColumnHeader("logInfo.DATA_LO", 32, length), - new ColumnHeader("logInfo.DATA_SIZE", 32, length), - new ColumnHeader("logInfo.INST", 32, length), - new ColumnHeader("logInfo.IS_LOG_X_0", 1, length), - new ColumnHeader("logInfo.IS_LOG_X_1", 1, length), - new ColumnHeader("logInfo.IS_LOG_X_2", 1, length), - new ColumnHeader("logInfo.IS_LOG_X_3", 1, length), - new ColumnHeader("logInfo.IS_LOG_X_4", 1, length), - new ColumnHeader("logInfo.PHASE", 32, length), - new ColumnHeader("logInfo.TOPIC_HI_1", 32, length), - new ColumnHeader("logInfo.TOPIC_HI_2", 32, length), - new ColumnHeader("logInfo.TOPIC_HI_3", 32, length), - new ColumnHeader("logInfo.TOPIC_HI_4", 32, length), - new ColumnHeader("logInfo.TOPIC_LO_1", 32, length), - new ColumnHeader("logInfo.TOPIC_LO_2", 32, length), - new ColumnHeader("logInfo.TOPIC_LO_3", 32, length), - new ColumnHeader("logInfo.TOPIC_LO_4", 32, length), - new ColumnHeader("logInfo.TXN_EMITS_LOGS", 1, length)); - } - - public Trace(List buffers) { - this.absLogNum = buffers.get(0); - this.absLogNumMax = buffers.get(1); - this.absTxnNum = buffers.get(2); - this.absTxnNumMax = buffers.get(3); - this.addrHi = buffers.get(4); - this.addrLo = buffers.get(5); - this.ct = buffers.get(6); - this.ctMax = buffers.get(7); - this.dataHi = buffers.get(8); - this.dataLo = buffers.get(9); - this.dataSize = buffers.get(10); - this.inst = buffers.get(11); - this.isLogX0 = buffers.get(12); - this.isLogX1 = buffers.get(13); - this.isLogX2 = buffers.get(14); - this.isLogX3 = buffers.get(15); - this.isLogX4 = buffers.get(16); - this.phase = buffers.get(17); - this.topicHi1 = buffers.get(18); - this.topicHi2 = buffers.get(19); - this.topicHi3 = buffers.get(20); - this.topicHi4 = buffers.get(21); - this.topicLo1 = buffers.get(22); - this.topicLo2 = buffers.get(23); - this.topicLo3 = buffers.get(24); - this.topicLo4 = buffers.get(25); - this.txnEmitsLogs = buffers.get(26); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace absLogNum(final BigInteger b) { - if (filled.get(0)) { - throw new IllegalStateException("logInfo.ABS_LOG_NUM already set"); - } else { - filled.set(0); - } - - absLogNum.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace absLogNumMax(final BigInteger b) { - if (filled.get(1)) { - throw new IllegalStateException("logInfo.ABS_LOG_NUM_MAX already set"); - } else { - filled.set(1); - } - - absLogNumMax.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace absTxnNum(final BigInteger b) { - if (filled.get(2)) { - throw new IllegalStateException("logInfo.ABS_TXN_NUM already set"); - } else { - filled.set(2); - } - - absTxnNum.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace absTxnNumMax(final BigInteger b) { - if (filled.get(3)) { - throw new IllegalStateException("logInfo.ABS_TXN_NUM_MAX already set"); - } else { - filled.set(3); - } - - absTxnNumMax.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace addrHi(final BigInteger b) { - if (filled.get(4)) { - throw new IllegalStateException("logInfo.ADDR_HI already set"); - } else { - filled.set(4); - } - - addrHi.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace addrLo(final BigInteger b) { - if (filled.get(5)) { - throw new IllegalStateException("logInfo.ADDR_LO already set"); - } else { - filled.set(5); - } - - addrLo.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace ct(final BigInteger b) { - if (filled.get(6)) { - throw new IllegalStateException("logInfo.CT already set"); - } else { - filled.set(6); - } - - ct.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace ctMax(final BigInteger b) { - if (filled.get(7)) { - throw new IllegalStateException("logInfo.CT_MAX already set"); - } else { - filled.set(7); - } - - ctMax.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace dataHi(final BigInteger b) { - if (filled.get(8)) { - throw new IllegalStateException("logInfo.DATA_HI already set"); - } else { - filled.set(8); - } - - dataHi.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace dataLo(final BigInteger b) { - if (filled.get(9)) { - throw new IllegalStateException("logInfo.DATA_LO already set"); - } else { - filled.set(9); - } - - dataLo.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace dataSize(final BigInteger b) { - if (filled.get(10)) { - throw new IllegalStateException("logInfo.DATA_SIZE already set"); - } else { - filled.set(10); - } - - dataSize.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace inst(final BigInteger b) { - if (filled.get(11)) { - throw new IllegalStateException("logInfo.INST already set"); - } else { - filled.set(11); - } - - inst.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace isLogX0(final Boolean b) { - if (filled.get(12)) { - throw new IllegalStateException("logInfo.IS_LOG_X_0 already set"); - } else { - filled.set(12); - } - - isLogX0.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isLogX1(final Boolean b) { - if (filled.get(13)) { - throw new IllegalStateException("logInfo.IS_LOG_X_1 already set"); - } else { - filled.set(13); - } - - isLogX1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isLogX2(final Boolean b) { - if (filled.get(14)) { - throw new IllegalStateException("logInfo.IS_LOG_X_2 already set"); - } else { - filled.set(14); - } - - isLogX2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isLogX3(final Boolean b) { - if (filled.get(15)) { - throw new IllegalStateException("logInfo.IS_LOG_X_3 already set"); - } else { - filled.set(15); - } - - isLogX3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isLogX4(final Boolean b) { - if (filled.get(16)) { - throw new IllegalStateException("logInfo.IS_LOG_X_4 already set"); - } else { - filled.set(16); - } - - isLogX4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase(final BigInteger b) { - if (filled.get(17)) { - throw new IllegalStateException("logInfo.PHASE already set"); - } else { - filled.set(17); - } - - phase.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace topicHi1(final BigInteger b) { - if (filled.get(18)) { - throw new IllegalStateException("logInfo.TOPIC_HI_1 already set"); - } else { - filled.set(18); - } - - topicHi1.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace topicHi2(final BigInteger b) { - if (filled.get(19)) { - throw new IllegalStateException("logInfo.TOPIC_HI_2 already set"); - } else { - filled.set(19); - } - - topicHi2.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace topicHi3(final BigInteger b) { - if (filled.get(20)) { - throw new IllegalStateException("logInfo.TOPIC_HI_3 already set"); - } else { - filled.set(20); - } - - topicHi3.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace topicHi4(final BigInteger b) { - if (filled.get(21)) { - throw new IllegalStateException("logInfo.TOPIC_HI_4 already set"); - } else { - filled.set(21); - } - - topicHi4.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace topicLo1(final BigInteger b) { - if (filled.get(22)) { - throw new IllegalStateException("logInfo.TOPIC_LO_1 already set"); - } else { - filled.set(22); - } - - topicLo1.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace topicLo2(final BigInteger b) { - if (filled.get(23)) { - throw new IllegalStateException("logInfo.TOPIC_LO_2 already set"); - } else { - filled.set(23); - } - - topicLo2.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace topicLo3(final BigInteger b) { - if (filled.get(24)) { - throw new IllegalStateException("logInfo.TOPIC_LO_3 already set"); - } else { - filled.set(24); - } - - topicLo3.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace topicLo4(final BigInteger b) { - if (filled.get(25)) { - throw new IllegalStateException("logInfo.TOPIC_LO_4 already set"); - } else { - filled.set(25); - } - - topicLo4.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace txnEmitsLogs(final Boolean b) { - if (filled.get(26)) { - throw new IllegalStateException("logInfo.TXN_EMITS_LOGS already set"); - } else { - filled.set(26); - } - - txnEmitsLogs.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("logInfo.ABS_LOG_NUM has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("logInfo.ABS_LOG_NUM_MAX has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("logInfo.ABS_TXN_NUM has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("logInfo.ABS_TXN_NUM_MAX has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("logInfo.ADDR_HI has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("logInfo.ADDR_LO has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("logInfo.CT has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("logInfo.CT_MAX has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("logInfo.DATA_HI has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("logInfo.DATA_LO has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("logInfo.DATA_SIZE has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("logInfo.INST has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("logInfo.IS_LOG_X_0 has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("logInfo.IS_LOG_X_1 has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("logInfo.IS_LOG_X_2 has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("logInfo.IS_LOG_X_3 has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("logInfo.IS_LOG_X_4 has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("logInfo.PHASE has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("logInfo.TOPIC_HI_1 has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("logInfo.TOPIC_HI_2 has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("logInfo.TOPIC_HI_3 has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("logInfo.TOPIC_HI_4 has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("logInfo.TOPIC_LO_1 has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("logInfo.TOPIC_LO_2 has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("logInfo.TOPIC_LO_3 has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("logInfo.TOPIC_LO_4 has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("logInfo.TXN_EMITS_LOGS has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - absLogNum.position(absLogNum.position() + 32); - } - - if (!filled.get(1)) { - absLogNumMax.position(absLogNumMax.position() + 32); - } - - if (!filled.get(2)) { - absTxnNum.position(absTxnNum.position() + 32); - } - - if (!filled.get(3)) { - absTxnNumMax.position(absTxnNumMax.position() + 32); - } - - if (!filled.get(4)) { - addrHi.position(addrHi.position() + 32); - } - - if (!filled.get(5)) { - addrLo.position(addrLo.position() + 32); - } - - if (!filled.get(6)) { - ct.position(ct.position() + 32); - } - - if (!filled.get(7)) { - ctMax.position(ctMax.position() + 32); - } - - if (!filled.get(8)) { - dataHi.position(dataHi.position() + 32); - } - - if (!filled.get(9)) { - dataLo.position(dataLo.position() + 32); - } - - if (!filled.get(10)) { - dataSize.position(dataSize.position() + 32); - } - - if (!filled.get(11)) { - inst.position(inst.position() + 32); - } - - if (!filled.get(12)) { - isLogX0.position(isLogX0.position() + 1); - } - - if (!filled.get(13)) { - isLogX1.position(isLogX1.position() + 1); - } - - if (!filled.get(14)) { - isLogX2.position(isLogX2.position() + 1); - } - - if (!filled.get(15)) { - isLogX3.position(isLogX3.position() + 1); - } - - if (!filled.get(16)) { - isLogX4.position(isLogX4.position() + 1); - } - - if (!filled.get(17)) { - phase.position(phase.position() + 32); - } - - if (!filled.get(18)) { - topicHi1.position(topicHi1.position() + 32); - } - - if (!filled.get(19)) { - topicHi2.position(topicHi2.position() + 32); - } - - if (!filled.get(20)) { - topicHi3.position(topicHi3.position() + 32); - } - - if (!filled.get(21)) { - topicHi4.position(topicHi4.position() + 32); - } - - if (!filled.get(22)) { - topicLo1.position(topicLo1.position() + 32); - } - - if (!filled.get(23)) { - topicLo2.position(topicLo2.position() + 32); - } - - if (!filled.get(24)) { - topicLo3.position(topicLo3.position() + 32); - } - - if (!filled.get(25)) { - topicLo4.position(topicLo4.position() + 32); - } - - if (!filled.get(26)) { - txnEmitsLogs.position(txnEmitsLogs.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} 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 deleted file mode 100644 index 0801717af..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/Mmio.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.mmio; - -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; - -public class Mmio implements Module { - @Override - public String moduleKey() { - return "MMIO"; - } - - @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - return 0; - } - - @Override - public List columnsHeaders() { - throw new RuntimeException("TODO"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Contexts.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Contexts.java deleted file mode 100644 index d39eec57a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Contexts.java +++ /dev/null @@ -1,30 +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.mmu; - -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; - -@Accessors(fluent = true) -@EqualsAndHashCode -@Builder -class Contexts { - @Getter @Setter private int source; - @Getter @Setter private int target; -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/InstructionContext.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/InstructionContext.java deleted file mode 100644 index d7997ef9e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/InstructionContext.java +++ /dev/null @@ -1,23 +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.mmu; - -import lombok.Builder; -import net.consensys.linea.zktracer.types.EWord; - -@Builder -record InstructionContext( - int self, int caller, int returner, EWord returnOffset, int returnCapacity) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/LimbByte.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/LimbByte.java deleted file mode 100644 index aaea82d65..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/LimbByte.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.mmu; - -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.UnsignedByte; - -@Builder -@Accessors(fluent = true) -@EqualsAndHashCode -class LimbByte { - @Getter @Setter private EWord limb; - @Getter @Setter private UnsignedByte uByte; -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MicroData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MicroData.java deleted file mode 100644 index 2de1eeb26..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MicroData.java +++ /dev/null @@ -1,290 +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.mmu; - -import static net.consensys.linea.zktracer.types.Conversions.bytesToUnsignedBytes; -import static net.consensys.linea.zktracer.types.Conversions.unsignedBytesToEWord; - -import java.math.BigInteger; -import java.util.Arrays; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.opcode.OpCode; -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.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -@AllArgsConstructor -@Accessors(fluent = true) -class MicroData extends ModuleOperation { - private static final UnsignedByte[] DEFAULT_NIBBLES = new UnsignedByte[9]; - private static final UnsignedByte[][] DEFAULT_ACCS = new UnsignedByte[8][32]; - private static final boolean[] DEFAULT_BITS = new boolean[8]; - private static final UnsignedByte[] DEFAULT_VAL_A_CACHE = new UnsignedByte[16]; - private static final UnsignedByte[] DEFAULT_VAL_C_CACHE = new UnsignedByte[16]; - private static final UnsignedByte[] DEFAULT_VAL_B_CACHE = new UnsignedByte[16]; - - @Getter @Setter private int callStackDepth; - @Getter @Setter private int callStackSize; - @Getter @Setter private int callDataOffset; - @Getter @Setter private int callDataSize; - @Getter @Setter private OpCode opCode; - @Getter @Setter private boolean skip; - @Getter @Setter private int processingRow; - // Same as {@link ReadPad#totalNumberPaddingMicroInstructions()} in size. - @Getter @Setter private boolean toRam; - // < 16 - @Getter @Setter private int counter; - @Getter @Setter private int microOp; - @Getter @Setter private boolean aligned; - @Getter @Setter private ReadPad readPad; - // < 1.000.000 - @Getter @Setter private int sizeImported; - // < 1.000.000 - @Getter @Setter private int size; - // stack element <=> uint256 - @Getter @Setter private Bytes value; - // stack element - @Getter @Setter private Pointers pointers; - // stack element - @Getter @Setter private Offsets offsets; - // precomputation type - @Getter @Setter private int precomputation; - // < 1.000.000 - @Getter @Setter private int min; - @Getter @Setter private int ternary; - @Getter @Setter private InstructionContext instructionContext; - @Getter @Setter private Contexts contexts; - // every acc is actually on 16 bytes - @Getter @Setter private UnsignedByte[] nibbles; - @Getter @Setter private UnsignedByte[][] accs; - @Getter @Setter private boolean[] bits; - @Getter @Setter private boolean exoIsHash; - @Getter @Setter private boolean exoIsLog; - @Getter @Setter private boolean exoIsRom; - @Getter @Setter private boolean exoIsTxcd; - @Getter @Setter private boolean info; - private UnsignedByte[] valACache; - private UnsignedByte[] valBCache; - private UnsignedByte[] valCCache; - // < 1.000.000 - @Getter @Setter private int referenceOffset; - // < 1.000.000 - @Getter @Setter private int referenceSize; - - MicroData() { - this( - 0, - 0, - 0, - 0, - null, - false, - 0, - false, - 0, - 0, - false, - null, - 0, - 0, - null, - null, - null, - 0, - 0, - 0, - null, - null, - DEFAULT_NIBBLES, - DEFAULT_ACCS, - DEFAULT_BITS, - false, - false, - false, - false, - false, - DEFAULT_VAL_A_CACHE, - DEFAULT_VAL_B_CACHE, - DEFAULT_VAL_C_CACHE, - 0, - 0); - } - - @Override - protected int computeLineCount() { - return Mmu.maxCounter(this.pointers.oob()); - } - - boolean isErf() { - return microOp == MmuTrace.StoreXInAThreeRequired; - } - - boolean isFast() { - return Arrays.asList( - MmuTrace.RamToRam, - MmuTrace.ExoToRam, - MmuTrace.RamIsExo, - MmuTrace.KillingOne, - MmuTrace.PushTwoRamToStack, - MmuTrace.PushOneRamToStack, - MmuTrace.ExceptionalRamToStack3To2FullFast, - MmuTrace.PushTwoStackToRam, - MmuTrace.StoreXInAThreeRequired, - MmuTrace.StoreXInB, - MmuTrace.StoreXInC) - .contains(microOp); - } - - boolean isType5() { - return microOp == OpCode.CALLDATALOAD.getData().value(); - } - - int remainingMicroInstructions() { - return readPad.remainingMicroInstructions(processingRow); - } - - boolean isRead() { - return readPad.isRead(processingRow); - } - - int remainingReads() { - return readPad.remainingReads(processingRow); - } - - int remainingPads() { - return readPad.remainingPads(processingRow); - } - - boolean isFirstRead() { - return readPad.isFirstRead(processingRow); - } - - boolean isFirstPad() { - return readPad.isFirstPad(processingRow); - } - - boolean isFirstMicroInstruction() { - return readPad.isFirstMicroInstruction(processingRow); - } - - boolean isLastRead() { - return readPad.isLastRead(processingRow); - } - - boolean isLastPad() { - return readPad.isLastPad(processingRow); - } - - boolean isRootContext() { - return callStackDepth == 1; - } - - int sourceContext() { - return contexts.source(); - } - - void sourceContext(final int value) { - contexts.source(value); - } - - int targetContext() { - return contexts.target(); - } - - void targetContext(final int value) { - contexts.target(value); - } - - EWord sourceLimbOffset() { - return offsets.source().limb(); - } - - void sourceLimbOffset(final EWord value) { - offsets.source().limb(value); - } - - UnsignedByte sourceByteOffset() { - return offsets.source().uByte(); - } - - void sourceByteOffset(final UnsignedByte value) { - offsets.source().uByte(value); - } - - EWord targetLimbOffset() { - return offsets.target().limb(); - } - - void targetLimbOffset(final EWord value) { - offsets.target().limb(value); - } - - UnsignedByte targetByteOffset() { - return offsets.target().uByte(); - } - - void targetByteOffset(final UnsignedByte value) { - offsets.target().uByte(value); - } - - EWord getAccsAtIndex(final int index) { - return unsignedBytesToEWord(accs[index]); - } - - void setAccsAtIndex(final int index, final EWord value) { - byte[] rawBytes = value.hiBigInt().toByteArray(); - - accs[index] = bytesToUnsignedBytes(rawBytes); - } - - void setAccsAtIndex(final int index, final BigInteger value) { - byte[] rawBytes = value.toByteArray(); - - accs[index] = bytesToUnsignedBytes(rawBytes); - } - - void setAccsAndNibblesAtIndex(final int index, final EWord value) { - EWord div = value.divide(16); - setAccsAtIndex(index, div); - - UnsignedByte modulus = UnsignedByte.of(value.mod(16).toLong()); - nibbles[index] = modulus; - } - - void setInfo(final CallStack callStack) { - if (Arrays.asList(OpCode.CODECOPY, OpCode.RETURN).contains(opCode)) { - info = callStack.current().type() == CallFrameType.INIT_CODE; - // TODO: settle EXTCODEDOPY info for CODECOPY - } else if (opCode == OpCode.CALLDATACOPY) { - info = callStack.depth() == 1; - } - } - - void incrementCounter(final int value) { - counter += value; - } - - void incrementProcessingRow(final int value) { - processingRow += value; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MicroDataProcessor.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MicroDataProcessor.java deleted file mode 100644 index 95219dda0..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MicroDataProcessor.java +++ /dev/null @@ -1,96 +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.mmu; - -import java.util.Map; - -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.runtime.callstack.CallFrameType; -import net.consensys.linea.zktracer.runtime.callstack.CallStack; -import net.consensys.linea.zktracer.runtime.stack.StackOperation; -import org.apache.commons.lang3.function.TriFunction; - -class MicroDataProcessor { - private final MicroData microData; - - private final PreComputations preComputations; - - MicroDataProcessor() { - this.microData = new MicroData(); - this.preComputations = new PreComputations(); - } - - void initializeProcessing(final CallStack callStack, final MicroData microData) { - executeProcessingActionPerType(callStack, microData, MmuPreComputation::process); - } - - void initializePreProcessing(final CallStack callStack) { - executeProcessingActionPerType(callStack, microData, MmuPreComputation::preProcess); - } - - MicroData dispatchOpCode( - final OpCode opCode, final Map stackOps, final CallStack callStack) { - int preComputation = typeOf(opCode, callStack); - - microData.precomputation(preComputation); - - long returnLength = callStack.caller().returnDataTarget().length(); - microData.instructionContext( - InstructionContext.builder() - .self(callStack.current().contextNumber()) - .caller(callStack.caller().contextNumber()) - .returnOffset(callStack.caller().returnTarget().absolute()) - .returnCapacity((int) returnLength) - .returner(callStack.current().returner()) - .build()); - - microData.opCode(opCode); - microData.setInfo(callStack); - - MmuPreComputation currentPreComputation = preComputations.typeMap().get(preComputation); - - return currentPreComputation.dispatch(microData, opCode, stackOps, callStack); - } - - private void executeProcessingActionPerType( - final CallStack callStack, - final MicroData microData, - final TriFunction processorFunc) { - for (MmuPreComputation p : preComputations.types()) { - if (p.preComputationTypes().contains(microData.precomputation())) { - processorFunc.apply(p, microData, callStack); - return; - } - } - } - - private int typeOf(final OpCode opCode, final CallStack callStack) { - if (opCode == OpCode.RETURN && callStack.current().type() == CallFrameType.INIT_CODE) { - return MmuTrace.type3; - } - - return switch (opCode) { - case MLOAD, MSTORE, MSTORE8 -> MmuTrace.type1; - case RETURN, REVERT -> MmuTrace.type2; - case CREATE, CREATE2, SHA3, LOG0, LOG1, LOG2, LOG3, LOG4 -> MmuTrace.type3; - case CODECOPY, EXTCODECOPY -> MmuTrace.type4CC; - case CALLDATACOPY -> MmuTrace.type4CD; - case RETURNDATACOPY -> MmuTrace.type4RD; - case CALLDATALOAD -> MmuTrace.type5; - default -> throw new IllegalArgumentException("Unsupported opcode: %s".formatted(opCode)); - }; - } -} 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 deleted file mode 100644 index dda32222d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java +++ /dev/null @@ -1,246 +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.mmu; - -import static net.consensys.linea.zktracer.types.Conversions.booleanToBigInteger; -import static net.consensys.linea.zktracer.types.Conversions.unsignedBytesToUnsignedBigInteger; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.List; -import java.util.Map; - -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.mmio.Mmio; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.runtime.callstack.CallStack; -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.commons.lang3.ArrayUtils; - -public class Mmu implements Module { - private final StackedList state = new StackedList<>(); - private Mmio mmio; - private int ramStamp; - private boolean isMicro; - private final MicroDataProcessor microDataProcessor; - - private final CallStack callStack; - - public Mmu(final CallStack callStack) { - this.callStack = callStack; - this.mmio = new Mmio(); - this.microDataProcessor = new MicroDataProcessor(); - } - - @Override - public String moduleKey() { - return "MMU"; - } - - @Override - public void enterTransaction() { - this.state.enter(); - } - - @Override - public void popTransaction() { - this.state.pop(); - } - - @Override - public int lineCount() { - return this.state.lineCount(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - for (MicroData m : this.state) { - traceMicroData(m, callStack, trace); - } - } - - /** - * TODO: should be called from the hub. - * - * @param opCode - * @param stackOps - * @param callStack - */ - public void handleRam( - final OpCode opCode, final Map stackOps, final CallStack callStack) { - MicroData microData = microDataProcessor.dispatchOpCode(opCode, stackOps, callStack); - - this.state.add(microData); - } - - private void traceMicroData(MicroData microData, final CallStack callStack, Trace trace) { - if (microData.skip()) { - return; - } - - this.ramStamp++; - this.isMicro = false; - int maxCounter = maxCounter(microData.pointers().oob()); - - microData.processingRow(-1); - - while (microData.counter() < maxCounter) { - microDataProcessor.initializePreProcessing(callStack); - trace(microData, trace); - microData.incrementCounter(1); - } - - this.isMicro = true; - microData.counter(0); - microData.processingRow(0); - - while (microData.processingRow() < microData.readPad().totalNumber()) { - microDataProcessor.initializeProcessing(callStack, microData); - // self.Mmio.handleRam(&uop, self.MicroStamp, callStack, moduleStamp) - trace(microData, trace); - microData.incrementProcessingRow(1); - } - } - - private void trace(MicroData microData, Trace trace) { - Pointers pointers = microData.pointers(); - - BigInteger value = microData.value().toUnsignedBigInteger(); - - InstructionContext stackFrames = microData.instructionContext(); - - UnsignedByte[] nibbles = microData.nibbles(); - - boolean[] bits = microData.bits(); - - final EWord eStack1 = EWord.of(pointers.stack1()); - - trace - .ramStamp(BigInteger.valueOf(this.ramStamp)) - .microInstructionStamp(BigInteger.ZERO) - .isMicroInstruction(this.isMicro) - .off1Lo(eStack1.lo().toUnsignedBigInteger()) - .off2Hi(pointers.stack2().toUnsignedBigInteger()) - .sizeImported(BigInteger.valueOf(microData.sizeImported())) - .valHi(value) - .valLo(value) - .contextNumber(BigInteger.valueOf(stackFrames.self())) - .caller(BigInteger.valueOf(stackFrames.caller())) - .returner(BigInteger.valueOf(stackFrames.returner())) - .contextSource(BigInteger.valueOf(microData.sourceContext())) - .contextTarget(BigInteger.valueOf(microData.targetContext())) - .counter(BigInteger.valueOf(microData.counter())) - .offsetOutOfBounds(pointers.oob()) - .precomputation(BigInteger.valueOf(microData.precomputation())) - .ternary(BigInteger.valueOf(microData.ternary())) - .microInstruction(BigInteger.valueOf(microData.microOp())) - .exoIsRom(microData.exoIsRom()) - .exoIsLog(microData.exoIsLog()) - .exoIsHash(microData.exoIsHash()) - .exoIsTxcd(microData.exoIsTxcd()) - .sourceLimbOffset(microData.sourceLimbOffset().toUnsignedBigInteger()) - .sourceByteOffset(microData.sourceByteOffset().toBigInteger()) - .targetLimbOffset(microData.targetLimbOffset().toUnsignedBigInteger()) - .targetByteOffset(microData.targetByteOffset().toBigInteger()) - .size(BigInteger.valueOf(microData.size())) - .nib1(nibbles[0]) - .nib2(nibbles[1]) - .nib3(nibbles[2]) - .nib4(nibbles[3]) - .nib5(nibbles[4]) - .nib6(nibbles[5]) - .nib7(nibbles[6]) - .nib8(nibbles[7]) - .nib9(nibbles[8]) - .acc1(acc(0, microData)) - .byte1(accByte(0, microData)) - .acc2(acc(1, microData)) - .byte2(accByte(1, microData)) - .acc3(acc(2, microData)) - .byte3(accByte(2, microData)) - .acc4(acc(3, microData)) - .byte4(accByte(3, microData)) - .acc5(acc(4, microData)) - .byte5(accByte(4, microData)) - .acc6(acc(5, microData)) - .byte6(accByte(5, microData)) - .acc7(acc(6, microData)) - .byte7(accByte(6, microData)) - .acc8(acc(7, microData)) - .byte8(accByte(7, microData)) - .bit1(bits[0]) - .bit2(bits[1]) - .bit3(bits[2]) - .bit4(bits[3]) - .bit5(bits[4]) - .bit6(bits[5]) - .bit7(bits[6]) - .bit8(bits[7]) - .aligned(booleanToBigInteger(microData.aligned())) - .fast(booleanToBigInteger(microData.isFast())) - .min(BigInteger.valueOf(microData.min())) - .callStackDepth(BigInteger.valueOf(microData.callStackDepth())) - .callDataSize(BigInteger.valueOf(microData.callDataOffset())) - .instruction(BigInteger.valueOf(microData.opCode().getData().value())) - .totalNumberOfMicroInstructions( - BigInteger.valueOf(this.ramStamp == 0 ? 0 : microData.remainingMicroInstructions())) - .totalNumberOfReads(BigInteger.valueOf(microData.remainingReads())) - .totalNumberOfPaddings(BigInteger.valueOf(microData.remainingPads())) - .toRam(microData.toRam()) - .erf(isMicro && microData.isErf()) - .returnOffset( - stackFrames.returnOffset().isUInt64() || stackFrames.returnCapacity() == 0 - ? BigInteger.ZERO - : stackFrames.returnOffset().toUnsignedBigInteger()) - .returnCapacity(BigInteger.valueOf(stackFrames.returnCapacity())) - .refs(BigInteger.valueOf(microData.referenceSize())) - .refo(BigInteger.valueOf(microData.referenceOffset())) - .info(booleanToBigInteger(microData.info())) - .isData(this.ramStamp != 0) - .validateRow(); - } - - private BigInteger acc(final int accIndex, final MicroData microData) { - int maxCounter = maxCounter(microData.pointers().oob()); - - return unsignedBytesToUnsignedBigInteger( - ArrayUtils.subarray( - microData.accs()[accIndex], - 32 - maxCounter, - 32 - maxCounter + microData.counter() + 1)); - } - - private UnsignedByte accByte(final int accIndex, final MicroData microData) { - int maxCounter = maxCounter(microData.pointers().oob()); - - return microData.accs()[accIndex][32 - maxCounter + microData.counter()]; - } - - static int maxCounter(final boolean oob) { - return oob ? 16 : 3; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuPreComputation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuPreComputation.java deleted file mode 100644 index 17f26c776..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuPreComputation.java +++ /dev/null @@ -1,37 +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.mmu; - -import java.util.Map; -import java.util.Set; - -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.runtime.callstack.CallStack; -import net.consensys.linea.zktracer.runtime.stack.StackOperation; - -interface MmuPreComputation { - MicroData dispatch( - MicroData microData, - OpCode opCode, - Map stackOps, - CallStack callStack); - - MicroData preProcess(MicroData microData, CallStack callStack); - - MicroData process(MicroData microData, CallStack callStack); - - Set preComputationTypes(); -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuTrace.java deleted file mode 100644 index 0d56a74c7..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuTrace.java +++ /dev/null @@ -1,80 +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.mmu; - -import com.fasterxml.jackson.annotation.JsonProperty; -import net.consensys.linea.zktracer.module.ModuleTrace; - -/** - * WARNING: This code is generated automatically. Any modifications to this code may be overwritten - * and could lead to unexpected behavior. Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -record MmuTrace(@JsonProperty("Trace") Trace trace) implements ModuleTrace { - static final int CALLDATACOPY = 55; - static final int CALLDATALOAD = 53; - static final int CODECOPY = 57; - static final int EXTCODECOPY = 60; - static final int ExceptionalRamToStack3To2FullFast = 607; - static final int Exceptional_RamToStack_3To2Full = 627; - static final int ExoToRam = 602; - static final int ExoToRamSlideChunk = 616; - static final int ExoToRamSlideOverlappingChunk = 618; - static final int FirstFastSecondPadded = 625; - static final int FirstPaddedSecondZero = 626; - static final int FullExoFromTwo = 621; - static final int FullStackToRam = 623; - static final int KillingOne = 604; - static final int LIMB_SIZE = 16; - static final int LIMB_SIZE_MINUS_ONE = 15; - static final int LsbFromStackToRAM = 624; - static final int NA_RamToStack_1To1PaddedAndZero = 633; - static final int NA_RamToStack_2To1FullAndZero = 631; - static final int NA_RamToStack_2To1PaddedAndZero = 632; - static final int NA_RamToStack_2To2Padded = 630; - static final int NA_RamToStack_3To2Full = 628; - static final int NA_RamToStack_3To2Padded = 629; - static final int PaddedExoFromOne = 619; - static final int PaddedExoFromTwo = 620; - static final int PushOneRamToStack = 606; - static final int PushTwoRamToStack = 605; - static final int PushTwoStackToRam = 608; - static final int RETURNDATACOPY = 62; - static final int RamIsExo = 603; - static final int RamLimbExcision = 613; - static final int RamToRam = 601; - static final int RamToRamSlideChunk = 614; - static final int RamToRamSlideOverlappingChunk = 615; - static final int SMALL_LIMB_SIZE = 4; - static final int SMALL_LIMB_SIZE_MINUS_ONE = 3; - static final int StoreXInAThreeRequired = 609; - static final int StoreXInB = 610; - static final int StoreXInC = 611; - static final int tern0 = 0; - static final int tern1 = 1; - static final int tern2 = 2; - static final int type1 = 100; - static final int type2 = 200; - static final int type3 = 300; - static final int type4CC = 401; - static final int type4CD = 402; - static final int type4RD = 403; - static final int type5 = 500; - - @Override - public int length() { - return this.trace.size(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Offsets.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Offsets.java deleted file mode 100644 index 1dcb6a9a0..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Offsets.java +++ /dev/null @@ -1,30 +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.mmu; - -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; - -@Getter -@Setter -@Builder -@Accessors(fluent = true) -class Offsets { - private LimbByte source; - private LimbByte target; -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Pointers.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Pointers.java deleted file mode 100644 index 5e3f4c107..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Pointers.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.mmu; - -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import org.apache.tuweni.bytes.Bytes; - -@Builder -@Getter -@Setter -@Accessors(fluent = true) -class Pointers { - private Bytes stack1; - private Bytes stack2; - private boolean oob; -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/PreComputations.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/PreComputations.java deleted file mode 100644 index d8740364d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/PreComputations.java +++ /dev/null @@ -1,51 +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.mmu; - -import java.util.List; -import java.util.Map; - -import lombok.Getter; -import lombok.experimental.Accessors; - -@Accessors(fluent = true) -class PreComputations { - @Getter private final Type1PreComputation type1; - @Getter private final Type2PreComputation type2; - @Getter private final Type3PreComputation type3; - @Getter private final Type4PreComputation type4; - @Getter private final Type5PreComputation type5; - @Getter private final Map typeMap; - @Getter private final List types; - - PreComputations() { - this.type1 = new Type1PreComputation(); - this.type2 = new Type2PreComputation(); - this.type3 = new Type3PreComputation(); - this.type4 = new Type4PreComputation(); - this.type5 = new Type5PreComputation(); - this.types = List.of(type1, type2, type3, type4, type5); - this.typeMap = - Map.of( - MmuTrace.type1, type1, - MmuTrace.type2, type2, - MmuTrace.type3, type3, - MmuTrace.type4CC, type4, - MmuTrace.type4CD, type4, - MmuTrace.type4RD, type4, - MmuTrace.type5, type5); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/ReadPad.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/ReadPad.java deleted file mode 100644 index 425daf9c5..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/ReadPad.java +++ /dev/null @@ -1,80 +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.mmu; - -import lombok.Builder; - -@Builder -record ReadPad(int totalNumberLimbs, int totalNumberPaddingMicroInstructions) { - - int totalNumber() { - return totalNumberLimbs + totalNumberPaddingMicroInstructions; - } - - boolean isRead(final int processingRow) { - return processingRow < totalNumberLimbs; - } - - boolean isPad(final int processingRow) { - return !isRead(processingRow); - } - - boolean isFirstRead(final int processingRow) { - return processingRow == 0 && totalNumberLimbs != 0; - } - - boolean isFirstPad(final int processingRow) { - return totalNumberPaddingMicroInstructions != 0 && processingRow == totalNumberLimbs; - } - - boolean isFirstMicroInstruction(final int processingRow) { - return isFirstRead(processingRow) || (totalNumberLimbs == 0 && isFirstPad(processingRow)); - } - - boolean isLastRead(final int processingRow) { - return totalNumberLimbs != 0 && (processingRow + 1) == totalNumberLimbs; - } - - boolean isLastPad(final int processingRow) { - return totalNumberPaddingMicroInstructions != 0 && processingRow == (totalNumber() - 1); - } - - int remainingMicroInstructions(final int processingRow) { - if (!isRead(processingRow) || isPad(processingRow)) { - return totalNumber(); - } - - return totalNumber() - processingRow - 1; - } - - int remainingReads(final int processingRow) { - if (isRead(processingRow)) { - return totalNumberLimbs - processingRow - 1; - } - - return 0; - } - - int remainingPads(final int processingRow) { - if (processingRow == -1 || isRead(processingRow)) { - return totalNumberPaddingMicroInstructions; - } - - return totalNumberPaddingMicroInstructions - - (processingRow - totalNumberPaddingMicroInstructions) - - 1; - } -} 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 deleted file mode 100644 index 1b8f23f3f..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Trace.java +++ /dev/null @@ -1,1891 +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.mmu; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer acc1; - private final MappedByteBuffer acc2; - private final MappedByteBuffer acc3; - private final MappedByteBuffer acc4; - private final MappedByteBuffer acc5; - private final MappedByteBuffer acc6; - private final MappedByteBuffer acc7; - private final MappedByteBuffer acc8; - private final MappedByteBuffer aligned; - private final MappedByteBuffer bit1; - private final MappedByteBuffer bit2; - private final MappedByteBuffer bit3; - private final MappedByteBuffer bit4; - private final MappedByteBuffer bit5; - private final MappedByteBuffer bit6; - private final MappedByteBuffer bit7; - private final MappedByteBuffer bit8; - private final MappedByteBuffer byte1; - private final MappedByteBuffer byte2; - private final MappedByteBuffer byte3; - private final MappedByteBuffer byte4; - private final MappedByteBuffer byte5; - private final MappedByteBuffer byte6; - private final MappedByteBuffer byte7; - private final MappedByteBuffer byte8; - private final MappedByteBuffer callDataOffset; - private final MappedByteBuffer callDataSize; - private final MappedByteBuffer callStackDepth; - private final MappedByteBuffer caller; - private final MappedByteBuffer contextNumber; - private final MappedByteBuffer contextSource; - private final MappedByteBuffer contextTarget; - private final MappedByteBuffer counter; - private final MappedByteBuffer erf; - private final MappedByteBuffer exoIsHash; - private final MappedByteBuffer exoIsLog; - private final MappedByteBuffer exoIsRom; - private final MappedByteBuffer exoIsTxcd; - private final MappedByteBuffer fast; - private final MappedByteBuffer info; - private final MappedByteBuffer instruction; - private final MappedByteBuffer isData; - private final MappedByteBuffer isMicroInstruction; - private final MappedByteBuffer microInstruction; - private final MappedByteBuffer microInstructionStamp; - private final MappedByteBuffer min; - private final MappedByteBuffer nib1; - private final MappedByteBuffer nib2; - private final MappedByteBuffer nib3; - private final MappedByteBuffer nib4; - private final MappedByteBuffer nib5; - private final MappedByteBuffer nib6; - private final MappedByteBuffer nib7; - private final MappedByteBuffer nib8; - private final MappedByteBuffer nib9; - private final MappedByteBuffer off1Lo; - private final MappedByteBuffer off2Hi; - private final MappedByteBuffer off2Lo; - private final MappedByteBuffer offsetOutOfBounds; - private final MappedByteBuffer precomputation; - private final MappedByteBuffer ramStamp; - private final MappedByteBuffer refo; - private final MappedByteBuffer refs; - private final MappedByteBuffer returnCapacity; - private final MappedByteBuffer returnOffset; - private final MappedByteBuffer returner; - private final MappedByteBuffer size; - private final MappedByteBuffer sizeImported; - private final MappedByteBuffer sourceByteOffset; - private final MappedByteBuffer sourceLimbOffset; - private final MappedByteBuffer targetByteOffset; - private final MappedByteBuffer targetLimbOffset; - private final MappedByteBuffer ternary; - private final MappedByteBuffer toRam; - private final MappedByteBuffer totalNumberOfMicroInstructions; - private final MappedByteBuffer totalNumberOfPaddings; - private final MappedByteBuffer totalNumberOfReads; - private final MappedByteBuffer valHi; - private final MappedByteBuffer valLo; - - static List headers(int length) { - return List.of( - new ColumnHeader("mmu.ACC_1", 32, length), - new ColumnHeader("mmu.ACC_2", 32, length), - new ColumnHeader("mmu.ACC_3", 32, length), - new ColumnHeader("mmu.ACC_4", 32, length), - new ColumnHeader("mmu.ACC_5", 32, length), - new ColumnHeader("mmu.ACC_6", 32, length), - new ColumnHeader("mmu.ACC_7", 32, length), - new ColumnHeader("mmu.ACC_8", 32, length), - new ColumnHeader("mmu.ALIGNED", 32, length), - new ColumnHeader("mmu.BIT_1", 1, length), - new ColumnHeader("mmu.BIT_2", 1, length), - new ColumnHeader("mmu.BIT_3", 1, length), - new ColumnHeader("mmu.BIT_4", 1, length), - new ColumnHeader("mmu.BIT_5", 1, length), - new ColumnHeader("mmu.BIT_6", 1, length), - new ColumnHeader("mmu.BIT_7", 1, length), - new ColumnHeader("mmu.BIT_8", 1, length), - new ColumnHeader("mmu.BYTE_1", 1, length), - new ColumnHeader("mmu.BYTE_2", 1, length), - new ColumnHeader("mmu.BYTE_3", 1, length), - new ColumnHeader("mmu.BYTE_4", 1, length), - new ColumnHeader("mmu.BYTE_5", 1, length), - new ColumnHeader("mmu.BYTE_6", 1, length), - new ColumnHeader("mmu.BYTE_7", 1, length), - new ColumnHeader("mmu.BYTE_8", 1, length), - new ColumnHeader("mmu.CALL_DATA_OFFSET", 32, length), - new ColumnHeader("mmu.CALL_DATA_SIZE", 32, length), - new ColumnHeader("mmu.CALL_STACK_DEPTH", 32, length), - new ColumnHeader("mmu.CALLER", 32, length), - new ColumnHeader("mmu.CONTEXT_NUMBER", 32, length), - new ColumnHeader("mmu.CONTEXT_SOURCE", 32, length), - new ColumnHeader("mmu.CONTEXT_TARGET", 32, length), - new ColumnHeader("mmu.COUNTER", 32, length), - new ColumnHeader("mmu.ERF", 1, length), - new ColumnHeader("mmu.EXO_IS_HASH", 1, length), - new ColumnHeader("mmu.EXO_IS_LOG", 1, length), - new ColumnHeader("mmu.EXO_IS_ROM", 1, length), - new ColumnHeader("mmu.EXO_IS_TXCD", 1, length), - new ColumnHeader("mmu.FAST", 32, length), - new ColumnHeader("mmu.INFO", 32, length), - new ColumnHeader("mmu.INSTRUCTION", 32, length), - new ColumnHeader("mmu.IS_DATA", 1, length), - new ColumnHeader("mmu.IS_MICRO_INSTRUCTION", 1, length), - new ColumnHeader("mmu.MICRO_INSTRUCTION", 32, length), - new ColumnHeader("mmu.MICRO_INSTRUCTION_STAMP", 32, length), - new ColumnHeader("mmu.MIN", 32, length), - new ColumnHeader("mmu.NIB_1", 1, length), - new ColumnHeader("mmu.NIB_2", 1, length), - new ColumnHeader("mmu.NIB_3", 1, length), - new ColumnHeader("mmu.NIB_4", 1, length), - new ColumnHeader("mmu.NIB_5", 1, length), - new ColumnHeader("mmu.NIB_6", 1, length), - new ColumnHeader("mmu.NIB_7", 1, length), - new ColumnHeader("mmu.NIB_8", 1, length), - new ColumnHeader("mmu.NIB_9", 1, length), - new ColumnHeader("mmu.OFF_1_LO", 32, length), - new ColumnHeader("mmu.OFF_2_HI", 32, length), - new ColumnHeader("mmu.OFF_2_LO", 32, length), - new ColumnHeader("mmu.OFFSET_OUT_OF_BOUNDS", 1, length), - new ColumnHeader("mmu.PRECOMPUTATION", 32, length), - new ColumnHeader("mmu.RAM_STAMP", 32, length), - new ColumnHeader("mmu.REFO", 32, length), - new ColumnHeader("mmu.REFS", 32, length), - new ColumnHeader("mmu.RETURN_CAPACITY", 32, length), - new ColumnHeader("mmu.RETURN_OFFSET", 32, length), - new ColumnHeader("mmu.RETURNER", 32, length), - new ColumnHeader("mmu.SIZE", 32, length), - new ColumnHeader("mmu.SIZE_IMPORTED", 32, length), - new ColumnHeader("mmu.SOURCE_BYTE_OFFSET", 32, length), - new ColumnHeader("mmu.SOURCE_LIMB_OFFSET", 32, length), - new ColumnHeader("mmu.TARGET_BYTE_OFFSET", 32, length), - new ColumnHeader("mmu.TARGET_LIMB_OFFSET", 32, length), - new ColumnHeader("mmu.TERNARY", 32, length), - new ColumnHeader("mmu.TO_RAM", 1, length), - new ColumnHeader("mmu.TOTAL_NUMBER_OF_MICRO_INSTRUCTIONS", 32, length), - new ColumnHeader("mmu.TOTAL_NUMBER_OF_PADDINGS", 32, length), - new ColumnHeader("mmu.TOTAL_NUMBER_OF_READS", 32, length), - new ColumnHeader("mmu.VAL_HI", 32, length), - new ColumnHeader("mmu.VAL_LO", 32, length)); - } - - public Trace(List buffers) { - this.acc1 = buffers.get(0); - this.acc2 = buffers.get(1); - this.acc3 = buffers.get(2); - this.acc4 = buffers.get(3); - this.acc5 = buffers.get(4); - this.acc6 = buffers.get(5); - this.acc7 = buffers.get(6); - this.acc8 = buffers.get(7); - this.aligned = buffers.get(8); - this.bit1 = buffers.get(9); - this.bit2 = buffers.get(10); - this.bit3 = buffers.get(11); - this.bit4 = buffers.get(12); - this.bit5 = buffers.get(13); - this.bit6 = buffers.get(14); - this.bit7 = buffers.get(15); - this.bit8 = buffers.get(16); - this.byte1 = buffers.get(17); - this.byte2 = buffers.get(18); - this.byte3 = buffers.get(19); - this.byte4 = buffers.get(20); - this.byte5 = buffers.get(21); - this.byte6 = buffers.get(22); - this.byte7 = buffers.get(23); - this.byte8 = buffers.get(24); - this.callDataOffset = buffers.get(25); - this.callDataSize = buffers.get(26); - this.callStackDepth = buffers.get(27); - this.caller = buffers.get(28); - this.contextNumber = buffers.get(29); - this.contextSource = buffers.get(30); - this.contextTarget = buffers.get(31); - this.counter = buffers.get(32); - this.erf = buffers.get(33); - this.exoIsHash = buffers.get(34); - this.exoIsLog = buffers.get(35); - this.exoIsRom = buffers.get(36); - this.exoIsTxcd = buffers.get(37); - this.fast = buffers.get(38); - this.info = buffers.get(39); - this.instruction = buffers.get(40); - this.isData = buffers.get(41); - this.isMicroInstruction = buffers.get(42); - this.microInstruction = buffers.get(43); - this.microInstructionStamp = buffers.get(44); - this.min = buffers.get(45); - this.nib1 = buffers.get(46); - this.nib2 = buffers.get(47); - this.nib3 = buffers.get(48); - this.nib4 = buffers.get(49); - this.nib5 = buffers.get(50); - this.nib6 = buffers.get(51); - this.nib7 = buffers.get(52); - this.nib8 = buffers.get(53); - this.nib9 = buffers.get(54); - this.off1Lo = buffers.get(55); - this.off2Hi = buffers.get(56); - this.off2Lo = buffers.get(57); - this.offsetOutOfBounds = buffers.get(58); - this.precomputation = buffers.get(59); - this.ramStamp = buffers.get(60); - this.refo = buffers.get(61); - this.refs = buffers.get(62); - this.returnCapacity = buffers.get(63); - this.returnOffset = buffers.get(64); - this.returner = buffers.get(65); - this.size = buffers.get(66); - this.sizeImported = buffers.get(67); - this.sourceByteOffset = buffers.get(68); - this.sourceLimbOffset = buffers.get(69); - this.targetByteOffset = buffers.get(70); - this.targetLimbOffset = buffers.get(71); - this.ternary = buffers.get(72); - this.toRam = buffers.get(73); - this.totalNumberOfMicroInstructions = buffers.get(74); - this.totalNumberOfPaddings = buffers.get(75); - this.totalNumberOfReads = buffers.get(76); - this.valHi = buffers.get(77); - this.valLo = buffers.get(78); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace acc1(final BigInteger b) { - if (filled.get(0)) { - throw new IllegalStateException("mmu.ACC_1 already set"); - } else { - filled.set(0); - } - - acc1.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace acc2(final BigInteger b) { - if (filled.get(1)) { - throw new IllegalStateException("mmu.ACC_2 already set"); - } else { - filled.set(1); - } - - acc2.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace acc3(final BigInteger b) { - if (filled.get(2)) { - throw new IllegalStateException("mmu.ACC_3 already set"); - } else { - filled.set(2); - } - - acc3.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace acc4(final BigInteger b) { - if (filled.get(3)) { - throw new IllegalStateException("mmu.ACC_4 already set"); - } else { - filled.set(3); - } - - acc4.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace acc5(final BigInteger b) { - if (filled.get(4)) { - throw new IllegalStateException("mmu.ACC_5 already set"); - } else { - filled.set(4); - } - - acc5.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace acc6(final BigInteger b) { - if (filled.get(5)) { - throw new IllegalStateException("mmu.ACC_6 already set"); - } else { - filled.set(5); - } - - acc6.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace acc7(final BigInteger b) { - if (filled.get(6)) { - throw new IllegalStateException("mmu.ACC_7 already set"); - } else { - filled.set(6); - } - - acc7.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace acc8(final BigInteger b) { - if (filled.get(7)) { - throw new IllegalStateException("mmu.ACC_8 already set"); - } else { - filled.set(7); - } - - acc8.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace aligned(final BigInteger b) { - if (filled.get(8)) { - throw new IllegalStateException("mmu.ALIGNED already set"); - } else { - filled.set(8); - } - - aligned.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace bit1(final Boolean b) { - if (filled.get(9)) { - throw new IllegalStateException("mmu.BIT_1 already set"); - } else { - filled.set(9); - } - - bit1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit2(final Boolean b) { - if (filled.get(10)) { - throw new IllegalStateException("mmu.BIT_2 already set"); - } else { - filled.set(10); - } - - bit2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit3(final Boolean b) { - if (filled.get(11)) { - throw new IllegalStateException("mmu.BIT_3 already set"); - } else { - filled.set(11); - } - - bit3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit4(final Boolean b) { - if (filled.get(12)) { - throw new IllegalStateException("mmu.BIT_4 already set"); - } else { - filled.set(12); - } - - bit4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit5(final Boolean b) { - if (filled.get(13)) { - throw new IllegalStateException("mmu.BIT_5 already set"); - } else { - filled.set(13); - } - - bit5.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit6(final Boolean b) { - if (filled.get(14)) { - throw new IllegalStateException("mmu.BIT_6 already set"); - } else { - filled.set(14); - } - - bit6.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit7(final Boolean b) { - if (filled.get(15)) { - throw new IllegalStateException("mmu.BIT_7 already set"); - } else { - filled.set(15); - } - - bit7.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit8(final Boolean b) { - if (filled.get(16)) { - throw new IllegalStateException("mmu.BIT_8 already set"); - } else { - filled.set(16); - } - - bit8.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace byte1(final UnsignedByte b) { - if (filled.get(17)) { - throw new IllegalStateException("mmu.BYTE_1 already set"); - } else { - filled.set(17); - } - - byte1.put(b.toByte()); - - return this; - } - - public Trace byte2(final UnsignedByte b) { - if (filled.get(18)) { - throw new IllegalStateException("mmu.BYTE_2 already set"); - } else { - filled.set(18); - } - - byte2.put(b.toByte()); - - return this; - } - - public Trace byte3(final UnsignedByte b) { - if (filled.get(19)) { - throw new IllegalStateException("mmu.BYTE_3 already set"); - } else { - filled.set(19); - } - - byte3.put(b.toByte()); - - return this; - } - - public Trace byte4(final UnsignedByte b) { - if (filled.get(20)) { - throw new IllegalStateException("mmu.BYTE_4 already set"); - } else { - filled.set(20); - } - - byte4.put(b.toByte()); - - return this; - } - - public Trace byte5(final UnsignedByte b) { - if (filled.get(21)) { - throw new IllegalStateException("mmu.BYTE_5 already set"); - } else { - filled.set(21); - } - - byte5.put(b.toByte()); - - return this; - } - - public Trace byte6(final UnsignedByte b) { - if (filled.get(22)) { - throw new IllegalStateException("mmu.BYTE_6 already set"); - } else { - filled.set(22); - } - - byte6.put(b.toByte()); - - return this; - } - - public Trace byte7(final UnsignedByte b) { - if (filled.get(23)) { - throw new IllegalStateException("mmu.BYTE_7 already set"); - } else { - filled.set(23); - } - - byte7.put(b.toByte()); - - return this; - } - - public Trace byte8(final UnsignedByte b) { - if (filled.get(24)) { - throw new IllegalStateException("mmu.BYTE_8 already set"); - } else { - filled.set(24); - } - - byte8.put(b.toByte()); - - return this; - } - - public Trace callDataOffset(final BigInteger b) { - if (filled.get(26)) { - throw new IllegalStateException("mmu.CALL_DATA_OFFSET already set"); - } else { - filled.set(26); - } - - callDataOffset.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace callDataSize(final BigInteger b) { - if (filled.get(27)) { - throw new IllegalStateException("mmu.CALL_DATA_SIZE already set"); - } else { - filled.set(27); - } - - callDataSize.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace callStackDepth(final BigInteger b) { - if (filled.get(28)) { - throw new IllegalStateException("mmu.CALL_STACK_DEPTH already set"); - } else { - filled.set(28); - } - - callStackDepth.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace caller(final BigInteger b) { - if (filled.get(25)) { - throw new IllegalStateException("mmu.CALLER already set"); - } else { - filled.set(25); - } - - caller.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace contextNumber(final BigInteger b) { - if (filled.get(29)) { - throw new IllegalStateException("mmu.CONTEXT_NUMBER already set"); - } else { - filled.set(29); - } - - contextNumber.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace contextSource(final BigInteger b) { - if (filled.get(30)) { - throw new IllegalStateException("mmu.CONTEXT_SOURCE already set"); - } else { - filled.set(30); - } - - contextSource.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace contextTarget(final BigInteger b) { - if (filled.get(31)) { - throw new IllegalStateException("mmu.CONTEXT_TARGET already set"); - } else { - filled.set(31); - } - - contextTarget.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace counter(final BigInteger b) { - if (filled.get(32)) { - throw new IllegalStateException("mmu.COUNTER already set"); - } else { - filled.set(32); - } - - counter.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace erf(final Boolean b) { - if (filled.get(33)) { - throw new IllegalStateException("mmu.ERF already set"); - } else { - filled.set(33); - } - - erf.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace exoIsHash(final Boolean b) { - if (filled.get(34)) { - throw new IllegalStateException("mmu.EXO_IS_HASH already set"); - } else { - filled.set(34); - } - - exoIsHash.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace exoIsLog(final Boolean b) { - if (filled.get(35)) { - throw new IllegalStateException("mmu.EXO_IS_LOG already set"); - } else { - filled.set(35); - } - - exoIsLog.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace exoIsRom(final Boolean b) { - if (filled.get(36)) { - throw new IllegalStateException("mmu.EXO_IS_ROM already set"); - } else { - filled.set(36); - } - - exoIsRom.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace exoIsTxcd(final Boolean b) { - if (filled.get(37)) { - throw new IllegalStateException("mmu.EXO_IS_TXCD already set"); - } else { - filled.set(37); - } - - exoIsTxcd.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace fast(final BigInteger b) { - if (filled.get(38)) { - throw new IllegalStateException("mmu.FAST already set"); - } else { - filled.set(38); - } - - fast.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace info(final BigInteger b) { - if (filled.get(39)) { - throw new IllegalStateException("mmu.INFO already set"); - } else { - filled.set(39); - } - - info.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace instruction(final BigInteger b) { - if (filled.get(40)) { - throw new IllegalStateException("mmu.INSTRUCTION already set"); - } else { - filled.set(40); - } - - instruction.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace isData(final Boolean b) { - if (filled.get(41)) { - throw new IllegalStateException("mmu.IS_DATA already set"); - } else { - filled.set(41); - } - - isData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isMicroInstruction(final Boolean b) { - if (filled.get(42)) { - throw new IllegalStateException("mmu.IS_MICRO_INSTRUCTION already set"); - } else { - filled.set(42); - } - - isMicroInstruction.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace microInstruction(final BigInteger b) { - if (filled.get(43)) { - throw new IllegalStateException("mmu.MICRO_INSTRUCTION already set"); - } else { - filled.set(43); - } - - microInstruction.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace microInstructionStamp(final BigInteger b) { - if (filled.get(44)) { - throw new IllegalStateException("mmu.MICRO_INSTRUCTION_STAMP already set"); - } else { - filled.set(44); - } - - microInstructionStamp.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace min(final BigInteger b) { - if (filled.get(45)) { - throw new IllegalStateException("mmu.MIN already set"); - } else { - filled.set(45); - } - - min.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace nib1(final UnsignedByte b) { - if (filled.get(46)) { - throw new IllegalStateException("mmu.NIB_1 already set"); - } else { - filled.set(46); - } - - nib1.put(b.toByte()); - - return this; - } - - public Trace nib2(final UnsignedByte b) { - if (filled.get(47)) { - throw new IllegalStateException("mmu.NIB_2 already set"); - } else { - filled.set(47); - } - - nib2.put(b.toByte()); - - return this; - } - - public Trace nib3(final UnsignedByte b) { - if (filled.get(48)) { - throw new IllegalStateException("mmu.NIB_3 already set"); - } else { - filled.set(48); - } - - nib3.put(b.toByte()); - - return this; - } - - public Trace nib4(final UnsignedByte b) { - if (filled.get(49)) { - throw new IllegalStateException("mmu.NIB_4 already set"); - } else { - filled.set(49); - } - - nib4.put(b.toByte()); - - return this; - } - - public Trace nib5(final UnsignedByte b) { - if (filled.get(50)) { - throw new IllegalStateException("mmu.NIB_5 already set"); - } else { - filled.set(50); - } - - nib5.put(b.toByte()); - - return this; - } - - public Trace nib6(final UnsignedByte b) { - if (filled.get(51)) { - throw new IllegalStateException("mmu.NIB_6 already set"); - } else { - filled.set(51); - } - - nib6.put(b.toByte()); - - return this; - } - - public Trace nib7(final UnsignedByte b) { - if (filled.get(52)) { - throw new IllegalStateException("mmu.NIB_7 already set"); - } else { - filled.set(52); - } - - nib7.put(b.toByte()); - - return this; - } - - public Trace nib8(final UnsignedByte b) { - if (filled.get(53)) { - throw new IllegalStateException("mmu.NIB_8 already set"); - } else { - filled.set(53); - } - - nib8.put(b.toByte()); - - return this; - } - - public Trace nib9(final UnsignedByte b) { - if (filled.get(54)) { - throw new IllegalStateException("mmu.NIB_9 already set"); - } else { - filled.set(54); - } - - nib9.put(b.toByte()); - - return this; - } - - public Trace off1Lo(final BigInteger b) { - if (filled.get(56)) { - throw new IllegalStateException("mmu.OFF_1_LO already set"); - } else { - filled.set(56); - } - - off1Lo.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace off2Hi(final BigInteger b) { - if (filled.get(57)) { - throw new IllegalStateException("mmu.OFF_2_HI already set"); - } else { - filled.set(57); - } - - off2Hi.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace off2Lo(final BigInteger b) { - if (filled.get(58)) { - throw new IllegalStateException("mmu.OFF_2_LO already set"); - } else { - filled.set(58); - } - - off2Lo.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace offsetOutOfBounds(final Boolean b) { - if (filled.get(55)) { - throw new IllegalStateException("mmu.OFFSET_OUT_OF_BOUNDS already set"); - } else { - filled.set(55); - } - - offsetOutOfBounds.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace precomputation(final BigInteger b) { - if (filled.get(59)) { - throw new IllegalStateException("mmu.PRECOMPUTATION already set"); - } else { - filled.set(59); - } - - precomputation.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace ramStamp(final BigInteger b) { - if (filled.get(60)) { - throw new IllegalStateException("mmu.RAM_STAMP already set"); - } else { - filled.set(60); - } - - ramStamp.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace refo(final BigInteger b) { - if (filled.get(61)) { - throw new IllegalStateException("mmu.REFO already set"); - } else { - filled.set(61); - } - - refo.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace refs(final BigInteger b) { - if (filled.get(62)) { - throw new IllegalStateException("mmu.REFS already set"); - } else { - filled.set(62); - } - - refs.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace returnCapacity(final BigInteger b) { - if (filled.get(64)) { - throw new IllegalStateException("mmu.RETURN_CAPACITY already set"); - } else { - filled.set(64); - } - - returnCapacity.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace returnOffset(final BigInteger b) { - if (filled.get(65)) { - throw new IllegalStateException("mmu.RETURN_OFFSET already set"); - } else { - filled.set(65); - } - - returnOffset.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace returner(final BigInteger b) { - if (filled.get(63)) { - throw new IllegalStateException("mmu.RETURNER already set"); - } else { - filled.set(63); - } - - returner.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace size(final BigInteger b) { - if (filled.get(66)) { - throw new IllegalStateException("mmu.SIZE already set"); - } else { - filled.set(66); - } - - size.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace sizeImported(final BigInteger b) { - if (filled.get(67)) { - throw new IllegalStateException("mmu.SIZE_IMPORTED already set"); - } else { - filled.set(67); - } - - sizeImported.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace sourceByteOffset(final BigInteger b) { - if (filled.get(68)) { - throw new IllegalStateException("mmu.SOURCE_BYTE_OFFSET already set"); - } else { - filled.set(68); - } - - sourceByteOffset.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace sourceLimbOffset(final BigInteger b) { - if (filled.get(69)) { - throw new IllegalStateException("mmu.SOURCE_LIMB_OFFSET already set"); - } else { - filled.set(69); - } - - sourceLimbOffset.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace targetByteOffset(final BigInteger b) { - if (filled.get(70)) { - throw new IllegalStateException("mmu.TARGET_BYTE_OFFSET already set"); - } else { - filled.set(70); - } - - targetByteOffset.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace targetLimbOffset(final BigInteger b) { - if (filled.get(71)) { - throw new IllegalStateException("mmu.TARGET_LIMB_OFFSET already set"); - } else { - filled.set(71); - } - - targetLimbOffset.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace ternary(final BigInteger b) { - if (filled.get(72)) { - throw new IllegalStateException("mmu.TERNARY already set"); - } else { - filled.set(72); - } - - ternary.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace toRam(final Boolean b) { - if (filled.get(76)) { - throw new IllegalStateException("mmu.TO_RAM already set"); - } else { - filled.set(76); - } - - toRam.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace totalNumberOfMicroInstructions(final BigInteger b) { - if (filled.get(73)) { - throw new IllegalStateException("mmu.TOTAL_NUMBER_OF_MICRO_INSTRUCTIONS already set"); - } else { - filled.set(73); - } - - totalNumberOfMicroInstructions.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace totalNumberOfPaddings(final BigInteger b) { - if (filled.get(74)) { - throw new IllegalStateException("mmu.TOTAL_NUMBER_OF_PADDINGS already set"); - } else { - filled.set(74); - } - - totalNumberOfPaddings.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace totalNumberOfReads(final BigInteger b) { - if (filled.get(75)) { - throw new IllegalStateException("mmu.TOTAL_NUMBER_OF_READS already set"); - } else { - filled.set(75); - } - - totalNumberOfReads.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace valHi(final BigInteger b) { - if (filled.get(77)) { - throw new IllegalStateException("mmu.VAL_HI already set"); - } else { - filled.set(77); - } - - valHi.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace valLo(final BigInteger b) { - if (filled.get(78)) { - throw new IllegalStateException("mmu.VAL_LO already set"); - } else { - filled.set(78); - } - - valLo.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("mmu.ACC_1 has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("mmu.ACC_2 has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("mmu.ACC_3 has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("mmu.ACC_4 has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("mmu.ACC_5 has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("mmu.ACC_6 has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("mmu.ACC_7 has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("mmu.ACC_8 has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("mmu.ALIGNED has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("mmu.BIT_1 has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("mmu.BIT_2 has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("mmu.BIT_3 has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("mmu.BIT_4 has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("mmu.BIT_5 has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("mmu.BIT_6 has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("mmu.BIT_7 has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("mmu.BIT_8 has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("mmu.BYTE_1 has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("mmu.BYTE_2 has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("mmu.BYTE_3 has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("mmu.BYTE_4 has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("mmu.BYTE_5 has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("mmu.BYTE_6 has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("mmu.BYTE_7 has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("mmu.BYTE_8 has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("mmu.CALL_DATA_OFFSET has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("mmu.CALL_DATA_SIZE has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("mmu.CALL_STACK_DEPTH has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("mmu.CALLER has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("mmu.CONTEXT_NUMBER has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("mmu.CONTEXT_SOURCE has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("mmu.CONTEXT_TARGET has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("mmu.COUNTER has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("mmu.ERF has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("mmu.EXO_IS_HASH has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("mmu.EXO_IS_LOG has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("mmu.EXO_IS_ROM has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("mmu.EXO_IS_TXCD has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("mmu.FAST has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("mmu.INFO has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("mmu.INSTRUCTION has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("mmu.IS_DATA has not been filled"); - } - - if (!filled.get(42)) { - throw new IllegalStateException("mmu.IS_MICRO_INSTRUCTION has not been filled"); - } - - if (!filled.get(43)) { - throw new IllegalStateException("mmu.MICRO_INSTRUCTION has not been filled"); - } - - if (!filled.get(44)) { - throw new IllegalStateException("mmu.MICRO_INSTRUCTION_STAMP has not been filled"); - } - - if (!filled.get(45)) { - throw new IllegalStateException("mmu.MIN has not been filled"); - } - - if (!filled.get(46)) { - throw new IllegalStateException("mmu.NIB_1 has not been filled"); - } - - if (!filled.get(47)) { - throw new IllegalStateException("mmu.NIB_2 has not been filled"); - } - - if (!filled.get(48)) { - throw new IllegalStateException("mmu.NIB_3 has not been filled"); - } - - if (!filled.get(49)) { - throw new IllegalStateException("mmu.NIB_4 has not been filled"); - } - - if (!filled.get(50)) { - throw new IllegalStateException("mmu.NIB_5 has not been filled"); - } - - if (!filled.get(51)) { - throw new IllegalStateException("mmu.NIB_6 has not been filled"); - } - - if (!filled.get(52)) { - throw new IllegalStateException("mmu.NIB_7 has not been filled"); - } - - if (!filled.get(53)) { - throw new IllegalStateException("mmu.NIB_8 has not been filled"); - } - - if (!filled.get(54)) { - throw new IllegalStateException("mmu.NIB_9 has not been filled"); - } - - if (!filled.get(56)) { - throw new IllegalStateException("mmu.OFF_1_LO has not been filled"); - } - - if (!filled.get(57)) { - throw new IllegalStateException("mmu.OFF_2_HI has not been filled"); - } - - if (!filled.get(58)) { - throw new IllegalStateException("mmu.OFF_2_LO has not been filled"); - } - - if (!filled.get(55)) { - throw new IllegalStateException("mmu.OFFSET_OUT_OF_BOUNDS has not been filled"); - } - - if (!filled.get(59)) { - throw new IllegalStateException("mmu.PRECOMPUTATION has not been filled"); - } - - if (!filled.get(60)) { - throw new IllegalStateException("mmu.RAM_STAMP has not been filled"); - } - - if (!filled.get(61)) { - throw new IllegalStateException("mmu.REFO has not been filled"); - } - - if (!filled.get(62)) { - throw new IllegalStateException("mmu.REFS has not been filled"); - } - - if (!filled.get(64)) { - throw new IllegalStateException("mmu.RETURN_CAPACITY has not been filled"); - } - - if (!filled.get(65)) { - throw new IllegalStateException("mmu.RETURN_OFFSET has not been filled"); - } - - if (!filled.get(63)) { - throw new IllegalStateException("mmu.RETURNER has not been filled"); - } - - if (!filled.get(66)) { - throw new IllegalStateException("mmu.SIZE has not been filled"); - } - - if (!filled.get(67)) { - throw new IllegalStateException("mmu.SIZE_IMPORTED has not been filled"); - } - - if (!filled.get(68)) { - throw new IllegalStateException("mmu.SOURCE_BYTE_OFFSET has not been filled"); - } - - if (!filled.get(69)) { - throw new IllegalStateException("mmu.SOURCE_LIMB_OFFSET has not been filled"); - } - - if (!filled.get(70)) { - throw new IllegalStateException("mmu.TARGET_BYTE_OFFSET has not been filled"); - } - - if (!filled.get(71)) { - throw new IllegalStateException("mmu.TARGET_LIMB_OFFSET has not been filled"); - } - - if (!filled.get(72)) { - throw new IllegalStateException("mmu.TERNARY has not been filled"); - } - - if (!filled.get(76)) { - throw new IllegalStateException("mmu.TO_RAM has not been filled"); - } - - if (!filled.get(73)) { - throw new IllegalStateException("mmu.TOTAL_NUMBER_OF_MICRO_INSTRUCTIONS has not been filled"); - } - - if (!filled.get(74)) { - throw new IllegalStateException("mmu.TOTAL_NUMBER_OF_PADDINGS has not been filled"); - } - - if (!filled.get(75)) { - throw new IllegalStateException("mmu.TOTAL_NUMBER_OF_READS has not been filled"); - } - - if (!filled.get(77)) { - throw new IllegalStateException("mmu.VAL_HI has not been filled"); - } - - if (!filled.get(78)) { - throw new IllegalStateException("mmu.VAL_LO has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - acc1.position(acc1.position() + 32); - } - - if (!filled.get(1)) { - acc2.position(acc2.position() + 32); - } - - if (!filled.get(2)) { - acc3.position(acc3.position() + 32); - } - - if (!filled.get(3)) { - acc4.position(acc4.position() + 32); - } - - if (!filled.get(4)) { - acc5.position(acc5.position() + 32); - } - - if (!filled.get(5)) { - acc6.position(acc6.position() + 32); - } - - if (!filled.get(6)) { - acc7.position(acc7.position() + 32); - } - - if (!filled.get(7)) { - acc8.position(acc8.position() + 32); - } - - if (!filled.get(8)) { - aligned.position(aligned.position() + 32); - } - - if (!filled.get(9)) { - bit1.position(bit1.position() + 1); - } - - if (!filled.get(10)) { - bit2.position(bit2.position() + 1); - } - - if (!filled.get(11)) { - bit3.position(bit3.position() + 1); - } - - if (!filled.get(12)) { - bit4.position(bit4.position() + 1); - } - - if (!filled.get(13)) { - bit5.position(bit5.position() + 1); - } - - if (!filled.get(14)) { - bit6.position(bit6.position() + 1); - } - - if (!filled.get(15)) { - bit7.position(bit7.position() + 1); - } - - if (!filled.get(16)) { - bit8.position(bit8.position() + 1); - } - - if (!filled.get(17)) { - byte1.position(byte1.position() + 1); - } - - if (!filled.get(18)) { - byte2.position(byte2.position() + 1); - } - - if (!filled.get(19)) { - byte3.position(byte3.position() + 1); - } - - if (!filled.get(20)) { - byte4.position(byte4.position() + 1); - } - - if (!filled.get(21)) { - byte5.position(byte5.position() + 1); - } - - if (!filled.get(22)) { - byte6.position(byte6.position() + 1); - } - - if (!filled.get(23)) { - byte7.position(byte7.position() + 1); - } - - if (!filled.get(24)) { - byte8.position(byte8.position() + 1); - } - - if (!filled.get(26)) { - callDataOffset.position(callDataOffset.position() + 32); - } - - if (!filled.get(27)) { - callDataSize.position(callDataSize.position() + 32); - } - - if (!filled.get(28)) { - callStackDepth.position(callStackDepth.position() + 32); - } - - if (!filled.get(25)) { - caller.position(caller.position() + 32); - } - - if (!filled.get(29)) { - contextNumber.position(contextNumber.position() + 32); - } - - if (!filled.get(30)) { - contextSource.position(contextSource.position() + 32); - } - - if (!filled.get(31)) { - contextTarget.position(contextTarget.position() + 32); - } - - if (!filled.get(32)) { - counter.position(counter.position() + 32); - } - - if (!filled.get(33)) { - erf.position(erf.position() + 1); - } - - if (!filled.get(34)) { - exoIsHash.position(exoIsHash.position() + 1); - } - - if (!filled.get(35)) { - exoIsLog.position(exoIsLog.position() + 1); - } - - if (!filled.get(36)) { - exoIsRom.position(exoIsRom.position() + 1); - } - - if (!filled.get(37)) { - exoIsTxcd.position(exoIsTxcd.position() + 1); - } - - if (!filled.get(38)) { - fast.position(fast.position() + 32); - } - - if (!filled.get(39)) { - info.position(info.position() + 32); - } - - if (!filled.get(40)) { - instruction.position(instruction.position() + 32); - } - - if (!filled.get(41)) { - isData.position(isData.position() + 1); - } - - if (!filled.get(42)) { - isMicroInstruction.position(isMicroInstruction.position() + 1); - } - - if (!filled.get(43)) { - microInstruction.position(microInstruction.position() + 32); - } - - if (!filled.get(44)) { - microInstructionStamp.position(microInstructionStamp.position() + 32); - } - - if (!filled.get(45)) { - min.position(min.position() + 32); - } - - if (!filled.get(46)) { - nib1.position(nib1.position() + 1); - } - - if (!filled.get(47)) { - nib2.position(nib2.position() + 1); - } - - if (!filled.get(48)) { - nib3.position(nib3.position() + 1); - } - - if (!filled.get(49)) { - nib4.position(nib4.position() + 1); - } - - if (!filled.get(50)) { - nib5.position(nib5.position() + 1); - } - - if (!filled.get(51)) { - nib6.position(nib6.position() + 1); - } - - if (!filled.get(52)) { - nib7.position(nib7.position() + 1); - } - - if (!filled.get(53)) { - nib8.position(nib8.position() + 1); - } - - if (!filled.get(54)) { - nib9.position(nib9.position() + 1); - } - - if (!filled.get(56)) { - off1Lo.position(off1Lo.position() + 32); - } - - if (!filled.get(57)) { - off2Hi.position(off2Hi.position() + 32); - } - - if (!filled.get(58)) { - off2Lo.position(off2Lo.position() + 32); - } - - if (!filled.get(55)) { - offsetOutOfBounds.position(offsetOutOfBounds.position() + 1); - } - - if (!filled.get(59)) { - precomputation.position(precomputation.position() + 32); - } - - if (!filled.get(60)) { - ramStamp.position(ramStamp.position() + 32); - } - - if (!filled.get(61)) { - refo.position(refo.position() + 32); - } - - if (!filled.get(62)) { - refs.position(refs.position() + 32); - } - - if (!filled.get(64)) { - returnCapacity.position(returnCapacity.position() + 32); - } - - if (!filled.get(65)) { - returnOffset.position(returnOffset.position() + 32); - } - - if (!filled.get(63)) { - returner.position(returner.position() + 32); - } - - if (!filled.get(66)) { - size.position(size.position() + 32); - } - - if (!filled.get(67)) { - sizeImported.position(sizeImported.position() + 32); - } - - if (!filled.get(68)) { - sourceByteOffset.position(sourceByteOffset.position() + 32); - } - - if (!filled.get(69)) { - sourceLimbOffset.position(sourceLimbOffset.position() + 32); - } - - if (!filled.get(70)) { - targetByteOffset.position(targetByteOffset.position() + 32); - } - - if (!filled.get(71)) { - targetLimbOffset.position(targetLimbOffset.position() + 32); - } - - if (!filled.get(72)) { - ternary.position(ternary.position() + 32); - } - - if (!filled.get(76)) { - toRam.position(toRam.position() + 1); - } - - if (!filled.get(73)) { - totalNumberOfMicroInstructions.position(totalNumberOfMicroInstructions.position() + 32); - } - - if (!filled.get(74)) { - totalNumberOfPaddings.position(totalNumberOfPaddings.position() + 32); - } - - if (!filled.get(75)) { - totalNumberOfReads.position(totalNumberOfReads.position() + 32); - } - - if (!filled.get(77)) { - valHi.position(valHi.position() + 32); - } - - if (!filled.get(78)) { - valLo.position(valLo.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - return null; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type1PreComputation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type1PreComputation.java deleted file mode 100644 index 1b2281c9c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type1PreComputation.java +++ /dev/null @@ -1,108 +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.mmu; - -import java.math.BigInteger; -import java.util.Map; -import java.util.Set; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.runtime.callstack.CallStack; -import net.consensys.linea.zktracer.runtime.stack.StackOperation; -import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.UnsignedByte; - -@AllArgsConstructor(access = AccessLevel.PACKAGE) -class Type1PreComputation implements MmuPreComputation { - - private static final Set TYPES = Set.of(MmuTrace.type1); - - @Override - public MicroData dispatch( - MicroData microData, - final OpCode opCode, - final Map stackOps, - final CallStack callStack) { - BigInteger off1 = stackOps.get(0).value().toUnsignedBigInteger(); - - microData.aligned(off1.mod(BigInteger.valueOf(16)).equals(BigInteger.ZERO)); - - microData.readPad( - ReadPad.builder().totalNumberLimbs(1).totalNumberPaddingMicroInstructions(0).build()); - - microData.value(stackOps.get(3).value().copy()); - - microData.pointers(Pointers.builder().stack1(stackOps.get(0).value().copy()).build()); - - UnsignedByte nibble0 = UnsignedByte.of(off1.mod(BigInteger.valueOf(16)).intValue()); - microData.nibbles()[0] = nibble0; - - BigInteger accs = off1.divide(BigInteger.valueOf(16)); - microData.setAccsAtIndex(0, accs); - - LimbByte limbByte = - LimbByte.builder().uByte(microData.nibbles()[0]).limb(EWord.of(accs)).build(); - - microData.offsets(Offsets.builder().target(limbByte).build()); - microData.contexts(Contexts.builder().source(callStack.current().contextNumber()).build()); - - switch (opCode) { - case MLOAD -> { - microData.toRam(false); - - if (microData.aligned()) { - microData.microOp(MmuTrace.PushTwoRamToStack); - } else { - microData.microOp(MmuTrace.NA_RamToStack_3To2Full); - } - } - case MSTORE8 -> { - microData.toRam(true); - microData.microOp(MmuTrace.LsbFromStackToRAM); - } - case MSTORE -> { - microData.toRam(true); - - if (microData.aligned()) { - microData.microOp(MmuTrace.PushTwoStackToRam); - } else { - microData.microOp(MmuTrace.FullStackToRam); - } - } - default -> throw new IllegalArgumentException( - "Opcode %s is not supported for type 1 pre-computation".formatted(opCode)); - } - - return microData; - } - - @Override - public MicroData preProcess(MicroData microData, final CallStack callStack) { - return microData; - } - - @Override - public MicroData process(MicroData microData, final CallStack callStack) { - return microData; - } - - @Override - public Set preComputationTypes() { - return TYPES; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type2PreComputation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type2PreComputation.java deleted file mode 100644 index a372c78a5..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type2PreComputation.java +++ /dev/null @@ -1,229 +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.mmu; - -import java.math.BigInteger; -import java.util.Map; -import java.util.Set; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.runtime.callstack.CallStack; -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.commons.lang3.BooleanUtils; - -@AllArgsConstructor(access = AccessLevel.PACKAGE) -class Type2PreComputation implements MmuPreComputation { - private static final Set TYPES = Set.of(MmuTrace.type2); - - @Override - public MicroData dispatch( - final MicroData microData, - final OpCode opCode, - final Map stackOps, - final CallStack callStack) { - microData.contexts( - Contexts.builder() - .source(callStack.current().contextNumber()) - .target(callStack.caller().contextNumber()) - .build()); - - microData.sizeImported(stackOps.get(2).value().toInt()); - - EWord retOffset = microData.instructionContext().returnOffset(); - EWord ax = retOffset.mod(16); - - int retCapacity = microData.instructionContext().returnCapacity(); - int sizeImported = microData.sizeImported(); - - microData.min(Math.min(sizeImported, retCapacity)); - - if (microData.min() == 0) { - microData.skip(true); - return microData; - } - - microData.pointers(Pointers.builder().stack1(stackOps.get(0).value().copy()).build()); - - int off1 = microData.pointers().stack1().toInt(); - int alignment = off1 % 16; - - microData.readPad( - ReadPad.builder() - .totalNumberLimbs((off1 + microData.min() - 1) / 16 - (off1 / 16) + 1) - .totalNumberPaddingMicroInstructions(0) - .build()); - - ax = ax.add(retOffset.add(microData.min())).subtract(1).mod(16); - - UnsignedByte[] nibbles = microData.nibbles(); - - int retAlignment = ax.intValue(); - - nibbles[0] = UnsignedByte.of(alignment); - nibbles[1] = UnsignedByte.of((off1 + microData.min() - 1) % 16); - nibbles[2] = UnsignedByte.of(retAlignment); - nibbles[3] = UnsignedByte.of(ax.toLong()); - - boolean[] bits = microData.bits(); - - bits[0] = retCapacity > sizeImported; - bits[1] = nibbles[2].toInteger() > nibbles[0].toInteger(); - bits[2] = nibbles[1].toInteger() > nibbles[3].toInteger(); - bits[3] = microData.readPad().totalNumberLimbs() == 1; - - if (bits[3]) { - int x = nibbles[2].toInteger() + microData.min() - 1; - bits[4] = x >= 16; - nibbles[6] = UnsignedByte.of(x % 16); - } else { - bits[4] = false; - nibbles[6] = UnsignedByte.ZERO; - } - - microData.setAccsAtIndex(0, BigInteger.valueOf(off1 / 16)); - microData.setAccsAtIndex(1, BigInteger.valueOf((off1 + microData.min() - 1) / 16)); - - ax = retOffset.divide(16); - microData.setAccsAtIndex(2, ax.toBigInteger()); - ax = retOffset.add(microData.min()).subtract(1).divide(16); - microData.setAccsAtIndex(3, ax.toBigInteger()); - - if (bits[0]) { - microData.setAccsAtIndex(4, BigInteger.valueOf(retCapacity - sizeImported - 1)); - } else { - microData.setAccsAtIndex(4, BigInteger.valueOf(sizeImported - retCapacity)); - } - - if (bits[1]) { - nibbles[4] = UnsignedByte.of(nibbles[2].toInteger() - nibbles[0].toInteger() - 1); - } else { - nibbles[4] = UnsignedByte.of(nibbles[0].toInteger() - nibbles[2].toInteger()); - } - - if (bits[2]) { - nibbles[5] = UnsignedByte.of(nibbles[1].toInteger() - nibbles[3].toInteger() - 1); - } else { - nibbles[5] = UnsignedByte.of(nibbles[3].toInteger() - nibbles[1].toInteger()); - } - - microData.aligned(nibbles[2].equals(nibbles[0])); - microData.offsets( - Offsets.builder() - .source(LimbByte.builder().limb(microData.getAccsAtIndex(0)).uByte(nibbles[0]).build()) - .target(LimbByte.builder().limb(microData.getAccsAtIndex(2)).uByte(nibbles[2]).build()) - .build()); - - return microData; - } - - @Override - public MicroData preProcess(MicroData microData, final CallStack callStack) { - return microData; - } - - @Override - public MicroData process(MicroData microData, final CallStack callStack) { - updateMicroOpType2(microData); - updateOffsetType2(microData); - - return microData; - } - - @Override - public Set preComputationTypes() { - return TYPES; - } - - private void updateOffsetType2(final MicroData microData) { - if (microData.isFirstMicroInstruction()) { - microData.sourceLimbOffset().add(1); - } - - boolean[] bits = microData.bits(); - UnsignedByte[] nibbles = microData.nibbles(); - - if (bits[3]) { - microData.size(microData.min()); - } else { - if (microData.isFirstMicroInstruction()) { - microData.size(15 - nibbles[0].toInteger() + 1); - } - - int processingRow = microData.processingRow(); - - if (processingRow == 1) { - microData - .targetLimbOffset() - .add(BooleanUtils.toInteger(microData.aligned()) + BooleanUtils.toInteger(bits[1])); - } - - if (processingRow > 1) { - microData.targetLimbOffset().add(1); - } - - if (!microData.isFirstMicroInstruction()) { - microData.sourceByteOffset(UnsignedByte.ZERO); - microData.targetByteOffset( - UnsignedByte.of( - nibbles[2].toInteger() - + 16 - - nibbles[0].toInteger() - - (16 * BooleanUtils.toInteger(microData.aligned()) - + BooleanUtils.toInteger(bits[1])))); - - if (microData.isLastRead()) { - microData.size(nibbles[1].toInteger() + 1); - } else { - microData.size(16); - } - } - } - } - - private void updateMicroOpType2(MicroData microData) { - boolean[] bits = microData.bits(); - - if (bits[3]) { - if (!bits[1]) { - microData.microOp(MmuTrace.RamToRamSlideChunk); - } else if (bits[4]) { - microData.microOp(MmuTrace.RamToRamSlideOverlappingChunk); - } else { - microData.microOp(MmuTrace.RamToRamSlideChunk); - } - } else if (microData.isFirstMicroInstruction()) { - if (bits[1]) { - microData.microOp(MmuTrace.RamToRamSlideOverlappingChunk); - } else { - microData.microOp(MmuTrace.RamToRamSlideChunk); - } - } else if (microData.isLastRead()) { - if (bits[2]) { - microData.microOp(MmuTrace.RamToRamSlideOverlappingChunk); - } else { - microData.microOp(MmuTrace.RamToRamSlideChunk); - } - } else if (microData.aligned()) { - microData.microOp(MmuTrace.RamToRam); - } else { - microData.microOp(MmuTrace.RamToRamSlideOverlappingChunk); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type3PreComputation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type3PreComputation.java deleted file mode 100644 index 02084ee0a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type3PreComputation.java +++ /dev/null @@ -1,149 +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.mmu; - -import java.math.BigInteger; -import java.util.Map; -import java.util.Set; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.runtime.callstack.CallStack; -import net.consensys.linea.zktracer.runtime.stack.StackOperation; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.commons.lang3.BooleanUtils; - -@AllArgsConstructor(access = AccessLevel.PACKAGE) -class Type3PreComputation implements MmuPreComputation { - private static final Set TYPES = Set.of(MmuTrace.type3); - - @Override - public MicroData dispatch( - MicroData microData, - final OpCode opCode, - final Map stackOps, - final CallStack callStack) { - Contexts contexts = microData.contexts(); - contexts.source(callStack.current().contextNumber()); - contexts.target(0); - - microData.value(stackOps.get(3).value().copy()); - - int sizeImported = stackOps.get(2).value().toInt(); - microData.sizeImported(sizeImported); - - if (sizeImported == 0) { - microData.skip(true); - return microData; - } - - microData.pointers(Pointers.builder().stack1(stackOps.get(0).value().copy()).build()); - - int off1 = microData.pointers().stack1().toInt(); - - // Accs - microData.setAccsAtIndex(0, BigInteger.valueOf(off1 / 16)); - microData.setAccsAtIndex(1, BigInteger.valueOf(sizeImported / 16)); - - // Nibbles - UnsignedByte[] nibbles = microData.nibbles(); - nibbles[0] = UnsignedByte.of(off1 % 16); - nibbles[1] = UnsignedByte.of(sizeImported % 16); - - microData.aligned(nibbles[0].equals(UnsignedByte.ZERO)); - - boolean[] bits = microData.bits(); - bits[0] = !nibbles[1].equals(UnsignedByte.ZERO); - - if (!microData.aligned()) { - int x = nibbles[0].toInteger() + nibbles[1].toInteger() - 1; - bits[1] = x >= 16; - nibbles[2] = UnsignedByte.of(x % 16); - } - - microData.readPad( - ReadPad.builder() - .totalNumberLimbs(microData.getAccsAtIndex(1).toInt() + BooleanUtils.toInteger(bits[0])) - .totalNumberPaddingMicroInstructions(0) - .build()); - - microData.sourceLimbOffset(microData.getAccsAtIndex(0)); - microData.sourceByteOffset(nibbles[0]); - - return microData; - } - - @Override - public MicroData preProcess(final MicroData microData, final CallStack callStack) { - switch (microData.opCode()) { - case SHA3 -> microData.exoIsHash(true); - case LOG0, LOG1, LOG2, LOG3, LOG4 -> microData.exoIsLog(true); - case CREATE, RETURN -> microData.exoIsRom(true); - case CREATE2 -> { - microData.exoIsRom(true); - microData.exoIsHash(true); - } - default -> throw new UnsupportedOperationException( - "OpCode.%s is not supported for MMU type 3 pre-processing." - .formatted(microData.opCode())); - } - - return microData; - } - - @Override - public MicroData process(MicroData microData, final CallStack callStack) { - updateMicroOpType3(microData); - updateOffsetType3(microData); - - return microData; - } - - @Override - public Set preComputationTypes() { - return TYPES; - } - - private void updateOffsetType3(MicroData microData) { - UnsignedByte[] nibbles = microData.nibbles(); - if (microData.isLastRead()) { - microData.size(nibbles[1].toInteger()); - } - - if (!microData.isFirstMicroInstruction()) { - microData.sourceLimbOffset().add(1); - microData.targetLimbOffset().add(1); - } - } - - private void updateMicroOpType3(MicroData microData) { - boolean[] bits = microData.bits(); - if (!microData.isLastRead()) { - if (microData.aligned()) { - microData.microOp(MmuTrace.RamIsExo); - } else { - microData.microOp(MmuTrace.FullExoFromTwo); - } - } else if (microData.aligned() && !bits[0]) { - microData.microOp(MmuTrace.RamIsExo); - } else if (bits[1]) { - microData.microOp(MmuTrace.PaddedExoFromTwo); - } else { - microData.microOp(MmuTrace.PaddedExoFromOne); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type4PreComputation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type4PreComputation.java deleted file mode 100644 index 8f4a359e6..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type4PreComputation.java +++ /dev/null @@ -1,661 +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.mmu; - -import java.util.Map; -import java.util.Set; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -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.runtime.stack.StackOperation; -import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.internal.Words; - -@AllArgsConstructor(access = AccessLevel.PACKAGE) -class Type4PreComputation implements MmuPreComputation { - private static final Set TYPES = - Set.of(MmuTrace.type4CC, MmuTrace.type4CD, MmuTrace.type4RD); - - @Override - public MicroData dispatch( - final MicroData microData, - final OpCode opCode, - final Map stackOps, - final CallStack callStack) { - microData.opCode(opCode); - microData.pointers( - Pointers.builder() - .stack1(stackOps.get(0).value().copy()) - .stack2(stackOps.get(1).value().copy()) - .build()); - - Bytes value = stackOps.get(3).value().copy(); - microData.sizeImported(value.toInt()); - microData.value(value); - - setTern(microData, callStack); - - if (microData.skip()) { - return microData; - } - - int ternary = microData.ternary(); - - if (ternary == MmuTrace.tern0) { - dispatchTern0(microData, callStack); - } else if (ternary == MmuTrace.tern1) { - dispatchTern1(microData, callStack); - } else if (ternary == MmuTrace.tern2) { - dispatchTern2(microData); - } else { - microData.skip(true); - } - - return microData; - } - - @Override - public MicroData preProcess(final MicroData microData, final CallStack callStack) { - setContext(false, microData, callStack); - - return microData; - } - - @Override - public MicroData process(final MicroData microData, final CallStack callStack) { - setContext(true, microData, callStack); - int ternary = microData.ternary(); - - if (ternary == MmuTrace.tern0) { - updateTern0(microData); - } else if (ternary == MmuTrace.tern1) { - updateMicroOpType4Tern1(microData); - updateOffsetType4Tern1(microData); - } else if (ternary == MmuTrace.tern2) { - updateMicroOpType4Tern2(microData); - updateOffsetType4Tern2(microData); - } - - return microData; - } - - @Override - public Set preComputationTypes() { - return TYPES; - } - - private void updateOffsetType4Tern2(MicroData microData) { - if (!microData.isFirstMicroInstruction()) { - microData.targetLimbOffset().add(1); - - if (!microData.bits()[0]) { - microData.targetByteOffset(UnsignedByte.ZERO); - } - } - } - - private void updateMicroOpType4Tern2(MicroData microData) { - boolean[] bits = microData.bits(); - UnsignedByte[] nibbles = microData.nibbles(); - - if (bits[0]) { - if (bits[2] && bits[3]) { - microData.microOp(MmuTrace.KillingOne); - } else { - microData.size(microData.sizeImported()); - microData.microOp(MmuTrace.RamLimbExcision); - } - } else if (microData.isFirstMicroInstruction()) { - if (bits[2]) { - microData.microOp(MmuTrace.KillingOne); - } else { - microData.size(16 - nibbles[0].toInteger()); - microData.microOp(MmuTrace.RamLimbExcision); - } - } else if (microData.isLastPad()) { - if (bits[3]) { - microData.microOp(MmuTrace.KillingOne); - } else { - microData.size(nibbles[3].toInteger() + 1); - microData.microOp(MmuTrace.RamLimbExcision); - } - } else { - microData.microOp(MmuTrace.KillingOne); - } - } - - private void updateOffsetType4Tern1(MicroData microData) { - if (microData.readPad().isRead(microData.processingRow())) { - updateOffsetType4Tern1DataExtraction(microData); - } else { - updateOffsetType4Tern1ZeroPadding(microData); - } - } - - private void updateOffsetType4Tern1ZeroPadding(MicroData microData) { - boolean[] bits = microData.bits(); - UnsignedByte[] nibbles = microData.nibbles(); - - if (microData.isFirstPad()) { - microData.targetByteOffset(nibbles[6]); - if (bits[2]) { - if (!bits[6]) { - microData.targetLimbOffset().add(BooleanUtils.toInteger(bits[4])); - } else { - microData.targetLimbOffset().add(1); - } - } else if (bits[1]) { - microData.targetLimbOffset().add(1); - } else { - microData.targetLimbOffset().add(BooleanUtils.toInteger(bits[4])); - } - } - - if (bits[3]) { - microData.sourceLimbOffset(EWord.ZERO); - microData.sourceByteOffset(UnsignedByte.ZERO); - - if (bits[4] && bits[5]) { - // TODO - } else { - microData.size(1 + nibbles[7].toInteger() - nibbles[6].toInteger()); - } - } else if (microData.isFirstPad()) { - microData.targetByteOffset(nibbles[6]); - microData.size(16 - nibbles[6].toInteger()); - } else { - microData.targetLimbOffset().add(1); - microData.targetByteOffset(UnsignedByte.ZERO); - microData.size(1 + nibbles[7].toInteger()); - } - } - - private void updateOffsetType4Tern1DataExtraction(MicroData microData) { - boolean[] bits = microData.bits(); - UnsignedByte[] nibbles = microData.nibbles(); - int alignedInt = BooleanUtils.toInteger(microData.aligned()); - - if (bits[2]) { - microData.size(1 + nibbles[3].toInteger() - nibbles[2].toInteger()); - - if (microData.processingRow() > 0) { - microData.targetByteOffset(nibbles[6]); - if (!bits[6]) { - microData.targetLimbOffset().add(BooleanUtils.toInteger(bits[4])); - } else { - microData.targetLimbOffset().add(microData.targetLimbOffset()).add(1); - } - } else { - if (microData.isFirstMicroInstruction()) { - microData.size(15 - nibbles[2].toInteger() + 1); - } else { - microData.sourceLimbOffset().add(1); - } - - int processingRow = microData.processingRow(); - if (processingRow == 1) { - microData.targetLimbOffset().add(alignedInt + BooleanUtils.toInteger(bits[0])); - } - - if (processingRow > 1) { - microData.targetLimbOffset().add(1); - } - - if (!microData.isFirstMicroInstruction() && microData.isRead()) { - microData.sourceByteOffset(UnsignedByte.ZERO); - microData.targetByteOffset( - UnsignedByte.of( - nibbles[4].toInteger() - + 1 - + (15 - nibbles[2].toInteger()) - - 16 * (alignedInt + BooleanUtils.toInteger(bits[0])))); - - if (!microData.isLastRead()) { - microData.size(16); - } else { - microData.size(nibbles[3].toInteger() + 1); - } - } - } - } - } - - private void updateMicroOpType4Tern1(MicroData microData) { - if (microData.readPad().isRead(microData.processingRow())) { - updateMicroOpType4Tern1DataExtraction(microData); - } else { - updateMicroOpType4Tern1ZeroPadding(microData); - } - } - - private void updateMicroOpType4Tern1ZeroPadding(MicroData microData) { - boolean[] bits = microData.bits(); - if (bits[3]) { - if (bits[4] && bits[5]) { - microData.microOp(MmuTrace.KillingOne); - } else { - microData.microOp(MmuTrace.RamLimbExcision); - } - } else if (!microData.isFirstPad()) { - if (!microData.isLastPad()) { - microData.microOp(MmuTrace.KillingOne); - } else { - if (!bits[5]) { - microData.microOp(MmuTrace.RamLimbExcision); - } else { - microData.microOp(MmuTrace.KillingOne); - } - } - } else if (bits[4]) { - microData.microOp(MmuTrace.KillingOne); - } else { - microData.microOp(MmuTrace.RamLimbExcision); - } - } - - private void updateMicroOpType4Tern1DataExtraction(MicroData microData) { - boolean[] bits = microData.bits(); - - if (bits[2]) { - if (!bits[6]) { - modifyOneLimb(microData); - } else { - modifyTwoLimbs(microData); - } - } else { - if (microData.isFirstMicroInstruction()) { - if (!bits[0]) { - modifyOneLimb(microData); - } else { - modifyTwoLimbs(microData); - } - } else { - if (microData.remainingReads() != 0) { - if (!microData.aligned()) { - int preComputation = microData.precomputation(); - if (preComputation == MmuTrace.type4CC) { - microData.microOp(MmuTrace.ExoToRam); - } else if (preComputation == MmuTrace.type4CD) { - if (!microData.info()) { - microData.microOp(MmuTrace.RamToRam); - } else { - microData.microOp(MmuTrace.ExoToRam); - } - } - } else { - modifyTwoLimbs(microData); - } - } else { - if (bits[1]) { - modifyOneLimb(microData); - } else { - modifyTwoLimbs(microData); - } - } - } - } - } - - private void updateTern0(MicroData microData) { - if (microData.bits()[2]) { - type4Tern0SingleMicroInstruction(microData); - } else { - type4Tern0MultipleMicroInstruction(microData); - } - } - - private void type4Tern0MultipleMicroInstruction(MicroData microData) { - if (microData.processingRow() == 0) { - if (microData.bits()[0]) { - modifyTwoLimbs(microData); - } else { - modifyOneLimb(microData); - } - - microData.size(16 - microData.nibbles()[2].toInteger()); - } - } - - private void type4Tern0SingleMicroInstruction(final MicroData microData) { - microData.size(microData.sizeImported()); - - if (microData.bits()[3]) { - modifyTwoLimbs(microData); - } else { - modifyOneLimb(microData); - } - } - - private void modifyOneLimb(MicroData microData) { - int preComputation = microData.precomputation(); - if (preComputation == MmuTrace.type4CC) { - microData.microOp(MmuTrace.ExoToRamSlideOverlappingChunk); - } else if (preComputation == MmuTrace.type4RD) { - microData.microOp(MmuTrace.RamToRamSlideOverlappingChunk); - } else if (preComputation == MmuTrace.type4CD) { - if (!microData.info()) { - microData.microOp(MmuTrace.RamToRamSlideOverlappingChunk); - } else { - microData.microOp(MmuTrace.ExoToRamSlideOverlappingChunk); - } - } else { - throw new IllegalArgumentException("Tern not supported"); - } - } - - private void modifyTwoLimbs(MicroData microData) { - int preComputation = microData.precomputation(); - if (preComputation == MmuTrace.type4CC) { - microData.microOp(MmuTrace.ExoToRamSlideOverlappingChunk); - } else if (preComputation == MmuTrace.type4RD) { - microData.microOp(MmuTrace.RamToRamSlideOverlappingChunk); - } else if (preComputation == MmuTrace.type4CD) { - if (!microData.info()) { - microData.microOp(MmuTrace.RamToRamSlideOverlappingChunk); - } else { - microData.microOp(MmuTrace.ExoToRamSlideOverlappingChunk); - } - } else { - throw new IllegalArgumentException("Tern not supported"); - } - } - - void setContext(final boolean isMicro, MicroData microData, final CallStack callStack) { - microData.targetContext(callStack.current().contextNumber()); - - switch (microData.opCode()) { - case RETURNDATACOPY -> { - microData.exoIsHash(false); - microData.exoIsLog(false); - microData.exoIsRom(false); - microData.exoIsTxcd(false); - } - case CALLDATACOPY -> { - microData.exoIsHash(false); - microData.exoIsLog(false); - microData.exoIsRom(false); - - if (isMicro && microData.isRead()) { - microData.exoIsTxcd(microData.info()); - } else { - microData.exoIsTxcd(false); - } - - if (microData.callStackDepth() != 1) { - microData.sourceContext(callStack.caller().contextNumber()); - } else { - microData.sourceContext(0); - } - } - case CODECOPY, EXTCODECOPY -> { - microData.exoIsHash(false); - microData.exoIsLog(false); - - microData.exoIsRom(isMicro && microData.isRead()); - microData.exoIsTxcd(false); - - microData.sourceContext(0); - } - default -> throw new UnsupportedOperationException( - "OpCode.%s is not supported for MMU type 4 pre-processing and/or processing" - .formatted(microData.opCode())); - } - } - - void setTern(MicroData microData, final CallStack callStack) { - final EWord off2 = EWord.of(microData.pointers().stack2()); - - microData.referenceSize(calculateReferenceSize(microData, callStack)); - - if ((microData.sizeImported() == 0 || microData.opCode() == OpCode.RETURNDATACOPY) - && EWord.of(microData.referenceSize()).lessThan(off2.add(microData.sizeImported()))) { - microData.skip(true); - return; - } - - EWord refSize = EWord.of(microData.referenceSize()); - EWord sizeImportedMinusOneEWord = EWord.of(microData.sizeImported() - 1); - if (!off2.hi().isZero()) { - microData.ternary(MmuTrace.tern2); - microData.pointers().oob(true); - } else if (off2.add(microData.sizeImported()).lessThan(refSize)) { - microData.ternary(MmuTrace.tern0); - microData.pointers().oob(false); - - EWord acc1 = refSize.subtract(off2).subtract(microData.sizeImported()); - microData.setAccsAtIndex(0, acc1); - } else if (off2.lessThan(refSize) - && refSize.lessOrEqualThan(sizeImportedMinusOneEWord.add(off2))) { - microData.ternary(MmuTrace.tern1); - microData.pointers().oob(false); - - EWord acc1 = EWord.of(microData.sizeImported() - 1 - microData.referenceSize()).add(off2); - microData.setAccsAtIndex(0, acc1); - - EWord acc2 = EWord.of(microData.referenceSize() - 1).subtract(off2); - microData.setAccsAtIndex(1, acc2); - } else if (refSize.lessOrEqualThan(off2)) { - microData.ternary(MmuTrace.tern2); - microData.pointers().oob(true); - - EWord acc1 = EWord.ZERO.subtract(refSize); - microData.setAccsAtIndex(0, acc1); - } - } - - private int calculateReferenceSize(final MicroData microData, final CallStack callStack) { - OpCode opCode = microData.opCode(); - CallFrame topCallFrame = callStack.current(); - - switch (opCode) { - case CODECOPY -> topCallFrame.code().getSize(); - case EXTCODECOPY -> { - final Address address = Words.toAddress(microData.value()); - topCallFrame.frame().getWorldUpdater().get(address).getCode().size(); - } - case CALLDATACOPY -> callStack.caller().callDataRange().length(); - case RETURNDATACOPY -> topCallFrame.returnDataRange().length(); - default -> throw new IllegalArgumentException( - "OpCode.%s not supported for type 4 reference size calculation.".formatted(opCode)); - } - - return 0; - } - - private void dispatchTern0(final MicroData microData, final CallStack callStack) { - Pointers pointers = microData.pointers(); - EWord off1Lo = EWord.of(pointers.stack1()); - EWord off2 = EWord.of(pointers.stack2()); - boolean[] bits = microData.bits(); - - microData.referenceOffset(calculateReferenceOffset(microData, callStack)); - - int refOffset = microData.referenceOffset(); - int sizeImported = microData.sizeImported(); - - microData.setAccsAndNibblesAtIndex(2, EWord.of(refOffset).add(off2)); - microData.setAccsAndNibblesAtIndex(3, EWord.of(refOffset + sizeImported - 1).add(off2)); - microData.setAccsAndNibblesAtIndex(4, off1Lo); - microData.setAccsAndNibblesAtIndex(5, EWord.of(sizeImported - 1).add(off1Lo)); - - UnsignedByte[] nibbles = microData.nibbles(); - if (nibbles[4].toInteger() > nibbles[5].toInteger()) { - bits[0] = true; - nibbles[0] = UnsignedByte.of(nibbles[4].toInteger() - nibbles[2].toInteger() - 1); - } else { - bits[0] = false; - nibbles[0] = UnsignedByte.of(nibbles[2].toInteger() - nibbles[4].toInteger()); - } - - if (nibbles[3].toInteger() > nibbles[5].toInteger()) { - bits[1] = true; - nibbles[1] = UnsignedByte.of(nibbles[3].toInteger() - nibbles[5].toInteger() - 1); - } else { - bits[1] = false; - nibbles[1] = UnsignedByte.of(nibbles[5].toInteger() - nibbles[3].toInteger()); - } - - microData.readPad( - ReadPad.builder() - .totalNumberLimbs( - microData.getAccsAtIndex(3).subtract(microData.getAccsAtIndex(2)).add(1).toInt()) - .totalNumberPaddingMicroInstructions(0) - .build()); - - if (nibbles[2].toInteger() == nibbles[4].toInteger()) { - microData.aligned(true); - } - - if (microData.readPad().totalNumber() == 1) { - bits[2] = true; - int sum = nibbles[4].toInteger() + sizeImported - 1; - bits[3] = sum >= 16; - nibbles[6] = UnsignedByte.of(sum % 16); - } - - microData.offsets( - Offsets.builder() - .source( - LimbByte.builder() - .limb(microData.getAccsAtIndex(2).copy()) - .uByte(nibbles[2]) - .build()) - .target( - LimbByte.builder() - .limb(microData.getAccsAtIndex(4).copy()) - .uByte(nibbles[4]) - .build()) - .build()); - } - - private int calculateReferenceOffset(final MicroData microData, final CallStack callStack) { - return switch (microData.opCode()) { - case CODECOPY, EXTCODECOPY -> 0; - case CALLDATACOPY -> callStack.caller().callDataRange().absolute().toInt(); - case RETURNDATACOPY -> callStack.current().returnDataRange().absolute().toInt(); - default -> throw new IllegalArgumentException( - "OpCode.%s not supported for type 4 reference offset calculation" - .formatted(microData.opCode())); - }; - } - - private void dispatchTern1(final MicroData microData, final CallStack callStack) { - Pointers pointers = microData.pointers(); - EWord off1Lo = EWord.of(pointers.stack1()); - EWord off2 = EWord.of(pointers.stack2()); - boolean[] bits = microData.bits(); - - microData.referenceOffset(calculateReferenceOffset(microData, callStack)); - - int refOffset = microData.referenceOffset(); - int refSize = microData.referenceSize(); - int sizeImported = microData.sizeImported(); - - microData.setAccsAndNibblesAtIndex(2, EWord.of(refOffset).add(off2)); - microData.setAccsAndNibblesAtIndex(3, EWord.of(refOffset + refSize - 1)); - microData.setAccsAndNibblesAtIndex(4, off1Lo); - microData.setAccsAndNibblesAtIndex(5, EWord.of(refSize - 1).add(off1Lo).subtract(off2)); - microData.setAccsAndNibblesAtIndex(6, EWord.of(refSize).add(off1Lo).subtract(off2)); - microData.setAccsAndNibblesAtIndex(7, EWord.of(sizeImported - 1).add(off1Lo)); - - UnsignedByte[] nibbles = microData.nibbles(); - - if (nibbles[4].toInteger() > nibbles[2].toInteger()) { - bits[0] = true; - nibbles[0] = UnsignedByte.of(nibbles[4].toInteger() - nibbles[2].toInteger() - 1); - } else { - bits[0] = false; - nibbles[0] = UnsignedByte.of(nibbles[2].toInteger() - nibbles[4].toInteger()); - } - - if (nibbles[3].toInteger() > nibbles[5].toInteger()) { - bits[1] = true; - nibbles[1] = UnsignedByte.of(nibbles[3].toInteger() - nibbles[5].toInteger() - 1); - } else { - bits[1] = false; - nibbles[1] = UnsignedByte.of(nibbles[5].toInteger() - nibbles[3].toInteger()); - } - - microData.readPad( - ReadPad.builder() - .totalNumberLimbs( - microData.getAccsAtIndex(3).subtract(microData.getAccsAtIndex(2)).add(1).toInt()) - .totalNumberPaddingMicroInstructions( - microData.getAccsAtIndex(7).subtract(microData.getAccsAtIndex(6)).add(1).toInt()) - .build()); - - microData.aligned(nibbles[2].toInteger() == nibbles[4].toInteger()); - - ReadPad readPad = microData.readPad(); - bits[2] = readPad.totalNumberLimbs() == 1; - bits[3] = readPad.totalNumberPaddingMicroInstructions() == 1; - bits[4] = nibbles[5].toInteger() == 15; - bits[5] = nibbles[7].toInteger() == 15; - - int calcNib = nibbles[4].toInteger() - nibbles[3].toInteger() - nibbles[2].toInteger(); - bits[6] = bits[2] && !(calcNib < 16); - - nibbles[8] = UnsignedByte.of(calcNib % 16); - - microData.sourceLimbOffset(microData.getAccsAtIndex(2).copy()); - microData.sourceByteOffset(nibbles[2]); - - microData.targetLimbOffset(microData.getAccsAtIndex(4).copy()); - microData.sourceByteOffset(nibbles[4]); - } - - private void dispatchTern2(MicroData microData) { - EWord off1 = EWord.of(microData.pointers().stack1()); - UnsignedByte[] nibbles = microData.nibbles(); - - // ACC_3 & NIB_3 - EWord acc3 = off1.divide(16); - microData.setAccsAtIndex(2, acc3); - - int nib3 = off1.mod(16).toInt(); - nibbles[2] = UnsignedByte.of(nib3); - - // ACC_4 & NIB_4 - EWord sum = EWord.of(microData.sizeImported() - 1).add(off1); - EWord acc4 = sum.divide(16).add(off1); - microData.setAccsAtIndex(3, acc4); - - int nib4 = sum.mod(16).toInt(); - nibbles[3] = UnsignedByte.of(nib4); - - microData.readPad( - ReadPad.builder() - .totalNumberLimbs(0) - .totalNumberPaddingMicroInstructions(acc4.subtract(acc3).add(1).toInt()) - .build()); - - boolean[] bits = microData.bits(); - - bits[0] = microData.readPad().totalNumber() == 1; - bits[2] = nib3 == 0; - bits[3] = nib4 == 15; - - microData.targetLimbOffset(acc3); - microData.targetByteOffset(UnsignedByte.of(nib3)); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type5PreComputation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type5PreComputation.java deleted file mode 100644 index faf830371..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Type5PreComputation.java +++ /dev/null @@ -1,223 +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.mmu; - -import java.util.Map; -import java.util.Set; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.runtime.callstack.CallStack; -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.commons.lang3.BooleanUtils; - -@AllArgsConstructor(access = AccessLevel.PACKAGE) -class Type5PreComputation implements MmuPreComputation { - private static final Set TYPES = Set.of(MmuTrace.type5); - - @Override - public MicroData dispatch( - final MicroData microData, - final OpCode opCode, - final Map stackOps, - final CallStack callStack) { - microData.callStackDepth(callStack.depth()); - microData.value(stackOps.get(3).value().copy()); - - if (microData.callStackDepth() == 1) { - microData.sourceContext(0); - } else { - microData.sourceContext(callStack.caller().contextNumber()); - } - - microData.pointers(Pointers.builder().stack1(stackOps.get(0).value().copy()).build()); - - final EWord offset = EWord.of(microData.pointers().stack1().copy()); - microData.callDataSize(callStack.caller().callDataRange().length().toInt()); - - int callDataSize = microData.callDataSize(); - final EWord callDataSizeEWord = EWord.of(callDataSize); - - if (callDataSize == 0 || callDataSizeEWord.lessOrEqualThan(offset)) { - microData.skip(true); - - return microData; - } - - boolean[] bits = microData.bits(); - bits[0] = EWord.THIRTY_TWO.add(offset).lessOrEqualThan(callDataSizeEWord); - - int bits0Int = BooleanUtils.toInteger(bits[0]); - int exp = - bits[0] - ? callDataSizeEWord.subtract(offset).subtract(32).getAsBigInteger().intValue() - + bits0Int - - 1 - : EWord.THIRTY_TWO.add(offset).subtract(callDataSize).getAsBigInteger().intValue() - + bits0Int - - 1; - - microData.setAccsAtIndex(0, EWord.of(exp)); - - EWord acc2 = bits[0] ? EWord.THIRTY_ONE : EWord.of(callDataSize - 1).subtract(offset); - - microData.setAccsAtIndex(1, acc2); - - bits[1] = !microData.getAccsAtIndex(1).divide(16).isZero(); - - UnsignedByte[] nibbles = microData.nibbles(); - nibbles[1] = UnsignedByte.of(microData.getAccsAtIndex(1).mod(16).toLong()); - - bits[2] = nibbles[1].toInteger() == 15; - - microData.readPad( - callDataSize == 1 - ? ReadPad.builder().totalNumberLimbs(4).totalNumberPaddingMicroInstructions(0).build() - : ReadPad.builder().totalNumberLimbs(1).totalNumberPaddingMicroInstructions(0).build()); - - microData.callDataOffset(callStack.caller().callDataRange().absolute().toInt()); - - int fullOffset = offset.add(microData.callDataOffset()).toInt(); - microData.setAccsAtIndex(2, EWord.of(fullOffset / 16)); - - nibbles[2] = UnsignedByte.of(fullOffset % 16); - microData.aligned(nibbles[2].toInteger() == 0); - - if (!microData.aligned()) { - bits[3] = 15 - nibbles[2].toInteger() < nibbles[1].toInteger(); - } - - int bits3Int = BooleanUtils.toInteger(bits[3]); - nibbles[3] = - UnsignedByte.of( - (2 * bits3Int - 1) * nibbles[1].toInteger() - 15 + nibbles[2].toInteger() - bits3Int); - - microData.sourceLimbOffset(microData.getAccsAtIndex(2).copy()); - microData.sourceByteOffset(nibbles[2]); - - return microData; - } - - @Override - public MicroData preProcess(MicroData microData, CallStack callStack) { - return microData; - } - - @Override - public MicroData process(MicroData microData, CallStack callStack) { - updateMicroOpType5(microData, callStack); - updateOffsetType5(microData, callStack); - - return microData; - } - - @Override - public Set preComputationTypes() { - return TYPES; - } - - private void updateOffsetType5(MicroData microData, final CallStack callStack) { - EWord acc3 = microData.getAccsAtIndex(2); - UnsignedByte[] nibbles = microData.nibbles(); - - if (microData.isLastRead()) { - microData.size(1 + nibbles[1].toInteger()); - } - - if (callStack.depth() == 1) { - switch (microData.remainingReads()) { - case 3 -> microData.sourceLimbOffset(acc3); - case 2 -> microData.sourceLimbOffset(acc3.add(1)); - case 1 -> microData.sourceLimbOffset(acc3.add(2)); - case 0 -> microData.sourceLimbOffset(EWord.ZERO); - default -> throw new IllegalStateException( - "Unexpected value: %s".formatted(microData.remainingReads())); - } - } else { - if (!microData.isLastRead()) { - throw new IllegalStateException("Should never happen"); - } - microData.sourceLimbOffset(acc3); - } - microData.sourceByteOffset(nibbles[2]); - } - - private void updateMicroOpType5(MicroData microData, final CallStack callStack) { - microData.exoIsTxcd(!microData.isLastRead()); - - switch (microData.remainingReads()) { - case 3 -> { - checkCallStackDepth(callStack); - microData.microOp(MmuTrace.StoreXInAThreeRequired); - } - case 2 -> { - checkCallStackDepth(callStack); - microData.microOp(MmuTrace.StoreXInB); - } - case 1 -> { - checkCallStackDepth(callStack); - microData.microOp(MmuTrace.StoreXInC); - } - case 0 -> { - boolean[] bits = microData.bits(); - if (callStack.depth() != 1) { - if (microData.aligned()) { - if (!bits[1] && bits[2]) { - microData.microOp(MmuTrace.FirstPaddedSecondZero); - } else if (!bits[1]) { - microData.microOp(MmuTrace.PushOneRamToStack); - } else if (!bits[2]) { - microData.microOp(MmuTrace.FirstFastSecondPadded); - } else { - microData.microOp(MmuTrace.PushTwoRamToStack); - } - } else { - if (!bits[1] && !bits[2]) { - microData.microOp( - bits[3] - ? MmuTrace.NA_RamToStack_2To1PaddedAndZero - : MmuTrace.NA_RamToStack_1To1PaddedAndZero); - } else if (!bits[1]) { - microData.microOp(MmuTrace.NA_RamToStack_2To1FullAndZero); - } else if (!bits[2]) { - microData.microOp( - bits[3] ? MmuTrace.NA_RamToStack_3To2Padded : MmuTrace.NA_RamToStack_2To2Padded); - } else { - microData.microOp(MmuTrace.NA_RamToStack_3To2Full); - } - } - } else { - if (microData.aligned() && bits[2]) { - microData.microOp(MmuTrace.ExceptionalRamToStack3To2FullFast); - } else { - microData.microOp(MmuTrace.Exceptional_RamToStack_3To2Full); - } - } - } - default -> throw new IllegalStateException( - "Unexpected value: %s".formatted(microData.remainingReads())); - } - } - - private static void checkCallStackDepth(CallStack callStack) { - if (callStack.depth() != 1) { - throw new IllegalStateException("Should never happen"); - } - } -} 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 deleted file mode 100644 index 63b47150d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/Mod.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.mod; - -import java.nio.MappedByteBuffer; -import java.util.List; - -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.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 - public String moduleKey() { - return "MOD"; - } - - private final StackedSet chunks = new StackedSet<>(); - - @Override - public void tracePreOpcode(final MessageFrame frame) { - final OpCodeData opCodeData = OpCodes.of(frame.getCurrentOperation().getOpcode()); - final Bytes32 arg1 = Bytes32.leftPad(frame.getStackItem(0)); - final Bytes32 arg2 = Bytes32.leftPad(frame.getStackItem(1)); - - this.chunks.add(new ModOperation(opCodeData, arg1, arg2)); - } - - @Override - public void enterTransaction() { - this.chunks.enter(); - } - - @Override - 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); - int stamp = 0; - for (ModOperation op : this.chunks) { - stamp++; - op.trace(trace, stamp); - } - } - - @Override - public int lineCount() { - return this.chunks.lineCount(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - /** - * Performs a context-free call to the DIV opcode in the current trace. - * - * @param arg1 the divider - * @param arg2 the dividend - */ - public void callDiv(Bytes32 arg1, Bytes32 arg2) { - this.chunks.add(new ModOperation(OpCode.DIV, arg1, arg2)); - } - - /** - * Performs a context-free call to the MOD opcode in the current trace. - * - * @param arg1 the number - * @param arg2 the module - */ - public void callMod(Bytes32 arg1, Bytes32 arg2) { - this.chunks.add(new ModOperation(OpCode.MOD, arg1, arg2)); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/ModOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/ModOperation.java deleted file mode 100644 index 83ca61d58..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/ModOperation.java +++ /dev/null @@ -1,300 +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.mod; - -import static com.google.common.base.Preconditions.checkElementIndex; -import static net.consensys.linea.zktracer.module.Util.byteBits; - -import java.math.BigInteger; -import java.util.Arrays; - -import lombok.EqualsAndHashCode; -import net.consensys.linea.zktracer.bytestheta.BaseBytes; -import net.consensys.linea.zktracer.bytestheta.BaseTheta; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.OpCodeData; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; -import org.apache.tuweni.units.bigints.UInt64; - -@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) -public class ModOperation extends ModuleOperation { - private static final int MMEDIUM = 8; - - @EqualsAndHashCode.Include private final OpCode opCode; - @EqualsAndHashCode.Include private final Bytes32 rawArg1; - @EqualsAndHashCode.Include private final Bytes32 rawArg2; - private final boolean oli; - private BaseBytes arg1; - private BaseBytes arg2; - - private BaseBytes result = BaseBytes.fromBytes32(Bytes32.ZERO); - private BaseTheta aBytes = BaseTheta.fromBytes32(Bytes32.ZERO); - private BaseTheta bBytes = BaseTheta.fromBytes32(Bytes32.ZERO); - private BaseTheta qBytes = BaseTheta.fromBytes32(Bytes32.ZERO); - private BaseTheta rBytes = BaseTheta.fromBytes32(Bytes32.ZERO); - private BaseTheta hBytes = BaseTheta.fromBytes32(Bytes32.ZERO); - private BaseTheta dBytes = BaseTheta.fromBytes32(Bytes32.ZERO); - private final boolean[] cmp1 = new boolean[8]; - private final boolean[] cmp2 = new boolean[8]; - private Boolean[] msb1 = new Boolean[8]; - private Boolean[] msb2 = new Boolean[8]; - - public ModOperation(OpCodeData opCodeData, Bytes32 arg1, Bytes32 arg2) { - this(opCodeData.mnemonic(), arg1, arg2); - } - - public ModOperation(OpCode opCode, Bytes32 arg1, Bytes32 arg2) { - this.rawArg1 = arg1; - this.rawArg2 = arg2; - - this.opCode = opCode; - this.oli = arg2.isZero(); - } - - private void compute() { - this.arg1 = BaseBytes.fromBytes32(this.rawArg1); - this.arg2 = BaseBytes.fromBytes32(this.rawArg2); - - Arrays.fill(msb1, false); - Arrays.fill(msb2, false); - - if (!this.oli) { - this.result = getRes(opCode, this.rawArg1, this.rawArg2); - - UInt256 a = absoluteValueIfSignedInst(this.rawArg1); - this.aBytes = BaseTheta.fromBytes32(a); - - UInt256 b = absoluteValueIfSignedInst(this.rawArg2); - this.bBytes = BaseTheta.fromBytes32(b); - - UInt256 q = a.divide(b); - this.qBytes = BaseTheta.fromBytes32(q); - - UInt256 r = a.mod(b); - this.rBytes = BaseTheta.fromBytes32(r); - - this.dBytes = BaseTheta.fromBytes32(Bytes32.ZERO); - this.setCmp12(); - this.setDeltas(); - this.setAlphaBetasH012(); - - UnsignedByte msb1 = UnsignedByte.of(this.arg1.getHigh().get(0)); - UnsignedByte msb2 = UnsignedByte.of(this.arg2.getHigh().get(0)); - - this.msb1 = byteBits(msb1); - this.msb2 = byteBits(msb2); - } - } - - private static BaseBytes getRes(OpCode op, Bytes32 arg1, Bytes32 arg2) { - return switch (op) { - case DIV -> BaseBytes.fromBytes32(UInt256.fromBytes(arg1).divide(UInt256.fromBytes(arg2))); - case SDIV -> BaseBytes.fromBytes32(UInt256.fromBytes(arg1).sdiv0(UInt256.fromBytes(arg2))); - case MOD -> BaseBytes.fromBytes32(UInt256.fromBytes(arg1).mod(UInt256.fromBytes(arg2))); - case SMOD -> BaseBytes.fromBytes32(UInt256.fromBytes(arg1).smod0(UInt256.fromBytes(arg2))); - default -> throw new IllegalArgumentException("Modular arithmetic was given wrong opcode"); - }; - } - - private UInt256 absoluteValueIfSignedInst(Bytes32 arg) { - if (isSigned()) { - return UInt256.valueOf(arg.toBigInteger().abs()); - } - return UInt256.fromBytes(arg); - } - - private UInt256 bVar(int k) { - checkElementIndex(k, 4); - return UInt256.fromBytes(bBytes.get(k)); - } - - private UInt256 qVar(int k) { - checkElementIndex(k, 4); - return UInt256.fromBytes(qBytes.get(k)); - } - - private UInt256 rVar(int k) { - checkElementIndex(k, 4); - return UInt256.fromBytes(rBytes.get(k)); - } - - private UInt256 hVar(int k) { - checkElementIndex(k, 3); - return UInt256.fromBytes(hBytes.get(k)); - } - - private void setCmp12() { - for (int k = 0; k < 4; k++) { - cmp1[k] = bVar(k).compareTo(rVar(k)) > 0; - cmp2[k] = bVar(k).compareTo(rVar(k)) == 0; - } - } - - private void setDeltas() { - for (int k = 0; k < 4; k++) { - UInt256 delta; - if (this.cmp1[k]) { - delta = bVar(k).subtract(rVar(k)).subtract(UInt256.ONE); - } else { - delta = rVar(k).subtract(bVar(k)); - } - dBytes.set(k, delta.slice(24, 8)); - } - } - - private void setAlphaBetasH012() { - UInt256 theta = UInt256.ONE; - UInt256 thetaSquared = UInt256.ONE; - - theta = theta.shiftLeft(64); - thetaSquared = thetaSquared.shiftLeft(128); - - UInt256 sum = bVar(0).multiply(qVar(1)).add(bVar(1).multiply(qVar(0))); - this.hBytes = BaseTheta.fromBytes32(sum); - - // alpha - cmp2[4] = sum.compareTo(thetaSquared) >= 0; - - sum = - bVar(0) - .multiply(qVar(3)) - .add(bVar(1).multiply(qVar(2))) - .add(bVar(2).multiply(qVar(1))) - .add(bVar(3).multiply(qVar(0))); - - if (sum.bitLength() > 64) { - throw new RuntimeException("b[0]q[3] + b[1]q[2] + b[2]q[1] + b[3]q[0] >= (1 << 64)"); - } - - hBytes.set(2, sum.slice(24, 8)); - - sum = qVar(0).multiply(bVar(0)); - sum = sum.add(hVar(0).multiply(theta)); - sum = sum.add(UInt256.fromBytes(rBytes.getLow())); - - UInt256 beta = sum.divide(thetaSquared); - if (beta.compareTo(UInt256.valueOf(2)) > 0) { - throw new RuntimeException("b[0]q[0] + theta.h[0] + rLo = [beta|...] with beta > 2"); - } - - UInt64 betaUInt64 = UInt64.valueOf(beta.toUnsignedBigInteger()); - cmp2[5] = betaUInt64.mod(UInt64.valueOf(2)).compareTo(UInt64.ONE) == 0; // beta_0 - cmp2[6] = betaUInt64.divide(UInt64.valueOf(2)).compareTo(UInt64.ONE) == 0; // beta_1 - - BigInteger sumInt = sum.mod(thetaSquared).toUnsignedBigInteger(); - BigInteger aLo = this.aBytes.getLow().toUnsignedBigInteger(); - if (sumInt.compareTo(aLo) != 0) { - throw new RuntimeException("b[0]q[0] + theta.h[0] + rLo = [beta|xxx] and xxx != aLo"); - } - } - - boolean isSigned() { - return this.opCode == OpCode.SDIV || this.opCode == OpCode.SMOD; - } - - boolean isDiv() { - return this.opCode == OpCode.DIV || this.opCode == OpCode.SDIV; - } - - int maxCounter() { - if (this.oli) { - return 1; - } else { - return MMEDIUM; - } - } - - public void trace(Trace trace, int stamp) { - this.compute(); - - for (int i = 0; i < this.maxCounter(); i++) { - final int accLength = i + 1; - trace - .stamp(Bytes.ofUnsignedLong(stamp)) - .oli(this.oli) - .ct(Bytes.of(i)) - .inst(Bytes.of(this.opCode.byteValue())) - .decSigned(this.isSigned()) - .decOutput(this.isDiv()) - .arg1Hi(this.arg1.getHigh()) - .arg1Lo(this.arg1.getLow()) - .arg2Hi(this.arg2.getHigh()) - .arg2Lo(this.arg2.getLow()) - .resHi(this.result.getHigh()) - .resLo(this.result.getLow()) - .acc12(this.arg1.getBytes32().slice(8, i + 1)) - .acc13(this.arg1.getBytes32().slice(0, i + 1)) - .acc22(this.arg2.getBytes32().slice(8, i + 1)) - .acc23(this.arg2.getBytes32().slice(0, i + 1)) - .accB0(this.bBytes.get(0).slice(0, accLength)) - .accB1(this.bBytes.get(1).slice(0, accLength)) - .accB2(this.bBytes.get(2).slice(0, accLength)) - .accB3(this.bBytes.get(3).slice(0, accLength)) - .accR0(this.rBytes.get(0).slice(0, accLength)) - .accR1(this.rBytes.get(1).slice(0, accLength)) - .accR2(this.rBytes.get(2).slice(0, accLength)) - .accR3(this.rBytes.get(3).slice(0, accLength)) - .accQ0(this.qBytes.get(0).slice(0, accLength)) - .accQ1(this.qBytes.get(1).slice(0, accLength)) - .accQ2(this.qBytes.get(2).slice(0, accLength)) - .accQ3(this.qBytes.get(3).slice(0, accLength)) - .accDelta0(this.dBytes.get(0).slice(0, accLength)) - .accDelta1(this.dBytes.get(1).slice(0, accLength)) - .accDelta2(this.dBytes.get(2).slice(0, accLength)) - .accDelta3(this.dBytes.get(3).slice(0, accLength)) - .byte22(UnsignedByte.of(this.arg2.getByte(i + 8))) - .byte23(UnsignedByte.of(this.arg2.getByte(i))) - .byte12(UnsignedByte.of(this.arg1.getByte(i + 8))) - .byte13(UnsignedByte.of(this.arg1.getByte(i))) - .byteB0(UnsignedByte.of(this.bBytes.get(0).get(i))) - .byteB1(UnsignedByte.of(this.bBytes.get(1).get(i))) - .byteB2(UnsignedByte.of(this.bBytes.get(2).get(i))) - .byteB3(UnsignedByte.of(this.bBytes.get(3).get(i))) - .byteR0(UnsignedByte.of(this.rBytes.get(0).get(i))) - .byteR1(UnsignedByte.of(this.rBytes.get(1).get(i))) - .byteR2(UnsignedByte.of(this.rBytes.get(2).get(i))) - .byteR3(UnsignedByte.of(this.rBytes.get(3).get(i))) - .byteQ0(UnsignedByte.of(this.qBytes.get(0).get(i))) - .byteQ1(UnsignedByte.of(this.qBytes.get(1).get(i))) - .byteQ2(UnsignedByte.of(this.qBytes.get(2).get(i))) - .byteQ3(UnsignedByte.of(this.qBytes.get(3).get(i))) - .byteDelta0(UnsignedByte.of(this.dBytes.get(0).get(i))) - .byteDelta1(UnsignedByte.of(this.dBytes.get(1).get(i))) - .byteDelta2(UnsignedByte.of(this.dBytes.get(2).get(i))) - .byteDelta3(UnsignedByte.of(this.dBytes.get(3).get(i))) - .byteH0(UnsignedByte.of(this.hBytes.get(0).get(i))) - .byteH1(UnsignedByte.of(this.hBytes.get(1).get(i))) - .byteH2(UnsignedByte.of(this.hBytes.get(2).get(i))) - .accH0(Bytes.wrap(this.hBytes.get(0)).slice(0, i + 1)) - .accH1(Bytes.wrap(this.hBytes.get(1)).slice(0, i + 1)) - .accH2(Bytes.wrap(this.hBytes.get(2)).slice(0, i + 1)) - .cmp1(this.cmp1[i]) - .cmp2(this.cmp2[i]) - .msb1(this.msb1[i]) - .msb2(this.msb2[i]) - .validateRow(); - } - } - - @Override - protected int computeLineCount() { - return this.maxCounter(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/Trace.java deleted file mode 100644 index 61edaad7b..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/Trace.java +++ /dev/null @@ -1,1626 +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.mod; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer acc12; - private final MappedByteBuffer acc13; - private final MappedByteBuffer acc22; - private final MappedByteBuffer acc23; - private final MappedByteBuffer accB0; - private final MappedByteBuffer accB1; - private final MappedByteBuffer accB2; - private final MappedByteBuffer accB3; - private final MappedByteBuffer accDelta0; - private final MappedByteBuffer accDelta1; - private final MappedByteBuffer accDelta2; - private final MappedByteBuffer accDelta3; - private final MappedByteBuffer accH0; - private final MappedByteBuffer accH1; - private final MappedByteBuffer accH2; - private final MappedByteBuffer accQ0; - private final MappedByteBuffer accQ1; - private final MappedByteBuffer accQ2; - private final MappedByteBuffer accQ3; - private final MappedByteBuffer accR0; - private final MappedByteBuffer accR1; - private final MappedByteBuffer accR2; - private final MappedByteBuffer accR3; - private final MappedByteBuffer arg1Hi; - private final MappedByteBuffer arg1Lo; - private final MappedByteBuffer arg2Hi; - private final MappedByteBuffer arg2Lo; - private final MappedByteBuffer byte12; - private final MappedByteBuffer byte13; - private final MappedByteBuffer byte22; - private final MappedByteBuffer byte23; - private final MappedByteBuffer byteB0; - private final MappedByteBuffer byteB1; - private final MappedByteBuffer byteB2; - private final MappedByteBuffer byteB3; - private final MappedByteBuffer byteDelta0; - private final MappedByteBuffer byteDelta1; - private final MappedByteBuffer byteDelta2; - private final MappedByteBuffer byteDelta3; - private final MappedByteBuffer byteH0; - private final MappedByteBuffer byteH1; - private final MappedByteBuffer byteH2; - private final MappedByteBuffer byteQ0; - private final MappedByteBuffer byteQ1; - private final MappedByteBuffer byteQ2; - private final MappedByteBuffer byteQ3; - private final MappedByteBuffer byteR0; - private final MappedByteBuffer byteR1; - private final MappedByteBuffer byteR2; - private final MappedByteBuffer byteR3; - private final MappedByteBuffer cmp1; - private final MappedByteBuffer cmp2; - private final MappedByteBuffer ct; - private final MappedByteBuffer decOutput; - private final MappedByteBuffer decSigned; - private final MappedByteBuffer inst; - private final MappedByteBuffer msb1; - private final MappedByteBuffer msb2; - private final MappedByteBuffer oli; - private final MappedByteBuffer resHi; - private final MappedByteBuffer resLo; - private final MappedByteBuffer stamp; - - static List headers(int length) { - return List.of( - new ColumnHeader("mod.ACC_1_2", 32, length), - new ColumnHeader("mod.ACC_1_3", 32, length), - new ColumnHeader("mod.ACC_2_2", 32, length), - new ColumnHeader("mod.ACC_2_3", 32, length), - new ColumnHeader("mod.ACC_B_0", 32, length), - new ColumnHeader("mod.ACC_B_1", 32, length), - new ColumnHeader("mod.ACC_B_2", 32, length), - new ColumnHeader("mod.ACC_B_3", 32, length), - new ColumnHeader("mod.ACC_DELTA_0", 32, length), - new ColumnHeader("mod.ACC_DELTA_1", 32, length), - new ColumnHeader("mod.ACC_DELTA_2", 32, length), - new ColumnHeader("mod.ACC_DELTA_3", 32, length), - new ColumnHeader("mod.ACC_H_0", 32, length), - new ColumnHeader("mod.ACC_H_1", 32, length), - new ColumnHeader("mod.ACC_H_2", 32, length), - new ColumnHeader("mod.ACC_Q_0", 32, length), - new ColumnHeader("mod.ACC_Q_1", 32, length), - new ColumnHeader("mod.ACC_Q_2", 32, length), - new ColumnHeader("mod.ACC_Q_3", 32, length), - new ColumnHeader("mod.ACC_R_0", 32, length), - new ColumnHeader("mod.ACC_R_1", 32, length), - new ColumnHeader("mod.ACC_R_2", 32, length), - new ColumnHeader("mod.ACC_R_3", 32, length), - new ColumnHeader("mod.ARG_1_HI", 32, length), - new ColumnHeader("mod.ARG_1_LO", 32, length), - new ColumnHeader("mod.ARG_2_HI", 32, length), - new ColumnHeader("mod.ARG_2_LO", 32, length), - new ColumnHeader("mod.BYTE_1_2", 1, length), - new ColumnHeader("mod.BYTE_1_3", 1, length), - new ColumnHeader("mod.BYTE_2_2", 1, length), - new ColumnHeader("mod.BYTE_2_3", 1, length), - new ColumnHeader("mod.BYTE_B_0", 1, length), - new ColumnHeader("mod.BYTE_B_1", 1, length), - new ColumnHeader("mod.BYTE_B_2", 1, length), - new ColumnHeader("mod.BYTE_B_3", 1, length), - new ColumnHeader("mod.BYTE_DELTA_0", 1, length), - new ColumnHeader("mod.BYTE_DELTA_1", 1, length), - new ColumnHeader("mod.BYTE_DELTA_2", 1, length), - new ColumnHeader("mod.BYTE_DELTA_3", 1, length), - new ColumnHeader("mod.BYTE_H_0", 1, length), - new ColumnHeader("mod.BYTE_H_1", 1, length), - new ColumnHeader("mod.BYTE_H_2", 1, length), - new ColumnHeader("mod.BYTE_Q_0", 1, length), - new ColumnHeader("mod.BYTE_Q_1", 1, length), - new ColumnHeader("mod.BYTE_Q_2", 1, length), - new ColumnHeader("mod.BYTE_Q_3", 1, length), - new ColumnHeader("mod.BYTE_R_0", 1, length), - new ColumnHeader("mod.BYTE_R_1", 1, length), - new ColumnHeader("mod.BYTE_R_2", 1, length), - new ColumnHeader("mod.BYTE_R_3", 1, length), - new ColumnHeader("mod.CMP_1", 1, length), - new ColumnHeader("mod.CMP_2", 1, length), - new ColumnHeader("mod.CT", 32, length), - new ColumnHeader("mod.DEC_OUTPUT", 1, length), - new ColumnHeader("mod.DEC_SIGNED", 1, length), - new ColumnHeader("mod.INST", 32, length), - new ColumnHeader("mod.MSB_1", 1, length), - new ColumnHeader("mod.MSB_2", 1, length), - new ColumnHeader("mod.OLI", 1, length), - new ColumnHeader("mod.RES_HI", 32, length), - new ColumnHeader("mod.RES_LO", 32, length), - new ColumnHeader("mod.STAMP", 32, length)); - } - - public Trace(List buffers) { - this.acc12 = buffers.get(0); - this.acc13 = buffers.get(1); - this.acc22 = buffers.get(2); - this.acc23 = buffers.get(3); - this.accB0 = buffers.get(4); - this.accB1 = buffers.get(5); - this.accB2 = buffers.get(6); - this.accB3 = buffers.get(7); - this.accDelta0 = buffers.get(8); - this.accDelta1 = buffers.get(9); - this.accDelta2 = buffers.get(10); - this.accDelta3 = buffers.get(11); - this.accH0 = buffers.get(12); - this.accH1 = buffers.get(13); - this.accH2 = buffers.get(14); - this.accQ0 = buffers.get(15); - this.accQ1 = buffers.get(16); - this.accQ2 = buffers.get(17); - this.accQ3 = buffers.get(18); - this.accR0 = buffers.get(19); - this.accR1 = buffers.get(20); - this.accR2 = buffers.get(21); - this.accR3 = buffers.get(22); - this.arg1Hi = buffers.get(23); - this.arg1Lo = buffers.get(24); - this.arg2Hi = buffers.get(25); - this.arg2Lo = buffers.get(26); - this.byte12 = buffers.get(27); - this.byte13 = buffers.get(28); - this.byte22 = buffers.get(29); - this.byte23 = buffers.get(30); - this.byteB0 = buffers.get(31); - this.byteB1 = buffers.get(32); - this.byteB2 = buffers.get(33); - this.byteB3 = buffers.get(34); - this.byteDelta0 = buffers.get(35); - this.byteDelta1 = buffers.get(36); - this.byteDelta2 = buffers.get(37); - this.byteDelta3 = buffers.get(38); - this.byteH0 = buffers.get(39); - this.byteH1 = buffers.get(40); - this.byteH2 = buffers.get(41); - this.byteQ0 = buffers.get(42); - this.byteQ1 = buffers.get(43); - this.byteQ2 = buffers.get(44); - this.byteQ3 = buffers.get(45); - this.byteR0 = buffers.get(46); - this.byteR1 = buffers.get(47); - this.byteR2 = buffers.get(48); - this.byteR3 = buffers.get(49); - this.cmp1 = buffers.get(50); - this.cmp2 = buffers.get(51); - this.ct = buffers.get(52); - this.decOutput = buffers.get(53); - this.decSigned = buffers.get(54); - this.inst = buffers.get(55); - this.msb1 = buffers.get(56); - this.msb2 = buffers.get(57); - this.oli = buffers.get(58); - this.resHi = buffers.get(59); - this.resLo = buffers.get(60); - this.stamp = buffers.get(61); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace acc12(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("mod.ACC_1_2 already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc12.put((byte) 0); - } - acc12.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc13(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("mod.ACC_1_3 already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc13.put((byte) 0); - } - acc13.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc22(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("mod.ACC_2_2 already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc22.put((byte) 0); - } - acc22.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc23(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("mod.ACC_2_3 already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc23.put((byte) 0); - } - acc23.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB0(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("mod.ACC_B_0 already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB0.put((byte) 0); - } - accB0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB1(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("mod.ACC_B_1 already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB1.put((byte) 0); - } - accB1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB2(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("mod.ACC_B_2 already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB2.put((byte) 0); - } - accB2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB3(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("mod.ACC_B_3 already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB3.put((byte) 0); - } - accB3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accDelta0(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("mod.ACC_DELTA_0 already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accDelta0.put((byte) 0); - } - accDelta0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accDelta1(final Bytes b) { - if (filled.get(9)) { - throw new IllegalStateException("mod.ACC_DELTA_1 already set"); - } else { - filled.set(9); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accDelta1.put((byte) 0); - } - accDelta1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accDelta2(final Bytes b) { - if (filled.get(10)) { - throw new IllegalStateException("mod.ACC_DELTA_2 already set"); - } else { - filled.set(10); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accDelta2.put((byte) 0); - } - accDelta2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accDelta3(final Bytes b) { - if (filled.get(11)) { - throw new IllegalStateException("mod.ACC_DELTA_3 already set"); - } else { - filled.set(11); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accDelta3.put((byte) 0); - } - accDelta3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH0(final Bytes b) { - if (filled.get(12)) { - throw new IllegalStateException("mod.ACC_H_0 already set"); - } else { - filled.set(12); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH0.put((byte) 0); - } - accH0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH1(final Bytes b) { - if (filled.get(13)) { - throw new IllegalStateException("mod.ACC_H_1 already set"); - } else { - filled.set(13); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH1.put((byte) 0); - } - accH1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH2(final Bytes b) { - if (filled.get(14)) { - throw new IllegalStateException("mod.ACC_H_2 already set"); - } else { - filled.set(14); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH2.put((byte) 0); - } - accH2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ0(final Bytes b) { - if (filled.get(15)) { - throw new IllegalStateException("mod.ACC_Q_0 already set"); - } else { - filled.set(15); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ0.put((byte) 0); - } - accQ0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ1(final Bytes b) { - if (filled.get(16)) { - throw new IllegalStateException("mod.ACC_Q_1 already set"); - } else { - filled.set(16); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ1.put((byte) 0); - } - accQ1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ2(final Bytes b) { - if (filled.get(17)) { - throw new IllegalStateException("mod.ACC_Q_2 already set"); - } else { - filled.set(17); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ2.put((byte) 0); - } - accQ2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ3(final Bytes b) { - if (filled.get(18)) { - throw new IllegalStateException("mod.ACC_Q_3 already set"); - } else { - filled.set(18); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ3.put((byte) 0); - } - accQ3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accR0(final Bytes b) { - if (filled.get(19)) { - throw new IllegalStateException("mod.ACC_R_0 already set"); - } else { - filled.set(19); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accR0.put((byte) 0); - } - accR0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accR1(final Bytes b) { - if (filled.get(20)) { - throw new IllegalStateException("mod.ACC_R_1 already set"); - } else { - filled.set(20); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accR1.put((byte) 0); - } - accR1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accR2(final Bytes b) { - if (filled.get(21)) { - throw new IllegalStateException("mod.ACC_R_2 already set"); - } else { - filled.set(21); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accR2.put((byte) 0); - } - accR2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accR3(final Bytes b) { - if (filled.get(22)) { - throw new IllegalStateException("mod.ACC_R_3 already set"); - } else { - filled.set(22); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accR3.put((byte) 0); - } - accR3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg1Hi(final Bytes b) { - if (filled.get(23)) { - throw new IllegalStateException("mod.ARG_1_HI already set"); - } else { - filled.set(23); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Hi.put((byte) 0); - } - arg1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg1Lo(final Bytes b) { - if (filled.get(24)) { - throw new IllegalStateException("mod.ARG_1_LO already set"); - } else { - filled.set(24); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Lo.put((byte) 0); - } - arg1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg2Hi(final Bytes b) { - if (filled.get(25)) { - throw new IllegalStateException("mod.ARG_2_HI already set"); - } else { - filled.set(25); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg2Hi.put((byte) 0); - } - arg2Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg2Lo(final Bytes b) { - if (filled.get(26)) { - throw new IllegalStateException("mod.ARG_2_LO already set"); - } else { - filled.set(26); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg2Lo.put((byte) 0); - } - arg2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace byte12(final UnsignedByte b) { - if (filled.get(27)) { - throw new IllegalStateException("mod.BYTE_1_2 already set"); - } else { - filled.set(27); - } - - byte12.put(b.toByte()); - - return this; - } - - public Trace byte13(final UnsignedByte b) { - if (filled.get(28)) { - throw new IllegalStateException("mod.BYTE_1_3 already set"); - } else { - filled.set(28); - } - - byte13.put(b.toByte()); - - return this; - } - - public Trace byte22(final UnsignedByte b) { - if (filled.get(29)) { - throw new IllegalStateException("mod.BYTE_2_2 already set"); - } else { - filled.set(29); - } - - byte22.put(b.toByte()); - - return this; - } - - public Trace byte23(final UnsignedByte b) { - if (filled.get(30)) { - throw new IllegalStateException("mod.BYTE_2_3 already set"); - } else { - filled.set(30); - } - - byte23.put(b.toByte()); - - return this; - } - - public Trace byteB0(final UnsignedByte b) { - if (filled.get(31)) { - throw new IllegalStateException("mod.BYTE_B_0 already set"); - } else { - filled.set(31); - } - - byteB0.put(b.toByte()); - - return this; - } - - public Trace byteB1(final UnsignedByte b) { - if (filled.get(32)) { - throw new IllegalStateException("mod.BYTE_B_1 already set"); - } else { - filled.set(32); - } - - byteB1.put(b.toByte()); - - return this; - } - - public Trace byteB2(final UnsignedByte b) { - if (filled.get(33)) { - throw new IllegalStateException("mod.BYTE_B_2 already set"); - } else { - filled.set(33); - } - - byteB2.put(b.toByte()); - - return this; - } - - public Trace byteB3(final UnsignedByte b) { - if (filled.get(34)) { - throw new IllegalStateException("mod.BYTE_B_3 already set"); - } else { - filled.set(34); - } - - byteB3.put(b.toByte()); - - return this; - } - - public Trace byteDelta0(final UnsignedByte b) { - if (filled.get(35)) { - throw new IllegalStateException("mod.BYTE_DELTA_0 already set"); - } else { - filled.set(35); - } - - byteDelta0.put(b.toByte()); - - return this; - } - - public Trace byteDelta1(final UnsignedByte b) { - if (filled.get(36)) { - throw new IllegalStateException("mod.BYTE_DELTA_1 already set"); - } else { - filled.set(36); - } - - byteDelta1.put(b.toByte()); - - return this; - } - - public Trace byteDelta2(final UnsignedByte b) { - if (filled.get(37)) { - throw new IllegalStateException("mod.BYTE_DELTA_2 already set"); - } else { - filled.set(37); - } - - byteDelta2.put(b.toByte()); - - return this; - } - - public Trace byteDelta3(final UnsignedByte b) { - if (filled.get(38)) { - throw new IllegalStateException("mod.BYTE_DELTA_3 already set"); - } else { - filled.set(38); - } - - byteDelta3.put(b.toByte()); - - return this; - } - - public Trace byteH0(final UnsignedByte b) { - if (filled.get(39)) { - throw new IllegalStateException("mod.BYTE_H_0 already set"); - } else { - filled.set(39); - } - - byteH0.put(b.toByte()); - - return this; - } - - public Trace byteH1(final UnsignedByte b) { - if (filled.get(40)) { - throw new IllegalStateException("mod.BYTE_H_1 already set"); - } else { - filled.set(40); - } - - byteH1.put(b.toByte()); - - return this; - } - - public Trace byteH2(final UnsignedByte b) { - if (filled.get(41)) { - throw new IllegalStateException("mod.BYTE_H_2 already set"); - } else { - filled.set(41); - } - - byteH2.put(b.toByte()); - - return this; - } - - public Trace byteQ0(final UnsignedByte b) { - if (filled.get(42)) { - throw new IllegalStateException("mod.BYTE_Q_0 already set"); - } else { - filled.set(42); - } - - byteQ0.put(b.toByte()); - - return this; - } - - public Trace byteQ1(final UnsignedByte b) { - if (filled.get(43)) { - throw new IllegalStateException("mod.BYTE_Q_1 already set"); - } else { - filled.set(43); - } - - byteQ1.put(b.toByte()); - - return this; - } - - public Trace byteQ2(final UnsignedByte b) { - if (filled.get(44)) { - throw new IllegalStateException("mod.BYTE_Q_2 already set"); - } else { - filled.set(44); - } - - byteQ2.put(b.toByte()); - - return this; - } - - public Trace byteQ3(final UnsignedByte b) { - if (filled.get(45)) { - throw new IllegalStateException("mod.BYTE_Q_3 already set"); - } else { - filled.set(45); - } - - byteQ3.put(b.toByte()); - - return this; - } - - public Trace byteR0(final UnsignedByte b) { - if (filled.get(46)) { - throw new IllegalStateException("mod.BYTE_R_0 already set"); - } else { - filled.set(46); - } - - byteR0.put(b.toByte()); - - return this; - } - - public Trace byteR1(final UnsignedByte b) { - if (filled.get(47)) { - throw new IllegalStateException("mod.BYTE_R_1 already set"); - } else { - filled.set(47); - } - - byteR1.put(b.toByte()); - - return this; - } - - public Trace byteR2(final UnsignedByte b) { - if (filled.get(48)) { - throw new IllegalStateException("mod.BYTE_R_2 already set"); - } else { - filled.set(48); - } - - byteR2.put(b.toByte()); - - return this; - } - - public Trace byteR3(final UnsignedByte b) { - if (filled.get(49)) { - throw new IllegalStateException("mod.BYTE_R_3 already set"); - } else { - filled.set(49); - } - - byteR3.put(b.toByte()); - - return this; - } - - public Trace cmp1(final Boolean b) { - if (filled.get(50)) { - throw new IllegalStateException("mod.CMP_1 already set"); - } else { - filled.set(50); - } - - cmp1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace cmp2(final Boolean b) { - if (filled.get(51)) { - throw new IllegalStateException("mod.CMP_2 already set"); - } else { - filled.set(51); - } - - cmp2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ct(final Bytes b) { - if (filled.get(52)) { - throw new IllegalStateException("mod.CT already set"); - } else { - filled.set(52); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - ct.put((byte) 0); - } - ct.put(b.toArrayUnsafe()); - - return this; - } - - public Trace decOutput(final Boolean b) { - if (filled.get(53)) { - throw new IllegalStateException("mod.DEC_OUTPUT already set"); - } else { - filled.set(53); - } - - decOutput.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace decSigned(final Boolean b) { - if (filled.get(54)) { - throw new IllegalStateException("mod.DEC_SIGNED already set"); - } else { - filled.set(54); - } - - decSigned.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace inst(final Bytes b) { - if (filled.get(55)) { - throw new IllegalStateException("mod.INST already set"); - } else { - filled.set(55); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - inst.put((byte) 0); - } - inst.put(b.toArrayUnsafe()); - - return this; - } - - public Trace msb1(final Boolean b) { - if (filled.get(56)) { - throw new IllegalStateException("mod.MSB_1 already set"); - } else { - filled.set(56); - } - - msb1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace msb2(final Boolean b) { - if (filled.get(57)) { - throw new IllegalStateException("mod.MSB_2 already set"); - } else { - filled.set(57); - } - - msb2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace oli(final Boolean b) { - if (filled.get(58)) { - throw new IllegalStateException("mod.OLI already set"); - } else { - filled.set(58); - } - - oli.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace resHi(final Bytes b) { - if (filled.get(59)) { - throw new IllegalStateException("mod.RES_HI already set"); - } else { - filled.set(59); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resHi.put((byte) 0); - } - resHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace resLo(final Bytes b) { - if (filled.get(60)) { - throw new IllegalStateException("mod.RES_LO already set"); - } else { - filled.set(60); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resLo.put((byte) 0); - } - resLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace stamp(final Bytes b) { - if (filled.get(61)) { - throw new IllegalStateException("mod.STAMP already set"); - } else { - filled.set(61); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stamp.put((byte) 0); - } - stamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("mod.ACC_1_2 has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("mod.ACC_1_3 has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("mod.ACC_2_2 has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("mod.ACC_2_3 has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("mod.ACC_B_0 has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("mod.ACC_B_1 has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("mod.ACC_B_2 has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("mod.ACC_B_3 has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("mod.ACC_DELTA_0 has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("mod.ACC_DELTA_1 has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("mod.ACC_DELTA_2 has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("mod.ACC_DELTA_3 has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("mod.ACC_H_0 has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("mod.ACC_H_1 has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("mod.ACC_H_2 has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("mod.ACC_Q_0 has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("mod.ACC_Q_1 has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("mod.ACC_Q_2 has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("mod.ACC_Q_3 has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("mod.ACC_R_0 has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("mod.ACC_R_1 has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("mod.ACC_R_2 has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("mod.ACC_R_3 has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("mod.ARG_1_HI has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("mod.ARG_1_LO has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("mod.ARG_2_HI has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("mod.ARG_2_LO has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("mod.BYTE_1_2 has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("mod.BYTE_1_3 has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("mod.BYTE_2_2 has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("mod.BYTE_2_3 has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("mod.BYTE_B_0 has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("mod.BYTE_B_1 has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("mod.BYTE_B_2 has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("mod.BYTE_B_3 has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("mod.BYTE_DELTA_0 has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("mod.BYTE_DELTA_1 has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("mod.BYTE_DELTA_2 has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("mod.BYTE_DELTA_3 has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("mod.BYTE_H_0 has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("mod.BYTE_H_1 has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("mod.BYTE_H_2 has not been filled"); - } - - if (!filled.get(42)) { - throw new IllegalStateException("mod.BYTE_Q_0 has not been filled"); - } - - if (!filled.get(43)) { - throw new IllegalStateException("mod.BYTE_Q_1 has not been filled"); - } - - if (!filled.get(44)) { - throw new IllegalStateException("mod.BYTE_Q_2 has not been filled"); - } - - if (!filled.get(45)) { - throw new IllegalStateException("mod.BYTE_Q_3 has not been filled"); - } - - if (!filled.get(46)) { - throw new IllegalStateException("mod.BYTE_R_0 has not been filled"); - } - - if (!filled.get(47)) { - throw new IllegalStateException("mod.BYTE_R_1 has not been filled"); - } - - if (!filled.get(48)) { - throw new IllegalStateException("mod.BYTE_R_2 has not been filled"); - } - - if (!filled.get(49)) { - throw new IllegalStateException("mod.BYTE_R_3 has not been filled"); - } - - if (!filled.get(50)) { - throw new IllegalStateException("mod.CMP_1 has not been filled"); - } - - if (!filled.get(51)) { - throw new IllegalStateException("mod.CMP_2 has not been filled"); - } - - if (!filled.get(52)) { - throw new IllegalStateException("mod.CT has not been filled"); - } - - if (!filled.get(53)) { - throw new IllegalStateException("mod.DEC_OUTPUT has not been filled"); - } - - if (!filled.get(54)) { - throw new IllegalStateException("mod.DEC_SIGNED has not been filled"); - } - - if (!filled.get(55)) { - throw new IllegalStateException("mod.INST has not been filled"); - } - - if (!filled.get(56)) { - throw new IllegalStateException("mod.MSB_1 has not been filled"); - } - - if (!filled.get(57)) { - throw new IllegalStateException("mod.MSB_2 has not been filled"); - } - - if (!filled.get(58)) { - throw new IllegalStateException("mod.OLI has not been filled"); - } - - if (!filled.get(59)) { - throw new IllegalStateException("mod.RES_HI has not been filled"); - } - - if (!filled.get(60)) { - throw new IllegalStateException("mod.RES_LO has not been filled"); - } - - if (!filled.get(61)) { - throw new IllegalStateException("mod.STAMP has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - acc12.position(acc12.position() + 32); - } - - if (!filled.get(1)) { - acc13.position(acc13.position() + 32); - } - - if (!filled.get(2)) { - acc22.position(acc22.position() + 32); - } - - if (!filled.get(3)) { - acc23.position(acc23.position() + 32); - } - - if (!filled.get(4)) { - accB0.position(accB0.position() + 32); - } - - if (!filled.get(5)) { - accB1.position(accB1.position() + 32); - } - - if (!filled.get(6)) { - accB2.position(accB2.position() + 32); - } - - if (!filled.get(7)) { - accB3.position(accB3.position() + 32); - } - - if (!filled.get(8)) { - accDelta0.position(accDelta0.position() + 32); - } - - if (!filled.get(9)) { - accDelta1.position(accDelta1.position() + 32); - } - - if (!filled.get(10)) { - accDelta2.position(accDelta2.position() + 32); - } - - if (!filled.get(11)) { - accDelta3.position(accDelta3.position() + 32); - } - - if (!filled.get(12)) { - accH0.position(accH0.position() + 32); - } - - if (!filled.get(13)) { - accH1.position(accH1.position() + 32); - } - - if (!filled.get(14)) { - accH2.position(accH2.position() + 32); - } - - if (!filled.get(15)) { - accQ0.position(accQ0.position() + 32); - } - - if (!filled.get(16)) { - accQ1.position(accQ1.position() + 32); - } - - if (!filled.get(17)) { - accQ2.position(accQ2.position() + 32); - } - - if (!filled.get(18)) { - accQ3.position(accQ3.position() + 32); - } - - if (!filled.get(19)) { - accR0.position(accR0.position() + 32); - } - - if (!filled.get(20)) { - accR1.position(accR1.position() + 32); - } - - if (!filled.get(21)) { - accR2.position(accR2.position() + 32); - } - - if (!filled.get(22)) { - accR3.position(accR3.position() + 32); - } - - if (!filled.get(23)) { - arg1Hi.position(arg1Hi.position() + 32); - } - - if (!filled.get(24)) { - arg1Lo.position(arg1Lo.position() + 32); - } - - if (!filled.get(25)) { - arg2Hi.position(arg2Hi.position() + 32); - } - - if (!filled.get(26)) { - arg2Lo.position(arg2Lo.position() + 32); - } - - if (!filled.get(27)) { - byte12.position(byte12.position() + 1); - } - - if (!filled.get(28)) { - byte13.position(byte13.position() + 1); - } - - if (!filled.get(29)) { - byte22.position(byte22.position() + 1); - } - - if (!filled.get(30)) { - byte23.position(byte23.position() + 1); - } - - if (!filled.get(31)) { - byteB0.position(byteB0.position() + 1); - } - - if (!filled.get(32)) { - byteB1.position(byteB1.position() + 1); - } - - if (!filled.get(33)) { - byteB2.position(byteB2.position() + 1); - } - - if (!filled.get(34)) { - byteB3.position(byteB3.position() + 1); - } - - if (!filled.get(35)) { - byteDelta0.position(byteDelta0.position() + 1); - } - - if (!filled.get(36)) { - byteDelta1.position(byteDelta1.position() + 1); - } - - if (!filled.get(37)) { - byteDelta2.position(byteDelta2.position() + 1); - } - - if (!filled.get(38)) { - byteDelta3.position(byteDelta3.position() + 1); - } - - if (!filled.get(39)) { - byteH0.position(byteH0.position() + 1); - } - - if (!filled.get(40)) { - byteH1.position(byteH1.position() + 1); - } - - if (!filled.get(41)) { - byteH2.position(byteH2.position() + 1); - } - - if (!filled.get(42)) { - byteQ0.position(byteQ0.position() + 1); - } - - if (!filled.get(43)) { - byteQ1.position(byteQ1.position() + 1); - } - - if (!filled.get(44)) { - byteQ2.position(byteQ2.position() + 1); - } - - if (!filled.get(45)) { - byteQ3.position(byteQ3.position() + 1); - } - - if (!filled.get(46)) { - byteR0.position(byteR0.position() + 1); - } - - if (!filled.get(47)) { - byteR1.position(byteR1.position() + 1); - } - - if (!filled.get(48)) { - byteR2.position(byteR2.position() + 1); - } - - if (!filled.get(49)) { - byteR3.position(byteR3.position() + 1); - } - - if (!filled.get(50)) { - cmp1.position(cmp1.position() + 1); - } - - if (!filled.get(51)) { - cmp2.position(cmp2.position() + 1); - } - - if (!filled.get(52)) { - ct.position(ct.position() + 32); - } - - if (!filled.get(53)) { - decOutput.position(decOutput.position() + 1); - } - - if (!filled.get(54)) { - decSigned.position(decSigned.position() + 1); - } - - if (!filled.get(55)) { - inst.position(inst.position() + 32); - } - - if (!filled.get(56)) { - msb1.position(msb1.position() + 1); - } - - if (!filled.get(57)) { - msb2.position(msb2.position() + 1); - } - - if (!filled.get(58)) { - oli.position(oli.position() + 1); - } - - if (!filled.get(59)) { - resHi.position(resHi.position() + 32); - } - - if (!filled.get(60)) { - resLo.position(resLo.position() + 32); - } - - if (!filled.get(61)) { - stamp.position(stamp.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/ModexpData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/ModexpData.java deleted file mode 100644 index c3f346d19..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/ModexpData.java +++ /dev/null @@ -1,68 +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.modexpdata; - -import java.nio.MappedByteBuffer; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.container.stacked.set.StackedSet; -import net.consensys.linea.zktracer.module.Module; - -public class ModexpData implements Module { - private StackedSet state = new StackedSet<>(); - - @Override - public String moduleKey() { - return "MODEXP"; - } - - @Override - public void enterTransaction() { - this.state.enter(); - } - - @Override - public void popTransaction() { - this.state.pop(); - } - - @Override - public int lineCount() { - return this.state.lineCount(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - public int call(final ModexpDataOperation operation) { - this.state.add(operation); - - return operation.prevHubStamp(); - } - - @Override - public void commit(List buffers) { - Trace trace = new Trace(buffers); - int stamp = 0; - for (ModexpDataOperation o : this.state) { - stamp++; - o.trace(trace, stamp); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/ModexpDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/ModexpDataOperation.java deleted file mode 100644 index e1e3c5f38..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/ModexpDataOperation.java +++ /dev/null @@ -1,120 +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.modexpdata; - -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.bytesToUnsignedBytes; -import static net.consensys.linea.zktracer.types.Utils.leftPadTo; -import static net.consensys.linea.zktracer.types.Utils.rightPadTo; - -import java.math.BigInteger; - -import com.google.common.base.Preconditions; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.experimental.Accessors; -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) -@Accessors(fluent = true) -public class ModexpDataOperation extends ModuleOperation { - private static final int BEMR_LINE_COUNT = 32 * 4; - private static final int COMPONENT_SIZE = 512; - - private final int hubStamp; - @Getter private int prevHubStamp; - @EqualsAndHashCode.Include private final Bytes base; - @EqualsAndHashCode.Include private final Bytes exp; - @EqualsAndHashCode.Include private final Bytes mod; - private Bytes result; - - public ModexpDataOperation(int hubStamp, int prevHubStamp, Bytes base, Bytes exp, Bytes mod) { - this.hubStamp = hubStamp; - this.prevHubStamp = prevHubStamp; - this.base = base; - this.exp = exp; - this.mod = mod; - } - - @Override - protected int computeLineCount() { - return BEMR_LINE_COUNT; - } - - public void computeResult() { - final BigInteger baseBigInt = base.toUnsignedBigInteger(); - final BigInteger expBigInt = exp.toUnsignedBigInteger(); - final BigInteger modBigInt = mod.toUnsignedBigInteger(); - - result = bigIntegerToBytes(baseBigInt.modPow(expBigInt, modBigInt)); - } - - void trace(Trace trace, int stamp) { - computeResult(); - - final UnsignedByte stampBytes = UnsignedByte.of(stamp); - final Bytes currentHubStamp = Bytes.ofUnsignedInt(this.hubStamp + 1); - - final Bytes basePadded = leftPadTo(base, COMPONENT_SIZE); - final Bytes expPadded = leftPadTo(exp, COMPONENT_SIZE); - final Bytes modPadded = leftPadTo(mod, COMPONENT_SIZE); - final Bytes resultPadded = leftPadTo(result, COMPONENT_SIZE); - final Bytes bemrLimb = Bytes.concatenate(basePadded, expPadded, modPadded, resultPadded); - - BigInteger prevHubStampBigInt = BigInteger.valueOf(prevHubStamp); - BigInteger hubStampBigInt = currentHubStamp.toUnsignedBigInteger(); - BigInteger hubStampDiff = hubStampBigInt.subtract(prevHubStampBigInt).subtract(BigInteger.ONE); - - Preconditions.checkArgument( - hubStampDiff.compareTo(BigInteger.valueOf(256 ^ 6)) < 0, - "Hub stamp difference should never exceed 256 ^ 6"); - - UnsignedByte[] hubStampDiffBytes = - bytesToUnsignedBytes( - rightPadTo(leftPadTo(bigIntegerToBytes(hubStampDiff), 6), 128).toArray()); - - for (int bemrIndex = 1; bemrIndex <= 4; bemrIndex++) { - UnsignedByte phase = - UnsignedByte.of( - switch (bemrIndex) { - case 1 -> Trace.PHASE_BASE; - case 2 -> Trace.PHASE_EXPONENT; - case 3 -> Trace.PHASE_MODULUS; - case 4 -> Trace.PHASE_RESULT; - default -> throw new IllegalStateException("Unexpected value: " + bemrIndex); - }); - - for (int index = 0; index < 32; index++) { - int counter = 32 * (bemrIndex - 1) + index; - - trace - .ct(UnsignedByte.of(counter)) - .bemr(UnsignedByte.of(bemrIndex)) - .phase(phase) - .bytes(hubStampDiffBytes[counter]) - .limb(bemrLimb.slice(16 * counter, 16)) - .index(UnsignedByte.of(index)) - .resultDataContext(currentHubStamp) - .stamp(stampBytes) - .validateRow(); - } - } - - prevHubStamp = currentHubStamp.toInt(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/Trace.java deleted file mode 100644 index dc45be797..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/modexpdata/Trace.java +++ /dev/null @@ -1,268 +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.modexpdata; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - static final int PHASE_BASE = 1; - static final int PHASE_EXPONENT = 2; - static final int PHASE_MODULUS = 3; - static final int PHASE_RESULT = 4; - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer bemr; - private final MappedByteBuffer bytes; - private final MappedByteBuffer ct; - private final MappedByteBuffer index; - private final MappedByteBuffer limb; - private final MappedByteBuffer phase; - private final MappedByteBuffer resultDataContext; - private final MappedByteBuffer stamp; - - static List headers(int length) { - return List.of( - new ColumnHeader("modexpdata.BEMR", 1, length), - new ColumnHeader("modexpdata.BYTES", 1, length), - new ColumnHeader("modexpdata.CT", 1, length), - new ColumnHeader("modexpdata.INDEX", 1, length), - new ColumnHeader("modexpdata.LIMB", 2, length), - new ColumnHeader("modexpdata.PHASE", 1, length), - new ColumnHeader("modexpdata.RESULT_DATA_CONTEXT", 4, length), - new ColumnHeader("modexpdata.STAMP", 1, length)); - } - - public Trace(List buffers) { - this.bemr = buffers.get(0); - this.bytes = buffers.get(1); - this.ct = buffers.get(2); - this.index = buffers.get(3); - this.limb = buffers.get(4); - this.phase = buffers.get(5); - this.resultDataContext = buffers.get(6); - this.stamp = buffers.get(7); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace bemr(final UnsignedByte b) { - if (filled.get(0)) { - throw new IllegalStateException("modexpdata.BEMR already set"); - } else { - filled.set(0); - } - - bemr.put(b.toByte()); - - return this; - } - - public Trace bytes(final UnsignedByte b) { - if (filled.get(1)) { - throw new IllegalStateException("modexpdata.BYTES already set"); - } else { - filled.set(1); - } - - bytes.put(b.toByte()); - - return this; - } - - public Trace ct(final UnsignedByte b) { - if (filled.get(2)) { - throw new IllegalStateException("modexpdata.CT already set"); - } else { - filled.set(2); - } - - ct.put(b.toByte()); - - return this; - } - - public Trace index(final UnsignedByte b) { - if (filled.get(3)) { - throw new IllegalStateException("modexpdata.INDEX already set"); - } else { - filled.set(3); - } - - index.put(b.toByte()); - - return this; - } - - public Trace limb(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("modexpdata.LIMB already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - limb.put((byte) 0); - } - limb.put(b.toArrayUnsafe()); - - return this; - } - - public Trace phase(final UnsignedByte b) { - if (filled.get(5)) { - throw new IllegalStateException("modexpdata.PHASE already set"); - } else { - filled.set(5); - } - - phase.put(b.toByte()); - - return this; - } - - public Trace resultDataContext(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("modexpdata.RESULT_DATA_CONTEXT already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resultDataContext.put((byte) 0); - } - resultDataContext.put(b.toArrayUnsafe()); - - return this; - } - - public Trace stamp(final UnsignedByte b) { - if (filled.get(7)) { - throw new IllegalStateException("modexpdata.STAMP already set"); - } else { - filled.set(7); - } - - stamp.put(b.toByte()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("modexpdata.BEMR has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("modexpdata.BYTES has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("modexpdata.CT has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("modexpdata.INDEX has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("modexpdata.LIMB has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("modexpdata.PHASE has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("modexpdata.RESULT_DATA_CONTEXT has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("modexpdata.STAMP has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - bemr.position(bemr.position() + 1); - } - - if (!filled.get(1)) { - bytes.position(bytes.position() + 1); - } - - if (!filled.get(2)) { - ct.position(ct.position() + 1); - } - - if (!filled.get(3)) { - index.position(index.position() + 1); - } - - if (!filled.get(4)) { - limb.position(limb.position() + 2); - } - - if (!filled.get(5)) { - phase.position(phase.position() + 1); - } - - if (!filled.get(6)) { - resultDataContext.position(resultDataContext.position() + 4); - } - - if (!filled.get(7)) { - stamp.position(stamp.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} 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 deleted file mode 100644 index 1efcb203c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Mul.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.mul; - -import java.nio.MappedByteBuffer; -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.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.datatypes.Transaction; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.worldstate.WorldView; - -@RequiredArgsConstructor -public class Mul implements Module { - private final Hub hub; - /** A set of the operations to trace */ - private final StackedSet operations = new StackedSet<>(); - - @Override - public String moduleKey() { - return "MUL"; - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = this.hub.opCode(); - final Bytes32 arg1 = Bytes32.leftPad(frame.getStackItem(0)); - final Bytes32 arg2 = Bytes32.leftPad(frame.getStackItem(1)); - - operations.add(new MulOperation(opCode, arg1, arg2)); - } - - @Override - public void enterTransaction() { - this.operations.enter(); - } - - @Override - 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(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - int stamp = 0; - for (var op : this.operations) { - stamp++; - op.trace(trace, stamp); - } - (new MulOperation(OpCode.EXP, Bytes32.ZERO, Bytes32.ZERO)).trace(trace, stamp + 1); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/MulOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/MulOperation.java deleted file mode 100644 index 735a79a47..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/MulOperation.java +++ /dev/null @@ -1,503 +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.mul; - -import static net.consensys.linea.zktracer.module.Util.boolToByte; -import static net.consensys.linea.zktracer.module.Util.byteBits; -import static net.consensys.linea.zktracer.module.Util.getBit; -import static net.consensys.linea.zktracer.module.Util.getOverflow; - -import java.lang.reflect.Array; -import java.math.BigInteger; -import java.util.Arrays; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import net.consensys.linea.zktracer.bytestheta.BaseBytes; -import net.consensys.linea.zktracer.bytestheta.BaseTheta; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.Bytes16; -import net.consensys.linea.zktracer.types.Conversions; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; - -@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) -public class MulOperation extends ModuleOperation { - private static final int MMEDIUM = 8; - - @EqualsAndHashCode.Include @Getter private final OpCode opCode; - @EqualsAndHashCode.Include @Getter private final Bytes32 arg1; - @EqualsAndHashCode.Include @Getter private final Bytes32 arg2; - - @Getter private final Bytes16 arg1Hi; - @Getter private final Bytes16 arg1Lo; - @Getter private final Bytes16 arg2Hi; - @Getter private final Bytes16 arg2Lo; - - @Getter private final boolean tinyBase; - @Getter private final boolean tinyExponent; - - UInt256 resAcc = - UInt256.ZERO; // accumulator which converges in a series of "square and multiply"'s - UInt256 expAcc = - UInt256.ZERO; // accumulator for doubles and adds of the exponent, resets at some point - - final BaseTheta aBytes; - final BaseTheta bBytes; - BaseTheta cBytes = BaseTheta.fromBytes32(Bytes32.ZERO); - BaseTheta hBytes = BaseTheta.fromBytes32(Bytes32.ZERO); - boolean squareAndMultiply = false; - int index; - Boolean[] bits = new Boolean[8]; - String exponentBits = "0"; - - BaseBytes res; - - public MulOperation(OpCode opCode, Bytes32 arg1, Bytes32 arg2) { - this.opCode = opCode; - this.arg1 = arg1; - this.arg2 = arg2; - this.aBytes = BaseTheta.fromBytes32(arg1); - this.bBytes = BaseTheta.fromBytes32(arg2); - - arg1Hi = Bytes16.wrap(arg1.slice(0, 16)); - arg1Lo = Bytes16.wrap(arg1.slice(16)); - arg2Hi = Bytes16.wrap(arg2.slice(0, 16)); - arg2Lo = Bytes16.wrap(arg2.slice(16)); - - this.res = getRes(opCode, arg1, arg2); - - final BigInteger arg1BigInt = UInt256.fromBytes(arg1).toUnsignedBigInteger(); - final BigInteger arg2BigInt = UInt256.fromBytes(arg2).toUnsignedBigInteger(); - - this.tinyBase = isTiny(arg1BigInt); - this.tinyExponent = isTiny(arg2BigInt); - - // initialize bits - Arrays.fill(bits, false); - - final Regime regime = getRegime(); - switch (regime) { - case TRIVIAL_MUL -> {} - case NON_TRIVIAL_MUL -> cBytes = BaseTheta.fromBytes32(res.getBytes32()); - case EXPONENT_ZERO_RESULT -> setArraysForZeroResultCase(); - case EXPONENT_NON_ZERO_RESULT -> { - this.exponentBits = new BigInteger(1, arg2.toArray()).toString(2); - squareAndMultiply = false; - } - case IOTA -> throw new RuntimeException("alu/mul regime was never set"); - default -> throw new IllegalStateException("[MUL module] Unexpected regime value: " + regime); - } - } - - public MulOperation clone() { - return new MulOperation(this.opCode, this.arg1, this.arg2); - } - - private static BaseBytes getRes(OpCode opCode, Bytes32 arg1, Bytes32 arg2) { - return switch (opCode) { - case MUL -> BaseBytes.fromBytes32(UInt256.fromBytes(arg1).multiply(UInt256.fromBytes(arg2))); - case EXP -> BaseBytes.fromBytes32(UInt256.fromBytes(arg1).pow(UInt256.fromBytes(arg2))); - default -> throw new IllegalStateException("[MUL module] Unexpected opcode: " + opCode); - }; - } - - private void setArraysForZeroResultCase() { - int nu = twoAdicity(arg1); - - if (nu >= 128) { - return; - } - - Bytes ones = Bytes.repeat((byte) 1, 8); - Bytes bytes; - - if (128 > nu && nu >= 64) { - bytes = aBytes.get(1); - } else { - for (int i = 0; i < 8; i++) { - cBytes.setChunk(0, ones); - } - bytes = aBytes.get(0); - } - - int nuQuo = (nu / 8) % 8; - int nuRem = nu % 8; - byte pivotByte = bytes.get(7 - nuQuo); - - for (int i = 0; i < 8; i++) { - cBytes.set(1, i, pivotByte); - cBytes.set(2, i, boolToByte(i > 7 - nuRem)); - cBytes.set(3, i, boolToByte(i > 7 - nuQuo)); - hBytes.set(2, i, callFunc(i, 7 - nuRem)); - hBytes.set(3, i, callFunc(i, 7 - nuQuo)); - } - - bits = byteBits(UnsignedByte.of(pivotByte)); - - int lowerBoundOnTwoAdicity = 8 * (int) (hBytes.get(3, 7)) + (int) (hBytes.get(2, 7)); - - if (nu >= 64) { - lowerBoundOnTwoAdicity += 64; - } - - // our lower bound should coincide with the 2-adicity - if (lowerBoundOnTwoAdicity != nu) { - String s = - String.format( - "2-adicity nu = %d != %d = lower bound on 2-adicity", nu, lowerBoundOnTwoAdicity); - throw new RuntimeException(s); - } - if (lowerBoundOnTwoAdicity == 0) { - throw new RuntimeException("lower bound on 2 adicity == 0 in the zero result case"); - } - - final UInt256 twoFiftySix = UInt256.valueOf(256); - if (arg2.compareTo(twoFiftySix) >= 0) { - // arg2 = exponent >= 256 - hBytes.set(1, 6, (byte) ((lowerBoundOnTwoAdicity - 1) / 256)); - hBytes.set(1, 7, (byte) ((lowerBoundOnTwoAdicity - 1) % 256)); - } else { - // exponent < 256 - int exponent = arg2.toUnsignedBigInteger().intValue(); - int target = exponent * lowerBoundOnTwoAdicity - 256; - - if (target < 0) { - throw new RuntimeException("lower bound on 2-adicity is wrong"); - } - - if (target > 255 * (8 * 7 + 7 + 64)) { - throw new RuntimeException("something went awfully wrong ..."); - } - - final BaseTheta thing = BaseTheta.fromBytes32(UInt256.valueOf(target)); - hBytes.setChunk(1, thing.get(0)); - } - } - - public static byte callFunc(final int x, final int k) { - if (x < k) { - return 0; - } - - return (byte) (x - k); - } - - public boolean isExponentBitSet() { - return exponentBits.charAt(index) == '1'; - } - - public boolean isExponentInSource() { - return this.index + 128 >= exponentBits.length(); - } - - public static int twoAdicity(final Bytes32 x) { - if (x.isZero()) { - // panic("twoAdicity was called on zero") - return 256; - } - - String baseStringBase2 = Conversions.reallyToSignedBigInteger(x).toString(2); - - for (int i = 0; i < baseStringBase2.length(); i++) { - int j = baseStringBase2.length() - i - 1; - char zeroAscii = '0'; - if (baseStringBase2.charAt(j) != zeroAscii) { - return i; - } - } - - return 0; - } - - public boolean isOneLineInstruction() { - return tinyBase || tinyExponent; - } - - Regime getRegime() { - if (isOneLineInstruction()) { - return Regime.TRIVIAL_MUL; - } - - if (OpCode.MUL.equals(opCode)) { - return Regime.NON_TRIVIAL_MUL; - } - - if (OpCode.EXP.equals(opCode)) { - if (res.isZero()) { - return Regime.EXPONENT_ZERO_RESULT; - } else { - return Regime.EXPONENT_NON_ZERO_RESULT; - } - } - - return Regime.IOTA; - } - - public static boolean isTiny(BigInteger arg) { - return arg.compareTo(BigInteger.valueOf(1)) <= 0; - } - - public boolean carryOn() { - // first round is special - if (index == 0 && !squareAndMultiply) { - squareAndMultiply = true; - resAcc = UInt256.valueOf(1); - cBytes = BaseTheta.fromBytes32(arg1); - - return true; - } - - if (squareAndMultiply == isExponentBitSet()) { - hiToLoExponentBitAccumulatorReset(); - index++; - squareAndMultiply = false; - return index != exponentBits.length(); - } else { - squareAndMultiply = true; - } - - return true; - } - - public int getBitNum() { - return bitNum(index, exponentBits.length()); - } - - private int bitNum(int i, int length) { - if (length <= 128) { - return i; - } else { - if (i + 128 < length) { - return i; - } else { - return i + 128 - length; - } - } - } - - public void update() { - final BigInteger arg1BigInt = UInt256.fromBytes(arg1).toUnsignedBigInteger(); - if (!squareAndMultiply) { - // squaring - setHsAndBits(resAcc, resAcc); - expAcc = expAcc.add(expAcc); - resAcc = resAcc.multiply(resAcc); - } else { - // multiplying by base - setHsAndBits(UInt256.valueOf(arg1BigInt), resAcc); - expAcc = expAcc.add(UInt256.ONE); - resAcc = UInt256.valueOf(arg1BigInt).multiply(resAcc); - } - cBytes = BaseTheta.fromBytes32(resAcc); - } - - public void setHsAndBits(UInt256 a, UInt256 b) { - setHsAndBitsFromBaseThetas(BaseTheta.fromBytes32(a), BaseTheta.fromBytes32(b)); - } - - @SuppressWarnings("checkstyle:VariableDeclarationUsageDistance") - public void setHsAndBitsFromBaseThetas(BaseTheta aBaseTheta, BaseTheta bBaseTheta) { - UInt256[] aBaseThetaInts = (UInt256[]) Array.newInstance(UInt256.class, 4); - UInt256[] bBaseThetaInts = (UInt256[]) Array.newInstance(UInt256.class, 4); - - for (int i = 0; i < 4; i++) { - aBaseThetaInts[i] = UInt256.fromBytes(aBaseTheta.get(i)); - bBaseThetaInts[i] = UInt256.fromBytes(bBaseTheta.get(i)); - } - - UInt256 prod = aBaseThetaInts[1].multiply(bBaseThetaInts[0]); - UInt256 sum = prod; // sum := a1 * b0 - prod = aBaseThetaInts[0].multiply(bBaseThetaInts[1]); - sum = sum.add(prod); // sum += a0 * b1 - - BaseTheta sumBaseTheta = BaseTheta.fromBytes32(sum); - hBytes.setChunk(0, sumBaseTheta.get(0)); - hBytes.setChunk(1, sumBaseTheta.get(1)); - - long alpha = getOverflow(sum, 1, "alpha OOB"); - - sum = aBaseThetaInts[3].multiply(bBaseThetaInts[0]); // sum := a3 * b0 - prod = aBaseThetaInts[2].multiply(bBaseThetaInts[1]); - sum = sum.add(prod); // sum += a2 * b1 - prod = aBaseThetaInts[1].multiply(bBaseThetaInts[2]); - sum = sum.add(prod); // sum += a1 * b2 - prod = aBaseThetaInts[0].multiply(bBaseThetaInts[3]); - sum = sum.add(prod); // sum += a0 * b3 - - sumBaseTheta = BaseTheta.fromBytes32(sum); - hBytes.setChunk(2, sumBaseTheta.get(0)); - hBytes.setChunk(3, sumBaseTheta.get(1)); - - long beta = getOverflow(sum, 3, "beta OOB"); - prod = aBaseThetaInts[0].multiply(bBaseThetaInts[0]); - sum = prod; // sum := a0 * b0 - - prod = UInt256.fromBytes(hBytes.get(0)).shiftLeft(64); - sum = sum.add(prod); // sum += (h0 << 64) - - long eta = getOverflow(sum, 1, "eta OOB"); - - sum = UInt256.valueOf(eta); // sum := eta - sum = sum.add(UInt256.fromBytes(hBytes.get(1))); // sum += h1 - prod = UInt256.valueOf(alpha).shiftLeft(64); - sum = sum.add(prod); // sum += (alpha << 64) - prod = aBaseThetaInts[2].multiply(bBaseThetaInts[0]); - sum = sum.add(prod); // sum += a2 * b0 - prod = aBaseThetaInts[1].multiply(bBaseThetaInts[1]); - sum = sum.add(prod); // sum += a1 * b1 - prod = aBaseThetaInts[0].multiply(bBaseThetaInts[2]); - sum = sum.add(prod); // sum += a0 * b2 - sum = sum.add(UInt256.fromBytes(hBytes.get(2)).shiftLeft(64)); // sum += (h2 << 64) - - long mu = getOverflow(sum, 3, "mu OOB"); - - bits[0] = false; - bits[1] = false; - bits[2] = getBit(alpha, 0); - bits[3] = getBit(beta, 0); - bits[4] = getBit(beta, 1); - bits[5] = getBit(eta, 0); - bits[6] = getBit(mu, 0); - bits[7] = getBit(mu, 1); - } - - // hiToLoExponentBitAccumulatorReset resets the exponent bit accumulator - // under the following conditions: - // - we are dealing with the high part of the exponent bits, i.e. md.exponentBit() = 0 - // - SQUARE_AND_MULTIPLY == EXPONENT_BIT - // - the exponent bit accumulator coincides with the high part of the exponent - private void hiToLoExponentBitAccumulatorReset() { - if (!isExponentInSource()) { - if (squareAndMultiply == isExponentBitSet()) { // note: when called this is already assumed - Bytes32 arg2Copy = arg2.copy(); - if (arg2Copy.shiftRight(128).equals(expAcc)) { - expAcc = UInt256.MIN_VALUE; - } - } - } - } - - public int maxCt() { - return isOneLineInstruction() ? 1 : MMEDIUM; - } - - void trace(Trace trace, int stamp) { - switch (this.getRegime()) { - case EXPONENT_ZERO_RESULT -> this.traceSubOp(trace, stamp); - - case EXPONENT_NON_ZERO_RESULT -> { - while (this.carryOn()) { - this.update(); - this.traceSubOp(trace, stamp); - } - } - - case TRIVIAL_MUL, NON_TRIVIAL_MUL -> { - this.setHsAndBits(UInt256.fromBytes(this.getArg1()), UInt256.fromBytes(this.getArg2())); - this.traceSubOp(trace, stamp); - } - - default -> throw new RuntimeException("regime not supported"); - } - } - - private void traceSubOp(Trace trace, int stamp) { - for (int i = 0; i < this.maxCt(); i++) { - trace - .mulStamp(Bytes.ofUnsignedLong(stamp)) - .counter(Bytes.of(i)) - .oli(this.isOneLineInstruction()) - .tinyBase(this.isTinyBase()) - .tinyExponent(this.isTinyExponent()) - .resultVanishes(this.res.isZero()) - .instruction(Bytes.of(this.getOpCode().byteValue())) - .arg1Hi(this.getArg1Hi()) - .arg1Lo(this.getArg1Lo()) - .arg2Hi(this.getArg2Hi()) - .arg2Lo(this.getArg2Lo()) - .resHi(this.res.getHigh()) - .resLo(this.res.getLow()) - .bits(this.bits[i]) - .byteA3(UnsignedByte.of(this.aBytes.get(3, i))) - .byteA2(UnsignedByte.of(this.aBytes.get(2, i))) - .byteA1(UnsignedByte.of(this.aBytes.get(1, i))) - .byteA0(UnsignedByte.of(this.aBytes.get(0, i))) - .accA3(this.aBytes.getRange(3, 0, i + 1)) - .accA2(this.aBytes.getRange(2, 0, i + 1)) - .accA1(this.aBytes.getRange(1, 0, i + 1)) - .accA0(this.aBytes.getRange(0, 0, i + 1)) - .byteB3(UnsignedByte.of(this.bBytes.get(3, i))) - .byteB2(UnsignedByte.of(this.bBytes.get(2, i))) - .byteB1(UnsignedByte.of(this.bBytes.get(1, i))) - .byteB0(UnsignedByte.of(this.bBytes.get(0, i))) - .accB3(this.bBytes.getRange(3, 0, i + 1)) - .accB2(this.bBytes.getRange(2, 0, i + 1)) - .accB1(this.bBytes.getRange(1, 0, i + 1)) - .accB0(this.bBytes.getRange(0, 0, i + 1)) - .byteC3(UnsignedByte.of(this.cBytes.get(3, i))) - .byteC2(UnsignedByte.of(this.cBytes.get(2, i))) - .byteC1(UnsignedByte.of(this.cBytes.get(1, i))) - .byteC0(UnsignedByte.of(this.cBytes.get(0, i))) - .accC3(this.cBytes.getRange(3, 0, i + 1)) - .accC2(this.cBytes.getRange(2, 0, i + 1)) - .accC1(this.cBytes.getRange(1, 0, i + 1)) - .accC0(this.cBytes.getRange(0, 0, i + 1)) - .byteH3(UnsignedByte.of(this.hBytes.get(3, i))) - .byteH2(UnsignedByte.of(this.hBytes.get(2, i))) - .byteH1(UnsignedByte.of(this.hBytes.get(1, i))) - .byteH0(UnsignedByte.of(this.hBytes.get(0, i))) - .accH3(this.hBytes.getRange(3, 0, i + 1)) - .accH2(this.hBytes.getRange(2, 0, i + 1)) - .accH1(this.hBytes.getRange(1, 0, i + 1)) - .accH0(this.hBytes.getRange(0, 0, i + 1)) - .exponentBit(this.isExponentBitSet()) - .exponentBitAccumulator(this.expAcc) - .exponentBitSource(this.isExponentInSource()) - .squareAndMultiply(this.squareAndMultiply) - .bitNum(Bytes.ofUnsignedShort(this.getBitNum())) - .validateRow(); - } - } - - @Override - protected int computeLineCount() { - final MulOperation op = this.clone(); - - return switch (this.getRegime()) { - case EXPONENT_ZERO_RESULT -> op.maxCt(); - - case EXPONENT_NON_ZERO_RESULT -> { - int r = 0; - while (op.carryOn()) { - op.update(); - r += op.maxCt(); - } - yield r; - } - - case TRIVIAL_MUL, NON_TRIVIAL_MUL -> { - op.setHsAndBits(UInt256.fromBytes(op.getArg1()), UInt256.fromBytes(op.getArg2())); - yield op.maxCt(); - } - - default -> throw new RuntimeException("regime not supported"); - }; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Regime.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Regime.java deleted file mode 100644 index 08a890f09..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Regime.java +++ /dev/null @@ -1,24 +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.mul; - -enum Regime { - IOTA, - TRIVIAL_MUL, - NON_TRIVIAL_MUL, - EXPONENT_ZERO_RESULT, - EXPONENT_NON_ZERO_RESULT -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Trace.java deleted file mode 100644 index 6ced31f0c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Trace.java +++ /dev/null @@ -1,1353 +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.mul; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer accA0; - private final MappedByteBuffer accA1; - private final MappedByteBuffer accA2; - private final MappedByteBuffer accA3; - private final MappedByteBuffer accB0; - private final MappedByteBuffer accB1; - private final MappedByteBuffer accB2; - private final MappedByteBuffer accB3; - private final MappedByteBuffer accC0; - private final MappedByteBuffer accC1; - private final MappedByteBuffer accC2; - private final MappedByteBuffer accC3; - private final MappedByteBuffer accH0; - private final MappedByteBuffer accH1; - private final MappedByteBuffer accH2; - private final MappedByteBuffer accH3; - private final MappedByteBuffer arg1Hi; - private final MappedByteBuffer arg1Lo; - private final MappedByteBuffer arg2Hi; - private final MappedByteBuffer arg2Lo; - private final MappedByteBuffer bitNum; - private final MappedByteBuffer bits; - private final MappedByteBuffer byteA0; - private final MappedByteBuffer byteA1; - private final MappedByteBuffer byteA2; - private final MappedByteBuffer byteA3; - private final MappedByteBuffer byteB0; - private final MappedByteBuffer byteB1; - private final MappedByteBuffer byteB2; - private final MappedByteBuffer byteB3; - private final MappedByteBuffer byteC0; - private final MappedByteBuffer byteC1; - private final MappedByteBuffer byteC2; - private final MappedByteBuffer byteC3; - private final MappedByteBuffer byteH0; - private final MappedByteBuffer byteH1; - private final MappedByteBuffer byteH2; - private final MappedByteBuffer byteH3; - private final MappedByteBuffer counter; - private final MappedByteBuffer exponentBit; - private final MappedByteBuffer exponentBitAccumulator; - private final MappedByteBuffer exponentBitSource; - private final MappedByteBuffer instruction; - private final MappedByteBuffer mulStamp; - private final MappedByteBuffer oli; - private final MappedByteBuffer resHi; - private final MappedByteBuffer resLo; - private final MappedByteBuffer resultVanishes; - private final MappedByteBuffer squareAndMultiply; - private final MappedByteBuffer tinyBase; - private final MappedByteBuffer tinyExponent; - - static List headers(int length) { - return List.of( - new ColumnHeader("mul.ACC_A_0", 32, length), - new ColumnHeader("mul.ACC_A_1", 32, length), - new ColumnHeader("mul.ACC_A_2", 32, length), - new ColumnHeader("mul.ACC_A_3", 32, length), - new ColumnHeader("mul.ACC_B_0", 32, length), - new ColumnHeader("mul.ACC_B_1", 32, length), - new ColumnHeader("mul.ACC_B_2", 32, length), - new ColumnHeader("mul.ACC_B_3", 32, length), - new ColumnHeader("mul.ACC_C_0", 32, length), - new ColumnHeader("mul.ACC_C_1", 32, length), - new ColumnHeader("mul.ACC_C_2", 32, length), - new ColumnHeader("mul.ACC_C_3", 32, length), - new ColumnHeader("mul.ACC_H_0", 32, length), - new ColumnHeader("mul.ACC_H_1", 32, length), - new ColumnHeader("mul.ACC_H_2", 32, length), - new ColumnHeader("mul.ACC_H_3", 32, length), - new ColumnHeader("mul.ARG_1_HI", 32, length), - new ColumnHeader("mul.ARG_1_LO", 32, length), - new ColumnHeader("mul.ARG_2_HI", 32, length), - new ColumnHeader("mul.ARG_2_LO", 32, length), - new ColumnHeader("mul.BIT_NUM", 32, length), - new ColumnHeader("mul.BITS", 1, length), - new ColumnHeader("mul.BYTE_A_0", 1, length), - new ColumnHeader("mul.BYTE_A_1", 1, length), - new ColumnHeader("mul.BYTE_A_2", 1, length), - new ColumnHeader("mul.BYTE_A_3", 1, length), - new ColumnHeader("mul.BYTE_B_0", 1, length), - new ColumnHeader("mul.BYTE_B_1", 1, length), - new ColumnHeader("mul.BYTE_B_2", 1, length), - new ColumnHeader("mul.BYTE_B_3", 1, length), - new ColumnHeader("mul.BYTE_C_0", 1, length), - new ColumnHeader("mul.BYTE_C_1", 1, length), - new ColumnHeader("mul.BYTE_C_2", 1, length), - new ColumnHeader("mul.BYTE_C_3", 1, length), - new ColumnHeader("mul.BYTE_H_0", 1, length), - new ColumnHeader("mul.BYTE_H_1", 1, length), - new ColumnHeader("mul.BYTE_H_2", 1, length), - new ColumnHeader("mul.BYTE_H_3", 1, length), - new ColumnHeader("mul.COUNTER", 32, length), - new ColumnHeader("mul.EXPONENT_BIT", 1, length), - new ColumnHeader("mul.EXPONENT_BIT_ACCUMULATOR", 32, length), - new ColumnHeader("mul.EXPONENT_BIT_SOURCE", 1, length), - new ColumnHeader("mul.INSTRUCTION", 32, length), - new ColumnHeader("mul.MUL_STAMP", 32, length), - new ColumnHeader("mul.OLI", 1, length), - new ColumnHeader("mul.RES_HI", 32, length), - new ColumnHeader("mul.RES_LO", 32, length), - new ColumnHeader("mul.RESULT_VANISHES", 1, length), - new ColumnHeader("mul.SQUARE_AND_MULTIPLY", 1, length), - new ColumnHeader("mul.TINY_BASE", 1, length), - new ColumnHeader("mul.TINY_EXPONENT", 1, length)); - } - - public Trace(List buffers) { - this.accA0 = buffers.get(0); - this.accA1 = buffers.get(1); - this.accA2 = buffers.get(2); - this.accA3 = buffers.get(3); - this.accB0 = buffers.get(4); - this.accB1 = buffers.get(5); - this.accB2 = buffers.get(6); - this.accB3 = buffers.get(7); - this.accC0 = buffers.get(8); - this.accC1 = buffers.get(9); - this.accC2 = buffers.get(10); - this.accC3 = buffers.get(11); - this.accH0 = buffers.get(12); - this.accH1 = buffers.get(13); - this.accH2 = buffers.get(14); - this.accH3 = buffers.get(15); - this.arg1Hi = buffers.get(16); - this.arg1Lo = buffers.get(17); - this.arg2Hi = buffers.get(18); - this.arg2Lo = buffers.get(19); - this.bitNum = buffers.get(20); - this.bits = buffers.get(21); - this.byteA0 = buffers.get(22); - this.byteA1 = buffers.get(23); - this.byteA2 = buffers.get(24); - this.byteA3 = buffers.get(25); - this.byteB0 = buffers.get(26); - this.byteB1 = buffers.get(27); - this.byteB2 = buffers.get(28); - this.byteB3 = buffers.get(29); - this.byteC0 = buffers.get(30); - this.byteC1 = buffers.get(31); - this.byteC2 = buffers.get(32); - this.byteC3 = buffers.get(33); - this.byteH0 = buffers.get(34); - this.byteH1 = buffers.get(35); - this.byteH2 = buffers.get(36); - this.byteH3 = buffers.get(37); - this.counter = buffers.get(38); - this.exponentBit = buffers.get(39); - this.exponentBitAccumulator = buffers.get(40); - this.exponentBitSource = buffers.get(41); - this.instruction = buffers.get(42); - this.mulStamp = buffers.get(43); - this.oli = buffers.get(44); - this.resHi = buffers.get(45); - this.resLo = buffers.get(46); - this.resultVanishes = buffers.get(47); - this.squareAndMultiply = buffers.get(48); - this.tinyBase = buffers.get(49); - this.tinyExponent = buffers.get(50); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace accA0(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("mul.ACC_A_0 already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accA0.put((byte) 0); - } - accA0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accA1(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("mul.ACC_A_1 already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accA1.put((byte) 0); - } - accA1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accA2(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("mul.ACC_A_2 already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accA2.put((byte) 0); - } - accA2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accA3(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("mul.ACC_A_3 already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accA3.put((byte) 0); - } - accA3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB0(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("mul.ACC_B_0 already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB0.put((byte) 0); - } - accB0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB1(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("mul.ACC_B_1 already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB1.put((byte) 0); - } - accB1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB2(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("mul.ACC_B_2 already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB2.put((byte) 0); - } - accB2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accB3(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("mul.ACC_B_3 already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accB3.put((byte) 0); - } - accB3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accC0(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("mul.ACC_C_0 already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accC0.put((byte) 0); - } - accC0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accC1(final Bytes b) { - if (filled.get(9)) { - throw new IllegalStateException("mul.ACC_C_1 already set"); - } else { - filled.set(9); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accC1.put((byte) 0); - } - accC1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accC2(final Bytes b) { - if (filled.get(10)) { - throw new IllegalStateException("mul.ACC_C_2 already set"); - } else { - filled.set(10); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accC2.put((byte) 0); - } - accC2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accC3(final Bytes b) { - if (filled.get(11)) { - throw new IllegalStateException("mul.ACC_C_3 already set"); - } else { - filled.set(11); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accC3.put((byte) 0); - } - accC3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH0(final Bytes b) { - if (filled.get(12)) { - throw new IllegalStateException("mul.ACC_H_0 already set"); - } else { - filled.set(12); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH0.put((byte) 0); - } - accH0.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH1(final Bytes b) { - if (filled.get(13)) { - throw new IllegalStateException("mul.ACC_H_1 already set"); - } else { - filled.set(13); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH1.put((byte) 0); - } - accH1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH2(final Bytes b) { - if (filled.get(14)) { - throw new IllegalStateException("mul.ACC_H_2 already set"); - } else { - filled.set(14); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH2.put((byte) 0); - } - accH2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accH3(final Bytes b) { - if (filled.get(15)) { - throw new IllegalStateException("mul.ACC_H_3 already set"); - } else { - filled.set(15); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accH3.put((byte) 0); - } - accH3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg1Hi(final Bytes b) { - if (filled.get(16)) { - throw new IllegalStateException("mul.ARG_1_HI already set"); - } else { - filled.set(16); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Hi.put((byte) 0); - } - arg1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg1Lo(final Bytes b) { - if (filled.get(17)) { - throw new IllegalStateException("mul.ARG_1_LO already set"); - } else { - filled.set(17); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Lo.put((byte) 0); - } - arg1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg2Hi(final Bytes b) { - if (filled.get(18)) { - throw new IllegalStateException("mul.ARG_2_HI already set"); - } else { - filled.set(18); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg2Hi.put((byte) 0); - } - arg2Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg2Lo(final Bytes b) { - if (filled.get(19)) { - throw new IllegalStateException("mul.ARG_2_LO already set"); - } else { - filled.set(19); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg2Lo.put((byte) 0); - } - arg2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace bitNum(final Bytes b) { - if (filled.get(21)) { - throw new IllegalStateException("mul.BIT_NUM already set"); - } else { - filled.set(21); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - bitNum.put((byte) 0); - } - bitNum.put(b.toArrayUnsafe()); - - return this; - } - - public Trace bits(final Boolean b) { - if (filled.get(20)) { - throw new IllegalStateException("mul.BITS already set"); - } else { - filled.set(20); - } - - bits.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace byteA0(final UnsignedByte b) { - if (filled.get(22)) { - throw new IllegalStateException("mul.BYTE_A_0 already set"); - } else { - filled.set(22); - } - - byteA0.put(b.toByte()); - - return this; - } - - public Trace byteA1(final UnsignedByte b) { - if (filled.get(23)) { - throw new IllegalStateException("mul.BYTE_A_1 already set"); - } else { - filled.set(23); - } - - byteA1.put(b.toByte()); - - return this; - } - - public Trace byteA2(final UnsignedByte b) { - if (filled.get(24)) { - throw new IllegalStateException("mul.BYTE_A_2 already set"); - } else { - filled.set(24); - } - - byteA2.put(b.toByte()); - - return this; - } - - public Trace byteA3(final UnsignedByte b) { - if (filled.get(25)) { - throw new IllegalStateException("mul.BYTE_A_3 already set"); - } else { - filled.set(25); - } - - byteA3.put(b.toByte()); - - return this; - } - - public Trace byteB0(final UnsignedByte b) { - if (filled.get(26)) { - throw new IllegalStateException("mul.BYTE_B_0 already set"); - } else { - filled.set(26); - } - - byteB0.put(b.toByte()); - - return this; - } - - public Trace byteB1(final UnsignedByte b) { - if (filled.get(27)) { - throw new IllegalStateException("mul.BYTE_B_1 already set"); - } else { - filled.set(27); - } - - byteB1.put(b.toByte()); - - return this; - } - - public Trace byteB2(final UnsignedByte b) { - if (filled.get(28)) { - throw new IllegalStateException("mul.BYTE_B_2 already set"); - } else { - filled.set(28); - } - - byteB2.put(b.toByte()); - - return this; - } - - public Trace byteB3(final UnsignedByte b) { - if (filled.get(29)) { - throw new IllegalStateException("mul.BYTE_B_3 already set"); - } else { - filled.set(29); - } - - byteB3.put(b.toByte()); - - return this; - } - - public Trace byteC0(final UnsignedByte b) { - if (filled.get(30)) { - throw new IllegalStateException("mul.BYTE_C_0 already set"); - } else { - filled.set(30); - } - - byteC0.put(b.toByte()); - - return this; - } - - public Trace byteC1(final UnsignedByte b) { - if (filled.get(31)) { - throw new IllegalStateException("mul.BYTE_C_1 already set"); - } else { - filled.set(31); - } - - byteC1.put(b.toByte()); - - return this; - } - - public Trace byteC2(final UnsignedByte b) { - if (filled.get(32)) { - throw new IllegalStateException("mul.BYTE_C_2 already set"); - } else { - filled.set(32); - } - - byteC2.put(b.toByte()); - - return this; - } - - public Trace byteC3(final UnsignedByte b) { - if (filled.get(33)) { - throw new IllegalStateException("mul.BYTE_C_3 already set"); - } else { - filled.set(33); - } - - byteC3.put(b.toByte()); - - return this; - } - - public Trace byteH0(final UnsignedByte b) { - if (filled.get(34)) { - throw new IllegalStateException("mul.BYTE_H_0 already set"); - } else { - filled.set(34); - } - - byteH0.put(b.toByte()); - - return this; - } - - public Trace byteH1(final UnsignedByte b) { - if (filled.get(35)) { - throw new IllegalStateException("mul.BYTE_H_1 already set"); - } else { - filled.set(35); - } - - byteH1.put(b.toByte()); - - return this; - } - - public Trace byteH2(final UnsignedByte b) { - if (filled.get(36)) { - throw new IllegalStateException("mul.BYTE_H_2 already set"); - } else { - filled.set(36); - } - - byteH2.put(b.toByte()); - - return this; - } - - public Trace byteH3(final UnsignedByte b) { - if (filled.get(37)) { - throw new IllegalStateException("mul.BYTE_H_3 already set"); - } else { - filled.set(37); - } - - byteH3.put(b.toByte()); - - return this; - } - - public Trace counter(final Bytes b) { - if (filled.get(38)) { - throw new IllegalStateException("mul.COUNTER already set"); - } else { - filled.set(38); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - counter.put((byte) 0); - } - counter.put(b.toArrayUnsafe()); - - return this; - } - - public Trace exponentBit(final Boolean b) { - if (filled.get(39)) { - throw new IllegalStateException("mul.EXPONENT_BIT already set"); - } else { - filled.set(39); - } - - exponentBit.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace exponentBitAccumulator(final Bytes b) { - if (filled.get(40)) { - throw new IllegalStateException("mul.EXPONENT_BIT_ACCUMULATOR already set"); - } else { - filled.set(40); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - exponentBitAccumulator.put((byte) 0); - } - exponentBitAccumulator.put(b.toArrayUnsafe()); - - return this; - } - - public Trace exponentBitSource(final Boolean b) { - if (filled.get(41)) { - throw new IllegalStateException("mul.EXPONENT_BIT_SOURCE already set"); - } else { - filled.set(41); - } - - exponentBitSource.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace instruction(final Bytes b) { - if (filled.get(42)) { - throw new IllegalStateException("mul.INSTRUCTION already set"); - } else { - filled.set(42); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - instruction.put((byte) 0); - } - instruction.put(b.toArrayUnsafe()); - - return this; - } - - public Trace mulStamp(final Bytes b) { - if (filled.get(43)) { - throw new IllegalStateException("mul.MUL_STAMP already set"); - } else { - filled.set(43); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mulStamp.put((byte) 0); - } - mulStamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace oli(final Boolean b) { - if (filled.get(44)) { - throw new IllegalStateException("mul.OLI already set"); - } else { - filled.set(44); - } - - oli.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace resHi(final Bytes b) { - if (filled.get(46)) { - throw new IllegalStateException("mul.RES_HI already set"); - } else { - filled.set(46); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resHi.put((byte) 0); - } - resHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace resLo(final Bytes b) { - if (filled.get(47)) { - throw new IllegalStateException("mul.RES_LO already set"); - } else { - filled.set(47); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resLo.put((byte) 0); - } - resLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace resultVanishes(final Boolean b) { - if (filled.get(45)) { - throw new IllegalStateException("mul.RESULT_VANISHES already set"); - } else { - filled.set(45); - } - - resultVanishes.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace squareAndMultiply(final Boolean b) { - if (filled.get(48)) { - throw new IllegalStateException("mul.SQUARE_AND_MULTIPLY already set"); - } else { - filled.set(48); - } - - squareAndMultiply.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace tinyBase(final Boolean b) { - if (filled.get(49)) { - throw new IllegalStateException("mul.TINY_BASE already set"); - } else { - filled.set(49); - } - - tinyBase.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace tinyExponent(final Boolean b) { - if (filled.get(50)) { - throw new IllegalStateException("mul.TINY_EXPONENT already set"); - } else { - filled.set(50); - } - - tinyExponent.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("mul.ACC_A_0 has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("mul.ACC_A_1 has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("mul.ACC_A_2 has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("mul.ACC_A_3 has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("mul.ACC_B_0 has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("mul.ACC_B_1 has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("mul.ACC_B_2 has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("mul.ACC_B_3 has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("mul.ACC_C_0 has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("mul.ACC_C_1 has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("mul.ACC_C_2 has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("mul.ACC_C_3 has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("mul.ACC_H_0 has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("mul.ACC_H_1 has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("mul.ACC_H_2 has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("mul.ACC_H_3 has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("mul.ARG_1_HI has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("mul.ARG_1_LO has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("mul.ARG_2_HI has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("mul.ARG_2_LO has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("mul.BIT_NUM has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("mul.BITS has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("mul.BYTE_A_0 has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("mul.BYTE_A_1 has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("mul.BYTE_A_2 has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("mul.BYTE_A_3 has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("mul.BYTE_B_0 has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("mul.BYTE_B_1 has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("mul.BYTE_B_2 has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("mul.BYTE_B_3 has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("mul.BYTE_C_0 has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("mul.BYTE_C_1 has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("mul.BYTE_C_2 has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("mul.BYTE_C_3 has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("mul.BYTE_H_0 has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("mul.BYTE_H_1 has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("mul.BYTE_H_2 has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("mul.BYTE_H_3 has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("mul.COUNTER has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("mul.EXPONENT_BIT has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("mul.EXPONENT_BIT_ACCUMULATOR has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("mul.EXPONENT_BIT_SOURCE has not been filled"); - } - - if (!filled.get(42)) { - throw new IllegalStateException("mul.INSTRUCTION has not been filled"); - } - - if (!filled.get(43)) { - throw new IllegalStateException("mul.MUL_STAMP has not been filled"); - } - - if (!filled.get(44)) { - throw new IllegalStateException("mul.OLI has not been filled"); - } - - if (!filled.get(46)) { - throw new IllegalStateException("mul.RES_HI has not been filled"); - } - - if (!filled.get(47)) { - throw new IllegalStateException("mul.RES_LO has not been filled"); - } - - if (!filled.get(45)) { - throw new IllegalStateException("mul.RESULT_VANISHES has not been filled"); - } - - if (!filled.get(48)) { - throw new IllegalStateException("mul.SQUARE_AND_MULTIPLY has not been filled"); - } - - if (!filled.get(49)) { - throw new IllegalStateException("mul.TINY_BASE has not been filled"); - } - - if (!filled.get(50)) { - throw new IllegalStateException("mul.TINY_EXPONENT has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - accA0.position(accA0.position() + 32); - } - - if (!filled.get(1)) { - accA1.position(accA1.position() + 32); - } - - if (!filled.get(2)) { - accA2.position(accA2.position() + 32); - } - - if (!filled.get(3)) { - accA3.position(accA3.position() + 32); - } - - if (!filled.get(4)) { - accB0.position(accB0.position() + 32); - } - - if (!filled.get(5)) { - accB1.position(accB1.position() + 32); - } - - if (!filled.get(6)) { - accB2.position(accB2.position() + 32); - } - - if (!filled.get(7)) { - accB3.position(accB3.position() + 32); - } - - if (!filled.get(8)) { - accC0.position(accC0.position() + 32); - } - - if (!filled.get(9)) { - accC1.position(accC1.position() + 32); - } - - if (!filled.get(10)) { - accC2.position(accC2.position() + 32); - } - - if (!filled.get(11)) { - accC3.position(accC3.position() + 32); - } - - if (!filled.get(12)) { - accH0.position(accH0.position() + 32); - } - - if (!filled.get(13)) { - accH1.position(accH1.position() + 32); - } - - if (!filled.get(14)) { - accH2.position(accH2.position() + 32); - } - - if (!filled.get(15)) { - accH3.position(accH3.position() + 32); - } - - if (!filled.get(16)) { - arg1Hi.position(arg1Hi.position() + 32); - } - - if (!filled.get(17)) { - arg1Lo.position(arg1Lo.position() + 32); - } - - if (!filled.get(18)) { - arg2Hi.position(arg2Hi.position() + 32); - } - - if (!filled.get(19)) { - arg2Lo.position(arg2Lo.position() + 32); - } - - if (!filled.get(21)) { - bitNum.position(bitNum.position() + 32); - } - - if (!filled.get(20)) { - bits.position(bits.position() + 1); - } - - if (!filled.get(22)) { - byteA0.position(byteA0.position() + 1); - } - - if (!filled.get(23)) { - byteA1.position(byteA1.position() + 1); - } - - if (!filled.get(24)) { - byteA2.position(byteA2.position() + 1); - } - - if (!filled.get(25)) { - byteA3.position(byteA3.position() + 1); - } - - if (!filled.get(26)) { - byteB0.position(byteB0.position() + 1); - } - - if (!filled.get(27)) { - byteB1.position(byteB1.position() + 1); - } - - if (!filled.get(28)) { - byteB2.position(byteB2.position() + 1); - } - - if (!filled.get(29)) { - byteB3.position(byteB3.position() + 1); - } - - if (!filled.get(30)) { - byteC0.position(byteC0.position() + 1); - } - - if (!filled.get(31)) { - byteC1.position(byteC1.position() + 1); - } - - if (!filled.get(32)) { - byteC2.position(byteC2.position() + 1); - } - - if (!filled.get(33)) { - byteC3.position(byteC3.position() + 1); - } - - if (!filled.get(34)) { - byteH0.position(byteH0.position() + 1); - } - - if (!filled.get(35)) { - byteH1.position(byteH1.position() + 1); - } - - if (!filled.get(36)) { - byteH2.position(byteH2.position() + 1); - } - - if (!filled.get(37)) { - byteH3.position(byteH3.position() + 1); - } - - if (!filled.get(38)) { - counter.position(counter.position() + 32); - } - - if (!filled.get(39)) { - exponentBit.position(exponentBit.position() + 1); - } - - if (!filled.get(40)) { - exponentBitAccumulator.position(exponentBitAccumulator.position() + 32); - } - - if (!filled.get(41)) { - exponentBitSource.position(exponentBitSource.position() + 1); - } - - if (!filled.get(42)) { - instruction.position(instruction.position() + 32); - } - - if (!filled.get(43)) { - mulStamp.position(mulStamp.position() + 32); - } - - if (!filled.get(44)) { - oli.position(oli.position() + 1); - } - - if (!filled.get(46)) { - resHi.position(resHi.position() + 32); - } - - if (!filled.get(47)) { - resLo.position(resLo.position() + 32); - } - - if (!filled.get(45)) { - resultVanishes.position(resultVanishes.position() + 1); - } - - if (!filled.get(48)) { - squareAndMultiply.position(squareAndMultiply.position() + 1); - } - - if (!filled.get(49)) { - tinyBase.position(tinyBase.position() + 1); - } - - if (!filled.get(50)) { - tinyExponent.position(tinyExponent.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Chunk.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Chunk.java deleted file mode 100644 index 41ca7387f..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Chunk.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.mxp; - -public record Chunk() {} 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 deleted file mode 100644 index 85e20f061..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Mxp.java +++ /dev/null @@ -1,82 +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.mxp; - -import java.nio.MappedByteBuffer; -import java.util.List; - -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.Hub; -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 Hub hub; - - @Override - public String moduleKey() { - return "MXP"; - } - - public Mxp(Hub hub) { - this.hub = hub; - } - - // TODO: update tests and eliminate this constructor - public Mxp() {} - - @Override - public void tracePreOpcode(MessageFrame frame) { // This will be renamed to tracePreOp - this.chunks.add(new MxpData(frame, hub)); - } - - @Override - public void enterTransaction() { - this.chunks.enter(); - } - - @Override - public void popTransaction() { - this.chunks.pop(); - } - - @Override - public int lineCount() { - return this.chunks.lineCount(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @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); - } - } - - @Override - public void tracePostOp(MessageFrame frame) { // This is paired with tracePreOp - } -} 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 deleted file mode 100644 index 6674a0edb..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpData.java +++ /dev/null @@ -1,560 +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.mxp; - -import static net.consensys.linea.zktracer.module.Util.max; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static org.hyperledger.besu.evm.internal.Words.clampedAdd; -import static org.hyperledger.besu.evm.internal.Words.clampedMultiply; - -import java.math.BigInteger; -import java.util.Arrays; - -import com.google.common.base.Preconditions; -import lombok.Getter; -import net.consensys.linea.zktracer.container.ModuleOperation; -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.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.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -@Getter -public class MxpData extends ModuleOperation { - public static final BigInteger TWO_POW_128 = BigInteger.ONE.shiftLeft(128); - public static final BigInteger TWO_POW_32 = BigInteger.ONE.shiftLeft(32); - - // constants from protocol_params.go - - private final OpCodeData opCodeData; - 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 comp; - private BigInteger acc1 = BigInteger.ZERO; - private BigInteger acc2 = BigInteger.ZERO; - private BigInteger acc3 = BigInteger.ZERO; - private BigInteger acc4 = BigInteger.ZERO; - private BigInteger accA = BigInteger.ZERO; - private BigInteger accW = BigInteger.ZERO; - private BigInteger accQ = BigInteger.ZERO; - private UnsignedByte[] byte1; - private UnsignedByte[] byte2; - private UnsignedByte[] byte3; - private UnsignedByte[] byte4; - private UnsignedByte[] byteA; - private UnsignedByte[] byteW; - 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 MxpData(final MessageFrame frame, final Hub hub) { - this.opCodeData = hub.opCodeData(); - this.contextNumber = hub.currentFrame().contextNumber(); - this.typeMxp = opCodeData.billing().type(); - - this.words = frame.memoryWordSize(); - this.wordsNew = frame.memoryWordSize(); - this.cMem = memoryCost(frame.memoryWordSize()); - this.cMemNew = memoryCost(frame.memoryWordSize()); - this.deploys = hub.currentFrame().underDeployment(); - - setOffsetsAndSizes(frame); - setRoob(); - setNoOperation(); - setMaxOffset1and2(); - setMaxOffsetAndMxpx(); - setInitializeByteArrays(); - setAccAAndFirstTwoBytesOfByteR(); - setExpands(); - setWordsNew(frame); - } - - @Override - protected int computeLineCount() { - return this.maxCt(); - } - - void compute() { - setCMemNew(); - setComp(); - setAcc1and2(); - setAcc3(); - setAcc4(); - setAccWAndLastTwoBytesOfByteR(); - setAccQAndByteQQ(); - setBytes(); - setCosts(); - } - - private void setInitializeByteArrays() { - byte1 = new UnsignedByte[maxCt()]; - byte2 = new UnsignedByte[maxCt()]; - byte3 = new UnsignedByte[maxCt()]; - byte4 = new UnsignedByte[maxCt()]; - byteA = new UnsignedByte[maxCt()]; - byteW = new UnsignedByte[maxCt()]; - byteQ = new UnsignedByte[maxCt()]; - byteQQ = new UnsignedByte[maxCt()]; - byteR = new UnsignedByte[maxCt()]; - Arrays.fill(byte1, UnsignedByte.of(0)); - Arrays.fill(byte2, UnsignedByte.of(0)); - Arrays.fill(byte3, UnsignedByte.of(0)); - Arrays.fill(byte4, UnsignedByte.of(0)); - Arrays.fill(byteA, UnsignedByte.of(0)); - Arrays.fill(byteW, UnsignedByte.of(0)); - Arrays.fill(byteQ, UnsignedByte.of(0)); - Arrays.fill(byteQQ, UnsignedByte.of(0)); - Arrays.fill(byteR, UnsignedByte.of(0)); - } - - private void setOffsetsAndSizes(final MessageFrame frame) { - 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)); - } - case MSIZE -> {} - case CALLDATACOPY, CODECOPY, RETURNDATACOPY -> { - offset1 = EWord.of(frame.getStackItem(0)); - size1 = EWord.of(frame.getStackItem(2)); - } - case EXTCODECOPY -> { - offset1 = EWord.of(frame.getStackItem(1)); - size1 = EWord.of(frame.getStackItem(3)); - } - case MLOAD, MSTORE, MSTORE8 -> offset1 = EWord.of(frame.getStackItem(0)); - case CREATE, CREATE2 -> { - offset1 = EWord.of(frame.getStackItem(1)); - size1 = EWord.of(frame.getStackItem(2)); - } - case CALL, CALLCODE -> { - offset1 = EWord.of(frame.getStackItem(3)); - size1 = EWord.of(frame.getStackItem(4)); - offset2 = EWord.of(frame.getStackItem(5)); - size2 = EWord.of(frame.getStackItem(6)); - } - case DELEGATECALL, STATICCALL -> { - offset1 = EWord.of(frame.getStackItem(2)); - size1 = EWord.of(frame.getStackItem(3)); - offset2 = EWord.of(frame.getStackItem(4)); - size2 = EWord.of(frame.getStackItem(5)); - } - default -> throw new IllegalStateException("Unexpected value: " + opCode); - } - } - - /** get ridiculously out of bounds. */ - protected void setRoob() { - roob = - switch (typeMxp) { - case TYPE_2, TYPE_3 -> offset1.toBigInteger().compareTo(TWO_POW_128) >= 0; - case TYPE_4 -> size1.toBigInteger().compareTo(TWO_POW_128) >= 0 - || (offset1.toBigInteger().compareTo(TWO_POW_128) >= 0 - && !size1.toBigInteger().equals(BigInteger.ZERO)); - case TYPE_5 -> size1.toBigInteger().compareTo(TWO_POW_128) >= 0 - || (offset1.toBigInteger().compareTo(TWO_POW_128) >= 0 - && !size1.toBigInteger().equals(BigInteger.ZERO)) - || (size2.toBigInteger().compareTo(TWO_POW_128) >= 0 - || (offset2.toBigInteger().compareTo(TWO_POW_128) >= 0 - && !size2.toBigInteger().equals(BigInteger.ZERO))); - default -> false; - }; - } - - /** get no op. */ - protected void setNoOperation() { - if (roob) { - noOperation = false; - } - noOperation = - switch (typeMxp) { - case TYPE_1 -> true; - case TYPE_4 -> size1.isZero(); - case TYPE_5 -> size1.isZero() && size2.isZero(); - default -> false; - }; - } - - /** set max offsets 1 and 2. */ - protected void setMaxOffset1and2() { - if (getMxpExecutionPath() != mxpExecutionPath.TRIVIAL) { - switch (typeMxp) { - case TYPE_2 -> maxOffset1 = offset1.toBigInteger().add(BigInteger.valueOf(31)); - case TYPE_3 -> maxOffset1 = offset1.toBigInteger(); - case TYPE_4 -> { - if (!size1.toBigInteger().equals(BigInteger.ZERO)) { - maxOffset1 = offset1.toBigInteger().add(size1.toBigInteger()).subtract(BigInteger.ONE); - } - } - case TYPE_5 -> { - if (!size1.toBigInteger().equals(BigInteger.ZERO)) { - maxOffset1 = offset1.toBigInteger().add(size1.toBigInteger()).subtract(BigInteger.ONE); - } - if (!size2.toBigInteger().equals(BigInteger.ZERO)) { - maxOffset2 = offset2.toBigInteger().add(size2.toBigInteger()).subtract(BigInteger.ONE); - } - } - } - } - } - - /** set max offset and mxpx. */ - protected void setMaxOffsetAndMxpx() { - if (roob || noOperation) { - mxpx = roob; - } else { - // choose the max value - maxOffset = max(maxOffset1, maxOffset2); - mxpx = maxOffset.compareTo(TWO_POW_32) >= 0; - } - } - - public void setExpands() { - if (!roob && !noOperation && !mxpx) { - expands = accA.compareTo(BigInteger.valueOf(words)) > 0; - } - } - - // This is a copy and past from FrontierGasCalculator.java - private static long memoryCost(final long length) { - final long lengthSquare = clampedMultiply(length, length); - final long base = - (lengthSquare == Long.MAX_VALUE) - ? clampedMultiply(length / 512, length) - : lengthSquare / 512; - - return clampedAdd(clampedMultiply(GasConstants.G_MEMORY.cost(), length), base); - } - - private long getLinCost(OpCodeData opCodeData, long sizeInBytes) { - if (getMxpExecutionPath() == mxpExecutionPath.NON_TRIVIAL) { - if (opCodeData.billing().billingRate() == BillingRate.BY_BYTE) { - return opCodeData.billing().perUnit().cost() * sizeInBytes; - } - if (opCodeData.billing().billingRate() == BillingRate.BY_WORD) { - long sizeInWords = (sizeInBytes + 31) / 32; - return opCodeData.billing().perUnit().cost() * sizeInWords; - } - } - return 0; - } - - protected void setComp() { - comp = maxOffset1.compareTo(maxOffset2) >= 0; - } - - // This should translate into code page 12, point 5? - protected void setAccAAndFirstTwoBytesOfByteR() { - if (this.getMxpExecutionPath() == mxpExecutionPath.NON_TRIVIAL) { - BigInteger maxOffsetPlusOne = maxOffset.add(BigInteger.ONE); - accA = divRoundedUpBigInteger(maxOffsetPlusOne, BigInteger.valueOf(32)); - BigInteger diff = accA.multiply(BigInteger.valueOf(32)).subtract(maxOffsetPlusOne); - Bytes32 diffBytes = Bytes32.leftPad(UInt256.valueOf(diff)); - - UnsignedByte r = UnsignedByte.of(diffBytes.get(31)); - int rAsInt = r.toInteger(); - byteR[0] = UnsignedByte.of(rAsInt + 224); - byteR[1] = UnsignedByte.of(rAsInt); - } - } - - public BigInteger divRoundedUpBigInteger(BigInteger a, BigInteger b) { - return a.add(b.subtract(BigInteger.ONE)).divide(b); - } - - protected void setAcc1and2() { - if (roob) { - return; - } - if (mxpx) { - if (maxOffset1.compareTo(TWO_POW_32) >= 0) { - acc1 = maxOffset1.subtract(TWO_POW_32); - } else { - Preconditions.checkArgument(maxOffset2.compareTo(TWO_POW_32) >= 0); - acc2 = maxOffset2.subtract(TWO_POW_32); - } - } else { - acc1 = maxOffset1; - acc2 = maxOffset2; - } - } - - protected void setAcc3() { - if (comp) { - acc3 = maxOffset1.subtract(maxOffset2); - } else { - acc3 = maxOffset2.subtract(maxOffset1); - acc3 = acc3.subtract(BigInteger.ONE); - } - } - - protected void setAcc4() { - if (this.getMxpExecutionPath() == mxpExecutionPath.NON_TRIVIAL) { - if (expands) { - acc4 = accA.subtract(BigInteger.valueOf(words + 1)); - } else { - acc4 = BigInteger.valueOf(words).subtract(accA); - } - } - } - - protected void setAccWAndLastTwoBytesOfByteR() { - // @TODO: do it also for other cases - if (this.getMxpExecutionPath() == mxpExecutionPath.NON_TRIVIAL) { - if (typeMxp != MxpType.TYPE_4) { - return; - } - - accW = size1.toBigInteger().add(BigInteger.valueOf(31)).divide(BigInteger.valueOf(32)); - - BigInteger r = accW.multiply(BigInteger.valueOf(32)).subtract(size1.toBigInteger()); - - // r in [0,31] - UnsignedByte rByte = UnsignedByte.of(r.toByteArray()[r.toByteArray().length - 1]); - int rByteAsInt = rByte.toInteger(); - byteR[2] = UnsignedByte.of(rByteAsInt + 224); - byteR[3] = rByte; - } - } - - protected enum mxpExecutionPath { - TRIVIAL, - NON_TRIVIAL_BUT_MXPX, - NON_TRIVIAL - } - - private mxpExecutionPath getMxpExecutionPath() { - if (this.isRoob() || this.isNoOperation()) { - return mxpExecutionPath.TRIVIAL; - } - if (this.isMxpx()) { - return mxpExecutionPath.NON_TRIVIAL_BUT_MXPX; - } - return mxpExecutionPath.NON_TRIVIAL; - } - - public int maxCt() { - return switch (this.getMxpExecutionPath()) { - case TRIVIAL -> 1; - case NON_TRIVIAL_BUT_MXPX -> 17; - case NON_TRIVIAL -> 4; - }; - } - - protected void setAccQAndByteQQ() { - // accQ and byteQQ all equal to 0 by default - if (this.getMxpExecutionPath() == mxpExecutionPath.NON_TRIVIAL) { - setAccQAndByteQQNonTrivialCase(); - } - } - - protected void setAccQAndByteQQNonTrivialCase() { - long square = wordsNew * wordsNew; // ACC_A - - long quotient = square / 512; - long remainder = square % 512; - - accQ = BigInteger.valueOf(quotient % (1L << 32)); - - Bytes32 quotientBytes = UInt256.valueOf(quotient); // q' - Bytes32 remainderBytes = UInt256.valueOf(remainder); // r' - - byteQQ[0] = UnsignedByte.of(quotientBytes.get(quotientBytes.size() - 6)); - byteQQ[1] = UnsignedByte.of(quotientBytes.get(quotientBytes.size() - 5)); - byteQQ[2] = UnsignedByte.of(remainderBytes.get(quotientBytes.size() - 2)); - byteQQ[3] = UnsignedByte.of(remainderBytes.get(quotientBytes.size() - 1)); - } - - protected void setBytes() { - int maxCt = maxCt(); - Bytes32 b1 = UInt256.valueOf(acc1); - Bytes32 b2 = UInt256.valueOf(acc2); - Bytes32 b3 = UInt256.valueOf(acc3); - Bytes32 b4 = UInt256.valueOf(acc4); - Bytes32 bA = UInt256.valueOf(accA); - Bytes32 bW = UInt256.valueOf(accW); - Bytes32 bQ = UInt256.valueOf(accQ); - for (int i = 0; i < maxCt; i++) { - byte1[i] = UnsignedByte.of(b1.get(b1.size() - 1 - maxCt + i)); - byte2[i] = UnsignedByte.of(b2.get(b2.size() - 1 - maxCt + i)); - byte3[i] = UnsignedByte.of(b3.get(b3.size() - 1 - maxCt + i)); - byte4[i] = UnsignedByte.of(b4.get(b4.size() - 1 - maxCt + i)); - byteA[i] = UnsignedByte.of(bA.get(bA.size() - 1 - maxCt + i)); - byteW[i] = UnsignedByte.of(bW.get(bW.size() - 1 - maxCt + i)); - byteQ[i] = UnsignedByte.of(bQ.get(bQ.size() - 1 - maxCt + i)); - } - } - - private void setWordsNew(final MessageFrame frame) { - if (getMxpExecutionPath() == MxpData.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_4 -> wordsNew = - frame.calculateMemoryExpansion( - Words.clampedToLong(offset1), Words.clampedToLong(size1)); - case TYPE_5 -> { - long wordsNew1 = - frame.calculateMemoryExpansion( - Words.clampedToLong(offset1), Words.clampedToLong(size1)); - long wordsNew2 = - frame.calculateMemoryExpansion( - Words.clampedToLong(offset2), Words.clampedToLong(size2)); - wordsNew = Math.max(wordsNew1, wordsNew2); - } - } - } - } - - private void setCMemNew() { - if (getMxpExecutionPath() == MxpData.mxpExecutionPath.NON_TRIVIAL && expands) { - cMemNew = memoryCost(wordsNew); - } - } - - private void setCosts() { - if (getMxpExecutionPath() == mxpExecutionPath.NON_TRIVIAL) { - quadCost = cMemNew - cMem; - linCost = getLinCost(opCodeData, Words.clampedToLong(size1)); - } - } - - long getEffectiveLinCost() { - if (opCodeData.mnemonic() != OpCode.RETURN) { - return getLinCost(opCodeData, Words.clampedToLong(size1)); - } else { - if (deploys) { - return getLinCost(opCodeData, Words.clampedToLong(size1)); - } else { - return 0; - } - } - } - - final void trace(int stamp, Trace trace) { - this.compute(); - - Bytes32 acc1Bytes32 = Bytes32.leftPad(bigIntegerToBytes(this.getAcc1())); - Bytes32 acc2Bytes32 = Bytes32.leftPad(bigIntegerToBytes(this.getAcc2())); - Bytes32 acc3Bytes32 = Bytes32.leftPad(bigIntegerToBytes(this.getAcc3())); - Bytes32 acc4Bytes32 = Bytes32.leftPad(bigIntegerToBytes(this.getAcc4())); - 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); - - int maxCt = this.maxCt(); - int maxCtComplement = 32 - maxCt; - - for (int i = 0; i < maxCt; i++) { - trace - .stamp(Bytes.ofUnsignedLong(stamp)) - .cn(Bytes.ofUnsignedLong(this.getContextNumber())) - .ct(Bytes.of(i)) - .roob(this.isRoob()) - .noop(this.isNoOperation()) - .mxpx(this.isMxpx()) - .inst(Bytes.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) - .gword( - Bytes.ofUnsignedLong( - this.getOpCodeData().billing().billingRate() == BillingRate.BY_WORD - ? this.getOpCodeData().billing().perUnit().cost() - : 0)) - .gbyte( - Bytes.ofUnsignedLong( - this.getOpCodeData().billing().billingRate() == BillingRate.BY_BYTE - ? this.getOpCodeData().billing().perUnit().cost() - : 0)) - .deploys(this.isDeploys()) - .offset1Hi(eOffset1.hi()) - .offset1Lo(eOffset1.lo()) - .offset2Hi(eOffset2.hi()) - .offset2Lo(eOffset2.lo()) - .size1Hi(eSize1.hi()) - .size1Lo(eSize1.lo()) - .size2Hi(eSize2.hi()) - .size2Lo(eSize2.lo()) - .maxOffset1(bigIntegerToBytes(this.getMaxOffset1())) - .maxOffset2(bigIntegerToBytes(this.getMaxOffset2())) - .maxOffset(bigIntegerToBytes(this.getMaxOffset())) - .comp(this.isComp()) - .acc1(acc1Bytes32.slice(maxCtComplement, 1 + i)) - .acc2(acc2Bytes32.slice(maxCtComplement, 1 + i)) - .acc3(acc3Bytes32.slice(maxCtComplement, 1 + i)) - .acc4(acc4Bytes32.slice(maxCtComplement, 1 + i)) - .accA(accABytes32.slice(maxCtComplement, 1 + i)) - .accW(accWBytes32.slice(maxCtComplement, 1 + i)) - .accQ(accQBytes32.slice(maxCtComplement, 1 + i)) - .byte1(UnsignedByte.of(acc1Bytes32.get(maxCtComplement + i))) - .byte2(UnsignedByte.of(acc2Bytes32.get(maxCtComplement + i))) - .byte3(UnsignedByte.of(acc3Bytes32.get(maxCtComplement + i))) - .byte4(UnsignedByte.of(acc4Bytes32.get(maxCtComplement + i))) - .byteA(UnsignedByte.of(accABytes32.get(maxCtComplement + i))) - .byteW(UnsignedByte.of(accWBytes32.get(maxCtComplement + i))) - .byteQ(UnsignedByte.of(accQBytes32.get(maxCtComplement + i))) - .byteQq(Bytes.ofUnsignedLong(this.getByteQQ()[i].toInteger())) - .byteR(Bytes.ofUnsignedLong(this.getByteR()[i].toInteger())) - .words(Bytes.ofUnsignedLong(this.getWords())) - .wordsNew( - Bytes.ofUnsignedLong( - this.getWordsNew())) // TODO: Could (should?) be set in tracePostOp? - .cMem(Bytes.ofUnsignedLong(this.getCMem())) // Returns current memory size in EVM words - .cMemNew(Bytes.ofUnsignedLong(this.getCMemNew())) - .quadCost(Bytes.ofUnsignedLong(this.getQuadCost())) - .linCost(Bytes.ofUnsignedLong(this.getLinCost())) - .gasMxp(Bytes.ofUnsignedLong(this.getQuadCost() + this.getEffectiveLinCost())) - .expands(this.isExpands()) - .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 deleted file mode 100644 index d61860b30..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Trace.java +++ /dev/null @@ -1,1377 +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.mxp; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer acc1; - private final MappedByteBuffer acc2; - private final MappedByteBuffer acc3; - private final MappedByteBuffer acc4; - private final MappedByteBuffer accA; - private final MappedByteBuffer accQ; - private final MappedByteBuffer accW; - private final MappedByteBuffer byte1; - private final MappedByteBuffer byte2; - private final MappedByteBuffer byte3; - private final MappedByteBuffer byte4; - private final MappedByteBuffer byteA; - private final MappedByteBuffer byteQ; - private final MappedByteBuffer byteQq; - private final MappedByteBuffer byteR; - private final MappedByteBuffer byteW; - private final MappedByteBuffer cMem; - private final MappedByteBuffer cMemNew; - private final MappedByteBuffer cn; - private final MappedByteBuffer comp; - private final MappedByteBuffer ct; - private final MappedByteBuffer deploys; - private final MappedByteBuffer expands; - private final MappedByteBuffer gasMxp; - private final MappedByteBuffer gbyte; - private final MappedByteBuffer gword; - private final MappedByteBuffer inst; - private final MappedByteBuffer linCost; - private final MappedByteBuffer maxOffset; - private final MappedByteBuffer maxOffset1; - private final MappedByteBuffer maxOffset2; - private final MappedByteBuffer mxpType1; - private final MappedByteBuffer mxpType2; - private final MappedByteBuffer mxpType3; - private final MappedByteBuffer mxpType4; - private final MappedByteBuffer mxpType5; - private final MappedByteBuffer mxpx; - private final MappedByteBuffer noop; - private final MappedByteBuffer offset1Hi; - private final MappedByteBuffer offset1Lo; - private final MappedByteBuffer offset2Hi; - private final MappedByteBuffer offset2Lo; - private final MappedByteBuffer quadCost; - private final MappedByteBuffer roob; - private final MappedByteBuffer size1Hi; - private final MappedByteBuffer size1Lo; - private final MappedByteBuffer size2Hi; - private final MappedByteBuffer size2Lo; - private final MappedByteBuffer stamp; - private final MappedByteBuffer words; - private final MappedByteBuffer wordsNew; - - static List headers(int length) { - return List.of( - new ColumnHeader("mxp.ACC_1", 32, length), - new ColumnHeader("mxp.ACC_2", 32, length), - new ColumnHeader("mxp.ACC_3", 32, length), - new ColumnHeader("mxp.ACC_4", 32, length), - new ColumnHeader("mxp.ACC_A", 32, length), - new ColumnHeader("mxp.ACC_Q", 32, length), - new ColumnHeader("mxp.ACC_W", 32, length), - new ColumnHeader("mxp.BYTE_1", 1, length), - new ColumnHeader("mxp.BYTE_2", 1, length), - new ColumnHeader("mxp.BYTE_3", 1, length), - new ColumnHeader("mxp.BYTE_4", 1, length), - new ColumnHeader("mxp.BYTE_A", 1, length), - new ColumnHeader("mxp.BYTE_Q", 1, length), - new ColumnHeader("mxp.BYTE_QQ", 32, length), - new ColumnHeader("mxp.BYTE_R", 32, length), - new ColumnHeader("mxp.BYTE_W", 1, length), - new ColumnHeader("mxp.C_MEM", 32, length), - new ColumnHeader("mxp.C_MEM_NEW", 32, length), - new ColumnHeader("mxp.CN", 32, length), - new ColumnHeader("mxp.COMP", 1, length), - new ColumnHeader("mxp.CT", 32, length), - new ColumnHeader("mxp.DEPLOYS", 1, length), - new ColumnHeader("mxp.EXPANDS", 1, length), - new ColumnHeader("mxp.GAS_MXP", 32, length), - new ColumnHeader("mxp.GBYTE", 32, length), - new ColumnHeader("mxp.GWORD", 32, length), - new ColumnHeader("mxp.INST", 32, length), - new ColumnHeader("mxp.LIN_COST", 32, length), - new ColumnHeader("mxp.MAX_OFFSET", 32, length), - new ColumnHeader("mxp.MAX_OFFSET_1", 32, length), - new ColumnHeader("mxp.MAX_OFFSET_2", 32, length), - new ColumnHeader("mxp.MXP_TYPE_1", 1, length), - new ColumnHeader("mxp.MXP_TYPE_2", 1, length), - new ColumnHeader("mxp.MXP_TYPE_3", 1, length), - new ColumnHeader("mxp.MXP_TYPE_4", 1, length), - new ColumnHeader("mxp.MXP_TYPE_5", 1, length), - new ColumnHeader("mxp.MXPX", 1, length), - new ColumnHeader("mxp.NOOP", 1, length), - new ColumnHeader("mxp.OFFSET_1_HI", 32, length), - new ColumnHeader("mxp.OFFSET_1_LO", 32, length), - new ColumnHeader("mxp.OFFSET_2_HI", 32, length), - new ColumnHeader("mxp.OFFSET_2_LO", 32, length), - new ColumnHeader("mxp.QUAD_COST", 32, length), - new ColumnHeader("mxp.ROOB", 1, length), - new ColumnHeader("mxp.SIZE_1_HI", 32, length), - new ColumnHeader("mxp.SIZE_1_LO", 32, length), - new ColumnHeader("mxp.SIZE_2_HI", 32, length), - new ColumnHeader("mxp.SIZE_2_LO", 32, length), - new ColumnHeader("mxp.STAMP", 32, length), - new ColumnHeader("mxp.WORDS", 32, length), - new ColumnHeader("mxp.WORDS_NEW", 32, length)); - } - - public Trace(List buffers) { - this.acc1 = buffers.get(0); - this.acc2 = buffers.get(1); - this.acc3 = buffers.get(2); - this.acc4 = buffers.get(3); - this.accA = buffers.get(4); - this.accQ = buffers.get(5); - this.accW = buffers.get(6); - this.byte1 = buffers.get(7); - this.byte2 = buffers.get(8); - this.byte3 = buffers.get(9); - this.byte4 = buffers.get(10); - this.byteA = buffers.get(11); - this.byteQ = buffers.get(12); - this.byteQq = buffers.get(13); - this.byteR = buffers.get(14); - this.byteW = buffers.get(15); - this.cMem = buffers.get(16); - this.cMemNew = buffers.get(17); - this.cn = buffers.get(18); - this.comp = buffers.get(19); - this.ct = buffers.get(20); - this.deploys = buffers.get(21); - this.expands = buffers.get(22); - this.gasMxp = buffers.get(23); - this.gbyte = buffers.get(24); - this.gword = buffers.get(25); - this.inst = buffers.get(26); - this.linCost = buffers.get(27); - this.maxOffset = buffers.get(28); - this.maxOffset1 = buffers.get(29); - this.maxOffset2 = buffers.get(30); - this.mxpType1 = buffers.get(31); - this.mxpType2 = buffers.get(32); - this.mxpType3 = buffers.get(33); - this.mxpType4 = buffers.get(34); - this.mxpType5 = buffers.get(35); - this.mxpx = buffers.get(36); - this.noop = buffers.get(37); - this.offset1Hi = buffers.get(38); - this.offset1Lo = buffers.get(39); - this.offset2Hi = buffers.get(40); - this.offset2Lo = buffers.get(41); - this.quadCost = buffers.get(42); - this.roob = buffers.get(43); - this.size1Hi = buffers.get(44); - this.size1Lo = buffers.get(45); - this.size2Hi = buffers.get(46); - this.size2Lo = buffers.get(47); - this.stamp = buffers.get(48); - this.words = buffers.get(49); - this.wordsNew = buffers.get(50); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace acc1(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("mxp.ACC_1 already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc1.put((byte) 0); - } - acc1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc2(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("mxp.ACC_2 already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc2.put((byte) 0); - } - acc2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc3(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("mxp.ACC_3 already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc3.put((byte) 0); - } - acc3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc4(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("mxp.ACC_4 already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc4.put((byte) 0); - } - acc4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accA(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("mxp.ACC_A already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accA.put((byte) 0); - } - accA.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accQ(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("mxp.ACC_Q already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accQ.put((byte) 0); - } - accQ.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accW(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("mxp.ACC_W already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accW.put((byte) 0); - } - accW.put(b.toArrayUnsafe()); - - return this; - } - - public Trace byte1(final UnsignedByte b) { - if (filled.get(7)) { - throw new IllegalStateException("mxp.BYTE_1 already set"); - } else { - filled.set(7); - } - - byte1.put(b.toByte()); - - return this; - } - - public Trace byte2(final UnsignedByte b) { - if (filled.get(8)) { - throw new IllegalStateException("mxp.BYTE_2 already set"); - } else { - filled.set(8); - } - - byte2.put(b.toByte()); - - return this; - } - - public Trace byte3(final UnsignedByte b) { - if (filled.get(9)) { - throw new IllegalStateException("mxp.BYTE_3 already set"); - } else { - filled.set(9); - } - - byte3.put(b.toByte()); - - return this; - } - - public Trace byte4(final UnsignedByte b) { - if (filled.get(10)) { - throw new IllegalStateException("mxp.BYTE_4 already set"); - } else { - filled.set(10); - } - - byte4.put(b.toByte()); - - return this; - } - - public Trace byteA(final UnsignedByte b) { - if (filled.get(11)) { - throw new IllegalStateException("mxp.BYTE_A already set"); - } else { - filled.set(11); - } - - byteA.put(b.toByte()); - - return this; - } - - public Trace byteQ(final UnsignedByte b) { - if (filled.get(12)) { - throw new IllegalStateException("mxp.BYTE_Q already set"); - } else { - filled.set(12); - } - - byteQ.put(b.toByte()); - - return this; - } - - public Trace byteQq(final Bytes b) { - if (filled.get(13)) { - throw new IllegalStateException("mxp.BYTE_QQ already set"); - } else { - filled.set(13); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - byteQq.put((byte) 0); - } - byteQq.put(b.toArrayUnsafe()); - - return this; - } - - public Trace byteR(final Bytes b) { - if (filled.get(14)) { - throw new IllegalStateException("mxp.BYTE_R already set"); - } else { - filled.set(14); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - byteR.put((byte) 0); - } - byteR.put(b.toArrayUnsafe()); - - return this; - } - - public Trace byteW(final UnsignedByte b) { - if (filled.get(15)) { - throw new IllegalStateException("mxp.BYTE_W already set"); - } else { - filled.set(15); - } - - byteW.put(b.toByte()); - - return this; - } - - public Trace cMem(final Bytes b) { - if (filled.get(19)) { - throw new IllegalStateException("mxp.C_MEM already set"); - } else { - filled.set(19); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - cMem.put((byte) 0); - } - cMem.put(b.toArrayUnsafe()); - - return this; - } - - public Trace cMemNew(final Bytes b) { - if (filled.get(20)) { - throw new IllegalStateException("mxp.C_MEM_NEW already set"); - } else { - filled.set(20); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - cMemNew.put((byte) 0); - } - cMemNew.put(b.toArrayUnsafe()); - - return this; - } - - public Trace cn(final Bytes b) { - if (filled.get(16)) { - throw new IllegalStateException("mxp.CN already set"); - } else { - filled.set(16); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - cn.put((byte) 0); - } - cn.put(b.toArrayUnsafe()); - - return this; - } - - public Trace comp(final Boolean b) { - if (filled.get(17)) { - throw new IllegalStateException("mxp.COMP already set"); - } else { - filled.set(17); - } - - comp.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ct(final Bytes b) { - if (filled.get(18)) { - throw new IllegalStateException("mxp.CT already set"); - } else { - filled.set(18); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - ct.put((byte) 0); - } - ct.put(b.toArrayUnsafe()); - - return this; - } - - public Trace deploys(final Boolean b) { - if (filled.get(21)) { - throw new IllegalStateException("mxp.DEPLOYS already set"); - } else { - filled.set(21); - } - - deploys.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace expands(final Boolean b) { - if (filled.get(22)) { - throw new IllegalStateException("mxp.EXPANDS already set"); - } else { - filled.set(22); - } - - expands.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace gasMxp(final Bytes b) { - if (filled.get(23)) { - throw new IllegalStateException("mxp.GAS_MXP already set"); - } else { - filled.set(23); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasMxp.put((byte) 0); - } - gasMxp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gbyte(final Bytes b) { - if (filled.get(24)) { - throw new IllegalStateException("mxp.GBYTE already set"); - } else { - filled.set(24); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gbyte.put((byte) 0); - } - gbyte.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gword(final Bytes b) { - if (filled.get(25)) { - throw new IllegalStateException("mxp.GWORD already set"); - } else { - filled.set(25); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gword.put((byte) 0); - } - gword.put(b.toArrayUnsafe()); - - return this; - } - - public Trace inst(final Bytes b) { - if (filled.get(26)) { - throw new IllegalStateException("mxp.INST already set"); - } else { - filled.set(26); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - inst.put((byte) 0); - } - inst.put(b.toArrayUnsafe()); - - return this; - } - - public Trace linCost(final Bytes b) { - if (filled.get(27)) { - throw new IllegalStateException("mxp.LIN_COST already set"); - } else { - filled.set(27); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - linCost.put((byte) 0); - } - linCost.put(b.toArrayUnsafe()); - - return this; - } - - public Trace maxOffset(final Bytes b) { - if (filled.get(28)) { - throw new IllegalStateException("mxp.MAX_OFFSET already set"); - } else { - filled.set(28); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - maxOffset.put((byte) 0); - } - maxOffset.put(b.toArrayUnsafe()); - - return this; - } - - public Trace maxOffset1(final Bytes b) { - if (filled.get(29)) { - throw new IllegalStateException("mxp.MAX_OFFSET_1 already set"); - } else { - filled.set(29); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - maxOffset1.put((byte) 0); - } - maxOffset1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace maxOffset2(final Bytes b) { - if (filled.get(30)) { - throw new IllegalStateException("mxp.MAX_OFFSET_2 already set"); - } else { - filled.set(30); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - maxOffset2.put((byte) 0); - } - maxOffset2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace mxpType1(final Boolean b) { - if (filled.get(32)) { - throw new IllegalStateException("mxp.MXP_TYPE_1 already set"); - } else { - filled.set(32); - } - - mxpType1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace mxpType2(final Boolean b) { - if (filled.get(33)) { - throw new IllegalStateException("mxp.MXP_TYPE_2 already set"); - } else { - filled.set(33); - } - - mxpType2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace mxpType3(final Boolean b) { - if (filled.get(34)) { - throw new IllegalStateException("mxp.MXP_TYPE_3 already set"); - } else { - filled.set(34); - } - - mxpType3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace mxpType4(final Boolean b) { - if (filled.get(35)) { - throw new IllegalStateException("mxp.MXP_TYPE_4 already set"); - } else { - filled.set(35); - } - - mxpType4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace mxpType5(final Boolean b) { - if (filled.get(36)) { - throw new IllegalStateException("mxp.MXP_TYPE_5 already set"); - } else { - filled.set(36); - } - - mxpType5.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace mxpx(final Boolean b) { - if (filled.get(31)) { - throw new IllegalStateException("mxp.MXPX already set"); - } else { - filled.set(31); - } - - mxpx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace noop(final Boolean b) { - if (filled.get(37)) { - throw new IllegalStateException("mxp.NOOP already set"); - } else { - filled.set(37); - } - - noop.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace offset1Hi(final Bytes b) { - if (filled.get(38)) { - throw new IllegalStateException("mxp.OFFSET_1_HI already set"); - } else { - filled.set(38); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - offset1Hi.put((byte) 0); - } - offset1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace offset1Lo(final Bytes b) { - if (filled.get(39)) { - throw new IllegalStateException("mxp.OFFSET_1_LO already set"); - } else { - filled.set(39); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - offset1Lo.put((byte) 0); - } - offset1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace offset2Hi(final Bytes b) { - if (filled.get(40)) { - throw new IllegalStateException("mxp.OFFSET_2_HI already set"); - } else { - filled.set(40); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - offset2Hi.put((byte) 0); - } - offset2Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace offset2Lo(final Bytes b) { - if (filled.get(41)) { - throw new IllegalStateException("mxp.OFFSET_2_LO already set"); - } else { - filled.set(41); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - offset2Lo.put((byte) 0); - } - offset2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace quadCost(final Bytes b) { - if (filled.get(42)) { - throw new IllegalStateException("mxp.QUAD_COST already set"); - } else { - filled.set(42); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - quadCost.put((byte) 0); - } - quadCost.put(b.toArrayUnsafe()); - - return this; - } - - public Trace roob(final Boolean b) { - if (filled.get(43)) { - throw new IllegalStateException("mxp.ROOB already set"); - } else { - filled.set(43); - } - - roob.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace size1Hi(final Bytes b) { - if (filled.get(44)) { - throw new IllegalStateException("mxp.SIZE_1_HI already set"); - } else { - filled.set(44); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - size1Hi.put((byte) 0); - } - size1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace size1Lo(final Bytes b) { - if (filled.get(45)) { - throw new IllegalStateException("mxp.SIZE_1_LO already set"); - } else { - filled.set(45); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - size1Lo.put((byte) 0); - } - size1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace size2Hi(final Bytes b) { - if (filled.get(46)) { - throw new IllegalStateException("mxp.SIZE_2_HI already set"); - } else { - filled.set(46); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - size2Hi.put((byte) 0); - } - size2Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace size2Lo(final Bytes b) { - if (filled.get(47)) { - throw new IllegalStateException("mxp.SIZE_2_LO already set"); - } else { - filled.set(47); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - size2Lo.put((byte) 0); - } - size2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace stamp(final Bytes b) { - if (filled.get(48)) { - throw new IllegalStateException("mxp.STAMP already set"); - } else { - filled.set(48); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stamp.put((byte) 0); - } - stamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace words(final Bytes b) { - if (filled.get(49)) { - throw new IllegalStateException("mxp.WORDS already set"); - } else { - filled.set(49); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - words.put((byte) 0); - } - words.put(b.toArrayUnsafe()); - - return this; - } - - public Trace wordsNew(final Bytes b) { - if (filled.get(50)) { - throw new IllegalStateException("mxp.WORDS_NEW already set"); - } else { - filled.set(50); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - wordsNew.put((byte) 0); - } - wordsNew.put(b.toArrayUnsafe()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("mxp.ACC_1 has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("mxp.ACC_2 has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("mxp.ACC_3 has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("mxp.ACC_4 has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("mxp.ACC_A has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("mxp.ACC_Q has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("mxp.ACC_W has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("mxp.BYTE_1 has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("mxp.BYTE_2 has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("mxp.BYTE_3 has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("mxp.BYTE_4 has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("mxp.BYTE_A has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("mxp.BYTE_Q has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("mxp.BYTE_QQ has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("mxp.BYTE_R has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("mxp.BYTE_W has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("mxp.C_MEM has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("mxp.C_MEM_NEW has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("mxp.CN has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("mxp.COMP has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("mxp.CT has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("mxp.DEPLOYS has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("mxp.EXPANDS has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("mxp.GAS_MXP has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("mxp.GBYTE has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("mxp.GWORD has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("mxp.INST has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("mxp.LIN_COST has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("mxp.MAX_OFFSET has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("mxp.MAX_OFFSET_1 has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("mxp.MAX_OFFSET_2 has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("mxp.MXP_TYPE_1 has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("mxp.MXP_TYPE_2 has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("mxp.MXP_TYPE_3 has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("mxp.MXP_TYPE_4 has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("mxp.MXP_TYPE_5 has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("mxp.MXPX has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("mxp.NOOP has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("mxp.OFFSET_1_HI has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("mxp.OFFSET_1_LO has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("mxp.OFFSET_2_HI has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("mxp.OFFSET_2_LO has not been filled"); - } - - if (!filled.get(42)) { - throw new IllegalStateException("mxp.QUAD_COST has not been filled"); - } - - if (!filled.get(43)) { - throw new IllegalStateException("mxp.ROOB has not been filled"); - } - - if (!filled.get(44)) { - throw new IllegalStateException("mxp.SIZE_1_HI has not been filled"); - } - - if (!filled.get(45)) { - throw new IllegalStateException("mxp.SIZE_1_LO has not been filled"); - } - - if (!filled.get(46)) { - throw new IllegalStateException("mxp.SIZE_2_HI has not been filled"); - } - - if (!filled.get(47)) { - throw new IllegalStateException("mxp.SIZE_2_LO has not been filled"); - } - - if (!filled.get(48)) { - throw new IllegalStateException("mxp.STAMP has not been filled"); - } - - if (!filled.get(49)) { - throw new IllegalStateException("mxp.WORDS has not been filled"); - } - - if (!filled.get(50)) { - throw new IllegalStateException("mxp.WORDS_NEW has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - acc1.position(acc1.position() + 32); - } - - if (!filled.get(1)) { - acc2.position(acc2.position() + 32); - } - - if (!filled.get(2)) { - acc3.position(acc3.position() + 32); - } - - if (!filled.get(3)) { - acc4.position(acc4.position() + 32); - } - - if (!filled.get(4)) { - accA.position(accA.position() + 32); - } - - if (!filled.get(5)) { - accQ.position(accQ.position() + 32); - } - - if (!filled.get(6)) { - accW.position(accW.position() + 32); - } - - if (!filled.get(7)) { - byte1.position(byte1.position() + 1); - } - - if (!filled.get(8)) { - byte2.position(byte2.position() + 1); - } - - if (!filled.get(9)) { - byte3.position(byte3.position() + 1); - } - - if (!filled.get(10)) { - byte4.position(byte4.position() + 1); - } - - if (!filled.get(11)) { - byteA.position(byteA.position() + 1); - } - - if (!filled.get(12)) { - byteQ.position(byteQ.position() + 1); - } - - if (!filled.get(13)) { - byteQq.position(byteQq.position() + 32); - } - - if (!filled.get(14)) { - byteR.position(byteR.position() + 32); - } - - if (!filled.get(15)) { - byteW.position(byteW.position() + 1); - } - - if (!filled.get(19)) { - cMem.position(cMem.position() + 32); - } - - if (!filled.get(20)) { - cMemNew.position(cMemNew.position() + 32); - } - - if (!filled.get(16)) { - cn.position(cn.position() + 32); - } - - if (!filled.get(17)) { - comp.position(comp.position() + 1); - } - - if (!filled.get(18)) { - ct.position(ct.position() + 32); - } - - if (!filled.get(21)) { - deploys.position(deploys.position() + 1); - } - - if (!filled.get(22)) { - expands.position(expands.position() + 1); - } - - if (!filled.get(23)) { - gasMxp.position(gasMxp.position() + 32); - } - - if (!filled.get(24)) { - gbyte.position(gbyte.position() + 32); - } - - if (!filled.get(25)) { - gword.position(gword.position() + 32); - } - - if (!filled.get(26)) { - inst.position(inst.position() + 32); - } - - if (!filled.get(27)) { - linCost.position(linCost.position() + 32); - } - - if (!filled.get(28)) { - maxOffset.position(maxOffset.position() + 32); - } - - if (!filled.get(29)) { - maxOffset1.position(maxOffset1.position() + 32); - } - - if (!filled.get(30)) { - maxOffset2.position(maxOffset2.position() + 32); - } - - if (!filled.get(32)) { - mxpType1.position(mxpType1.position() + 1); - } - - if (!filled.get(33)) { - mxpType2.position(mxpType2.position() + 1); - } - - if (!filled.get(34)) { - mxpType3.position(mxpType3.position() + 1); - } - - if (!filled.get(35)) { - mxpType4.position(mxpType4.position() + 1); - } - - if (!filled.get(36)) { - mxpType5.position(mxpType5.position() + 1); - } - - if (!filled.get(31)) { - mxpx.position(mxpx.position() + 1); - } - - if (!filled.get(37)) { - noop.position(noop.position() + 1); - } - - if (!filled.get(38)) { - offset1Hi.position(offset1Hi.position() + 32); - } - - if (!filled.get(39)) { - offset1Lo.position(offset1Lo.position() + 32); - } - - if (!filled.get(40)) { - offset2Hi.position(offset2Hi.position() + 32); - } - - if (!filled.get(41)) { - offset2Lo.position(offset2Lo.position() + 32); - } - - if (!filled.get(42)) { - quadCost.position(quadCost.position() + 32); - } - - if (!filled.get(43)) { - roob.position(roob.position() + 1); - } - - if (!filled.get(44)) { - size1Hi.position(size1Hi.position() + 32); - } - - if (!filled.get(45)) { - size1Lo.position(size1Lo.position() + 32); - } - - if (!filled.get(46)) { - size2Hi.position(size2Hi.position() + 32); - } - - if (!filled.get(47)) { - size2Lo.position(size2Lo.position() + 32); - } - - if (!filled.get(48)) { - stamp.position(stamp.position() + 32); - } - - if (!filled.get(49)) { - words.position(words.position() + 32); - } - - if (!filled.get(50)) { - wordsNew.position(wordsNew.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddr.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddr.java deleted file mode 100644 index f17c7c16a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddr.java +++ /dev/null @@ -1,301 +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.rlp.addr; - -import static net.consensys.linea.zktracer.module.rlputils.Pattern.byteCounting; -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.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.longToUnsignedBigInteger; -import static net.consensys.linea.zktracer.types.Utils.bitDecomposition; -import static net.consensys.linea.zktracer.types.Utils.leftPadTo; -import static net.consensys.linea.zktracer.types.Utils.rightPadTo; -import static org.hyperledger.besu.crypto.Hash.keccak256; -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -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.hub.Hub; -import net.consensys.linea.zktracer.module.rlputils.ByteCountAndPowerOutput; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.BitDecOutput; -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 { - private static final Bytes CREATE2_SHIFT = bigIntegerToBytes(BigInteger.valueOf(0xff)); - private static final Bytes INT_SHORT = bigIntegerToBytes(BigInteger.valueOf(0x80)); - private static final int LIST_SHORT = 0xc0; - private static final int LLARGE = 16; - private static final Bytes BYTES_LLARGE = Bytes.of(LLARGE); - - private final Hub hub; - private final StackedList chunkList = new StackedList<>(); - - @Override - public String moduleKey() { - return "RLP_ADDR"; - } - - @Override - public void enterTransaction() { - this.chunkList.enter(); - } - - @Override - public void popTransaction() { - this.chunkList.pop(); - } - - @Override - public void traceStartTx(WorldView world, Transaction tx) { - if (tx.getTo().isEmpty()) { - final Address senderAddress = tx.getSender(); - final long nonce = tx.getNonce(); - RlpAddrChunk chunk = - new RlpAddrChunk( - Address.contractAddress(senderAddress, nonce), - OpCode.CREATE, - longToUnsignedBigInteger(nonce), - senderAddress); - this.chunkList.add(chunk); - } - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opcode = this.hub.opCode(); - switch (opcode) { - case CREATE -> { - final Address currentAddress = frame.getRecipientAddress(); - RlpAddrChunk chunk = - new RlpAddrChunk( - getCreateAddress(frame), - OpCode.CREATE, - longToUnsignedBigInteger(frame.getWorldUpdater().get(currentAddress).getNonce()), - currentAddress); - this.chunkList.add(chunk); - } - case CREATE2 -> { - final long offset = clampedToLong(frame.getStackItem(1)); - final long length = clampedToLong(frame.getStackItem(2)); - final Bytes initCode = frame.shadowReadMemory(offset, length); - final Bytes32 salt = Bytes32.leftPad(frame.getStackItem(3)); - final Bytes32 hash = keccak256(initCode); - - RlpAddrChunk chunk = - new RlpAddrChunk( - getCreate2Address(frame), OpCode.CREATE2, frame.getRecipientAddress(), salt, hash); - this.chunkList.add(chunk); - } - } - } - - private void traceCreate2(int stamp, RlpAddrChunk chunk, Trace trace) { - for (int ct = 0; ct < 6; ct++) { - trace - .stamp(Bytes.ofUnsignedShort(stamp)) - .recipe(Bytes.of(2)) - .recipe1(false) - .recipe2(true) - .depAddrHi(chunk.depAddress().slice(0, 4)) - .depAddrLo(chunk.depAddress().slice(4, LLARGE)) - .addrHi(chunk.address().slice(0, 4)) - .addrLo(chunk.address().slice(4, LLARGE)) - .saltHi(chunk.salt().orElseThrow().slice(0, LLARGE)) - .saltLo(chunk.salt().orElseThrow().slice(LLARGE, LLARGE)) - .kecHi(chunk.keccak().orElseThrow().slice(0, LLARGE)) - .kecLo(chunk.keccak().orElseThrow().slice(LLARGE, LLARGE)) - .lc(true) - .index(Bytes.of(ct)) - .counter(Bytes.of(ct)); - - switch (ct) { - case 0 -> { - trace.limb( - rightPadTo(Bytes.concatenate(CREATE2_SHIFT, chunk.address().slice(0, 4)), LLARGE)); - trace.nBytes(Bytes.of(5)); - } - case 1 -> trace.limb(chunk.address().slice(4, LLARGE)).nBytes(BYTES_LLARGE); - case 2 -> trace.limb(chunk.salt().orElseThrow().slice(0, LLARGE)).nBytes(BYTES_LLARGE); - case 3 -> trace.limb(chunk.salt().orElseThrow().slice(LLARGE, LLARGE)).nBytes(BYTES_LLARGE); - case 4 -> trace.limb(chunk.keccak().orElseThrow().slice(0, LLARGE)).nBytes(BYTES_LLARGE); - case 5 -> trace - .limb(chunk.keccak().orElseThrow().slice(LLARGE, LLARGE)) - .nBytes(BYTES_LLARGE); - } - - // Columns unused for Recipe2 - trace - .nonce(Bytes.EMPTY) - .byte1(UnsignedByte.ZERO) - .acc(Bytes.EMPTY) - .accBytesize(Bytes.EMPTY) - .power(Bytes.EMPTY) - .bit1(false) - .bitAcc(UnsignedByte.ZERO) - .tinyNonZeroNonce(false); - - trace.validateRow(); - } - } - - private void traceCreate(int stamp, RlpAddrChunk chunk, Trace trace) { - final int RECIPE1_CT_MAX = 8; - final BigInteger nonce = chunk.nonce().orElseThrow(); - - Bytes nonceShifted = leftPadTo(bigIntegerToBytes(nonce), RECIPE1_CT_MAX); - Boolean tinyNonZeroNonce = true; - if (nonce.compareTo(BigInteger.ZERO) == 0 || nonce.compareTo(BigInteger.valueOf(128)) >= 0) { - tinyNonZeroNonce = false; - } - // Compute the BYTESIZE and POWER columns - int nonceByteSize = bigIntegerToBytes(nonce).size(); - if (nonce.equals(BigInteger.ZERO)) { - nonceByteSize = 0; - } - ByteCountAndPowerOutput byteCounting = byteCounting(nonceByteSize, RECIPE1_CT_MAX); - - // Compute the bit decomposition of the last input's byte - final byte lastByte = nonceShifted.get(RECIPE1_CT_MAX - 1); - BitDecOutput bitDecomposition = bitDecomposition(0xff & lastByte, RECIPE1_CT_MAX); - - int size_rlp_nonce = nonceByteSize; - if (!tinyNonZeroNonce) { - size_rlp_nonce += 1; - } - - // Bytes RLP(nonce) - Bytes rlpNonce; - if (nonce.compareTo(BigInteger.ZERO) == 0) { - rlpNonce = INT_SHORT; - } else { - if (tinyNonZeroNonce) { - rlpNonce = bigIntegerToBytes(nonce); - } else { - rlpNonce = - Bytes.concatenate( - bigIntegerToBytes( - BigInteger.valueOf( - 128 + byteCounting.accByteSizeList().get(RECIPE1_CT_MAX - 1))), - bigIntegerToBytes(nonce)); - } - } - - for (int ct = 0; ct < 8; ct++) { - trace - .stamp(Bytes.ofUnsignedShort(stamp)) - .recipe(Bytes.of(1)) - .recipe1(true) - .recipe2(false) - .addrHi(chunk.address().slice(0, 4)) - .addrLo(chunk.address().slice(4, LLARGE)) - .depAddrHi(chunk.depAddress().slice(0, 4)) - .depAddrLo(chunk.depAddress().slice(4, LLARGE)) - .nonce(bigIntegerToBytes(nonce)) - .counter(Bytes.of(ct)) - .byte1(UnsignedByte.of(nonceShifted.get(ct))) - .acc(nonceShifted.slice(0, ct + 1)) - .accBytesize(Bytes.of(byteCounting.accByteSizeList().get(ct))) - .power( - bigIntegerToBytes(byteCounting.powerList().get(ct).divide(BigInteger.valueOf(256)))) - .bit1(bitDecomposition.bitDecList().get(ct)) - .bitAcc(UnsignedByte.of(bitDecomposition.bitAccList().get(ct))) - .tinyNonZeroNonce(tinyNonZeroNonce); - - switch (ct) { - case 0, 1, 2, 3 -> trace.lc(false).limb(Bytes.EMPTY).nBytes(Bytes.EMPTY).index(Bytes.EMPTY); - case 4 -> trace - .lc(true) - .limb( - rightPadTo( - bigIntegerToBytes( - BigInteger.valueOf(LIST_SHORT) - .add(BigInteger.valueOf(21)) - .add(BigInteger.valueOf(size_rlp_nonce))), - LLARGE)) - .nBytes(Bytes.of(1)) - .index(Bytes.EMPTY); - case 5 -> trace - .lc(true) - .limb( - rightPadTo( - Bytes.concatenate( - bigIntegerToBytes(BigInteger.valueOf(148)), chunk.address().slice(0, 4)), - LLARGE)) - .nBytes(Bytes.of(5)) - .index(Bytes.of(1)); - case 6 -> trace - .lc(true) - .limb(chunk.address().slice(4, LLARGE)) - .nBytes(Bytes.of(16)) - .index(Bytes.of(2)); - case 7 -> trace - .lc(true) - .limb(rightPadTo(rlpNonce, LLARGE)) - .nBytes(Bytes.of(size_rlp_nonce)) - .index(Bytes.of(3)); - } - - // Column not used fo recipe 1: - trace - .saltHi(Bytes.EMPTY) - .saltLo(Bytes.EMPTY) - .kecHi(Bytes.EMPTY) - .kecLo(Bytes.EMPTY) - .validateRow(); - } - } - - private void traceChunks(RlpAddrChunk chunk, int stamp, Trace trace) { - if (chunk.opCode().equals(OpCode.CREATE)) { - traceCreate(stamp, chunk, trace); - } else { - traceCreate2(stamp, chunk, trace); - } - } - - @Override - public int lineCount() { - return this.chunkList.lineCount(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - for (int i = 0; i < this.chunkList.size(); i++) { - traceChunks(chunkList.get(i), i + 1, trace); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddrChunk.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddrChunk.java deleted file mode 100644 index 188f261c0..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddrChunk.java +++ /dev/null @@ -1,53 +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.rlp.addr; - -import java.math.BigInteger; -import java.util.Optional; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes32; -import org.hyperledger.besu.datatypes.Address; - -@RequiredArgsConstructor -@Getter -@Accessors(fluent = true) -public final class RlpAddrChunk extends ModuleOperation { - private final Address depAddress; - private final OpCode opCode; - private final Optional nonce; - private final Address address; - private final Optional salt; - private final Optional keccak; - - public RlpAddrChunk(Address depAddress, OpCode opCode, BigInteger nonce, Address address) { - this(depAddress, opCode, Optional.of(nonce), address, Optional.empty(), Optional.empty()); - } - - public RlpAddrChunk( - Address depAddress, OpCode opCode, Address address, Bytes32 salt, Bytes32 kec) { - this(depAddress, opCode, Optional.empty(), address, Optional.of(salt), Optional.of(kec)); - } - - @Override - protected int computeLineCount() { - return this.opCode.equals(OpCode.CREATE) ? 8 : 6; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/Trace.java deleted file mode 100644 index 97f01f511..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/Trace.java +++ /dev/null @@ -1,739 +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.rlp.addr; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - static final int CREATE2_SHIFT = 255; - static final int G_TXDATA_NONZERO = 16; - static final int G_TXDATA_ZERO = 4; - static final int INT_LONG = 183; - static final int INT_SHORT = 128; - static final int LIST_LONG = 247; - static final int LIST_SHORT = 192; - static final int LLARGE = 16; - static final int LLARGEMO = 15; - static final int RLPADDR_CONST_RECIPE_1 = 1; - static final int RLPADDR_CONST_RECIPE_2 = 2; - static final int RLPRECEIPT_SUBPHASE_ID_ADDR = 53; - static final int RLPRECEIPT_SUBPHASE_ID_CUMUL_GAS = 3; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_LIMB = 77; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_SIZE = 83; - static final int RLPRECEIPT_SUBPHASE_ID_NO_LOG_ENTRY = 11; - static final int RLPRECEIPT_SUBPHASE_ID_STATUS_CODE = 2; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE = 65; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA = 96; - static final int RLPRECEIPT_SUBPHASE_ID_TYPE = 7; - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer acc; - private final MappedByteBuffer accBytesize; - private final MappedByteBuffer addrHi; - private final MappedByteBuffer addrLo; - private final MappedByteBuffer bit1; - private final MappedByteBuffer bitAcc; - private final MappedByteBuffer byte1; - private final MappedByteBuffer counter; - private final MappedByteBuffer depAddrHi; - private final MappedByteBuffer depAddrLo; - private final MappedByteBuffer index; - private final MappedByteBuffer kecHi; - private final MappedByteBuffer kecLo; - private final MappedByteBuffer lc; - private final MappedByteBuffer limb; - private final MappedByteBuffer nBytes; - private final MappedByteBuffer nonce; - private final MappedByteBuffer power; - private final MappedByteBuffer recipe; - private final MappedByteBuffer recipe1; - private final MappedByteBuffer recipe2; - private final MappedByteBuffer saltHi; - private final MappedByteBuffer saltLo; - private final MappedByteBuffer stamp; - private final MappedByteBuffer tinyNonZeroNonce; - - static List headers(int length) { - return List.of( - new ColumnHeader("rlpAddr.ACC", 32, length), - new ColumnHeader("rlpAddr.ACC_BYTESIZE", 32, length), - new ColumnHeader("rlpAddr.ADDR_HI", 32, length), - new ColumnHeader("rlpAddr.ADDR_LO", 32, length), - new ColumnHeader("rlpAddr.BIT1", 1, length), - new ColumnHeader("rlpAddr.BIT_ACC", 1, length), - new ColumnHeader("rlpAddr.BYTE1", 1, length), - new ColumnHeader("rlpAddr.COUNTER", 32, length), - new ColumnHeader("rlpAddr.DEP_ADDR_HI", 32, length), - new ColumnHeader("rlpAddr.DEP_ADDR_LO", 32, length), - new ColumnHeader("rlpAddr.INDEX", 32, length), - new ColumnHeader("rlpAddr.KEC_HI", 32, length), - new ColumnHeader("rlpAddr.KEC_LO", 32, length), - new ColumnHeader("rlpAddr.LC", 1, length), - new ColumnHeader("rlpAddr.LIMB", 32, length), - new ColumnHeader("rlpAddr.nBYTES", 32, length), - new ColumnHeader("rlpAddr.NONCE", 32, length), - new ColumnHeader("rlpAddr.POWER", 32, length), - new ColumnHeader("rlpAddr.RECIPE", 32, length), - new ColumnHeader("rlpAddr.RECIPE_1", 1, length), - new ColumnHeader("rlpAddr.RECIPE_2", 1, length), - new ColumnHeader("rlpAddr.SALT_HI", 32, length), - new ColumnHeader("rlpAddr.SALT_LO", 32, length), - new ColumnHeader("rlpAddr.STAMP", 32, length), - new ColumnHeader("rlpAddr.TINY_NON_ZERO_NONCE", 1, length)); - } - - public Trace(List buffers) { - this.acc = buffers.get(0); - this.accBytesize = buffers.get(1); - this.addrHi = buffers.get(2); - this.addrLo = buffers.get(3); - this.bit1 = buffers.get(4); - this.bitAcc = buffers.get(5); - this.byte1 = buffers.get(6); - this.counter = buffers.get(7); - this.depAddrHi = buffers.get(8); - this.depAddrLo = buffers.get(9); - this.index = buffers.get(10); - this.kecHi = buffers.get(11); - this.kecLo = buffers.get(12); - this.lc = buffers.get(13); - this.limb = buffers.get(14); - this.nBytes = buffers.get(15); - this.nonce = buffers.get(16); - this.power = buffers.get(17); - this.recipe = buffers.get(18); - this.recipe1 = buffers.get(19); - this.recipe2 = buffers.get(20); - this.saltHi = buffers.get(21); - this.saltLo = buffers.get(22); - this.stamp = buffers.get(23); - this.tinyNonZeroNonce = buffers.get(24); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace acc(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("rlpAddr.ACC already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc.put((byte) 0); - } - acc.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accBytesize(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("rlpAddr.ACC_BYTESIZE already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accBytesize.put((byte) 0); - } - accBytesize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace addrHi(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("rlpAddr.ADDR_HI already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrHi.put((byte) 0); - } - addrHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace addrLo(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("rlpAddr.ADDR_LO already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrLo.put((byte) 0); - } - addrLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace bit1(final Boolean b) { - if (filled.get(4)) { - throw new IllegalStateException("rlpAddr.BIT1 already set"); - } else { - filled.set(4); - } - - bit1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bitAcc(final UnsignedByte b) { - if (filled.get(5)) { - throw new IllegalStateException("rlpAddr.BIT_ACC already set"); - } else { - filled.set(5); - } - - bitAcc.put(b.toByte()); - - return this; - } - - public Trace byte1(final UnsignedByte b) { - if (filled.get(6)) { - throw new IllegalStateException("rlpAddr.BYTE1 already set"); - } else { - filled.set(6); - } - - byte1.put(b.toByte()); - - return this; - } - - public Trace counter(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("rlpAddr.COUNTER already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - counter.put((byte) 0); - } - counter.put(b.toArrayUnsafe()); - - return this; - } - - public Trace depAddrHi(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("rlpAddr.DEP_ADDR_HI already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depAddrHi.put((byte) 0); - } - depAddrHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace depAddrLo(final Bytes b) { - if (filled.get(9)) { - throw new IllegalStateException("rlpAddr.DEP_ADDR_LO already set"); - } else { - filled.set(9); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depAddrLo.put((byte) 0); - } - depAddrLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace index(final Bytes b) { - if (filled.get(10)) { - throw new IllegalStateException("rlpAddr.INDEX already set"); - } else { - filled.set(10); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - index.put((byte) 0); - } - index.put(b.toArrayUnsafe()); - - return this; - } - - public Trace kecHi(final Bytes b) { - if (filled.get(11)) { - throw new IllegalStateException("rlpAddr.KEC_HI already set"); - } else { - filled.set(11); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - kecHi.put((byte) 0); - } - kecHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace kecLo(final Bytes b) { - if (filled.get(12)) { - throw new IllegalStateException("rlpAddr.KEC_LO already set"); - } else { - filled.set(12); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - kecLo.put((byte) 0); - } - kecLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace lc(final Boolean b) { - if (filled.get(13)) { - throw new IllegalStateException("rlpAddr.LC already set"); - } else { - filled.set(13); - } - - lc.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace limb(final Bytes b) { - if (filled.get(14)) { - throw new IllegalStateException("rlpAddr.LIMB already set"); - } else { - filled.set(14); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - limb.put((byte) 0); - } - limb.put(b.toArrayUnsafe()); - - return this; - } - - public Trace nBytes(final Bytes b) { - if (filled.get(24)) { - throw new IllegalStateException("rlpAddr.nBYTES already set"); - } else { - filled.set(24); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nBytes.put((byte) 0); - } - nBytes.put(b.toArrayUnsafe()); - - return this; - } - - public Trace nonce(final Bytes b) { - if (filled.get(15)) { - throw new IllegalStateException("rlpAddr.NONCE already set"); - } else { - filled.set(15); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonce.put((byte) 0); - } - nonce.put(b.toArrayUnsafe()); - - return this; - } - - public Trace power(final Bytes b) { - if (filled.get(16)) { - throw new IllegalStateException("rlpAddr.POWER already set"); - } else { - filled.set(16); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - power.put((byte) 0); - } - power.put(b.toArrayUnsafe()); - - return this; - } - - public Trace recipe(final Bytes b) { - if (filled.get(17)) { - throw new IllegalStateException("rlpAddr.RECIPE already set"); - } else { - filled.set(17); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - recipe.put((byte) 0); - } - recipe.put(b.toArrayUnsafe()); - - return this; - } - - public Trace recipe1(final Boolean b) { - if (filled.get(18)) { - throw new IllegalStateException("rlpAddr.RECIPE_1 already set"); - } else { - filled.set(18); - } - - recipe1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace recipe2(final Boolean b) { - if (filled.get(19)) { - throw new IllegalStateException("rlpAddr.RECIPE_2 already set"); - } else { - filled.set(19); - } - - recipe2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace saltHi(final Bytes b) { - if (filled.get(20)) { - throw new IllegalStateException("rlpAddr.SALT_HI already set"); - } else { - filled.set(20); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - saltHi.put((byte) 0); - } - saltHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace saltLo(final Bytes b) { - if (filled.get(21)) { - throw new IllegalStateException("rlpAddr.SALT_LO already set"); - } else { - filled.set(21); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - saltLo.put((byte) 0); - } - saltLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace stamp(final Bytes b) { - if (filled.get(22)) { - throw new IllegalStateException("rlpAddr.STAMP already set"); - } else { - filled.set(22); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stamp.put((byte) 0); - } - stamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace tinyNonZeroNonce(final Boolean b) { - if (filled.get(23)) { - throw new IllegalStateException("rlpAddr.TINY_NON_ZERO_NONCE already set"); - } else { - filled.set(23); - } - - tinyNonZeroNonce.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("rlpAddr.ACC has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("rlpAddr.ACC_BYTESIZE has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("rlpAddr.ADDR_HI has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("rlpAddr.ADDR_LO has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("rlpAddr.BIT1 has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("rlpAddr.BIT_ACC has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("rlpAddr.BYTE1 has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("rlpAddr.COUNTER has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("rlpAddr.DEP_ADDR_HI has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("rlpAddr.DEP_ADDR_LO has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("rlpAddr.INDEX has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("rlpAddr.KEC_HI has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("rlpAddr.KEC_LO has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("rlpAddr.LC has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("rlpAddr.LIMB has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("rlpAddr.nBYTES has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("rlpAddr.NONCE has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("rlpAddr.POWER has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("rlpAddr.RECIPE has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("rlpAddr.RECIPE_1 has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("rlpAddr.RECIPE_2 has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("rlpAddr.SALT_HI has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("rlpAddr.SALT_LO has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("rlpAddr.STAMP has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("rlpAddr.TINY_NON_ZERO_NONCE has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - acc.position(acc.position() + 32); - } - - if (!filled.get(1)) { - accBytesize.position(accBytesize.position() + 32); - } - - if (!filled.get(2)) { - addrHi.position(addrHi.position() + 32); - } - - if (!filled.get(3)) { - addrLo.position(addrLo.position() + 32); - } - - if (!filled.get(4)) { - bit1.position(bit1.position() + 1); - } - - if (!filled.get(5)) { - bitAcc.position(bitAcc.position() + 1); - } - - if (!filled.get(6)) { - byte1.position(byte1.position() + 1); - } - - if (!filled.get(7)) { - counter.position(counter.position() + 32); - } - - if (!filled.get(8)) { - depAddrHi.position(depAddrHi.position() + 32); - } - - if (!filled.get(9)) { - depAddrLo.position(depAddrLo.position() + 32); - } - - if (!filled.get(10)) { - index.position(index.position() + 32); - } - - if (!filled.get(11)) { - kecHi.position(kecHi.position() + 32); - } - - if (!filled.get(12)) { - kecLo.position(kecLo.position() + 32); - } - - if (!filled.get(13)) { - lc.position(lc.position() + 1); - } - - if (!filled.get(14)) { - limb.position(limb.position() + 32); - } - - if (!filled.get(24)) { - nBytes.position(nBytes.position() + 32); - } - - if (!filled.get(15)) { - nonce.position(nonce.position() + 32); - } - - if (!filled.get(16)) { - power.position(power.position() + 32); - } - - if (!filled.get(17)) { - recipe.position(recipe.position() + 32); - } - - if (!filled.get(18)) { - recipe1.position(recipe1.position() + 1); - } - - if (!filled.get(19)) { - recipe2.position(recipe2.position() + 1); - } - - if (!filled.get(20)) { - saltHi.position(saltHi.position() + 32); - } - - if (!filled.get(21)) { - saltLo.position(saltLo.position() + 32); - } - - if (!filled.get(22)) { - stamp.position(stamp.position() + 32); - } - - if (!filled.get(23)) { - tinyNonZeroNonce.position(tinyNonZeroNonce.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxn.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxn.java deleted file mode 100644 index 258ad861c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxn.java +++ /dev/null @@ -1,1216 +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.rlp.txn; - -import static net.consensys.linea.zktracer.module.Util.getTxTypeAsInt; -import static net.consensys.linea.zktracer.module.rlputils.Pattern.byteCounting; -import static net.consensys.linea.zktracer.module.rlputils.Pattern.innerRlpSize; -import static net.consensys.linea.zktracer.module.rlputils.Pattern.outerRlpSize; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.longToUnsignedBigInteger; -import static net.consensys.linea.zktracer.types.Utils.bitDecomposition; -import static net.consensys.linea.zktracer.types.Utils.leftPadTo; -import static net.consensys.linea.zktracer.types.Utils.rightPadTo; -import static org.hyperledger.besu.ethereum.core.encoding.EncodingContext.BLOCK_BODY; -import static org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder.encodeOpaqueBytes; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.function.Function; - -import com.google.common.base.Preconditions; -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.rlputils.ByteCountAndPowerOutput; -import net.consensys.linea.zktracer.module.romLex.RomLex; -import net.consensys.linea.zktracer.types.BitDecOutput; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; -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.ethereum.core.encoding.AccessListTransactionEncoder; -import org.hyperledger.besu.ethereum.rlp.RLP; -import org.hyperledger.besu.ethereum.rlp.RLPOutput; -import org.hyperledger.besu.evm.account.AccountState; -import org.hyperledger.besu.evm.worldstate.WorldView; - -public class RlpTxn implements Module { - private final RomLex romLex; - - public RlpTxn(RomLex _romLex) { - this.romLex = _romLex; - } - - @Override - public String moduleKey() { - return "TX_RLP"; - } - - public static final int LLARGE = TxnrlpTrace.LLARGE.intValue(); - public static final Bytes BYTES_PREFIX_SHORT_INT = - bigIntegerToBytes(BigInteger.valueOf(TxnrlpTrace.int_short.intValue())); - public static final int INT_PREFIX_SHORT_INT = - BYTES_PREFIX_SHORT_INT.toUnsignedBigInteger().intValueExact(); - public static final Bytes BYTES_PREFIX_LONG_INT = - bigIntegerToBytes(BigInteger.valueOf(TxnrlpTrace.int_long.intValue())); - public static final int INT_PREFIX_LONG_INT = - BYTES_PREFIX_LONG_INT.toUnsignedBigInteger().intValueExact(); - public static final Bytes BYTES_PREFIX_SHORT_LIST = - bigIntegerToBytes(BigInteger.valueOf(TxnrlpTrace.list_short.intValue())); - public static final int INT_PREFIX_SHORT_LIST = - BYTES_PREFIX_SHORT_LIST.toUnsignedBigInteger().intValueExact(); - public static final Bytes BYTES_PREFIX_LONG_LIST = - bigIntegerToBytes(BigInteger.valueOf(TxnrlpTrace.list_long.intValue())); - - public static final int INT_PREFIX_LONG_LIST = - BYTES_PREFIX_LONG_LIST.toUnsignedBigInteger().intValueExact(); - - private final StackedList chunkList = new StackedList<>(); - - // Used to check the reconstruction of RLPs - Bytes reconstructedRlpLt; - - Bytes reconstructedRlpLx; - - @Override - public void enterTransaction() { - this.chunkList.enter(); - } - - @Override - public void popTransaction() { - this.chunkList.pop(); - } - - @Override - public void traceStartTx(WorldView worldView, Transaction tx) { - // Contract Creation - if (tx.getTo().isEmpty() && !tx.getInit().orElseThrow().isEmpty()) { - this.chunkList.add(new RlpTxnChunk(tx, true, romLex.codeIdentifierBeforeLexOrder)); - } - - // Call to a non-empty smart contract - else if (tx.getTo().isPresent() - && Optional.ofNullable(worldView.get(tx.getTo().orElseThrow())) - .map(AccountState::hasCode) - .orElse(false)) { - this.chunkList.add(new RlpTxnChunk(tx, true)); - } else { - // Contract doesn't require EVM execution - this.chunkList.add(new RlpTxnChunk(tx, false)); - } - } - - public void traceChunk(RlpTxnChunk chunk, int absTxNum, int codeFragmentIndex, Trace trace) { - - // Create the local row storage and specify transaction constant columns - RlpTxnColumnsValue traceValue = new RlpTxnColumnsValue(); - traceValue.resetDataHiLo(); - traceValue.addrHi = bigIntegerToBytes(BigInteger.ZERO); - traceValue.addrLo = bigIntegerToBytes(BigInteger.ZERO); - traceValue.absTxNum = absTxNum; - traceValue.requiresEvmExecution = chunk.requireEvmExecution(); - traceValue.codeFragmentIndex = codeFragmentIndex; - traceValue.txType = getTxTypeAsInt(chunk.tx().getType()); - - // Initialise RLP_LT and RLP_LX byte size + verify that we construct the right RLP - this.reconstructedRlpLt = Bytes.EMPTY; - this.reconstructedRlpLx = Bytes.EMPTY; - Bytes besuRlpLt = - encodeOpaqueBytes((org.hyperledger.besu.ethereum.core.Transaction) chunk.tx(), BLOCK_BODY); - // the encodeOpaqueBytes method already concatenate with the first byte "transaction type" - if (traceValue.txType == 0) { - traceValue.rlpLtByteSize = innerRlpSize(besuRlpLt.size()); - } else { - traceValue.rlpLtByteSize = innerRlpSize(besuRlpLt.size() - 1); - } - - Bytes besuRlpLx; - switch (traceValue.txType) { - case 0 -> { - besuRlpLx = - frontierPreimage( - chunk.tx().getNonce(), - (Wei) chunk.tx().getGasPrice().orElseThrow(), - chunk.tx().getGasLimit(), - chunk.tx().getTo().map(x -> (Address) x), - (Wei) chunk.tx().getValue(), - chunk.tx().getPayload(), - chunk.tx().getChainId()); - traceValue.rlpLxByteSize = innerRlpSize(besuRlpLx.size()); - } - case 1 -> { - List accessList = null; - if (chunk.tx().getAccessList().isPresent()) { - accessList = chunk.tx().getAccessList().orElseThrow(); - } - besuRlpLx = - accessListPreimage( - chunk.tx().getNonce(), - (Wei) chunk.tx().getGasPrice().orElseThrow(), - chunk.tx().getGasLimit(), - chunk.tx().getTo().map(x -> (Address) x), - (Wei) chunk.tx().getValue(), - chunk.tx().getPayload(), - accessList, - chunk.tx().getChainId()); - // the innerRlp method already concatenate with the first byte "transaction type" - traceValue.rlpLxByteSize = innerRlpSize(besuRlpLx.size() - 1); - } - case 2 -> { - besuRlpLx = - eip1559Preimage( - chunk.tx().getNonce(), - (Wei) chunk.tx().getMaxPriorityFeePerGas().orElseThrow(), - (Wei) chunk.tx().getMaxFeePerGas().orElseThrow(), - chunk.tx().getGasLimit(), - chunk.tx().getTo().map(x -> (Address) x), - (Wei) chunk.tx().getValue(), - chunk.tx().getPayload(), - chunk.tx().getChainId(), - chunk.tx().getAccessList()); - // the innerRlp method already concatenate with the first byte "transaction type" - traceValue.rlpLxByteSize = innerRlpSize(besuRlpLx.size() - 1); - } - default -> throw new IllegalStateException( - "Transaction Type not supported: " + traceValue.txType); - } - - // Phase 0 : Global RLP prefix - traceValue.dataLo = BigInteger.valueOf(traceValue.txType); - handlePhaseGlobalRlpPrefix(traceValue, trace); - - // Phase 1 : ChainId - if (traceValue.txType == 1 || traceValue.txType == 2) { - Preconditions.checkArgument( - bigIntegerToBytes(chunk.tx().getChainId().orElseThrow()).size() <= 8, - "ChainId is longer than 8 bytes"); - handlePhaseInteger(traceValue, 1, chunk.tx().getChainId().get(), 8, trace); - } - - // Phase 2 : Nonce - BigInteger nonce = longToUnsignedBigInteger(chunk.tx().getNonce()); - traceValue.dataLo = nonce; - handlePhaseInteger(traceValue, 2, nonce, 8, trace); - - // Phase 3 : GasPrice - if (traceValue.txType == 0 || traceValue.txType == 1) { - BigInteger gasPrice = chunk.tx().getGasPrice().orElseThrow().getAsBigInteger(); - Preconditions.checkArgument( - bigIntegerToBytes(gasPrice).size() <= 8, "GasPrice is longer than 8 bytes"); - traceValue.dataLo = gasPrice; - handlePhaseInteger(traceValue, 3, gasPrice, 8, trace); - } - - // Phase 4 : max priority fee per gas (GasTipCap) - if (traceValue.txType == 2) { - BigInteger maxPriorityFeePerGas = - chunk.tx().getMaxPriorityFeePerGas().orElseThrow().getAsBigInteger(); - Preconditions.checkArgument( - bigIntegerToBytes(maxPriorityFeePerGas).size() <= 8, - "Max Priority Fee per Gas is longer than 8 bytes"); - handlePhaseInteger(traceValue, 4, maxPriorityFeePerGas, 8, trace); - } - - // Phase 5 : max fee per gas (GasFeeCap) - if (traceValue.txType == 2) { - traceValue.dataHi = chunk.tx().getMaxPriorityFeePerGas().orElseThrow().getAsBigInteger(); - BigInteger maxFeePerGas = chunk.tx().getMaxFeePerGas().orElseThrow().getAsBigInteger(); - Preconditions.checkArgument( - bigIntegerToBytes(maxFeePerGas).size() <= 8, "Max Fee per Gas is longer than 8 bytes"); - traceValue.dataLo = maxFeePerGas; - handlePhaseInteger(traceValue, 5, maxFeePerGas, 8, trace); - } - - // Phase 6 : GasLimit - BigInteger gasLimit = BigInteger.valueOf(chunk.tx().getGasLimit()); - traceValue.dataLo = gasLimit; - handlePhaseInteger(traceValue, 6, gasLimit, 8, trace); - - // Phase 7 : To - if (chunk.tx().getTo().isPresent()) { - traceValue.dataHi = chunk.tx().getTo().orElseThrow().slice(0, 4).toUnsignedBigInteger(); - traceValue.dataLo = chunk.tx().getTo().orElseThrow().slice(4, 16).toUnsignedBigInteger(); - } else { - traceValue.dataHi = BigInteger.ZERO; - traceValue.dataLo = BigInteger.ZERO; - } - handlePhaseTo(traceValue, chunk.tx(), trace); - - // Phase 8 : Value - BigInteger value = chunk.tx().getValue().getAsBigInteger(); - traceValue.dataLo = value; - if (chunk.tx().getTo().isEmpty()) { - traceValue.dataHi = BigInteger.ONE; - } else { - traceValue.dataHi = BigInteger.ZERO; - } - handlePhaseInteger(traceValue, 8, value, LLARGE, trace); - - // Phase 9 : Data - handlePhaseData(traceValue, chunk.tx(), trace); - - // Phase 10 : AccessList - if (traceValue.txType == 1 || traceValue.txType == 2) { - handlePhaseAccessList(traceValue, chunk.tx(), trace); - } - - // Phase 11 : Beta / w - if (traceValue.txType == 0) { - handlePhaseBeta(traceValue, chunk.tx(), trace); - } - - // Phase 12 : y - if (traceValue.txType == 1 || traceValue.txType == 2) { - handlePhaseY(traceValue, chunk.tx(), trace); - } - - // Phase 13 : r - handle32BytesInteger(traceValue, 13, chunk.tx().getR(), trace); - - // Phase 14 : s - handle32BytesInteger(traceValue, 14, chunk.tx().getS(), trace); - - Preconditions.checkArgument( - this.reconstructedRlpLt.equals(besuRlpLt), "Reconstructed RLP LT and Besu RLP LT differ"); - Preconditions.checkArgument( - this.reconstructedRlpLx.equals(besuRlpLx), "Reconstructed RLP LX and Besu RLP LX differ"); - } - - // Define each phase's constraints - private void handlePhaseGlobalRlpPrefix(RlpTxnColumnsValue traceValue, Trace trace) { - int phase = 0; - // First, trace the Type prefix of the transaction - traceValue.partialReset(phase, 1, true, true); - if (traceValue.txType != 0) { - traceValue.limbConstructed = true; - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(traceValue.txType)); - traceValue.nBytes = 1; - traceRow(traceValue, trace); - } else { - traceValue.lcCorrection = true; - traceRow(traceValue, trace); - } - - // RLP prefix of RLP(LT) - rlpByteString( - 0, - traceValue.rlpLtByteSize, - true, - true, - false, - false, - false, - false, - false, - traceValue, - trace); - - // RLP prefix of RLP(LT) - rlpByteString( - 0, - traceValue.rlpLxByteSize, - true, - false, - true, - false, - false, - false, - true, - traceValue, - trace); - } - - private void handlePhaseInteger( - RlpTxnColumnsValue traceValue, int phase, BigInteger input, int nbstep, Trace trace) { - if (input.equals(BigInteger.ZERO)) { - traceZeroInt(traceValue, phase, true, true, false, true, trace); - } else { - rlpInt(phase, input, nbstep, true, true, false, true, false, traceValue, trace); - } - } - - private void handlePhaseTo(RlpTxnColumnsValue traceValue, Transaction tx, Trace trace) { - int phase = 7; - boolean lt = true; - boolean lx = true; - - if (tx.getTo().isEmpty()) { - traceZeroInt(traceValue, phase, lt, lx, false, true, trace); - } else { - handleAddress(traceValue, phase, tx.getTo().get(), trace); - } - } - - private void handlePhaseData(RlpTxnColumnsValue traceValue, Transaction tx, Trace trace) { - int phase = 9; - boolean lt = true; - boolean lx = true; - - if (tx.getPayload().isEmpty()) { - // Trivial case - traceZeroInt(traceValue, phase, lt, lx, true, false, trace); - - // One row of padding - traceValue.partialReset(phase, 1, lt, lx); - traceValue.lcCorrection = true; - traceValue.phaseEnd = true; - traceRow(traceValue, trace); - } else { - // General case - - // Initialise DataSize and DataGasCost - Bytes data = tx.getPayload(); - traceValue.phaseByteSize = data.size(); - for (int i = 0; i < traceValue.phaseByteSize; i++) { - if (data.get(i) == 0) { - traceValue.dataGasCost += TxnrlpTrace.G_txdatazero.intValue(); - } else { - traceValue.dataGasCost += TxnrlpTrace.G_txdatanonzero.intValue(); - } - } - traceValue.dataHi = BigInteger.valueOf(traceValue.dataGasCost); - traceValue.dataLo = BigInteger.valueOf(traceValue.phaseByteSize); - - // Trace - // RLP prefix - if (traceValue.phaseByteSize == 1) { - rlpInt( - phase, - tx.getPayload().toUnsignedBigInteger(), - 8, - lt, - lx, - true, - false, - true, - traceValue, - trace); - } else { - // General case - rlpByteString( - phase, - traceValue.phaseByteSize, - false, - lt, - lx, - true, - false, - false, - false, - traceValue, - trace); - } - - // Tracing the Data: several 16-rows ct-loop - int nbstep = 16; - int nbloop = (traceValue.phaseByteSize - 1) / nbstep + 1; - data = rightPadTo(data, nbstep * nbloop); - for (int i = 0; i < nbloop; i++) { - traceValue.partialReset(phase, nbstep, lt, lx); - traceValue.input1 = data.slice(LLARGE * i, LLARGE); - int accByteSize = 0; - for (int ct = 0; ct < LLARGE; ct++) { - traceValue.counter = ct; - if (traceValue.phaseByteSize != 0) { - accByteSize += 1; - } - traceValue.byte1 = traceValue.input1.get(ct); - traceValue.acc1 = traceValue.input1.slice(0, ct + 1); - traceValue.accByteSize = accByteSize; - if (ct == nbstep - 1) { - traceValue.limbConstructed = true; - traceValue.limb = traceValue.input1; - traceValue.nBytes = accByteSize; - } - traceRow(traceValue, trace); - } - } - // Two rows of padding - traceValue.partialReset(phase, 2, lt, lx); - traceValue.lcCorrection = true; - traceRow(traceValue, trace); - - traceValue.counter = 1; - traceValue.phaseEnd = true; - traceRow(traceValue, trace); - } - - // Put INDEX_DATA to 0 at the end of the phase - traceValue.indexData = 0; - } - - private void handlePhaseAccessList(RlpTxnColumnsValue traceValue, Transaction tx, Trace trace) { - int phase = 10; - boolean lt = true; - boolean lx = true; - - // Trivial case - if (tx.getAccessList().get().isEmpty()) { - traceVoidList(traceValue, phase, lt, lx, true, false, false, true, trace); - } else { - // Initialise traceValue - int nbAddr = 0; - int nbSto = 0; - List nbStoPerAddrList = new ArrayList<>(); - List accessTupleByteSizeList = new ArrayList<>(); - int phaseByteSize = 0; - for (int i = 0; i < tx.getAccessList().orElseThrow().size(); i++) { - nbAddr += 1; - nbSto += tx.getAccessList().orElseThrow().get(i).storageKeys().size(); - nbStoPerAddrList.add(tx.getAccessList().orElseThrow().get(i).storageKeys().size()); - accessTupleByteSizeList.add( - 21 + outerRlpSize(33 * tx.getAccessList().orElseThrow().get(i).storageKeys().size())); - phaseByteSize += outerRlpSize(accessTupleByteSizeList.get(i)); - } - - traceValue.partialReset(phase, 0, lt, lx); - traceValue.nbAddr = nbAddr; - traceValue.dataLo = BigInteger.valueOf(nbAddr); - traceValue.nbSto = nbSto; - traceValue.dataHi = BigInteger.valueOf(nbSto); - traceValue.phaseByteSize = phaseByteSize; - - // Trace RLP(Phase Byte Size) - rlpByteString( - phase, - traceValue.phaseByteSize, - true, - lt, - lx, - true, - false, - false, - false, - traceValue, - trace); - - // Loop Over AccessTuple - for (int i = 0; i < nbAddr; i++) { - - // Update columns at the beginning of an AccessTuple entry - traceValue.nbAddr -= 1; - traceValue.nbStoPerAddr = nbStoPerAddrList.get(i); - traceValue.addrHi = tx.getAccessList().orElseThrow().get(i).address().slice(0, 4); - traceValue.addrLo = tx.getAccessList().orElseThrow().get(i).address().slice(4, LLARGE); - traceValue.accessTupleByteSize = accessTupleByteSizeList.get(i); - - // Rlp(AccessTupleByteSize) - rlpByteString( - phase, - traceValue.accessTupleByteSize, - true, - lt, - lx, - true, - true, - false, - false, - traceValue, - trace); - - // RLP (address) - handleAddress(traceValue, phase, tx.getAccessList().get().get(i).address(), trace); - - // Rlp prefix of the list of storage key - if (nbStoPerAddrList.get(i) == 0) { - traceVoidList( - traceValue, - phase, - lt, - lx, - true, - true, - true, - ((traceValue.nbSto == 0) && (traceValue.nbAddr == 0)), - trace); - } else { - rlpByteString( - phase, - 33L * traceValue.nbStoPerAddr, - true, - lt, - lx, - true, - true, - true, - false, - traceValue, - trace); - - // Loop over StorageKey - for (int j = 0; j < nbStoPerAddrList.get(i); j++) { - traceValue.nbSto -= 1; - traceValue.nbStoPerAddr -= 1; - handleStorageKey( - traceValue, - ((traceValue.nbSto == 0) && (traceValue.nbAddr == 0)), - tx.getAccessList().get().get(i).storageKeys().get(j), - trace); - } - } - traceValue.addrHi = bigIntegerToBytes(BigInteger.ZERO); - traceValue.addrLo = bigIntegerToBytes(BigInteger.ZERO); - } - } - } - - private void handlePhaseBeta(RlpTxnColumnsValue traceValue, Transaction tx, Trace trace) { - final int phase = 11; - final BigInteger V = tx.getV(); - Preconditions.checkArgument(bigIntegerToBytes(V).size() <= 8, "V is longer than 8 bytes"); - final boolean betaIsZero = - V.equals(BigInteger.valueOf(27)) - || V.equals(BigInteger.valueOf(28)); // beta = ChainId = 0 iff (V == 27 or V == 28) - - // Rlp(w) - rlpInt( - phase, - V, - 8, - true, - false, - false, - betaIsZero, - false, - traceValue, - trace); // end of the phase if beta == 0 - - // if beta != 0, then RLP(beta) and then one row with RLP().RLP () - if (!betaIsZero) { - final BigInteger beta = - BigInteger.valueOf( - (V.longValueExact() - 35) / 2); // when b != 0, V = 2 beta + 35 or V = 2 beta + 36; - - rlpInt(phase, beta, 8, false, true, true, false, false, traceValue, trace); - - traceValue.partialReset(phase, 1, false, true); - traceValue.limbConstructed = true; - traceValue.limb = Bytes.concatenate(BYTES_PREFIX_SHORT_INT, BYTES_PREFIX_SHORT_INT); - traceValue.nBytes = 2; - traceValue.phaseEnd = true; - traceRow(traceValue, trace); - } - } - - private void handlePhaseY(RlpTxnColumnsValue traceValue, Transaction tx, Trace trace) { - traceValue.partialReset(12, 1, true, false); - traceValue.input1 = bigIntegerToBytes(tx.getYParity()); - traceValue.limbConstructed = true; - if (tx.getYParity().equals(BigInteger.ZERO)) { - traceValue.limb = BYTES_PREFIX_SHORT_INT; - } else { - traceValue.limb = bigIntegerToBytes(BigInteger.ONE); - } - traceValue.nBytes = 1; - traceValue.phaseEnd = true; - traceRow(traceValue, trace); - } - - private void rlpByteString( - int phase, - long length, - boolean isList, - boolean lt, - boolean lx, - boolean isPrefix, - boolean depth1, - boolean depth2, - boolean endPhase, - RlpTxnColumnsValue traceValue, - Trace trace) { - int lengthSize = bigIntegerToBytes(BigInteger.valueOf(length)).size(); - - ByteCountAndPowerOutput byteCountingOutput = byteCounting(lengthSize, 8); - - traceValue.partialReset(phase, 8, lt, lx); - traceValue.input1 = bigIntegerToBytes(BigInteger.valueOf(length)); - traceValue.isPrefix = isPrefix; - traceValue.depth1 = depth1; - traceValue.depth2 = depth2; - - Bytes input1RightShift = leftPadTo(traceValue.input1, 8); - - long acc2LastRow; - if (length >= 56) { - acc2LastRow = length - 56; - } else { - acc2LastRow = 55 - length; - } - Bytes acc2LastRowShift = leftPadTo(bigIntegerToBytes(BigInteger.valueOf(acc2LastRow)), 8); - - for (int ct = 0; ct < 8; ct++) { - traceValue.counter = ct; - traceValue.accByteSize = byteCountingOutput.accByteSizeList().get(ct); - traceValue.power = byteCountingOutput.powerList().get(ct); - traceValue.byte1 = input1RightShift.get(ct); - traceValue.acc1 = input1RightShift.slice(0, ct + 1); - traceValue.byte2 = acc2LastRowShift.get(ct); - traceValue.acc2 = acc2LastRowShift.slice(0, ct + 1); - - if (length >= 56) { - if (ct == 6) { - traceValue.limbConstructed = true; - traceValue.nBytes = 1; - BigInteger tmp; - if (isList) { - tmp = BigInteger.valueOf(INT_PREFIX_LONG_LIST + lengthSize); - } else { - tmp = BigInteger.valueOf(INT_PREFIX_LONG_INT + lengthSize); - } - traceValue.limb = bigIntegerToBytes(tmp); - } - - if (ct == 7) { - traceValue.limb = traceValue.input1; - traceValue.nBytes = lengthSize; - traceValue.bit = true; - traceValue.bitAcc = 1; - traceValue.phaseEnd = endPhase; - } - } else { - if (ct == 7) { - traceValue.limbConstructed = true; - Bytes tmp; - if (isList) { - tmp = bigIntegerToBytes(BigInteger.valueOf(INT_PREFIX_SHORT_LIST + length)); - } else { - tmp = bigIntegerToBytes(BigInteger.valueOf(INT_PREFIX_SHORT_INT + length)); - } - traceValue.limb = tmp; - traceValue.nBytes = 1; - traceValue.phaseEnd = endPhase; - } - } - traceRow(traceValue, trace); - } - } - - private void rlpInt( - int phase, - BigInteger input, - int nStep, - boolean lt, - boolean lx, - boolean isPrefix, - boolean endPhase, - boolean onlyPrefix, - RlpTxnColumnsValue traceValue, - Trace trace) { - - traceValue.partialReset(phase, nStep, lt, lx); - traceValue.isPrefix = isPrefix; - - Bytes inputByte = bigIntegerToBytes(input); - int inputSize = inputByte.size(); - ByteCountAndPowerOutput byteCountingOutput = byteCounting(inputSize, nStep); - - Bytes inputBytePadded = leftPadTo(inputByte, nStep); - BitDecOutput bitDecOutput = - bitDecomposition(0xff & inputBytePadded.get(inputBytePadded.size() - 1), nStep); - - traceValue.input1 = inputByte; - - for (int ct = 0; ct < nStep; ct++) { - traceValue.counter = ct; - traceValue.byte1 = inputBytePadded.get(ct); - traceValue.acc1 = inputBytePadded.slice(0, ct + 1); - traceValue.power = byteCountingOutput.powerList().get(ct); - traceValue.accByteSize = byteCountingOutput.accByteSizeList().get(ct); - traceValue.bit = bitDecOutput.bitDecList().get(ct); - traceValue.bitAcc = bitDecOutput.bitAccList().get(ct); - - if (input.compareTo(BigInteger.valueOf(128)) >= 0 && ct == nStep - 2) { - traceValue.limbConstructed = true; - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(INT_PREFIX_SHORT_INT + inputSize)); - traceValue.nBytes = 1; - } - - if (ct == nStep - 1) { - if (onlyPrefix) { - traceValue.lcCorrection = true; - traceValue.limbConstructed = false; - traceValue.limb = Bytes.ofUnsignedShort(0); - traceValue.nBytes = 0; - } else { - traceValue.limbConstructed = true; - traceValue.limb = inputByte; - traceValue.nBytes = inputSize; - traceValue.phaseEnd = endPhase; - } - } - traceRow(traceValue, trace); - } - } - - private void handle32BytesInteger( - RlpTxnColumnsValue traceValue, int phase, BigInteger input, Trace trace) { - traceValue.partialReset(phase, LLARGE, true, false); - if (input.equals(BigInteger.ZERO)) { - // Trivial case - traceZeroInt(traceValue, phase, true, false, false, true, trace); - } else { - // General case - Bytes inputByte = bigIntegerToBytes(input); - int inputLen = inputByte.size(); - Bytes inputByte32 = leftPadTo(inputByte, 32); - traceValue.input1 = inputByte32.slice(0, LLARGE); - traceValue.input2 = inputByte32.slice(LLARGE, LLARGE); - - ByteCountAndPowerOutput byteCounting; - if (inputLen <= traceValue.nStep) { - ByteCountAndPowerOutput byteCountingOutput = byteCounting(inputLen, traceValue.nStep); - BitDecOutput bitDecOutput = - bitDecomposition(inputByte.get(inputByte.size() - 1), traceValue.nStep); - - for (int ct = 0; ct < traceValue.nStep; ct++) { - traceValue.counter = ct; - traceValue.byte2 = traceValue.input2.get(ct); - traceValue.acc2 = traceValue.input2.slice(0, ct + 1); - traceValue.accByteSize = byteCountingOutput.accByteSizeList().get(ct); - traceValue.power = byteCountingOutput.powerList().get(ct); - traceValue.bit = bitDecOutput.bitDecList().get(ct); - traceValue.bitAcc = bitDecOutput.bitAccList().get(ct); - - // if input >= 128, there is a RLP prefix, nothing if 0 < input < 128 - if (ct == traceValue.nStep - 2 && input.compareTo(BigInteger.valueOf(128)) >= 0) { - traceValue.limbConstructed = true; - traceValue.limb = - bigIntegerToBytes(BigInteger.valueOf(INT_PREFIX_SHORT_INT + inputLen)); - traceValue.nBytes = 1; - } - if (ct == traceValue.nStep - 1) { - traceValue.limbConstructed = true; - traceValue.limb = traceValue.input2.slice(LLARGE - inputLen, inputLen); - traceValue.nBytes = inputLen; - traceValue.phaseEnd = true; - } - traceRow(traceValue, trace); - } - } else { - inputLen -= traceValue.nStep; - byteCounting = byteCounting(inputLen, traceValue.nStep); - - for (int ct = 0; ct < traceValue.nStep; ct++) { - traceValue.counter = ct; - traceValue.byte1 = traceValue.input1.get(ct); - traceValue.acc1 = traceValue.input1.slice(0, ct + 1); - traceValue.byte2 = traceValue.input2.get(ct); - traceValue.acc2 = traceValue.input2.slice(0, ct + 1); - traceValue.accByteSize = byteCounting.accByteSizeList().get(ct); - traceValue.power = byteCounting.powerList().get(ct); - - if (ct == traceValue.nStep - 3) { - traceValue.limbConstructed = true; - traceValue.limb = - bigIntegerToBytes(BigInteger.valueOf(INT_PREFIX_SHORT_INT + LLARGE + inputLen)); - traceValue.nBytes = 1; - } - if (ct == traceValue.nStep - 2) { - traceValue.limb = traceValue.input1.slice(LLARGE - inputLen, inputLen); - traceValue.nBytes = inputLen; - } - if (ct == traceValue.nStep - 1) { - traceValue.limb = traceValue.input2; - traceValue.nBytes = LLARGE; - traceValue.phaseEnd = true; - } - traceRow(traceValue, trace); - } - } - } - } - - private void handleAddress( - RlpTxnColumnsValue traceValue, int phase, Address address, Trace trace) { - boolean lt = true; - boolean lx = true; - traceValue.partialReset(phase, LLARGE, lt, lx); - traceValue.input1 = leftPadTo(address.slice(0, 4), LLARGE); - traceValue.input2 = address.slice(4, LLARGE); - - if (phase == 10) { - traceValue.depth1 = true; - } - - for (int ct = 0; ct < traceValue.nStep; ct++) { - traceValue.counter = ct; - traceValue.byte1 = traceValue.input1.get(ct); - traceValue.acc1 = traceValue.input1.slice(0, ct + 1); - traceValue.byte2 = traceValue.input2.get(ct); - traceValue.acc2 = traceValue.input2.slice(0, ct + 1); - - if (ct == traceValue.nStep - 3) { - traceValue.limbConstructed = true; - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(INT_PREFIX_SHORT_INT + 20)); - traceValue.nBytes = 1; - } - - if (ct == traceValue.nStep - 2) { - traceValue.limb = address.slice(0, 4); - traceValue.nBytes = 4; - } - if (ct == traceValue.nStep - 1) { - traceValue.limb = traceValue.input2; - traceValue.nBytes = LLARGE; - - if (phase == 7) { - traceValue.phaseEnd = true; - } - } - traceRow(traceValue, trace); - } - } - - private void handleStorageKey( - RlpTxnColumnsValue traceValue, boolean end_phase, Bytes32 storage_key, Trace trace) { - traceValue.partialReset(10, LLARGE, true, true); - traceValue.depth1 = true; - traceValue.depth2 = true; - traceValue.input1 = storage_key.slice(0, LLARGE); - traceValue.input2 = storage_key.slice(LLARGE, LLARGE); - - for (int ct = 0; ct < traceValue.nStep; ct++) { - traceValue.counter = ct; - traceValue.byte1 = traceValue.input1.get(ct); - traceValue.acc1 = traceValue.input1.slice(0, ct + 1); - traceValue.byte2 = traceValue.input2.get(ct); - traceValue.acc2 = traceValue.input2.slice(0, ct + 1); - - if (ct == traceValue.nStep - 3) { - traceValue.limbConstructed = true; - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(INT_PREFIX_SHORT_INT + 32)); - traceValue.nBytes = 1; - } - - if (ct == traceValue.nStep - 2) { - traceValue.limb = traceValue.input1; - traceValue.nBytes = LLARGE; - } - - if (ct == traceValue.nStep - 1) { - traceValue.limb = traceValue.input2; - traceValue.phaseEnd = end_phase; - } - - traceRow(traceValue, trace); - } - } - - private static Bytes frontierPreimage( - final long nonce, - final Wei gasPrice, - final long gasLimit, - final Optional

to, - final Wei value, - final Bytes payload, - final Optional chainId) { - return RLP.encode( - rlpOutput -> { - rlpOutput.startList(); - rlpOutput.writeLongScalar(nonce); - rlpOutput.writeUInt256Scalar(gasPrice); - rlpOutput.writeLongScalar(gasLimit); - rlpOutput.writeBytes(to.map(Bytes::copy).orElse(Bytes.EMPTY)); - rlpOutput.writeUInt256Scalar(value); - rlpOutput.writeBytes(payload); - if (chainId.isPresent()) { - rlpOutput.writeBigIntegerScalar(chainId.orElseThrow()); - rlpOutput.writeUInt256Scalar(UInt256.ZERO); - rlpOutput.writeUInt256Scalar(UInt256.ZERO); - } - rlpOutput.endList(); - }); - } - - private static Bytes accessListPreimage( - final long nonce, - final Wei gasPrice, - final long gasLimit, - final Optional
to, - final Wei value, - final Bytes payload, - final List accessList, - final Optional chainId) { - final Bytes encode = - RLP.encode( - rlpOutput -> { - rlpOutput.startList(); - AccessListTransactionEncoder.encodeAccessListInner( - chainId, nonce, gasPrice, gasLimit, to, value, payload, accessList, rlpOutput); - rlpOutput.endList(); - }); - return Bytes.concatenate(Bytes.of(TransactionType.ACCESS_LIST.getSerializedType()), encode); - } - - private static Bytes eip1559Preimage( - final long nonce, - final Wei maxPriorityFeePerGas, - final Wei maxFeePerGas, - final long gasLimit, - final Optional
to, - final Wei value, - final Bytes payload, - final Optional chainId, - final Optional> accessList) { - final Bytes encoded = - RLP.encode( - rlpOutput -> { - rlpOutput.startList(); - eip1559PreimageFields( - nonce, - maxPriorityFeePerGas, - maxFeePerGas, - gasLimit, - to, - value, - payload, - chainId, - accessList, - rlpOutput); - rlpOutput.endList(); - }); - return Bytes.concatenate(Bytes.of(TransactionType.EIP1559.getSerializedType()), encoded); - } - - private static void eip1559PreimageFields( - final long nonce, - final Wei maxPriorityFeePerGas, - final Wei maxFeePerGas, - final long gasLimit, - final Optional
to, - final Wei value, - final Bytes payload, - final Optional chainId, - final Optional> accessList, - final RLPOutput rlpOutput) { - rlpOutput.writeBigIntegerScalar(chainId.orElseThrow()); - rlpOutput.writeLongScalar(nonce); - rlpOutput.writeUInt256Scalar(maxPriorityFeePerGas); - rlpOutput.writeUInt256Scalar(maxFeePerGas); - rlpOutput.writeLongScalar(gasLimit); - rlpOutput.writeBytes(to.map(Bytes::copy).orElse(Bytes.EMPTY)); - rlpOutput.writeUInt256Scalar(value); - rlpOutput.writeBytes(payload); - AccessListTransactionEncoder.writeAccessList(rlpOutput, accessList); - } - - private void traceZeroInt( - RlpTxnColumnsValue traceValue, - int phase, - boolean lt, - boolean lx, - boolean isPrefix, - boolean phaseEnd, - Trace trace) { - traceValue.partialReset(phase, 1, lt, lx); - traceValue.limbConstructed = true; - traceValue.limb = BYTES_PREFIX_SHORT_INT; - traceValue.nBytes = 1; - traceValue.isPrefix = true; - traceValue.phaseEnd = phaseEnd; - traceRow(traceValue, trace); - } - - private void traceVoidList( - RlpTxnColumnsValue traceValue, - int phase, - boolean lt, - boolean lx, - boolean isPrefix, - boolean depth1, - boolean depth2, - boolean phaseEnd, - Trace trace) { - traceValue.partialReset(phase, 1, lt, lx); - traceValue.limbConstructed = true; - traceValue.limb = BYTES_PREFIX_SHORT_LIST; - traceValue.nBytes = 1; - traceValue.isPrefix = isPrefix; - traceValue.depth1 = depth1; - traceValue.depth2 = depth2; - traceValue.phaseEnd = phaseEnd; - traceRow(traceValue, trace); - } - // Define the Tracer - private void traceRow(RlpTxnColumnsValue traceValue, Trace builder) { - // Decrements RLP_BYTESIZE - if (traceValue.phase != 0) { - if (traceValue.limbConstructed && traceValue.lt) { - traceValue.rlpLtByteSize -= traceValue.nBytes; - } - if (traceValue.limbConstructed && traceValue.lx) { - traceValue.rlpLxByteSize -= traceValue.nBytes; - } - } - - // Decrement phaseByteSize and accessTupleByteSize for Phase 10 (AccessList) - if (traceValue.phase == 10) { - // Decreases PhaseByteSize - if (traceValue.depth1 && traceValue.limbConstructed) { - traceValue.phaseByteSize -= traceValue.nBytes; - } - // Decreases AccessTupleSize - if (traceValue.depth1 - && !(traceValue.isPrefix && !traceValue.depth2) - && traceValue.limbConstructed) { - traceValue.accessTupleByteSize -= traceValue.nBytes; - } - } - - builder - .absTxNum(Bytes.ofUnsignedInt(traceValue.absTxNum)) - .absTxNumInfiny(Bytes.ofUnsignedInt(this.chunkList.size())) - .acc1(traceValue.acc1) - .acc2(traceValue.acc2) - .accBytesize(Bytes.ofUnsignedInt(traceValue.accByteSize)) - .accessTupleBytesize(Bytes.ofUnsignedInt(traceValue.accessTupleByteSize)) - .addrHi(traceValue.addrHi) - .addrLo(traceValue.addrLo) - .bit(traceValue.bit) - .bitAcc(Bytes.ofUnsignedInt(traceValue.bitAcc)) - .byte1(UnsignedByte.of(traceValue.byte1)) - .byte2(UnsignedByte.of(traceValue.byte2)) - .codeFragmentIndex(Bytes.ofUnsignedInt(traceValue.codeFragmentIndex)) - .counter(Bytes.ofUnsignedInt(traceValue.counter)) - .dataHi(bigIntegerToBytes(traceValue.dataHi)) - .dataLo(bigIntegerToBytes(traceValue.dataLo)) - .datagascost(Bytes.ofUnsignedInt(traceValue.dataGasCost)) - .depth1(traceValue.depth1) - .depth2(traceValue.depth2); - if (traceValue.counter == traceValue.nStep - 1) { - builder.done(Boolean.TRUE); - } else { - builder.done(Boolean.FALSE); - } - builder - .phaseEnd(traceValue.phaseEnd) - .indexData(Bytes.ofUnsignedInt(traceValue.indexData)) - .indexLt(Bytes.ofUnsignedInt(traceValue.indexLt)) - .indexLx(Bytes.ofUnsignedInt(traceValue.indexLx)) - .input1(traceValue.input1) - .input2(traceValue.input2) - .lcCorrection(traceValue.lcCorrection) - .isPrefix(traceValue.isPrefix) - .limb(rightPadTo(traceValue.limb, LLARGE)) - .limbConstructed(traceValue.limbConstructed) - .lt(traceValue.lt) - .lx(traceValue.lx) - .nBytes(Bytes.ofUnsignedInt(traceValue.nBytes)) - .nAddr(Bytes.ofUnsignedInt(traceValue.nbAddr)) - .nKeys(Bytes.ofUnsignedInt(traceValue.nbSto)) - .nKeysPerAddr(Bytes.ofUnsignedInt(traceValue.nbStoPerAddr)) - .nStep(Bytes.ofUnsignedInt(traceValue.nStep)); - List> phaseColumns = - List.of( - builder::phase0, - builder::phase1, - builder::phase2, - builder::phase3, - builder::phase4, - builder::phase5, - builder::phase6, - builder::phase7, - builder::phase8, - builder::phase9, - builder::phase10, - builder::phase11, - builder::phase12, - builder::phase13, - builder::phase14); - for (int i = 0; i < phaseColumns.size(); i++) { - phaseColumns.get(i).apply(i == traceValue.phase); - } - builder - .phaseSize(Bytes.ofUnsignedInt(traceValue.phaseByteSize)) - .power(bigIntegerToBytes(traceValue.power)) - .requiresEvmExecution(traceValue.requiresEvmExecution) - .rlpLtBytesize(Bytes.ofUnsignedInt(traceValue.rlpLtByteSize)) - .rlpLxBytesize(Bytes.ofUnsignedInt(traceValue.rlpLxByteSize)) - .type(Bytes.ofUnsignedInt(traceValue.txType)); - - // Increments Index - if (traceValue.limbConstructed && traceValue.lt) { - traceValue.indexLt += 1; - } - if (traceValue.limbConstructed && traceValue.lx) { - traceValue.indexLx += 1; - } - - // Increments IndexData (Phase 9) - if (traceValue.phase == 9 - && !traceValue.isPrefix - && (traceValue.limbConstructed || traceValue.lcCorrection)) { - traceValue.indexData += 1; - } - - // Decrements PhaseByteSize and DataGasCost in Data phase (phase 9) - if (traceValue.phase == 9) { - if (traceValue.phaseByteSize != 0 && !traceValue.isPrefix) { - traceValue.phaseByteSize -= 1; - if (traceValue.byte1 == 0) { - traceValue.dataGasCost -= TxnrlpTrace.G_txdatazero.intValue(); - } else { - traceValue.dataGasCost -= TxnrlpTrace.G_txdatanonzero.intValue(); - } - } - } - if (traceValue.phaseEnd) { - traceValue.resetDataHiLo(); - } - builder.validateRow(); - - // reconstruct RLPs - if (traceValue.limbConstructed && traceValue.lt) { - this.reconstructedRlpLt = - Bytes.concatenate(this.reconstructedRlpLt, traceValue.limb.slice(0, traceValue.nBytes)); - } - if (traceValue.limbConstructed && traceValue.lx) { - this.reconstructedRlpLx = - Bytes.concatenate(this.reconstructedRlpLx, traceValue.limb.slice(0, traceValue.nBytes)); - } - } - - @Override - public int lineCount() { - return this.chunkList.lineCount(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - int absTxNum = 0; - for (RlpTxnChunk chunk : this.chunkList) { - absTxNum += 1; - final int codeFragmentIndex = chunk.id().map(romLex::getCFIById).orElse(0); - traceChunk(chunk, absTxNum, codeFragmentIndex, trace); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxnChunk.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxnChunk.java deleted file mode 100644 index 668f99dbf..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxnChunk.java +++ /dev/null @@ -1,171 +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.rlp.txn; - -import static net.consensys.linea.zktracer.module.Util.getTxTypeAsInt; -import static net.consensys.linea.zktracer.module.rlp.txn.RlpTxn.LLARGE; - -import java.math.BigInteger; -import java.util.Optional; - -import lombok.Getter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.container.ModuleOperation; -import org.hyperledger.besu.datatypes.Transaction; - -@Accessors(fluent = true) -@Getter -public final class RlpTxnChunk extends ModuleOperation { - private final Transaction tx; - private final boolean requireEvmExecution; - private final Optional id; - - public RlpTxnChunk(Transaction tx, boolean requireEvmExecution, Optional id) { - this.tx = tx; - this.requireEvmExecution = requireEvmExecution; - this.id = id; - } - - public RlpTxnChunk(Transaction tx, boolean requireEvmExecution) { - this(tx, requireEvmExecution, Optional.empty()); - } - - public RlpTxnChunk(Transaction tx, boolean requireEvmExecution, int codeIdentifierPreLexOrder) { - this(tx, requireEvmExecution, Optional.of(codeIdentifierPreLexOrder)); - } - - @Override - protected int computeLineCount() { - final int txType = getTxTypeAsInt(this.tx.getType()); - // Phase 0 is always 17 rows long - int rowSize = 17; - - // Phase 1: chainID - if (txType == 1 || txType == 2) { - if (this.tx.getChainId().orElseThrow().equals(BigInteger.ZERO)) { - rowSize += 1; - } else { - rowSize += 8; - } - } - - // Phase 2: nonce - if (this.tx.getNonce() == 0) { - rowSize += 1; - } else { - rowSize += 8; - } - - // Phase 3: gasPrice - if (txType == 0 || txType == 1) { - rowSize += 8; - } - - // Phase 4: MaxPriorityFeeperGas - if (txType == 2) { - if (this.tx - .getMaxPriorityFeePerGas() - .orElseThrow() - .getAsBigInteger() - .equals(BigInteger.ZERO)) { - rowSize += 1; - } else { - rowSize += 8; - } - } - - // Phase 5: MaxFeePerGas - if (txType == 2) { - if (this.tx.getMaxFeePerGas().orElseThrow().getAsBigInteger().equals(BigInteger.ZERO)) { - rowSize += 1; - } else { - rowSize += 8; - } - } - - // Phase 6: GasLimit - rowSize += 8; - - // Phase 7: To - if (this.tx.getTo().isPresent()) { - rowSize += 16; - } else { - rowSize += 1; - } - - // Phase 8: Value - if (this.tx.getValue().getAsBigInteger().equals(BigInteger.ZERO)) { - rowSize += 1; - } else { - rowSize += 16; - } - - // Phase 9: Data - if (this.tx.getPayload().isEmpty()) { - rowSize += 2; // 1 for prefix + 1 for padding - } else { - int dataSize = this.tx.getPayload().size(); - rowSize += 8 + LLARGE * ((dataSize - 1) / LLARGE + 1); - rowSize += 2; // 2 lines of padding - } - - // Phase 10: AccessList - if (txType == 1 || txType == 2) { - if (this.tx.getAccessList().isEmpty() || this.tx.getAccessList().get().isEmpty()) { - rowSize += 1; - } else { - // Rlp prefix of the AccessList list - rowSize += 8; - for (int i = 0; i < this.tx.getAccessList().orElseThrow().size(); i++) { - rowSize += 8 + 16; - if (this.tx.getAccessList().orElseThrow().get(i).storageKeys().isEmpty()) { - rowSize += 1; - } else { - rowSize += 8 + 16 * this.tx.getAccessList().orElseThrow().get(i).storageKeys().size(); - } - } - } - } - - // Phase 11: beta - if (txType == 0) { - rowSize += 8; - if (this.tx.getV().compareTo(BigInteger.valueOf(28)) > 0) { - rowSize += 9; - } - } - - // Phase 12: y - if (txType == 1 || txType == 2) { - rowSize += 1; - } - - // Phase 13: r - if (this.tx.getR().equals(BigInteger.ZERO)) { - rowSize += 1; - } else { - rowSize += 16; - } - - // Phase 14: s - if (this.tx.getS().equals(BigInteger.ZERO)) { - rowSize += 1; - } else { - rowSize += 16; - } - return rowSize; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxnColumnsValue.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxnColumnsValue.java deleted file mode 100644 index ce1ab401e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/RlpTxnColumnsValue.java +++ /dev/null @@ -1,98 +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.rlp.txn; - -import java.math.BigInteger; - -import org.apache.tuweni.bytes.Bytes; - -class RlpTxnColumnsValue { - Bytes acc1; - Bytes acc2; - int accByteSize; - int accessTupleByteSize; - Bytes addrHi; - Bytes addrLo; - boolean bit; - int bitAcc; - byte byte1; - byte byte2; - int counter; - BigInteger dataHi; - BigInteger dataLo; - int dataGasCost; - boolean depth1; - boolean depth2; - boolean phaseEnd; - int indexData; - int indexLt; - int indexLx; - Bytes input1; - Bytes input2; - boolean lcCorrection; - boolean isPrefix; - Bytes limb; - boolean limbConstructed; - boolean lt; - boolean lx; - int nBytes; - int nbAddr; - int nbSto; - int nbStoPerAddr; - int nStep; - int phase; - int phaseByteSize; - BigInteger power; - int rlpLtByteSize; - int rlpLxByteSize; - boolean requiresEvmExecution; - int absTxNum; - int codeFragmentIndex; - int txType; - - void partialReset(int phase, int numberStep, boolean lt, boolean lx) { - this.phase = phase; - this.nStep = numberStep; - this.lt = lt; - this.lx = lx; - - // Set to default local values - this.limbConstructed = false; - this.acc1 = Bytes.of(0); - this.acc2 = Bytes.of(0); - this.accByteSize = 0; - this.bit = false; - this.bitAcc = 0; - this.byte1 = 0; - this.byte2 = 0; - this.counter = 0; - this.depth1 = false; - this.depth2 = false; - this.phaseEnd = false; - this.input1 = Bytes.of(0); - this.input2 = Bytes.of(0); - this.lcCorrection = false; - this.isPrefix = false; - this.limb = Bytes.of(0); - this.nBytes = 0; - this.power = BigInteger.ZERO; - } - - void resetDataHiLo() { - this.dataHi = BigInteger.ZERO; - this.dataLo = BigInteger.ZERO; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/Trace.java deleted file mode 100644 index b62296763..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/Trace.java +++ /dev/null @@ -1,1546 +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.rlp.txn; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - static final int CREATE2_SHIFT = 255; - static final int G_TXDATA_NONZERO = 16; - static final int G_TXDATA_ZERO = 4; - static final int INT_LONG = 183; - static final int INT_SHORT = 128; - static final int LIST_LONG = 247; - static final int LIST_SHORT = 192; - static final int LLARGE = 16; - static final int LLARGEMO = 15; - static final int RLPADDR_CONST_RECIPE_1 = 1; - static final int RLPADDR_CONST_RECIPE_2 = 2; - static final int RLPRECEIPT_SUBPHASE_ID_ADDR = 53; - static final int RLPRECEIPT_SUBPHASE_ID_CUMUL_GAS = 3; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_LIMB = 77; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_SIZE = 83; - static final int RLPRECEIPT_SUBPHASE_ID_NO_LOG_ENTRY = 11; - static final int RLPRECEIPT_SUBPHASE_ID_STATUS_CODE = 2; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE = 65; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA = 96; - static final int RLPRECEIPT_SUBPHASE_ID_TYPE = 7; - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer absTxNum; - private final MappedByteBuffer absTxNumInfiny; - private final MappedByteBuffer acc1; - private final MappedByteBuffer acc2; - private final MappedByteBuffer accBytesize; - private final MappedByteBuffer accessTupleBytesize; - private final MappedByteBuffer addrHi; - private final MappedByteBuffer addrLo; - private final MappedByteBuffer bit; - private final MappedByteBuffer bitAcc; - private final MappedByteBuffer byte1; - private final MappedByteBuffer byte2; - private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer counter; - private final MappedByteBuffer dataHi; - private final MappedByteBuffer dataLo; - private final MappedByteBuffer datagascost; - private final MappedByteBuffer depth1; - private final MappedByteBuffer depth2; - private final MappedByteBuffer done; - private final MappedByteBuffer indexData; - private final MappedByteBuffer indexLt; - private final MappedByteBuffer indexLx; - private final MappedByteBuffer input1; - private final MappedByteBuffer input2; - private final MappedByteBuffer isPrefix; - private final MappedByteBuffer lcCorrection; - private final MappedByteBuffer limb; - private final MappedByteBuffer limbConstructed; - private final MappedByteBuffer lt; - private final MappedByteBuffer lx; - private final MappedByteBuffer nAddr; - private final MappedByteBuffer nBytes; - private final MappedByteBuffer nKeys; - private final MappedByteBuffer nKeysPerAddr; - private final MappedByteBuffer nStep; - private final MappedByteBuffer phase0; - private final MappedByteBuffer phase1; - private final MappedByteBuffer phase10; - private final MappedByteBuffer phase11; - private final MappedByteBuffer phase12; - private final MappedByteBuffer phase13; - private final MappedByteBuffer phase14; - private final MappedByteBuffer phase2; - private final MappedByteBuffer phase3; - private final MappedByteBuffer phase4; - private final MappedByteBuffer phase5; - private final MappedByteBuffer phase6; - private final MappedByteBuffer phase7; - private final MappedByteBuffer phase8; - private final MappedByteBuffer phase9; - private final MappedByteBuffer phaseEnd; - private final MappedByteBuffer phaseSize; - private final MappedByteBuffer power; - private final MappedByteBuffer requiresEvmExecution; - private final MappedByteBuffer rlpLtBytesize; - private final MappedByteBuffer rlpLxBytesize; - private final MappedByteBuffer type; - - static List headers(int length) { - return List.of( - new ColumnHeader("rlpTxn.ABS_TX_NUM", 32, length), - new ColumnHeader("rlpTxn.ABS_TX_NUM_INFINY", 32, length), - new ColumnHeader("rlpTxn.ACC_1", 32, length), - new ColumnHeader("rlpTxn.ACC_2", 32, length), - new ColumnHeader("rlpTxn.ACC_BYTESIZE", 32, length), - new ColumnHeader("rlpTxn.ACCESS_TUPLE_BYTESIZE", 32, length), - new ColumnHeader("rlpTxn.ADDR_HI", 32, length), - new ColumnHeader("rlpTxn.ADDR_LO", 32, length), - new ColumnHeader("rlpTxn.BIT", 1, length), - new ColumnHeader("rlpTxn.BIT_ACC", 32, length), - new ColumnHeader("rlpTxn.BYTE_1", 1, length), - new ColumnHeader("rlpTxn.BYTE_2", 1, length), - new ColumnHeader("rlpTxn.CODE_FRAGMENT_INDEX", 32, length), - new ColumnHeader("rlpTxn.COUNTER", 32, length), - new ColumnHeader("rlpTxn.DATA_HI", 32, length), - new ColumnHeader("rlpTxn.DATA_LO", 32, length), - new ColumnHeader("rlpTxn.DATAGASCOST", 32, length), - new ColumnHeader("rlpTxn.DEPTH_1", 1, length), - new ColumnHeader("rlpTxn.DEPTH_2", 1, length), - new ColumnHeader("rlpTxn.DONE", 1, length), - new ColumnHeader("rlpTxn.INDEX_DATA", 32, length), - new ColumnHeader("rlpTxn.INDEX_LT", 32, length), - new ColumnHeader("rlpTxn.INDEX_LX", 32, length), - new ColumnHeader("rlpTxn.INPUT_1", 32, length), - new ColumnHeader("rlpTxn.INPUT_2", 32, length), - new ColumnHeader("rlpTxn.IS_PREFIX", 1, length), - new ColumnHeader("rlpTxn.LC_CORRECTION", 1, length), - new ColumnHeader("rlpTxn.LIMB", 32, length), - new ColumnHeader("rlpTxn.LIMB_CONSTRUCTED", 1, length), - new ColumnHeader("rlpTxn.LT", 1, length), - new ColumnHeader("rlpTxn.LX", 1, length), - new ColumnHeader("rlpTxn.nADDR", 32, length), - new ColumnHeader("rlpTxn.nBYTES", 32, length), - new ColumnHeader("rlpTxn.nKEYS", 32, length), - new ColumnHeader("rlpTxn.nKEYS_PER_ADDR", 32, length), - new ColumnHeader("rlpTxn.nSTEP", 32, length), - new ColumnHeader("rlpTxn.PHASE_0", 1, length), - new ColumnHeader("rlpTxn.PHASE_1", 1, length), - new ColumnHeader("rlpTxn.PHASE_10", 1, length), - new ColumnHeader("rlpTxn.PHASE_11", 1, length), - new ColumnHeader("rlpTxn.PHASE_12", 1, length), - new ColumnHeader("rlpTxn.PHASE_13", 1, length), - new ColumnHeader("rlpTxn.PHASE_14", 1, length), - new ColumnHeader("rlpTxn.PHASE_2", 1, length), - new ColumnHeader("rlpTxn.PHASE_3", 1, length), - new ColumnHeader("rlpTxn.PHASE_4", 1, length), - new ColumnHeader("rlpTxn.PHASE_5", 1, length), - new ColumnHeader("rlpTxn.PHASE_6", 1, length), - new ColumnHeader("rlpTxn.PHASE_7", 1, length), - new ColumnHeader("rlpTxn.PHASE_8", 1, length), - new ColumnHeader("rlpTxn.PHASE_9", 1, length), - new ColumnHeader("rlpTxn.PHASE_END", 1, length), - new ColumnHeader("rlpTxn.PHASE_SIZE", 32, length), - new ColumnHeader("rlpTxn.POWER", 32, length), - new ColumnHeader("rlpTxn.REQUIRES_EVM_EXECUTION", 1, length), - new ColumnHeader("rlpTxn.RLP_LT_BYTESIZE", 32, length), - new ColumnHeader("rlpTxn.RLP_LX_BYTESIZE", 32, length), - new ColumnHeader("rlpTxn.TYPE", 32, length)); - } - - public Trace(List buffers) { - this.absTxNum = buffers.get(0); - this.absTxNumInfiny = buffers.get(1); - this.acc1 = buffers.get(2); - this.acc2 = buffers.get(3); - this.accBytesize = buffers.get(4); - this.accessTupleBytesize = buffers.get(5); - this.addrHi = buffers.get(6); - this.addrLo = buffers.get(7); - this.bit = buffers.get(8); - this.bitAcc = buffers.get(9); - this.byte1 = buffers.get(10); - this.byte2 = buffers.get(11); - this.codeFragmentIndex = buffers.get(12); - this.counter = buffers.get(13); - this.dataHi = buffers.get(14); - this.dataLo = buffers.get(15); - this.datagascost = buffers.get(16); - this.depth1 = buffers.get(17); - this.depth2 = buffers.get(18); - this.done = buffers.get(19); - this.indexData = buffers.get(20); - this.indexLt = buffers.get(21); - this.indexLx = buffers.get(22); - this.input1 = buffers.get(23); - this.input2 = buffers.get(24); - this.isPrefix = buffers.get(25); - this.lcCorrection = buffers.get(26); - this.limb = buffers.get(27); - this.limbConstructed = buffers.get(28); - this.lt = buffers.get(29); - this.lx = buffers.get(30); - this.nAddr = buffers.get(31); - this.nBytes = buffers.get(32); - this.nKeys = buffers.get(33); - this.nKeysPerAddr = buffers.get(34); - this.nStep = buffers.get(35); - this.phase0 = buffers.get(36); - this.phase1 = buffers.get(37); - this.phase10 = buffers.get(38); - this.phase11 = buffers.get(39); - this.phase12 = buffers.get(40); - this.phase13 = buffers.get(41); - this.phase14 = buffers.get(42); - this.phase2 = buffers.get(43); - this.phase3 = buffers.get(44); - this.phase4 = buffers.get(45); - this.phase5 = buffers.get(46); - this.phase6 = buffers.get(47); - this.phase7 = buffers.get(48); - this.phase8 = buffers.get(49); - this.phase9 = buffers.get(50); - this.phaseEnd = buffers.get(51); - this.phaseSize = buffers.get(52); - this.power = buffers.get(53); - this.requiresEvmExecution = buffers.get(54); - this.rlpLtBytesize = buffers.get(55); - this.rlpLxBytesize = buffers.get(56); - this.type = buffers.get(57); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace absTxNum(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("rlpTxn.ABS_TX_NUM already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - absTxNum.put((byte) 0); - } - absTxNum.put(b.toArrayUnsafe()); - - return this; - } - - public Trace absTxNumInfiny(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("rlpTxn.ABS_TX_NUM_INFINY already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - absTxNumInfiny.put((byte) 0); - } - absTxNumInfiny.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc1(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("rlpTxn.ACC_1 already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc1.put((byte) 0); - } - acc1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc2(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("rlpTxn.ACC_2 already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc2.put((byte) 0); - } - acc2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accBytesize(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("rlpTxn.ACC_BYTESIZE already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accBytesize.put((byte) 0); - } - accBytesize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accessTupleBytesize(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("rlpTxn.ACCESS_TUPLE_BYTESIZE already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accessTupleBytesize.put((byte) 0); - } - accessTupleBytesize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace addrHi(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("rlpTxn.ADDR_HI already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrHi.put((byte) 0); - } - addrHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace addrLo(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("rlpTxn.ADDR_LO already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrLo.put((byte) 0); - } - addrLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace bit(final Boolean b) { - if (filled.get(8)) { - throw new IllegalStateException("rlpTxn.BIT already set"); - } else { - filled.set(8); - } - - bit.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bitAcc(final Bytes b) { - if (filled.get(9)) { - throw new IllegalStateException("rlpTxn.BIT_ACC already set"); - } else { - filled.set(9); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - bitAcc.put((byte) 0); - } - bitAcc.put(b.toArrayUnsafe()); - - return this; - } - - public Trace byte1(final UnsignedByte b) { - if (filled.get(10)) { - throw new IllegalStateException("rlpTxn.BYTE_1 already set"); - } else { - filled.set(10); - } - - byte1.put(b.toByte()); - - return this; - } - - public Trace byte2(final UnsignedByte b) { - if (filled.get(11)) { - throw new IllegalStateException("rlpTxn.BYTE_2 already set"); - } else { - filled.set(11); - } - - byte2.put(b.toByte()); - - return this; - } - - public Trace codeFragmentIndex(final Bytes b) { - if (filled.get(12)) { - throw new IllegalStateException("rlpTxn.CODE_FRAGMENT_INDEX already set"); - } else { - filled.set(12); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeFragmentIndex.put((byte) 0); - } - codeFragmentIndex.put(b.toArrayUnsafe()); - - return this; - } - - public Trace counter(final Bytes b) { - if (filled.get(13)) { - throw new IllegalStateException("rlpTxn.COUNTER already set"); - } else { - filled.set(13); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - counter.put((byte) 0); - } - counter.put(b.toArrayUnsafe()); - - return this; - } - - public Trace dataHi(final Bytes b) { - if (filled.get(15)) { - throw new IllegalStateException("rlpTxn.DATA_HI already set"); - } else { - filled.set(15); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - dataHi.put((byte) 0); - } - dataHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace dataLo(final Bytes b) { - if (filled.get(16)) { - throw new IllegalStateException("rlpTxn.DATA_LO already set"); - } else { - filled.set(16); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - dataLo.put((byte) 0); - } - dataLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace datagascost(final Bytes b) { - if (filled.get(14)) { - throw new IllegalStateException("rlpTxn.DATAGASCOST already set"); - } else { - filled.set(14); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - datagascost.put((byte) 0); - } - datagascost.put(b.toArrayUnsafe()); - - return this; - } - - public Trace depth1(final Boolean b) { - if (filled.get(17)) { - throw new IllegalStateException("rlpTxn.DEPTH_1 already set"); - } else { - filled.set(17); - } - - depth1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace depth2(final Boolean b) { - if (filled.get(18)) { - throw new IllegalStateException("rlpTxn.DEPTH_2 already set"); - } else { - filled.set(18); - } - - depth2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace done(final Boolean b) { - if (filled.get(19)) { - throw new IllegalStateException("rlpTxn.DONE already set"); - } else { - filled.set(19); - } - - done.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace indexData(final Bytes b) { - if (filled.get(20)) { - throw new IllegalStateException("rlpTxn.INDEX_DATA already set"); - } else { - filled.set(20); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - indexData.put((byte) 0); - } - indexData.put(b.toArrayUnsafe()); - - return this; - } - - public Trace indexLt(final Bytes b) { - if (filled.get(21)) { - throw new IllegalStateException("rlpTxn.INDEX_LT already set"); - } else { - filled.set(21); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - indexLt.put((byte) 0); - } - indexLt.put(b.toArrayUnsafe()); - - return this; - } - - public Trace indexLx(final Bytes b) { - if (filled.get(22)) { - throw new IllegalStateException("rlpTxn.INDEX_LX already set"); - } else { - filled.set(22); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - indexLx.put((byte) 0); - } - indexLx.put(b.toArrayUnsafe()); - - return this; - } - - public Trace input1(final Bytes b) { - if (filled.get(23)) { - throw new IllegalStateException("rlpTxn.INPUT_1 already set"); - } else { - filled.set(23); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - input1.put((byte) 0); - } - input1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace input2(final Bytes b) { - if (filled.get(24)) { - throw new IllegalStateException("rlpTxn.INPUT_2 already set"); - } else { - filled.set(24); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - input2.put((byte) 0); - } - input2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace isPrefix(final Boolean b) { - if (filled.get(25)) { - throw new IllegalStateException("rlpTxn.IS_PREFIX already set"); - } else { - filled.set(25); - } - - isPrefix.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace lcCorrection(final Boolean b) { - if (filled.get(26)) { - throw new IllegalStateException("rlpTxn.LC_CORRECTION already set"); - } else { - filled.set(26); - } - - lcCorrection.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace limb(final Bytes b) { - if (filled.get(27)) { - throw new IllegalStateException("rlpTxn.LIMB already set"); - } else { - filled.set(27); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - limb.put((byte) 0); - } - limb.put(b.toArrayUnsafe()); - - return this; - } - - public Trace limbConstructed(final Boolean b) { - if (filled.get(28)) { - throw new IllegalStateException("rlpTxn.LIMB_CONSTRUCTED already set"); - } else { - filled.set(28); - } - - limbConstructed.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace lt(final Boolean b) { - if (filled.get(29)) { - throw new IllegalStateException("rlpTxn.LT already set"); - } else { - filled.set(29); - } - - lt.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace lx(final Boolean b) { - if (filled.get(30)) { - throw new IllegalStateException("rlpTxn.LX already set"); - } else { - filled.set(30); - } - - lx.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace nAddr(final Bytes b) { - if (filled.get(53)) { - throw new IllegalStateException("rlpTxn.nADDR already set"); - } else { - filled.set(53); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nAddr.put((byte) 0); - } - nAddr.put(b.toArrayUnsafe()); - - return this; - } - - public Trace nBytes(final Bytes b) { - if (filled.get(54)) { - throw new IllegalStateException("rlpTxn.nBYTES already set"); - } else { - filled.set(54); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nBytes.put((byte) 0); - } - nBytes.put(b.toArrayUnsafe()); - - return this; - } - - public Trace nKeys(final Bytes b) { - if (filled.get(55)) { - throw new IllegalStateException("rlpTxn.nKEYS already set"); - } else { - filled.set(55); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nKeys.put((byte) 0); - } - nKeys.put(b.toArrayUnsafe()); - - return this; - } - - public Trace nKeysPerAddr(final Bytes b) { - if (filled.get(56)) { - throw new IllegalStateException("rlpTxn.nKEYS_PER_ADDR already set"); - } else { - filled.set(56); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nKeysPerAddr.put((byte) 0); - } - nKeysPerAddr.put(b.toArrayUnsafe()); - - return this; - } - - public Trace nStep(final Bytes b) { - if (filled.get(57)) { - throw new IllegalStateException("rlpTxn.nSTEP already set"); - } else { - filled.set(57); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nStep.put((byte) 0); - } - nStep.put(b.toArrayUnsafe()); - - return this; - } - - public Trace phase0(final Boolean b) { - if (filled.get(31)) { - throw new IllegalStateException("rlpTxn.PHASE_0 already set"); - } else { - filled.set(31); - } - - phase0.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase1(final Boolean b) { - if (filled.get(32)) { - throw new IllegalStateException("rlpTxn.PHASE_1 already set"); - } else { - filled.set(32); - } - - phase1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase10(final Boolean b) { - if (filled.get(33)) { - throw new IllegalStateException("rlpTxn.PHASE_10 already set"); - } else { - filled.set(33); - } - - phase10.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase11(final Boolean b) { - if (filled.get(34)) { - throw new IllegalStateException("rlpTxn.PHASE_11 already set"); - } else { - filled.set(34); - } - - phase11.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase12(final Boolean b) { - if (filled.get(35)) { - throw new IllegalStateException("rlpTxn.PHASE_12 already set"); - } else { - filled.set(35); - } - - phase12.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase13(final Boolean b) { - if (filled.get(36)) { - throw new IllegalStateException("rlpTxn.PHASE_13 already set"); - } else { - filled.set(36); - } - - phase13.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase14(final Boolean b) { - if (filled.get(37)) { - throw new IllegalStateException("rlpTxn.PHASE_14 already set"); - } else { - filled.set(37); - } - - phase14.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase2(final Boolean b) { - if (filled.get(38)) { - throw new IllegalStateException("rlpTxn.PHASE_2 already set"); - } else { - filled.set(38); - } - - phase2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase3(final Boolean b) { - if (filled.get(39)) { - throw new IllegalStateException("rlpTxn.PHASE_3 already set"); - } else { - filled.set(39); - } - - phase3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase4(final Boolean b) { - if (filled.get(40)) { - throw new IllegalStateException("rlpTxn.PHASE_4 already set"); - } else { - filled.set(40); - } - - phase4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase5(final Boolean b) { - if (filled.get(41)) { - throw new IllegalStateException("rlpTxn.PHASE_5 already set"); - } else { - filled.set(41); - } - - phase5.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase6(final Boolean b) { - if (filled.get(42)) { - throw new IllegalStateException("rlpTxn.PHASE_6 already set"); - } else { - filled.set(42); - } - - phase6.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase7(final Boolean b) { - if (filled.get(43)) { - throw new IllegalStateException("rlpTxn.PHASE_7 already set"); - } else { - filled.set(43); - } - - phase7.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase8(final Boolean b) { - if (filled.get(44)) { - throw new IllegalStateException("rlpTxn.PHASE_8 already set"); - } else { - filled.set(44); - } - - phase8.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase9(final Boolean b) { - if (filled.get(45)) { - throw new IllegalStateException("rlpTxn.PHASE_9 already set"); - } else { - filled.set(45); - } - - phase9.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phaseEnd(final Boolean b) { - if (filled.get(46)) { - throw new IllegalStateException("rlpTxn.PHASE_END already set"); - } else { - filled.set(46); - } - - phaseEnd.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phaseSize(final Bytes b) { - if (filled.get(47)) { - throw new IllegalStateException("rlpTxn.PHASE_SIZE already set"); - } else { - filled.set(47); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - phaseSize.put((byte) 0); - } - phaseSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace power(final Bytes b) { - if (filled.get(48)) { - throw new IllegalStateException("rlpTxn.POWER already set"); - } else { - filled.set(48); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - power.put((byte) 0); - } - power.put(b.toArrayUnsafe()); - - return this; - } - - public Trace requiresEvmExecution(final Boolean b) { - if (filled.get(49)) { - throw new IllegalStateException("rlpTxn.REQUIRES_EVM_EXECUTION already set"); - } else { - filled.set(49); - } - - requiresEvmExecution.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace rlpLtBytesize(final Bytes b) { - if (filled.get(50)) { - throw new IllegalStateException("rlpTxn.RLP_LT_BYTESIZE already set"); - } else { - filled.set(50); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpLtBytesize.put((byte) 0); - } - rlpLtBytesize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace rlpLxBytesize(final Bytes b) { - if (filled.get(51)) { - throw new IllegalStateException("rlpTxn.RLP_LX_BYTESIZE already set"); - } else { - filled.set(51); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpLxBytesize.put((byte) 0); - } - rlpLxBytesize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace type(final Bytes b) { - if (filled.get(52)) { - throw new IllegalStateException("rlpTxn.TYPE already set"); - } else { - filled.set(52); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - type.put((byte) 0); - } - type.put(b.toArrayUnsafe()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("rlpTxn.ABS_TX_NUM has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("rlpTxn.ABS_TX_NUM_INFINY has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("rlpTxn.ACC_1 has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("rlpTxn.ACC_2 has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("rlpTxn.ACC_BYTESIZE has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("rlpTxn.ACCESS_TUPLE_BYTESIZE has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("rlpTxn.ADDR_HI has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("rlpTxn.ADDR_LO has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("rlpTxn.BIT has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("rlpTxn.BIT_ACC has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("rlpTxn.BYTE_1 has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("rlpTxn.BYTE_2 has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("rlpTxn.CODE_FRAGMENT_INDEX has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("rlpTxn.COUNTER has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("rlpTxn.DATA_HI has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("rlpTxn.DATA_LO has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("rlpTxn.DATAGASCOST has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("rlpTxn.DEPTH_1 has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("rlpTxn.DEPTH_2 has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("rlpTxn.DONE has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("rlpTxn.INDEX_DATA has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("rlpTxn.INDEX_LT has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("rlpTxn.INDEX_LX has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("rlpTxn.INPUT_1 has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("rlpTxn.INPUT_2 has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("rlpTxn.IS_PREFIX has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("rlpTxn.LC_CORRECTION has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("rlpTxn.LIMB has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("rlpTxn.LIMB_CONSTRUCTED has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("rlpTxn.LT has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("rlpTxn.LX has not been filled"); - } - - if (!filled.get(53)) { - throw new IllegalStateException("rlpTxn.nADDR has not been filled"); - } - - if (!filled.get(54)) { - throw new IllegalStateException("rlpTxn.nBYTES has not been filled"); - } - - if (!filled.get(55)) { - throw new IllegalStateException("rlpTxn.nKEYS has not been filled"); - } - - if (!filled.get(56)) { - throw new IllegalStateException("rlpTxn.nKEYS_PER_ADDR has not been filled"); - } - - if (!filled.get(57)) { - throw new IllegalStateException("rlpTxn.nSTEP has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("rlpTxn.PHASE_0 has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("rlpTxn.PHASE_1 has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("rlpTxn.PHASE_10 has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("rlpTxn.PHASE_11 has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("rlpTxn.PHASE_12 has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("rlpTxn.PHASE_13 has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("rlpTxn.PHASE_14 has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("rlpTxn.PHASE_2 has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("rlpTxn.PHASE_3 has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("rlpTxn.PHASE_4 has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("rlpTxn.PHASE_5 has not been filled"); - } - - if (!filled.get(42)) { - throw new IllegalStateException("rlpTxn.PHASE_6 has not been filled"); - } - - if (!filled.get(43)) { - throw new IllegalStateException("rlpTxn.PHASE_7 has not been filled"); - } - - if (!filled.get(44)) { - throw new IllegalStateException("rlpTxn.PHASE_8 has not been filled"); - } - - if (!filled.get(45)) { - throw new IllegalStateException("rlpTxn.PHASE_9 has not been filled"); - } - - if (!filled.get(46)) { - throw new IllegalStateException("rlpTxn.PHASE_END has not been filled"); - } - - if (!filled.get(47)) { - throw new IllegalStateException("rlpTxn.PHASE_SIZE has not been filled"); - } - - if (!filled.get(48)) { - throw new IllegalStateException("rlpTxn.POWER has not been filled"); - } - - if (!filled.get(49)) { - throw new IllegalStateException("rlpTxn.REQUIRES_EVM_EXECUTION has not been filled"); - } - - if (!filled.get(50)) { - throw new IllegalStateException("rlpTxn.RLP_LT_BYTESIZE has not been filled"); - } - - if (!filled.get(51)) { - throw new IllegalStateException("rlpTxn.RLP_LX_BYTESIZE has not been filled"); - } - - if (!filled.get(52)) { - throw new IllegalStateException("rlpTxn.TYPE has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - absTxNum.position(absTxNum.position() + 32); - } - - if (!filled.get(1)) { - absTxNumInfiny.position(absTxNumInfiny.position() + 32); - } - - if (!filled.get(3)) { - acc1.position(acc1.position() + 32); - } - - if (!filled.get(4)) { - acc2.position(acc2.position() + 32); - } - - if (!filled.get(5)) { - accBytesize.position(accBytesize.position() + 32); - } - - if (!filled.get(2)) { - accessTupleBytesize.position(accessTupleBytesize.position() + 32); - } - - if (!filled.get(6)) { - addrHi.position(addrHi.position() + 32); - } - - if (!filled.get(7)) { - addrLo.position(addrLo.position() + 32); - } - - if (!filled.get(8)) { - bit.position(bit.position() + 1); - } - - if (!filled.get(9)) { - bitAcc.position(bitAcc.position() + 32); - } - - if (!filled.get(10)) { - byte1.position(byte1.position() + 1); - } - - if (!filled.get(11)) { - byte2.position(byte2.position() + 1); - } - - if (!filled.get(12)) { - codeFragmentIndex.position(codeFragmentIndex.position() + 32); - } - - if (!filled.get(13)) { - counter.position(counter.position() + 32); - } - - if (!filled.get(15)) { - dataHi.position(dataHi.position() + 32); - } - - if (!filled.get(16)) { - dataLo.position(dataLo.position() + 32); - } - - if (!filled.get(14)) { - datagascost.position(datagascost.position() + 32); - } - - if (!filled.get(17)) { - depth1.position(depth1.position() + 1); - } - - if (!filled.get(18)) { - depth2.position(depth2.position() + 1); - } - - if (!filled.get(19)) { - done.position(done.position() + 1); - } - - if (!filled.get(20)) { - indexData.position(indexData.position() + 32); - } - - if (!filled.get(21)) { - indexLt.position(indexLt.position() + 32); - } - - if (!filled.get(22)) { - indexLx.position(indexLx.position() + 32); - } - - if (!filled.get(23)) { - input1.position(input1.position() + 32); - } - - if (!filled.get(24)) { - input2.position(input2.position() + 32); - } - - if (!filled.get(25)) { - isPrefix.position(isPrefix.position() + 1); - } - - if (!filled.get(26)) { - lcCorrection.position(lcCorrection.position() + 1); - } - - if (!filled.get(27)) { - limb.position(limb.position() + 32); - } - - if (!filled.get(28)) { - limbConstructed.position(limbConstructed.position() + 1); - } - - if (!filled.get(29)) { - lt.position(lt.position() + 1); - } - - if (!filled.get(30)) { - lx.position(lx.position() + 1); - } - - if (!filled.get(53)) { - nAddr.position(nAddr.position() + 32); - } - - if (!filled.get(54)) { - nBytes.position(nBytes.position() + 32); - } - - if (!filled.get(55)) { - nKeys.position(nKeys.position() + 32); - } - - if (!filled.get(56)) { - nKeysPerAddr.position(nKeysPerAddr.position() + 32); - } - - if (!filled.get(57)) { - nStep.position(nStep.position() + 32); - } - - if (!filled.get(31)) { - phase0.position(phase0.position() + 1); - } - - if (!filled.get(32)) { - phase1.position(phase1.position() + 1); - } - - if (!filled.get(33)) { - phase10.position(phase10.position() + 1); - } - - if (!filled.get(34)) { - phase11.position(phase11.position() + 1); - } - - if (!filled.get(35)) { - phase12.position(phase12.position() + 1); - } - - if (!filled.get(36)) { - phase13.position(phase13.position() + 1); - } - - if (!filled.get(37)) { - phase14.position(phase14.position() + 1); - } - - if (!filled.get(38)) { - phase2.position(phase2.position() + 1); - } - - if (!filled.get(39)) { - phase3.position(phase3.position() + 1); - } - - if (!filled.get(40)) { - phase4.position(phase4.position() + 1); - } - - if (!filled.get(41)) { - phase5.position(phase5.position() + 1); - } - - if (!filled.get(42)) { - phase6.position(phase6.position() + 1); - } - - if (!filled.get(43)) { - phase7.position(phase7.position() + 1); - } - - if (!filled.get(44)) { - phase8.position(phase8.position() + 1); - } - - if (!filled.get(45)) { - phase9.position(phase9.position() + 1); - } - - if (!filled.get(46)) { - phaseEnd.position(phaseEnd.position() + 1); - } - - if (!filled.get(47)) { - phaseSize.position(phaseSize.position() + 32); - } - - if (!filled.get(48)) { - power.position(power.position() + 32); - } - - if (!filled.get(49)) { - requiresEvmExecution.position(requiresEvmExecution.position() + 1); - } - - if (!filled.get(50)) { - rlpLtBytesize.position(rlpLtBytesize.position() + 32); - } - - if (!filled.get(51)) { - rlpLxBytesize.position(rlpLxBytesize.position() + 32); - } - - if (!filled.get(52)) { - type.position(type.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/TxnrlpTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/TxnrlpTrace.java deleted file mode 100644 index a4a9fbad1..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txn/TxnrlpTrace.java +++ /dev/null @@ -1,35 +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.rlp.txn; - -import java.math.BigInteger; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * WARNING: This code is generated automatically. Any modifications to this code may be overwritten - * and could lead to unexpected behavior. Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -record TxnrlpTrace(@JsonProperty("Trace") Trace trace) { - static final BigInteger G_txdatanonzero = new BigInteger("16"); - static final BigInteger G_txdatazero = new BigInteger("4"); - static final BigInteger LLARGE = new BigInteger("16"); - static final BigInteger LLARGEMO = new BigInteger("15"); - static final BigInteger int_long = new BigInteger("183"); - static final BigInteger int_short = new BigInteger("128"); - static final BigInteger list_long = new BigInteger("247"); - static final BigInteger list_short = new BigInteger("192"); -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcpt.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcpt.java deleted file mode 100644 index 4a7157618..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcpt.java +++ /dev/null @@ -1,789 +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.rlp.txrcpt; - -import static net.consensys.linea.zktracer.module.rlputils.Pattern.byteCounting; -import static net.consensys.linea.zktracer.module.rlputils.Pattern.outerRlpSize; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Utils.bitDecomposition; -import static net.consensys.linea.zktracer.types.Utils.leftPadTo; -import static net.consensys.linea.zktracer.types.Utils.rightPadTo; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.List; -import java.util.function.Function; - -import lombok.Getter; -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.rlputils.ByteCountAndPowerOutput; -import net.consensys.linea.zktracer.types.BitDecOutput; -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 static final int LLARGE = Trace.LLARGE; - private static final Bytes BYTES_RLP_INT_SHORT = Bytes.minimalBytes(Trace.INT_SHORT); - private static final int INT_RLP_INT_SHORT = Trace.INT_SHORT; - private static final int INT_RLP_INT_LONG = Trace.INT_LONG; - private static final Bytes BYTES_RLP_LIST_SHORT = Bytes.minimalBytes(Trace.LIST_SHORT); - private static final int INT_RLP_LIST_SHORT = Trace.LIST_SHORT; - private static final int INT_RLP_LIST_LONG = Trace.LIST_LONG; - - private int absLogNum = 0; - @Getter public StackedList chunkList = new StackedList<>(); - - @Override - public String moduleKey() { - return "RLP_TXRCPT"; - } - - @Override - public void enterTransaction() { - this.chunkList.enter(); - } - - @Override - public void popTransaction() { - this.chunkList.pop(); - } - - @Override - public void traceEndTx( - WorldView worldView, - Transaction tx, - boolean isSuccessful, - Bytes output, - List logList, - long gasUsed) { - RlpTxrcptChunk chunk = new RlpTxrcptChunk(tx.getType(), isSuccessful, gasUsed, logList); - this.chunkList.add(chunk); - } - - public void traceChunk(final RlpTxrcptChunk chunk, int absTxNum, int absLogNumMax, Trace trace) { - RlpTxrcptColumns traceValue = new RlpTxrcptColumns(); - traceValue.txrcptSize = txRcptSize(chunk); - traceValue.absTxNum = absTxNum; - traceValue.absLogNumMax = absLogNumMax; - - // PHASE 1: RLP Prefix. - phase1(traceValue, chunk.txType(), trace); - - // PHASE 2: Status code Rz. - phase2(traceValue, chunk.status(), trace); - - // PHASE 3: Cumulative gas Ru. - phase3(traceValue, chunk.gasUsed(), trace); - - // PHASE 4: Bloom Filter Rb. - phase4(traceValue, chunk.logs(), trace); - - // Phase 5: log series Rl. - phase5(traceValue, chunk.logs(), trace); - } - - private void phase1(RlpTxrcptColumns traceValue, TransactionType txType, Trace trace) { - final int phase = 1; - // byte TYPE concatenation - traceValue.partialReset(phase, 1); - traceValue.isPrefix = true; - - if (txType == TransactionType.FRONTIER) { - traceValue.lcCorrection = true; - } else { - traceValue.limbConstructed = true; - traceValue.input1 = bigIntegerToBytes(BigInteger.valueOf(txType.getSerializedType())); - traceValue.limb = traceValue.input1; - traceValue.nBytes = 1; - } - - traceRow(traceValue, trace); - - // RLP prefix of the txRcpt list. - rlpByteString( - phase, traceValue.txrcptSize, true, false, false, false, true, false, 0, traceValue, trace); - } - - private void phase2(RlpTxrcptColumns traceValue, Boolean status, Trace trace) { - final int phase = 2; - traceValue.partialReset(phase, 1); - traceValue.limbConstructed = true; - - if (status) { - traceValue.input1 = bigIntegerToBytes(BigInteger.ONE); - traceValue.limb = traceValue.input1; - } else { - traceValue.input1 = Bytes.ofUnsignedShort(0); - traceValue.limb = BYTES_RLP_INT_SHORT; - } - - traceValue.nBytes = 1; - traceValue.phaseEnd = true; - - traceRow(traceValue, trace); - } - - private void phase3(RlpTxrcptColumns traceValue, Long cumulativeGasUsed, Trace trace) { - final int phase = 3; - // TODO: uncomment this - // if (cumulativeGasUsed ==0){ - // throw new IllegalStateException("Cumulative Gas Used can't be 0"); - // } - rlpInt( - 1, phase, cumulativeGasUsed, false, false, false, true, false, false, 0, traceValue, trace); - } - - public static void insertLog(LogsBloomFilter.Builder bloomBuilder, final Log log) { - bloomBuilder.insertBytes(log.getLogger()); - - for (var topic : log.getTopics()) { - bloomBuilder.insertBytes(topic); - } - } - - private void phase4(RlpTxrcptColumns traceValue, List logList, Trace trace) { - final int phase = 4; - // RLP prefix - traceValue.partialReset(phase, 1); - traceValue.isPrefix = true; - traceValue.phaseSize = 256; - traceValue.limbConstructed = true; - traceValue.limb = - Bytes.concatenate( - bigIntegerToBytes(BigInteger.valueOf(INT_RLP_INT_LONG + 2)), - bigIntegerToBytes(BigInteger.valueOf(256))); - traceValue.nBytes = 3; - traceRow(traceValue, trace); - - // Concatenation of Byte slice of the bloom Filter. - LogsBloomFilter.Builder bloomFilterBuilder = LogsBloomFilter.builder(); - for (Log log : logList) { - insertLog(bloomFilterBuilder, log); - } - final LogsBloomFilter bloomFilter = bloomFilterBuilder.build(); - for (int i = 0; i < 4; i++) { - traceValue.partialReset(phase, LLARGE); - - traceValue.input1 = bloomFilter.slice(64 * i, LLARGE); - traceValue.input2 = bloomFilter.slice(64 * i + LLARGE, LLARGE); - traceValue.input3 = bloomFilter.slice(64 * i + 2 * LLARGE, LLARGE); - traceValue.input4 = bloomFilter.slice(64 * i + 3 * LLARGE, LLARGE); - - for (int ct = 0; ct < LLARGE; ct++) { - traceValue.counter = ct; - traceValue.byte1 = traceValue.input1.get(ct); - traceValue.acc1 = traceValue.input1.slice(0, ct + 1); - traceValue.byte2 = traceValue.input2.get(ct); - traceValue.acc2 = traceValue.input2.slice(0, ct + 1); - traceValue.byte3 = traceValue.input3.get(ct); - traceValue.acc3 = traceValue.input3.slice(0, ct + 1); - traceValue.byte4 = traceValue.input4.get(ct); - traceValue.acc4 = traceValue.input4.slice(0, ct + 1); - - switch (ct) { - case 12 -> { - traceValue.limbConstructed = true; - traceValue.limb = traceValue.input1; - traceValue.nBytes = LLARGE; - } - case 13 -> { - traceValue.limbConstructed = true; - traceValue.limb = traceValue.input2; - traceValue.nBytes = LLARGE; - } - case 14 -> { - traceValue.limbConstructed = true; - traceValue.limb = traceValue.input3; - traceValue.nBytes = LLARGE; - } - case 15 -> { - traceValue.limbConstructed = true; - traceValue.limb = traceValue.input4; - traceValue.nBytes = LLARGE; - traceValue.phaseEnd = (i == 3); - } - default -> { - traceValue.limbConstructed = false; - traceValue.limb = Bytes.ofUnsignedShort(0); - traceValue.nBytes = 0; - } - } - traceRow(traceValue, trace); - // Update INDEX_LOCAL after the row when LIMB is constructed. - if (traceValue.limbConstructed) { - traceValue.indexLocal += 1; - } - } - } - // Put to 0 INDEX_LOCAL at the end of the phase. - traceValue.indexLocal = 0; - } - - private void phase5(RlpTxrcptColumns traceValue, List logList, Trace trace) { - final int phase = 5; - // Trivial case, there are no log entries. - if (logList.isEmpty()) { - traceValue.logEntrySize = 1; - traceEmptyList(traceValue, phase, true, true, trace); - } else { - // RLP prefix of the list of log entries. - int nbLog = logList.size(); - for (Log log : logList) { - traceValue.phaseSize += outerRlpSize(logSize(log)); - } - traceValue.partialReset(phase, 8); - rlpByteString( - phase, - traceValue.phaseSize, - true, - true, - false, - false, - false, - false, - 0, - traceValue, - trace); - - // Trace each Log Entry. - for (int i = 0; i < nbLog; i++) { - // Update ABS_LOG_NUM. - this.absLogNum += 1; - - // Log Entry RLP Prefix. - traceValue.logEntrySize = logSize(logList.get(i)); - rlpByteString( - phase, - traceValue.logEntrySize, - true, - true, - true, - false, - false, - false, - 0, - traceValue, - trace); - - // Logger's Address. - // Common values for CT=0 tp CT=2 - traceValue.partialReset(phase, 3); - traceValue.depth1 = true; - traceValue.input1 = logList.get(i).getLogger().slice(0, 4); - traceValue.input2 = logList.get(i).getLogger().slice(4, LLARGE); - traceValue.limbConstructed = true; - - traceValue.counter = 0; - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(INT_RLP_INT_SHORT + 20)); - traceValue.nBytes = 1; - traceRow(traceValue, trace); - - traceValue.counter = 1; - traceValue.limb = traceValue.input1; - traceValue.nBytes = 4; - traceRow(traceValue, trace); - - traceValue.counter = 2; - traceValue.limb = traceValue.input2; - traceValue.nBytes = LLARGE; - traceRow(traceValue, trace); - - // Log Topic's RLP prefix. - traceValue.partialReset(phase, 1); - traceValue.depth1 = true; - traceValue.isPrefix = true; - traceValue.isTopic = true; - traceValue.localSize = 33 * logList.get(i).getTopics().size(); - traceValue.limbConstructed = true; - - if (logList.get(i).getTopics().isEmpty() || logList.get(i).getTopics().size() == 1) { - traceValue.limb = - bigIntegerToBytes( - BYTES_RLP_LIST_SHORT - .toUnsignedBigInteger() - .add(BigInteger.valueOf(traceValue.localSize))); - traceValue.nBytes = 1; - } else { - traceValue.limb = - Bytes.concatenate( - bigIntegerToBytes(BigInteger.valueOf(INT_RLP_LIST_LONG + 1)), - bigIntegerToBytes(BigInteger.valueOf(traceValue.localSize))); - traceValue.nBytes = 2; - } - traceRow(traceValue, trace); - - // RLP Log Topic (if exist). - if (!logList.get(i).getTopics().isEmpty()) { - for (int j = 0; j < logList.get(i).getTopics().size(); j++) { - traceValue.partialReset(phase, 3); - traceValue.depth1 = true; - traceValue.isTopic = true; - traceValue.indexLocal += 1; - traceValue.input1 = logList.get(i).getTopics().get(j).slice(0, LLARGE); - traceValue.input2 = logList.get(i).getTopics().get(j).slice(LLARGE, LLARGE); - traceValue.limbConstructed = true; - - traceValue.counter = 0; - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(INT_RLP_INT_SHORT + 32)); - traceValue.nBytes = 1; - traceValue.localSize -= traceValue.nBytes; - traceRow(traceValue, trace); - - traceValue.counter = 1; - traceValue.limb = traceValue.input1; - traceValue.nBytes = LLARGE; - traceValue.localSize -= traceValue.nBytes; - traceRow(traceValue, trace); - - traceValue.counter = 2; - traceValue.limb = traceValue.input2; - traceValue.nBytes = LLARGE; - traceValue.localSize -= traceValue.nBytes; - traceRow(traceValue, trace); - } - } - // Reset the value of IndexLocal at the end of the Topic - final int indexLocalEndTopic = traceValue.indexLocal; - traceValue.indexLocal = 0; - - // RLP Prefix of the Data. - // Common to all the cases: - traceValue.localSize = logList.get(i).getData().size(); - // There are three cases for tracing the data RLP prefix: - switch (logList.get(i).getData().size()) { - case 0 -> { // Case no data: - traceValue.partialReset(phase, 1); - // In INPUT_2 is stored the number of topics, stored in INDEX_LOCAL at the - // previous row - traceValue.input2 = Bytes.ofUnsignedShort(indexLocalEndTopic); - traceValue.depth1 = true; - traceValue.isPrefix = true; - traceValue.isData = true; - traceValue.limbConstructed = true; - traceValue.limb = BYTES_RLP_INT_SHORT; - traceValue.nBytes = 1; - traceValue.phaseEnd = (i == nbLog - 1); - traceRow(traceValue, trace); - } - case 1 -> // Case with data is made of one byte - rlpInt( - 3, - phase, - logList.get(i).getData().toUnsignedBigInteger().longValueExact(), - true, - true, - true, - false, - true, - true, - indexLocalEndTopic, - traceValue, - trace); - - default -> // Default case, data is made of >= 2 bytes - rlpByteString( - phase, - logList.get(i).getData().size(), - false, - true, - true, - true, - false, - true, - indexLocalEndTopic, - traceValue, - trace); - } - - // Tracing the Data - if (!logList.get(i).getData().isEmpty()) { - int nbDataSlice = 1 + (logList.get(i).getData().size() - 1) / 16; - - int sizeDataLastSlice = logList.get(i).getData().size() - LLARGE * (nbDataSlice - 1); - - if (sizeDataLastSlice == 0) { - sizeDataLastSlice = LLARGE; - } - traceValue.partialReset(phase, nbDataSlice); - traceValue.localSize = logList.get(i).getData().size(); - traceValue.depth1 = true; - traceValue.isData = true; - traceValue.limbConstructed = true; - - for (int ct = 0; ct < nbDataSlice; ct++) { - traceValue.counter = ct; - traceValue.indexLocal = ct; - - if (ct != nbDataSlice - 1) { - traceValue.input1 = logList.get(i).getData().slice(LLARGE * ct, LLARGE); - traceValue.limb = traceValue.input1; - traceValue.nBytes = LLARGE; - traceValue.localSize -= LLARGE; - } else { - traceValue.input1 = - rightPadTo( - logList.get(i).getData().slice(LLARGE * ct, sizeDataLastSlice), LLARGE); - traceValue.limb = traceValue.input1; - traceValue.nBytes = sizeDataLastSlice; - traceValue.localSize -= sizeDataLastSlice; - traceValue.phaseEnd = (i == nbLog - 1); - } - - traceRow(traceValue, trace); - } - // set to 0 index local at the end of the data phase - traceValue.indexLocal = 0; - } - } - } - } - - private void traceEmptyList( - RlpTxrcptColumns traceValue, int phase, boolean isPrefix, boolean endPhase, Trace trace) { - traceValue.partialReset(phase, 1); - traceValue.limbConstructed = true; - traceValue.limb = BYTES_RLP_LIST_SHORT; - traceValue.nBytes = 1; - traceValue.isPrefix = isPrefix; - traceValue.phaseEnd = endPhase; - traceRow(traceValue, trace); - } - - private void rlpByteString( - int phase, - long length, - boolean isList, - boolean isPrefix, - boolean depth1, - boolean isData, - boolean endPhase, - boolean writeInput2, - int valueInput2, - RlpTxrcptColumns traceValue, - Trace trace) { - int lengthSize = - Bytes.ofUnsignedLong(length).size() - - Bytes.ofUnsignedLong(length).numberOfLeadingZeroBytes(); - - ByteCountAndPowerOutput byteCountingOutput = byteCounting(lengthSize, 8); - - traceValue.partialReset(phase, 8); - traceValue.input1 = bigIntegerToBytes(BigInteger.valueOf(length)); - traceValue.isPrefix = isPrefix; - traceValue.depth1 = depth1; - traceValue.isData = isData; - if (writeInput2) { - traceValue.input2 = Bytes.minimalBytes(valueInput2); - } - - Bytes input1RightShift = leftPadTo(traceValue.input1, traceValue.nStep); - long acc2LastRow; - - if (length >= 56) { - acc2LastRow = length - 56; - } else { - acc2LastRow = 55 - length; - } - - Bytes acc2LastRowShift = - leftPadTo(bigIntegerToBytes(BigInteger.valueOf(acc2LastRow)), traceValue.nStep); - for (int ct = 0; ct < 8; ct++) { - traceValue.counter = ct; - traceValue.accSize = byteCountingOutput.accByteSizeList().get(ct); - traceValue.power = byteCountingOutput.powerList().get(ct); - traceValue.byte1 = input1RightShift.get(ct); - traceValue.acc1 = input1RightShift.slice(0, ct + 1); - traceValue.byte2 = acc2LastRowShift.get(ct); - traceValue.acc2 = acc2LastRowShift.slice(0, ct + 1); - - if (length >= 56) { - if (ct == 6) { - traceValue.limbConstructed = true; - traceValue.nBytes = 1; - if (isList) { - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(INT_RLP_LIST_LONG + lengthSize)); - } else { - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(INT_RLP_INT_LONG + lengthSize)); - } - } - - if (ct == 7) { - traceValue.limbConstructed = true; - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(length)); - traceValue.nBytes = lengthSize; - traceValue.bit = true; - traceValue.bitAcc = 1; - traceValue.phaseEnd = endPhase; - } - } else { - if (ct == 7) { - traceValue.limbConstructed = true; - if (isList) { - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(INT_RLP_LIST_SHORT + length)); - } else { - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(INT_RLP_INT_SHORT + length)); - } - traceValue.nBytes = 1; - traceValue.phaseEnd = endPhase; - } - } - - traceRow(traceValue, trace); - } - } - - private void rlpInt( - int inputToWrite, - int phase, - long input, - boolean isPrefix, - boolean depth1, - boolean isData, - boolean endPhase, - boolean onlyPrefix, - boolean writeInput2, - int valueInput2, - RlpTxrcptColumns traceValue, - Trace trace) { - - final Bytes inputBytes = bigIntegerToBytes(BigInteger.valueOf(input)); - - traceValue.partialReset(phase, 8); - - traceValue.isPrefix = isPrefix; - traceValue.depth1 = depth1; - traceValue.isData = isData; - switch (inputToWrite) { - case 1 -> { - traceValue.input1 = inputBytes; - } - case 3 -> { - traceValue.input1 = Bytes.minimalBytes(1); - traceValue.input3 = inputBytes; - } - default -> throw new IllegalArgumentException( - "should be called only to write Input1 or Input3, not Input" + inputToWrite); - } - if (writeInput2) { - traceValue.input2 = Bytes.minimalBytes(valueInput2); - } - - final int inputSize = inputBytes.size(); - ByteCountAndPowerOutput byteCountingOutput = byteCounting(inputSize, 8); - - Bytes inputBytesPadded = leftPadTo(inputBytes, 8); - BitDecOutput bitDecOutput = - bitDecomposition(0xff & inputBytesPadded.get(inputBytesPadded.size() - 1), 8); - - for (int ct = 0; ct < 8; ct++) { - traceValue.counter = ct; - traceValue.byte1 = inputBytesPadded.get(ct); - traceValue.acc1 = inputBytesPadded.slice(0, ct + 1); - traceValue.power = byteCountingOutput.powerList().get(ct); - traceValue.accSize = byteCountingOutput.accByteSizeList().get(ct); - traceValue.bit = bitDecOutput.bitDecList().get(ct); - traceValue.bitAcc = bitDecOutput.bitAccList().get(ct); - - if (input >= 128 && ct == 6) { - traceValue.limbConstructed = true; - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(INT_RLP_INT_SHORT + inputSize)); - traceValue.nBytes = 1; - } - - if (ct == 7) { - if (onlyPrefix) { - traceValue.lcCorrection = true; - traceValue.limbConstructed = false; - traceValue.limb = bigIntegerToBytes(BigInteger.ZERO); - traceValue.nBytes = 0; - } else { - traceValue.limbConstructed = true; - traceValue.limb = bigIntegerToBytes(BigInteger.valueOf(input)); - traceValue.nBytes = inputSize; - traceValue.phaseEnd = endPhase; - } - } - - traceRow(traceValue, trace); - } - } - - private void traceRow(RlpTxrcptColumns traceValue, Trace trace) { - // Decrements sizes - if (traceValue.limbConstructed) { - if (traceValue.phase != 1) { - traceValue.txrcptSize -= traceValue.nBytes; - } - if ((traceValue.phase == 4 && !traceValue.isPrefix) - || (traceValue.phase == 5 && traceValue.depth1)) { - traceValue.phaseSize -= traceValue.nBytes; - } - if ((traceValue.phase == 5 && traceValue.depth1 && (!traceValue.isPrefix)) - || traceValue.isTopic - || traceValue.isData) { - traceValue.logEntrySize -= traceValue.nBytes; - } - } - - trace - .absLogNum(Bytes.ofUnsignedLong(this.absLogNum)) - .absLogNumMax(Bytes.ofUnsignedLong(traceValue.absLogNumMax)) - .absTxNum(Bytes.ofUnsignedLong(traceValue.absTxNum)) - .absTxNumMax(Bytes.ofUnsignedLong(this.chunkList.size())) - .acc1(traceValue.acc1) - .acc2(traceValue.acc2) - .acc3(traceValue.acc3) - .acc4(traceValue.acc4) - .accSize(Bytes.ofUnsignedLong(traceValue.accSize)) - .bit(traceValue.bit) - .bitAcc(UnsignedByte.of(traceValue.bitAcc)) - .byte1(UnsignedByte.of(traceValue.byte1)) - .byte2(UnsignedByte.of(traceValue.byte2)) - .byte3(UnsignedByte.of(traceValue.byte3)) - .byte4(UnsignedByte.of(traceValue.byte4)) - .counter(Bytes.ofUnsignedInt(traceValue.counter)) - .depth1(traceValue.depth1) - .done(traceValue.counter == traceValue.nStep - 1) - .index(Bytes.ofUnsignedInt(traceValue.index)) - .indexLocal(Bytes.ofUnsignedInt(traceValue.indexLocal)) - .input1(traceValue.input1) - .input2(traceValue.input2) - .input3(traceValue.input3) - .input4(traceValue.input4) - .isData(traceValue.isData) - .isPrefix(traceValue.isPrefix) - .isTopic(traceValue.isTopic) - .lcCorrection(traceValue.lcCorrection) - .limb(rightPadTo(traceValue.limb, LLARGE)) - .limbConstructed(traceValue.limbConstructed) - .localSize(Bytes.ofUnsignedInt(traceValue.localSize)) - .logEntrySize(Bytes.ofUnsignedInt(traceValue.logEntrySize)) - .nBytes(UnsignedByte.of(traceValue.nBytes)) - .nStep(Bytes.ofUnsignedInt(traceValue.nStep)); - - List> phaseColumns = - List.of(trace::phase1, trace::phase2, trace::phase3, trace::phase4, trace::phase5); - - for (int i = 0; i < phaseColumns.size(); i++) { - phaseColumns.get(i).apply(i + 1 == traceValue.phase); - } - - trace - .phaseEnd(traceValue.phaseEnd) - .phaseSize(Bytes.ofUnsignedInt(traceValue.phaseSize)) - .power(bigIntegerToBytes(traceValue.power)) - .txrcptSize(Bytes.ofUnsignedInt(traceValue.txrcptSize)); - - trace.validateRow(); - - // Increments Index. - if (traceValue.limbConstructed) { - traceValue.index += 1; - } - } - - /** - * Calculates the size of the RLP of a transaction receipt WITHOUT its RLP prefix. - * - * @param chunk an instance of {@link RlpTxrcptChunk} containing information pertaining to a - * transaction execution - * @return the size of the RLP of a transaction receipt WITHOUT its RLP prefix - */ - private int txRcptSize(RlpTxrcptChunk chunk) { - - // The encoded status code is always of size 1. - int size = 1; - - // As the cumulative gas is Gtransaction=21000, its size is >1. - size += outerRlpSize(Bytes.minimalBytes(chunk.gasUsed()).size()); - - // RLP(Rb) is always 259 (256+3) long. - size += 259; - - // Add the size of the RLP(Log). - int nbLog = chunk.logs().size(); - if (nbLog == 0) { - size += 1; - } else { - int tmp = 0; - for (int i = 0; i < nbLog; i++) { - tmp += outerRlpSize(logSize(chunk.logs().get(i))); - } - size += outerRlpSize(tmp); - } - - return size; - } - - // Gives the byte size of the RLP-isation of a log entry WITHOUT its RLP prefix. - private int logSize(Log log) { - // The size of RLP(Oa) is always 21. - int logSize = 21; - - // RLP(Topic) is of size 1 for 0 topic, 33+1 for 1 topic, 2 + 33*nTOPIC for 2 <= - // nTOPIC <=4. - logSize += outerRlpSize(33 * log.getTopics().size()); - - // RLP(Od) is of size OuterRlpSize(datasize) except if the Data is made of one - // byte. - if (log.getData().size() == 1) { - // If the byte is of value >= 128, its RLP is 2 byte, else 1 byte (no RLP - // prefix). - if (log.getData().toUnsignedBigInteger().compareTo(BigInteger.valueOf(128)) >= 0) { - logSize += 2; - } else { - logSize += 1; - } - } else { - logSize += outerRlpSize(log.getData().size()); - } - - return logSize; - } - - @Override - public int lineCount() { - return this.chunkList.lineCount(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - int absLogNumMax = 0; - for (RlpTxrcptChunk chunk : this.chunkList) { - absLogNumMax += chunk.logs().size(); - } - - int absTxNum = 0; - for (RlpTxrcptChunk chunk : this.chunkList) { - absTxNum += 1; - traceChunk(chunk, absTxNum, absLogNumMax, trace); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptChunk.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptChunk.java deleted file mode 100644 index 78ba5b04b..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptChunk.java +++ /dev/null @@ -1,72 +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.rlp.txrcpt; - -import java.util.List; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.container.ModuleOperation; -import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.evm.log.Log; - -@RequiredArgsConstructor -@Accessors(fluent = true) -@Getter -public final class RlpTxrcptChunk extends ModuleOperation { - private final TransactionType txType; - private final Boolean status; - private final Long gasUsed; - private final List logs; - - @Override - protected int computeLineCount() { - // Phase 0 is always 1+8=9 row long, Phase 1, 1 row long, Phase 2 8 row long, - // Phase 3 65 = 1 + - // 64 row long - int rowSize = 83; - - // add the number of rows for Phase 4 : Log entry - if (this.logs.isEmpty()) { - rowSize += 1; - } else { - // Rlp prefix of the list of log entries is always 8 rows long - rowSize += 8; - - for (int i = 0; i < this.logs.size(); i++) { - // Rlp prefix of a log entry is always 8, Log entry address is always 3 row - // long, Log topics - // rlp prefix always 1 - rowSize += 12; - - // Each log Topics is 3 rows long - rowSize += 3 * this.logs.get(i).getTopics().size(); - - // Row size of data is 1 if empty - if (this.logs.get(i).getData().isEmpty()) { - rowSize += 1; - } - // Row size of the data is 8 (RLP prefix)+ integer part (data-size - 1 /16) +1 - else { - rowSize += 8 + (this.logs.get(i).getData().size() - 1) / 16 + 1; - } - } - } - - return rowSize; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptColumns.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptColumns.java deleted file mode 100644 index 7f2de5a8d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptColumns.java +++ /dev/null @@ -1,92 +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.rlp.txrcpt; - -import java.math.BigInteger; - -import org.apache.tuweni.bytes.Bytes; - -class RlpTxrcptColumns { - int absTxNum; - int absLogNumMax; - Bytes acc1; - Bytes acc2; - Bytes acc3; - Bytes acc4; - int accSize; - boolean bit; - int bitAcc; - byte byte1; - byte byte2; - byte byte3; - byte byte4; - int counter; - boolean depth1; - int index; - int indexLocal; - Bytes input1; - Bytes input2; - Bytes input3; - Bytes input4; - boolean isData; - boolean isPrefix; - boolean isTopic; - boolean lcCorrection; - Bytes limb; - boolean limbConstructed; - int localSize; - int logEntrySize; - int nBytes; - int nStep; - int phase; - boolean phaseEnd; - int phaseSize; - BigInteger power; - int txrcptSize; - - void partialReset(int phase, int nStep) { - this.phase = phase; - this.nStep = nStep; - - // Set to default local values. - this.acc1 = Bytes.ofUnsignedShort(0); - this.acc2 = Bytes.ofUnsignedShort(0); - this.acc3 = Bytes.ofUnsignedShort(0); - this.acc4 = Bytes.ofUnsignedShort(0); - this.accSize = 0; - this.bit = false; - this.bitAcc = 0; - this.byte1 = 0; - this.byte2 = 0; - this.byte3 = 0; - this.byte4 = 0; - this.counter = 0; - this.depth1 = false; - this.input1 = Bytes.ofUnsignedShort(0); - this.input2 = Bytes.ofUnsignedShort(0); - this.input3 = Bytes.ofUnsignedShort(0); - this.input4 = Bytes.ofUnsignedShort(0); - this.isData = false; - this.isPrefix = false; - this.isTopic = false; - this.lcCorrection = false; - this.limb = Bytes.ofUnsignedShort(0); - this.limbConstructed = false; - this.nBytes = 0; - this.phaseEnd = false; - this.power = BigInteger.valueOf(0); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptTrace.java deleted file mode 100644 index 582ca7240..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/RlpTxrcptTrace.java +++ /dev/null @@ -1,51 +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.rlp.txrcpt; - -import com.fasterxml.jackson.annotation.JsonProperty; -import net.consensys.linea.zktracer.module.ModuleTrace; - -/** - * WARNING: This code is generated automatically. Any modifications to this code may be overwritten - * and could lead to unexpected behavior. Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -record RlpTxrcptTrace(@JsonProperty("Trace") Trace trace) implements ModuleTrace { - static final int CREATE2_SHIFT = 255; - static final int G_TXDATA_NONZERO = 16; - static final int G_TXDATA_ZERO = 4; - static final int INT_LONG = 183; - static final int INT_SHORT = 128; - static final int LIST_LONG = 247; - static final int LIST_SHORT = 192; - static final int LLARGE = 16; - static final int LLARGEMO = 15; - static final int RLPADDR_CONST_RECIPE_1 = 1; - static final int RLPADDR_CONST_RECIPE_2 = 2; - static final int RLPRECEIPT_SUBPHASE_ID_ADDR = 53; - static final int RLPRECEIPT_SUBPHASE_ID_CUMUL_GAS = 3; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_LIMB = 77; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_SIZE = 83; - static final int RLPRECEIPT_SUBPHASE_ID_NO_LOG_ENTRY = 11; - static final int RLPRECEIPT_SUBPHASE_ID_STATUS_CODE = 2; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE = 65; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA = 96; - static final int RLPRECEIPT_SUBPHASE_ID_TYPE = 7; - - @Override - public int length() { - return this.trace.size(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/Trace.java deleted file mode 100644 index 7cebc91e5..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/txrcpt/Trace.java +++ /dev/null @@ -1,1173 +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.rlp.txrcpt; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - static final int CREATE2_SHIFT = 255; - static final int G_TXDATA_NONZERO = 16; - static final int G_TXDATA_ZERO = 4; - static final int INT_LONG = 183; - static final int INT_SHORT = 128; - static final int LIST_LONG = 247; - static final int LIST_SHORT = 192; - static final int LLARGE = 16; - static final int LLARGEMO = 15; - static final int RLPADDR_CONST_RECIPE_1 = 1; - static final int RLPADDR_CONST_RECIPE_2 = 2; - static final int RLPRECEIPT_SUBPHASE_ID_ADDR = 53; - static final int RLPRECEIPT_SUBPHASE_ID_CUMUL_GAS = 3; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_LIMB = 77; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_SIZE = 83; - static final int RLPRECEIPT_SUBPHASE_ID_NO_LOG_ENTRY = 11; - static final int RLPRECEIPT_SUBPHASE_ID_STATUS_CODE = 2; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE = 65; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA = 96; - static final int RLPRECEIPT_SUBPHASE_ID_TYPE = 7; - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer absLogNum; - private final MappedByteBuffer absLogNumMax; - private final MappedByteBuffer absTxNum; - private final MappedByteBuffer absTxNumMax; - private final MappedByteBuffer acc1; - private final MappedByteBuffer acc2; - private final MappedByteBuffer acc3; - private final MappedByteBuffer acc4; - private final MappedByteBuffer accSize; - private final MappedByteBuffer bit; - private final MappedByteBuffer bitAcc; - private final MappedByteBuffer byte1; - private final MappedByteBuffer byte2; - private final MappedByteBuffer byte3; - private final MappedByteBuffer byte4; - private final MappedByteBuffer counter; - private final MappedByteBuffer depth1; - private final MappedByteBuffer done; - private final MappedByteBuffer index; - private final MappedByteBuffer indexLocal; - private final MappedByteBuffer input1; - private final MappedByteBuffer input2; - private final MappedByteBuffer input3; - private final MappedByteBuffer input4; - private final MappedByteBuffer isData; - private final MappedByteBuffer isPrefix; - private final MappedByteBuffer isTopic; - private final MappedByteBuffer lcCorrection; - private final MappedByteBuffer limb; - private final MappedByteBuffer limbConstructed; - private final MappedByteBuffer localSize; - private final MappedByteBuffer logEntrySize; - private final MappedByteBuffer nBytes; - private final MappedByteBuffer nStep; - private final MappedByteBuffer phase1; - private final MappedByteBuffer phase2; - private final MappedByteBuffer phase3; - private final MappedByteBuffer phase4; - private final MappedByteBuffer phase5; - private final MappedByteBuffer phaseEnd; - private final MappedByteBuffer phaseSize; - private final MappedByteBuffer power; - private final MappedByteBuffer txrcptSize; - - static List headers(int length) { - return List.of( - new ColumnHeader("rlpTxRcpt.ABS_LOG_NUM", 32, length), - new ColumnHeader("rlpTxRcpt.ABS_LOG_NUM_MAX", 32, length), - new ColumnHeader("rlpTxRcpt.ABS_TX_NUM", 32, length), - new ColumnHeader("rlpTxRcpt.ABS_TX_NUM_MAX", 32, length), - new ColumnHeader("rlpTxRcpt.ACC_1", 32, length), - new ColumnHeader("rlpTxRcpt.ACC_2", 32, length), - new ColumnHeader("rlpTxRcpt.ACC_3", 32, length), - new ColumnHeader("rlpTxRcpt.ACC_4", 32, length), - new ColumnHeader("rlpTxRcpt.ACC_SIZE", 32, length), - new ColumnHeader("rlpTxRcpt.BIT", 1, length), - new ColumnHeader("rlpTxRcpt.BIT_ACC", 1, length), - new ColumnHeader("rlpTxRcpt.BYTE_1", 1, length), - new ColumnHeader("rlpTxRcpt.BYTE_2", 1, length), - new ColumnHeader("rlpTxRcpt.BYTE_3", 1, length), - new ColumnHeader("rlpTxRcpt.BYTE_4", 1, length), - new ColumnHeader("rlpTxRcpt.COUNTER", 32, length), - new ColumnHeader("rlpTxRcpt.DEPTH_1", 1, length), - new ColumnHeader("rlpTxRcpt.DONE", 1, length), - new ColumnHeader("rlpTxRcpt.INDEX", 32, length), - new ColumnHeader("rlpTxRcpt.INDEX_LOCAL", 32, length), - new ColumnHeader("rlpTxRcpt.INPUT_1", 32, length), - new ColumnHeader("rlpTxRcpt.INPUT_2", 32, length), - new ColumnHeader("rlpTxRcpt.INPUT_3", 32, length), - new ColumnHeader("rlpTxRcpt.INPUT_4", 32, length), - new ColumnHeader("rlpTxRcpt.IS_DATA", 1, length), - new ColumnHeader("rlpTxRcpt.IS_PREFIX", 1, length), - new ColumnHeader("rlpTxRcpt.IS_TOPIC", 1, length), - new ColumnHeader("rlpTxRcpt.LC_CORRECTION", 1, length), - new ColumnHeader("rlpTxRcpt.LIMB", 32, length), - new ColumnHeader("rlpTxRcpt.LIMB_CONSTRUCTED", 1, length), - new ColumnHeader("rlpTxRcpt.LOCAL_SIZE", 32, length), - new ColumnHeader("rlpTxRcpt.LOG_ENTRY_SIZE", 32, length), - new ColumnHeader("rlpTxRcpt.nBYTES", 1, length), - new ColumnHeader("rlpTxRcpt.nSTEP", 32, length), - new ColumnHeader("rlpTxRcpt.PHASE_1", 1, length), - new ColumnHeader("rlpTxRcpt.PHASE_2", 1, length), - new ColumnHeader("rlpTxRcpt.PHASE_3", 1, length), - new ColumnHeader("rlpTxRcpt.PHASE_4", 1, length), - new ColumnHeader("rlpTxRcpt.PHASE_5", 1, length), - new ColumnHeader("rlpTxRcpt.PHASE_END", 1, length), - new ColumnHeader("rlpTxRcpt.PHASE_SIZE", 32, length), - new ColumnHeader("rlpTxRcpt.POWER", 32, length), - new ColumnHeader("rlpTxRcpt.TXRCPT_SIZE", 32, length)); - } - - public Trace(List buffers) { - this.absLogNum = buffers.get(0); - this.absLogNumMax = buffers.get(1); - this.absTxNum = buffers.get(2); - this.absTxNumMax = buffers.get(3); - this.acc1 = buffers.get(4); - this.acc2 = buffers.get(5); - this.acc3 = buffers.get(6); - this.acc4 = buffers.get(7); - this.accSize = buffers.get(8); - this.bit = buffers.get(9); - this.bitAcc = buffers.get(10); - this.byte1 = buffers.get(11); - this.byte2 = buffers.get(12); - this.byte3 = buffers.get(13); - this.byte4 = buffers.get(14); - this.counter = buffers.get(15); - this.depth1 = buffers.get(16); - this.done = buffers.get(17); - this.index = buffers.get(18); - this.indexLocal = buffers.get(19); - this.input1 = buffers.get(20); - this.input2 = buffers.get(21); - this.input3 = buffers.get(22); - this.input4 = buffers.get(23); - this.isData = buffers.get(24); - this.isPrefix = buffers.get(25); - this.isTopic = buffers.get(26); - this.lcCorrection = buffers.get(27); - this.limb = buffers.get(28); - this.limbConstructed = buffers.get(29); - this.localSize = buffers.get(30); - this.logEntrySize = buffers.get(31); - this.nBytes = buffers.get(32); - this.nStep = buffers.get(33); - this.phase1 = buffers.get(34); - this.phase2 = buffers.get(35); - this.phase3 = buffers.get(36); - this.phase4 = buffers.get(37); - this.phase5 = buffers.get(38); - this.phaseEnd = buffers.get(39); - this.phaseSize = buffers.get(40); - this.power = buffers.get(41); - this.txrcptSize = buffers.get(42); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace absLogNum(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("rlpTxRcpt.ABS_LOG_NUM already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - absLogNum.put((byte) 0); - } - absLogNum.put(b.toArrayUnsafe()); - - return this; - } - - public Trace absLogNumMax(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("rlpTxRcpt.ABS_LOG_NUM_MAX already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - absLogNumMax.put((byte) 0); - } - absLogNumMax.put(b.toArrayUnsafe()); - - return this; - } - - public Trace absTxNum(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("rlpTxRcpt.ABS_TX_NUM already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - absTxNum.put((byte) 0); - } - absTxNum.put(b.toArrayUnsafe()); - - return this; - } - - public Trace absTxNumMax(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("rlpTxRcpt.ABS_TX_NUM_MAX already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - absTxNumMax.put((byte) 0); - } - absTxNumMax.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc1(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("rlpTxRcpt.ACC_1 already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc1.put((byte) 0); - } - acc1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc2(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("rlpTxRcpt.ACC_2 already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc2.put((byte) 0); - } - acc2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc3(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("rlpTxRcpt.ACC_3 already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc3.put((byte) 0); - } - acc3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc4(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("rlpTxRcpt.ACC_4 already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc4.put((byte) 0); - } - acc4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accSize(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("rlpTxRcpt.ACC_SIZE already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accSize.put((byte) 0); - } - accSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace bit(final Boolean b) { - if (filled.get(9)) { - throw new IllegalStateException("rlpTxRcpt.BIT already set"); - } else { - filled.set(9); - } - - bit.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bitAcc(final UnsignedByte b) { - if (filled.get(10)) { - throw new IllegalStateException("rlpTxRcpt.BIT_ACC already set"); - } else { - filled.set(10); - } - - bitAcc.put(b.toByte()); - - return this; - } - - public Trace byte1(final UnsignedByte b) { - if (filled.get(11)) { - throw new IllegalStateException("rlpTxRcpt.BYTE_1 already set"); - } else { - filled.set(11); - } - - byte1.put(b.toByte()); - - return this; - } - - public Trace byte2(final UnsignedByte b) { - if (filled.get(12)) { - throw new IllegalStateException("rlpTxRcpt.BYTE_2 already set"); - } else { - filled.set(12); - } - - byte2.put(b.toByte()); - - return this; - } - - public Trace byte3(final UnsignedByte b) { - if (filled.get(13)) { - throw new IllegalStateException("rlpTxRcpt.BYTE_3 already set"); - } else { - filled.set(13); - } - - byte3.put(b.toByte()); - - return this; - } - - public Trace byte4(final UnsignedByte b) { - if (filled.get(14)) { - throw new IllegalStateException("rlpTxRcpt.BYTE_4 already set"); - } else { - filled.set(14); - } - - byte4.put(b.toByte()); - - return this; - } - - public Trace counter(final Bytes b) { - if (filled.get(15)) { - throw new IllegalStateException("rlpTxRcpt.COUNTER already set"); - } else { - filled.set(15); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - counter.put((byte) 0); - } - counter.put(b.toArrayUnsafe()); - - return this; - } - - public Trace depth1(final Boolean b) { - if (filled.get(16)) { - throw new IllegalStateException("rlpTxRcpt.DEPTH_1 already set"); - } else { - filled.set(16); - } - - depth1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace done(final Boolean b) { - if (filled.get(17)) { - throw new IllegalStateException("rlpTxRcpt.DONE already set"); - } else { - filled.set(17); - } - - done.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace index(final Bytes b) { - if (filled.get(18)) { - throw new IllegalStateException("rlpTxRcpt.INDEX already set"); - } else { - filled.set(18); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - index.put((byte) 0); - } - index.put(b.toArrayUnsafe()); - - return this; - } - - public Trace indexLocal(final Bytes b) { - if (filled.get(19)) { - throw new IllegalStateException("rlpTxRcpt.INDEX_LOCAL already set"); - } else { - filled.set(19); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - indexLocal.put((byte) 0); - } - indexLocal.put(b.toArrayUnsafe()); - - return this; - } - - public Trace input1(final Bytes b) { - if (filled.get(20)) { - throw new IllegalStateException("rlpTxRcpt.INPUT_1 already set"); - } else { - filled.set(20); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - input1.put((byte) 0); - } - input1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace input2(final Bytes b) { - if (filled.get(21)) { - throw new IllegalStateException("rlpTxRcpt.INPUT_2 already set"); - } else { - filled.set(21); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - input2.put((byte) 0); - } - input2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace input3(final Bytes b) { - if (filled.get(22)) { - throw new IllegalStateException("rlpTxRcpt.INPUT_3 already set"); - } else { - filled.set(22); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - input3.put((byte) 0); - } - input3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace input4(final Bytes b) { - if (filled.get(23)) { - throw new IllegalStateException("rlpTxRcpt.INPUT_4 already set"); - } else { - filled.set(23); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - input4.put((byte) 0); - } - input4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace isData(final Boolean b) { - if (filled.get(24)) { - throw new IllegalStateException("rlpTxRcpt.IS_DATA already set"); - } else { - filled.set(24); - } - - isData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isPrefix(final Boolean b) { - if (filled.get(25)) { - throw new IllegalStateException("rlpTxRcpt.IS_PREFIX already set"); - } else { - filled.set(25); - } - - isPrefix.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isTopic(final Boolean b) { - if (filled.get(26)) { - throw new IllegalStateException("rlpTxRcpt.IS_TOPIC already set"); - } else { - filled.set(26); - } - - isTopic.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace lcCorrection(final Boolean b) { - if (filled.get(27)) { - throw new IllegalStateException("rlpTxRcpt.LC_CORRECTION already set"); - } else { - filled.set(27); - } - - lcCorrection.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace limb(final Bytes b) { - if (filled.get(28)) { - throw new IllegalStateException("rlpTxRcpt.LIMB already set"); - } else { - filled.set(28); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - limb.put((byte) 0); - } - limb.put(b.toArrayUnsafe()); - - return this; - } - - public Trace limbConstructed(final Boolean b) { - if (filled.get(29)) { - throw new IllegalStateException("rlpTxRcpt.LIMB_CONSTRUCTED already set"); - } else { - filled.set(29); - } - - limbConstructed.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace localSize(final Bytes b) { - if (filled.get(30)) { - throw new IllegalStateException("rlpTxRcpt.LOCAL_SIZE already set"); - } else { - filled.set(30); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - localSize.put((byte) 0); - } - localSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace logEntrySize(final Bytes b) { - if (filled.get(31)) { - throw new IllegalStateException("rlpTxRcpt.LOG_ENTRY_SIZE already set"); - } else { - filled.set(31); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - logEntrySize.put((byte) 0); - } - logEntrySize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace nBytes(final UnsignedByte b) { - if (filled.get(41)) { - throw new IllegalStateException("rlpTxRcpt.nBYTES already set"); - } else { - filled.set(41); - } - - nBytes.put(b.toByte()); - - return this; - } - - public Trace nStep(final Bytes b) { - if (filled.get(42)) { - throw new IllegalStateException("rlpTxRcpt.nSTEP already set"); - } else { - filled.set(42); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nStep.put((byte) 0); - } - nStep.put(b.toArrayUnsafe()); - - return this; - } - - public Trace phase1(final Boolean b) { - if (filled.get(32)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_1 already set"); - } else { - filled.set(32); - } - - phase1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase2(final Boolean b) { - if (filled.get(33)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_2 already set"); - } else { - filled.set(33); - } - - phase2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase3(final Boolean b) { - if (filled.get(34)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_3 already set"); - } else { - filled.set(34); - } - - phase3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase4(final Boolean b) { - if (filled.get(35)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_4 already set"); - } else { - filled.set(35); - } - - phase4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phase5(final Boolean b) { - if (filled.get(36)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_5 already set"); - } else { - filled.set(36); - } - - phase5.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phaseEnd(final Boolean b) { - if (filled.get(37)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_END already set"); - } else { - filled.set(37); - } - - phaseEnd.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace phaseSize(final Bytes b) { - if (filled.get(38)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_SIZE already set"); - } else { - filled.set(38); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - phaseSize.put((byte) 0); - } - phaseSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace power(final Bytes b) { - if (filled.get(39)) { - throw new IllegalStateException("rlpTxRcpt.POWER already set"); - } else { - filled.set(39); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - power.put((byte) 0); - } - power.put(b.toArrayUnsafe()); - - return this; - } - - public Trace txrcptSize(final Bytes b) { - if (filled.get(40)) { - throw new IllegalStateException("rlpTxRcpt.TXRCPT_SIZE already set"); - } else { - filled.set(40); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - txrcptSize.put((byte) 0); - } - txrcptSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("rlpTxRcpt.ABS_LOG_NUM has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("rlpTxRcpt.ABS_LOG_NUM_MAX has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("rlpTxRcpt.ABS_TX_NUM has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("rlpTxRcpt.ABS_TX_NUM_MAX has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("rlpTxRcpt.ACC_1 has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("rlpTxRcpt.ACC_2 has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("rlpTxRcpt.ACC_3 has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("rlpTxRcpt.ACC_4 has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("rlpTxRcpt.ACC_SIZE has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("rlpTxRcpt.BIT has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("rlpTxRcpt.BIT_ACC has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("rlpTxRcpt.BYTE_1 has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("rlpTxRcpt.BYTE_2 has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("rlpTxRcpt.BYTE_3 has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("rlpTxRcpt.BYTE_4 has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("rlpTxRcpt.COUNTER has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("rlpTxRcpt.DEPTH_1 has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("rlpTxRcpt.DONE has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("rlpTxRcpt.INDEX has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("rlpTxRcpt.INDEX_LOCAL has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("rlpTxRcpt.INPUT_1 has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("rlpTxRcpt.INPUT_2 has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("rlpTxRcpt.INPUT_3 has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("rlpTxRcpt.INPUT_4 has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("rlpTxRcpt.IS_DATA has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("rlpTxRcpt.IS_PREFIX has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("rlpTxRcpt.IS_TOPIC has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("rlpTxRcpt.LC_CORRECTION has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("rlpTxRcpt.LIMB has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("rlpTxRcpt.LIMB_CONSTRUCTED has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("rlpTxRcpt.LOCAL_SIZE has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("rlpTxRcpt.LOG_ENTRY_SIZE has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("rlpTxRcpt.nBYTES has not been filled"); - } - - if (!filled.get(42)) { - throw new IllegalStateException("rlpTxRcpt.nSTEP has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_1 has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_2 has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_3 has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_4 has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_5 has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_END has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("rlpTxRcpt.PHASE_SIZE has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("rlpTxRcpt.POWER has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("rlpTxRcpt.TXRCPT_SIZE has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - absLogNum.position(absLogNum.position() + 32); - } - - if (!filled.get(1)) { - absLogNumMax.position(absLogNumMax.position() + 32); - } - - if (!filled.get(2)) { - absTxNum.position(absTxNum.position() + 32); - } - - if (!filled.get(3)) { - absTxNumMax.position(absTxNumMax.position() + 32); - } - - if (!filled.get(4)) { - acc1.position(acc1.position() + 32); - } - - if (!filled.get(5)) { - acc2.position(acc2.position() + 32); - } - - if (!filled.get(6)) { - acc3.position(acc3.position() + 32); - } - - if (!filled.get(7)) { - acc4.position(acc4.position() + 32); - } - - if (!filled.get(8)) { - accSize.position(accSize.position() + 32); - } - - if (!filled.get(9)) { - bit.position(bit.position() + 1); - } - - if (!filled.get(10)) { - bitAcc.position(bitAcc.position() + 1); - } - - if (!filled.get(11)) { - byte1.position(byte1.position() + 1); - } - - if (!filled.get(12)) { - byte2.position(byte2.position() + 1); - } - - if (!filled.get(13)) { - byte3.position(byte3.position() + 1); - } - - if (!filled.get(14)) { - byte4.position(byte4.position() + 1); - } - - if (!filled.get(15)) { - counter.position(counter.position() + 32); - } - - if (!filled.get(16)) { - depth1.position(depth1.position() + 1); - } - - if (!filled.get(17)) { - done.position(done.position() + 1); - } - - if (!filled.get(18)) { - index.position(index.position() + 32); - } - - if (!filled.get(19)) { - indexLocal.position(indexLocal.position() + 32); - } - - if (!filled.get(20)) { - input1.position(input1.position() + 32); - } - - if (!filled.get(21)) { - input2.position(input2.position() + 32); - } - - if (!filled.get(22)) { - input3.position(input3.position() + 32); - } - - if (!filled.get(23)) { - input4.position(input4.position() + 32); - } - - if (!filled.get(24)) { - isData.position(isData.position() + 1); - } - - if (!filled.get(25)) { - isPrefix.position(isPrefix.position() + 1); - } - - if (!filled.get(26)) { - isTopic.position(isTopic.position() + 1); - } - - if (!filled.get(27)) { - lcCorrection.position(lcCorrection.position() + 1); - } - - if (!filled.get(28)) { - limb.position(limb.position() + 32); - } - - if (!filled.get(29)) { - limbConstructed.position(limbConstructed.position() + 1); - } - - if (!filled.get(30)) { - localSize.position(localSize.position() + 32); - } - - if (!filled.get(31)) { - logEntrySize.position(logEntrySize.position() + 32); - } - - if (!filled.get(41)) { - nBytes.position(nBytes.position() + 1); - } - - if (!filled.get(42)) { - nStep.position(nStep.position() + 32); - } - - if (!filled.get(32)) { - phase1.position(phase1.position() + 1); - } - - if (!filled.get(33)) { - phase2.position(phase2.position() + 1); - } - - if (!filled.get(34)) { - phase3.position(phase3.position() + 1); - } - - if (!filled.get(35)) { - phase4.position(phase4.position() + 1); - } - - if (!filled.get(36)) { - phase5.position(phase5.position() + 1); - } - - if (!filled.get(37)) { - phaseEnd.position(phaseEnd.position() + 1); - } - - if (!filled.get(38)) { - phaseSize.position(phaseSize.position() + 32); - } - - if (!filled.get(39)) { - power.position(power.position() + 32); - } - - if (!filled.get(40)) { - txrcptSize.position(txrcptSize.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlputils/ByteCountAndPowerOutput.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlputils/ByteCountAndPowerOutput.java deleted file mode 100644 index ff0d56738..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlputils/ByteCountAndPowerOutput.java +++ /dev/null @@ -1,21 +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.rlputils; - -import java.math.BigInteger; -import java.util.List; - -public record ByteCountAndPowerOutput(List powerList, List accByteSizeList) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlputils/Pattern.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlputils/Pattern.java deleted file mode 100644 index 00cf0398e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlputils/Pattern.java +++ /dev/null @@ -1,108 +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.rlputils; - -import java.math.BigInteger; -import java.util.ArrayList; - -import com.google.common.base.Preconditions; -import org.apache.tuweni.bytes.Bytes; - -public class Pattern { - /** - * Returns the size of RLP(something) where something is of size inputSize (!=1) (it can be ZERO - * though). - */ - public static int outerRlpSize(int inputSize) { - int rlpSize = inputSize; - if (inputSize == 1) { - throw new IllegalArgumentException("Input size must be different from 1"); - } else { - rlpSize += 1; - if (inputSize >= 56) { - rlpSize += Bytes.minimalBytes(inputSize).size(); - } - } - return rlpSize; - } - - public static int innerRlpSize(int rlpSize) { - // If rlpSize >1, return size(something) where rlpSize = size(RLP(something)). - Preconditions.checkArgument(rlpSize >= 2, "rlpSize should be at least 2 to get its inner size"); - int output = rlpSize; - - if (rlpSize < 57) { - output -= 1; - } else if (rlpSize == 57) { - throw new RuntimeException("can't be of size 57"); - } else if (rlpSize < 258) { - output -= 2; - } else if (rlpSize == 258) { - throw new RuntimeException("can't be of size 258"); - } else { - for (int i = 1; i < 8; i++) { - if ((rlpSize - 2 - i >= Math.pow(2, 8 * i)) - && (rlpSize - i - 1 <= Math.pow(2, 8 * (i + 1)))) { - output -= (2 + i); - } else if (rlpSize == Math.pow(2, i) + 1 + i) { - throw new RuntimeException("can't be this size"); - } - } - } - return output; - } - - /** - * Create the Power and AccSize list of the ByteCountAndPower RLP pattern. - * - * @param inputByteLen represents the number of meaningful bytes of inputByte, i.e. without the - * zero left padding - * @param nbStep - * @return - */ - public static ByteCountAndPowerOutput byteCounting(int inputByteLen, int nbStep) { - - ArrayList powerInit = new ArrayList<>(nbStep); - ArrayList acc = new ArrayList<>(nbStep); - ByteCountAndPowerOutput output = new ByteCountAndPowerOutput(powerInit, acc); - - BigInteger power; - int accByteSize = 0; - int offset = 16 - nbStep; - - if (inputByteLen == nbStep) { - power = BigInteger.valueOf(256).pow(offset); - accByteSize = 1; - } else { - offset += 1; - power = BigInteger.valueOf(256).pow(offset); - } - - output.powerList().add(0, power); - output.accByteSizeList().add(0, accByteSize); - - for (int i = 1; i < nbStep; i++) { - if (inputByteLen + i < nbStep) { - power = power.multiply(BigInteger.valueOf(256)); - } else { - accByteSize += 1; - } - output.powerList().add(i, power); - output.accByteSizeList().add(i, accByteSize); - } - return output; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Rom.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Rom.java deleted file mode 100644 index c0ff698f6..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Rom.java +++ /dev/null @@ -1,65 +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.rom; - -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.module.romLex.RomChunk; -import net.consensys.linea.zktracer.module.romLex.RomLex; - -public class Rom implements Module { - private final RomLex romLex; - - public Rom(RomLex _romLex) { - this.romLex = _romLex; - } - - @Override - public String moduleKey() { - return "ROM"; - } - - @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - return this.romLex.chunks.lineCount(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - int cfi = 0; - final int cfiInfty = this.romLex.sortedChunks.size(); - for (RomChunk chunk : this.romLex.sortedChunks) { - cfi += 1; - chunk.trace(trace, cfi, cfiInfty); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Trace.java deleted file mode 100644 index 28218a01f..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Trace.java +++ /dev/null @@ -1,665 +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.rom; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer acc; - private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer codeFragmentIndexInfty; - private final MappedByteBuffer codeSize; - private final MappedByteBuffer codesizeReached; - private final MappedByteBuffer counter; - private final MappedByteBuffer counterMax; - private final MappedByteBuffer counterPush; - private final MappedByteBuffer index; - private final MappedByteBuffer isPush; - private final MappedByteBuffer isPushData; - private final MappedByteBuffer limb; - private final MappedByteBuffer nBytes; - private final MappedByteBuffer nBytesAcc; - private final MappedByteBuffer opcode; - private final MappedByteBuffer paddedBytecodeByte; - private final MappedByteBuffer programmeCounter; - private final MappedByteBuffer pushFunnelBit; - private final MappedByteBuffer pushParameter; - private final MappedByteBuffer pushValueAcc; - private final MappedByteBuffer pushValueHigh; - private final MappedByteBuffer pushValueLow; - private final MappedByteBuffer validJumpDestination; - - static List headers(int length) { - return List.of( - new ColumnHeader("rom.ACC", 32, length), - new ColumnHeader("rom.CODE_FRAGMENT_INDEX", 32, length), - new ColumnHeader("rom.CODE_FRAGMENT_INDEX_INFTY", 32, length), - new ColumnHeader("rom.CODE_SIZE", 32, length), - new ColumnHeader("rom.CODESIZE_REACHED", 1, length), - new ColumnHeader("rom.COUNTER", 32, length), - new ColumnHeader("rom.COUNTER_MAX", 32, length), - new ColumnHeader("rom.COUNTER_PUSH", 32, length), - new ColumnHeader("rom.INDEX", 32, length), - new ColumnHeader("rom.IS_PUSH", 1, length), - new ColumnHeader("rom.IS_PUSH_DATA", 1, length), - new ColumnHeader("rom.LIMB", 32, length), - new ColumnHeader("rom.nBYTES", 32, length), - new ColumnHeader("rom.nBYTES_ACC", 32, length), - new ColumnHeader("rom.OPCODE", 1, length), - new ColumnHeader("rom.PADDED_BYTECODE_BYTE", 1, length), - new ColumnHeader("rom.PROGRAMME_COUNTER", 32, length), - new ColumnHeader("rom.PUSH_FUNNEL_BIT", 1, length), - new ColumnHeader("rom.PUSH_PARAMETER", 32, length), - new ColumnHeader("rom.PUSH_VALUE_ACC", 32, length), - new ColumnHeader("rom.PUSH_VALUE_HIGH", 32, length), - new ColumnHeader("rom.PUSH_VALUE_LOW", 32, length), - new ColumnHeader("rom.VALID_JUMP_DESTINATION", 1, length)); - } - - public Trace(List buffers) { - this.acc = buffers.get(0); - this.codeFragmentIndex = buffers.get(1); - this.codeFragmentIndexInfty = buffers.get(2); - this.codeSize = buffers.get(3); - this.codesizeReached = buffers.get(4); - this.counter = buffers.get(5); - this.counterMax = buffers.get(6); - this.counterPush = buffers.get(7); - this.index = buffers.get(8); - this.isPush = buffers.get(9); - this.isPushData = buffers.get(10); - this.limb = buffers.get(11); - this.nBytes = buffers.get(12); - this.nBytesAcc = buffers.get(13); - this.opcode = buffers.get(14); - this.paddedBytecodeByte = buffers.get(15); - this.programmeCounter = buffers.get(16); - this.pushFunnelBit = buffers.get(17); - this.pushParameter = buffers.get(18); - this.pushValueAcc = buffers.get(19); - this.pushValueHigh = buffers.get(20); - this.pushValueLow = buffers.get(21); - this.validJumpDestination = buffers.get(22); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace acc(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("rom.ACC already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc.put((byte) 0); - } - acc.put(b.toArrayUnsafe()); - - return this; - } - - public Trace codeFragmentIndex(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("rom.CODE_FRAGMENT_INDEX already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeFragmentIndex.put((byte) 0); - } - codeFragmentIndex.put(b.toArrayUnsafe()); - - return this; - } - - public Trace codeFragmentIndexInfty(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("rom.CODE_FRAGMENT_INDEX_INFTY already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeFragmentIndexInfty.put((byte) 0); - } - codeFragmentIndexInfty.put(b.toArrayUnsafe()); - - return this; - } - - public Trace codeSize(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("rom.CODE_SIZE already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSize.put((byte) 0); - } - codeSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace codesizeReached(final Boolean b) { - if (filled.get(1)) { - throw new IllegalStateException("rom.CODESIZE_REACHED already set"); - } else { - filled.set(1); - } - - codesizeReached.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace counter(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("rom.COUNTER already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - counter.put((byte) 0); - } - counter.put(b.toArrayUnsafe()); - - return this; - } - - public Trace counterMax(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("rom.COUNTER_MAX already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - counterMax.put((byte) 0); - } - counterMax.put(b.toArrayUnsafe()); - - return this; - } - - public Trace counterPush(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("rom.COUNTER_PUSH already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - counterPush.put((byte) 0); - } - counterPush.put(b.toArrayUnsafe()); - - return this; - } - - public Trace index(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("rom.INDEX already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - index.put((byte) 0); - } - index.put(b.toArrayUnsafe()); - - return this; - } - - public Trace isPush(final Boolean b) { - if (filled.get(9)) { - throw new IllegalStateException("rom.IS_PUSH already set"); - } else { - filled.set(9); - } - - isPush.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isPushData(final Boolean b) { - if (filled.get(10)) { - throw new IllegalStateException("rom.IS_PUSH_DATA already set"); - } else { - filled.set(10); - } - - isPushData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace limb(final Bytes b) { - if (filled.get(11)) { - throw new IllegalStateException("rom.LIMB already set"); - } else { - filled.set(11); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - limb.put((byte) 0); - } - limb.put(b.toArrayUnsafe()); - - return this; - } - - public Trace nBytes(final Bytes b) { - if (filled.get(21)) { - throw new IllegalStateException("rom.nBYTES already set"); - } else { - filled.set(21); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nBytes.put((byte) 0); - } - nBytes.put(b.toArrayUnsafe()); - - return this; - } - - public Trace nBytesAcc(final Bytes b) { - if (filled.get(22)) { - throw new IllegalStateException("rom.nBYTES_ACC already set"); - } else { - filled.set(22); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nBytesAcc.put((byte) 0); - } - nBytesAcc.put(b.toArrayUnsafe()); - - return this; - } - - public Trace opcode(final UnsignedByte b) { - if (filled.get(12)) { - throw new IllegalStateException("rom.OPCODE already set"); - } else { - filled.set(12); - } - - opcode.put(b.toByte()); - - return this; - } - - public Trace paddedBytecodeByte(final UnsignedByte b) { - if (filled.get(13)) { - throw new IllegalStateException("rom.PADDED_BYTECODE_BYTE already set"); - } else { - filled.set(13); - } - - paddedBytecodeByte.put(b.toByte()); - - return this; - } - - public Trace programmeCounter(final Bytes b) { - if (filled.get(14)) { - throw new IllegalStateException("rom.PROGRAMME_COUNTER already set"); - } else { - filled.set(14); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - programmeCounter.put((byte) 0); - } - programmeCounter.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pushFunnelBit(final Boolean b) { - if (filled.get(15)) { - throw new IllegalStateException("rom.PUSH_FUNNEL_BIT already set"); - } else { - filled.set(15); - } - - pushFunnelBit.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pushParameter(final Bytes b) { - if (filled.get(16)) { - throw new IllegalStateException("rom.PUSH_PARAMETER already set"); - } else { - filled.set(16); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - pushParameter.put((byte) 0); - } - pushParameter.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pushValueAcc(final Bytes b) { - if (filled.get(17)) { - throw new IllegalStateException("rom.PUSH_VALUE_ACC already set"); - } else { - filled.set(17); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - pushValueAcc.put((byte) 0); - } - pushValueAcc.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pushValueHigh(final Bytes b) { - if (filled.get(18)) { - throw new IllegalStateException("rom.PUSH_VALUE_HIGH already set"); - } else { - filled.set(18); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - pushValueHigh.put((byte) 0); - } - pushValueHigh.put(b.toArrayUnsafe()); - - return this; - } - - public Trace pushValueLow(final Bytes b) { - if (filled.get(19)) { - throw new IllegalStateException("rom.PUSH_VALUE_LOW already set"); - } else { - filled.set(19); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - pushValueLow.put((byte) 0); - } - pushValueLow.put(b.toArrayUnsafe()); - - return this; - } - - public Trace validJumpDestination(final Boolean b) { - if (filled.get(20)) { - throw new IllegalStateException("rom.VALID_JUMP_DESTINATION already set"); - } else { - filled.set(20); - } - - validJumpDestination.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("rom.ACC has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("rom.CODE_FRAGMENT_INDEX has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("rom.CODE_FRAGMENT_INDEX_INFTY has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("rom.CODE_SIZE has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("rom.CODESIZE_REACHED has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("rom.COUNTER has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("rom.COUNTER_MAX has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("rom.COUNTER_PUSH has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("rom.INDEX has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("rom.IS_PUSH has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("rom.IS_PUSH_DATA has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("rom.LIMB has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("rom.nBYTES has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("rom.nBYTES_ACC has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("rom.OPCODE has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("rom.PADDED_BYTECODE_BYTE has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("rom.PROGRAMME_COUNTER has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("rom.PUSH_FUNNEL_BIT has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("rom.PUSH_PARAMETER has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("rom.PUSH_VALUE_ACC has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("rom.PUSH_VALUE_HIGH has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("rom.PUSH_VALUE_LOW has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("rom.VALID_JUMP_DESTINATION has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - acc.position(acc.position() + 32); - } - - if (!filled.get(2)) { - codeFragmentIndex.position(codeFragmentIndex.position() + 32); - } - - if (!filled.get(3)) { - codeFragmentIndexInfty.position(codeFragmentIndexInfty.position() + 32); - } - - if (!filled.get(4)) { - codeSize.position(codeSize.position() + 32); - } - - if (!filled.get(1)) { - codesizeReached.position(codesizeReached.position() + 1); - } - - if (!filled.get(5)) { - counter.position(counter.position() + 32); - } - - if (!filled.get(6)) { - counterMax.position(counterMax.position() + 32); - } - - if (!filled.get(7)) { - counterPush.position(counterPush.position() + 32); - } - - if (!filled.get(8)) { - index.position(index.position() + 32); - } - - if (!filled.get(9)) { - isPush.position(isPush.position() + 1); - } - - if (!filled.get(10)) { - isPushData.position(isPushData.position() + 1); - } - - if (!filled.get(11)) { - limb.position(limb.position() + 32); - } - - if (!filled.get(21)) { - nBytes.position(nBytes.position() + 32); - } - - if (!filled.get(22)) { - nBytesAcc.position(nBytesAcc.position() + 32); - } - - if (!filled.get(12)) { - opcode.position(opcode.position() + 1); - } - - if (!filled.get(13)) { - paddedBytecodeByte.position(paddedBytecodeByte.position() + 1); - } - - if (!filled.get(14)) { - programmeCounter.position(programmeCounter.position() + 32); - } - - if (!filled.get(15)) { - pushFunnelBit.position(pushFunnelBit.position() + 1); - } - - if (!filled.get(16)) { - pushParameter.position(pushParameter.position() + 32); - } - - if (!filled.get(17)) { - pushValueAcc.position(pushValueAcc.position() + 32); - } - - if (!filled.get(18)) { - pushValueHigh.position(pushValueHigh.position() + 32); - } - - if (!filled.get(19)) { - pushValueLow.position(pushValueLow.position() + 32); - } - - if (!filled.get(20)) { - validJumpDestination.position(validJumpDestination.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/RomChunk.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/RomChunk.java deleted file mode 100644 index 897efdcdc..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/RomChunk.java +++ /dev/null @@ -1,177 +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.romLex; - -import static net.consensys.linea.zktracer.types.Utils.rightPadTo; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.module.rom.Trace; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; - -@RequiredArgsConstructor -@Accessors(fluent = true) -@Getter -@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) -public final class RomChunk extends ModuleOperation { - private static final int LLARGE = 16; - private static final Bytes BYTES_LLARGE = Bytes.of(LLARGE); - private static final int LLARGE_MO = 15; - private static final Bytes BYTES_LLARGE_MO = Bytes.of(LLARGE_MO); - private static final int EVM_WORD_MO = 31; - private static final Bytes BYTES_EVW_WORD_MO = Bytes.of(EVM_WORD_MO); - private static final int PUSH_1 = 0x60; - private static final int PUSH_32 = 0x7f; - private static final UnsignedByte INVALID = UnsignedByte.of(0xFE); - private static final int JUMPDEST = 0x5b; - - @EqualsAndHashCode.Include private final int id; - private final Address address; - private final int deploymentNumber; - private final boolean deploymentStatus; - private final boolean readFromTheState; - private final boolean commitToTheState; - private final Bytes byteCode; - - public void trace(Trace trace, int cfi, int cfiInfty) { - final int chunkRowSize = this.lineCount(); - final int codeSize = this.byteCode().size(); - final int nLimbSlice = (codeSize + (LLARGE - 1)) / LLARGE; - final Bytes dataPadded = rightPadTo(this.byteCode(), chunkRowSize); - int nBytesLastRow = codeSize % LLARGE; - if (nBytesLastRow == 0) { - nBytesLastRow = LLARGE; - } - - int pushParameter = 0; - int ctPush = 0; - Bytes pushValueHigh = Bytes.minimalBytes(0); - Bytes pushValueLow = Bytes.minimalBytes(0); - - for (int i = 0; i < chunkRowSize; i++) { - boolean codeSizeReached = i >= codeSize; - int sliceNumber = i / 16; - - // Fill Generic columns - trace - .codeFragmentIndex(Bytes.ofUnsignedInt(cfi)) - .codeFragmentIndexInfty(Bytes.ofUnsignedInt(cfiInfty)) - .programmeCounter(Bytes.ofUnsignedInt(i)) - .limb(dataPadded.slice(sliceNumber * LLARGE, LLARGE)) - .codeSize(Bytes.ofUnsignedInt(codeSize)) - .paddedBytecodeByte(UnsignedByte.of(dataPadded.get(i))) - .acc(dataPadded.slice(sliceNumber * LLARGE, (i % LLARGE) + 1)) - .codesizeReached(codeSizeReached) - .index(Bytes.ofUnsignedInt(sliceNumber)); - - // Fill CT, CTmax nBYTES, nBYTES_ACC - if (sliceNumber < nLimbSlice) { - trace.counter(Bytes.of(i % LLARGE)).counterMax(BYTES_LLARGE_MO); - if (sliceNumber < nLimbSlice - 1) { - trace.nBytes(BYTES_LLARGE).nBytesAcc(Bytes.of((i % LLARGE) + 1)); - } - if (sliceNumber == nLimbSlice - 1) { - trace - .nBytes(Bytes.of(nBytesLastRow)) - .nBytesAcc(Bytes.of(Math.min(nBytesLastRow, (i % LLARGE) + 1))); - } - } else if (sliceNumber == nLimbSlice || sliceNumber == nLimbSlice + 1) { - trace - .counter(Bytes.of(i - nLimbSlice * LLARGE)) - .counterMax(BYTES_EVW_WORD_MO) - .nBytes(Bytes.EMPTY) - .nBytesAcc(Bytes.EMPTY); - } - - // Deal when not in a PUSH instruction - if (pushParameter == 0) { - UnsignedByte opCode = UnsignedByte.of(dataPadded.get(i)); - final boolean isPush = PUSH_1 <= opCode.toInteger() && opCode.toInteger() <= PUSH_32; - - // The OpCode is a PUSH instruction - if (isPush) { - pushParameter = opCode.toInteger() - PUSH_1 + 1; - if (pushParameter > LLARGE) { - pushValueHigh = dataPadded.slice(i + 1, pushParameter - LLARGE); - pushValueLow = dataPadded.slice(i + 1 + pushParameter - LLARGE, LLARGE); - } else { - pushValueLow = dataPadded.slice(i + 1, pushParameter); - } - } - - trace - .isPush(isPush) - .isPushData(false) - .opcode(opCode) - .pushParameter(Bytes.ofUnsignedShort(pushParameter)) - .counterPush(Bytes.EMPTY) - .pushValueAcc(Bytes.EMPTY) - .pushValueHigh(pushValueHigh) - .pushValueLow(pushValueLow) - .pushFunnelBit(false) - .validJumpDestination(opCode.toInteger() == JUMPDEST); - } - // Deal when in a PUSH instruction - else { - ctPush += 1; - trace - .isPush(false) - .isPushData(true) - .opcode(INVALID) - .pushParameter(Bytes.ofUnsignedShort(pushParameter)) - .pushValueHigh(pushValueHigh) - .pushValueLow(pushValueLow) - .counterPush(Bytes.of(ctPush)) - .pushFunnelBit(pushParameter > LLARGE && ctPush > pushParameter - LLARGE) - .validJumpDestination(false); - - if (pushParameter <= LLARGE) { - trace.pushValueAcc(pushValueLow.slice(0, ctPush)); - } else { - if (ctPush <= pushParameter - LLARGE) { - trace.pushValueAcc(pushValueHigh.slice(0, ctPush)); - } else { - trace.pushValueAcc(pushValueLow.slice(0, ctPush + LLARGE - pushParameter)); - } - } - - // reinitialise push constant data - if (ctPush == pushParameter) { - ctPush = 0; - pushParameter = 0; - pushValueHigh = Bytes.minimalBytes(0); - pushValueLow = Bytes.minimalBytes(0); - } - } - - trace.validateRow(); - } - } - - @Override - protected int computeLineCount() { - final int nPaddingRow = 32; - final int codeSize = this.byteCode.size(); - final int nbSlice = (codeSize + (LLARGE - 1)) / LLARGE; - - return LLARGE * nbSlice + nPaddingRow; - } -} 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 deleted file mode 100644 index 95671e73b..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/RomLex.java +++ /dev/null @@ -1,318 +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.romLex; - -import static net.consensys.linea.zktracer.types.AddressUtils.getCreate2Address; -import static net.consensys.linea.zktracer.types.AddressUtils.getCreateAddress; -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import java.nio.MappedByteBuffer; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; - -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.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Transaction; -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; - -public class RomLex implements Module { - private static final int LLARGE = 16; - private static final RomChunkComparator romChunkComparator = new RomChunkComparator(); - - private final Hub hub; - public int codeIdentifierBeforeLexOrder = 0; - - public final StackedSet chunks = new StackedSet<>(); - public final List sortedChunks = new ArrayList<>(); - private Bytes byteCode = Bytes.EMPTY; - private Address address = Address.ZERO; - - static class RomChunkComparator implements Comparator { - // Initialize the ChunkList - public int compare(RomChunk chunk1, RomChunk chunk2) { - // First sort by Address - int addressComparison = chunk1.address().compareTo(chunk2.address()); - if (addressComparison != 0) { - return addressComparison; - } else { - // Second, sort by Deployment Number - int deploymentNumberComparison = chunk1.deploymentNumber() - chunk2.deploymentNumber(); - if (deploymentNumberComparison != 0) { - return deploymentNumberComparison; - } else { - // Third sort by Deployment Status (true greater) - if (chunk1.deploymentStatus() == chunk2.deploymentStatus()) { - return 0; - } else { - return chunk1.deploymentStatus() ? -1 : 1; - } - } - } - } - } - - @Override - public String moduleKey() { - return "ROM_LEX"; - } - - public RomLex(Hub hub) { - this.hub = hub; - } - - @Override - public void enterTransaction() { - this.chunks.enter(); - } - - @Override - public void popTransaction() { - this.chunks.pop(); - } - - public int getCFIById(int value) { - if (this.sortedChunks.isEmpty()) { - throw new RuntimeException("Chunks have not been sorted yet"); - } - - int codeFragmentIndex = -1; - for (int i = 0; i < this.sortedChunks.size(); i++) { - if (this.sortedChunks.get(i).id() == value) { - codeFragmentIndex = i + 1; - } - } - - if (codeFragmentIndex < 0) { - throw new RuntimeException("RomChunk n°" + value + " not found"); - } - - return codeFragmentIndex; - } - - @Override - public void traceStartTx(WorldView worldView, Transaction tx) { - // Contract creation with InitCode - if (tx.getInit().isPresent() && !tx.getInit().orElseThrow().isEmpty()) { - codeIdentifierBeforeLexOrder += 1; - this.chunks.add( - new RomChunk( - codeIdentifierBeforeLexOrder, - Address.contractAddress(tx.getSender(), tx.getNonce()), - 1, - true, - false, - false, - tx.getInit().get())); - } - - // Call to an account with bytecode - tx.getTo() - .map(worldView::get) - .map(AccountState::getCode) - .ifPresent( - code -> { - codeIdentifierBeforeLexOrder += 1; - int depNumber = hub.conflation().deploymentInfo().number(tx.getTo().get()); - boolean depStatus = hub.conflation().deploymentInfo().isDeploying(tx.getTo().get()); - - this.chunks.add( - new RomChunk( - codeIdentifierBeforeLexOrder, - tx.getTo().get(), - depNumber, - depStatus, - true, - false, - code)); - }); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - OpCode opcode = this.hub.opCode(); - - switch (opcode) { - case CREATE -> { - this.address = getCreateAddress(frame); - final long offset = clampedToLong(frame.getStackItem(1)); - final long length = clampedToLong(frame.getStackItem(2)); - this.byteCode = frame.shadowReadMemory(offset, length); - if (!this.byteCode.isEmpty()) { - codeIdentifierBeforeLexOrder += 1; - } - } - - case CREATE2 -> { - final long offset = clampedToLong(frame.getStackItem(1)); - final long length = clampedToLong(frame.getStackItem(2)); - this.byteCode = frame.shadowReadMemory(offset, length); - - if (!this.byteCode.isEmpty()) { - codeIdentifierBeforeLexOrder += 1; - this.address = getCreate2Address(frame); - } - } - - case RETURN -> { - final long offset = clampedToLong(frame.getStackItem(0)); - final long length = clampedToLong(frame.getStackItem(1)); - final Bytes code = frame.shadowReadMemory(offset, length); - final boolean depStatus = - hub.conflation().deploymentInfo().isDeploying(frame.getContractAddress()); - if (!code.isEmpty() && depStatus) { - codeIdentifierBeforeLexOrder += 1; - int depNumber = hub.conflation().deploymentInfo().number(frame.getContractAddress()); - this.chunks.add( - new RomChunk( - codeIdentifierBeforeLexOrder, - frame.getContractAddress(), - depNumber, - depStatus, - true, - false, - code)); - } - } - - case CALL, CALLCODE, DELEGATECALL, STATICCALL -> { - final Address calledAddress = Words.toAddress(frame.getStackItem(1)); - final boolean depStatus = - hub.conflation().deploymentInfo().isDeploying(frame.getContractAddress()); - final int depNumber = hub.conflation().deploymentInfo().number(frame.getContractAddress()); - Optional.ofNullable(frame.getWorldUpdater().get(calledAddress)) - .map(AccountState::getCode) - .ifPresent( - byteCode -> { - codeIdentifierBeforeLexOrder += 1; - this.chunks.add( - new RomChunk( - codeIdentifierBeforeLexOrder, - calledAddress, - depNumber, - depStatus, - true, - false, - byteCode)); - }); - } - - case EXTCODECOPY -> { - final Address calledAddress = Words.toAddress(frame.getStackItem(0)); - final long length = Words.clampedToLong(frame.getStackItem(3)); - final boolean isDeploying = - hub.conflation().deploymentInfo().isDeploying(frame.getContractAddress()); - if (length == 0 || isDeploying) { - return; - } - final int depNumber = hub.conflation().deploymentInfo().number(frame.getContractAddress()); - Optional.ofNullable(frame.getWorldUpdater().get(calledAddress)) - .map(AccountState::getCode) - .ifPresent( - byteCode -> { - if (!byteCode.isEmpty()) { - codeIdentifierBeforeLexOrder += 1; - this.chunks.add( - new RomChunk( - codeIdentifierBeforeLexOrder, - calledAddress, - depNumber, - isDeploying, - true, - false, - byteCode)); - } - }); - } - } - } - - @Override - public void tracePostExecution(MessageFrame frame, Operation.OperationResult operationResult) { - OpCode opcode = OpCode.of(frame.getCurrentOperation().getOpcode()); - switch (opcode) { - case CREATE, CREATE2 -> { - final int depNumber = hub.conflation().deploymentInfo().number(this.address); - final boolean depStatus = hub.conflation().deploymentInfo().isDeploying(this.address); - - this.chunks.add( - new RomChunk( - codeIdentifierBeforeLexOrder, - this.address, - depNumber, - depStatus, - true, - false, - this.byteCode)); - } - } - } - - private void traceChunk( - final RomChunk chunk, int cfi, int codeFragmentIndexInfinity, Trace trace) { - trace - .codeFragmentIndex(Bytes.ofUnsignedInt(cfi)) - .codeFragmentIndexInfty(Bytes.ofUnsignedInt(codeFragmentIndexInfinity)) - .codeSize(Bytes.ofUnsignedInt(chunk.byteCode().size())) - .addrHi(chunk.address().slice(0, 4)) - .addrLo(chunk.address().slice(4, LLARGE)) - .commitToState(chunk.commitToTheState()) - .depNumber(Bytes.ofUnsignedInt(chunk.deploymentNumber())) - .depStatus(chunk.deploymentStatus()) - .readFromState(chunk.readFromTheState()) - .validateRow(); - } - - @Override - public void traceEndConflation() { - this.sortedChunks.addAll(this.chunks); - this.sortedChunks.sort(romChunkComparator); - } - - @Override - public int lineCount() { - // WARN: the line count for the RomLex is the *number of code fragments*, not their actual line - // count – that's for the ROM. - return this.chunks.size(); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - final int codeFragmentIndexInfinity = chunks.size(); - - int cfi = 0; - for (RomChunk chunk : sortedChunks) { - cfi += 1; - traceChunk(chunk, cfi, codeFragmentIndexInfinity, trace); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/Trace.java deleted file mode 100644 index 84816eb0c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/Trace.java +++ /dev/null @@ -1,302 +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.romLex; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer addrHi; - private final MappedByteBuffer addrLo; - private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer codeFragmentIndexInfty; - private final MappedByteBuffer codeSize; - private final MappedByteBuffer commitToState; - private final MappedByteBuffer depNumber; - private final MappedByteBuffer depStatus; - private final MappedByteBuffer readFromState; - - static List headers(int length) { - return List.of( - new ColumnHeader("romLex.ADDR_HI", 32, length), - new ColumnHeader("romLex.ADDR_LO", 32, length), - new ColumnHeader("romLex.CODE_FRAGMENT_INDEX", 32, length), - new ColumnHeader("romLex.CODE_FRAGMENT_INDEX_INFTY", 32, length), - new ColumnHeader("romLex.CODE_SIZE", 32, length), - new ColumnHeader("romLex.COMMIT_TO_STATE", 1, length), - new ColumnHeader("romLex.DEP_NUMBER", 32, length), - new ColumnHeader("romLex.DEP_STATUS", 1, length), - new ColumnHeader("romLex.READ_FROM_STATE", 1, length)); - } - - public Trace(List buffers) { - this.addrHi = buffers.get(0); - this.addrLo = buffers.get(1); - this.codeFragmentIndex = buffers.get(2); - this.codeFragmentIndexInfty = buffers.get(3); - this.codeSize = buffers.get(4); - this.commitToState = buffers.get(5); - this.depNumber = buffers.get(6); - this.depStatus = buffers.get(7); - this.readFromState = buffers.get(8); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace addrHi(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("romLex.ADDR_HI already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrHi.put((byte) 0); - } - addrHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace addrLo(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("romLex.ADDR_LO already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrLo.put((byte) 0); - } - addrLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace codeFragmentIndex(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("romLex.CODE_FRAGMENT_INDEX already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeFragmentIndex.put((byte) 0); - } - codeFragmentIndex.put(b.toArrayUnsafe()); - - return this; - } - - public Trace codeFragmentIndexInfty(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("romLex.CODE_FRAGMENT_INDEX_INFTY already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeFragmentIndexInfty.put((byte) 0); - } - codeFragmentIndexInfty.put(b.toArrayUnsafe()); - - return this; - } - - public Trace codeSize(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("romLex.CODE_SIZE already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSize.put((byte) 0); - } - codeSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace commitToState(final Boolean b) { - if (filled.get(5)) { - throw new IllegalStateException("romLex.COMMIT_TO_STATE already set"); - } else { - filled.set(5); - } - - commitToState.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace depNumber(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("romLex.DEP_NUMBER already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - depNumber.put((byte) 0); - } - depNumber.put(b.toArrayUnsafe()); - - return this; - } - - public Trace depStatus(final Boolean b) { - if (filled.get(7)) { - throw new IllegalStateException("romLex.DEP_STATUS already set"); - } else { - filled.set(7); - } - - depStatus.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace readFromState(final Boolean b) { - if (filled.get(8)) { - throw new IllegalStateException("romLex.READ_FROM_STATE already set"); - } else { - filled.set(8); - } - - readFromState.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("romLex.ADDR_HI has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("romLex.ADDR_LO has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("romLex.CODE_FRAGMENT_INDEX has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("romLex.CODE_FRAGMENT_INDEX_INFTY has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("romLex.CODE_SIZE has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("romLex.COMMIT_TO_STATE has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("romLex.DEP_NUMBER has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("romLex.DEP_STATUS has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("romLex.READ_FROM_STATE has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - addrHi.position(addrHi.position() + 32); - } - - if (!filled.get(1)) { - addrLo.position(addrLo.position() + 32); - } - - if (!filled.get(2)) { - codeFragmentIndex.position(codeFragmentIndex.position() + 32); - } - - if (!filled.get(3)) { - codeFragmentIndexInfty.position(codeFragmentIndexInfty.position() + 32); - } - - if (!filled.get(4)) { - codeSize.position(codeSize.position() + 32); - } - - if (!filled.get(5)) { - commitToState.position(commitToState.position() + 1); - } - - if (!filled.get(6)) { - depNumber.position(depNumber.position() + 32); - } - - if (!filled.get(7)) { - depStatus.position(depStatus.position() + 1); - } - - if (!filled.get(8)) { - readFromState.position(readFromState.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ByteChunks.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ByteChunks.java deleted file mode 100644 index 6ea75bb97..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ByteChunks.java +++ /dev/null @@ -1,36 +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.shf; - -import net.consensys.linea.zktracer.types.UnsignedByte; - -public record ByteChunks(UnsignedByte ra, UnsignedByte la, UnsignedByte ones) { - - public static ByteChunks fromBytes(final UnsignedByte b, final UnsignedByte mshp) { - if (mshp.toInteger() > 8) { - String s = - String.format("chunksFromByte given mshp = %d not in {0,1,...,8}", mshp.toInteger()); - throw new IllegalArgumentException(s); - } - - final UnsignedByte mshpCmp = UnsignedByte.of(8 - mshp.toInteger()); - final UnsignedByte ra = b.shiftRight(mshp); - final UnsignedByte la = b.shiftLeft(mshpCmp); - final UnsignedByte ones = UnsignedByte.of(255).shiftLeft(mshpCmp); - - return new ByteChunks(ra, la, ones); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Res.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Res.java deleted file mode 100644 index 478b95a03..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Res.java +++ /dev/null @@ -1,48 +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.shf; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.Bytes16; -import org.apache.tuweni.bytes.Bytes32; - -@RequiredArgsConstructor -public class Res { - @Getter final Bytes16 resHi; - @Getter final Bytes16 resLo; - - public static Res create(final OpCode opCode, final Bytes32 arg1, final Bytes32 arg2) { - final Bytes32 result = Shifter.shift(opCode, arg2, shiftBy(arg1)); - - return new Res(Bytes16.wrap(result.slice(0, 16)), Bytes16.wrap(result.slice(16))); - } - - private static int shiftBy(final Bytes32 arg) { - return allButLastByteZero(arg) ? arg.get(31) & 0xff : 256; - } - - private static boolean allButLastByteZero(final Bytes32 bytes) { - for (int i = 0; i < 31; i++) { - if (bytes.get(i) != 0) { - return false; - } - } - - return true; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shb.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shb.java deleted file mode 100644 index b12463995..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shb.java +++ /dev/null @@ -1,52 +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.shf; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes32; - -@RequiredArgsConstructor -public class Shb { - - @Getter private final UnsignedByte[][] shbHi; - @Getter private final UnsignedByte[][] shbLo; - - public static Shb create(final OpCode opCode, final Bytes32 arg2, final UnsignedByte lsb) { - final UnsignedByte[][] shbHi = new UnsignedByte[5][16]; - final UnsignedByte[][] shbLo = new UnsignedByte[5][16]; - - for (int i = 3; i < 8; i++) { - final UnsignedByte shiftAmount = (lsb.shiftLeft(8 - i)).shiftRight(8 - i); - - Bytes32 shiftedBytes = Shifter.shift(opCode, arg2, shiftAmount.toInteger()); - - final byte[] shbHiByteArray = shiftedBytes.slice(0, 16).toArray(); - for (int j = 0; j < shbHiByteArray.length; j++) { - shbHi[i - 3][j] = UnsignedByte.of(shbHiByteArray[j]); - } - - final byte[] shbLoByteArray = shiftedBytes.slice(16).toArray(); - for (int j = 0; j < shbLoByteArray.length; j++) { - shbLo[i - 3][j] = UnsignedByte.of(shbLoByteArray[j]); - } - } - - return new Shb(shbHi, shbLo); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shf.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shf.java deleted file mode 100644 index 8b4186bb6..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shf.java +++ /dev/null @@ -1,74 +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.shf; - -import java.nio.MappedByteBuffer; -import java.util.List; - -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 org.apache.tuweni.bytes.Bytes32; -import org.hyperledger.besu.evm.frame.MessageFrame; - -public class Shf implements Module { - private final StackedSet operations = new StackedSet<>(); - - @Override - public String moduleKey() { - return "SHF"; - } - - @Override - public void enterTransaction() { - this.operations.enter(); - } - - @Override - public void popTransaction() { - this.operations.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final Bytes32 arg1 = Bytes32.leftPad(frame.getStackItem(0)); - final Bytes32 arg2 = Bytes32.leftPad(frame.getStackItem(1)); - this.operations.add( - new ShfOperation(OpCode.of(frame.getCurrentOperation().getOpcode()), arg1, arg2)); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - int stamp = 0; - for (ShfOperation op : this.operations) { - stamp++; - op.trace(trace, stamp); - } - } - - @Override - public int lineCount() { - return this.operations.lineCount(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ShfOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ShfOperation.java deleted file mode 100644 index 046855e8d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ShfOperation.java +++ /dev/null @@ -1,208 +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.shf; - -import static net.consensys.linea.zktracer.module.Util.byteBits; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import lombok.EqualsAndHashCode; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.Bytes16; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; - -@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) -final class ShfOperation extends ModuleOperation { - private static final int LIMB_SIZE = 16; - - @EqualsAndHashCode.Include private final OpCode opCode; - @EqualsAndHashCode.Include private final Bytes32 arg1; - @EqualsAndHashCode.Include private final Bytes32 arg2; - private final boolean isOneLineInstruction; - private boolean isNegative; - private boolean isShiftRight; - private boolean isKnown; - private UnsignedByte low3; - private UnsignedByte mshp; - private List bits; - private Shb shb; - private Res res; - private boolean isBitB3; - private boolean isBitB4; - private boolean isBitB5; - private boolean isBitB6; - private boolean isBitB7; - - public ShfOperation(OpCode opCode, Bytes32 arg1, Bytes32 arg2) { - this.opCode = opCode; - this.arg1 = arg1; - this.arg2 = arg2; - this.isOneLineInstruction = isOneLineInstruction(opCode, arg1Hi()); - } - - private static boolean isOneLineInstruction(final OpCode opCode, final Bytes16 arg1Hi) { - return (opCode == OpCode.SHR || opCode == OpCode.SHL) && !arg1Hi.isZero(); - } - - private static boolean isKnown(final OpCode opCode, final Bytes16 arg1Hi, final Bytes16 arg1Lo) { - if (opCode.equals(OpCode.SAR) && !arg1Hi.isZero()) { - return true; - } - - return !allButLastByteZero(arg1Lo); - } - - private static boolean allButLastByteZero(final Bytes16 bytes) { - for (int i = 0; i < 15; i++) { - if (bytes.get(i) != 0) { - return false; - } - } - - return true; - } - - private void compute() { - this.isNegative = Long.compareUnsigned(arg2Hi().get(0), 128) >= 0; - this.isShiftRight = List.of(OpCode.SAR, OpCode.SHR).contains(opCode); - this.isKnown = isKnown(opCode, arg1Hi(), arg1Lo()); - - UnsignedByte msb = UnsignedByte.of(arg2Hi().get(0)); - UnsignedByte lsb = UnsignedByte.of(arg1Lo().get(15)); - this.low3 = lsb.shiftLeft(5).shiftRight(5); - - if (isShiftRight) { - this.mshp = low3; - } else { - this.mshp = UnsignedByte.of(8 - low3.toInteger()); - } - - Boolean[] lsbBits = byteBits(lsb); - Boolean[] msbBits = byteBits(msb); - - this.bits = new ArrayList<>(lsbBits.length + msbBits.length); - Collections.addAll(this.bits, msbBits); - Collections.addAll(this.bits, lsbBits); - - this.shb = Shb.create(opCode, arg2, lsb); - this.res = Res.create(opCode, arg1, arg2); - - this.isBitB3 = lsbBits[4]; - this.isBitB4 = lsbBits[3]; - this.isBitB5 = lsbBits[2]; - this.isBitB6 = lsbBits[1]; - this.isBitB7 = lsbBits[0]; - } - - public Bytes16 arg1Hi() { - return Bytes16.wrap(arg1.slice(0, 16)); - } - - public Bytes16 arg1Lo() { - return Bytes16.wrap(arg1.slice(16)); - } - - public Bytes16 arg2Hi() { - return Bytes16.wrap(arg2.slice(0, 16)); - } - - public Bytes16 arg2Lo() { - return Bytes16.wrap(arg2.slice(16)); - } - - public int maxCt() { - return this.isOneLineInstruction ? 1 : LIMB_SIZE; - } - - public void trace(Trace trace, int stamp) { - this.compute(); - - for (int i = 0; i < this.maxCt(); i++) { - final ByteChunks arg2HiByteChunks = - ByteChunks.fromBytes(UnsignedByte.of(this.arg2Hi().get(i)), this.mshp); - final ByteChunks arg2LoByteChunks = - ByteChunks.fromBytes(UnsignedByte.of(this.arg2Lo().get(i)), this.mshp); - - trace - .acc1(this.arg1Lo().slice(0, 1 + i)) - .acc2(this.arg2Hi().slice(0, 1 + i)) - .acc3(this.arg2Lo().slice(0, 1 + i)) - .acc4(this.res.getResHi().slice(0, 1 + i)) - .acc5(this.res.getResLo().slice(0, 1 + i)) - .arg1Hi(this.arg1Hi()) - .arg1Lo(this.arg1Lo()) - .arg2Hi(this.arg2Hi()) - .arg2Lo(this.arg2Lo()); - - if (this.isShiftRight) { - trace.bit1(i >= 1).bit2(i >= 2).bit3(i >= 4).bit4(i >= 8); - } else { - trace.bit1(i >= (16 - 1)).bit2(i >= (16 - 2)).bit3(i >= (16 - 4)).bit4(i >= (16 - 8)); - } - - trace - .bitB3(this.isBitB3) - .bitB4(this.isBitB4) - .bitB5(this.isBitB5) - .bitB6(this.isBitB6) - .bitB7(this.isBitB7) - .byte1(UnsignedByte.of(this.arg1Lo().get(i))) - .byte2(UnsignedByte.of(this.arg2Hi().get(i))) - .byte3(UnsignedByte.of(this.arg2Lo().get(i))) - .byte4(UnsignedByte.of(this.res.getResHi().get(i))) - .byte5(UnsignedByte.of(this.res.getResLo().get(i))) - .bits(this.bits.get(i)) - .counter(Bytes.of(i)) - .inst(Bytes.of(this.opCode.byteValue())) - .known(this.isKnown) - .neg(this.isNegative) - .oneLineInstruction(this.isOneLineInstruction) - .low3(Bytes.of(this.low3.toInteger())) - .microShiftParameter(Bytes.ofUnsignedInt(this.mshp.toInteger())) - .resHi(this.res.getResHi()) - .resLo(this.res.getResLo()) - .leftAlignedSuffixHigh(Bytes.ofUnsignedShort(arg2HiByteChunks.la().toInteger())) - .rightAlignedPrefixHigh(Bytes.ofUnsignedInt(arg2HiByteChunks.ra().toInteger())) - .ones(Bytes.ofUnsignedInt(arg2HiByteChunks.ones().toInteger())) - .leftAlignedSuffixLow(Bytes.ofUnsignedInt(arg2LoByteChunks.la().toInteger())) - .rightAlignedPrefixLow(Bytes.ofUnsignedInt(arg2LoByteChunks.ra().toInteger())) - .shb3Hi(Bytes.ofUnsignedInt(this.shb.getShbHi()[0][i].toInteger())) - .shb3Lo(Bytes.ofUnsignedInt(this.shb.getShbLo()[0][i].toInteger())) - .shb4Hi(Bytes.ofUnsignedInt(this.shb.getShbHi()[4 - 3][i].toInteger())) - .shb4Lo(Bytes.ofUnsignedInt(this.shb.getShbLo()[4 - 3][i].toInteger())) - .shb5Hi(Bytes.ofUnsignedInt(this.shb.getShbHi()[5 - 3][i].toInteger())) - .shb5Lo(Bytes.ofUnsignedInt(this.shb.getShbLo()[5 - 3][i].toInteger())) - .shb6Hi(Bytes.ofUnsignedInt(this.shb.getShbHi()[6 - 3][i].toInteger())) - .shb6Lo(Bytes.ofUnsignedInt(this.shb.getShbLo()[6 - 3][i].toInteger())) - .shb7Hi(Bytes.ofUnsignedInt(this.shb.getShbHi()[7 - 3][i].toInteger())) - .shb7Lo(Bytes.ofUnsignedInt(this.shb.getShbLo()[7 - 3][i].toInteger())) - .shiftDirection(this.isShiftRight) - .isData(stamp != 0) - .shiftStamp(Bytes.ofUnsignedInt(stamp)) - .validateRow(); - } - } - - @Override - protected int computeLineCount() { - return this.maxCt(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ShfTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ShfTrace.java deleted file mode 100644 index ea1a63420..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/ShfTrace.java +++ /dev/null @@ -1,31 +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.shf; - -import com.fasterxml.jackson.annotation.JsonProperty; -import net.consensys.linea.zktracer.module.ModuleTrace; - -/** - * WARNING: This code is generated automatically. Any modifications to this code may be overwritten - * and could lead to unexpected behavior. Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -record ShfTrace(@JsonProperty("Trace") Trace trace) implements ModuleTrace { - - @Override - public int length() { - return this.trace.size(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shifter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shifter.java deleted file mode 100644 index 0935a98be..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Shifter.java +++ /dev/null @@ -1,58 +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.shf; - -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; - -public class Shifter { - private static final UInt256 ALL_BITS = UInt256.MAX_VALUE; - - public static Bytes32 shift(final OpCode opCode, final Bytes32 value, final int shiftAmount) { - return switch (opCode) { - case SHR -> value.shiftRight(shiftAmount); - case SHL -> value.shiftLeft(shiftAmount); - case SAR -> sarOperation(value, shiftAmount); - default -> Bytes32.ZERO; - }; - } - - private static Bytes32 sarOperation(final Bytes32 value, final int shiftAmountInt) { - Bytes shiftAmountBytes = Bytes.ofUnsignedInt(shiftAmountInt); - final boolean isNegativeNumber = value.get(0) < 0; - - if (shiftAmountBytes.size() > 4 && shiftAmountBytes.trimLeadingZeros().size() > 4) { - return isNegativeNumber ? ALL_BITS : UInt256.ZERO; - } else { - if (shiftAmountInt >= 256 || shiftAmountInt < 0) { - return isNegativeNumber ? ALL_BITS : UInt256.ZERO; - } else { - // first perform standard shift right. - Bytes32 result = value.shiftRight(shiftAmountInt); - - // if a negative number, carry through the sign. - if (isNegativeNumber) { - final Bytes32 significantBits = ALL_BITS.shiftLeft(256 - shiftAmountInt); - result = result.or(significantBits); - } - - return result; - } - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Trace.java deleted file mode 100644 index 37806a79c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shf/Trace.java +++ /dev/null @@ -1,1369 +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.shf; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer acc1; - private final MappedByteBuffer acc2; - private final MappedByteBuffer acc3; - private final MappedByteBuffer acc4; - private final MappedByteBuffer acc5; - private final MappedByteBuffer arg1Hi; - private final MappedByteBuffer arg1Lo; - private final MappedByteBuffer arg2Hi; - private final MappedByteBuffer arg2Lo; - private final MappedByteBuffer bit1; - private final MappedByteBuffer bit2; - private final MappedByteBuffer bit3; - private final MappedByteBuffer bit4; - private final MappedByteBuffer bitB3; - private final MappedByteBuffer bitB4; - private final MappedByteBuffer bitB5; - private final MappedByteBuffer bitB6; - private final MappedByteBuffer bitB7; - private final MappedByteBuffer bits; - private final MappedByteBuffer byte1; - private final MappedByteBuffer byte2; - private final MappedByteBuffer byte3; - private final MappedByteBuffer byte4; - private final MappedByteBuffer byte5; - private final MappedByteBuffer counter; - private final MappedByteBuffer inst; - private final MappedByteBuffer isData; - private final MappedByteBuffer known; - private final MappedByteBuffer leftAlignedSuffixHigh; - private final MappedByteBuffer leftAlignedSuffixLow; - private final MappedByteBuffer low3; - private final MappedByteBuffer microShiftParameter; - private final MappedByteBuffer neg; - private final MappedByteBuffer oneLineInstruction; - private final MappedByteBuffer ones; - private final MappedByteBuffer resHi; - private final MappedByteBuffer resLo; - private final MappedByteBuffer rightAlignedPrefixHigh; - private final MappedByteBuffer rightAlignedPrefixLow; - private final MappedByteBuffer shb3Hi; - private final MappedByteBuffer shb3Lo; - private final MappedByteBuffer shb4Hi; - private final MappedByteBuffer shb4Lo; - private final MappedByteBuffer shb5Hi; - private final MappedByteBuffer shb5Lo; - private final MappedByteBuffer shb6Hi; - private final MappedByteBuffer shb6Lo; - private final MappedByteBuffer shb7Hi; - private final MappedByteBuffer shb7Lo; - private final MappedByteBuffer shiftDirection; - private final MappedByteBuffer shiftStamp; - - static List headers(int length) { - return List.of( - new ColumnHeader("shf.ACC_1", 32, length), - new ColumnHeader("shf.ACC_2", 32, length), - new ColumnHeader("shf.ACC_3", 32, length), - new ColumnHeader("shf.ACC_4", 32, length), - new ColumnHeader("shf.ACC_5", 32, length), - new ColumnHeader("shf.ARG_1_HI", 32, length), - new ColumnHeader("shf.ARG_1_LO", 32, length), - new ColumnHeader("shf.ARG_2_HI", 32, length), - new ColumnHeader("shf.ARG_2_LO", 32, length), - new ColumnHeader("shf.BIT_1", 1, length), - new ColumnHeader("shf.BIT_2", 1, length), - new ColumnHeader("shf.BIT_3", 1, length), - new ColumnHeader("shf.BIT_4", 1, length), - new ColumnHeader("shf.BIT_B_3", 1, length), - new ColumnHeader("shf.BIT_B_4", 1, length), - new ColumnHeader("shf.BIT_B_5", 1, length), - new ColumnHeader("shf.BIT_B_6", 1, length), - new ColumnHeader("shf.BIT_B_7", 1, length), - new ColumnHeader("shf.BITS", 1, length), - new ColumnHeader("shf.BYTE_1", 1, length), - new ColumnHeader("shf.BYTE_2", 1, length), - new ColumnHeader("shf.BYTE_3", 1, length), - new ColumnHeader("shf.BYTE_4", 1, length), - new ColumnHeader("shf.BYTE_5", 1, length), - new ColumnHeader("shf.COUNTER", 32, length), - new ColumnHeader("shf.INST", 32, length), - new ColumnHeader("shf.IS_DATA", 1, length), - new ColumnHeader("shf.KNOWN", 1, length), - new ColumnHeader("shf.LEFT_ALIGNED_SUFFIX_HIGH", 32, length), - new ColumnHeader("shf.LEFT_ALIGNED_SUFFIX_LOW", 32, length), - new ColumnHeader("shf.LOW_3", 32, length), - new ColumnHeader("shf.MICRO_SHIFT_PARAMETER", 32, length), - new ColumnHeader("shf.NEG", 1, length), - new ColumnHeader("shf.ONE_LINE_INSTRUCTION", 1, length), - new ColumnHeader("shf.ONES", 32, length), - new ColumnHeader("shf.RES_HI", 32, length), - new ColumnHeader("shf.RES_LO", 32, length), - new ColumnHeader("shf.RIGHT_ALIGNED_PREFIX_HIGH", 32, length), - new ColumnHeader("shf.RIGHT_ALIGNED_PREFIX_LOW", 32, length), - new ColumnHeader("shf.SHB_3_HI", 32, length), - new ColumnHeader("shf.SHB_3_LO", 32, length), - new ColumnHeader("shf.SHB_4_HI", 32, length), - new ColumnHeader("shf.SHB_4_LO", 32, length), - new ColumnHeader("shf.SHB_5_HI", 32, length), - new ColumnHeader("shf.SHB_5_LO", 32, length), - new ColumnHeader("shf.SHB_6_HI", 32, length), - new ColumnHeader("shf.SHB_6_LO", 32, length), - new ColumnHeader("shf.SHB_7_HI", 32, length), - new ColumnHeader("shf.SHB_7_LO", 32, length), - new ColumnHeader("shf.SHIFT_DIRECTION", 1, length), - new ColumnHeader("shf.SHIFT_STAMP", 32, length)); - } - - public Trace(List buffers) { - this.acc1 = buffers.get(0); - this.acc2 = buffers.get(1); - this.acc3 = buffers.get(2); - this.acc4 = buffers.get(3); - this.acc5 = buffers.get(4); - this.arg1Hi = buffers.get(5); - this.arg1Lo = buffers.get(6); - this.arg2Hi = buffers.get(7); - this.arg2Lo = buffers.get(8); - this.bit1 = buffers.get(9); - this.bit2 = buffers.get(10); - this.bit3 = buffers.get(11); - this.bit4 = buffers.get(12); - this.bitB3 = buffers.get(13); - this.bitB4 = buffers.get(14); - this.bitB5 = buffers.get(15); - this.bitB6 = buffers.get(16); - this.bitB7 = buffers.get(17); - this.bits = buffers.get(18); - this.byte1 = buffers.get(19); - this.byte2 = buffers.get(20); - this.byte3 = buffers.get(21); - this.byte4 = buffers.get(22); - this.byte5 = buffers.get(23); - this.counter = buffers.get(24); - this.inst = buffers.get(25); - this.isData = buffers.get(26); - this.known = buffers.get(27); - this.leftAlignedSuffixHigh = buffers.get(28); - this.leftAlignedSuffixLow = buffers.get(29); - this.low3 = buffers.get(30); - this.microShiftParameter = buffers.get(31); - this.neg = buffers.get(32); - this.oneLineInstruction = buffers.get(33); - this.ones = buffers.get(34); - this.resHi = buffers.get(35); - this.resLo = buffers.get(36); - this.rightAlignedPrefixHigh = buffers.get(37); - this.rightAlignedPrefixLow = buffers.get(38); - this.shb3Hi = buffers.get(39); - this.shb3Lo = buffers.get(40); - this.shb4Hi = buffers.get(41); - this.shb4Lo = buffers.get(42); - this.shb5Hi = buffers.get(43); - this.shb5Lo = buffers.get(44); - this.shb6Hi = buffers.get(45); - this.shb6Lo = buffers.get(46); - this.shb7Hi = buffers.get(47); - this.shb7Lo = buffers.get(48); - this.shiftDirection = buffers.get(49); - this.shiftStamp = buffers.get(50); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace acc1(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("shf.ACC_1 already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc1.put((byte) 0); - } - acc1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc2(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("shf.ACC_2 already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc2.put((byte) 0); - } - acc2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc3(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("shf.ACC_3 already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc3.put((byte) 0); - } - acc3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc4(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("shf.ACC_4 already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc4.put((byte) 0); - } - acc4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc5(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("shf.ACC_5 already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc5.put((byte) 0); - } - acc5.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg1Hi(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("shf.ARG_1_HI already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Hi.put((byte) 0); - } - arg1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg1Lo(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("shf.ARG_1_LO already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Lo.put((byte) 0); - } - arg1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg2Hi(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("shf.ARG_2_HI already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg2Hi.put((byte) 0); - } - arg2Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg2Lo(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("shf.ARG_2_LO already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg2Lo.put((byte) 0); - } - arg2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace bit1(final Boolean b) { - if (filled.get(10)) { - throw new IllegalStateException("shf.BIT_1 already set"); - } else { - filled.set(10); - } - - bit1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit2(final Boolean b) { - if (filled.get(11)) { - throw new IllegalStateException("shf.BIT_2 already set"); - } else { - filled.set(11); - } - - bit2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit3(final Boolean b) { - if (filled.get(12)) { - throw new IllegalStateException("shf.BIT_3 already set"); - } else { - filled.set(12); - } - - bit3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit4(final Boolean b) { - if (filled.get(13)) { - throw new IllegalStateException("shf.BIT_4 already set"); - } else { - filled.set(13); - } - - bit4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bitB3(final Boolean b) { - if (filled.get(14)) { - throw new IllegalStateException("shf.BIT_B_3 already set"); - } else { - filled.set(14); - } - - bitB3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bitB4(final Boolean b) { - if (filled.get(15)) { - throw new IllegalStateException("shf.BIT_B_4 already set"); - } else { - filled.set(15); - } - - bitB4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bitB5(final Boolean b) { - if (filled.get(16)) { - throw new IllegalStateException("shf.BIT_B_5 already set"); - } else { - filled.set(16); - } - - bitB5.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bitB6(final Boolean b) { - if (filled.get(17)) { - throw new IllegalStateException("shf.BIT_B_6 already set"); - } else { - filled.set(17); - } - - bitB6.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bitB7(final Boolean b) { - if (filled.get(18)) { - throw new IllegalStateException("shf.BIT_B_7 already set"); - } else { - filled.set(18); - } - - bitB7.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bits(final Boolean b) { - if (filled.get(9)) { - throw new IllegalStateException("shf.BITS already set"); - } else { - filled.set(9); - } - - bits.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace byte1(final UnsignedByte b) { - if (filled.get(19)) { - throw new IllegalStateException("shf.BYTE_1 already set"); - } else { - filled.set(19); - } - - byte1.put(b.toByte()); - - return this; - } - - public Trace byte2(final UnsignedByte b) { - if (filled.get(20)) { - throw new IllegalStateException("shf.BYTE_2 already set"); - } else { - filled.set(20); - } - - byte2.put(b.toByte()); - - return this; - } - - public Trace byte3(final UnsignedByte b) { - if (filled.get(21)) { - throw new IllegalStateException("shf.BYTE_3 already set"); - } else { - filled.set(21); - } - - byte3.put(b.toByte()); - - return this; - } - - public Trace byte4(final UnsignedByte b) { - if (filled.get(22)) { - throw new IllegalStateException("shf.BYTE_4 already set"); - } else { - filled.set(22); - } - - byte4.put(b.toByte()); - - return this; - } - - public Trace byte5(final UnsignedByte b) { - if (filled.get(23)) { - throw new IllegalStateException("shf.BYTE_5 already set"); - } else { - filled.set(23); - } - - byte5.put(b.toByte()); - - return this; - } - - public Trace counter(final Bytes b) { - if (filled.get(24)) { - throw new IllegalStateException("shf.COUNTER already set"); - } else { - filled.set(24); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - counter.put((byte) 0); - } - counter.put(b.toArrayUnsafe()); - - return this; - } - - public Trace inst(final Bytes b) { - if (filled.get(25)) { - throw new IllegalStateException("shf.INST already set"); - } else { - filled.set(25); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - inst.put((byte) 0); - } - inst.put(b.toArrayUnsafe()); - - return this; - } - - public Trace isData(final Boolean b) { - if (filled.get(26)) { - throw new IllegalStateException("shf.IS_DATA already set"); - } else { - filled.set(26); - } - - isData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace known(final Boolean b) { - if (filled.get(27)) { - throw new IllegalStateException("shf.KNOWN already set"); - } else { - filled.set(27); - } - - known.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace leftAlignedSuffixHigh(final Bytes b) { - if (filled.get(28)) { - throw new IllegalStateException("shf.LEFT_ALIGNED_SUFFIX_HIGH already set"); - } else { - filled.set(28); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - leftAlignedSuffixHigh.put((byte) 0); - } - leftAlignedSuffixHigh.put(b.toArrayUnsafe()); - - return this; - } - - public Trace leftAlignedSuffixLow(final Bytes b) { - if (filled.get(29)) { - throw new IllegalStateException("shf.LEFT_ALIGNED_SUFFIX_LOW already set"); - } else { - filled.set(29); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - leftAlignedSuffixLow.put((byte) 0); - } - leftAlignedSuffixLow.put(b.toArrayUnsafe()); - - return this; - } - - public Trace low3(final Bytes b) { - if (filled.get(30)) { - throw new IllegalStateException("shf.LOW_3 already set"); - } else { - filled.set(30); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - low3.put((byte) 0); - } - low3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace microShiftParameter(final Bytes b) { - if (filled.get(31)) { - throw new IllegalStateException("shf.MICRO_SHIFT_PARAMETER already set"); - } else { - filled.set(31); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - microShiftParameter.put((byte) 0); - } - microShiftParameter.put(b.toArrayUnsafe()); - - return this; - } - - public Trace neg(final Boolean b) { - if (filled.get(32)) { - throw new IllegalStateException("shf.NEG already set"); - } else { - filled.set(32); - } - - neg.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace oneLineInstruction(final Boolean b) { - if (filled.get(34)) { - throw new IllegalStateException("shf.ONE_LINE_INSTRUCTION already set"); - } else { - filled.set(34); - } - - oneLineInstruction.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ones(final Bytes b) { - if (filled.get(33)) { - throw new IllegalStateException("shf.ONES already set"); - } else { - filled.set(33); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - ones.put((byte) 0); - } - ones.put(b.toArrayUnsafe()); - - return this; - } - - public Trace resHi(final Bytes b) { - if (filled.get(35)) { - throw new IllegalStateException("shf.RES_HI already set"); - } else { - filled.set(35); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resHi.put((byte) 0); - } - resHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace resLo(final Bytes b) { - if (filled.get(36)) { - throw new IllegalStateException("shf.RES_LO already set"); - } else { - filled.set(36); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resLo.put((byte) 0); - } - resLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace rightAlignedPrefixHigh(final Bytes b) { - if (filled.get(37)) { - throw new IllegalStateException("shf.RIGHT_ALIGNED_PREFIX_HIGH already set"); - } else { - filled.set(37); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rightAlignedPrefixHigh.put((byte) 0); - } - rightAlignedPrefixHigh.put(b.toArrayUnsafe()); - - return this; - } - - public Trace rightAlignedPrefixLow(final Bytes b) { - if (filled.get(38)) { - throw new IllegalStateException("shf.RIGHT_ALIGNED_PREFIX_LOW already set"); - } else { - filled.set(38); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rightAlignedPrefixLow.put((byte) 0); - } - rightAlignedPrefixLow.put(b.toArrayUnsafe()); - - return this; - } - - public Trace shb3Hi(final Bytes b) { - if (filled.get(39)) { - throw new IllegalStateException("shf.SHB_3_HI already set"); - } else { - filled.set(39); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - shb3Hi.put((byte) 0); - } - shb3Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace shb3Lo(final Bytes b) { - if (filled.get(40)) { - throw new IllegalStateException("shf.SHB_3_LO already set"); - } else { - filled.set(40); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - shb3Lo.put((byte) 0); - } - shb3Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace shb4Hi(final Bytes b) { - if (filled.get(41)) { - throw new IllegalStateException("shf.SHB_4_HI already set"); - } else { - filled.set(41); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - shb4Hi.put((byte) 0); - } - shb4Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace shb4Lo(final Bytes b) { - if (filled.get(42)) { - throw new IllegalStateException("shf.SHB_4_LO already set"); - } else { - filled.set(42); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - shb4Lo.put((byte) 0); - } - shb4Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace shb5Hi(final Bytes b) { - if (filled.get(43)) { - throw new IllegalStateException("shf.SHB_5_HI already set"); - } else { - filled.set(43); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - shb5Hi.put((byte) 0); - } - shb5Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace shb5Lo(final Bytes b) { - if (filled.get(44)) { - throw new IllegalStateException("shf.SHB_5_LO already set"); - } else { - filled.set(44); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - shb5Lo.put((byte) 0); - } - shb5Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace shb6Hi(final Bytes b) { - if (filled.get(45)) { - throw new IllegalStateException("shf.SHB_6_HI already set"); - } else { - filled.set(45); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - shb6Hi.put((byte) 0); - } - shb6Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace shb6Lo(final Bytes b) { - if (filled.get(46)) { - throw new IllegalStateException("shf.SHB_6_LO already set"); - } else { - filled.set(46); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - shb6Lo.put((byte) 0); - } - shb6Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace shb7Hi(final Bytes b) { - if (filled.get(47)) { - throw new IllegalStateException("shf.SHB_7_HI already set"); - } else { - filled.set(47); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - shb7Hi.put((byte) 0); - } - shb7Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace shb7Lo(final Bytes b) { - if (filled.get(48)) { - throw new IllegalStateException("shf.SHB_7_LO already set"); - } else { - filled.set(48); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - shb7Lo.put((byte) 0); - } - shb7Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace shiftDirection(final Boolean b) { - if (filled.get(49)) { - throw new IllegalStateException("shf.SHIFT_DIRECTION already set"); - } else { - filled.set(49); - } - - shiftDirection.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace shiftStamp(final Bytes b) { - if (filled.get(50)) { - throw new IllegalStateException("shf.SHIFT_STAMP already set"); - } else { - filled.set(50); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - shiftStamp.put((byte) 0); - } - shiftStamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("shf.ACC_1 has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("shf.ACC_2 has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("shf.ACC_3 has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("shf.ACC_4 has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("shf.ACC_5 has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("shf.ARG_1_HI has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("shf.ARG_1_LO has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("shf.ARG_2_HI has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("shf.ARG_2_LO has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("shf.BIT_1 has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("shf.BIT_2 has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("shf.BIT_3 has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("shf.BIT_4 has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("shf.BIT_B_3 has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("shf.BIT_B_4 has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("shf.BIT_B_5 has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("shf.BIT_B_6 has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("shf.BIT_B_7 has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("shf.BITS has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("shf.BYTE_1 has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("shf.BYTE_2 has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("shf.BYTE_3 has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("shf.BYTE_4 has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("shf.BYTE_5 has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("shf.COUNTER has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("shf.INST has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("shf.IS_DATA has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("shf.KNOWN has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("shf.LEFT_ALIGNED_SUFFIX_HIGH has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("shf.LEFT_ALIGNED_SUFFIX_LOW has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("shf.LOW_3 has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("shf.MICRO_SHIFT_PARAMETER has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("shf.NEG has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("shf.ONE_LINE_INSTRUCTION has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("shf.ONES has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("shf.RES_HI has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("shf.RES_LO has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("shf.RIGHT_ALIGNED_PREFIX_HIGH has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("shf.RIGHT_ALIGNED_PREFIX_LOW has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("shf.SHB_3_HI has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("shf.SHB_3_LO has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("shf.SHB_4_HI has not been filled"); - } - - if (!filled.get(42)) { - throw new IllegalStateException("shf.SHB_4_LO has not been filled"); - } - - if (!filled.get(43)) { - throw new IllegalStateException("shf.SHB_5_HI has not been filled"); - } - - if (!filled.get(44)) { - throw new IllegalStateException("shf.SHB_5_LO has not been filled"); - } - - if (!filled.get(45)) { - throw new IllegalStateException("shf.SHB_6_HI has not been filled"); - } - - if (!filled.get(46)) { - throw new IllegalStateException("shf.SHB_6_LO has not been filled"); - } - - if (!filled.get(47)) { - throw new IllegalStateException("shf.SHB_7_HI has not been filled"); - } - - if (!filled.get(48)) { - throw new IllegalStateException("shf.SHB_7_LO has not been filled"); - } - - if (!filled.get(49)) { - throw new IllegalStateException("shf.SHIFT_DIRECTION has not been filled"); - } - - if (!filled.get(50)) { - throw new IllegalStateException("shf.SHIFT_STAMP has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - acc1.position(acc1.position() + 32); - } - - if (!filled.get(1)) { - acc2.position(acc2.position() + 32); - } - - if (!filled.get(2)) { - acc3.position(acc3.position() + 32); - } - - if (!filled.get(3)) { - acc4.position(acc4.position() + 32); - } - - if (!filled.get(4)) { - acc5.position(acc5.position() + 32); - } - - if (!filled.get(5)) { - arg1Hi.position(arg1Hi.position() + 32); - } - - if (!filled.get(6)) { - arg1Lo.position(arg1Lo.position() + 32); - } - - if (!filled.get(7)) { - arg2Hi.position(arg2Hi.position() + 32); - } - - if (!filled.get(8)) { - arg2Lo.position(arg2Lo.position() + 32); - } - - if (!filled.get(10)) { - bit1.position(bit1.position() + 1); - } - - if (!filled.get(11)) { - bit2.position(bit2.position() + 1); - } - - if (!filled.get(12)) { - bit3.position(bit3.position() + 1); - } - - if (!filled.get(13)) { - bit4.position(bit4.position() + 1); - } - - if (!filled.get(14)) { - bitB3.position(bitB3.position() + 1); - } - - if (!filled.get(15)) { - bitB4.position(bitB4.position() + 1); - } - - if (!filled.get(16)) { - bitB5.position(bitB5.position() + 1); - } - - if (!filled.get(17)) { - bitB6.position(bitB6.position() + 1); - } - - if (!filled.get(18)) { - bitB7.position(bitB7.position() + 1); - } - - if (!filled.get(9)) { - bits.position(bits.position() + 1); - } - - if (!filled.get(19)) { - byte1.position(byte1.position() + 1); - } - - if (!filled.get(20)) { - byte2.position(byte2.position() + 1); - } - - if (!filled.get(21)) { - byte3.position(byte3.position() + 1); - } - - if (!filled.get(22)) { - byte4.position(byte4.position() + 1); - } - - if (!filled.get(23)) { - byte5.position(byte5.position() + 1); - } - - if (!filled.get(24)) { - counter.position(counter.position() + 32); - } - - if (!filled.get(25)) { - inst.position(inst.position() + 32); - } - - if (!filled.get(26)) { - isData.position(isData.position() + 1); - } - - if (!filled.get(27)) { - known.position(known.position() + 1); - } - - if (!filled.get(28)) { - leftAlignedSuffixHigh.position(leftAlignedSuffixHigh.position() + 32); - } - - if (!filled.get(29)) { - leftAlignedSuffixLow.position(leftAlignedSuffixLow.position() + 32); - } - - if (!filled.get(30)) { - low3.position(low3.position() + 32); - } - - if (!filled.get(31)) { - microShiftParameter.position(microShiftParameter.position() + 32); - } - - if (!filled.get(32)) { - neg.position(neg.position() + 1); - } - - if (!filled.get(34)) { - oneLineInstruction.position(oneLineInstruction.position() + 1); - } - - if (!filled.get(33)) { - ones.position(ones.position() + 32); - } - - if (!filled.get(35)) { - resHi.position(resHi.position() + 32); - } - - if (!filled.get(36)) { - resLo.position(resLo.position() + 32); - } - - if (!filled.get(37)) { - rightAlignedPrefixHigh.position(rightAlignedPrefixHigh.position() + 32); - } - - if (!filled.get(38)) { - rightAlignedPrefixLow.position(rightAlignedPrefixLow.position() + 32); - } - - if (!filled.get(39)) { - shb3Hi.position(shb3Hi.position() + 32); - } - - if (!filled.get(40)) { - shb3Lo.position(shb3Lo.position() + 32); - } - - if (!filled.get(41)) { - shb4Hi.position(shb4Hi.position() + 32); - } - - if (!filled.get(42)) { - shb4Lo.position(shb4Lo.position() + 32); - } - - if (!filled.get(43)) { - shb5Hi.position(shb5Hi.position() + 32); - } - - if (!filled.get(44)) { - shb5Lo.position(shb5Lo.position() + 32); - } - - if (!filled.get(45)) { - shb6Hi.position(shb6Hi.position() + 32); - } - - if (!filled.get(46)) { - shb6Lo.position(shb6Lo.position() + 32); - } - - if (!filled.get(47)) { - shb7Hi.position(shb7Hi.position() + 32); - } - - if (!filled.get(48)) { - shb7Lo.position(shb7Lo.position() + 32); - } - - if (!filled.get(49)) { - shiftDirection.position(shiftDirection.position() + 1); - } - - if (!filled.get(50)) { - shiftStamp.position(shiftStamp.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} 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 deleted file mode 100644 index 2ba1cee78..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java +++ /dev/null @@ -1,221 +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.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; -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.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; -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 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 Wcp wcp; - private final Mod mod; - - @Override - public String moduleKey() { - return "STP"; - } - - private final StackedSet chunks = new StackedSet<>(); - - @Override - public void enterTransaction() { - this.chunks.enter(); - } - - @Override - public void popTransaction() { - this.chunks.pop(); - } - - @Override - public int lineCount() { - return this.chunks.lineCount(); - } - - @Override - 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 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)); - } - } - 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())); - } - 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())); - } - } - } - } - - 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( - this.hub.opCode(), - gasRemaining, - gasPrelim, - gasRemaining < gasPrelim, - gasMxp, - frame.getWorldUpdater().get(frame.getContractAddress()).getBalance(), - to, - Bytes32.leftPad(frame.getStackItem(0))); - } - - private StpChunk getCallData(final MessageFrame frame) { - 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 StpChunk( - opcode, - gasActual, - gasPrelim, - oogx, - gasMxp, - frame.getWorldUpdater().get(frame.getContractAddress()).getBalance(), - to, - value, - toExists, - toWarm, - Bytes32.leftPad(frame.getStackItem(0))); - } - - 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); - - int stamp = 0; - for (StpChunk chunk : chunks) { - 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/StpChunk.java deleted file mode 100644 index ac1ac179d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpChunk.java +++ /dev/null @@ -1,297 +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.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.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -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; - -@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; - - // 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()); - } - - // 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)); - } - - long getGDiff() { - Preconditions.checkArgument(!this.oogx()); - return this.gasActual() - this.gasPrelim(); - } - - long getGDiffOver64() { - return this.getGDiff() / 64; - } - - long get63of64GDiff() { - return this.getGDiff() - this.getGDiffOver64(); - } - - void trace(Trace trace, int stamp) { - if (this.opCode().isCreate()) { - this.traceCreate(trace, stamp); - } else { - this.traceCall(trace, stamp); - } - } - - private void traceCreate(Trace trace, int stamp) { - final int ctMax = this.maxCt(); - final long gasOopkt = this.oogx() ? 0 : this.get63of64GDiff(); - - for (int ct = 0; ct <= ctMax; ct++) { - trace - .stamp(Bytes.ofUnsignedInt(stamp)) - .ct(Bytes.of(ct)) - .ctMax(Bytes.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())) - .gasOopkt(Bytes.ofUnsignedLong(gasOopkt)) - .gasStipend(Bytes.EMPTY) - .arg1Hi(Bytes.EMPTY); - - switch (ct) { - case 0 -> trace - .arg1Lo(Bytes.ofUnsignedLong(this.gasActual())) - .arg2Lo(Bytes.EMPTY) - .exogenousModuleInstruction(UnsignedByte.of(OpCode.LT.byteValue())) - .resLo(Bytes.EMPTY) // we REQUIRE that the currently available gas is nonnegative - .wcpFlag(true) - .modFlag(false) - .validateRow(); - case 1 -> trace - .arg1Lo(Bytes.ofUnsignedLong(this.gasActual())) - .arg2Lo(Bytes.ofUnsignedLong(this.gasPrelim())) - .exogenousModuleInstruction(UnsignedByte.of(OpCode.LT.byteValue())) - .resLo(Bytes.of(this.oogx() ? 1 : 0)) - .wcpFlag(true) - .modFlag(false) - .validateRow(); - case 2 -> trace - .arg1Lo(Bytes.ofUnsignedLong(getGDiff())) - .arg2Lo(Bytes.of(64)) - .exogenousModuleInstruction(UnsignedByte.of(OpCode.DIV.byteValue())) - .resLo(Bytes.ofUnsignedLong(getGDiffOver64())) - .wcpFlag(false) - .modFlag(true) - .validateRow(); - default -> throw new IllegalArgumentException("counter too big, should be <=" + ctMax); - } - } - } - - 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(Bytes.ofUnsignedInt(stamp)) - .ct(Bytes.of(ct)) - .ctMax(Bytes.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())) - .gasOopkt(gasOopkt) - .gasStipend(Bytes.ofUnsignedLong(gasStipend)); - - switch (ct) { - case 0 -> trace - .arg1Hi(Bytes.EMPTY) - .arg1Lo(Bytes.ofUnsignedLong(this.gasActual())) - .arg2Lo(Bytes.EMPTY) - .exogenousModuleInstruction(UnsignedByte.of(OpCode.LT.byteValue())) - .resLo(Bytes.EMPTY) // we REQUIRE that the currently available gas is nonnegative - .wcpFlag(true) - .modFlag(false) - .validateRow(); - case 1 -> trace - .arg1Hi(this.value().slice(0, 16)) - .arg1Lo(this.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())) - .modFlag(false) - .validateRow(); - case 2 -> trace - .arg1Hi(Bytes.EMPTY) - .arg1Lo(Bytes.ofUnsignedLong(this.gasActual())) - .arg2Lo(Bytes.ofUnsignedLong(this.gasPrelim())) - .exogenousModuleInstruction(UnsignedByte.of(OpCode.LT.byteValue())) - .resLo(Bytes.of(this.oogx() ? 1 : 0)) - .wcpFlag(true) - .modFlag(false) - .validateRow(); - // the following rows are only filled in if no out of gas exception - case 3 -> trace - .arg1Hi(Bytes.EMPTY) - .arg1Lo(Bytes.ofUnsignedLong(getGDiff())) - .arg2Lo(Bytes.of(64)) - .exogenousModuleInstruction(UnsignedByte.of(OpCode.DIV.byteValue())) - .resLo(Bytes.ofUnsignedLong(getGDiffOver64())) - .wcpFlag(false) - .modFlag(true) - .validateRow(); - case 4 -> trace - .arg1Hi(this.gas().orElseThrow().slice(0, 16)) - .arg1Lo(this.gas().orElseThrow().slice(16, 16)) - .arg2Lo(Bytes.ofUnsignedLong(getGDiff() - getGDiffOver64())) - .exogenousModuleInstruction(UnsignedByte.of(OpCode.LT.byteValue())) - .resLo( - Bytes.of( - this.gas() - .orElseThrow() - .toUnsignedBigInteger() - .compareTo(BigInteger.valueOf(get63of64GDiff())) - < 0 - ? 1 - : 0)) - .wcpFlag(true) - .modFlag(false) - .validateRow(); - default -> throw new IllegalArgumentException("counter too big, should be <=" + ctMax); - } - } - } - - private int maxCt() { - if (this.oogx) { - return this.opCode.isCreate() ? 1 : 2; - } else { - return this.opCode.isCreate() ? 2 : 4; - } - } - - @Override - protected int computeLineCount() { - return 1 + this.maxCt(); - } -} 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 deleted file mode 100644 index 5f6dbf48e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Trace.java +++ /dev/null @@ -1,803 +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.stp; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer arg1Hi; - private final MappedByteBuffer arg1Lo; - private final MappedByteBuffer arg2Lo; - private final MappedByteBuffer ct; - private final MappedByteBuffer ctMax; - private final MappedByteBuffer exists; - private final MappedByteBuffer exogenousModuleInstruction; - private final MappedByteBuffer gasActual; - private final MappedByteBuffer gasHi; - private final MappedByteBuffer gasLo; - private final MappedByteBuffer gasMxp; - private final MappedByteBuffer gasOopkt; - private final MappedByteBuffer gasStipend; - private final MappedByteBuffer gasUpfront; - private final MappedByteBuffer instruction; - private final MappedByteBuffer isCall; - private final MappedByteBuffer isCallcode; - private final MappedByteBuffer isCreate; - private final MappedByteBuffer isCreate2; - private final MappedByteBuffer isDelegatecall; - private final MappedByteBuffer isStaticcall; - private final MappedByteBuffer modFlag; - private final MappedByteBuffer outOfGasException; - private final MappedByteBuffer resLo; - private final MappedByteBuffer stamp; - private final MappedByteBuffer valHi; - private final MappedByteBuffer valLo; - private final MappedByteBuffer warm; - private final MappedByteBuffer wcpFlag; - - static List headers(int length) { - return List.of( - new ColumnHeader("stp.ARG_1_HI", 32, length), - new ColumnHeader("stp.ARG_1_LO", 32, length), - new ColumnHeader("stp.ARG_2_LO", 32, length), - new ColumnHeader("stp.CT", 32, length), - new ColumnHeader("stp.CT_MAX", 32, 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_HI", 32, length), - new ColumnHeader("stp.GAS_LO", 32, length), - new ColumnHeader("stp.GAS_MXP", 32, length), - new ColumnHeader("stp.GAS_OOPKT", 32, length), - new ColumnHeader("stp.GAS_STIPEND", 32, length), - new ColumnHeader("stp.GAS_UPFRONT", 32, length), - new ColumnHeader("stp.INSTRUCTION", 1, length), - new ColumnHeader("stp.IS_CALL", 1, length), - new ColumnHeader("stp.IS_CALLCODE", 1, length), - new ColumnHeader("stp.IS_CREATE", 1, length), - new ColumnHeader("stp.IS_CREATE2", 1, length), - new ColumnHeader("stp.IS_DELEGATECALL", 1, length), - new ColumnHeader("stp.IS_STATICCALL", 1, length), - new ColumnHeader("stp.MOD_FLAG", 1, length), - new ColumnHeader("stp.OUT_OF_GAS_EXCEPTION", 1, length), - new ColumnHeader("stp.RES_LO", 32, length), - new ColumnHeader("stp.STAMP", 32, length), - new ColumnHeader("stp.VAL_HI", 32, length), - new ColumnHeader("stp.VAL_LO", 32, length), - new ColumnHeader("stp.WARM", 1, length), - new ColumnHeader("stp.WCP_FLAG", 1, length)); - } - - public Trace(List buffers) { - this.arg1Hi = buffers.get(0); - this.arg1Lo = buffers.get(1); - this.arg2Lo = buffers.get(2); - this.ct = buffers.get(3); - this.ctMax = buffers.get(4); - this.exists = buffers.get(5); - this.exogenousModuleInstruction = buffers.get(6); - this.gasActual = buffers.get(7); - this.gasHi = buffers.get(8); - this.gasLo = buffers.get(9); - this.gasMxp = buffers.get(10); - this.gasOopkt = buffers.get(11); - this.gasStipend = buffers.get(12); - this.gasUpfront = buffers.get(13); - this.instruction = buffers.get(14); - this.isCall = buffers.get(15); - this.isCallcode = buffers.get(16); - this.isCreate = buffers.get(17); - this.isCreate2 = buffers.get(18); - this.isDelegatecall = buffers.get(19); - this.isStaticcall = buffers.get(20); - this.modFlag = buffers.get(21); - this.outOfGasException = buffers.get(22); - this.resLo = buffers.get(23); - this.stamp = buffers.get(24); - this.valHi = buffers.get(25); - this.valLo = buffers.get(26); - this.warm = buffers.get(27); - this.wcpFlag = buffers.get(28); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace arg1Hi(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("stp.ARG_1_HI already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Hi.put((byte) 0); - } - arg1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg1Lo(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("stp.ARG_1_LO already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg1Lo.put((byte) 0); - } - arg1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace arg2Lo(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("stp.ARG_2_LO already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - arg2Lo.put((byte) 0); - } - arg2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace ct(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("stp.CT already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - ct.put((byte) 0); - } - ct.put(b.toArrayUnsafe()); - - return this; - } - - public Trace ctMax(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("stp.CT_MAX already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - ctMax.put((byte) 0); - } - ctMax.put(b.toArrayUnsafe()); - - return this; - } - - public Trace exists(final Boolean b) { - if (filled.get(5)) { - throw new IllegalStateException("stp.EXISTS already set"); - } else { - filled.set(5); - } - - exists.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace exogenousModuleInstruction(final UnsignedByte b) { - if (filled.get(6)) { - throw new IllegalStateException("stp.EXOGENOUS_MODULE_INSTRUCTION already set"); - } else { - filled.set(6); - } - - exogenousModuleInstruction.put(b.toByte()); - - return this; - } - - public Trace gasActual(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("stp.GAS_ACTUAL already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasActual.put((byte) 0); - } - gasActual.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasHi(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("stp.GAS_HI already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasHi.put((byte) 0); - } - gasHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasLo(final Bytes b) { - if (filled.get(9)) { - throw new IllegalStateException("stp.GAS_LO already set"); - } else { - filled.set(9); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasLo.put((byte) 0); - } - gasLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasMxp(final Bytes b) { - if (filled.get(10)) { - throw new IllegalStateException("stp.GAS_MXP already set"); - } else { - filled.set(10); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasMxp.put((byte) 0); - } - gasMxp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasOopkt(final Bytes b) { - if (filled.get(11)) { - throw new IllegalStateException("stp.GAS_OOPKT already set"); - } else { - filled.set(11); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasOopkt.put((byte) 0); - } - gasOopkt.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasStipend(final Bytes b) { - if (filled.get(12)) { - throw new IllegalStateException("stp.GAS_STIPEND already set"); - } else { - filled.set(12); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasStipend.put((byte) 0); - } - gasStipend.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasUpfront(final Bytes b) { - if (filled.get(13)) { - throw new IllegalStateException("stp.GAS_UPFRONT already set"); - } else { - filled.set(13); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasUpfront.put((byte) 0); - } - gasUpfront.put(b.toArrayUnsafe()); - - return this; - } - - public Trace instruction(final UnsignedByte b) { - if (filled.get(14)) { - throw new IllegalStateException("stp.INSTRUCTION already set"); - } else { - filled.set(14); - } - - instruction.put(b.toByte()); - - return this; - } - - public Trace isCall(final Boolean b) { - if (filled.get(15)) { - throw new IllegalStateException("stp.IS_CALL already set"); - } else { - filled.set(15); - } - - isCall.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isCallcode(final Boolean b) { - if (filled.get(16)) { - throw new IllegalStateException("stp.IS_CALLCODE already set"); - } else { - filled.set(16); - } - - isCallcode.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isCreate(final Boolean b) { - if (filled.get(17)) { - throw new IllegalStateException("stp.IS_CREATE already set"); - } else { - filled.set(17); - } - - isCreate.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isCreate2(final Boolean b) { - if (filled.get(18)) { - throw new IllegalStateException("stp.IS_CREATE2 already set"); - } else { - filled.set(18); - } - - isCreate2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isDelegatecall(final Boolean b) { - if (filled.get(19)) { - throw new IllegalStateException("stp.IS_DELEGATECALL already set"); - } else { - filled.set(19); - } - - isDelegatecall.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isStaticcall(final Boolean b) { - if (filled.get(20)) { - throw new IllegalStateException("stp.IS_STATICCALL already set"); - } else { - filled.set(20); - } - - isStaticcall.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace modFlag(final Boolean b) { - if (filled.get(21)) { - throw new IllegalStateException("stp.MOD_FLAG already set"); - } else { - filled.set(21); - } - - modFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace outOfGasException(final Boolean b) { - if (filled.get(22)) { - throw new IllegalStateException("stp.OUT_OF_GAS_EXCEPTION already set"); - } else { - filled.set(22); - } - - outOfGasException.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace resLo(final Bytes b) { - if (filled.get(23)) { - throw new IllegalStateException("stp.RES_LO already set"); - } else { - filled.set(23); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - resLo.put((byte) 0); - } - resLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace stamp(final Bytes b) { - if (filled.get(24)) { - throw new IllegalStateException("stp.STAMP already set"); - } else { - filled.set(24); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stamp.put((byte) 0); - } - stamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace valHi(final Bytes b) { - if (filled.get(25)) { - throw new IllegalStateException("stp.VAL_HI already set"); - } else { - filled.set(25); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - valHi.put((byte) 0); - } - valHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace valLo(final Bytes b) { - if (filled.get(26)) { - throw new IllegalStateException("stp.VAL_LO already set"); - } else { - filled.set(26); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - valLo.put((byte) 0); - } - valLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace warm(final Boolean b) { - if (filled.get(27)) { - throw new IllegalStateException("stp.WARM already set"); - } else { - filled.set(27); - } - - warm.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace wcpFlag(final Boolean b) { - if (filled.get(28)) { - throw new IllegalStateException("stp.WCP_FLAG already set"); - } else { - filled.set(28); - } - - wcpFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("stp.ARG_1_HI has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("stp.ARG_1_LO has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("stp.ARG_2_LO has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("stp.CT has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("stp.CT_MAX has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("stp.EXISTS has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("stp.EXOGENOUS_MODULE_INSTRUCTION has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("stp.GAS_ACTUAL has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("stp.GAS_HI has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("stp.GAS_LO has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("stp.GAS_MXP has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("stp.GAS_OOPKT has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("stp.GAS_STIPEND has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("stp.GAS_UPFRONT has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("stp.INSTRUCTION has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("stp.IS_CALL has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("stp.IS_CALLCODE has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("stp.IS_CREATE has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("stp.IS_CREATE2 has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("stp.IS_DELEGATECALL has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("stp.IS_STATICCALL has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("stp.MOD_FLAG has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("stp.OUT_OF_GAS_EXCEPTION has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("stp.RES_LO has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("stp.STAMP has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("stp.VAL_HI has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("stp.VAL_LO has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("stp.WARM has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("stp.WCP_FLAG has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - arg1Hi.position(arg1Hi.position() + 32); - } - - if (!filled.get(1)) { - arg1Lo.position(arg1Lo.position() + 32); - } - - if (!filled.get(2)) { - arg2Lo.position(arg2Lo.position() + 32); - } - - if (!filled.get(3)) { - ct.position(ct.position() + 32); - } - - if (!filled.get(4)) { - ctMax.position(ctMax.position() + 32); - } - - if (!filled.get(5)) { - exists.position(exists.position() + 1); - } - - if (!filled.get(6)) { - exogenousModuleInstruction.position(exogenousModuleInstruction.position() + 1); - } - - if (!filled.get(7)) { - gasActual.position(gasActual.position() + 32); - } - - if (!filled.get(8)) { - gasHi.position(gasHi.position() + 32); - } - - if (!filled.get(9)) { - gasLo.position(gasLo.position() + 32); - } - - if (!filled.get(10)) { - gasMxp.position(gasMxp.position() + 32); - } - - if (!filled.get(11)) { - gasOopkt.position(gasOopkt.position() + 32); - } - - if (!filled.get(12)) { - gasStipend.position(gasStipend.position() + 32); - } - - if (!filled.get(13)) { - gasUpfront.position(gasUpfront.position() + 32); - } - - if (!filled.get(14)) { - instruction.position(instruction.position() + 1); - } - - if (!filled.get(15)) { - isCall.position(isCall.position() + 1); - } - - if (!filled.get(16)) { - isCallcode.position(isCallcode.position() + 1); - } - - if (!filled.get(17)) { - isCreate.position(isCreate.position() + 1); - } - - if (!filled.get(18)) { - isCreate2.position(isCreate2.position() + 1); - } - - if (!filled.get(19)) { - isDelegatecall.position(isDelegatecall.position() + 1); - } - - if (!filled.get(20)) { - isStaticcall.position(isStaticcall.position() + 1); - } - - if (!filled.get(21)) { - modFlag.position(modFlag.position() + 1); - } - - if (!filled.get(22)) { - outOfGasException.position(outOfGasException.position() + 1); - } - - if (!filled.get(23)) { - resLo.position(resLo.position() + 32); - } - - if (!filled.get(24)) { - stamp.position(stamp.position() + 32); - } - - if (!filled.get(25)) { - valHi.position(valHi.position() + 32); - } - - if (!filled.get(26)) { - valLo.position(valLo.position() + 32); - } - - if (!filled.get(27)) { - warm.position(warm.position() + 1); - } - - if (!filled.get(28)) { - wcpFlag.position(wcpFlag.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/bin/BinRt.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/bin/BinRt.java deleted file mode 100644 index 63f6d67b6..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/bin/BinRt.java +++ /dev/null @@ -1,132 +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.tables.bin; - -import java.nio.MappedByteBuffer; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.BinRt.Trace; -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -public class BinRt implements Module { - @Override - public String moduleKey() { - return "binRT"; - } - - @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - return 3 * 256 * 256 + 256; // 256*256 lines for AND, OR and XOR, and 256 lines for NOT - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - // AND - UnsignedByte opCode = UnsignedByte.of(OpCode.AND.byteValue()); - - for (short input1 = 0; input1 <= 255; input1++) { - final Bytes input1Bytes = Bytes.of(input1); - final UnsignedByte input1UByte = UnsignedByte.of(input1); - - for (short input2 = 0; input2 <= 255; input2++) { - final Bytes input2Bytes = Bytes.of(input2); - final UnsignedByte input2UByte = UnsignedByte.of(input2); - - final UnsignedByte result = UnsignedByte.of(input1Bytes.and(input2Bytes).get(0)); - trace - .inst(opCode) - .resultByte(result) - .inputByte1(input1UByte) - .inputByte2(input2UByte) - .validateRow(); - } - } - - // OR - opCode = UnsignedByte.of(OpCode.OR.byteValue()); - - for (short input1 = 0; input1 <= 255; input1++) { - final Bytes input1Bytes = Bytes.of(input1); - final UnsignedByte input1UByte = UnsignedByte.of(input1); - - for (short input2 = 0; input2 <= 255; input2++) { - final Bytes input2Bytes = Bytes.of(input2); - final UnsignedByte input2UByte = UnsignedByte.of(input2); - - final UnsignedByte result = UnsignedByte.of(input1Bytes.or(input2Bytes).get(0)); - trace - .inst(opCode) - .resultByte(result) - .inputByte1(input1UByte) - .inputByte2(input2UByte) - .validateRow(); - } - } - - // XOR - opCode = UnsignedByte.of(OpCode.XOR.byteValue()); - - for (short input1 = 0; input1 <= 255; input1++) { - final Bytes input1Bytes = Bytes.of(input1); - final UnsignedByte input1UByte = UnsignedByte.of(input1); - - for (short input2 = 0; input2 <= 255; input2++) { - final Bytes input2Bytes = Bytes.of(input2); - final UnsignedByte input2UByte = UnsignedByte.of(input2); - - final UnsignedByte result = UnsignedByte.of(input1Bytes.xor(input2Bytes).get(0)); - trace - .inst(opCode) - .resultByte(result) - .inputByte1(input1UByte) - .inputByte2(input2UByte) - .validateRow(); - } - } - - // NOT - opCode = UnsignedByte.of(OpCode.NOT.byteValue()); - - for (short input1 = 0; input1 <= 255; input1++) { - final Bytes input1Bytes = Bytes.of(input1); - final UnsignedByte input1UByte = UnsignedByte.of(input1); - - final UnsignedByte result = UnsignedByte.of(input1Bytes.not().get(0)); - trace - .inst(opCode) - .resultByte(result) - .inputByte1(input1UByte) - .inputByte2(UnsignedByte.ZERO) - .validateRow(); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/bin/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/bin/Trace.java deleted file mode 100644 index 42d1093d6..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/bin/Trace.java +++ /dev/null @@ -1,163 +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.BinRt; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer inputByte1; - private final MappedByteBuffer inputByte2; - private final MappedByteBuffer inst; - private final MappedByteBuffer resultByte; - - public static List headers(int length) { - return List.of( - new ColumnHeader("binRT.INPUT_BYTE_1", 1, length), - new ColumnHeader("binRT.INPUT_BYTE_2", 1, length), - new ColumnHeader("binRT.INST", 1, length), - new ColumnHeader("binRT.RESULT_BYTE", 1, length)); - } - - public Trace(List buffers) { - this.inputByte1 = buffers.get(0); - this.inputByte2 = buffers.get(1); - this.inst = buffers.get(2); - this.resultByte = buffers.get(3); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace inputByte1(final UnsignedByte b) { - if (filled.get(0)) { - throw new IllegalStateException("binRT.INPUT_BYTE_1 already set"); - } else { - filled.set(0); - } - - inputByte1.put(b.toByte()); - - return this; - } - - public Trace inputByte2(final UnsignedByte b) { - if (filled.get(1)) { - throw new IllegalStateException("binRT.INPUT_BYTE_2 already set"); - } else { - filled.set(1); - } - - inputByte2.put(b.toByte()); - - return this; - } - - public Trace inst(final UnsignedByte b) { - if (filled.get(2)) { - throw new IllegalStateException("binRT.INST already set"); - } else { - filled.set(2); - } - - inst.put(b.toByte()); - - return this; - } - - public Trace resultByte(final UnsignedByte b) { - if (filled.get(3)) { - throw new IllegalStateException("binRT.RESULT_BYTE already set"); - } else { - filled.set(3); - } - - resultByte.put(b.toByte()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("binRT.INPUT_BYTE_1 has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("binRT.INPUT_BYTE_2 has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("binRT.INST has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("binRT.RESULT_BYTE has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - inputByte1.position(inputByte1.position() + 1); - } - - if (!filled.get(1)) { - inputByte2.position(inputByte2.position() + 1); - } - - if (!filled.get(2)) { - inst.position(inst.position() + 1); - } - - if (!filled.get(3)) { - resultByte.position(resultByte.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} 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 deleted file mode 100644 index 15139d441..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java +++ /dev/null @@ -1,180 +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.tables.instructionDecoder; - -import java.math.BigInteger; -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; - -public final class InstructionDecoder implements Module { - private static void traceFamily(OpCodeData op, Trace trace) { - trace - .familyAdd(op.instructionFamily() == InstructionFamily.ADD) - .familyMod(op.instructionFamily() == InstructionFamily.MOD) - .familyMul(op.instructionFamily() == InstructionFamily.MUL) - .familyExt(op.instructionFamily() == InstructionFamily.EXT) - .familyWcp(op.instructionFamily() == InstructionFamily.WCP) - .familyBin(op.instructionFamily() == InstructionFamily.BIN) - .familyShf(op.instructionFamily() == InstructionFamily.SHF) - .familyKec(op.instructionFamily() == InstructionFamily.KEC) - .familyContext(op.instructionFamily() == InstructionFamily.CONTEXT) - .familyAccount(op.instructionFamily() == InstructionFamily.ACCOUNT) - .familyCopy(op.instructionFamily() == InstructionFamily.COPY) - .familyTransaction(op.instructionFamily() == InstructionFamily.TRANSACTION) - .familyBatch(op.instructionFamily() == InstructionFamily.BATCH) - .familyStackRam(op.instructionFamily() == InstructionFamily.STACK_RAM) - .familyStorage(op.instructionFamily() == InstructionFamily.STORAGE) - .familyJump(op.instructionFamily() == InstructionFamily.JUMP) - .familyMachineState(op.instructionFamily() == InstructionFamily.JUMP) - .familyPushPop(op.instructionFamily() == InstructionFamily.PUSH_POP) - .familyDup(op.instructionFamily() == InstructionFamily.DUP) - .familySwap(op.instructionFamily() == InstructionFamily.SWAP) - .familyLog(op.instructionFamily() == InstructionFamily.LOG) - .familyCreate(op.instructionFamily() == InstructionFamily.CREATE) - .familyCall(op.instructionFamily() == InstructionFamily.CALL) - .familyHalt(op.instructionFamily() == InstructionFamily.HALT) - .familyInvalid(op.instructionFamily() == InstructionFamily.INVALID); - } - - 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(BigInteger.valueOf(op.stackSettings().staticGas().cost())) - .twoLinesInstruction(op.stackSettings().twoLinesInstruction()) - .forbiddenInStatic(op.stackSettings().forbiddenInStatic()) - .addressTrimmingInstruction(op.stackSettings().addressTrimmingInstruction()) - .flag1(op.stackSettings().flag1()) - .flag2(op.stackSettings().flag2()) - .flag3(op.stackSettings().flag3()) - .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( - BigInteger.valueOf( - op.billing().billingRate() == BillingRate.BY_WORD - ? op.billing().perUnit().cost() - : 0)) - .billingPerByte( - BigInteger.valueOf( - op.billing().billingRate() == BillingRate.BY_BYTE - ? op.billing().perUnit().cost() - : 0)) - .mxpType1(op.billing().type() == MxpType.TYPE_1) - .mxpType2(op.billing().type() == MxpType.TYPE_2) - .mxpType3(op.billing().type() == MxpType.TYPE_3) - .mxpType4(op.billing().type() == MxpType.TYPE_4) - .mxpType5(op.billing().type() == MxpType.TYPE_5); - } - - @Override - public String moduleKey() { - return "instruction-decoder"; - } - - @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - return 256; - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - Trace trace = new Trace(buffers); - - for (int i = 0; i < 256; i++) { - final OpCodeData op = OpCode.of(i).getData(); - - traceFamily(op, trace); - traceStackSettings(op, trace); - traceRamSettings(op, trace); - traceBillingSettings(op, trace); - trace - .opcode(BigInteger.valueOf(i)) - .isPush(op.pushFlag()) - .isJumpdest(op.jumpFlag()) - .validateRow(); - } - } -} 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 deleted file mode 100644 index 92c521d03..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/Trace.java +++ /dev/null @@ -1,2023 +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.tables.instructionDecoder; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -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; - private final MappedByteBuffer delta; - private final MappedByteBuffer familyAccount; - private final MappedByteBuffer familyAdd; - private final MappedByteBuffer familyBatch; - private final MappedByteBuffer familyBin; - private final MappedByteBuffer familyCall; - private final MappedByteBuffer familyContext; - private final MappedByteBuffer familyCopy; - private final MappedByteBuffer familyCreate; - private final MappedByteBuffer familyDup; - private final MappedByteBuffer familyExt; - private final MappedByteBuffer familyHalt; - private final MappedByteBuffer familyInvalid; - private final MappedByteBuffer familyJump; - private final MappedByteBuffer familyKec; - private final MappedByteBuffer familyLog; - private final MappedByteBuffer familyMachineState; - private final MappedByteBuffer familyMod; - private final MappedByteBuffer familyMul; - private final MappedByteBuffer familyPushPop; - private final MappedByteBuffer familyShf; - private final MappedByteBuffer familyStackRam; - private final MappedByteBuffer familyStorage; - private final MappedByteBuffer familySwap; - private final MappedByteBuffer familyTransaction; - private final MappedByteBuffer familyWcp; - private final MappedByteBuffer flag1; - private final MappedByteBuffer flag2; - private final MappedByteBuffer flag3; - private final MappedByteBuffer flag4; - private final MappedByteBuffer forbiddenInStatic; - private final MappedByteBuffer isJumpdest; - private final MappedByteBuffer isPush; - private final MappedByteBuffer mxpType1; - private final MappedByteBuffer mxpType2; - private final MappedByteBuffer mxpType3; - private final MappedByteBuffer mxpType4; - private final MappedByteBuffer mxpType5; - 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 staticGas; - private final MappedByteBuffer twoLinesInstruction; - - static List headers(int length) { - return List.of( - new ColumnHeader("instruction-decoder.ADDRESS_TRIMMING_INSTRUCTION", 1, length), - new ColumnHeader("instruction-decoder.ALPHA", 1, length), - new ColumnHeader("instruction-decoder.BILLING_PER_BYTE", 32, length), - new ColumnHeader("instruction-decoder.BILLING_PER_WORD", 32, length), - new ColumnHeader("instruction-decoder.DELTA", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_ACCOUNT", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_ADD", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_BATCH", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_BIN", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_CALL", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_CONTEXT", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_COPY", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_CREATE", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_DUP", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_EXT", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_HALT", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_INVALID", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_JUMP", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_KEC", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_LOG", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_MACHINE_STATE", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_MOD", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_MUL", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_PUSH_POP", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_SHF", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_STACK_RAM", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_STORAGE", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_SWAP", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_TRANSACTION", 1, length), - new ColumnHeader("instruction-decoder.FAMILY_WCP", 1, length), - new ColumnHeader("instruction-decoder.FLAG1", 1, length), - new ColumnHeader("instruction-decoder.FLAG2", 1, length), - new ColumnHeader("instruction-decoder.FLAG3", 1, length), - new ColumnHeader("instruction-decoder.FLAG4", 1, length), - new ColumnHeader("instruction-decoder.FORBIDDEN_IN_STATIC", 1, length), - new ColumnHeader("instruction-decoder.IS_JUMPDEST", 1, length), - new ColumnHeader("instruction-decoder.IS_PUSH", 1, length), - new ColumnHeader("instruction-decoder.MXP_TYPE_1", 1, length), - new ColumnHeader("instruction-decoder.MXP_TYPE_2", 1, length), - new ColumnHeader("instruction-decoder.MXP_TYPE_3", 1, length), - new ColumnHeader("instruction-decoder.MXP_TYPE_4", 1, length), - new ColumnHeader("instruction-decoder.MXP_TYPE_5", 1, length), - new ColumnHeader("instruction-decoder.NB_ADDED", 1, length), - new ColumnHeader("instruction-decoder.NB_REMOVED", 1, length), - new ColumnHeader("instruction-decoder.OPCODE", 32, length), - new ColumnHeader("instruction-decoder.PATTERN_CALL", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_COPY", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_CREATE", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_DUP", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_LOAD_STORE", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_LOG", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_ONE_ONE", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_ONE_ZERO", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_SWAP", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_THREE_ONE", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_TWO_ONE", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_TWO_ZERO", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_ZERO_ONE", 1, length), - new ColumnHeader("instruction-decoder.PATTERN_ZERO_ZERO", 1, length), - new ColumnHeader("instruction-decoder.RAM_ENABLED", 1, length), - new ColumnHeader("instruction-decoder.RAM_SOURCE_BLAKE_DATA", 1, length), - new ColumnHeader("instruction-decoder.RAM_SOURCE_EC_DATA", 1, length), - new ColumnHeader("instruction-decoder.RAM_SOURCE_EC_INFO", 1, length), - new ColumnHeader("instruction-decoder.RAM_SOURCE_HASH_DATA", 1, length), - new ColumnHeader("instruction-decoder.RAM_SOURCE_HASH_INFO", 1, length), - new ColumnHeader("instruction-decoder.RAM_SOURCE_LOG_DATA", 1, length), - new ColumnHeader("instruction-decoder.RAM_SOURCE_MODEXP_DATA", 1, length), - new ColumnHeader("instruction-decoder.RAM_SOURCE_RAM", 1, length), - new ColumnHeader("instruction-decoder.RAM_SOURCE_ROM", 1, length), - new ColumnHeader("instruction-decoder.RAM_SOURCE_STACK", 1, length), - new ColumnHeader("instruction-decoder.RAM_SOURCE_TXN_DATA", 1, length), - new ColumnHeader("instruction-decoder.RAM_TARGET_BLAKE_DATA", 1, length), - new ColumnHeader("instruction-decoder.RAM_TARGET_EC_DATA", 1, length), - new ColumnHeader("instruction-decoder.RAM_TARGET_EC_INFO", 1, length), - new ColumnHeader("instruction-decoder.RAM_TARGET_HASH_DATA", 1, length), - new ColumnHeader("instruction-decoder.RAM_TARGET_HASH_INFO", 1, length), - new ColumnHeader("instruction-decoder.RAM_TARGET_LOG_DATA", 1, length), - new ColumnHeader("instruction-decoder.RAM_TARGET_MODEXP_DATA", 1, length), - new ColumnHeader("instruction-decoder.RAM_TARGET_RAM", 1, length), - new ColumnHeader("instruction-decoder.RAM_TARGET_ROM", 1, length), - new ColumnHeader("instruction-decoder.RAM_TARGET_STACK", 1, length), - new ColumnHeader("instruction-decoder.RAM_TARGET_TXN_DATA", 1, length), - new ColumnHeader("instruction-decoder.STATIC_GAS", 32, length), - new ColumnHeader("instruction-decoder.TWO_LINES_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.forbiddenInStatic = buffers.get(34); - this.isJumpdest = buffers.get(35); - this.isPush = 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.staticGas = buffers.get(82); - this.twoLinesInstruction = buffers.get(83); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace addressTrimmingInstruction(final Boolean b) { - if (filled.get(0)) { - throw new IllegalStateException( - "instruction-decoder.ADDRESS_TRIMMING_INSTRUCTION already set"); - } else { - filled.set(0); - } - - addressTrimmingInstruction.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace alpha(final UnsignedByte b) { - if (filled.get(1)) { - throw new IllegalStateException("instruction-decoder.ALPHA already set"); - } else { - filled.set(1); - } - - alpha.put(b.toByte()); - - return this; - } - - public Trace billingPerByte(final BigInteger b) { - if (filled.get(2)) { - throw new IllegalStateException("instruction-decoder.BILLING_PER_BYTE already set"); - } else { - filled.set(2); - } - - billingPerByte.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace billingPerWord(final BigInteger b) { - if (filled.get(3)) { - throw new IllegalStateException("instruction-decoder.BILLING_PER_WORD already set"); - } else { - filled.set(3); - } - - billingPerWord.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace delta(final UnsignedByte b) { - if (filled.get(4)) { - throw new IllegalStateException("instruction-decoder.DELTA already set"); - } else { - filled.set(4); - } - - delta.put(b.toByte()); - - return this; - } - - public Trace familyAccount(final Boolean b) { - if (filled.get(5)) { - throw new IllegalStateException("instruction-decoder.FAMILY_ACCOUNT already set"); - } else { - filled.set(5); - } - - familyAccount.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyAdd(final Boolean b) { - if (filled.get(6)) { - throw new IllegalStateException("instruction-decoder.FAMILY_ADD already set"); - } else { - filled.set(6); - } - - familyAdd.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyBatch(final Boolean b) { - if (filled.get(7)) { - throw new IllegalStateException("instruction-decoder.FAMILY_BATCH already set"); - } else { - filled.set(7); - } - - familyBatch.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyBin(final Boolean b) { - if (filled.get(8)) { - throw new IllegalStateException("instruction-decoder.FAMILY_BIN already set"); - } else { - filled.set(8); - } - - familyBin.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyCall(final Boolean b) { - if (filled.get(9)) { - throw new IllegalStateException("instruction-decoder.FAMILY_CALL already set"); - } else { - filled.set(9); - } - - familyCall.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyContext(final Boolean b) { - if (filled.get(10)) { - throw new IllegalStateException("instruction-decoder.FAMILY_CONTEXT already set"); - } else { - filled.set(10); - } - - familyContext.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyCopy(final Boolean b) { - if (filled.get(11)) { - throw new IllegalStateException("instruction-decoder.FAMILY_COPY already set"); - } else { - filled.set(11); - } - - familyCopy.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyCreate(final Boolean b) { - if (filled.get(12)) { - throw new IllegalStateException("instruction-decoder.FAMILY_CREATE already set"); - } else { - filled.set(12); - } - - familyCreate.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyDup(final Boolean b) { - if (filled.get(13)) { - throw new IllegalStateException("instruction-decoder.FAMILY_DUP already set"); - } else { - filled.set(13); - } - - familyDup.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyExt(final Boolean b) { - if (filled.get(14)) { - throw new IllegalStateException("instruction-decoder.FAMILY_EXT already set"); - } else { - filled.set(14); - } - - familyExt.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyHalt(final Boolean b) { - if (filled.get(15)) { - throw new IllegalStateException("instruction-decoder.FAMILY_HALT already set"); - } else { - filled.set(15); - } - - familyHalt.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyInvalid(final Boolean b) { - if (filled.get(16)) { - throw new IllegalStateException("instruction-decoder.FAMILY_INVALID already set"); - } else { - filled.set(16); - } - - familyInvalid.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyJump(final Boolean b) { - if (filled.get(17)) { - throw new IllegalStateException("instruction-decoder.FAMILY_JUMP already set"); - } else { - filled.set(17); - } - - familyJump.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyKec(final Boolean b) { - if (filled.get(18)) { - throw new IllegalStateException("instruction-decoder.FAMILY_KEC already set"); - } else { - filled.set(18); - } - - familyKec.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyLog(final Boolean b) { - if (filled.get(19)) { - throw new IllegalStateException("instruction-decoder.FAMILY_LOG already set"); - } else { - filled.set(19); - } - - familyLog.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyMachineState(final Boolean b) { - if (filled.get(20)) { - throw new IllegalStateException("instruction-decoder.FAMILY_MACHINE_STATE already set"); - } else { - filled.set(20); - } - - familyMachineState.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyMod(final Boolean b) { - if (filled.get(21)) { - throw new IllegalStateException("instruction-decoder.FAMILY_MOD already set"); - } else { - filled.set(21); - } - - familyMod.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyMul(final Boolean b) { - if (filled.get(22)) { - throw new IllegalStateException("instruction-decoder.FAMILY_MUL already set"); - } else { - filled.set(22); - } - - familyMul.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyPushPop(final Boolean b) { - if (filled.get(23)) { - throw new IllegalStateException("instruction-decoder.FAMILY_PUSH_POP already set"); - } else { - filled.set(23); - } - - familyPushPop.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyShf(final Boolean b) { - if (filled.get(24)) { - throw new IllegalStateException("instruction-decoder.FAMILY_SHF already set"); - } else { - filled.set(24); - } - - familyShf.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyStackRam(final Boolean b) { - if (filled.get(25)) { - throw new IllegalStateException("instruction-decoder.FAMILY_STACK_RAM already set"); - } else { - filled.set(25); - } - - familyStackRam.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyStorage(final Boolean b) { - if (filled.get(26)) { - throw new IllegalStateException("instruction-decoder.FAMILY_STORAGE already set"); - } else { - filled.set(26); - } - - familyStorage.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familySwap(final Boolean b) { - if (filled.get(27)) { - throw new IllegalStateException("instruction-decoder.FAMILY_SWAP already set"); - } else { - filled.set(27); - } - - familySwap.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyTransaction(final Boolean b) { - if (filled.get(28)) { - throw new IllegalStateException("instruction-decoder.FAMILY_TRANSACTION already set"); - } else { - filled.set(28); - } - - familyTransaction.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace familyWcp(final Boolean b) { - if (filled.get(29)) { - throw new IllegalStateException("instruction-decoder.FAMILY_WCP already set"); - } else { - filled.set(29); - } - - familyWcp.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace flag1(final Boolean b) { - if (filled.get(30)) { - throw new IllegalStateException("instruction-decoder.FLAG1 already set"); - } else { - filled.set(30); - } - - flag1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace flag2(final Boolean b) { - if (filled.get(31)) { - throw new IllegalStateException("instruction-decoder.FLAG2 already set"); - } else { - filled.set(31); - } - - flag2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace flag3(final Boolean b) { - if (filled.get(32)) { - throw new IllegalStateException("instruction-decoder.FLAG3 already set"); - } else { - filled.set(32); - } - - flag3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace flag4(final Boolean b) { - if (filled.get(33)) { - throw new IllegalStateException("instruction-decoder.FLAG4 already set"); - } else { - filled.set(33); - } - - flag4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace forbiddenInStatic(final Boolean b) { - if (filled.get(34)) { - throw new IllegalStateException("instruction-decoder.FORBIDDEN_IN_STATIC already set"); - } else { - filled.set(34); - } - - forbiddenInStatic.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isJumpdest(final Boolean b) { - if (filled.get(35)) { - throw new IllegalStateException("instruction-decoder.IS_JUMPDEST already set"); - } else { - filled.set(35); - } - - isJumpdest.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isPush(final Boolean b) { - if (filled.get(36)) { - throw new IllegalStateException("instruction-decoder.IS_PUSH already set"); - } else { - filled.set(36); - } - - isPush.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace mxpType1(final Boolean b) { - if (filled.get(37)) { - throw new IllegalStateException("instruction-decoder.MXP_TYPE_1 already set"); - } else { - filled.set(37); - } - - mxpType1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace mxpType2(final Boolean b) { - if (filled.get(38)) { - throw new IllegalStateException("instruction-decoder.MXP_TYPE_2 already set"); - } else { - filled.set(38); - } - - mxpType2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace mxpType3(final Boolean b) { - if (filled.get(39)) { - throw new IllegalStateException("instruction-decoder.MXP_TYPE_3 already set"); - } else { - filled.set(39); - } - - mxpType3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace mxpType4(final Boolean b) { - if (filled.get(40)) { - throw new IllegalStateException("instruction-decoder.MXP_TYPE_4 already set"); - } else { - filled.set(40); - } - - mxpType4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace mxpType5(final Boolean b) { - if (filled.get(41)) { - throw new IllegalStateException("instruction-decoder.MXP_TYPE_5 already set"); - } else { - filled.set(41); - } - - mxpType5.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace nbAdded(final UnsignedByte b) { - if (filled.get(42)) { - throw new IllegalStateException("instruction-decoder.NB_ADDED already set"); - } else { - filled.set(42); - } - - nbAdded.put(b.toByte()); - - return this; - } - - public Trace nbRemoved(final UnsignedByte b) { - if (filled.get(43)) { - throw new IllegalStateException("instruction-decoder.NB_REMOVED already set"); - } else { - filled.set(43); - } - - nbRemoved.put(b.toByte()); - - return this; - } - - public Trace opcode(final BigInteger b) { - if (filled.get(44)) { - throw new IllegalStateException("instruction-decoder.OPCODE already set"); - } else { - filled.set(44); - } - - opcode.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace patternCall(final Boolean b) { - if (filled.get(45)) { - throw new IllegalStateException("instruction-decoder.PATTERN_CALL already set"); - } else { - filled.set(45); - } - - patternCall.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternCopy(final Boolean b) { - if (filled.get(46)) { - throw new IllegalStateException("instruction-decoder.PATTERN_COPY already set"); - } else { - filled.set(46); - } - - patternCopy.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternCreate(final Boolean b) { - if (filled.get(47)) { - throw new IllegalStateException("instruction-decoder.PATTERN_CREATE already set"); - } else { - filled.set(47); - } - - patternCreate.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternDup(final Boolean b) { - if (filled.get(48)) { - throw new IllegalStateException("instruction-decoder.PATTERN_DUP already set"); - } else { - filled.set(48); - } - - patternDup.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternLoadStore(final Boolean b) { - if (filled.get(49)) { - throw new IllegalStateException("instruction-decoder.PATTERN_LOAD_STORE already set"); - } else { - filled.set(49); - } - - patternLoadStore.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternLog(final Boolean b) { - if (filled.get(50)) { - throw new IllegalStateException("instruction-decoder.PATTERN_LOG already set"); - } else { - filled.set(50); - } - - patternLog.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternOneOne(final Boolean b) { - if (filled.get(51)) { - throw new IllegalStateException("instruction-decoder.PATTERN_ONE_ONE already set"); - } else { - filled.set(51); - } - - patternOneOne.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternOneZero(final Boolean b) { - if (filled.get(52)) { - throw new IllegalStateException("instruction-decoder.PATTERN_ONE_ZERO already set"); - } else { - filled.set(52); - } - - patternOneZero.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternSwap(final Boolean b) { - if (filled.get(53)) { - throw new IllegalStateException("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.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("instruction-decoder.RAM_TARGET_TXN_DATA already set"); - } else { - filled.set(81); - } - - ramTargetTxnData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace staticGas(final BigInteger b) { - if (filled.get(82)) { - throw new IllegalStateException("instruction-decoder.STATIC_GAS already set"); - } else { - filled.set(82); - } - - staticGas.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace twoLinesInstruction(final Boolean b) { - if (filled.get(83)) { - throw new IllegalStateException("instruction-decoder.TWO_LINES_INSTRUCTION already set"); - } else { - filled.set(83); - } - - twoLinesInstruction.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException( - "instruction-decoder.ADDRESS_TRIMMING_INSTRUCTION has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("instruction-decoder.ALPHA has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("instruction-decoder.BILLING_PER_BYTE has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("instruction-decoder.BILLING_PER_WORD has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("instruction-decoder.DELTA has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("instruction-decoder.FAMILY_ACCOUNT has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("instruction-decoder.FAMILY_ADD has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("instruction-decoder.FAMILY_BATCH has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("instruction-decoder.FAMILY_BIN has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("instruction-decoder.FAMILY_CALL has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("instruction-decoder.FAMILY_CONTEXT has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("instruction-decoder.FAMILY_COPY has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("instruction-decoder.FAMILY_CREATE has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("instruction-decoder.FAMILY_DUP has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("instruction-decoder.FAMILY_EXT has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("instruction-decoder.FAMILY_HALT has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("instruction-decoder.FAMILY_INVALID has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("instruction-decoder.FAMILY_JUMP has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("instruction-decoder.FAMILY_KEC has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("instruction-decoder.FAMILY_LOG has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException( - "instruction-decoder.FAMILY_MACHINE_STATE has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("instruction-decoder.FAMILY_MOD has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("instruction-decoder.FAMILY_MUL has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("instruction-decoder.FAMILY_PUSH_POP has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("instruction-decoder.FAMILY_SHF has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("instruction-decoder.FAMILY_STACK_RAM has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("instruction-decoder.FAMILY_STORAGE has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("instruction-decoder.FAMILY_SWAP has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("instruction-decoder.FAMILY_TRANSACTION has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("instruction-decoder.FAMILY_WCP has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("instruction-decoder.FLAG1 has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("instruction-decoder.FLAG2 has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("instruction-decoder.FLAG3 has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("instruction-decoder.FLAG4 has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException( - "instruction-decoder.FORBIDDEN_IN_STATIC has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("instruction-decoder.IS_JUMPDEST has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("instruction-decoder.IS_PUSH has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("instruction-decoder.MXP_TYPE_1 has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("instruction-decoder.MXP_TYPE_2 has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("instruction-decoder.MXP_TYPE_3 has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("instruction-decoder.MXP_TYPE_4 has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("instruction-decoder.MXP_TYPE_5 has not been filled"); - } - - if (!filled.get(42)) { - throw new IllegalStateException("instruction-decoder.NB_ADDED has not been filled"); - } - - if (!filled.get(43)) { - throw new IllegalStateException("instruction-decoder.NB_REMOVED has not been filled"); - } - - if (!filled.get(44)) { - throw new IllegalStateException("instruction-decoder.OPCODE has not been filled"); - } - - if (!filled.get(45)) { - throw new IllegalStateException("instruction-decoder.PATTERN_CALL has not been filled"); - } - - if (!filled.get(46)) { - throw new IllegalStateException("instruction-decoder.PATTERN_COPY has not been filled"); - } - - if (!filled.get(47)) { - throw new IllegalStateException("instruction-decoder.PATTERN_CREATE has not been filled"); - } - - if (!filled.get(48)) { - throw new IllegalStateException("instruction-decoder.PATTERN_DUP has not been filled"); - } - - if (!filled.get(49)) { - throw new IllegalStateException("instruction-decoder.PATTERN_LOAD_STORE has not been filled"); - } - - if (!filled.get(50)) { - throw new IllegalStateException("instruction-decoder.PATTERN_LOG has not been filled"); - } - - if (!filled.get(51)) { - throw new IllegalStateException("instruction-decoder.PATTERN_ONE_ONE has not been filled"); - } - - if (!filled.get(52)) { - throw new IllegalStateException("instruction-decoder.PATTERN_ONE_ZERO has not been filled"); - } - - if (!filled.get(53)) { - throw new IllegalStateException("instruction-decoder.PATTERN_SWAP has not been filled"); - } - - if (!filled.get(54)) { - throw new IllegalStateException("instruction-decoder.PATTERN_THREE_ONE has not been filled"); - } - - if (!filled.get(55)) { - throw new IllegalStateException("instruction-decoder.PATTERN_TWO_ONE has not been filled"); - } - - if (!filled.get(56)) { - throw new IllegalStateException("instruction-decoder.PATTERN_TWO_ZERO has not been filled"); - } - - if (!filled.get(57)) { - throw new IllegalStateException("instruction-decoder.PATTERN_ZERO_ONE has not been filled"); - } - - if (!filled.get(58)) { - throw new IllegalStateException("instruction-decoder.PATTERN_ZERO_ZERO has not been filled"); - } - - if (!filled.get(59)) { - throw new IllegalStateException("instruction-decoder.RAM_ENABLED has not been filled"); - } - - if (!filled.get(60)) { - throw new IllegalStateException( - "instruction-decoder.RAM_SOURCE_BLAKE_DATA has not been filled"); - } - - if (!filled.get(61)) { - throw new IllegalStateException("instruction-decoder.RAM_SOURCE_EC_DATA has not been filled"); - } - - if (!filled.get(62)) { - throw new IllegalStateException("instruction-decoder.RAM_SOURCE_EC_INFO has not been filled"); - } - - if (!filled.get(63)) { - throw new IllegalStateException( - "instruction-decoder.RAM_SOURCE_HASH_DATA has not been filled"); - } - - if (!filled.get(64)) { - throw new IllegalStateException( - "instruction-decoder.RAM_SOURCE_HASH_INFO has not been filled"); - } - - if (!filled.get(65)) { - throw new IllegalStateException( - "instruction-decoder.RAM_SOURCE_LOG_DATA has not been filled"); - } - - if (!filled.get(66)) { - throw new IllegalStateException( - "instruction-decoder.RAM_SOURCE_MODEXP_DATA has not been filled"); - } - - if (!filled.get(67)) { - throw new IllegalStateException("instruction-decoder.RAM_SOURCE_RAM has not been filled"); - } - - if (!filled.get(68)) { - throw new IllegalStateException("instruction-decoder.RAM_SOURCE_ROM has not been filled"); - } - - if (!filled.get(69)) { - throw new IllegalStateException("instruction-decoder.RAM_SOURCE_STACK has not been filled"); - } - - if (!filled.get(70)) { - throw new IllegalStateException( - "instruction-decoder.RAM_SOURCE_TXN_DATA has not been filled"); - } - - if (!filled.get(71)) { - throw new IllegalStateException( - "instruction-decoder.RAM_TARGET_BLAKE_DATA has not been filled"); - } - - if (!filled.get(72)) { - throw new IllegalStateException("instruction-decoder.RAM_TARGET_EC_DATA has not been filled"); - } - - if (!filled.get(73)) { - throw new IllegalStateException("instruction-decoder.RAM_TARGET_EC_INFO has not been filled"); - } - - if (!filled.get(74)) { - throw new IllegalStateException( - "instruction-decoder.RAM_TARGET_HASH_DATA has not been filled"); - } - - if (!filled.get(75)) { - throw new IllegalStateException( - "instruction-decoder.RAM_TARGET_HASH_INFO has not been filled"); - } - - if (!filled.get(76)) { - throw new IllegalStateException( - "instruction-decoder.RAM_TARGET_LOG_DATA has not been filled"); - } - - if (!filled.get(77)) { - throw new IllegalStateException( - "instruction-decoder.RAM_TARGET_MODEXP_DATA has not been filled"); - } - - if (!filled.get(78)) { - throw new IllegalStateException("instruction-decoder.RAM_TARGET_RAM has not been filled"); - } - - if (!filled.get(79)) { - throw new IllegalStateException("instruction-decoder.RAM_TARGET_ROM has not been filled"); - } - - if (!filled.get(80)) { - throw new IllegalStateException("instruction-decoder.RAM_TARGET_STACK has not been filled"); - } - - if (!filled.get(81)) { - throw new IllegalStateException( - "instruction-decoder.RAM_TARGET_TXN_DATA has not been filled"); - } - - if (!filled.get(82)) { - throw new IllegalStateException("instruction-decoder.STATIC_GAS has not been filled"); - } - - if (!filled.get(83)) { - throw new IllegalStateException( - "instruction-decoder.TWO_LINES_INSTRUCTION has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - addressTrimmingInstruction.position(addressTrimmingInstruction.position() + 1); - } - - if (!filled.get(1)) { - alpha.position(alpha.position() + 1); - } - - if (!filled.get(2)) { - billingPerByte.position(billingPerByte.position() + 32); - } - - if (!filled.get(3)) { - billingPerWord.position(billingPerWord.position() + 32); - } - - if (!filled.get(4)) { - delta.position(delta.position() + 1); - } - - if (!filled.get(5)) { - familyAccount.position(familyAccount.position() + 1); - } - - if (!filled.get(6)) { - familyAdd.position(familyAdd.position() + 1); - } - - if (!filled.get(7)) { - familyBatch.position(familyBatch.position() + 1); - } - - if (!filled.get(8)) { - familyBin.position(familyBin.position() + 1); - } - - if (!filled.get(9)) { - familyCall.position(familyCall.position() + 1); - } - - if (!filled.get(10)) { - familyContext.position(familyContext.position() + 1); - } - - if (!filled.get(11)) { - familyCopy.position(familyCopy.position() + 1); - } - - if (!filled.get(12)) { - familyCreate.position(familyCreate.position() + 1); - } - - if (!filled.get(13)) { - familyDup.position(familyDup.position() + 1); - } - - if (!filled.get(14)) { - familyExt.position(familyExt.position() + 1); - } - - if (!filled.get(15)) { - familyHalt.position(familyHalt.position() + 1); - } - - if (!filled.get(16)) { - familyInvalid.position(familyInvalid.position() + 1); - } - - if (!filled.get(17)) { - familyJump.position(familyJump.position() + 1); - } - - if (!filled.get(18)) { - familyKec.position(familyKec.position() + 1); - } - - if (!filled.get(19)) { - familyLog.position(familyLog.position() + 1); - } - - if (!filled.get(20)) { - familyMachineState.position(familyMachineState.position() + 1); - } - - if (!filled.get(21)) { - familyMod.position(familyMod.position() + 1); - } - - if (!filled.get(22)) { - familyMul.position(familyMul.position() + 1); - } - - if (!filled.get(23)) { - familyPushPop.position(familyPushPop.position() + 1); - } - - if (!filled.get(24)) { - familyShf.position(familyShf.position() + 1); - } - - if (!filled.get(25)) { - familyStackRam.position(familyStackRam.position() + 1); - } - - if (!filled.get(26)) { - familyStorage.position(familyStorage.position() + 1); - } - - if (!filled.get(27)) { - familySwap.position(familySwap.position() + 1); - } - - if (!filled.get(28)) { - familyTransaction.position(familyTransaction.position() + 1); - } - - if (!filled.get(29)) { - familyWcp.position(familyWcp.position() + 1); - } - - if (!filled.get(30)) { - flag1.position(flag1.position() + 1); - } - - if (!filled.get(31)) { - flag2.position(flag2.position() + 1); - } - - if (!filled.get(32)) { - flag3.position(flag3.position() + 1); - } - - if (!filled.get(33)) { - flag4.position(flag4.position() + 1); - } - - if (!filled.get(34)) { - forbiddenInStatic.position(forbiddenInStatic.position() + 1); - } - - if (!filled.get(35)) { - isJumpdest.position(isJumpdest.position() + 1); - } - - if (!filled.get(36)) { - isPush.position(isPush.position() + 1); - } - - if (!filled.get(37)) { - mxpType1.position(mxpType1.position() + 1); - } - - if (!filled.get(38)) { - mxpType2.position(mxpType2.position() + 1); - } - - if (!filled.get(39)) { - mxpType3.position(mxpType3.position() + 1); - } - - if (!filled.get(40)) { - mxpType4.position(mxpType4.position() + 1); - } - - if (!filled.get(41)) { - mxpType5.position(mxpType5.position() + 1); - } - - if (!filled.get(42)) { - nbAdded.position(nbAdded.position() + 1); - } - - if (!filled.get(43)) { - nbRemoved.position(nbRemoved.position() + 1); - } - - if (!filled.get(44)) { - opcode.position(opcode.position() + 32); - } - - if (!filled.get(45)) { - patternCall.position(patternCall.position() + 1); - } - - 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)) { - staticGas.position(staticGas.position() + 32); - } - - if (!filled.get(83)) { - twoLinesInstruction.position(twoLinesInstruction.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - return null; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/shf/ShfRt.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/shf/ShfRt.java deleted file mode 100644 index e0aa8f381..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/shf/ShfRt.java +++ /dev/null @@ -1,72 +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.tables.shf; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; -import org.apache.tuweni.bytes.Bytes; - -public record ShfRt() implements Module { - @Override - public String moduleKey() { - return "shfRT"; - } - - @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - return 256 * 9 + 1; - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - for (int a = 0; a <= 255; a++) { - for (int uShp = 0; uShp <= 8; uShp++) { - trace - ._byte(BigInteger.valueOf(a)) - .las(BigInteger.valueOf(Bytes.of((byte) a).shiftLeft(8 - uShp).toInt())) // a<<(8-µShp) - .mshp(BigInteger.valueOf(uShp)) - .rap(BigInteger.valueOf(Bytes.ofUnsignedShort(a).shiftRight(uShp).toInt())) - .ones(BigInteger.valueOf((Bytes.fromHexString("0xFF").shiftRight(uShp)).not().toInt())) - .isInRt(BigInteger.ONE) - .validateRow(); - } - } - - trace - ._byte(BigInteger.ZERO) - .isInRt(BigInteger.ZERO) - .las(BigInteger.ZERO) - .mshp(BigInteger.ZERO) - .ones(BigInteger.ZERO) - .rap(BigInteger.ZERO) - .validateRow(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/shf/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/shf/Trace.java deleted file mode 100644 index e9231bb59..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/shf/Trace.java +++ /dev/null @@ -1,211 +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.tables.shf; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import org.apache.tuweni.units.bigints.UInt256; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer _byte; - private final MappedByteBuffer isInRt; - private final MappedByteBuffer las; - private final MappedByteBuffer mshp; - private final MappedByteBuffer ones; - private final MappedByteBuffer rap; - - static List headers(int length) { - return List.of( - new ColumnHeader("shfRT.BYTE", 32, length), - new ColumnHeader("shfRT.IS_IN_RT", 32, length), - new ColumnHeader("shfRT.LAS", 32, length), - new ColumnHeader("shfRT.MSHP", 32, length), - new ColumnHeader("shfRT.ONES", 32, length), - new ColumnHeader("shfRT.RAP", 32, length)); - } - - public Trace(List buffers) { - this._byte = buffers.get(0); - this.isInRt = buffers.get(1); - this.las = buffers.get(2); - this.mshp = buffers.get(3); - this.ones = buffers.get(4); - this.rap = buffers.get(5); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace _byte(final BigInteger b) { - if (filled.get(0)) { - throw new IllegalStateException("shfRT.BYTE already set"); - } else { - filled.set(0); - } - - _byte.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace isInRt(final BigInteger b) { - if (filled.get(1)) { - throw new IllegalStateException("shfRT.IS_IN_RT already set"); - } else { - filled.set(1); - } - - isInRt.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace las(final BigInteger b) { - if (filled.get(2)) { - throw new IllegalStateException("shfRT.LAS already set"); - } else { - filled.set(2); - } - - las.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace mshp(final BigInteger b) { - if (filled.get(3)) { - throw new IllegalStateException("shfRT.MSHP already set"); - } else { - filled.set(3); - } - - mshp.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace ones(final BigInteger b) { - if (filled.get(4)) { - throw new IllegalStateException("shfRT.ONES already set"); - } else { - filled.set(4); - } - - ones.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace rap(final BigInteger b) { - if (filled.get(5)) { - throw new IllegalStateException("shfRT.RAP already set"); - } else { - filled.set(5); - } - - rap.put(UInt256.valueOf(b).toBytes().toArray()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("shfRT.BYTE has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("shfRT.IS_IN_RT has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("shfRT.LAS has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("shfRT.MSHP has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("shfRT.ONES has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("shfRT.RAP has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - _byte.position(_byte.position() + 32); - } - - if (!filled.get(1)) { - isInRt.position(isInRt.position() + 32); - } - - if (!filled.get(2)) { - las.position(las.position() + 32); - } - - if (!filled.get(3)) { - mshp.position(mshp.position() + 32); - } - - if (!filled.get(4)) { - ones.position(ones.position() + 32); - } - - if (!filled.get(5)) { - rap.position(rap.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - return null; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trace.java deleted file mode 100644 index 37d7a997c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trace.java +++ /dev/null @@ -1,403 +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.trm; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer accHi; - private final MappedByteBuffer accLo; - private final MappedByteBuffer accT; - private final MappedByteBuffer addrHi; - private final MappedByteBuffer addrLo; - private final MappedByteBuffer byteHi; - private final MappedByteBuffer byteLo; - private final MappedByteBuffer ct; - private final MappedByteBuffer isPrec; - private final MappedByteBuffer one; - private final MappedByteBuffer pbit; - private final MappedByteBuffer stamp; - private final MappedByteBuffer trmAddrHi; - - static List headers(int length) { - return List.of( - new ColumnHeader("trm.ACC_HI", 32, length), - new ColumnHeader("trm.ACC_LO", 32, length), - new ColumnHeader("trm.ACC_T", 32, length), - new ColumnHeader("trm.ADDR_HI", 32, length), - new ColumnHeader("trm.ADDR_LO", 32, length), - new ColumnHeader("trm.BYTE_HI", 1, length), - new ColumnHeader("trm.BYTE_LO", 1, length), - new ColumnHeader("trm.CT", 32, length), - new ColumnHeader("trm.IS_PREC", 1, length), - new ColumnHeader("trm.ONE", 1, length), - new ColumnHeader("trm.PBIT", 1, length), - new ColumnHeader("trm.STAMP", 32, length), - new ColumnHeader("trm.TRM_ADDR_HI", 32, length)); - } - - public Trace(List buffers) { - this.accHi = buffers.get(0); - this.accLo = buffers.get(1); - this.accT = buffers.get(2); - this.addrHi = buffers.get(3); - this.addrLo = buffers.get(4); - this.byteHi = buffers.get(5); - this.byteLo = buffers.get(6); - this.ct = buffers.get(7); - this.isPrec = buffers.get(8); - this.one = buffers.get(9); - this.pbit = buffers.get(10); - this.stamp = buffers.get(11); - this.trmAddrHi = buffers.get(12); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace accHi(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("trm.ACC_HI already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accHi.put((byte) 0); - } - accHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accLo(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("trm.ACC_LO already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accLo.put((byte) 0); - } - accLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace accT(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("trm.ACC_T already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accT.put((byte) 0); - } - accT.put(b.toArrayUnsafe()); - - return this; - } - - public Trace addrHi(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("trm.ADDR_HI already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrHi.put((byte) 0); - } - addrHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace addrLo(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("trm.ADDR_LO already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addrLo.put((byte) 0); - } - addrLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace byteHi(final UnsignedByte b) { - if (filled.get(5)) { - throw new IllegalStateException("trm.BYTE_HI already set"); - } else { - filled.set(5); - } - - byteHi.put(b.toByte()); - - return this; - } - - public Trace byteLo(final UnsignedByte b) { - if (filled.get(6)) { - throw new IllegalStateException("trm.BYTE_LO already set"); - } else { - filled.set(6); - } - - byteLo.put(b.toByte()); - - return this; - } - - public Trace ct(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("trm.CT already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - ct.put((byte) 0); - } - ct.put(b.toArrayUnsafe()); - - return this; - } - - public Trace isPrec(final Boolean b) { - if (filled.get(8)) { - throw new IllegalStateException("trm.IS_PREC already set"); - } else { - filled.set(8); - } - - isPrec.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace one(final Boolean b) { - if (filled.get(9)) { - throw new IllegalStateException("trm.ONE already set"); - } else { - filled.set(9); - } - - one.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace pbit(final Boolean b) { - if (filled.get(10)) { - throw new IllegalStateException("trm.PBIT already set"); - } else { - filled.set(10); - } - - pbit.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace stamp(final Bytes b) { - if (filled.get(11)) { - throw new IllegalStateException("trm.STAMP already set"); - } else { - filled.set(11); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stamp.put((byte) 0); - } - stamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace trmAddrHi(final Bytes b) { - if (filled.get(12)) { - throw new IllegalStateException("trm.TRM_ADDR_HI already set"); - } else { - filled.set(12); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - trmAddrHi.put((byte) 0); - } - trmAddrHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("trm.ACC_HI has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("trm.ACC_LO has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("trm.ACC_T has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("trm.ADDR_HI has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("trm.ADDR_LO has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("trm.BYTE_HI has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("trm.BYTE_LO has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("trm.CT has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("trm.IS_PREC has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("trm.ONE has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("trm.PBIT has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("trm.STAMP has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("trm.TRM_ADDR_HI has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - accHi.position(accHi.position() + 32); - } - - if (!filled.get(1)) { - accLo.position(accLo.position() + 32); - } - - if (!filled.get(2)) { - accT.position(accT.position() + 32); - } - - if (!filled.get(3)) { - addrHi.position(addrHi.position() + 32); - } - - if (!filled.get(4)) { - addrLo.position(addrLo.position() + 32); - } - - if (!filled.get(5)) { - byteHi.position(byteHi.position() + 1); - } - - if (!filled.get(6)) { - byteLo.position(byteLo.position() + 1); - } - - if (!filled.get(7)) { - ct.position(ct.position() + 32); - } - - if (!filled.get(8)) { - isPrec.position(isPrec.position() + 1); - } - - if (!filled.get(9)) { - one.position(one.position() + 1); - } - - if (!filled.get(10)) { - pbit.position(pbit.position() + 1); - } - - if (!filled.get(11)) { - stamp.position(stamp.position() + 32); - } - - if (!filled.get(12)) { - trmAddrHi.position(trmAddrHi.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} 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 deleted file mode 100644 index b34f8f974..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java +++ /dev/null @@ -1,115 +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 java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.List; - -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 org.hyperledger.besu.datatypes.AccessListEntry; -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 { - private int stamp = 0; - static final int MAX_CT = 16; - static final int LLARGE = 16; - static final int PIVOT_BIT_FLIPS_TO_TRUE = 12; - - private final StackedSet trimmings = new StackedSet<>(); - - @Override - public String moduleKey() { - return "TRM"; - } - - @Override - public void enterTransaction() { - this.trimmings.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)))); - } - } - } - - @Override - public void traceStartTx(WorldView worldView, Transaction tx) { - 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()))); - } - } - } - case FRONTIER -> { - return; - } - default -> { - throw new IllegalStateException("TransactionType not supported: " + txType); - } - } - } - - 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()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - int stamp = 0; - for (TrmOperation operation : this.trimmings) { - stamp++; - operation.trace(trace, stamp); - } - } - - @Override - public int lineCount() { - return this.trimmings.lineCount(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/TrmOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/TrmOperation.java deleted file mode 100644 index 1c6f3d954..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/TrmOperation.java +++ /dev/null @@ -1,70 +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.LLARGE; -import static net.consensys.linea.zktracer.module.trm.Trm.MAX_CT; -import static net.consensys.linea.zktracer.module.trm.Trm.PIVOT_BIT_FLIPS_TO_TRUE; -import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; -import static net.consensys.linea.zktracer.types.Utils.bitDecomposition; -import static net.consensys.linea.zktracer.types.Utils.leftPadTo; - -import java.util.List; - -import lombok.EqualsAndHashCode; -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.container.ModuleOperation; -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; - -@RequiredArgsConstructor -@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) -public class TrmOperation extends ModuleOperation { - @EqualsAndHashCode.Include private final EWord value; - - void trace(Trace trace, int stamp) { - Bytes trmHi = leftPadTo(this.value.hi().slice(PIVOT_BIT_FLIPS_TO_TRUE, 4), LLARGE); - Boolean isPrec = isPrecompile(Address.extract(this.value)); - final int accLastByte = - isPrec ? 9 - (0xff & this.value.get(31)) : (0xff & this.value.get(31)) - 10; - List ones = bitDecomposition(accLastByte, MAX_CT).bitDecList(); - - for (int ct = 0; ct < MAX_CT; ct++) { - trace - .ct(Bytes.of(ct)) - .stamp(Bytes.ofUnsignedInt(stamp)) - .isPrec(isPrec) - .pbit(ct >= PIVOT_BIT_FLIPS_TO_TRUE) - .addrHi(this.value.hi()) - .addrLo(this.value.lo()) - .trmAddrHi(trmHi) - .accHi(this.value.hi().slice(0, ct + 1)) - .accLo(this.value.lo().slice(0, ct + 1)) - .accT(trmHi.slice(0, ct + 1)) - .byteHi(UnsignedByte.of(this.value.hi().get(ct))) - .byteLo(UnsignedByte.of(this.value.lo().get(ct))) - .one(ones.get(ct)) - .validateRow(); - } - } - - @Override - protected int computeLineCount() { - return MAX_CT; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/TrmTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/TrmTrace.java deleted file mode 100644 index 5f2d11dc5..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/TrmTrace.java +++ /dev/null @@ -1,31 +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 com.fasterxml.jackson.annotation.JsonProperty; -import net.consensys.linea.zktracer.module.ModuleTrace; - -/** - * WARNING: This code is generated automatically. Any modifications to this code may be overwritten - * and could lead to unexpected behavior. Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -record TrmTrace(@JsonProperty("Trace") Trace trace) implements ModuleTrace { - - @Override - public int length() { - return this.trace.size(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/BlockSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/BlockSnapshot.java deleted file mode 100644 index 09f0e4427..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/BlockSnapshot.java +++ /dev/null @@ -1,100 +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.txn_data; - -import java.util.Optional; - -import lombok.Getter; -import net.consensys.linea.zktracer.container.stacked.list.StackedList; -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; - -/** - * This class gathers the block-related information required to trace the {@link TxnData} module. - */ -public class BlockSnapshot { - /** Sequential ID of this block within a conflation */ - @Getter int id; - /** A list of {@link TransactionSnapshot} contained in this block */ - @Getter private final StackedList txs = new StackedList<>(); - /** The base fee of this block */ - @Getter private final Optional baseFee; - /** The coinbase of this block */ - @Getter private final Address coinbaseAddress; - - BlockSnapshot(int id, ProcessableBlockHeader header) { - this.id = id; - this.baseFee = header.getBaseFee().map(x -> (Wei) x); - this.coinbaseAddress = header.getCoinbase(); - } - - /** - * 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(int codeIdBeforeLex, WorldView worldView, Transaction tx) { - final TransactionSnapshot snapshot = - TransactionSnapshot.fromTransaction(codeIdBeforeLex, tx, worldView, this.baseFee); - this.txs.add(snapshot); - } - - /** - * Finishes capturing a transaction in this block. - * - * @param cumulativeGasUsed - * @param leftoverGas - * @param refundCounter - * @param status true if the transaction was successful - */ - void endTx(long cumulativeGasUsed, long leftoverGas, long refundCounter, boolean status) { - final long effectiveGasRefund = this.getEffectiveGasRefund(leftoverGas, refundCounter); - this.currentTx().status(status); - this.currentTx().refundCounter(refundCounter); - this.currentTx().leftoverGas(leftoverGas); - this.currentTx().effectiveGasRefund(effectiveGasRefund); - this.currentTx().cumulativeGasConsumption(cumulativeGasUsed); - } - - /** - * Computes the amount of gas being effectively refunded during transaction finalization. - * - * @param leftoverGas - * @param refundCounter - * @return - */ - long getEffectiveGasRefund(long leftoverGas, long refundCounter) { - long gasLimitMinusLeftoverGasOverTwo = 0; - if (!this.txs.isEmpty()) { - gasLimitMinusLeftoverGasOverTwo = (this.currentTx().gasLimit() - leftoverGas) >> 1; - } - - return leftoverGas + Long.min(refundCounter, gasLimitMinusLeftoverGasOverTwo); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java deleted file mode 100644 index 1700e61bf..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java +++ /dev/null @@ -1,1182 +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.txn_data; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - static final int CREATE2_SHIFT = 255; - static final int G_TXDATA_NONZERO = 16; - static final int G_TXDATA_ZERO = 4; - static final int INT_LONG = 183; - static final int INT_SHORT = 128; - static final int LIST_LONG = 247; - static final int LIST_SHORT = 192; - static final int LLARGE = 16; - static final int LLARGEMO = 15; - static final int RLPADDR_CONST_RECIPE_1 = 1; - static final int RLPADDR_CONST_RECIPE_2 = 2; - static final int RLPRECEIPT_SUBPHASE_ID_ADDR = 53; - static final int RLPRECEIPT_SUBPHASE_ID_CUMUL_GAS = 3; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_LIMB = 77; - static final int RLPRECEIPT_SUBPHASE_ID_DATA_SIZE = 83; - static final int RLPRECEIPT_SUBPHASE_ID_NO_LOG_ENTRY = 11; - static final int RLPRECEIPT_SUBPHASE_ID_STATUS_CODE = 2; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_BASE = 65; - static final int RLPRECEIPT_SUBPHASE_ID_TOPIC_DELTA = 96; - static final int RLPRECEIPT_SUBPHASE_ID_TYPE = 7; - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer absTxNum; - private final MappedByteBuffer absTxNumMax; - private final MappedByteBuffer basefee; - private final MappedByteBuffer btcNum; - private final MappedByteBuffer btcNumMax; - private final MappedByteBuffer callDataSize; - private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer coinbaseHi; - private final MappedByteBuffer coinbaseLo; - private final MappedByteBuffer ct; - private final MappedByteBuffer cumulativeConsumedGas; - private final MappedByteBuffer fromHi; - private final MappedByteBuffer fromLo; - private final MappedByteBuffer gasLimit; - private final MappedByteBuffer gasPrice; - private final MappedByteBuffer initCodeSize; - private final MappedByteBuffer initialBalance; - private final MappedByteBuffer initialGas; - private final MappedByteBuffer isDep; - private final MappedByteBuffer leftoverGas; - private final MappedByteBuffer nonce; - private final MappedByteBuffer outgoingHi; - private final MappedByteBuffer outgoingLo; - private final MappedByteBuffer outgoingRlpTxnrcpt; - private final MappedByteBuffer phaseRlpTxn; - private final MappedByteBuffer phaseRlpTxnrcpt; - private final MappedByteBuffer refundAmount; - private final MappedByteBuffer refundCounter; - private final MappedByteBuffer relTxNum; - private final MappedByteBuffer relTxNumMax; - private final MappedByteBuffer requiresEvmExecution; - private final MappedByteBuffer statusCode; - private final MappedByteBuffer toHi; - private final MappedByteBuffer toLo; - private final MappedByteBuffer type0; - private final MappedByteBuffer type1; - private final MappedByteBuffer type2; - private final MappedByteBuffer value; - private final MappedByteBuffer wcpArgOneLo; - private final MappedByteBuffer wcpArgTwoLo; - private final MappedByteBuffer wcpInst; - private final MappedByteBuffer wcpRes; - - static List headers(int length) { - return List.of( - new ColumnHeader("txnData.ABS_TX_NUM", 32, length), - new ColumnHeader("txnData.ABS_TX_NUM_MAX", 32, length), - new ColumnHeader("txnData.BASEFEE", 32, length), - new ColumnHeader("txnData.BTC_NUM", 32, length), - new ColumnHeader("txnData.BTC_NUM_MAX", 32, length), - new ColumnHeader("txnData.CALL_DATA_SIZE", 32, length), - new ColumnHeader("txnData.CODE_FRAGMENT_INDEX", 32, length), - new ColumnHeader("txnData.COINBASE_HI", 32, length), - new ColumnHeader("txnData.COINBASE_LO", 32, length), - new ColumnHeader("txnData.CT", 1, length), - new ColumnHeader("txnData.CUMULATIVE_CONSUMED_GAS", 32, length), - new ColumnHeader("txnData.FROM_HI", 32, length), - new ColumnHeader("txnData.FROM_LO", 32, length), - new ColumnHeader("txnData.GAS_LIMIT", 32, length), - new ColumnHeader("txnData.GAS_PRICE", 32, length), - new ColumnHeader("txnData.INIT_CODE_SIZE", 32, length), - new ColumnHeader("txnData.INITIAL_BALANCE", 32, length), - new ColumnHeader("txnData.INITIAL_GAS", 32, length), - new ColumnHeader("txnData.IS_DEP", 1, length), - new ColumnHeader("txnData.LEFTOVER_GAS", 32, length), - new ColumnHeader("txnData.NONCE", 32, length), - new ColumnHeader("txnData.OUTGOING_HI", 32, length), - new ColumnHeader("txnData.OUTGOING_LO", 32, length), - new ColumnHeader("txnData.OUTGOING_RLP_TXNRCPT", 32, length), - new ColumnHeader("txnData.PHASE_RLP_TXN", 1, length), - new ColumnHeader("txnData.PHASE_RLP_TXNRCPT", 1, length), - new ColumnHeader("txnData.REFUND_AMOUNT", 32, length), - new ColumnHeader("txnData.REFUND_COUNTER", 32, length), - new ColumnHeader("txnData.REL_TX_NUM", 32, length), - new ColumnHeader("txnData.REL_TX_NUM_MAX", 32, length), - new ColumnHeader("txnData.REQUIRES_EVM_EXECUTION", 1, length), - new ColumnHeader("txnData.STATUS_CODE", 1, length), - new ColumnHeader("txnData.TO_HI", 32, length), - new ColumnHeader("txnData.TO_LO", 32, length), - new ColumnHeader("txnData.TYPE0", 1, length), - new ColumnHeader("txnData.TYPE1", 1, length), - new ColumnHeader("txnData.TYPE2", 1, length), - new ColumnHeader("txnData.VALUE", 32, length), - new ColumnHeader("txnData.WCP_ARG_ONE_LO", 32, length), - new ColumnHeader("txnData.WCP_ARG_TWO_LO", 32, length), - new ColumnHeader("txnData.WCP_INST", 1, length), - new ColumnHeader("txnData.WCP_RES", 1, length)); - } - - public Trace(List buffers) { - this.absTxNum = buffers.get(0); - this.absTxNumMax = buffers.get(1); - this.basefee = buffers.get(2); - this.btcNum = buffers.get(3); - this.btcNumMax = buffers.get(4); - this.callDataSize = buffers.get(5); - this.codeFragmentIndex = buffers.get(6); - this.coinbaseHi = buffers.get(7); - this.coinbaseLo = buffers.get(8); - this.ct = buffers.get(9); - this.cumulativeConsumedGas = buffers.get(10); - this.fromHi = buffers.get(11); - this.fromLo = buffers.get(12); - this.gasLimit = buffers.get(13); - this.gasPrice = buffers.get(14); - this.initCodeSize = buffers.get(15); - this.initialBalance = buffers.get(16); - this.initialGas = buffers.get(17); - this.isDep = buffers.get(18); - this.leftoverGas = buffers.get(19); - this.nonce = buffers.get(20); - this.outgoingHi = buffers.get(21); - this.outgoingLo = buffers.get(22); - this.outgoingRlpTxnrcpt = buffers.get(23); - this.phaseRlpTxn = buffers.get(24); - this.phaseRlpTxnrcpt = buffers.get(25); - this.refundAmount = buffers.get(26); - this.refundCounter = buffers.get(27); - this.relTxNum = buffers.get(28); - this.relTxNumMax = buffers.get(29); - this.requiresEvmExecution = buffers.get(30); - this.statusCode = buffers.get(31); - this.toHi = buffers.get(32); - this.toLo = buffers.get(33); - this.type0 = buffers.get(34); - this.type1 = buffers.get(35); - this.type2 = buffers.get(36); - this.value = buffers.get(37); - this.wcpArgOneLo = buffers.get(38); - this.wcpArgTwoLo = buffers.get(39); - this.wcpInst = buffers.get(40); - this.wcpRes = buffers.get(41); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace absTxNum(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("txnData.ABS_TX_NUM already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - absTxNum.put((byte) 0); - } - absTxNum.put(b.toArrayUnsafe()); - - return this; - } - - public Trace absTxNumMax(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("txnData.ABS_TX_NUM_MAX already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - absTxNumMax.put((byte) 0); - } - absTxNumMax.put(b.toArrayUnsafe()); - - return this; - } - - public Trace basefee(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("txnData.BASEFEE already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - basefee.put((byte) 0); - } - basefee.put(b.toArrayUnsafe()); - - return this; - } - - public Trace btcNum(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("txnData.BTC_NUM already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - btcNum.put((byte) 0); - } - btcNum.put(b.toArrayUnsafe()); - - return this; - } - - public Trace btcNumMax(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("txnData.BTC_NUM_MAX already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - btcNumMax.put((byte) 0); - } - btcNumMax.put(b.toArrayUnsafe()); - - return this; - } - - public Trace callDataSize(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("txnData.CALL_DATA_SIZE already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - callDataSize.put((byte) 0); - } - callDataSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace codeFragmentIndex(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("txnData.CODE_FRAGMENT_INDEX already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeFragmentIndex.put((byte) 0); - } - codeFragmentIndex.put(b.toArrayUnsafe()); - - return this; - } - - public Trace coinbaseHi(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("txnData.COINBASE_HI already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - coinbaseHi.put((byte) 0); - } - coinbaseHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace coinbaseLo(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("txnData.COINBASE_LO already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - coinbaseLo.put((byte) 0); - } - coinbaseLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace ct(final UnsignedByte b) { - if (filled.get(9)) { - throw new IllegalStateException("txnData.CT already set"); - } else { - filled.set(9); - } - - ct.put(b.toByte()); - - return this; - } - - public Trace cumulativeConsumedGas(final Bytes b) { - if (filled.get(10)) { - throw new IllegalStateException("txnData.CUMULATIVE_CONSUMED_GAS already set"); - } else { - filled.set(10); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - cumulativeConsumedGas.put((byte) 0); - } - cumulativeConsumedGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace fromHi(final Bytes b) { - if (filled.get(11)) { - throw new IllegalStateException("txnData.FROM_HI already set"); - } else { - filled.set(11); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - fromHi.put((byte) 0); - } - fromHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace fromLo(final Bytes b) { - if (filled.get(12)) { - throw new IllegalStateException("txnData.FROM_LO already set"); - } else { - filled.set(12); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - fromLo.put((byte) 0); - } - fromLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasLimit(final Bytes b) { - if (filled.get(13)) { - throw new IllegalStateException("txnData.GAS_LIMIT already set"); - } else { - filled.set(13); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasLimit.put((byte) 0); - } - gasLimit.put(b.toArrayUnsafe()); - - return this; - } - - public Trace gasPrice(final Bytes b) { - if (filled.get(14)) { - throw new IllegalStateException("txnData.GAS_PRICE already set"); - } else { - filled.set(14); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasPrice.put((byte) 0); - } - gasPrice.put(b.toArrayUnsafe()); - - return this; - } - - public Trace initCodeSize(final Bytes b) { - if (filled.get(17)) { - throw new IllegalStateException("txnData.INIT_CODE_SIZE already set"); - } else { - filled.set(17); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - initCodeSize.put((byte) 0); - } - initCodeSize.put(b.toArrayUnsafe()); - - return this; - } - - public Trace initialBalance(final Bytes b) { - if (filled.get(15)) { - throw new IllegalStateException("txnData.INITIAL_BALANCE already set"); - } else { - filled.set(15); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - initialBalance.put((byte) 0); - } - initialBalance.put(b.toArrayUnsafe()); - - return this; - } - - public Trace initialGas(final Bytes b) { - if (filled.get(16)) { - throw new IllegalStateException("txnData.INITIAL_GAS already set"); - } else { - filled.set(16); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - initialGas.put((byte) 0); - } - initialGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace isDep(final Boolean b) { - if (filled.get(18)) { - throw new IllegalStateException("txnData.IS_DEP already set"); - } else { - filled.set(18); - } - - isDep.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace leftoverGas(final Bytes b) { - if (filled.get(19)) { - throw new IllegalStateException("txnData.LEFTOVER_GAS already set"); - } else { - filled.set(19); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - leftoverGas.put((byte) 0); - } - leftoverGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace nonce(final Bytes b) { - if (filled.get(20)) { - throw new IllegalStateException("txnData.NONCE already set"); - } else { - filled.set(20); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonce.put((byte) 0); - } - nonce.put(b.toArrayUnsafe()); - - return this; - } - - public Trace outgoingHi(final Bytes b) { - if (filled.get(21)) { - throw new IllegalStateException("txnData.OUTGOING_HI already set"); - } else { - filled.set(21); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - outgoingHi.put((byte) 0); - } - outgoingHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace outgoingLo(final Bytes b) { - if (filled.get(22)) { - throw new IllegalStateException("txnData.OUTGOING_LO already set"); - } else { - filled.set(22); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - outgoingLo.put((byte) 0); - } - outgoingLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace outgoingRlpTxnrcpt(final Bytes b) { - if (filled.get(23)) { - throw new IllegalStateException("txnData.OUTGOING_RLP_TXNRCPT already set"); - } else { - filled.set(23); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - outgoingRlpTxnrcpt.put((byte) 0); - } - outgoingRlpTxnrcpt.put(b.toArrayUnsafe()); - - return this; - } - - public Trace phaseRlpTxn(final UnsignedByte b) { - if (filled.get(24)) { - throw new IllegalStateException("txnData.PHASE_RLP_TXN already set"); - } else { - filled.set(24); - } - - phaseRlpTxn.put(b.toByte()); - - return this; - } - - public Trace phaseRlpTxnrcpt(final UnsignedByte b) { - if (filled.get(25)) { - throw new IllegalStateException("txnData.PHASE_RLP_TXNRCPT already set"); - } else { - filled.set(25); - } - - phaseRlpTxnrcpt.put(b.toByte()); - - return this; - } - - public Trace refundAmount(final Bytes b) { - if (filled.get(26)) { - throw new IllegalStateException("txnData.REFUND_AMOUNT already set"); - } else { - filled.set(26); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - refundAmount.put((byte) 0); - } - refundAmount.put(b.toArrayUnsafe()); - - return this; - } - - public Trace refundCounter(final Bytes b) { - if (filled.get(27)) { - throw new IllegalStateException("txnData.REFUND_COUNTER already set"); - } else { - filled.set(27); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - refundCounter.put((byte) 0); - } - refundCounter.put(b.toArrayUnsafe()); - - return this; - } - - public Trace relTxNum(final Bytes b) { - if (filled.get(28)) { - throw new IllegalStateException("txnData.REL_TX_NUM already set"); - } else { - filled.set(28); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - relTxNum.put((byte) 0); - } - relTxNum.put(b.toArrayUnsafe()); - - return this; - } - - public Trace relTxNumMax(final Bytes b) { - if (filled.get(29)) { - throw new IllegalStateException("txnData.REL_TX_NUM_MAX already set"); - } else { - filled.set(29); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - relTxNumMax.put((byte) 0); - } - relTxNumMax.put(b.toArrayUnsafe()); - - return this; - } - - public Trace requiresEvmExecution(final Boolean b) { - if (filled.get(30)) { - throw new IllegalStateException("txnData.REQUIRES_EVM_EXECUTION already set"); - } else { - filled.set(30); - } - - requiresEvmExecution.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace statusCode(final Boolean b) { - if (filled.get(31)) { - throw new IllegalStateException("txnData.STATUS_CODE already set"); - } else { - filled.set(31); - } - - statusCode.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace toHi(final Bytes b) { - if (filled.get(32)) { - throw new IllegalStateException("txnData.TO_HI already set"); - } else { - filled.set(32); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - toHi.put((byte) 0); - } - toHi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace toLo(final Bytes b) { - if (filled.get(33)) { - throw new IllegalStateException("txnData.TO_LO already set"); - } else { - filled.set(33); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - toLo.put((byte) 0); - } - toLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace type0(final Boolean b) { - if (filled.get(34)) { - throw new IllegalStateException("txnData.TYPE0 already set"); - } else { - filled.set(34); - } - - type0.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace type1(final Boolean b) { - if (filled.get(35)) { - throw new IllegalStateException("txnData.TYPE1 already set"); - } else { - filled.set(35); - } - - type1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace type2(final Boolean b) { - if (filled.get(36)) { - throw new IllegalStateException("txnData.TYPE2 already set"); - } else { - filled.set(36); - } - - type2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace value(final Bytes b) { - if (filled.get(37)) { - throw new IllegalStateException("txnData.VALUE already set"); - } else { - filled.set(37); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - value.put((byte) 0); - } - value.put(b.toArrayUnsafe()); - - return this; - } - - public Trace wcpArgOneLo(final Bytes b) { - if (filled.get(38)) { - throw new IllegalStateException("txnData.WCP_ARG_ONE_LO already set"); - } else { - filled.set(38); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - wcpArgOneLo.put((byte) 0); - } - wcpArgOneLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace wcpArgTwoLo(final Bytes b) { - if (filled.get(39)) { - throw new IllegalStateException("txnData.WCP_ARG_TWO_LO already set"); - } else { - filled.set(39); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - wcpArgTwoLo.put((byte) 0); - } - wcpArgTwoLo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace wcpInst(final UnsignedByte b) { - if (filled.get(40)) { - throw new IllegalStateException("txnData.WCP_INST already set"); - } else { - filled.set(40); - } - - wcpInst.put(b.toByte()); - - return this; - } - - public Trace wcpRes(final Boolean b) { - if (filled.get(41)) { - throw new IllegalStateException("txnData.WCP_RES already set"); - } else { - filled.set(41); - } - - wcpRes.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("txnData.ABS_TX_NUM has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("txnData.ABS_TX_NUM_MAX has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("txnData.BASEFEE has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("txnData.BTC_NUM has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("txnData.BTC_NUM_MAX has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("txnData.CALL_DATA_SIZE has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("txnData.CODE_FRAGMENT_INDEX has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("txnData.COINBASE_HI has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("txnData.COINBASE_LO has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("txnData.CT has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("txnData.CUMULATIVE_CONSUMED_GAS has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("txnData.FROM_HI has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("txnData.FROM_LO has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("txnData.GAS_LIMIT has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("txnData.GAS_PRICE has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("txnData.INIT_CODE_SIZE has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("txnData.INITIAL_BALANCE has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("txnData.INITIAL_GAS has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("txnData.IS_DEP has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("txnData.LEFTOVER_GAS has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("txnData.NONCE has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("txnData.OUTGOING_HI has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("txnData.OUTGOING_LO has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("txnData.OUTGOING_RLP_TXNRCPT has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("txnData.PHASE_RLP_TXN has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("txnData.PHASE_RLP_TXNRCPT has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("txnData.REFUND_AMOUNT has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("txnData.REFUND_COUNTER has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("txnData.REL_TX_NUM has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("txnData.REL_TX_NUM_MAX has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("txnData.REQUIRES_EVM_EXECUTION has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("txnData.STATUS_CODE has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("txnData.TO_HI has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("txnData.TO_LO has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("txnData.TYPE0 has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("txnData.TYPE1 has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("txnData.TYPE2 has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("txnData.VALUE has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("txnData.WCP_ARG_ONE_LO has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("txnData.WCP_ARG_TWO_LO has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("txnData.WCP_INST has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("txnData.WCP_RES has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - absTxNum.position(absTxNum.position() + 32); - } - - if (!filled.get(1)) { - absTxNumMax.position(absTxNumMax.position() + 32); - } - - if (!filled.get(2)) { - basefee.position(basefee.position() + 32); - } - - if (!filled.get(3)) { - btcNum.position(btcNum.position() + 32); - } - - if (!filled.get(4)) { - btcNumMax.position(btcNumMax.position() + 32); - } - - if (!filled.get(5)) { - callDataSize.position(callDataSize.position() + 32); - } - - if (!filled.get(6)) { - codeFragmentIndex.position(codeFragmentIndex.position() + 32); - } - - if (!filled.get(7)) { - coinbaseHi.position(coinbaseHi.position() + 32); - } - - if (!filled.get(8)) { - coinbaseLo.position(coinbaseLo.position() + 32); - } - - if (!filled.get(9)) { - ct.position(ct.position() + 1); - } - - if (!filled.get(10)) { - cumulativeConsumedGas.position(cumulativeConsumedGas.position() + 32); - } - - if (!filled.get(11)) { - fromHi.position(fromHi.position() + 32); - } - - if (!filled.get(12)) { - fromLo.position(fromLo.position() + 32); - } - - if (!filled.get(13)) { - gasLimit.position(gasLimit.position() + 32); - } - - if (!filled.get(14)) { - gasPrice.position(gasPrice.position() + 32); - } - - if (!filled.get(17)) { - initCodeSize.position(initCodeSize.position() + 32); - } - - if (!filled.get(15)) { - initialBalance.position(initialBalance.position() + 32); - } - - if (!filled.get(16)) { - initialGas.position(initialGas.position() + 32); - } - - if (!filled.get(18)) { - isDep.position(isDep.position() + 1); - } - - if (!filled.get(19)) { - leftoverGas.position(leftoverGas.position() + 32); - } - - if (!filled.get(20)) { - nonce.position(nonce.position() + 32); - } - - if (!filled.get(21)) { - outgoingHi.position(outgoingHi.position() + 32); - } - - if (!filled.get(22)) { - outgoingLo.position(outgoingLo.position() + 32); - } - - if (!filled.get(23)) { - outgoingRlpTxnrcpt.position(outgoingRlpTxnrcpt.position() + 32); - } - - if (!filled.get(24)) { - phaseRlpTxn.position(phaseRlpTxn.position() + 1); - } - - if (!filled.get(25)) { - phaseRlpTxnrcpt.position(phaseRlpTxnrcpt.position() + 1); - } - - if (!filled.get(26)) { - refundAmount.position(refundAmount.position() + 32); - } - - if (!filled.get(27)) { - refundCounter.position(refundCounter.position() + 32); - } - - if (!filled.get(28)) { - relTxNum.position(relTxNum.position() + 32); - } - - if (!filled.get(29)) { - relTxNumMax.position(relTxNumMax.position() + 32); - } - - if (!filled.get(30)) { - requiresEvmExecution.position(requiresEvmExecution.position() + 1); - } - - if (!filled.get(31)) { - statusCode.position(statusCode.position() + 1); - } - - if (!filled.get(32)) { - toHi.position(toHi.position() + 32); - } - - if (!filled.get(33)) { - toLo.position(toLo.position() + 32); - } - - if (!filled.get(34)) { - type0.position(type0.position() + 1); - } - - if (!filled.get(35)) { - type1.position(type1.position() + 1); - } - - if (!filled.get(36)) { - type2.position(type2.position() + 1); - } - - if (!filled.get(37)) { - value.position(value.position() + 32); - } - - if (!filled.get(38)) { - wcpArgOneLo.position(wcpArgOneLo.position() + 32); - } - - if (!filled.get(39)) { - wcpArgTwoLo.position(wcpArgTwoLo.position() + 32); - } - - if (!filled.get(40)) { - wcpInst.position(wcpInst.position() + 1); - } - - if (!filled.get(41)) { - wcpRes.position(wcpRes.position() + 1); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java deleted file mode 100644 index 23a51d395..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java +++ /dev/null @@ -1,259 +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.txn_data; - -import java.math.BigInteger; -import java.util.List; -import java.util.Optional; - -import com.google.common.base.Preconditions; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.container.ModuleOperation; -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 static final int nROWS0 = 6; - private static final int nROWS1 = 7; - private static final int nROWS2 = 7; - - private static final int G_accesslistaddress = 2400; - private static final int G_accessliststorage = 1900; - private static final int G_transaction = 21000; - private static final int G_txcreate = 32000; - - /** 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; - /** CodeFragmentIndex, given by the {@link net.consensys.linea.zktracer.module.romLex.RomLex} */ - private final int codeIdBeforeLex; - /** 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 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; - - public TransactionSnapshot( - BigInteger value, - Address from, - Address to, - long nonce, - int prewarmedAddressesCount, - int prewarmedStorageKeysCount, - boolean isDeployment, - boolean requiresEvmExecution, - TransactionType type, - int codeFragmentIndex, - BigInteger initialSenderBalance, - Bytes payload, - long gasLimit, - BigInteger effectiveGasPrice, - Optional maxFeePerGas, - Optional maxPriorityFeePerGas) { - - 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.codeIdBeforeLex = codeFragmentIndex; - this.initialSenderBalance = initialSenderBalance; - this.payload = payload; - this.gasLimit = gasLimit; - this.effectiveGasPrice = effectiveGasPrice; - this.maxFeePerGas = maxFeePerGas; - this.maxPriorityFeePerGas = maxPriorityFeePerGas; - } - - public static TransactionSnapshot fromTransaction( - int codeIdBeforeLex, Transaction tx, WorldView world, Optional baseFee) { - - return new TransactionSnapshot( - 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(), - codeIdBeforeLex, - 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()); - } - - // dataCost returns the gas cost of the call data / init code - // 0x00 costs 4 gas, any other byte costs 16 = 4 + 12 - public long dataCost() { - Bytes payload = this.payload(); - long dataCost = 4 * (long) payload.size(); - for (int i = 0; i < payload.size(); i++) { - if (payload.get(i) != 0) { - dataCost += 12; - } - } - 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"); - }; - } - - /** - * Computes minimumNecessaryBalance := T_v + T_g * T_p where - * - *

T_v = value field of transaction - * - *

T_p = gas price for Type 0 & Type 1 transactions | max priority fee for Type 2 transactions - * - * @return - */ - BigInteger getMaximalUpfrontCost() { - BigInteger minimumNecessaryBalance = this.value(); - BigInteger gasLimit = BigInteger.valueOf(this.gasLimit()); - BigInteger maximalGasPrice = - switch (this.type()) { - case FRONTIER, ACCESS_LIST -> this.effectiveGasPrice; - case EIP1559 -> this.maxFeePerGas().get().getAsBigInteger(); - default -> throw new RuntimeException("transaction type not supported"); - }; - return minimumNecessaryBalance.add(gasLimit.multiply(maximalGasPrice)); - } - - /** - * Converts the {@link TransactionType} to an integer. - * - * @return an integer encoding the transaction type - */ - int typeAsInt() { - return switch (this.type()) { - case FRONTIER -> 0; - case ACCESS_LIST -> 1; - case EIP1559 -> 2; - default -> throw new RuntimeException("transaction type not supported"); - }; - } - - // getData should return either: - // - call data (message call) - // - init code (contract creation) - long maxCounter() { - return switch (this.type()) { - case FRONTIER -> 1 + nROWS0; - case ACCESS_LIST -> 1 + nROWS1; - case EIP1559 -> 1 + nROWS2; - default -> throw new RuntimeException("transaction type not supported"); - }; - } - - long getUpfrontGasCost() { - long initialCost = this.dataCost(); - - if (this.isDeployment()) { - initialCost += G_txcreate; - } - - initialCost += G_transaction; - - if (this.type() != TransactionType.FRONTIER) { - initialCost += (long) this.prewarmedAddressesCount() * G_accesslistaddress; - initialCost += (long) this.prewarmedStorageKeysCount() * G_accessliststorage; - } - - Preconditions.checkState( - this.gasLimit() >= initialCost, - "gasLimit ({}) < initialGasCost ({})", - this.gasLimit(), - initialCost); - - return initialCost; - } - - BigInteger getLimitMinusLeftoverGas() { - return BigInteger.valueOf(this.gasLimit() - this.leftoverGas()); - } - - BigInteger getLimitMinusLeftoverGasDividedByTwo() { - return this.getLimitMinusLeftoverGas().divide(BigInteger.TWO); - } - - @Override - protected int computeLineCount() { - throw new IllegalStateException("should never be called"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java deleted file mode 100644 index 69a831c51..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java +++ /dev/null @@ -1,538 +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.txn_data; - -import static net.consensys.linea.zktracer.module.Util.getTxTypeAsInt; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -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.romLex.RomLex; -import net.consensys.linea.zktracer.module.wcp.Wcp; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import net.consensys.linea.zktracer.types.Bytes16; -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.Transaction; -import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.evm.account.AccountState; -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.ProcessableBlockHeader; -import org.jetbrains.annotations.NotNull; - -@RequiredArgsConstructor -public class TxnData implements Module { - private static final int N_ROWS_FRONTIER_TX = 7; - private static final int N_ROWS_ACCESS_LIST_TX = 8; - private static final int N_ROWS_EIP_1559_TX = 8; - private static final int N_ROWS_TX_MAX = - Math.max(Math.max(N_ROWS_FRONTIER_TX, N_ROWS_ACCESS_LIST_TX), N_ROWS_EIP_1559_TX); - private static final int LT = 16; - static final int COMMON_RLP_TXN_PHASE_NUMBER_0 = 0; - static final int COMMON_RLP_TXN_PHASE_NUMBER_1 = 7; - static final int COMMON_RLP_TXN_PHASE_NUMBER_2 = 2; - static final int COMMON_RLP_TXN_PHASE_NUMBER_3 = 8; - static final int COMMON_RLP_TXN_PHASE_NUMBER_4 = 9; - static final int COMMON_RLP_TXN_PHASE_NUMBER_5 = 6; - static final int TYPE_0_RLP_TXN_PHASE_NUMBER_6 = 3; - static final int TYPE_1_RLP_TXN_PHASE_NUMBER_6 = 3; - static final int TYPE_1_RLP_TXN_PHASE_NUMBER_7 = 10; - static final int TYPE_2_RLP_TXN_PHASE_NUMBER_6 = 5; - static final int TYPE_2_RLP_TXN_PHASE_NUMBER_7 = 10; - - private final Hub hub; - private final RomLex romLex; - private final Wcp wcp; - - @Override - public String moduleKey() { - return "TXN_DATA"; - } - - private final List blocks = new ArrayList<>(); - - @Override - public void enterTransaction() { - this.currentBlock().getTxs().enter(); - } - - @Override - public void popTransaction() { - this.currentBlock().getTxs().pop(); - } - - private 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)); - } - - @Override - public void traceStartTx(WorldView worldView, Transaction tx) { - int codeIdBeforeLex = 0; - if ((tx.getTo().isEmpty() && tx.getInit().isPresent() && !tx.getInit().orElseThrow().isEmpty() - || tx.getTo().isPresent() - && Optional.ofNullable(worldView.get(tx.getTo().orElseThrow())) - .map(AccountState::hasCode) - .orElse(false))) { - codeIdBeforeLex = this.romLex.codeIdentifierBeforeLexOrder; - } - this.currentBlock().captureTx(codeIdBeforeLex, worldView, tx); - } - - @Override - public void traceEndTx( - WorldView worldView, - Transaction tx, - boolean isSuccessful, - Bytes output, - List logs, - long cumulativeGasUsed) { - final long refundCounter = hub.refundedGas(); - final long leftoverGas = hub.remainingGas(); - this.currentBlock().endTx(cumulativeGasUsed, leftoverGas, refundCounter, isSuccessful); - - // Call the wcp module: - if (!this.currentBlock().getTxs().isEmpty()) { - this.callWcp(); - } - } - - public void callWcp() { - final List wcpArgOneLo = setWcpArgumentOne(this.currentBlock().currentTx()); - final List wcpArgTwoLo = - setWcpArgumentTwo(this.currentBlock(), this.currentBlock().currentTx()); - for (int ct = 0; ct < 4; ct++) { - this.wcp.callLT(Bytes32.leftPad(wcpArgOneLo.get(ct)), Bytes32.leftPad(wcpArgTwoLo.get(ct))); - } - if (this.currentBlock().currentTx().type() == TransactionType.EIP1559) { - for (int ct = 4; ct < 7; ct++) { - this.wcp.callLT(Bytes32.leftPad(wcpArgOneLo.get(ct)), Bytes32.leftPad(wcpArgTwoLo.get(ct))); - } - } - } - - @Override - public int lineCount() { - int traceSize = 0; - for (BlockSnapshot block : this.blocks) { - for (TransactionSnapshot tx : block.getTxs()) { - switch (tx.type()) { - case FRONTIER -> traceSize += N_ROWS_FRONTIER_TX; - case ACCESS_LIST -> traceSize += N_ROWS_ACCESS_LIST_TX; - case EIP1559 -> traceSize += N_ROWS_EIP_1559_TX; - default -> throw new RuntimeException("Transaction type not supported:" + tx.type()); - } - } - } - return traceSize; - } - - private List> setOutgoingHisAndLos(TransactionSnapshot tx) { - final EWord toAddress = EWord.of(tx.to()); - boolean isDeployment = tx.isDeployment(); - - List commonHis = - List.of( - BigInteger.ZERO, // ct = 0 - isDeployment ? BigInteger.ZERO : toAddress.hiBigInt(), // ct = 1 - BigInteger.ZERO, // ct = 2 - isDeployment ? BigInteger.ONE : BigInteger.ZERO, // ct = 3 - BigInteger.valueOf(tx.dataCost()), // ct = 4 - BigInteger.ZERO // ct = 5 - ); - - List commonLos = - List.of( - BigInteger.valueOf(tx.typeAsInt()), // ct = 0 - isDeployment ? BigInteger.ZERO : toAddress.loBigInt(), // ct = 1 - BigInteger.valueOf(tx.nonce()), // ct = 2 - tx.value(), // ct = 3 - BigInteger.valueOf(tx.payload().size()), // ct = 4 - BigInteger.valueOf(tx.gasLimit()) // ct = 5 - ); - - List suffixHi; - List suffixLo; - - switch (tx.type()) { - case FRONTIER -> { - suffixHi = - List.of( - BigInteger.ZERO // ct = 6 - ); - suffixLo = - List.of( - tx.effectiveGasPrice() // ct = 6 - ); - } - case ACCESS_LIST -> { - suffixHi = - List.of( - BigInteger.ZERO, // ct = 6 - BigInteger.valueOf(tx.prewarmedStorageKeysCount()) // ct = 7 - ); - suffixLo = - List.of( - tx.effectiveGasPrice(), // ct = 6 - BigInteger.valueOf(tx.prewarmedAddressesCount()) // ct = 7 - ); - } - case EIP1559 -> { - suffixHi = - List.of( - tx.maxPriorityFeePerGas().orElseThrow().getAsBigInteger(), // ct = 6 - BigInteger.valueOf(tx.prewarmedStorageKeysCount()) // ct = 7 - ); - suffixLo = - List.of( - tx.maxFeePerGas().orElseThrow().getAsBigInteger(), // ct = 6 - BigInteger.valueOf(tx.prewarmedAddressesCount()) // ct = 7 - ); - } - default -> throw new RuntimeException("transaction type not supported"); - } - return List.of( - Stream.concat(commonHis.stream(), suffixHi.stream()).toList(), - Stream.concat(commonLos.stream(), suffixLo.stream()).toList()); - } - - private List setWcpInst(TransactionSnapshot tx) { - List common = - List.of( - LT, // ct = 0 - LT, // ct = 1 - LT, // ct = 2 - LT // ct = 3 - ); - List suffix = - switch (tx.type()) { - case FRONTIER, ACCESS_LIST -> List.of( - 0, // ct = 4 - 0, // ct = 5 - 0, // ct = 6 - 0 // ct = 7 - ); - case EIP1559 -> List.of( - LT, // ct = 4 - LT, // ct = 5 - LT, // ct = 6 - 0 // ct = 7 - ); - default -> throw new RuntimeException("transaction type not supported"); - }; - return Stream.concat(common.stream(), suffix.stream()).toList(); - } - - private List setWcpArgumentOne(TransactionSnapshot tx) { - List output = new ArrayList<>(N_ROWS_TX_MAX); - - output.add(0, Bytes16.leftPad(bigIntegerToBytes(tx.initialSenderBalance()))); // ct = 0 - output.add(1, Bytes16.leftPad(Bytes.ofUnsignedLong(tx.gasLimit()))); // ct = 1 - output.add(2, Bytes16.leftPad(bigIntegerToBytes(tx.getLimitMinusLeftoverGas()))); // ct = 2 - output.add(3, Bytes16.leftPad(Bytes.ofUnsignedLong(tx.refundCounter()))); // ct = 3 - - switch (tx.type()) { - case FRONTIER, ACCESS_LIST -> { - output.add(4, Bytes16.ZERO); // ct = 4 - output.add(5, Bytes16.ZERO); // ct = 5 - output.add(6, Bytes16.ZERO); // ct = 6 - output.add(7, Bytes16.ZERO); // ct = 7 - } - - case EIP1559 -> { - final Bytes16 maxFeePerGas = - Bytes16.leftPad(bigIntegerToBytes(tx.maxFeePerGas().orElseThrow().getAsBigInteger())); - output.add(4, maxFeePerGas); // ct = 4 - output.add(5, maxFeePerGas); // ct = 5 - output.add(6, maxFeePerGas); // ct = 6 - output.add(7, Bytes16.ZERO); // ct = 7 - } - default -> throw new RuntimeException("transaction type not supported"); - } - return output; - } - - private List setWcpArgumentTwo(BlockSnapshot block, TransactionSnapshot tx) { - final Bytes16 limitMinusLeftOverGasDividedByTwo = - Bytes16.leftPad(bigIntegerToBytes(tx.getLimitMinusLeftoverGasDividedByTwo())); - - List commonTwos = - List.of( - Bytes16.leftPad(bigIntegerToBytes(tx.getMaximalUpfrontCost())), // ct = 0 - Bytes16.leftPad(Bytes.ofUnsignedLong(tx.getUpfrontGasCost())), // ct = 1 - limitMinusLeftOverGasDividedByTwo, // ct = 2 - limitMinusLeftOverGasDividedByTwo // ct = 3 - ); - - List suffixTwos = - switch (tx.type()) { - case FRONTIER, ACCESS_LIST -> List.of( - Bytes16.ZERO, // ct = 4 - Bytes16.ZERO, // ct = 5 - Bytes16.ZERO, // ct = 6 - Bytes16.ZERO // ct =7 - ); - case EIP1559 -> List.of( - Bytes16.leftPad( - bigIntegerToBytes(block.getBaseFee().orElseThrow().getAsBigInteger())), // ct = 4 - Bytes16.leftPad( - bigIntegerToBytes( - tx.maxPriorityFeePerGas().orElseThrow().getAsBigInteger())), // ct = 5 - Bytes16.leftPad( - bigIntegerToBytes( - block - .getBaseFee() - .orElseThrow() - .getAsBigInteger() - .add( - tx.maxPriorityFeePerGas() - .orElseThrow() - .getAsBigInteger()))), // ct = 6 - Bytes16.ZERO // ct = 7 - ); - default -> throw new IllegalStateException("transaction type not supported:" + tx.type()); - }; - - return Stream.concat(commonTwos.stream(), suffixTwos.stream()).toList(); - } - - private List setWcpRes(BlockSnapshot block, TransactionSnapshot tx) { - return List.of( - false, // ct = 0 - false, // ct = 1 - false, // ct = 2 - tx.getLimitMinusLeftoverGasDividedByTwo().compareTo(BigInteger.valueOf(tx.refundCounter())) - >= 0, // ct = 3, - false, // ct = 4 - false, // ct = 5 - tx.type() == TransactionType.EIP1559 - && tx.maxFeePerGas() - .orElseThrow() - .getAsBigInteger() - .compareTo( - block - .getBaseFee() - .orElseThrow() - .getAsBigInteger() - .add(tx.maxPriorityFeePerGas().orElseThrow().getAsBigInteger())) - < 0, // ct = 6, - false // ct = 7 - ); - } - - private List setPhaseRlpTxnNumbers(TransactionSnapshot tx) { - List common = - List.of( - COMMON_RLP_TXN_PHASE_NUMBER_0, // ct = 0 - COMMON_RLP_TXN_PHASE_NUMBER_1, // ct = 1 - COMMON_RLP_TXN_PHASE_NUMBER_2, // ct = 2 - COMMON_RLP_TXN_PHASE_NUMBER_3, // ct = 3 - COMMON_RLP_TXN_PHASE_NUMBER_4, // ct = 4 - COMMON_RLP_TXN_PHASE_NUMBER_5 // ct = 5 - ); - - List phaseDependentSuffix = computePhaseDependentSuffix(tx); - return Stream.concat(common.stream(), phaseDependentSuffix.stream()).toList(); - } - - @NotNull - private static List computePhaseDependentSuffix(TransactionSnapshot tx) { - List phaseDependentSuffix; - - switch (tx.type()) { - case FRONTIER -> phaseDependentSuffix = - List.of( - TYPE_0_RLP_TXN_PHASE_NUMBER_6 // ct = 6 - ); - case ACCESS_LIST -> phaseDependentSuffix = - List.of( - TYPE_1_RLP_TXN_PHASE_NUMBER_6, // ct = 6 - TYPE_1_RLP_TXN_PHASE_NUMBER_7 // ct = 7 - ); - case EIP1559 -> phaseDependentSuffix = - List.of( - TYPE_2_RLP_TXN_PHASE_NUMBER_6, // ct = 6 - TYPE_2_RLP_TXN_PHASE_NUMBER_7 // ct = 7 - ); - default -> throw new IllegalStateException("transaction type not supported:" + tx.type()); - } - return phaseDependentSuffix; - } - - private List setPhaseRlpTxnRcpt() { - return List.of( - Trace.RLPRECEIPT_SUBPHASE_ID_TYPE, // ct =0 - Trace.RLPRECEIPT_SUBPHASE_ID_STATUS_CODE, // ct = 1 - Trace.RLPRECEIPT_SUBPHASE_ID_CUMUL_GAS, // ct = 2 - 0, // ct = 3 - 0, // ct = 4 - 0, // ct = 5 - 0, // ct = 6 - 0 // ct = 7 - ); - } - - private List setOutgoingRlpTxnRcpt(TransactionSnapshot tx) { - long statusTx = 0L; - if (tx.status()) { - statusTx = 1L; - } - - return List.of( - (long) getTxTypeAsInt(tx.type()), // ct = 0 - statusTx, // ct = 1 - tx.cumulativeGasConsumption(), // ct = 2 - 0L, // ct = 3 - 0L, // ct = 4 - 0L, // ct = 5 - 0L, // ct = 6 - 0L // ct = 7 - ); - } - - // getRefundCounter returns the sum of SSTORE related refunds - // + the sum of SELFDESTRUCT related refunds. - // Reference: [EYP] §6.2. Execution. Equation (71) - long getRefundCounter(final MessageFrame frame) { - long sstoreGasRefunds = frame.getGasRefund(); - long selfdestructGasRefunds = - (long) frame.getSelfDestructs().size() * GasConstants.R_SELF_DESTRUCT.cost(); - return sstoreGasRefunds + selfdestructGasRefunds; - } - - private void traceTx( - Trace trace, - BlockSnapshot block, - TransactionSnapshot tx, - int absTxNumMax, - int absTxNum, - int btcNumMax, - int btcNum, - int relTxNumMax, - int relTxNum) { - final EWord from = EWord.of(tx.from()); - final EWord to = EWord.of(tx.to()); - final EWord coinbase = EWord.of(block.getCoinbaseAddress()); - final int codeFragmentIndex = - tx.codeIdBeforeLex() == 0 ? 0 : this.romLex.getCFIById(tx.codeIdBeforeLex()); - final List outgoingHis = setOutgoingHisAndLos(tx).get(0); - final List outgoingLos = setOutgoingHisAndLos(tx).get(1); - final List wcpArgOneLo = setWcpArgumentOne(tx); - final List wcpArgTwoLo = setWcpArgumentTwo(block, tx); - final List wcpInsts = setWcpInst(tx); - final List wcpRes = setWcpRes(block, tx); - final List phaseNumbers = setPhaseRlpTxnNumbers(tx); - final List phaseRlpTxnRcpt = setPhaseRlpTxnRcpt(); - final List outgoingRlpTxnRcpt = setOutgoingRlpTxnRcpt(tx); - for (int ct = 0; ct < tx.maxCounter(); ct++) { - trace - .absTxNumMax(Bytes.ofUnsignedInt(absTxNumMax)) - .absTxNum(Bytes.ofUnsignedInt(absTxNum)) - .btcNumMax(Bytes.ofUnsignedInt(btcNumMax)) - .btcNum(Bytes.ofUnsignedInt(btcNum)) - .relTxNumMax(Bytes.ofUnsignedInt(relTxNumMax)) - .relTxNum(Bytes.ofUnsignedInt(relTxNum)) - .ct(UnsignedByte.of(ct)) - .fromHi(from.hi()) - .fromLo(from.lo()) - .nonce(Bytes.ofUnsignedLong(tx.nonce())) - .initialBalance(bigIntegerToBytes(tx.initialSenderBalance())) - .value(bigIntegerToBytes(tx.value())) - .toHi(to.hi()) - .toLo(to.lo()) - .isDep(tx.isDeployment()) - .gasLimit(Bytes.ofUnsignedLong(tx.gasLimit())) - .initialGas(Bytes.ofUnsignedLong(tx.gasLimit() - tx.getUpfrontGasCost())) - .gasPrice(bigIntegerToBytes(tx.effectiveGasPrice())) - .basefee(block.getBaseFee().orElseThrow()) - .coinbaseHi(coinbase.hi()) - .coinbaseLo(coinbase.lo()) - .callDataSize(tx.isDeployment() ? Bytes.EMPTY : Bytes.ofUnsignedInt(tx.payload().size())) - .initCodeSize(tx.isDeployment() ? Bytes.ofUnsignedInt(tx.payload().size()) : Bytes.EMPTY) - .type0(tx.type() == TransactionType.FRONTIER) - .type1(tx.type() == TransactionType.ACCESS_LIST) - .type2(tx.type() == TransactionType.EIP1559) - .requiresEvmExecution(tx.requiresEvmExecution()) - .leftoverGas(Bytes.ofUnsignedLong(tx.leftoverGas())) - .refundCounter(Bytes.ofUnsignedLong(tx.refundCounter())) - .refundAmount(Bytes.ofUnsignedLong(tx.effectiveGasRefund())) - .cumulativeConsumedGas(Bytes.ofUnsignedLong(tx.cumulativeGasConsumption())) - .statusCode(tx.status()) - .codeFragmentIndex(Bytes.ofUnsignedInt(codeFragmentIndex)) - .phaseRlpTxn(UnsignedByte.of(phaseNumbers.get(ct))) - .outgoingHi(bigIntegerToBytes(outgoingHis.get(ct))) - .outgoingLo(bigIntegerToBytes(outgoingLos.get(ct))) - .wcpArgOneLo(wcpArgOneLo.get(ct)) - .wcpArgTwoLo(wcpArgTwoLo.get(ct)) - .wcpRes(wcpRes.get(ct)) - .wcpInst(UnsignedByte.of(wcpInsts.get(ct))) - .phaseRlpTxnrcpt(UnsignedByte.of(phaseRlpTxnRcpt.get(ct))) - .outgoingRlpTxnrcpt(Bytes.ofUnsignedLong(outgoingRlpTxnRcpt.get(ct))) - .validateRow(); - } - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - int absTxNumMax = 0; - int absTxNum = 0; - int batchNumMax = 0; - int btchNum = 0; - for (BlockSnapshot block : this.blocks) { - absTxNumMax += block.getTxs().size(); - if (!block.getTxs().isEmpty()) { - batchNumMax += 1; - } - } - for (BlockSnapshot block : this.blocks) { - int relTxNumMax = block.getTxs().size(); - if (relTxNumMax != 0) { - btchNum++; - int relTxNum = 0; - for (TransactionSnapshot tx : block.getTxs()) { - absTxNum++; - relTxNum++; - this.traceTx( - trace, block, tx, absTxNumMax, absTxNum, batchNumMax, btchNum, relTxNumMax, relTxNum); - } - } - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/Trace.java deleted file mode 100644 index 9f42ac2ea..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/Trace.java +++ /dev/null @@ -1,990 +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.wcp; - -import java.nio.MappedByteBuffer; -import java.util.BitSet; -import java.util.List; - -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -/** - * WARNING: This code is generated automatically. - * - *

Any modifications to this code may be overwritten and could lead to unexpected behavior. - * Please DO NOT ATTEMPT TO MODIFY this code directly. - */ -public class Trace { - - private final BitSet filled = new BitSet(); - private int currentLine = 0; - - private final MappedByteBuffer acc1; - private final MappedByteBuffer acc2; - private final MappedByteBuffer acc3; - private final MappedByteBuffer acc4; - private final MappedByteBuffer acc5; - private final MappedByteBuffer acc6; - private final MappedByteBuffer argument1Hi; - private final MappedByteBuffer argument1Lo; - private final MappedByteBuffer argument2Hi; - private final MappedByteBuffer argument2Lo; - private final MappedByteBuffer bit1; - private final MappedByteBuffer bit2; - private final MappedByteBuffer bit3; - private final MappedByteBuffer bit4; - private final MappedByteBuffer bits; - private final MappedByteBuffer byte1; - private final MappedByteBuffer byte2; - private final MappedByteBuffer byte3; - private final MappedByteBuffer byte4; - private final MappedByteBuffer byte5; - private final MappedByteBuffer byte6; - private final MappedByteBuffer counter; - private final MappedByteBuffer ctMax; - private final MappedByteBuffer inst; - private final MappedByteBuffer isEq; - private final MappedByteBuffer isGeq; - private final MappedByteBuffer isGt; - private final MappedByteBuffer isIszero; - private final MappedByteBuffer isLeq; - private final MappedByteBuffer isLt; - private final MappedByteBuffer isSgt; - private final MappedByteBuffer isSlt; - private final MappedByteBuffer neg1; - private final MappedByteBuffer neg2; - private final MappedByteBuffer oneLineInstruction; - private final MappedByteBuffer result; - private final MappedByteBuffer variableLengthInstruction; - private final MappedByteBuffer wordComparisonStamp; - - static List headers(int length) { - return List.of( - new ColumnHeader("wcp.ACC_1", 32, length), - new ColumnHeader("wcp.ACC_2", 32, length), - new ColumnHeader("wcp.ACC_3", 32, length), - new ColumnHeader("wcp.ACC_4", 32, length), - new ColumnHeader("wcp.ACC_5", 32, length), - new ColumnHeader("wcp.ACC_6", 32, length), - new ColumnHeader("wcp.ARGUMENT_1_HI", 32, length), - new ColumnHeader("wcp.ARGUMENT_1_LO", 32, length), - new ColumnHeader("wcp.ARGUMENT_2_HI", 32, length), - new ColumnHeader("wcp.ARGUMENT_2_LO", 32, length), - new ColumnHeader("wcp.BIT_1", 1, length), - new ColumnHeader("wcp.BIT_2", 1, length), - new ColumnHeader("wcp.BIT_3", 1, length), - new ColumnHeader("wcp.BIT_4", 1, length), - new ColumnHeader("wcp.BITS", 1, length), - new ColumnHeader("wcp.BYTE_1", 1, length), - new ColumnHeader("wcp.BYTE_2", 1, length), - new ColumnHeader("wcp.BYTE_3", 1, length), - new ColumnHeader("wcp.BYTE_4", 1, length), - new ColumnHeader("wcp.BYTE_5", 1, length), - new ColumnHeader("wcp.BYTE_6", 1, length), - new ColumnHeader("wcp.COUNTER", 1, length), - new ColumnHeader("wcp.CT_MAX", 1, length), - new ColumnHeader("wcp.INST", 1, length), - new ColumnHeader("wcp.IS_EQ", 1, length), - new ColumnHeader("wcp.IS_GEQ", 1, length), - new ColumnHeader("wcp.IS_GT", 1, length), - new ColumnHeader("wcp.IS_ISZERO", 1, length), - new ColumnHeader("wcp.IS_LEQ", 1, length), - new ColumnHeader("wcp.IS_LT", 1, length), - new ColumnHeader("wcp.IS_SGT", 1, length), - new ColumnHeader("wcp.IS_SLT", 1, length), - new ColumnHeader("wcp.NEG_1", 1, length), - new ColumnHeader("wcp.NEG_2", 1, length), - new ColumnHeader("wcp.ONE_LINE_INSTRUCTION", 1, length), - new ColumnHeader("wcp.RESULT", 1, length), - new ColumnHeader("wcp.VARIABLE_LENGTH_INSTRUCTION", 1, length), - new ColumnHeader("wcp.WORD_COMPARISON_STAMP", 32, length)); - } - - public Trace(List buffers) { - this.acc1 = buffers.get(0); - this.acc2 = buffers.get(1); - this.acc3 = buffers.get(2); - this.acc4 = buffers.get(3); - this.acc5 = buffers.get(4); - this.acc6 = buffers.get(5); - this.argument1Hi = buffers.get(6); - this.argument1Lo = buffers.get(7); - this.argument2Hi = buffers.get(8); - this.argument2Lo = buffers.get(9); - this.bit1 = buffers.get(10); - this.bit2 = buffers.get(11); - this.bit3 = buffers.get(12); - this.bit4 = buffers.get(13); - this.bits = buffers.get(14); - this.byte1 = buffers.get(15); - this.byte2 = buffers.get(16); - this.byte3 = buffers.get(17); - this.byte4 = buffers.get(18); - this.byte5 = buffers.get(19); - this.byte6 = buffers.get(20); - this.counter = buffers.get(21); - this.ctMax = buffers.get(22); - this.inst = buffers.get(23); - this.isEq = buffers.get(24); - this.isGeq = buffers.get(25); - this.isGt = buffers.get(26); - this.isIszero = buffers.get(27); - this.isLeq = buffers.get(28); - this.isLt = buffers.get(29); - this.isSgt = buffers.get(30); - this.isSlt = buffers.get(31); - this.neg1 = buffers.get(32); - this.neg2 = buffers.get(33); - this.oneLineInstruction = buffers.get(34); - this.result = buffers.get(35); - this.variableLengthInstruction = buffers.get(36); - this.wordComparisonStamp = buffers.get(37); - } - - public int size() { - if (!filled.isEmpty()) { - throw new RuntimeException("Cannot measure a trace with a non-validated row."); - } - - return this.currentLine; - } - - public Trace acc1(final Bytes b) { - if (filled.get(0)) { - throw new IllegalStateException("wcp.ACC_1 already set"); - } else { - filled.set(0); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc1.put((byte) 0); - } - acc1.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc2(final Bytes b) { - if (filled.get(1)) { - throw new IllegalStateException("wcp.ACC_2 already set"); - } else { - filled.set(1); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc2.put((byte) 0); - } - acc2.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc3(final Bytes b) { - if (filled.get(2)) { - throw new IllegalStateException("wcp.ACC_3 already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc3.put((byte) 0); - } - acc3.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc4(final Bytes b) { - if (filled.get(3)) { - throw new IllegalStateException("wcp.ACC_4 already set"); - } else { - filled.set(3); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc4.put((byte) 0); - } - acc4.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc5(final Bytes b) { - if (filled.get(4)) { - throw new IllegalStateException("wcp.ACC_5 already set"); - } else { - filled.set(4); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc5.put((byte) 0); - } - acc5.put(b.toArrayUnsafe()); - - return this; - } - - public Trace acc6(final Bytes b) { - if (filled.get(5)) { - throw new IllegalStateException("wcp.ACC_6 already set"); - } else { - filled.set(5); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - acc6.put((byte) 0); - } - acc6.put(b.toArrayUnsafe()); - - return this; - } - - public Trace argument1Hi(final Bytes b) { - if (filled.get(6)) { - throw new IllegalStateException("wcp.ARGUMENT_1_HI already set"); - } else { - filled.set(6); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - argument1Hi.put((byte) 0); - } - argument1Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace argument1Lo(final Bytes b) { - if (filled.get(7)) { - throw new IllegalStateException("wcp.ARGUMENT_1_LO already set"); - } else { - filled.set(7); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - argument1Lo.put((byte) 0); - } - argument1Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace argument2Hi(final Bytes b) { - if (filled.get(8)) { - throw new IllegalStateException("wcp.ARGUMENT_2_HI already set"); - } else { - filled.set(8); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - argument2Hi.put((byte) 0); - } - argument2Hi.put(b.toArrayUnsafe()); - - return this; - } - - public Trace argument2Lo(final Bytes b) { - if (filled.get(9)) { - throw new IllegalStateException("wcp.ARGUMENT_2_LO already set"); - } else { - filled.set(9); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - argument2Lo.put((byte) 0); - } - argument2Lo.put(b.toArrayUnsafe()); - - return this; - } - - public Trace bit1(final Boolean b) { - if (filled.get(11)) { - throw new IllegalStateException("wcp.BIT_1 already set"); - } else { - filled.set(11); - } - - bit1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit2(final Boolean b) { - if (filled.get(12)) { - throw new IllegalStateException("wcp.BIT_2 already set"); - } else { - filled.set(12); - } - - bit2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit3(final Boolean b) { - if (filled.get(13)) { - throw new IllegalStateException("wcp.BIT_3 already set"); - } else { - filled.set(13); - } - - bit3.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bit4(final Boolean b) { - if (filled.get(14)) { - throw new IllegalStateException("wcp.BIT_4 already set"); - } else { - filled.set(14); - } - - bit4.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace bits(final Boolean b) { - if (filled.get(10)) { - throw new IllegalStateException("wcp.BITS already set"); - } else { - filled.set(10); - } - - bits.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace byte1(final UnsignedByte b) { - if (filled.get(15)) { - throw new IllegalStateException("wcp.BYTE_1 already set"); - } else { - filled.set(15); - } - - byte1.put(b.toByte()); - - return this; - } - - public Trace byte2(final UnsignedByte b) { - if (filled.get(16)) { - throw new IllegalStateException("wcp.BYTE_2 already set"); - } else { - filled.set(16); - } - - byte2.put(b.toByte()); - - return this; - } - - public Trace byte3(final UnsignedByte b) { - if (filled.get(17)) { - throw new IllegalStateException("wcp.BYTE_3 already set"); - } else { - filled.set(17); - } - - byte3.put(b.toByte()); - - return this; - } - - public Trace byte4(final UnsignedByte b) { - if (filled.get(18)) { - throw new IllegalStateException("wcp.BYTE_4 already set"); - } else { - filled.set(18); - } - - byte4.put(b.toByte()); - - return this; - } - - public Trace byte5(final UnsignedByte b) { - if (filled.get(19)) { - throw new IllegalStateException("wcp.BYTE_5 already set"); - } else { - filled.set(19); - } - - byte5.put(b.toByte()); - - return this; - } - - public Trace byte6(final UnsignedByte b) { - if (filled.get(20)) { - throw new IllegalStateException("wcp.BYTE_6 already set"); - } else { - filled.set(20); - } - - byte6.put(b.toByte()); - - return this; - } - - public Trace counter(final UnsignedByte b) { - if (filled.get(21)) { - throw new IllegalStateException("wcp.COUNTER already set"); - } else { - filled.set(21); - } - - counter.put(b.toByte()); - - return this; - } - - public Trace ctMax(final UnsignedByte b) { - if (filled.get(22)) { - throw new IllegalStateException("wcp.CT_MAX already set"); - } else { - filled.set(22); - } - - ctMax.put(b.toByte()); - - return this; - } - - public Trace inst(final UnsignedByte b) { - if (filled.get(23)) { - throw new IllegalStateException("wcp.INST already set"); - } else { - filled.set(23); - } - - inst.put(b.toByte()); - - return this; - } - - public Trace isEq(final Boolean b) { - if (filled.get(24)) { - throw new IllegalStateException("wcp.IS_EQ already set"); - } else { - filled.set(24); - } - - isEq.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isGeq(final Boolean b) { - if (filled.get(25)) { - throw new IllegalStateException("wcp.IS_GEQ already set"); - } else { - filled.set(25); - } - - isGeq.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isGt(final Boolean b) { - if (filled.get(26)) { - throw new IllegalStateException("wcp.IS_GT already set"); - } else { - filled.set(26); - } - - isGt.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isIszero(final Boolean b) { - if (filled.get(27)) { - throw new IllegalStateException("wcp.IS_ISZERO already set"); - } else { - filled.set(27); - } - - isIszero.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isLeq(final Boolean b) { - if (filled.get(28)) { - throw new IllegalStateException("wcp.IS_LEQ already set"); - } else { - filled.set(28); - } - - isLeq.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isLt(final Boolean b) { - if (filled.get(29)) { - throw new IllegalStateException("wcp.IS_LT already set"); - } else { - filled.set(29); - } - - isLt.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isSgt(final Boolean b) { - if (filled.get(30)) { - throw new IllegalStateException("wcp.IS_SGT already set"); - } else { - filled.set(30); - } - - isSgt.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace isSlt(final Boolean b) { - if (filled.get(31)) { - throw new IllegalStateException("wcp.IS_SLT already set"); - } else { - filled.set(31); - } - - isSlt.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace neg1(final Boolean b) { - if (filled.get(32)) { - throw new IllegalStateException("wcp.NEG_1 already set"); - } else { - filled.set(32); - } - - neg1.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace neg2(final Boolean b) { - if (filled.get(33)) { - throw new IllegalStateException("wcp.NEG_2 already set"); - } else { - filled.set(33); - } - - neg2.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace oneLineInstruction(final Boolean b) { - if (filled.get(34)) { - throw new IllegalStateException("wcp.ONE_LINE_INSTRUCTION already set"); - } else { - filled.set(34); - } - - oneLineInstruction.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace result(final Boolean b) { - if (filled.get(35)) { - throw new IllegalStateException("wcp.RESULT already set"); - } else { - filled.set(35); - } - - result.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace variableLengthInstruction(final Boolean b) { - if (filled.get(36)) { - throw new IllegalStateException("wcp.VARIABLE_LENGTH_INSTRUCTION already set"); - } else { - filled.set(36); - } - - variableLengthInstruction.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace wordComparisonStamp(final Bytes b) { - if (filled.get(37)) { - throw new IllegalStateException("wcp.WORD_COMPARISON_STAMP already set"); - } else { - filled.set(37); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - wordComparisonStamp.put((byte) 0); - } - wordComparisonStamp.put(b.toArrayUnsafe()); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException("wcp.ACC_1 has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("wcp.ACC_2 has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("wcp.ACC_3 has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("wcp.ACC_4 has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("wcp.ACC_5 has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("wcp.ACC_6 has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("wcp.ARGUMENT_1_HI has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("wcp.ARGUMENT_1_LO has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("wcp.ARGUMENT_2_HI has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("wcp.ARGUMENT_2_LO has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("wcp.BIT_1 has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("wcp.BIT_2 has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("wcp.BIT_3 has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("wcp.BIT_4 has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("wcp.BITS has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("wcp.BYTE_1 has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("wcp.BYTE_2 has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("wcp.BYTE_3 has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("wcp.BYTE_4 has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("wcp.BYTE_5 has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("wcp.BYTE_6 has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("wcp.COUNTER has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("wcp.CT_MAX has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("wcp.INST has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("wcp.IS_EQ has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("wcp.IS_GEQ has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("wcp.IS_GT has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("wcp.IS_ISZERO has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("wcp.IS_LEQ has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("wcp.IS_LT has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("wcp.IS_SGT has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("wcp.IS_SLT has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("wcp.NEG_1 has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("wcp.NEG_2 has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("wcp.ONE_LINE_INSTRUCTION has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("wcp.RESULT has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("wcp.VARIABLE_LENGTH_INSTRUCTION has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("wcp.WORD_COMPARISON_STAMP has not been filled"); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public Trace fillAndValidateRow() { - if (!filled.get(0)) { - acc1.position(acc1.position() + 32); - } - - if (!filled.get(1)) { - acc2.position(acc2.position() + 32); - } - - if (!filled.get(2)) { - acc3.position(acc3.position() + 32); - } - - if (!filled.get(3)) { - acc4.position(acc4.position() + 32); - } - - if (!filled.get(4)) { - acc5.position(acc5.position() + 32); - } - - if (!filled.get(5)) { - acc6.position(acc6.position() + 32); - } - - if (!filled.get(6)) { - argument1Hi.position(argument1Hi.position() + 32); - } - - if (!filled.get(7)) { - argument1Lo.position(argument1Lo.position() + 32); - } - - if (!filled.get(8)) { - argument2Hi.position(argument2Hi.position() + 32); - } - - if (!filled.get(9)) { - argument2Lo.position(argument2Lo.position() + 32); - } - - if (!filled.get(11)) { - bit1.position(bit1.position() + 1); - } - - if (!filled.get(12)) { - bit2.position(bit2.position() + 1); - } - - if (!filled.get(13)) { - bit3.position(bit3.position() + 1); - } - - if (!filled.get(14)) { - bit4.position(bit4.position() + 1); - } - - if (!filled.get(10)) { - bits.position(bits.position() + 1); - } - - if (!filled.get(15)) { - byte1.position(byte1.position() + 1); - } - - if (!filled.get(16)) { - byte2.position(byte2.position() + 1); - } - - if (!filled.get(17)) { - byte3.position(byte3.position() + 1); - } - - if (!filled.get(18)) { - byte4.position(byte4.position() + 1); - } - - if (!filled.get(19)) { - byte5.position(byte5.position() + 1); - } - - if (!filled.get(20)) { - byte6.position(byte6.position() + 1); - } - - if (!filled.get(21)) { - counter.position(counter.position() + 1); - } - - if (!filled.get(22)) { - ctMax.position(ctMax.position() + 1); - } - - if (!filled.get(23)) { - inst.position(inst.position() + 1); - } - - if (!filled.get(24)) { - isEq.position(isEq.position() + 1); - } - - if (!filled.get(25)) { - isGeq.position(isGeq.position() + 1); - } - - if (!filled.get(26)) { - isGt.position(isGt.position() + 1); - } - - if (!filled.get(27)) { - isIszero.position(isIszero.position() + 1); - } - - if (!filled.get(28)) { - isLeq.position(isLeq.position() + 1); - } - - if (!filled.get(29)) { - isLt.position(isLt.position() + 1); - } - - if (!filled.get(30)) { - isSgt.position(isSgt.position() + 1); - } - - if (!filled.get(31)) { - isSlt.position(isSlt.position() + 1); - } - - if (!filled.get(32)) { - neg1.position(neg1.position() + 1); - } - - if (!filled.get(33)) { - neg2.position(neg2.position() + 1); - } - - if (!filled.get(34)) { - oneLineInstruction.position(oneLineInstruction.position() + 1); - } - - if (!filled.get(35)) { - result.position(result.position() + 1); - } - - if (!filled.get(36)) { - variableLengthInstruction.position(variableLengthInstruction.position() + 1); - } - - if (!filled.get(37)) { - wordComparisonStamp.position(wordComparisonStamp.position() + 32); - } - - filled.clear(); - this.currentLine++; - - return this; - } - - public void build() { - if (!filled.isEmpty()) { - throw new IllegalStateException("Cannot build trace with a non-validated row."); - } - } -} 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 deleted file mode 100644 index 66c1a2709..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/Wcp.java +++ /dev/null @@ -1,118 +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.wcp; - -import static net.consensys.linea.zktracer.module.wcp.WcpOperation.GEQbv; -import static net.consensys.linea.zktracer.module.wcp.WcpOperation.LEQbv; - -import java.nio.MappedByteBuffer; -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.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; -import org.hyperledger.besu.evm.frame.MessageFrame; - -@RequiredArgsConstructor -public class Wcp implements Module { - private final StackedSet operations = new StackedSet<>(); - - private final Hub hub; - - @Override - public String moduleKey() { - return "WCP"; - } - - @Override - public void enterTransaction() { - this.operations.enter(); - } - - @Override - public void popTransaction() { - this.operations.pop(); - } - - @Override - public void tracePreOpcode(final MessageFrame frame) { - final OpCode opcode = this.hub.opCode(); - final Bytes32 arg1 = Bytes32.leftPad(frame.getStackItem(0)); - final Bytes32 arg2 = - (opcode != OpCode.ISZERO) ? Bytes32.leftPad(frame.getStackItem(1)) : Bytes32.ZERO; - - this.operations.add(new WcpOperation(opcode.byteValue(), arg1, arg2)); - } - - @Override - public List columnsHeaders() { - return Trace.headers(this.lineCount()); - } - - @Override - public void commit(List buffers) { - final Trace trace = new Trace(buffers); - - int stamp = 0; - for (WcpOperation operation : this.operations) { - stamp++; - operation.trace(trace, stamp); - } - } - - @Override - public int lineCount() { - return this.operations.lineCount(); - } - - public boolean callLT(Bytes32 arg1, Bytes32 arg2) { - this.operations.add(new WcpOperation(OpCode.LT.byteValue(), arg1, arg2)); - return arg1.compareTo(arg2) < 0; - } - - public boolean callLT(Bytes arg1, Bytes arg2) { - return this.callLT(Bytes32.leftPad(arg1), Bytes32.leftPad(arg2)); - } - - public boolean callEQ(Bytes32 arg1, Bytes32 arg2) { - this.operations.add(new WcpOperation(OpCode.EQ.byteValue(), arg1, arg2)); - return arg1.compareTo(arg2) == 0; - } - - public boolean callEQ(Bytes arg1, Bytes arg2) { - return this.callEQ(Bytes32.leftPad(arg1), Bytes32.leftPad(arg2)); - } - - public boolean callISZERO(Bytes32 arg1) { - this.operations.add(new WcpOperation(OpCode.ISZERO.byteValue(), arg1, Bytes32.ZERO)); - return arg1.isZero(); - } - - public boolean callLEQ(Bytes32 arg1, Bytes32 arg2) { - this.operations.add(new WcpOperation(LEQbv, arg1, arg2)); - return arg1.compareTo(arg2) <= 0; - } - - public boolean callGEQ(Bytes32 arg1, Bytes32 arg2) { - this.operations.add(new WcpOperation(GEQbv, arg1, arg2)); - return arg1.compareTo(arg2) >= 0; - } -} 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 deleted file mode 100644 index 44797cf77..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/WcpOperation.java +++ /dev/null @@ -1,242 +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.wcp; - -import static net.consensys.linea.zktracer.module.Util.byteBits; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.reallyToSignedBigInteger; - -import java.math.BigInteger; -import java.security.InvalidParameterException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import lombok.EqualsAndHashCode; -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.types.Bytes16; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; - -@Slf4j -@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) -public class WcpOperation extends ModuleOperation { - private static final int LLARGEMO = 15; - private static final int LLARGE = 16; - public static final byte LEQbv = 0x0E; - public static final byte GEQbv = 0x0F; - private static final byte LTbv = 0x10; - private static final byte GTbv = 0x11; - private static final byte SLTbv = 0x12; - private static final byte SGTbv = 0x13; - private static final byte EQbv = 0x14; - - private static final byte ISZERObv = 0x15; - - @EqualsAndHashCode.Include private final byte wcpInst; - @EqualsAndHashCode.Include private final Bytes32 arg1; - @EqualsAndHashCode.Include private final Bytes32 arg2; - final int ctMax; - - private Bytes arg1Hi; - private Bytes arg1Lo; - private Bytes arg2Hi; - private Bytes arg2Lo; - - private Bytes adjHi; - private Bytes adjLo; - private Boolean neg1; - - private Boolean neg2; - private boolean bit1; - private Boolean bit2; - private Boolean bit3; - private Boolean bit4; - private Boolean resLo; - - final List bits = new ArrayList<>(16); - - public WcpOperation(byte wcpInst, Bytes32 arg1, Bytes32 arg2) { - this.wcpInst = wcpInst; - this.arg1 = arg1; - this.arg2 = arg2; - - this.ctMax = maxCt(); - } - - private void compute() { - final int length = this.isOli() ? LLARGE : this.ctMax + 1; - final int offset = LLARGE - length; - this.arg1Hi = arg1.slice(offset, length); - this.arg1Lo = arg1.slice(LLARGE + offset, length); - this.arg2Hi = arg2.slice(offset, length); - this.arg2Lo = arg2.slice(LLARGE + offset, length); - - // Calculate Result Low - resLo = calculateResLow(wcpInst, arg1, arg2); - - // Set bit 3 and AdjHi - final BigInteger firstHi = this.arg1.slice(0, LLARGE).toUnsignedBigInteger(); - final BigInteger secondHi = this.arg2.slice(0, LLARGE).toUnsignedBigInteger(); - this.bit3 = firstHi.compareTo(secondHi) > 0; - this.adjHi = calculateAdj(bit3, firstHi, secondHi).slice(offset, length); - - // Set bit 4 and AdjLo - final BigInteger firstLo = this.arg1.slice(LLARGE, LLARGE).toUnsignedBigInteger(); - final BigInteger secondLo = this.arg2.slice(LLARGE, LLARGE).toUnsignedBigInteger(); - this.bit4 = firstLo.compareTo(secondLo) > 0; - this.adjLo = calculateAdj(bit4, firstLo, secondLo).slice(offset, length); - - // Initiate negatives and BITS - if (this.ctMax == LLARGEMO && (this.wcpInst == SLTbv || this.wcpInst == SGTbv)) { - // meaningful only for signed OpCode with LLARGE argument - UnsignedByte msb1 = UnsignedByte.of(this.arg1Hi.get(0)); - UnsignedByte msb2 = UnsignedByte.of(this.arg2Hi.get(0)); - Boolean[] msb1Bits = byteBits(msb1); - Boolean[] msb2Bits = byteBits(msb2); - this.neg1 = msb1Bits[0]; - this.neg2 = msb2Bits[0]; - Collections.addAll(bits, msb1Bits); - Collections.addAll(bits, msb2Bits); - } else { - this.neg1 = false; - this.neg2 = false; - for (int ct = 0; ct <= this.ctMax; ct++) { - bits.add(ct, false); - } - } - - // Set bit 1 and 2 - this.bit1 = this.arg1Hi.compareTo(this.arg2Hi) == 0; - this.bit2 = this.arg1Lo.compareTo(this.arg2Lo) == 0; - } - - private boolean calculateResLow(byte opCode, Bytes32 arg1, Bytes32 arg2) { - return switch (opCode) { - case EQbv -> arg1.compareTo(arg2) == 0; - case ISZERObv -> arg1.isZero(); - case SLTbv -> reallyToSignedBigInteger(arg1).compareTo(reallyToSignedBigInteger(arg2)) < 0; - case SGTbv -> reallyToSignedBigInteger(arg1).compareTo(reallyToSignedBigInteger(arg2)) > 0; - case LTbv -> arg1.compareTo(arg2) < 0; - case GTbv -> arg1.compareTo(arg2) > 0; - case LEQbv -> arg1.compareTo(arg2) <= 0; - case GEQbv -> arg1.compareTo(arg2) >= 0; - default -> throw new InvalidParameterException("Invalid opcode"); - }; - } - - private Bytes16 calculateAdj(boolean cmp, BigInteger arg1, BigInteger arg2) { - return cmp - ? Bytes16.leftPad(bigIntegerToBytes(arg1.subtract(arg2).subtract(BigInteger.ONE))) - : Bytes16.leftPad(bigIntegerToBytes(arg2.subtract(arg1))); - } - - void trace(Trace trace, int stamp) { - this.compute(); - - final boolean resLo = this.resLo; - final boolean oli = isOli(); - final boolean vli = isVli(); - final UnsignedByte inst = UnsignedByte.of(this.wcpInst); - - for (int ct = 0; ct <= this.maxCt(); ct++) { - trace - .wordComparisonStamp(Bytes.ofUnsignedInt(stamp)) - .oneLineInstruction(oli) - .variableLengthInstruction(vli) - .counter(UnsignedByte.of(ct)) - .ctMax(UnsignedByte.of(this.ctMax)) - .inst(inst) - .isEq(this.wcpInst == EQbv) - .isIszero(this.wcpInst == ISZERObv) - .isSlt(this.wcpInst == SLTbv) - .isSgt(this.wcpInst == SGTbv) - .isLt(this.wcpInst == LTbv) - .isGt(this.wcpInst == GTbv) - .isLeq(this.wcpInst == LEQbv) - .isGeq(this.wcpInst == GEQbv) - .argument1Hi(this.arg1Hi) - .argument1Lo(this.arg1Lo) - .argument2Hi(this.arg2Hi) - .argument2Lo(this.arg2Lo) - .result(resLo) - .bits(bits.get(ct)) - .neg1(neg1) - .neg2(neg2) - .byte1(UnsignedByte.of(this.arg1Hi.get(ct))) - .byte2(UnsignedByte.of(this.arg1Lo.get(ct))) - .byte3(UnsignedByte.of(this.arg2Hi.get(ct))) - .byte4(UnsignedByte.of(this.arg2Lo.get(ct))) - .byte5(UnsignedByte.of(adjHi.get(ct))) - .byte6(UnsignedByte.of(adjLo.get(ct))) - .acc1(this.arg1Hi.slice(0, 1 + ct)) - .acc2(this.arg1Lo.slice(0, 1 + ct)) - .acc3(this.arg2Hi.slice(0, 1 + ct)) - .acc4(this.arg2Lo.slice(0, 1 + ct)) - .acc5(adjHi.slice(0, 1 + ct)) - .acc6(adjLo.slice(0, 1 + ct)) - .bit1(bit1) - .bit2(bit2) - .bit3(bit3) - .bit4(bit4) - .validateRow(); - } - } - - private boolean isOli() { - return switch (this.wcpInst) { - case ISZERObv, EQbv -> true; - case SLTbv, SGTbv, LTbv, GTbv, LEQbv, GEQbv -> false; - default -> throw new IllegalStateException("Unexpected value: " + this.wcpInst); - }; - } - - private boolean isVli() { - return switch (this.wcpInst) { - case LTbv, GTbv, LEQbv, GEQbv, SLTbv, SGTbv -> true; - case ISZERObv, EQbv -> false; - default -> throw new IllegalStateException("Unexpected value: " + this.wcpInst); - }; - } - - private int maxCt() { - switch (this.wcpInst) { - case ISZERObv, EQbv -> { - return 0; - } - case LTbv, GTbv, LEQbv, GEQbv, SLTbv, SGTbv -> { - if (this.arg1.isZero() && this.arg2.isZero()) { - return 0; - } else { - final ArrayList sizes = new ArrayList<>(4); - sizes.add(this.arg1.slice(0, LLARGE).trimLeadingZeros().size()); - sizes.add(this.arg2.slice(0, LLARGE).trimLeadingZeros().size()); - sizes.add(this.arg1.slice(LLARGE, LLARGE).trimLeadingZeros().size()); - sizes.add(this.arg2.slice(LLARGE, LLARGE).trimLeadingZeros().size()); - return Collections.max(sizes) - 1; - } - } - default -> throw new IllegalStateException("Unexpected value: " + this.wcpInst); - } - } - - @Override - protected int computeLineCount() { - return this.ctMax + 1; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/DataLocation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/DataLocation.java deleted file mode 100644 index 4634f1cb8..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/DataLocation.java +++ /dev/null @@ -1,31 +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.opcode; - -public enum DataLocation { - NONE, - ROM, - TXN_CALL_DATA, - RAM, - STACK, - EC_DATA, - EC_INFO, - MOD_EXP_DATA, - HASH_DATA, - HASH_INFO, - BLAKE_DATA, - LOG_DATA, -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/InstructionFamily.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/InstructionFamily.java deleted file mode 100644 index e40b6dbc2..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/InstructionFamily.java +++ /dev/null @@ -1,45 +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.opcode; - -/** All the instruction families, as used by the hub. */ -public enum InstructionFamily { - ADD, - MOD, - MUL, - EXT, - WCP, - BIN, - SHF, - KEC, - CONTEXT, - ACCOUNT, - COPY, - TRANSACTION, - BATCH, - STACK_RAM, - STORAGE, - JUMP, - MACHINE_STATE, - PUSH_POP, - DUP, - SWAP, - LOG, - CREATE, - CALL, - HALT, - INVALID -} 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 deleted file mode 100644 index 8a3594408..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCode.java +++ /dev/null @@ -1,230 +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.opcode; - -/** Represents the entire set of opcodes that are required by the arithmetization process. */ -public enum OpCode { - STOP, - ADD, - MUL, - SUB, - DIV, - SDIV, - MOD, - SMOD, - ADDMOD, - MULMOD, - EXP, - SIGNEXTEND, - LT, - GT, - SLT, - SGT, - EQ, - ISZERO, - AND, - OR, - XOR, - NOT, - BYTE, - SHL, - SHR, - SAR, - SHA3, - ADDRESS, - BALANCE, - ORIGIN, - CALLER, - CALLVALUE, - CALLDATALOAD, - CALLDATASIZE, - CALLDATACOPY, - CODESIZE, - CODECOPY, - GASPRICE, - EXTCODESIZE, - EXTCODECOPY, - RETURNDATASIZE, - RETURNDATACOPY, - EXTCODEHASH, - BLOCKHASH, - COINBASE, - TIMESTAMP, - NUMBER, - DIFFICULTY, - GASLIMIT, - CHAINID, - SELFBALANCE, - BASEFEE, - POP, - MLOAD, - MSTORE, - MSTORE8, - SLOAD, - SSTORE, - JUMP, - JUMPI, - PC, - MSIZE, - GAS, - JUMPDEST, - // PUSH0, - PUSH1, - PUSH2, - PUSH3, - PUSH4, - PUSH5, - PUSH6, - PUSH7, - PUSH8, - PUSH9, - PUSH10, - PUSH11, - PUSH12, - PUSH13, - PUSH14, - PUSH15, - PUSH16, - PUSH17, - PUSH18, - PUSH19, - PUSH20, - PUSH21, - PUSH22, - PUSH23, - PUSH24, - PUSH25, - PUSH26, - PUSH27, - PUSH28, - PUSH29, - PUSH30, - PUSH31, - PUSH32, - DUP1, - DUP2, - DUP3, - DUP4, - DUP5, - DUP6, - DUP7, - DUP8, - DUP9, - DUP10, - DUP11, - DUP12, - DUP13, - DUP14, - DUP15, - DUP16, - SWAP1, - SWAP2, - SWAP3, - SWAP4, - SWAP5, - SWAP6, - SWAP7, - SWAP8, - SWAP9, - SWAP10, - SWAP11, - SWAP12, - SWAP13, - SWAP14, - SWAP15, - SWAP16, - LOG0, - LOG1, - LOG2, - LOG3, - LOG4, - CREATE, - CALL, - CALLCODE, - RETURN, - DELEGATECALL, - CREATE2, - STATICCALL, - REVERT, - INVALID, - SELFDESTRUCT; - - /** - * Convert a mnemonic in any case into the matching {@link OpCode}. - * - * @param mnemonic the opcode menmonic - * @return the corresponding OpCode - */ - public static OpCode fromMnemonic(final String mnemonic) { - return OpCode.valueOf(mnemonic.toUpperCase()); - } - - /** - * Retrieves {@link OpCode} metadata of type {@link OpCodeData}. - * - * @return the current {@link OpCode}'s {@link OpCodeData} - */ - public OpCodeData getData() { - return OpCodes.of(this); - } - - /** - * Retrieves the {@link OpCode} corresponding to a given value. - * - * @return the {@link OpCode} - */ - public static OpCode of(final int value) { - return OpCodes.of(value).mnemonic(); - } - - /** - * Returns the {@link OpCode}'s long value as a byte type. - * - * @return the {@link OpCode}'s value as a byte - */ - public byte byteValue() { - return (byte) this.getData().value(); - } - - /** Returns whether the {@link OpCode} entails a contract creation. */ - public boolean isCreate() { - return this == OpCode.CREATE || this == OpCode.CREATE2; - } - - /** Returns whether the {@link OpCode} is one of the CALL opcodes */ - public boolean isCall() { - return this == OpCode.CALL - || this == OpCode.CALLCODE - || this == OpCode.DELEGATECALL - || this == OpCode.STATICCALL; - } - - /** - * Matches if the current {@link OpCode} is contained within a list of {@link OpCode}s. - * - * @param opCodes list of {@link OpCode}s to match against. - * @return if the current {@link OpCode} is contained within the list. - */ - public boolean isAnyOf(OpCode... opCodes) { - for (OpCode opCode : opCodes) { - if (opCode.equals(this)) { - return true; - } - } - - return false; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodeData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodeData.java deleted file mode 100644 index 09aab1f9d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodeData.java +++ /dev/null @@ -1,92 +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.opcode; - -import java.util.Objects; - -import net.consensys.linea.zktracer.opcode.gas.Billing; -import net.consensys.linea.zktracer.opcode.gas.MxpType; -import net.consensys.linea.zktracer.opcode.stack.StackSettings; - -/** - * Contains the {@link OpCode} and its related metadata. - * - * @param mnemonic The type of the opcode represented by {@link OpCode}. - * @param value The actual unsigned byte value of the opcode. - * @param instructionFamily The {@link InstructionFamily} to which the opcode belongs. - * @param stackSettings A {@link StackSettings} instance describing how the opcode alters the EVM - * stack. - * @param ramSettings A {@link RamSettings} instance describing how the opcode alters the memory. - * @param billing A {@link Billing} instance describing the billing scheme of the instruction. - */ -public record OpCodeData( - OpCode mnemonic, - int value, - boolean pushFlag, - boolean jumpFlag, - InstructionFamily instructionFamily, - StackSettings stackSettings, - RamSettings ramSettings, - Billing billing) { - - /** - * Returns the number of arguments supported by the given opcode. - * - * @return number of arguments supported by the given opcode. - */ - public int numberOfArguments() { - return this.stackSettings.nbRemoved(); - } - - public RamSettings ramSettings() { - return Objects.requireNonNullElse(this.ramSettings, RamSettings.DEFAULT); - } - - public Billing billing() { - return Objects.requireNonNullElse(this.billing, Billing.DEFAULT); - } - - /** - * A method singling out PUSHx instructions. - * - * @return true if this opcode is a PUSHx - */ - boolean isPush() { - return (0x60 <= this.value) && (this.value < 0x80); - } - - /** - * Returns whether this instruction belong to the HALT family. - * - * @return true if {@link InstructionFamily} is HALT - */ - public boolean isHalt() { - return this.instructionFamily == InstructionFamily.HALT; - } - - /** - * Returns whether this instruction belong to the INVALID family. - * - * @return true if {@link InstructionFamily} is INVALID - */ - public boolean isInvalid() { - return this.instructionFamily == InstructionFamily.INVALID; - } - - public boolean isMxp() { - return this.billing.type() != MxpType.NONE; - } -} 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 deleted file mode 100644 index 2b293bfb6..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodes.java +++ /dev/null @@ -1,96 +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.opcode; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.type.CollectionType; -import com.fasterxml.jackson.databind.type.TypeFactory; -import lombok.SneakyThrows; -import net.consensys.linea.zktracer.json.JsonConverter; - -/** Responsible for managing opcode loading and opcode metadata retrieval. */ -public class OpCodes { - private static final JsonConverter YAML_CONVERTER = JsonConverter.builder().enableYaml().build(); - - private static Map valueToOpCodeDataMap; - private static Map opCodeToOpCodeDataMap; - - /** Loads all opcode metadata from src/main/resources/opcodes.yml. */ - @SneakyThrows(IOException.class) - public static void load() { - JsonNode rootNode = - YAML_CONVERTER - .getObjectMapper() - .readTree(OpCodes.class.getClassLoader().getResourceAsStream("opcodes.yml")) - .get("opcodes"); - - CollectionType typeReference = - TypeFactory.defaultInstance().constructCollectionType(List.class, OpCodeData.class); - - List opCodes = - YAML_CONVERTER.getObjectMapper().treeToValue(rootNode, typeReference); - - valueToOpCodeDataMap = opCodes.stream().collect(Collectors.toMap(OpCodeData::value, e -> e)); - opCodeToOpCodeDataMap = - opCodes.stream().collect(Collectors.toMap(OpCodeData::mnemonic, e -> e)); - } - - /** - * Get opcode metadata per opcode long value. - * - * @param value opcode long value. - * @return an instance of {@link OpCodeData} corresponding to the numeric (long) value. - */ - public static OpCodeData of(final int value) { - if (value < 0 || value > 255) { - throw new IllegalArgumentException("No OpCode with value %s is defined.".formatted(value)); - } - - return valueToOpCodeDataMap.getOrDefault(value, of(OpCode.INVALID)); - } - - /** - * Get opcode metadata per opcode mnemonic of type {@link OpCode}. - * - * @param code opcode mnemonic of type {@link OpCode}. - * @return an instance of {@link OpCodeData} corresponding to mnemonic of type {@link OpCode}. - */ - public static OpCodeData of(final OpCode code) { - return Optional.ofNullable(opCodeToOpCodeDataMap.get(code)) - .orElseThrow( - () -> - new IllegalArgumentException( - "No OpCode of mnemonic %s is defined.".formatted(code))); - } - - /** - * Get opcode metadata for a list of {@link OpCode}s. - * - * @param codes a list of opcode mnemonics of type {@link OpCode}. - * @return a list of {@link OpCodeData} items corresponding their mnemonics of type {@link - * OpCode}. - */ - public static List of(final OpCode... codes) { - return Arrays.stream(codes).map(OpCodes::of).toList(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/RamSettings.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/RamSettings.java deleted file mode 100644 index f51c67a7a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/RamSettings.java +++ /dev/null @@ -1,31 +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.opcode; - -import java.util.Objects; - -public record RamSettings(DataLocation source, DataLocation target) { - public static final RamSettings DEFAULT = new RamSettings(DataLocation.NONE, DataLocation.NONE); - - public RamSettings(DataLocation source, DataLocation target) { - this.source = Objects.requireNonNullElse(source, DataLocation.NONE); - this.target = Objects.requireNonNullElse(target, DataLocation.NONE); - } - - public boolean enabled() { - return this.source != DataLocation.NONE || this.target != DataLocation.NONE; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/Billing.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/Billing.java deleted file mode 100644 index 6e7cf1fa7..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/Billing.java +++ /dev/null @@ -1,80 +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.opcode.gas; - -import java.util.Objects; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - -/** - * An ancillary class to compute gas billing of some instructions. - * - * @param perUnit gas cost of a unit - * @param billingRate the unit used to bill gas - */ -@JsonDeserialize(using = BillingDeserializer.class) -public record Billing(GasConstants perUnit, BillingRate billingRate, MxpType type) { - public static final Billing DEFAULT = - new Billing(GasConstants.G_ZERO, BillingRate.NONE, MxpType.NONE); - - public Billing() { - this(GasConstants.G_ZERO, BillingRate.NONE, MxpType.NONE); - } - - public GasConstants perUnit() { - return Objects.requireNonNullElse(this.perUnit, GasConstants.G_ZERO); - } - - public BillingRate billingRate() { - return Objects.requireNonNullElse(this.billingRate, BillingRate.NONE); - } - - public MxpType type() { - return Objects.requireNonNullElse(this.type, MxpType.NONE); - } - - /** - * Create a billing scheme only dependent on the Mxp. - * - * @param type the MXP type - * @return the billing scheme - */ - public static Billing byMxp(MxpType type) { - return new Billing(null, null, type); - } - - /** - * Create a per-word billing scheme. - * - * @param type the MXP type - * @param wordPrice gas cost of a word - * @return the billing scheme - */ - public static Billing byWord(MxpType type, GasConstants wordPrice) { - return new Billing(wordPrice, BillingRate.BY_WORD, type); - } - - /** - * Create a per-byte billing scheme. - * - * @param type the MXP type - * @param bytePrice gas cost of a byte - * @return the billing scheme - */ - public static Billing byByte(MxpType type, GasConstants bytePrice) { - return new Billing(bytePrice, BillingRate.BY_BYTE, type); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/BillingDeserializer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/BillingDeserializer.java deleted file mode 100644 index a1466ffdd..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/BillingDeserializer.java +++ /dev/null @@ -1,100 +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.opcode.gas; - -import java.util.Optional; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -import lombok.SneakyThrows; - -/** Custom Jackson deserializer for handling {@link Billing} properties. */ -public class BillingDeserializer extends StdDeserializer { - - public BillingDeserializer() { - this(Billing.class); - } - - protected BillingDeserializer(Class vc) { - super(vc); - } - - @SneakyThrows - @Override - public Billing deserialize(JsonParser p, DeserializationContext context) { - JsonNode node = p.getCodec().readTree(p); - - Optional byWord = Optional.ofNullable(node.get("byWord")); - Optional byMxp = Optional.ofNullable(node.get("byMxp")); - Optional byByte = Optional.ofNullable(node.get("byByte")); - - if (byWord.isPresent()) { - JsonNode wordNode = byWord.get(); - - JsonNode wordPriceNode = - Optional.of(wordNode.get("wordPrice")) - .orElseThrow( - () -> - new IllegalArgumentException( - "'wordPrice' is a mandatory property when declaring 'byWord' billing")); - - MxpType type = extractMxpType(wordNode, "byWord"); - GasConstants wordPrice = GasConstants.valueOf(wordPriceNode.textValue()); - - return Billing.byWord(type, wordPrice); - } - - if (byMxp.isPresent()) { - JsonNode mxpNode = byMxp.get(); - - MxpType type = extractMxpType(mxpNode, "byMxp"); - - return Billing.byMxp(type); - } - - if (byByte.isPresent()) { - JsonNode byteNode = byByte.get(); - - JsonNode bytePriceNode = - Optional.of(byteNode.get("bytePrice")) - .orElseThrow( - () -> - new IllegalArgumentException( - "'bytePrice' is a mandatory property when declaring 'byByte' billing")); - - MxpType type = extractMxpType(byteNode, "byByte"); - GasConstants bytePrice = GasConstants.valueOf(bytePriceNode.textValue()); - - return Billing.byByte(type, bytePrice); - } - - return new Billing(); - } - - private MxpType extractMxpType(JsonNode node, String billingRate) { - JsonNode typeNode = - Optional.of(node.get("type")) - .orElseThrow( - () -> - new IllegalArgumentException( - "'mnemonic' is a mandatory property when declaring '%s' billing" - .formatted(billingRate))); - - return MxpType.valueOf(typeNode.textValue()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/BillingRate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/BillingRate.java deleted file mode 100644 index b4a9b0615..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/BillingRate.java +++ /dev/null @@ -1,23 +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.opcode.gas; - -/** The unit used to bill the gas usage of an instruction. */ -public enum BillingRate { - NONE, - BY_WORD, - BY_BYTE -} 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 deleted file mode 100644 index e01648d17..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/GasConstants.java +++ /dev/null @@ -1,86 +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.opcode.gas; - -import lombok.RequiredArgsConstructor; - -/** All the classes of gas prices per instruction used in the EVM. */ -@RequiredArgsConstructor -public enum GasConstants { - G_ZERO(0), - G_JUMP_DEST(0), - 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), - // 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 - // data for memory expansion, STP data for gas stipend <- made it its own type - S_HUB(0), - S_STP(0), - S_PREC_INFO(0); - - /** The gas price of the instruction family. */ - private final int cost; - - public int cost() { - return this.cost; - } - - /** Constants required to compute some instruction families base price. */ - private static class Constants { - /** Base price for a LOGx call. */ - private static final int LOG = 375; - /** Additional price per topic for a LOGx call. */ - private static final int LOG_TOPIC = 375; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/MxpType.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/MxpType.java deleted file mode 100644 index 5c1166ed5..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/MxpType.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.opcode.gas; - -/** All the ways for the Mxp to compute the total gas consumption of an instruction. */ -public enum MxpType { - NONE, - TYPE_1, - TYPE_2, - TYPE_3, - TYPE_4, - TYPE_5, -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/AccountAccess.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/AccountAccess.java deleted file mode 100644 index 2c88149a3..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/AccountAccess.java +++ /dev/null @@ -1,49 +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.opcode.gas.projector; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public final class AccountAccess implements GasProjection { - private final MessageFrame frame; - private Address target = null; - - public AccountAccess(MessageFrame frame) { - if (frame.stackSize() > 0) { - this.target = Words.toAddress(frame.getStackItem(0)); - } - this.frame = frame; - } - - boolean isInvalid() { - return this.target == null; - } - - @Override - public long accountAccess() { - if (this.isInvalid()) { - return 0; - } - - if (frame.isAddressWarm(this.target)) { - return gc.getWarmStorageReadCost(); - } else { - return gc.getColdAccountAccessCost(); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Base.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Base.java deleted file mode 100644 index 20eeff3fb..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Base.java +++ /dev/null @@ -1,23 +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.opcode.gas.projector; - -public final class Base implements GasProjection { - @Override - public long staticGas() { - return gc.getBaseTierGasCost(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/BlockHash.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/BlockHash.java deleted file mode 100644 index 51e240e55..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/BlockHash.java +++ /dev/null @@ -1,23 +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.opcode.gas.projector; - -public final class BlockHash implements GasProjection { - @Override - public long staticGas() { - return gc.getBlockHashOperationGasCost(); - } -} 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 deleted file mode 100644 index e6a765247..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java +++ /dev/null @@ -1,132 +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.opcode.gas.projector; - -import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; - -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public record Call( - MessageFrame frame, - long stipend, - long inputDataOffset, - long inputDataLength, - long returnDataOffset, - long returnDataLength, - Wei value, - Account recipient, - Address to) - implements GasProjection { - public static Call invalid() { - return new Call(null, 0, 0, 0, 0, 0, Wei.ZERO, null, null); - } - - boolean isInvalid() { - return this.frame == null; - } - - @Override - public long memoryExpansion() { - if (this.isInvalid()) { - return 0; - } - - return Math.max( - gc.memoryExpansionGasCost(frame, inputDataOffset, inputDataLength), - gc.memoryExpansionGasCost(frame, returnDataOffset, returnDataLength)); - } - - @Override - public long largestOffset() { - if (this.isInvalid()) { - return 0; - } - - return Math.max( - inputDataLength == 0 ? 0 : Words.clampedAdd(inputDataOffset, inputDataLength), - returnDataLength == 0 ? 0 : Words.clampedAdd(returnDataOffset, returnDataLength)); - } - - @Override - public long accountAccess() { - if (this.isInvalid()) { - return 0; - } - - if (frame.isAddressWarm(to) || isPrecompile(to)) { - return GasConstants.G_WARM_ACCESS.cost(); - } else { - return GasConstants.G_COLD_ACCOUNT_ACCESS.cost(); - } - } - - @Override - public long accountCreation() { - if (this.isInvalid()) { - return 0; - } - - if ((recipient == null || recipient.isEmpty()) && !value.isZero()) { - return GasConstants.G_NEW_ACCOUNT.cost(); - } else { - return 0L; - } - } - - @Override - public long transferValue() { - if (this.isInvalid()) { - return 0; - } - - if (value.isZero()) { - return 0L; - } else { - return GasConstants.G_CALL_VALUE.cost(); - } - } - - @Override - public long rawStipend() { - if (this.isInvalid()) { - return 0; - } - - final long cost = memoryExpansion() + accountAccess() + accountCreation() + transferValue(); - if (cost > frame.getRemainingGas()) { - return 0L; - } else { - final long remaining = frame.getRemainingGas() - cost; - final long weird = remaining - remaining / 64; - - return Math.min(weird, stipend); - } - } - - @Override - public long extraStipend() { - if (this.isInvalid() || this.value.isZero()) { - return 0; - } - - return GasConstants.G_CALL_STIPEND.cost(); - } -} 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 deleted file mode 100644 index b0db7ebc4..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create.java +++ /dev/null @@ -1,63 +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.opcode.gas.projector; - -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public final class Create implements GasProjection { - private final MessageFrame frame; - private long initCodeOffset = 0; - private long initCodeLength = 0; - - public Create(MessageFrame frame) { - this.frame = frame; - if (frame.stackSize() > 2) { - this.initCodeOffset = clampedToLong(frame.getStackItem(1)); - this.initCodeLength = clampedToLong(frame.getStackItem(2)); - } - } - - @Override - public long staticGas() { - return GasConstants.G_CREATE.cost(); - } - - @Override - public long memoryExpansion() { - return gc.memoryExpansionGasCost(frame, initCodeOffset, initCodeLength); - } - - @Override - public long largestOffset() { - return initCodeLength == 0 ? 0 : Words.clampedAdd(initCodeOffset, initCodeLength); - } - - @Override - public long rawStipend() { - long currentGas = frame.getRemainingGas(); - long gasCost = this.staticGas() + this.memoryExpansion(); - - if (gasCost > currentGas) { - return 0; - } else { - return currentGas - currentGas / 64; - } - } -} 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 deleted file mode 100644 index 8209d2f61..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create2.java +++ /dev/null @@ -1,73 +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.opcode.gas.projector; - -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public final class Create2 implements GasProjection { - private final MessageFrame frame; - private long initCodeOffset = 0; - private long initCodeLength = 0; - - public Create2(MessageFrame frame) { - this.frame = frame; - if (frame.stackSize() > 2) { - this.initCodeOffset = clampedToLong(frame.getStackItem(1)); - this.initCodeLength = clampedToLong(frame.getStackItem(2)); - } - } - - @Override - public long staticGas() { - return GasConstants.G_CREATE.cost(); - } - - @Override - public long memoryExpansion() { - return gc.memoryExpansionGasCost(frame, initCodeOffset, initCodeLength); - } - - @Override - public long largestOffset() { - return initCodeLength == 0 ? 0 : Words.clampedAdd(initCodeOffset, initCodeLength); - } - - @Override - public long linearPerWord() { - return linearCost(GasConstants.G_KECCAK_256_WORD.cost(), initCodeLength, 32); - } - - @Override - public long rawStipend() { - long currentGas = frame.getRemainingGas(); - long gasCost = this.staticGas() + this.memoryExpansion() + this.linearPerWord(); - - if (gasCost > currentGas) { - return 0; - } else { - return currentGas - currentGas / 64; - } - } - - @Override - public long messageSize() { - return this.initCodeLength; - } -} 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 deleted file mode 100644 index 77c32c548..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/DataCopy.java +++ /dev/null @@ -1,63 +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.opcode.gas.projector; - -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import lombok.extern.slf4j.Slf4j; -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; - -@Slf4j -public final class DataCopy implements GasProjection { - private final MessageFrame frame; - private long offset = 0; - private long len = 0; - - public DataCopy(MessageFrame frame, OpCode opCode) { - this.frame = frame; - if (frame.stackSize() > 2) { - if (opCode == OpCode.CODECOPY) { - this.offset = clampedToLong(frame.getStackItem(0)); - } else { - this.offset = clampedToLong(frame.getStackItem(1)); - } - this.len = clampedToLong(frame.getStackItem(2)); - } - } - - @Override - public long staticGas() { - return gc.getVeryLowTierGasCost(); - } - - @Override - public long memoryExpansion() { - return gc.memoryExpansionGasCost(frame, this.offset, this.len); - } - - @Override - public long linearPerWord() { - return linearCost(GasConstants.G_COPY.cost(), this.len, 32); - } - - @Override - public long largestOffset() { - return this.len == 0 ? 0 : Words.clampedAdd(this.offset, this.len); - } -} 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 deleted file mode 100644 index cb2816b9c..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Exp.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.opcode.gas.projector; - -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import org.hyperledger.besu.evm.frame.MessageFrame; - -public final class Exp implements GasProjection { - private int exponentByteSize = 0; - - public Exp(MessageFrame frame) { - if (frame.stackSize() > 1) { - final int bitLength = frame.getStackItem(1).bitLength(); - this.exponentByteSize = (bitLength + 7) / 8; - } - } - - @Override - public long staticGas() { - return GasConstants.G_EXP.cost(); - } - - @Override - public long expGas() { - return linearCost(GasConstants.G_EXP_BYTE.cost(), 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 deleted file mode 100644 index 7f755ae26..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/ExtCodeCopy.java +++ /dev/null @@ -1,66 +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.opcode.gas.projector; - -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public final class ExtCodeCopy implements GasProjection { - private final MessageFrame frame; - private long offset = 0; - private long size = 0; - private long bitSize = 0; - private Address target = Address.ZERO; - - public ExtCodeCopy(MessageFrame frame) { - this.frame = frame; - if (frame.stackSize() > 3) { - this.target = Words.toAddress(frame.getStackItem(0)); - this.offset = clampedToLong(frame.getStackItem(1)); - this.size = clampedToLong(frame.getStackItem(3)); - this.bitSize = frame.getStackItem(3).bitLength(); - } - } - - @Override - public long memoryExpansion() { - - return gc.memoryExpansionGasCost(frame, offset, this.size); - } - - @Override - public long largestOffset() { - return this.size == 0 ? 0 : Words.clampedAdd(this.offset, this.size); - } - - @Override - public long accountAccess() { - if (frame.isAddressWarm(this.target)) { - return gc.getWarmStorageReadCost(); - } else { - return gc.getColdAccountAccessCost(); - } - } - - @Override - public long linearPerWord() { - return linearCost(GasConstants.G_COPY.cost(), this.bitSize, 32); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/GasProjection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/GasProjection.java deleted file mode 100644 index dc2fccfbb..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/GasProjection.java +++ /dev/null @@ -1,114 +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.opcode.gas.projector; - -import com.google.common.base.Preconditions; -import net.consensys.linea.zktracer.ZkTracer; -import org.hyperledger.besu.evm.gascalculator.GasCalculator; -import org.hyperledger.besu.evm.internal.Words; - -public interface GasProjection { - GasCalculator gc = ZkTracer.gasCalculator; - - default long linearCost(long a, long x, long unit) { - Preconditions.checkArgument((unit == 1) || (unit == 32)); - return Words.clampedMultiply(a, (Words.clampedAdd(x, unit) - 1) / unit); - } - - default long staticGas() { - return 0; - } - - default long expGas() { - return 0; - } - - default long memoryExpansion() { - return 0; - } - - default long accountAccess() { - return 0; - } - - default long accountCreation() { - return 0; - } - - default long transferValue() { - return 0; - } - - default long linearPerWord() { - return 0; - } - - default long linearPerByte() { - return 0; - } - - default long storageWarmth() { - return 0; - } - - default long sStoreValue() { - return 0; - } - - default long rawStipend() { - return 0; - } - - default long extraStipend() { - return 0; - } - - default long deploymentCost() { - return 0; - } - - default long refund() { - return 0; - } - - default long messageSize() { - return 0; - } - - /** - * Returns the largest memory expansion offset generated by this instruction if applicable, 0 - * otherwise. - * - * @return how far in the memory this instruction reaches - */ - default long largestOffset() { - return 0; - } - - default long total() { - return staticGas() - + expGas() - + memoryExpansion() - + accountAccess() - + accountCreation() - + transferValue() - + linearPerWord() - + linearPerByte() - + storageWarmth() - + sStoreValue() - + deploymentCost(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/GasProjector.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/GasProjector.java deleted file mode 100644 index c5c8c1522..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/GasProjector.java +++ /dev/null @@ -1,253 +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.opcode.gas.projector; - -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import net.consensys.linea.zktracer.opcode.OpCode; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public class GasProjector { - public GasProjection of(MessageFrame frame, OpCode opCode) { - return switch (opCode) { - case STOP -> new Zero(); - case ADD, - SUB, - NOT, - LT, - GT, - SLT, - SGT, - EQ, - ISZERO, - AND, - OR, - XOR, - BYTE, - SHL, - SHR, - SAR, - CALLDATALOAD, - PUSH1, - PUSH2, - PUSH3, - PUSH4, - PUSH5, - PUSH6, - PUSH7, - PUSH8, - PUSH9, - PUSH10, - PUSH11, - PUSH12, - PUSH13, - PUSH14, - PUSH15, - PUSH16, - PUSH17, - PUSH18, - PUSH19, - PUSH20, - PUSH21, - PUSH22, - PUSH23, - PUSH24, - PUSH25, - PUSH26, - PUSH27, - PUSH28, - PUSH29, - PUSH30, - PUSH31, - PUSH32, - DUP1, - DUP2, - DUP3, - DUP4, - DUP5, - DUP6, - DUP7, - DUP8, - DUP9, - DUP10, - DUP11, - DUP12, - DUP13, - DUP14, - DUP15, - DUP16, - SWAP1, - SWAP2, - SWAP3, - SWAP4, - SWAP5, - SWAP6, - SWAP7, - SWAP8, - SWAP9, - SWAP10, - SWAP11, - SWAP12, - SWAP13, - SWAP14, - SWAP15, - SWAP16 -> new VeryLow(); - case MUL, DIV, SDIV, MOD, SMOD, SIGNEXTEND, SELFBALANCE -> new Low(); - case ADDMOD, MULMOD, JUMP -> new Mid(); - case EXP -> new Exp(frame); - case SHA3 -> new Sha3(frame); - case ADDRESS, - ORIGIN, - CALLER, - CALLVALUE, - CALLDATASIZE, - CODESIZE, - GASPRICE, - COINBASE, - TIMESTAMP, - NUMBER, - DIFFICULTY, - GASLIMIT, - CHAINID, - RETURNDATASIZE, - POP, - PC, - MSIZE, - GAS, - BASEFEE -> new Base(); - case BALANCE, EXTCODESIZE, EXTCODEHASH -> new AccountAccess(frame); - case CALLDATACOPY, CODECOPY, RETURNDATACOPY -> new DataCopy(frame, opCode); - case EXTCODECOPY -> new ExtCodeCopy(frame); - case BLOCKHASH -> new BlockHash(); - case MLOAD, MSTORE -> new MLoadStore(frame); - case MSTORE8 -> new MStore8(frame); - case SLOAD -> new SLoad(frame); - case SSTORE -> new SStore(frame); - case JUMPI -> new High(); - case JUMPDEST -> new JumpDest(); - case LOG0 -> new Log(frame, 0); - case LOG1 -> new Log(frame, 1); - case LOG2 -> new Log(frame, 2); - case LOG3 -> new Log(frame, 3); - case LOG4 -> new Log(frame, 4); - case CREATE -> new Create(frame); - case CREATE2 -> new Create2(frame); - case CALL -> { - if (frame.stackSize() > 6) { - final long stipend = clampedToLong(frame.getStackItem(0)); - final Address to = Words.toAddress(frame.getStackItem(1)); - final Account recipient = frame.getWorldUpdater().get(to); - final Wei value = Wei.wrap(frame.getStackItem(2)); - final long inputDataOffset = clampedToLong(frame.getStackItem(3)); - final long inputDataLength = clampedToLong(frame.getStackItem(4)); - final long returnDataOffset = clampedToLong(frame.getStackItem(5)); - final long returnDataLength = clampedToLong(frame.getStackItem(6)); - yield new Call( - frame, - stipend, - inputDataOffset, - inputDataLength, - returnDataOffset, - returnDataLength, - value, - recipient, - to); - } else { - yield Call.invalid(); - } - } - case CALLCODE -> { - if (frame.stackSize() > 6) { - final long stipend = clampedToLong(frame.getStackItem(0)); - final Account recipient = frame.getWorldUpdater().get(frame.getRecipientAddress()); - final Address to = Words.toAddress(frame.getStackItem(1)); - final Wei value = Wei.wrap(frame.getStackItem(2)); - final long inputDataOffset = clampedToLong(frame.getStackItem(3)); - final long inputDataLength = clampedToLong(frame.getStackItem(4)); - final long returnDataOffset = clampedToLong(frame.getStackItem(5)); - final long returnDataLength = clampedToLong(frame.getStackItem(6)); - yield new Call( - frame, - stipend, - inputDataOffset, - inputDataLength, - returnDataOffset, - returnDataLength, - value, - recipient, - to); - } else { - yield Call.invalid(); - } - } - case DELEGATECALL -> { - if (frame.stackSize() > 5) { - final long stipend = clampedToLong(frame.getStackItem(0)); - final Account recipient = frame.getWorldUpdater().get(frame.getRecipientAddress()); - final Address to = Words.toAddress(frame.getStackItem(1)); - final long inputDataOffset = clampedToLong(frame.getStackItem(2)); - final long inputDataLength = clampedToLong(frame.getStackItem(3)); - final long returnDataOffset = clampedToLong(frame.getStackItem(4)); - final long returnDataLength = clampedToLong(frame.getStackItem(5)); - yield new Call( - frame, - stipend, - inputDataOffset, - inputDataLength, - returnDataOffset, - returnDataLength, - Wei.ZERO, - recipient, - to); - } else { - yield Call.invalid(); - } - } - case STATICCALL -> { - if (frame.stackSize() > 5) { - final long stipend = clampedToLong(frame.getStackItem(0)); - final Address to = Words.toAddress(frame.getStackItem(1)); - final Account recipient = frame.getWorldUpdater().get(to); - final long inputDataOffset = clampedToLong(frame.getStackItem(2)); - final long inputDataLength = clampedToLong(frame.getStackItem(3)); - final long returnDataOffset = clampedToLong(frame.getStackItem(4)); - final long returnDataLength = clampedToLong(frame.getStackItem(5)); - yield new Call( - frame, - stipend, - inputDataOffset, - inputDataLength, - returnDataOffset, - returnDataLength, - Wei.ZERO, - recipient, - to); - } else { - yield Call.invalid(); - } - } - case RETURN -> new Return(frame); - case REVERT -> new Revert(frame); - case INVALID -> new GasProjection() {}; - case SELFDESTRUCT -> new SelfDestruct(frame); - default -> throw new IllegalStateException("Unexpected value: " + opCode); - }; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/High.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/High.java deleted file mode 100644 index effbcfb9d..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/High.java +++ /dev/null @@ -1,23 +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.opcode.gas.projector; - -public record High() implements GasProjection { - @Override - public long staticGas() { - return gc.getHighTierGasCost(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/JumpDest.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/JumpDest.java deleted file mode 100644 index 64766ce81..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/JumpDest.java +++ /dev/null @@ -1,23 +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.opcode.gas.projector; - -public record JumpDest() implements GasProjection { - @Override - public long staticGas() { - return gc.getJumpDestOperationGasCost(); - } -} 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 deleted file mode 100644 index ebd418d45..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Log.java +++ /dev/null @@ -1,75 +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.opcode.gas.projector; - -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public final class Log implements GasProjection { - private final MessageFrame frame; - private long offset = 0; - private long size = 0; - private final int numTopics; - - public Log(MessageFrame frame, int numTopics) { - this.frame = frame; - this.numTopics = numTopics; - if (frame.stackSize() > 1) { - this.offset = clampedToLong(frame.getStackItem(0)); - this.size = clampedToLong(frame.getStackItem(1)); - } - } - - @Override - public long staticGas() { - switch (numTopics) { - case 0 -> { - return GasConstants.G_LOG_0.cost(); - } - case 1 -> { - return GasConstants.G_LOG_1.cost(); - } - case 2 -> { - return GasConstants.G_LOG_2.cost(); - } - case 3 -> { - return GasConstants.G_LOG_3.cost(); - } - case 4 -> { - return GasConstants.G_LOG_4.cost(); - } - default -> throw new IllegalStateException("Unexpected value: " + numTopics); - } - } - - @Override - public long memoryExpansion() { - return gc.memoryExpansionGasCost(frame, offset, size); - } - - @Override - public long largestOffset() { - return size == 0 ? 0 : Words.clampedAdd(offset, size); - } - - @Override - public long linearPerByte() { - return linearCost(GasConstants.G_LOG_DATA.cost(), size, 1); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Low.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Low.java deleted file mode 100644 index e7677b576..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Low.java +++ /dev/null @@ -1,23 +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.opcode.gas.projector; - -public record Low() implements GasProjection { - @Override - public long staticGas() { - return gc.getLowTierGasCost(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/MLoadStore.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/MLoadStore.java deleted file mode 100644 index a2fe68e63..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/MLoadStore.java +++ /dev/null @@ -1,48 +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.opcode.gas.projector; - -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public final class MLoadStore implements GasProjection { - private final MessageFrame frame; - private long offset = 0; - - public MLoadStore(MessageFrame frame) { - this.frame = frame; - if (frame.stackSize() > 0) { - this.offset = clampedToLong(frame.getStackItem(0)); - } - } - - @Override - public long staticGas() { - return gc.getVeryLowTierGasCost(); - } - - @Override - public long memoryExpansion() { - return gc.memoryExpansionGasCost(this.frame, this.offset, 32); - } - - @Override - public long largestOffset() { - return Words.clampedAdd(this.offset, 32); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/MStore8.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/MStore8.java deleted file mode 100644 index 22e0640c3..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/MStore8.java +++ /dev/null @@ -1,47 +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.opcode.gas.projector; - -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import org.hyperledger.besu.evm.frame.MessageFrame; - -public final class MStore8 implements GasProjection { - private final MessageFrame frame; - private long offset = 0; - - public MStore8(MessageFrame frame) { - this.frame = frame; - if (frame.stackSize() > 0) { - this.offset = clampedToLong(frame.getStackItem(0)); - } - } - - @Override - public long staticGas() { - return gc.getVeryLowTierGasCost(); - } - - @Override - public long memoryExpansion() { - return gc.memoryExpansionGasCost(this.frame, this.offset, 1); - } - - @Override - public long largestOffset() { - return this.offset; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Mid.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Mid.java deleted file mode 100644 index 5d2b79d3b..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Mid.java +++ /dev/null @@ -1,23 +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.opcode.gas.projector; - -public record Mid() implements GasProjection { - @Override - public long staticGas() { - return gc.getMidTierGasCost(); - } -} 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 deleted file mode 100644 index d9fa982f9..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Return.java +++ /dev/null @@ -1,60 +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.opcode.gas.projector; - -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public final class Return implements GasProjection { - private final MessageFrame frame; - private long offset = 0; - private long size = 0; - - public Return(MessageFrame frame) { - this.frame = frame; - if (frame.stackSize() > 1) { - this.offset = clampedToLong(frame.getStackItem(0)); - this.size = clampedToLong(frame.getStackItem(1)); - } - } - - @Override - public long memoryExpansion() { - return gc.memoryExpansionGasCost(this.frame, this.offset, this.size); - } - - @Override - public long largestOffset() { - return this.size == 0 ? 0 : Words.clampedAdd(this.offset, this.size); - } - - @Override - public long deploymentCost() { - if (this.size > 24_576) { - return 0L; - } else { - return GasConstants.G_CODE_DEPOSIT.cost() * this.size; - } - } - - @Override - public long messageSize() { - return this.size; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Revert.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Revert.java deleted file mode 100644 index a3fe3957a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Revert.java +++ /dev/null @@ -1,45 +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.opcode.gas.projector; - -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public final class Revert implements GasProjection { - private final MessageFrame frame; - private long offset = 0; - private long size = 0; - - public Revert(MessageFrame frame) { - this.frame = frame; - if (frame.stackSize() > 1) { - this.offset = clampedToLong(frame.getStackItem(0)); - this.size = clampedToLong(frame.getStackItem(1)); - } - } - - @Override - public long memoryExpansion() { - return gc.memoryExpansionGasCost(this.frame, this.offset, this.size); - } - - @Override - public long largestOffset() { - return this.size == 0 ? 0 : Words.clampedAdd(this.offset, 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 deleted file mode 100644 index bc67acf18..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SLoad.java +++ /dev/null @@ -1,45 +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.opcode.gas.projector; - -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.evm.frame.MessageFrame; - -public final class SLoad implements GasProjection { - private final MessageFrame frame; - private UInt256 key = null; - - public SLoad(MessageFrame frame) { - this.frame = frame; - if (frame.stackSize() > 0) { - this.key = UInt256.fromBytes(frame.getStackItem(0)); - } - } - - @Override - public long storageWarmth() { - if (key == null) { - return 0; - } else { - if (frame.isStorageWarm(frame.getRecipientAddress(), key)) { - return GasConstants.G_WARM_ACCESS.cost(); - } else { - return GasConstants.G_COLD_S_LOAD.cost(); - } - } - } -} 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 deleted file mode 100644 index 1a842f208..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SStore.java +++ /dev/null @@ -1,91 +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.opcode.gas.projector; - -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.frame.MessageFrame; - -public final class SStore implements GasProjection { - private final MessageFrame frame; - private UInt256 key = UInt256.ZERO; - private UInt256 originalValue = UInt256.ZERO; - private UInt256 currentValue = UInt256.ZERO; - private UInt256 newValue = UInt256.ZERO; - - public SStore(MessageFrame frame) { - this.frame = frame; - if (frame.stackSize() > 1) { - this.key = UInt256.fromBytes(frame.getStackItem(0)); - final Account account = frame.getWorldUpdater().getAccount(frame.getRecipientAddress()); - if (account == null) { - return; - } - - this.originalValue = account.getOriginalStorageValue(key); - this.currentValue = account.getStorageValue(key); - this.newValue = UInt256.fromBytes(frame.getStackItem(1)); - } - } - - @Override - public long storageWarmth() { - if (frame.isStorageWarm(frame.getRecipientAddress(), key)) { - return 0L; - } else { - return GasConstants.G_COLD_S_LOAD.cost(); - } - } - - @Override - public long sStoreValue() { - if (newValue.equals(currentValue) || !originalValue.equals(currentValue)) { - return GasConstants.G_WARM_ACCESS.cost(); - } else { - return originalValue.isZero() ? GasConstants.G_S_SET.cost() : GasConstants.G_S_RESET.cost(); - } - } - - @Override - public long refund() { - long rDirtyClear = 0; - if (!originalValue.isZero() && currentValue.isZero()) { - rDirtyClear = -GasConstants.R_S_CLEAR.cost(); - } - if (!originalValue.isZero() && newValue.isZero()) { - rDirtyClear = GasConstants.R_S_CLEAR.cost(); - } - - long rDirtyReset = 0; - if (originalValue.equals(newValue) && originalValue.isZero()) { - rDirtyReset = GasConstants.G_S_SET.cost() - GasConstants.G_WARM_ACCESS.cost(); - } - if (originalValue.equals(newValue) && !originalValue.isZero()) { - rDirtyReset = GasConstants.G_S_RESET.cost() - GasConstants.G_WARM_ACCESS.cost(); - } - - long r = 0; - if (!currentValue.equals(newValue) && currentValue.equals(originalValue) && newValue.isZero()) { - r = GasConstants.R_S_CLEAR.cost(); - } - if (!currentValue.equals(newValue) && !currentValue.equals(originalValue)) { - r = rDirtyClear + rDirtyReset; - } - - return r; - } -} 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 deleted file mode 100644 index 810f9b638..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SelfDestruct.java +++ /dev/null @@ -1,79 +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.opcode.gas.projector; - -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -public final class SelfDestruct implements GasProjection { - private final MessageFrame frame; - private Address beneficiaryAddress = null; - - public SelfDestruct(MessageFrame frame) { - this.frame = frame; - if (frame.stackSize() > 0) { - this.beneficiaryAddress = Words.toAddress(frame.getStackItem(0)); - } - } - - boolean isInvalid() { - return this.beneficiaryAddress == null; - } - - @Override - public long staticGas() { - return GasConstants.G_SELF_DESTRUCT.cost(); - } - - @Override - public long accountAccess() { - if (this.isInvalid()) { - return 0; - } - - if (frame.isAddressWarm(this.beneficiaryAddress)) { - return 0L; - } else { - return GasConstants.G_COLD_ACCOUNT_ACCESS.cost(); - } - } - - @Override - public long accountCreation() { - if (this.isInvalid()) { - return 0; - } - - final Account beneficiaryAccount = frame.getWorldUpdater().get(this.beneficiaryAddress); - final Address me = frame.getRecipientAddress(); - final Wei balance = frame.getWorldUpdater().get(me).getBalance(); - - if ((beneficiaryAccount == null || beneficiaryAccount.isEmpty()) && !balance.isZero()) { - return GasConstants.G_NEW_ACCOUNT.cost(); - } else { - return 0L; - } - } - - @Override - public long refund() { - return GasConstants.R_SELF_DESTRUCT.cost(); - } -} 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 deleted file mode 100644 index 7fde68844..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Sha3.java +++ /dev/null @@ -1,63 +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.opcode.gas.projector; - -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 org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.frame.MessageFrame; - -public final class Sha3 implements GasProjection { - private final MessageFrame frame; - private long offset = 0; - private long length = 0; - - public Sha3(MessageFrame frame) { - this.frame = frame; - if (frame.stackSize() >= 2) { - Bytes biLength = frame.getStackItem(1); - this.offset = clampedToLong(frame.getStackItem(0)); - this.length = clampedToLong(biLength); - } - } - - @Override - public long staticGas() { - return GasConstants.G_KECCAK_256.cost(); - } - - @Override - public long memoryExpansion() { - return gc.memoryExpansionGasCost(frame, offset, length); - } - - @Override - public long largestOffset() { - return this.length == 0 ? 0 : clampedAdd(this.offset, this.length); - } - - @Override - public long linearPerWord() { - return linearCost(GasConstants.G_KECCAK_256_WORD.cost(), this.length, 32); - } - - @Override - public long messageSize() { - return this.length; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/VeryLow.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/VeryLow.java deleted file mode 100644 index 0045b9959..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/VeryLow.java +++ /dev/null @@ -1,23 +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.opcode.gas.projector; - -public record VeryLow() implements GasProjection { - @Override - public long staticGas() { - return gc.getVeryLowTierGasCost(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Zero.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Zero.java deleted file mode 100644 index 878699d0a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Zero.java +++ /dev/null @@ -1,23 +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.opcode.gas.projector; - -public record Zero() implements GasProjection { - @Override - public long staticGas() { - return gc.getZeroTierGasCost(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/stack/Pattern.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/stack/Pattern.java deleted file mode 100644 index 076741b38..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/stack/Pattern.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.opcode.stack; - -public enum Pattern { - ZERO_ZERO, - ONE_ZERO, - TWO_ZERO, - ZERO_ONE, - ONE_ONE, - TWO_ONE, - THREE_ONE, - LOAD_STORE, - DUP, - SWAP, - LOG, - COPY, - CALL, - CREATE, -} 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 deleted file mode 100644 index fb1de9044..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/stack/StackSettings.java +++ /dev/null @@ -1,52 +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.opcode.stack; - -import net.consensys.linea.zktracer.opcode.gas.GasConstants; - -/** - * Stores instruction-specific data that are required to generate the stack traces. - * - * @param pattern the stack pattern as given in the spec - * @param alpha alpha as set in the spec - * @param delta delta as set in the sped - * @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 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 - * @param flag1 - * @param flag2 - * @param flag3 - * @param flag4 - */ -public record StackSettings( - Pattern pattern, - int alpha, - int delta, - int nbAdded, - int nbRemoved, - GasConstants staticGas, - boolean twoLinesInstruction, - boolean forbiddenInStatic, - boolean addressTrimmingInstruction, - boolean oobFlag, - boolean flag1, - boolean flag2, - boolean flag3, - boolean flag4) {} 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 deleted file mode 100644 index 1284f15e0..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ /dev/null @@ -1,244 +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.runtime.callstack; - -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.module.hub.Bytecode; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.memory.MemorySpan; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.OpCodeData; -import net.consensys.linea.zktracer.opcode.OpCodes; -import net.consensys.linea.zktracer.runtime.stack.Stack; -import net.consensys.linea.zktracer.runtime.stack.StackContext; -import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.MemoryRange; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.frame.MessageFrame; - -@Accessors(fluent = true) -public class CallFrame { - public static final CallFrame EMPTY = new CallFrame(Address.ZERO); - /** 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 */ - @Getter private final int contextNumber; - /** the depth of this CallFrame within its call hierarchy. */ - @Getter private int depth; - /** */ - @Getter private int accountDeploymentNumber; - /** */ - @Getter private int codeDeploymentNumber; - /** */ - @Getter private boolean underDeployment; - - @Getter @Setter private TraceSection needsUnlatchingAtReEntry = null; - - /** the position of this {@link CallFrame} parent in the {@link CallStack}. */ - @Getter private int parentFrame; - /** all the {@link CallFrame} that have been called by this frame. */ - @Getter private final List childFrames = new ArrayList<>(); - - /** the {@link Address} of the account executing this {@link CallFrame}. */ - @Getter private final Address address; - /** 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; - /** A memoized {@link EWord} conversion of `codeAddress` */ - private EWord eCodeAddress = null; - - /** the {@link CallFrameType} of this frame. */ - @Getter private final CallFrameType type; - - /** the {@link Bytecode} executing within this frame. */ - @Getter private Bytecode code = Bytecode.EMPTY; - - @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 - /** the gas given to this frame. */ - @Getter private long gasEndowment; - - /** the call data given to this frame. */ - @Getter private Bytes callData = Bytes.EMPTY; - /** the call data span in the parent memory. */ - @Getter private final MemorySpan callDataPointer; - /** the data returned by the latest callee. */ - @Getter @Setter private Bytes returnData = Bytes.EMPTY; - /** returnData position within the latest callee memory space. */ - @Getter @Setter private MemorySpan returnDataPointer = new MemorySpan(0, 0); - /** where this frame is expected to write its returnData within its parent's memory space. */ - @Getter private final MemorySpan returnDataTarget; - - // where I should put my RETURNDATARange in my caller's RAM - @Getter private MemoryRange returnTarget; - - // where my CALLDATA is in my caller's RAM - @Getter private MemoryRange callDataRange; - - // position of the returner's RETURNDATARange in its RAM - @Getter private MemoryRange returnDataRange; - - // last called context - @Getter private int returner; - - @Getter @Setter private int selfRevertsAt = 0; - @Getter @Setter private int getsRevertedAt = 0; - - /** this frame {@link Stack}. */ - @Getter private final Stack stack = new Stack(); - - /** the latched context of this callframe stack. */ - @Getter @Setter private StackContext pending; - - /** Create a root call frame. */ - CallFrame(Address address) { - this.type = CallFrameType.BEDROCK; - this.contextNumber = 0; - this.address = address; - this.callDataPointer = new MemorySpan(0, 0); - this.returnDataTarget = new MemorySpan(0, 0); - } - - /** - * 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 address 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, - int codeDeploymentNumber, - boolean isDeployment, - int id, - int hubStamp, - Address address, - Address codeAddress, - Bytecode code, - CallFrameType type, - int caller, - Wei value, - long gas, - Bytes callData, - int depth) { - this.accountDeploymentNumber = accountDeploymentNumber; - this.codeDeploymentNumber = codeDeploymentNumber; - this.underDeployment = isDeployment; - this.id = id; - this.contextNumber = hubStamp + 1; - this.address = address; - this.codeAddress = codeAddress; - this.code = code; - this.type = type; - this.parentFrame = caller; - this.value = value; - this.gasEndowment = gas; - this.callData = callData; - this.callDataPointer = new MemorySpan(0, callData.size()); - this.depth = depth; - this.returnDataPointer = new MemorySpan(0, 0); - this.returnDataTarget = new MemorySpan(0, 0); // TODO: fix me Franklin - } - - /** - * Return the address of this CallFrame as an {@link EWord}. - * - * @return the address - */ - public EWord addressAsEWord() { - if (this.eAddress == null) { - this.eAddress = EWord.of(this.address); - } - return this.eAddress; - } - - /** - * Return the address of the code executed within this callframe as an {@link EWord}. - * - * @return the address - */ - public EWord codeAddressAsEWord() { - if (this.eCodeAddress == null) { - this.eCodeAddress = EWord.of(this.codeAddress); - } - return this.eCodeAddress; - } - - /** - * If any, returns the ID of the latest callee of this frame. - * - * @return the ID of the latest callee - */ - public Optional lastCallee() { - if (this.childFrames.isEmpty()) { - return Optional.empty(); - } - - return Optional.of(this.childFrames.get(this.childFrames.size() - 1)); - } - - private void revertChildren(CallStack callStack, int stamp) { - if (this.getsRevertedAt == 0) { - this.getsRevertedAt = stamp; - this.childFrames.stream() - .map(callStack::get) - .forEach(frame -> frame.revertChildren(callStack, stamp)); - } - } - - 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 boolean hasReverted() { - return (this.selfRevertsAt > 0) || (this.getsRevertedAt > 0); - } - - public void frame(MessageFrame frame) { - this.frame = frame; - this.opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); - this.opCodeData = OpCodes.of(this.opCode); - this.pc = frame.getPC(); - } -} 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 deleted file mode 100644 index 57b822c4e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrameType.java +++ /dev/null @@ -1,58 +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.runtime.callstack; - -import net.consensys.linea.zktracer.opcode.OpCode; - -public enum CallFrameType { - /** Executing deployment code. */ - INIT_CODE, - /** Executing standard contract. */ - STANDARD, - /** Within a delegate call. */ - DELEGATE, - /** Within a static call. */ - STATIC, - /** Within a call code. */ - CALL_CODE, - /** The bedrock context. */ - BEDROCK; - - /** - * Returns the kind of {@link CallFrameType} context that an opcode will create; throws if the - * opcode does not create a new context. - * - * @param opCode a context-changing {@link OpCode} - * @return the associated {@link CallFrameType} - */ - public CallFrameType ofOpCode(OpCode opCode) { - if (this.isStatic()) { - return STATIC; - } else { - return switch (opCode) { - case CREATE, CREATE2 -> INIT_CODE; - case DELEGATECALL -> DELEGATE; - case CALLCODE -> CALL_CODE; - case STATICCALL -> STATIC; - default -> throw new IllegalStateException(String.valueOf(opCode)); - }; - } - } - - public boolean isStatic() { - return this == STATIC; - } -} 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 deleted file mode 100644 index 62870d546..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ /dev/null @@ -1,241 +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.runtime.callstack; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import com.google.common.base.Preconditions; -import lombok.Getter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.Bytecode; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.memory.MemorySpan; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.Code; - -/** - * 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 - * representing the path from the latest leaf to the root context. - */ -@Accessors(fluent = true) -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<>(); - /** the current depth of the call stack. */ - @Getter private int depth; - /** a "pointer" to the current {@link CallFrame} in frames. */ - private int current; - - public void newBedrock( - int hubStamp, - Address from, - Address to, - CallFrameType type, - Bytecode toCode, - Wei value, - long gas, - Bytes callData, - int accountDeploymentNumber, - int codeDeploymentNumber, - boolean codeDeploymentStatus) { - this.depth = 0; - this.frames.add(new CallFrame(from)); - this.enter( - hubStamp, - to, - to, - toCode == null ? Bytecode.EMPTY : toCode, - type, - value, - gas, - callData, - accountDeploymentNumber, - codeDeploymentNumber, - codeDeploymentStatus); - this.current = this.frames.size() - 1; - } - - /** - * @return the currently executing {@link CallFrame} - */ - public CallFrame current() { - return this.frames.get(this.current); - } - - public boolean isEmpty() { - return this.frames.isEmpty(); - } - - public int futureId() { - return this.frames.size(); - } - - /** - * @return the parent {@link CallFrame} of the current frame - */ - public CallFrame parent() { - return this.frames.get(this.current().parentFrame()); - } - - public Optional maybeCurrent() { - return this.frames.isEmpty() ? Optional.empty() : Optional.of(this.current()); - } - - /** - * 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 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 - */ - public void enter( - int hubStamp, - Address address, - Address codeAddress, - Bytecode code, - CallFrameType type, - Wei value, - long gas, - Bytes input, - int accountDeploymentNumber, - int codeDeploymentNumber, - boolean isDeployment) { - final int caller = this.current; - final int newTop = this.frames.size(); - Bytes callData; - if (type != CallFrameType.INIT_CODE) { - callData = input; - } else { - callData = Bytes.EMPTY; - } - - this.depth += 1; - CallFrame newFrame = - new CallFrame( - accountDeploymentNumber, - codeDeploymentNumber, - isDeployment, - newTop, - hubStamp, - address, - codeAddress, - code, - type, - caller, - value, - gas, - callData, - this.depth); - - this.frames.add(newFrame); - this.current = newTop; - this.frames.get(caller).childFrames().add(newTop); - } - - /** - * Exit the current context, sets it return data for the caller to read, and marks its last - * position in the hub traces. - * - * @param returnData the return data of the current frame - */ - public void exit(Bytes returnData) { - this.depth -= 1; - Preconditions.checkState(this.depth >= 0); - this.current().returnDataPointer(new MemorySpan(0, 0)); // TODO: fix me Franklin - final int parent = this.current().parentFrame(); - this.frames.get(parent).childFrames().add(this.current); - this.frames.get(parent).returnData(returnData); - this.current = parent; - } - - /** - * @return whether the call stack is in an overflow state - */ - public boolean isOverflow() { - return this.depth > MAX_CALLSTACK_SIZE; - } - - /** - * @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; - } - - /** - * @return whether the current frame is a static context - */ - public boolean isStatic() { - return this.current().type() == CallFrameType.STATIC; - } - - /** - * Get the {@link CallFrame} representing the caller of the current frame - * - * @return the caller of the current frame - */ - public CallFrame caller() { - return this.frames.get(this.current().parentFrame()); - } - - /** - * Returns the ith {@link CallFrame} in this call stack. - * - * @param i ID of the call frame to fetch - * @return the ith call frame - * @throws IndexOutOfBoundsException if the index is out of range - */ - public CallFrame get(int i) { - // The case where the CF #0 is called on an empty stack stems from a skipped - // transaction, where - // no CF of interest is available to trace. - // TODO: use an explicit -1 as marker - if (i == 0 && this.frames.isEmpty()) { - return CallFrame.EMPTY; - } - return this.frames.get(i); - } - - /** - * Returns the parent of the ith {@link CallFrame} in this call stack. - * - * @param i 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) { - return this.get(this.frames.get(i).parentFrame()); - } - - public void revert(int stamp) { - this.current().revert(this, stamp); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Action.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Action.java deleted file mode 100644 index 5b1be2c02..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Action.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.runtime.stack; - -public enum Action { - NONE, - PUSH, - POP -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/ConflationInfo.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/ConflationInfo.java deleted file mode 100644 index 9f09aaee9..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/ConflationInfo.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.runtime.stack; - -import lombok.Getter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.DeploymentInfo; - -/** Stores data relative to the conflation. */ -@Accessors(fluent = true) -@Getter -public class ConflationInfo { - private int number = 0; - private DeploymentInfo deploymentInfo; - - public void update() { - this.number++; - this.deploymentInfo = new DeploymentInfo(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/IndexedStackOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/IndexedStackOperation.java deleted file mode 100644 index 4a529f8e1..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/IndexedStackOperation.java +++ /dev/null @@ -1,35 +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.runtime.stack; - -/** - * An operation within a {@link StackLine}. This structure is useful because stack lines may be - * sparse. - * - * @param i the index of the stack item within a stack line -- within [[1, 4] - * @param it the details of the {@link StackOperation} to apply to a column of a stack line - */ -record IndexedStackOperation(int i, StackOperation it) { - /** - * For the sake of homogeneity with the zkEVM spec, {@param i} is set with 1-based indices. - * However, these indices are used to index 0-based array; hence this sneaky conversion. - * - * @return the actual stack operation index - */ - public int i() { - return this.i - 1; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Stack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Stack.java deleted file mode 100644 index 69b8267a6..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Stack.java +++ /dev/null @@ -1,371 +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.runtime.stack; - -import lombok.Getter; -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; - -public class Stack { - public static final int MAX_STACK_SIZE = 1024; - - @Getter int height; - @Getter int heightNew; - @Getter OpCodeData currentOpcodeData; - Status status; - int stamp; - - public Stack() { - this.height = 0; - this.heightNew = 0; - this.status = Status.NORMAL; - } - - public Stack snapshot() { - var r = new Stack(); - r.height = this.height; - r.heightNew = this.heightNew; - r.currentOpcodeData = this.currentOpcodeData; - r.status = this.status; - - return r; - } - - 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))); - } - - private void twoZero(MessageFrame frame, StackContext pending) { - Bytes val1 = getStack(frame, 0); - 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))); - } - - private void zeroOne(MessageFrame ignoredFrame, StackContext pending) { - pending.addArmingLine( - new IndexedStackOperation(4, StackOperation.push(this.height + 1, this.stamp))); - } - - 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))); - } - - private void twoOne(MessageFrame frame, StackContext pending) { - Bytes val1 = getStack(frame, 0); - 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))); - } - - private void threeOne(MessageFrame frame, StackContext pending) { - Bytes val1 = getStack(frame, 0); - Bytes val2 = getStack(frame, 1); - 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))); - } - - private void loadStore(MessageFrame frame, StackContext pending) { - if (this.currentOpcodeData.stackSettings().flag3() - || this.currentOpcodeData.stackSettings().flag4()) { - 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))); - } 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))); - } - } - - private void dup(MessageFrame frame, StackContext pending) { - int depth = this.currentOpcodeData.stackSettings().delta() - 1; - 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))); - } - - private void swap(MessageFrame frame, StackContext pending) { - int depth = this.currentOpcodeData.stackSettings().delta() - 1; - Bytes val1 = getStack(frame, 0); - 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))); - } - - private void log(MessageFrame frame, StackContext pending) { - Bytes offset = getStack(frame, 0); - Bytes size = getStack(frame, 1); - - // 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))); - - // Stack line 2 - IndexedStackOperation[] line2 = new IndexedStackOperation[] {}; - switch (this.currentOpcodeData.mnemonic()) { - case LOG0 -> {} - case LOG1 -> { - Bytes topic1 = getStack(frame, 2); - - line2 = - new IndexedStackOperation[] { - new IndexedStackOperation( - 1, StackOperation.pop(this.height - 2, topic1, this.stamp + 2)), - }; - } - case LOG2 -> { - Bytes topic1 = getStack(frame, 2); - Bytes topic2 = getStack(frame, 3); - - 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)), - }; - } - case LOG3 -> { - Bytes topic1 = getStack(frame, 2); - Bytes topic2 = getStack(frame, 3); - Bytes topic3 = getStack(frame, 4); - - 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)), - }; - } - case LOG4 -> { - Bytes topic1 = getStack(frame, 2); - Bytes topic2 = getStack(frame, 3); - Bytes topic3 = getStack(frame, 4); - Bytes topic4 = getStack(frame, 5); - - 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)), - }; - } - default -> throw new RuntimeException("not a LOGx"); - } - pending.addLine(line2); - } - - private void copy(MessageFrame frame, StackContext pending) { - if (this.currentOpcodeData.stackSettings().addressTrimmingInstruction()) { - Bytes val0 = getStack(frame, 0); - Bytes val1 = getStack(frame, 1); - Bytes val2 = getStack(frame, 2); - 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(4, StackOperation.pop(this.height, val0, this.stamp))); - } else { - Bytes val1 = getStack(frame, 0); - Bytes val2 = getStack(frame, 2); - 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))); - } - } - - private void call(MessageFrame frame, StackContext pending) { - Bytes val1 = getStack(frame, 0); - Bytes val2 = getStack(frame, 1); - Bytes val3 = getStack(frame, 2); - Bytes val4 = getStack(frame, 3); - Bytes val5 = getStack(frame, 4); - Bytes val6 = getStack(frame, 5); - - boolean sevenItems = - this.currentOpcodeData.stackSettings().flag1() - || this.currentOpcodeData.stackSettings().flag2(); - if (sevenItems) { - 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))); - 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))); - } 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))); - - 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))); - } - } - - private void create(MessageFrame frame, StackContext pending) { - Bytes val1 = getStack(frame, 1); - 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))); - 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))); - } 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))); - } - } - - /** - * @return true if no stack exception has been raised - */ - public boolean isOk() { - return this.status == Status.NORMAL; - } - - /** - * @return true if a stack underflow exception has been raised - */ - public boolean isUnderflow() { - return this.status == Status.UNDERFLOW; - } - - /** - * @return true if a stack underflow exception has been raised - */ - public boolean isOverflow() { - return this.status == Status.OVERFLOW; - } - - public void processInstruction(MessageFrame frame, CallFrame callFrame, int stackStamp) { - this.stamp = stackStamp; - this.height = this.heightNew; - this.currentOpcodeData = callFrame.opCodeData(); - callFrame.pending(new StackContext(this.currentOpcodeData.mnemonic())); - - this.heightNew += this.currentOpcodeData.stackSettings().nbAdded(); - this.heightNew -= this.currentOpcodeData.stackSettings().nbRemoved(); - - if (frame.stackSize() - < this.currentOpcodeData.stackSettings().delta()) { // Testing for underflow - this.status = Status.UNDERFLOW; - } else if (this.heightNew > MAX_STACK_SIZE) { // Testing for overflow - this.status = Status.OVERFLOW; - } - - if (this.status.isFailure()) { - this.heightNew = 0; - - if (this.currentOpcodeData.stackSettings().twoLinesInstruction()) { - this.stamp += callFrame.pending().addEmptyLines(2); - } else { - this.stamp += callFrame.pending().addEmptyLines(1); - } - - return; - } - - switch (this.currentOpcodeData.stackSettings().pattern()) { - case ZERO_ZERO -> this.stamp += callFrame.pending().addEmptyLines(1); - case ONE_ZERO -> this.oneZero(frame, callFrame.pending()); - case TWO_ZERO -> this.twoZero(frame, callFrame.pending()); - case ZERO_ONE -> this.zeroOne(frame, callFrame.pending()); - case ONE_ONE -> this.oneOne(frame, callFrame.pending()); - case TWO_ONE -> this.twoOne(frame, callFrame.pending()); - case THREE_ONE -> this.threeOne(frame, callFrame.pending()); - case LOAD_STORE -> this.loadStore(frame, callFrame.pending()); - case DUP -> this.dup(frame, callFrame.pending()); - case SWAP -> this.swap(frame, callFrame.pending()); - case LOG -> this.log(frame, callFrame.pending()); - case COPY -> this.copy(frame, callFrame.pending()); - case CALL -> this.call(frame, callFrame.pending()); - case CREATE -> this.create(frame, callFrame.pending()); - } - } -} 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 deleted file mode 100644 index 1acc8bb47..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackContext.java +++ /dev/null @@ -1,90 +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.runtime.stack; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import lombok.Getter; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.runtime.callstack.CallFrame; - -/** - * A StackContext encode the stack-related information pertaining to the execution of an opcode - * within a {@link CallFrame}. These cached information are used by the {@link Hub} to generate its - * traces in the stack perspective. - */ -public final class StackContext { - /** The opcode that triggered the stack operations. */ - OpCode opCode; - /** One or two lines to be traced, representing the stack operations performed by the opcode. */ - @Getter final List lines = new ArrayList<>(4); - - /** - * The default constructor for a valid, albeit empty line. - * - * @param opCode the {@link OpCode} triggering the lines creation - */ - StackContext(OpCode opCode) { - this.opCode = opCode; - } - - /** - * Generate a given number of empty stack lines; typically used as valid padding in the case of - * stack exception. - * - * @param k the number of empty lines to generate - * @return the number of empty lines generated - */ - int addEmptyLines(int k) { - for (int i = 0; i < k; i++) { - this.lines.add(new StackLine()); - } - return k; - } - - /** - * Creates a new stack lint that will not require unlatching, either because no value are pushed - * or because they are already known. - * - * @param items the stack operations to execute - */ - void addLine(IndexedStackOperation... items) { - int newPos = this.lines.size(); - this.lines.add(new StackLine(newPos, items)); - } - - /** - * Creates a new stack line that will require unlatching. - * - * @param posResult in which stack item the result shall be unlatched - * @param items the stack operations to execute - */ - void addArmingLine(int posResult, IndexedStackOperation... items) { - this.lines.add(new StackLine(Arrays.stream(items).toList(), posResult)); - } - - /** - * As virtually all latched stack operations write to item #4, this provides a shortcut for it. - * - * @param items the stack operations to execute - */ - void addArmingLine(IndexedStackOperation... items) { - this.addArmingLine(4, items); - } -} 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 deleted file mode 100644 index 86ba10c73..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackLine.java +++ /dev/null @@ -1,113 +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.runtime.stack; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import lombok.Getter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.Hub; -import org.apache.tuweni.bytes.Bytes; - -/** - * As the zkEVM spec can only handle up to four stack operations per trace line of the {@link Hub}, - * operations on the stack must be decomposed in “lines” (mapping 1-to-1 with a trace line from the - * hub, hence the name) of zero to four atomic {@link StackOperation}. - */ -@Accessors(fluent = true) -public final class StackLine { - private final List items; - @Getter private final int resultColumn; - - /** - * @param items zero to four stack operations contained within this line - * @param resultColumn if positive, in which item to store the expected retroactive result - */ - public StackLine(List items, int resultColumn) { - this.items = items; - this.resultColumn = resultColumn; - } - - /** The default constructor, an empty stack line. */ - public StackLine() { - this(new ArrayList<>(4), -1); - } - - /** - * Build a stack line from a set of {@link StackOperation}. - * - * @param ct the index of this line within the parent {@link StackContext} - * @param items the {@link IndexedStackOperation} to include in this line - */ - StackLine(int ct, IndexedStackOperation... items) { - this.items = Arrays.asList(items); - this.resultColumn = -1; - } - - /** - * @return a consolidated 4-elements array of the {@link StackOperation} – or no-ops - */ - public List asStackOperations() { - StackOperation[] r = - new StackOperation[] { - new StackOperation(), new StackOperation(), new StackOperation(), new StackOperation() - }; - for (IndexedStackOperation item : this.items) { - r[item.i()] = item.it(); - } - return Arrays.asList(r); - } - - /** - * Sets the value of a stack item in the line. Used to retroactively set the value of push {@link - * Action} during the unlatching process. - * - * @param i the 1-based stack item to alter - * @param value the {@link Bytes} to use - */ - public void setResult(int i, Bytes value) { - for (var item : this.items) { - if (item.i() == i - 1) { - item.it().setValue(value); - return; - } - } - - throw new RuntimeException(String.format("Item #%s not found in stack line", i)); - } - - /** - * Sets the value of stack item resultColumn. Used to retroactively set the value of - * push {@link Action} during the unlatching process. - * - * @param value the {@link Bytes} to use - */ - public void setResult(Bytes value) { - if (this.resultColumn == -1) { - throw new RuntimeException("Stack line has no result column"); - } - this.setResult(this.resultColumn, value); - } - - /** - * @return whether an item in this stack line requires a retroactively set value. - */ - public boolean needsResult() { - return this.resultColumn >= 0; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackOperation.java deleted file mode 100644 index b93503600..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackOperation.java +++ /dev/null @@ -1,91 +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.runtime.stack; - -import org.apache.tuweni.bytes.Bytes; - -/** - * An atomic operation (read/pop or write/push) on the stack, indexed within a {@link - * IndexedStackOperation}. - * - *

Alterations of the stack by an EVM instruction are decomposed in one or two chunks, or {@link - * StackLine}, made of {@link IndexedStackOperation}, which are then stored, with the associated - * metadata, in a {@link StackContext}. - */ -public final class StackOperation { - private static final Bytes MARKER = Bytes.fromHexString("0xDEADBEEF"); - /** - * The relative height of the element with regard to the stack height just before executing the - * linked EVM instruction. - */ - private final int height; - /** The value having been popped from/pushed on the stack. */ - private Bytes value; - /** whether this action is a push or a pop. */ - private final Action action; - /** - * The stamp of this operation relative to the stack stamp before executing the linked EVM - * instruction. - */ - private final int stackStamp; - - StackOperation() { - this.height = 0; - this.value = Bytes.EMPTY; - this.action = Action.NONE; - this.stackStamp = 0; - } - - StackOperation(int height, Bytes value, Action action, int stackStamp) { - this.height = height; - this.value = value; - this.action = action; - this.stackStamp = stackStamp; - } - - public static StackOperation pop(int height, Bytes value, int stackStamp) { - return new StackOperation(height, value, Action.POP, stackStamp); - } - - public static StackOperation push(int height, int stackStamp) { - return new StackOperation( - height, MARKER /* marker value, erased on unlatching */, Action.PUSH, stackStamp); - } - - public static StackOperation pushImmediate(int height, Bytes val, int stackStamp) { - return new StackOperation(height, val.copy(), Action.PUSH, stackStamp); - } - - public void setValue(Bytes x) { - this.value = x; - } - - public int height() { - return height; - } - - public Bytes value() { - return value; - } - - public Action action() { - return action; - } - - public int stackStamp() { - return stackStamp; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Status.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Status.java deleted file mode 100644 index 0733056a3..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Status.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.runtime.stack; - -enum Status { - NORMAL, - UNDERFLOW, - OVERFLOW; - - boolean isFailure() { - return this != Status.NORMAL; - } -} 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 deleted file mode 100644 index f088a4562..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java +++ /dev/null @@ -1,77 +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 static org.hyperledger.besu.evm.internal.Words.clampedToLong; - -import java.util.List; - -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; -import org.hyperledger.besu.evm.frame.MessageFrame; - -public class AddressUtils { - private static final List

precompileAddress = - List.of( - Address.ECREC, - Address.SHA256, - Address.RIPEMD160, - Address.ID, - Address.MODEXP, - Address.ALTBN128_ADD, - Address.ALTBN128_MUL, - Address.ALTBN128_PAIRING, - Address.BLAKE2B_F_COMPRESSION); - - public static boolean isPrecompile(Address to) { - return precompileAddress.contains(to); - } - - public static Address getCreateAddress(final MessageFrame frame) { - if (!OpCode.of(frame.getCurrentOperation().getOpcode()).equals(OpCode.CREATE)) { - throw new IllegalArgumentException("Must be called only for CREATE opcode"); - } - final Address currentAddress = frame.getRecipientAddress(); - return Address.contractAddress( - currentAddress, frame.getWorldUpdater().get(currentAddress).getNonce()); - } - - public static Address getCreate2Address(final MessageFrame frame) { - if (!OpCode.of(frame.getCurrentOperation().getOpcode()).equals(OpCode.CREATE2)) { - throw new IllegalArgumentException("Must be called only for CREATE2 opcode"); - } - 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); - Bytes PREFIX = Bytes.fromHexString("0xff"); - final Bytes32 hash = - Hash.keccak256(Bytes.concatenate(PREFIX, sender, salt, Hash.keccak256(initCode))); - return Address.extract(hash); - } - - 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"); - } - return opcode.equals(OpCode.CREATE) ? getCreateAddress(frame) : getCreate2Address(frame); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/ArrayWrappingBytes.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/ArrayWrappingBytes.java deleted file mode 100644 index aeb091659..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/ArrayWrappingBytes.java +++ /dev/null @@ -1,171 +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 java.nio.ByteBuffer; -import java.security.MessageDigest; -import java.util.Arrays; - -import io.vertx.core.buffer.Buffer; -import org.apache.tuweni.bytes.AbstractBytes; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.MutableBytes; -import org.jetbrains.annotations.NotNull; - -class ArrayWrappingBytes extends AbstractBytes { - - protected final byte[] bytes; - protected final int offset; - protected final int length; - - ArrayWrappingBytes(byte[] bytes) { - this(bytes, 0, bytes.length); - } - - ArrayWrappingBytes(byte[] bytes, int offset, int length) { - Checks.checkArgument(length >= 0, "Invalid negative length"); - if (bytes.length > 0) { - Checks.checkElementIndex(offset, bytes.length); - } - Checks.checkArgument( - offset + length <= bytes.length, - "Provided length %s is too big: the value has only %s bytes from offset %s", - length, - bytes.length - offset, - offset); - - this.bytes = bytes; - this.offset = offset; - this.length = length; - } - - @Override - public int size() { - return length; - } - - @Override - public byte get(int i) { - // Check bounds because while the array access would throw, the error message - // would be confusing - // for the caller. - Checks.checkElementIndex(i, size()); - return bytes[offset + i]; - } - - @Override - public Bytes slice(int i, int length) { - if (i == 0 && length == this.length) { - return this; - } - if (length == 0) { - return Bytes.EMPTY; - } - - Checks.checkElementIndex(i, this.length); - Checks.checkArgument( - i + length <= this.length, - "Provided length %s is too big: the value has size %s and has only %s bytes from %s", - length, - this.length, - this.length - i, - i); - - return length == Bytes16.SIZE - ? new ArrayWrappingBytes16(bytes, offset + i) - : new ArrayWrappingBytes(bytes, offset + i, length); - } - - // MUST be overridden by mutable implementations - @Override - public Bytes copy() { - if (offset == 0 && length == bytes.length) { - return this; - } - return new ArrayWrappingBytes(toArray()); - } - - @Override - public MutableBytes mutableCopy() { - return new MutableArrayWrappingBytes(toArray()); - } - - @Override - public int commonPrefixLength(@NotNull Bytes other) { - if (!(other instanceof ArrayWrappingBytes o)) { - return super.commonPrefixLength(other); - } - - int i = 0; - while (i < length && i < o.length && bytes[offset + i] == o.bytes[o.offset + i]) { - i++; - } - - return i; - } - - @Override - public void update(MessageDigest digest) { - digest.update(bytes, offset, length); - } - - @Override - public void copyTo(@NotNull MutableBytes destination, int destinationOffset) { - if (!(destination instanceof MutableArrayWrappingBytes d)) { - super.copyTo(destination, destinationOffset); - return; - } - - int size = size(); - if (size == 0) { - return; - } - - Checks.checkElementIndex(destinationOffset, destination.size()); - Checks.checkArgument( - destination.size() - destinationOffset >= size, - "Cannot copy %s bytes, destination has only %s bytes from index %s", - size, - destination.size() - destinationOffset, - destinationOffset); - - System.arraycopy(bytes, offset, d.bytes, d.offset + destinationOffset, size); - } - - @Override - public void appendTo(ByteBuffer byteBuffer) { - byteBuffer.put(bytes, offset, length); - } - - @Override - public void appendTo(Buffer buffer) { - buffer.appendBytes(bytes, offset, length); - } - - @Override - public byte[] toArray() { - return Arrays.copyOfRange(bytes, offset, offset + length); - } - - @Override - public byte[] toArrayUnsafe() { - if (offset == 0 && length == bytes.length) { - return bytes; - } - - return toArray(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/ArrayWrappingBytes16.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/ArrayWrappingBytes16.java deleted file mode 100644 index 81c1eeab9..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/ArrayWrappingBytes16.java +++ /dev/null @@ -1,57 +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; - -final class ArrayWrappingBytes16 extends ArrayWrappingBytes implements Bytes16 { - - ArrayWrappingBytes16(byte[] bytes) { - this(checkLength(bytes), 0); - } - - ArrayWrappingBytes16(byte[] bytes, int offset) { - super(checkLength(bytes, offset), offset, SIZE); - } - - // Ensures a proper error message. - private static byte[] checkLength(byte[] bytes) { - Checks.checkArgument(bytes.length == SIZE, "Expected %s bytes but got %s", SIZE, bytes.length); - return bytes; - } - - // Ensures a proper error message. - private static byte[] checkLength(byte[] bytes, int offset) { - Checks.checkArgument( - bytes.length - offset >= SIZE, - "Expected at least %s bytes from offset %s but got only %s", - SIZE, - offset, - bytes.length - offset); - return bytes; - } - - @Override - public Bytes16 copy() { - if (offset == 0 && length == bytes.length) { - return this; - } - return new ArrayWrappingBytes16(toArray()); - } - - @Override - public MutableBytes16 mutableCopy() { - return new MutableArrayWrappingBytes16(toArray()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/BitDecOutput.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/BitDecOutput.java deleted file mode 100644 index 293cf7438..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/BitDecOutput.java +++ /dev/null @@ -1,20 +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.types; - -import java.util.List; - -public record BitDecOutput(List bitDecList, List bitAccList) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Bytes16.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Bytes16.java deleted file mode 100644 index ece70dcb7..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Bytes16.java +++ /dev/null @@ -1,278 +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 java.security.SecureRandom; -import java.util.Random; - -import org.apache.tuweni.bytes.Bytes; - -/** A {@link Bytes} value that is guaranteed to contain exactly 16 bytes. */ -public interface Bytes16 extends Bytes { - /** The number of bytes in this value - i.e. 16 */ - int SIZE = 16; - - /** A {@link Bytes16} containing all zero bytes. */ - Bytes16 ZERO = wrap(new byte[SIZE]); - - /** - * Wrap the provided byte array, which must be of length 16, as a {@link Bytes16}. - * - *

Note that value is not copied, only wrapped, and thus any future update to {@code value} - * will be reflected in the returned value. - * - * @param bytes The bytes to wrap. - * @return A {@link Bytes16} wrapping {@code value}. - * @throws IllegalArgumentException if {@code value.length != 16}. - */ - static Bytes16 wrap(byte[] bytes) { - Checks.checkNotNull(bytes); - Checks.checkArgument(bytes.length == SIZE, "Expected %s bytes but got %s", SIZE, bytes.length); - return wrap(bytes, 0); - } - - /** - * Wrap a slice/sub-part of the provided array as a {@link Bytes16}. - * - *

Note that value is not copied, only wrapped, and thus any future update to {@code value} - * within the wrapped parts will be reflected in the returned value. - * - * @param bytes The bytes to wrap. - * @param offset The index (inclusive) in {@code value} of the first byte exposed by the returned - * value. In other words, you will have {@code wrap(value, i).get(0) == value[i]}. - * @return A {@link Bytes16} that exposes the bytes of {@code value} from {@code offset} - * (inclusive) to {@code offset + 16} (exclusive). - * @throws IndexOutOfBoundsException if {@code offset < 0 || (value.length > 0 && offset >= - * value.length)}. - * @throws IllegalArgumentException if {@code length < 0 || offset + 16 > value.length}. - */ - static Bytes16 wrap(byte[] bytes, int offset) { - Checks.checkNotNull(bytes); - return new ArrayWrappingBytes16(bytes, offset); - } - - /** - * Wrap the provided value, which must be of size 16, as a {@link Bytes16}. - * - *

Note that value is not copied, only wrapped, and thus any future update to {@code value} - * will be reflected in the returned value. - * - * @param value The bytes to wrap. - * @return A {@link Bytes16} that exposes the bytes of {@code value}. - * @throws IllegalArgumentException if {@code value.size() != 16}. - */ - static Bytes16 wrap(Bytes value) { - Checks.checkNotNull(value); - if (value instanceof Bytes16) { - return (Bytes16) value; - } - Checks.checkArgument(value.size() == SIZE, "Expected %s bytes but got %s", SIZE, value.size()); - return new DelegatingBytes16(value); - } - - /** - * Wrap a slice/sub-part of the provided value as a {@link Bytes16}. - * - *

Note that value is not copied, only wrapped, and thus any future update to {@code value} - * within the wrapped parts will be reflected in the returned value. - * - * @param value The bytes to wrap. - * @param offset The index (inclusive) in {@code value} of the first byte exposed by the returned - * value. In other words, you will have {@code wrap(value, i).get(0) == value.get(i)}. - * @return A {@link Bytes16} that exposes the bytes of {@code value} from {@code offset} - * (inclusive) to {@code offset + 16} (exclusive). - * @throws IndexOutOfBoundsException if {@code offset < 0 || (value.size() > 0 && offset >= - * value.size())}. - * @throws IllegalArgumentException if {@code length < 0 || offset + 16 > value.size()}. - */ - static Bytes16 wrap(Bytes value, int offset) { - Checks.checkNotNull(value); - if (value instanceof Bytes16) { - return (Bytes16) value; - } - Bytes slice = value.slice(offset, Bytes16.SIZE); - if (slice instanceof Bytes16) { - return (Bytes16) slice; - } - return new DelegatingBytes16(Bytes16.wrap(slice)); - } - - /** - * Left pad a {@link Bytes} value with zero bytes to create a {@link Bytes16}. - * - * @param value The bytes value pad. - * @return A {@link Bytes16} that exposes the left-padded bytes of {@code value}. - * @throws IllegalArgumentException if {@code value.size() > 16}. - */ - static Bytes16 leftPad(Bytes value) { - Checks.checkNotNull(value); - if (value instanceof Bytes16) { - return (Bytes16) value; - } - Checks.checkArgument( - value.size() <= SIZE, "Expected at most %s bytes but got %s", SIZE, value.size()); - MutableBytes16 result = MutableBytes16.create(); - value.copyTo(result, SIZE - value.size()); - return result; - } - - /** - * Right pad a {@link Bytes} value with zero bytes to create a {@link Bytes16}. - * - * @param value The bytes value pad. - * @return A {@link Bytes16} that exposes the right-padded bytes of {@code value}. - * @throws IllegalArgumentException if {@code value.size() > 16}. - */ - static Bytes16 rightPad(Bytes value) { - Checks.checkNotNull(value); - if (value instanceof Bytes16) { - return (Bytes16) value; - } - Checks.checkArgument( - value.size() <= SIZE, "Expected at most %s bytes but got %s", SIZE, value.size()); - MutableBytes16 result = MutableBytes16.create(); - value.copyTo(result, 0); - return result; - } - - /** - * Parse a hexadecimal string into a {@link Bytes16}. - * - *

This method is lenient in that {@code str} may of an odd length, in which case it will - * behave exactly as if it had an additional 0 in front. - * - * @param str The hexadecimal string to parse, which may or may not start with "0x". That - * representation may contain less than 16 bytes, in which case the result is left padded with - * zeros (see {@link #fromHexStringStrict} if this is not what you want). - * @return The value corresponding to {@code str}. - * @throws IllegalArgumentException if {@code str} does not correspond to a valid hexadecimal - * representation or contains more than 16 bytes. - */ - static Bytes16 fromHexStringLenient(CharSequence str) { - Checks.checkNotNull(str); - return wrap(BytesValues.fromRawHexString(str, SIZE, true)); - } - - /** - * Parse a hexadecimal string into a {@link Bytes16}. - * - *

This method is strict in that {@code str} must of an even length. - * - * @param str The hexadecimal string to parse, which may or may not start with "0x". That - * representation may contain less than 16 bytes, in which case the result is left padded with - * zeros (see {@link #fromHexStringStrict} if this is not what you want). - * @return The value corresponding to {@code str}. - * @throws IllegalArgumentException if {@code str} does not correspond to a valid hexadecimal - * representation, is of an odd length, or contains more than 16 bytes. - */ - static Bytes16 fromHexString(CharSequence str) { - Checks.checkNotNull(str); - return wrap(BytesValues.fromRawHexString(str, SIZE, false)); - } - - /** - * Generate random bytes. - * - * @return A value containing random bytes. - */ - static Bytes16 random() { - return random(new SecureRandom()); - } - - /** - * Generate random bytes. - * - * @param generator The generator for random bytes. - * @return A value containing random bytes. - */ - static Bytes16 random(Random generator) { - byte[] array = new byte[16]; - generator.nextBytes(array); - return wrap(array); - } - - /** - * Parse a hexadecimal string into a {@link Bytes16}. - * - *

This method is extra strict in that {@code str} must have an even length and the provided - * representation must have exactly 16 bytes. - * - * @param str The hexadecimal string to parse, which may or may not start with "0x". - * @return The value corresponding to {@code str}. - * @throws IllegalArgumentException if {@code str} does not correspond to a valid hexadecimal - * representation, is of an odd length or does not contain exactly 16 bytes. - */ - static Bytes16 fromHexStringStrict(CharSequence str) { - Checks.checkNotNull(str); - return wrap(BytesValues.fromRawHexString(str, -1, false)); - } - - @Override - default int size() { - return SIZE; - } - - /** - * Return a bit-wise AND of these bytes and the supplied bytes. - * - * @param other The bytes to perform the operation with. - * @return The result of a bit-wise AND. - */ - default Bytes16 and(Bytes16 other) { - return and(other, MutableBytes16.create()); - } - - /** - * Return a bit-wise OR of these bytes and the supplied bytes. - * - * @param other The bytes to perform the operation with. - * @return The result of a bit-wise OR. - */ - default Bytes16 or(Bytes16 other) { - return or(other, MutableBytes16.create()); - } - - /** - * Return a bit-wise XOR of these bytes and the supplied bytes. - * - * @param other The bytes to perform the operation with. - * @return The result of a bit-wise XOR. - */ - default Bytes16 xor(Bytes16 other) { - return xor(other, MutableBytes16.create()); - } - - @Override - default Bytes16 not() { - return not(MutableBytes16.create()); - } - - @Override - default Bytes16 shiftRight(int distance) { - return shiftRight(distance, MutableBytes16.create()); - } - - @Override - default Bytes16 shiftLeft(int distance) { - return shiftLeft(distance, MutableBytes16.create()); - } - - @Override - Bytes16 copy(); - - @Override - MutableBytes16 mutableCopy(); -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/BytesValues.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/BytesValues.java deleted file mode 100644 index cc0f7a01a..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/BytesValues.java +++ /dev/null @@ -1,85 +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 org.apache.tuweni.bytes.Bytes; - -final class BytesValues { - private BytesValues() {} - - static final int MAX_UNSIGNED_SHORT = (1 << 16) - 1; - static final long MAX_UNSIGNED_INT = (1L << 32) - 1; - static final long MAX_UNSIGNED_LONG = Long.MAX_VALUE; - - static Bytes fromHexString(CharSequence str, int destSize, boolean lenient) { - return Bytes.wrap(fromRawHexString(str, destSize, lenient)); - } - - static byte[] fromRawHexString(CharSequence str, int destSize, boolean lenient) { - int len = str.length(); - CharSequence hex = str; - if (len >= 2 && str.charAt(0) == '0' && str.charAt(1) == 'x') { - hex = str.subSequence(2, len); - len -= 2; - } - - int idxShift = 0; - if ((len & 0x01) != 0) { - if (!lenient) { - throw new IllegalArgumentException("Invalid odd-length hex binary representation"); - } - - hex = "0" + hex; - len += 1; - idxShift = 1; - } - - int size = len >> 1; - if (destSize < 0) { - destSize = size; - } else { - Checks.checkArgument( - size <= destSize, - "Hex value is too large: expected at most %s bytes but got %s", - destSize, - size); - } - - byte[] out = new byte[destSize]; - - int destOffset = (destSize - size); - for (int i = destOffset, j = 0; j < len; i++) { - int h = Character.digit(hex.charAt(j), 16); - if (h == -1) { - throw new IllegalArgumentException( - String.format( - "Illegal character '%c' found at index %d in hex binary representation", - hex.charAt(j), j - idxShift)); - } - j++; - int l = Character.digit(hex.charAt(j), 16); - if (l == -1) { - throw new IllegalArgumentException( - String.format( - "Illegal character '%c' found at index %d in hex binary representation", - hex.charAt(j), j - idxShift)); - } - j++; - out[i] = (byte) ((h << 4) + l); - } - return out; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Checks.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Checks.java deleted file mode 100644 index 543b736d9..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Checks.java +++ /dev/null @@ -1,41 +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 javax.annotation.Nullable; - -import com.google.errorprone.annotations.FormatMethod; - -class Checks { - static void checkNotNull(@Nullable Object object) { - if (object == null) { - throw new NullPointerException("argument cannot be null"); - } - } - - static void checkElementIndex(int index, int size) { - if (index < 0 || index >= size) { - throw new IndexOutOfBoundsException("index is out of bounds"); - } - } - - @FormatMethod - static void checkArgument(boolean condition, String message, Object... args) { - if (!condition) { - throw new IllegalArgumentException(String.format(message, args)); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Containers.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Containers.java deleted file mode 100644 index 43a012abc..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Containers.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 java.util.ArrayList; -import java.util.List; - -public class Containers { - /** - * @param elt the element to fill the list with - * @param count number of element to fill the list with - * @return a {@link List} filled with count × elt - */ - public static List repeat(T elt, int count) { - final List r = new ArrayList<>(count); - for (int i = 0; i < count; i++) { - r.add(elt); - } - return r; - } -} 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 deleted file mode 100644 index ed3ecbdde..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java +++ /dev/null @@ -1,93 +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 java.math.BigInteger; -import java.util.Arrays; -import java.util.stream.IntStream; - -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; - -public class Conversions { - public static final BigInteger UNSIGNED_LONG_MASK = - BigInteger.ONE.shiftLeft(Long.SIZE).subtract(BigInteger.ONE); - - public static Bytes bigIntegerToBytes(final BigInteger input) { - Bytes bytes; - if (input.equals(BigInteger.ZERO)) { - bytes = Bytes.of(0x00); - } else { - byte[] byteArray = input.toByteArray(); - if (byteArray[0] == 0) { - Bytes tmp = Bytes.wrap(byteArray); - bytes = Bytes.wrap(tmp.slice(1, tmp.size() - 1)); - } else { - bytes = Bytes.wrap(byteArray); - } - } - - return bytes; - } - - public static BigInteger unsignedBytesToUnsignedBigInteger(final UnsignedByte[] input) { - return Bytes.concatenate(Arrays.stream(input).map(i -> Bytes.of(i.toInteger())).toList()) - .toUnsignedBigInteger(); - } - - public static EWord unsignedBytesToEWord(final UnsignedByte[] input) { - return EWord.of(unsignedBytesToUnsignedBigInteger(input)); - } - - public static UnsignedByte[] bytesToUnsignedBytes(final byte[] bytes) { - return (UnsignedByte[]) - IntStream.range(0, bytes.length).mapToObj(i -> UnsignedByte.of(bytes[i])).toArray(); - } - - public static BigInteger booleanToBigInteger(final boolean input) { - return input ? BigInteger.ONE : BigInteger.ZERO; - } - - public static BigInteger longToUnsignedBigInteger(final long input) { - final BigInteger output = BigInteger.valueOf(input).and(UNSIGNED_LONG_MASK); - if (output.bitLength() > 64) { - throw new IllegalArgumentException( - "a long can't be more than 64 bits long, and is" + output.bitLength()); - } - return output; - } - - /** - * Convert the given {@link Bytes} to a signed {@link BigInteger}, even if the Bytes.toBigInteger - * is overloaded to create unsigned BigInteger (e.g. in {@link - * org.apache.tuweni.units.bigints.UInt256}. - * - * @param a a object implement {@link Bytes} - * @return the signed BigInteger represented by a's bytes - */ - public static BigInteger reallyToSignedBigInteger(Bytes a) { - byte[] bs = a.toArrayUnsafe(); - return new BigInteger(bs, 0, bs.length); - } - - public static Bytes32 longToBytes32(final long input) { - return Bytes32.leftPad(Bytes.minimalBytes(input)); - } - - public static Bytes longToBytes(final long input) { - return input == 0 ? Bytes.of(0) : Bytes.minimalBytes(input); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/DelegatingBytes16.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/DelegatingBytes16.java deleted file mode 100644 index c6bf9f528..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/DelegatingBytes16.java +++ /dev/null @@ -1,41 +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 org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.DelegatingBytes; - -/** Holds and delegates all operations to its inner bytes field of exactly 16 bytes. */ -public class DelegatingBytes16 extends DelegatingBytes implements Bytes16 { - protected DelegatingBytes16(Bytes delegate) { - super(delegate); - } - - @Override - public int size() { - return Bytes16.SIZE; - } - - @Override - public Bytes16 copy() { - return Bytes16.wrap(toArray()); - } - - @Override - public MutableBytes16 mutableCopy() { - return MutableBytes16.wrap(toArray()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/DelegatingMutableBytes16.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/DelegatingMutableBytes16.java deleted file mode 100644 index d52dd963e..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/DelegatingMutableBytes16.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.types; - -import org.apache.tuweni.bytes.DelegatingMutableBytes; -import org.apache.tuweni.bytes.MutableBytes; - -final class DelegatingMutableBytes16 extends DelegatingMutableBytes implements MutableBytes16 { - - final MutableBytes delegate; - - private DelegatingMutableBytes16(MutableBytes delegate) { - super(delegate); - this.delegate = delegate; - } - - static MutableBytes16 delegateTo(MutableBytes value) { - Checks.checkArgument(value.size() == SIZE, "Expected %s bytes but got %s", SIZE, value.size()); - return new DelegatingMutableBytes16(value); - } - - @Override - public Bytes16 copy() { - return Bytes16.wrap(delegate.toArray()); - } - - @Override - public MutableBytes16 mutableCopy() { - return MutableBytes16.wrap(delegate.toArray()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/EWord.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/EWord.java deleted file mode 100644 index cf8fc7376..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/EWord.java +++ /dev/null @@ -1,197 +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 java.math.BigInteger; - -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.BaseUInt256Value; -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Quantity; - -public final class EWord extends BaseUInt256Value implements Quantity { - /** The constant ZERO. */ - public static final EWord ZERO = of(0); - - /** The constant ONE. */ - public static final EWord ONE = of(1); - - public static final EWord THIRTY_TWO = of(32); - - public static final EWord THIRTY_ONE = of(31); - - private static final UInt256 TWO_POW_64 = UInt256.ONE.shiftLeft(64); - - /** - * Instantiates a new EVM word. - * - * @param value the value - */ - EWord(final UInt256 value) { - super(value, EWord::new); - } - - private EWord(final long v) { - this(UInt256.valueOf(v)); - } - - private EWord(final BigInteger v) { - this(UInt256.valueOf(v)); - } - - private EWord(final String hexString) { - this(UInt256.fromHexString(hexString)); - } - - /** - * EVM word of long. - * - * @param value the value - * @return the EVM word - */ - public static EWord of(final long value) { - return new EWord(value); - } - - /** - * EVM word of {@link BigInteger}. - * - * @param value the value - * @return the EVM word - */ - public static EWord of(final BigInteger value) { - return new EWord(value); - } - - /** - * EVM word of {@link UInt256}. - * - * @param value the value - * @return the EVM word - */ - public static EWord of(final UInt256 value) { - return new EWord(value); - } - - /** - * EVM word of {@link Number}. - * - * @param value the value - * @return the EVM word - */ - public static EWord of(final Number value) { - return new EWord((BigInteger) value); - } - - /** - * Wrap bytes into EVM word. - * - * @param value the value - * @return the EVM word - */ - public static EWord of(final Bytes value) { - return new EWord(UInt256.fromBytes(value)); - } - - /** - * From hex string to EVM word. - * - * @param str the str - * @return the EVM word - */ - public static EWord ofHexString(final String str) { - return new EWord(str); - } - - @Override - public Number getValue() { - return getAsBigInteger(); - } - - @Override - public BigInteger getAsBigInteger() { - return toBigInteger(); - } - - @Override - public String toHexString() { - return super.toHexString(); - } - - public Address toAddress() { - return Address.wrap(this.slice(12, 20)); - } - - @Override - public String toShortHexString() { - return super.isZero() ? "0x0" : super.toShortHexString(); - } - - /** - * Return the high half of the EWord - * - * @return the 16 high {@link Bytes} - */ - public Bytes hi() { - return this.toBytes().slice(0, 16); - } - - /** - * Return the low half of the EWord - * - * @return the 16 low {@link Bytes} - */ - public Bytes lo() { - return this.toBytes().slice(16); - } - - /** - * Returns a {@link BigInteger} containing the high half of the EWord - * - * @return the high bytes as a {@link BigInteger} - */ - public BigInteger hiBigInt() { - return this.hi().toUnsignedBigInteger(); - } - - /** - * Returns a {@link BigInteger} containing the low half of the EWord - * - * @return the low bytes as a {@link BigInteger} - */ - public BigInteger loBigInt() { - return this.lo().toUnsignedBigInteger(); - } - - public boolean isUInt64() { - return this.toUInt256().greaterOrEqualThan(TWO_POW_64); - } - - /** - * From {@link Quantity} to EVM word. - * - * @param quantity the quantity - * @return the EVM word - */ - public static EWord ofQuantity(final Quantity quantity) { - return EWord.of((Bytes) quantity); - } - - public int byteLength() { - return (this.bitLength() + 7) / 8; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemoryPoint.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemoryPoint.java deleted file mode 100644 index 3fa15d59f..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemoryPoint.java +++ /dev/null @@ -1,54 +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.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.experimental.Accessors; - -@AllArgsConstructor(access = AccessLevel.PRIVATE) -@Accessors(fluent = true) -public class MemoryPoint { - @Getter private EWord word; - @Getter private UnsignedByte uByte; - - public static MemoryPoint fromAddress(long memAddr) { - EWord word = EWord.of(memAddr).divide(EWord.THIRTY_TWO); - UnsignedByte uByte = UnsignedByte.of(memAddr % 32); - - return new MemoryPoint(word, uByte); - } - - public static MemoryPoint fromAddress(EWord memAddr) { - EWord word = memAddr.divide(EWord.THIRTY_TWO); - EWord remainder = memAddr.mod(32); - UnsignedByte uByte = UnsignedByte.of(remainder.toLong()); - - return new MemoryPoint(word, uByte); - } - - public EWord toAbsolute() { - // out = 32×Word + Byte - EWord out = EWord.THIRTY_TWO.multiply(word); - return out.add(EWord.of(uByte.toBigInteger().longValue())); - } - - @Override - public String toString() { - return "[%s]%02d".formatted(word.toString(), uByte.toBigInteger().longValue()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemoryRange.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemoryRange.java deleted file mode 100644 index a63ea499b..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemoryRange.java +++ /dev/null @@ -1,58 +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.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.experimental.Accessors; - -@AllArgsConstructor(access = AccessLevel.PRIVATE) -@Accessors(fluent = true) -public class MemoryRange { - @Getter private MemoryPoint start; - @Getter private MemoryPoint end; - - public static MemoryRange newInstance(EWord offset, EWord length) { - EWord endWord = offset.add(length); - - MemoryPoint start = MemoryPoint.fromAddress(offset); - MemoryPoint end = MemoryPoint.fromAddress(endWord); - - return new MemoryRange(start, end); - } - - public EWord length() { - return end.word() - .subtract(start.word()) - .multiply(32) - .add(end.uByte().toBigInteger().longValue()) - .subtract(start.uByte().toBigInteger().longValue()); - } - - public EWord absolute() { - return start.toAbsolute(); - } - - public boolean isUint64() { - return length().isUInt64(); - } - - @Override - public String toString() { - return "%s -- %s (%d)".formatted(start, end, length().toBigInteger().longValue()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableArrayWrappingBytes.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableArrayWrappingBytes.java deleted file mode 100644 index 379d23202..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableArrayWrappingBytes.java +++ /dev/null @@ -1,113 +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 java.util.Arrays; - -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.MutableBytes; - -class MutableArrayWrappingBytes extends ArrayWrappingBytes implements MutableBytes { - - MutableArrayWrappingBytes(byte[] bytes) { - super(bytes); - } - - MutableArrayWrappingBytes(byte[] bytes, int offset, int length) { - super(bytes, offset, length); - } - - @Override - public void set(int i, byte b) { - // Check bounds because while the array access would throw, the error message - // would be confusing - // for the caller. - Checks.checkElementIndex(i, length); - bytes[offset + i] = b; - } - - @Override - public void set(int i, Bytes b) { - byte[] bytesArray = b.toArrayUnsafe(); - System.arraycopy(bytesArray, 0, bytes, offset + i, bytesArray.length); - } - - @Override - public MutableBytes increment() { - for (int i = length - 1; i >= offset; --i) { - if (bytes[i] == (byte) 0xFF) { - bytes[i] = (byte) 0x00; - } else { - ++bytes[i]; - break; - } - } - - return this; - } - - @Override - public MutableBytes decrement() { - for (int i = length - 1; i >= offset; --i) { - if (bytes[i] == (byte) 0x00) { - bytes[i] = (byte) 0xFF; - } else { - --bytes[i]; - break; - } - } - - return this; - } - - @Override - public MutableBytes mutableSlice(int i, int length) { - if (i == 0 && length == this.length) { - return this; - } - if (length == 0) { - return MutableBytes.EMPTY; - } - - Checks.checkElementIndex(i, this.length); - Checks.checkArgument( - i + length <= this.length, - "Specified length %s is too large: the value has size %s and has only %s bytes from %s", - length, - this.length, - this.length - i, - i); - - return length == Bytes16.SIZE - ? new MutableArrayWrappingBytes16(bytes, offset + i) - : new MutableArrayWrappingBytes(bytes, offset + i, length); - } - - @Override - public void fill(byte b) { - Arrays.fill(bytes, offset, offset + length, b); - } - - @Override - public Bytes copy() { - return new ArrayWrappingBytes(toArray()); - } - - @Override - public int hashCode() { - return computeHashcode(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableArrayWrappingBytes16.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableArrayWrappingBytes16.java deleted file mode 100644 index c5dce7e94..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableArrayWrappingBytes16.java +++ /dev/null @@ -1,38 +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; - -final class MutableArrayWrappingBytes16 extends MutableArrayWrappingBytes - implements MutableBytes16 { - - MutableArrayWrappingBytes16(byte[] bytes) { - this(bytes, 0); - } - - MutableArrayWrappingBytes16(byte[] bytes, int offset) { - super(bytes, offset, SIZE); - } - - @Override - public Bytes16 copy() { - return new ArrayWrappingBytes16(toArray()); - } - - @Override - public MutableBytes16 mutableCopy() { - return new MutableArrayWrappingBytes16(toArray()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableBytes16.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableBytes16.java deleted file mode 100644 index a47b6d30f..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MutableBytes16.java +++ /dev/null @@ -1,111 +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 org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.MutableBytes; - -/** A mutable {@link Bytes16}, that is a mutable {@link Bytes} value of exactly 16 bytes. */ -public interface MutableBytes16 extends MutableBytes, Bytes16 { - - /** - * Create a new mutable 16 bytes value. - * - * @return A newly allocated {@link MutableBytes} value. - */ - static MutableBytes16 create() { - return new MutableArrayWrappingBytes16(new byte[SIZE]); - } - - /** - * Wrap a 16 bytes array as a mutable 16 bytes value. - * - * @param value The value to wrap. - * @return A {@link MutableBytes16} wrapping {@code value}. - * @throws IllegalArgumentException if {@code value.length != 16}. - */ - static MutableBytes16 wrap(byte[] value) { - Checks.checkNotNull(value); - return new MutableArrayWrappingBytes16(value); - } - - /** - * Wrap the provided array as a {@link MutableBytes16}. - * - *

Note that value is not copied, only wrapped, and thus any future update to {@code value} - * within the wrapped parts will be reflected in the returned value. - * - * @param value The bytes to wrap. - * @param offset The index (inclusive) in {@code value} of the first byte exposed by the returned - * value. In other words, you will have {@code wrap(value, i).get(0) == value[i]}. - * @return A {@link MutableBytes16} that exposes the bytes of {@code value} from {@code offset} - * (inclusive) to {@code offset + 16} (exclusive). - * @throws IndexOutOfBoundsException if {@code offset < 0 || (value.length > 0 && offset >= - * value.length)}. - * @throws IllegalArgumentException if {@code length < 0 || offset + 16 > value.length}. - */ - static MutableBytes16 wrap(byte[] value, int offset) { - Checks.checkNotNull(value); - return new MutableArrayWrappingBytes16(value, offset); - } - - /** - * Wrap the provided value, which must be of size 16, as a {@link MutableBytes16}. - * - *

Note that value is not copied, only wrapped, and thus any future update to {@code value} - * will be reflected in the returned value. - * - * @param value The bytes to wrap. - * @return A {@link MutableBytes16} that exposes the bytes of {@code value}. - * @throws IllegalArgumentException if {@code value.size() != 16}. - */ - static MutableBytes16 wrap(MutableBytes value) { - Checks.checkNotNull(value); - if (value instanceof MutableBytes16) { - return (MutableBytes16) value; - } - return DelegatingMutableBytes16.delegateTo(value); - } - - /** - * Wrap a slice/sub-part of the provided value as a {@link MutableBytes16}. - * - *

Note that the value is not copied, and thus any future update to {@code value} within the - * wrapped parts will be reflected in the returned value. - * - * @param value The bytes to wrap. - * @param offset The index (inclusive) in {@code value} of the first byte exposed by the returned - * value. In other words, you will have {@code wrap(value, i).get(0) == value.get(i)}. - * @return A {@link Bytes16} that exposes the bytes of {@code value} from {@code offset} - * (inclusive) to {@code offset + 16} (exclusive). - * @throws IndexOutOfBoundsException if {@code offset < 0 || (value.size() > 0 && offset >= - * value.size())}. - * @throws IllegalArgumentException if {@code length < 0 || offset + 16 > value.size()}. - */ - static MutableBytes16 wrap(MutableBytes value, int offset) { - Checks.checkNotNull(value); - if (value instanceof MutableBytes16) { - return (MutableBytes16) value; - } - - MutableBytes slice = value.mutableSlice(offset, SIZE); - if (slice instanceof MutableBytes16) { - return (MutableBytes16) slice; - } - - return DelegatingMutableBytes16.delegateTo(slice); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/UnsignedByte.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/UnsignedByte.java deleted file mode 100644 index 9b413c0c5..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/UnsignedByte.java +++ /dev/null @@ -1,143 +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 java.math.BigInteger; - -import com.fasterxml.jackson.annotation.JsonValue; - -/** Represents an unsigned byte type. */ -public class UnsignedByte { - public static final UnsignedByte ZERO = UnsignedByte.of(0); - - private final short unsignedByte; - - private UnsignedByte(final short unsignedByte) { - this.unsignedByte = unsignedByte; - } - - /** - * Factory method for the creation of an {@link UnsignedByte} from a primitive byte type. - * - * @param b parameter of type byte. - * @return an instance of {@link UnsignedByte}. - */ - public static UnsignedByte of(final byte b) { - final short unsignedB = (short) (b & 0xff); - - checkLength(unsignedB); - - return new UnsignedByte(unsignedB); - } - - /** - * Factory method for the creation of an {@link UnsignedByte} from a primitive int type. - * - * @param b parameter of type int. - * @return an instance of {@link UnsignedByte}. - */ - public static UnsignedByte of(final int b) { - checkLength(b); - - return new UnsignedByte((short) b); - } - - /** - * Factory method for the creation of an {@link UnsignedByte} from a primitive long type. - * - * @param b parameter of type long. - * @return an instance of {@link UnsignedByte}. - */ - public static UnsignedByte of(final long b) { - checkLength(b); - - return new UnsignedByte((short) b); - } - - /** - * Left bit shift operation on an instance of {@link UnsignedByte}. - * - * @param shiftAmount amount of bits represented as a {@link UnsignedByte} type to shift left. - * @return a bit shifted instance of {@link UnsignedByte}. - */ - public UnsignedByte shiftLeft(final UnsignedByte shiftAmount) { - return shiftLeft(shiftAmount.toInteger()); - } - - /** - * Left bit shift operation on an instance of {@link UnsignedByte}. - * - * @param shiftAmount amount of bits represented as an int type to shift left. - * @return a bit shifted instance of {@link UnsignedByte}. - */ - public UnsignedByte shiftLeft(final int shiftAmount) { - return new UnsignedByte((short) ((unsignedByte << shiftAmount) & 0xff)); - } - - /** - * Right bit shift operation on an instance of {@link UnsignedByte}. - * - * @param shiftAmount amount of bits represented as a {@link UnsignedByte} type to shift right. - * @return a bit shifted instance of {@link UnsignedByte}. - */ - public UnsignedByte shiftRight(final UnsignedByte shiftAmount) { - return shiftRight(shiftAmount.toInteger()); - } - - /** - * Right bit shift operation on an instance of {@link UnsignedByte}. - * - * @param shiftAmount amount of bits represented as an int type to shift right. - * @return a bit shifted instance of {@link UnsignedByte}. - */ - public UnsignedByte shiftRight(final int shiftAmount) { - return new UnsignedByte((short) ((unsignedByte >> shiftAmount) & 0xff)); - } - - /** - * Mod operation on an instance of {@link UnsignedByte}. - * - * @param m right hand side of division by mod operation. - * @return the result of mod division as an instance of {@link UnsignedByte}. - */ - public UnsignedByte mod(final int m) { - return new UnsignedByte((short) (unsignedByte % m)); - } - - @JsonValue - public int toInteger() { - return unsignedByte; - } - - public byte toByte() { - return (byte) unsignedByte; - } - - /** - * Converts to {@link BigInteger} type. - * - * @return the unsigned byte to converted to {@link BigInteger} - */ - public BigInteger toBigInteger() { - return BigInteger.valueOf(this.toInteger()); - } - - private static void checkLength(final long b) { - if (b < 0 || b > 255) { - throw new IllegalArgumentException("Unsigned byte value must be between 0 - 255. Is " + b); - } - } -} 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 deleted file mode 100644 index 54a184640..000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java +++ /dev/null @@ -1,86 +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.types; - -import java.util.ArrayList; - -import com.google.common.base.Preconditions; -import org.apache.tuweni.bytes.Bytes; - -public class Utils { - - /** - * Add zeroes to the left of the {@link Bytes} to create {@link Bytes} of the given size. The - * wantedSize must be at least the size of the Bytes. - * - * @param input - * @param wantedSize - * @return - */ - public static Bytes leftPadTo(Bytes input, int wantedSize) { - Preconditions.checkArgument( - wantedSize >= input.size(), "wantedSize can't be shorter than the input size"); - return Bytes.concatenate(Bytes.repeat((byte) 0, wantedSize - input.size()), input); - } - - public static Bytes rightPadTo(Bytes input, int wantedSize) { - Preconditions.checkArgument( - wantedSize >= input.size(), "wantedSize can't be shorter than the input size"); - return Bytes.concatenate(input, Bytes.repeat((byte) 0, wantedSize - input.size())); - } - - /** - * Create the Bit and BitDec list of the RLP pattern of an int. - * - * @param input - * @param nbStep - * @return - */ - public static BitDecOutput bitDecomposition(int input, int nbStep) { - final int nbStepMin = 8; - Preconditions.checkArgument( - nbStep >= nbStepMin, "Number of steps must be at least " + nbStepMin); - - ArrayList bit = new ArrayList<>(nbStep); - ArrayList acc = new ArrayList<>(nbStep); - for (int i = 0; i < nbStep - nbStepMin; i++) { - bit.add(i, false); - acc.add(i, 0); - } - BitDecOutput output = new BitDecOutput(bit, acc); - - int bitAcc = 0; - boolean bitDec = false; - double div = 0; - - for (int i = nbStepMin - 1; i >= 0; i--) { - div = Math.pow(2, i); - bitAcc *= 2; - - if (input >= div) { - bitDec = true; - bitAcc += 1; - input -= (int) div; - } else { - bitDec = false; - } - - output.bitDecList().add(nbStep - i - 1, bitDec); - output.bitAccList().add(nbStep - i - 1, bitAcc); - } - return output; - } -} diff --git a/arithmetization/src/main/resources/opcodes.yml b/arithmetization/src/main/resources/opcodes.yml deleted file mode 100644 index f2574c890..000000000 --- a/arithmetization/src/main/resources/opcodes.yml +++ /dev/null @@ -1,1669 +0,0 @@ -opcodes: - - mnemonic: STOP - value: 0x00 - instructionFamily: HALT - stackSettings: - pattern: ZERO_ZERO - alpha: 0 - delta: 0 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_ZERO - flag3: true - - mnemonic: ADD - value: 0x01 - instructionFamily: ADD - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: MUL - value: 0x02 - instructionFamily: MUL - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_LOW - - mnemonic: SUB - value: 0x03 - instructionFamily: ADD - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: DIV - value: 0x04 - instructionFamily: MOD - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_LOW - - mnemonic: SDIV - value: 0x05 - instructionFamily: MOD - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_LOW - - mnemonic: MOD - value: 0x06 - instructionFamily: MOD - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_LOW - - mnemonic: SMOD - value: 0x07 - instructionFamily: MOD - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_LOW - - mnemonic: ADDMOD - value: 0x8 - instructionFamily: EXT - stackSettings: - pattern: THREE_ONE - alpha: 1 - delta: 3 - nbAdded: 1 - nbRemoved: 3 - staticGas: G_LOW - - mnemonic: MULMOD - value: 0x9 - instructionFamily: EXT - stackSettings: - pattern: THREE_ONE - alpha: 1 - delta: 3 - nbAdded: 1 - nbRemoved: 3 - staticGas: G_LOW - - mnemonic: EXP - value: 0xa - instructionFamily: MUL - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_EXP - - mnemonic: SIGNEXTEND - value: 0xb - instructionFamily: BIN - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - 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. - - mnemonic: LT - value: 0x10 - instructionFamily: WCP - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: GT - value: 0x11 - instructionFamily: WCP - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: SLT - value: 0x12 - instructionFamily: WCP - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: SGT - value: 0x13 - instructionFamily: WCP - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: EQ - value: 0x14 - instructionFamily: WCP - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: ISZERO - value: 0x15 - instructionFamily: WCP - stackSettings: - pattern: ONE_ONE - alpha: 1 - delta: 1 - nbAdded: 1 - nbRemoved: 1 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: AND - value: 0x16 - instructionFamily: BIN - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: OR - value: 0x17 - instructionFamily: BIN - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: XOR - value: 0x18 - instructionFamily: BIN - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: NOT - value: 0x19 - instructionFamily: BIN - stackSettings: - pattern: ONE_ONE - alpha: 1 - delta: 1 - nbAdded: 1 - nbRemoved: 1 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: BYTE - value: 0x1a - instructionFamily: BIN - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: SHL - value: 0x1b - instructionFamily: SHF - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: SHR - value: 0x1c - instructionFamily: SHF - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: SAR - value: 0x1d - instructionFamily: SHF - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: G_VERY_LOW - - mnemonic: SHA3 - value: 0x20 - instructionFamily: KEC - stackSettings: - pattern: TWO_ONE - alpha: 1 - delta: 2 - nbAdded: 1 - nbRemoved: 2 - staticGas: S_MXP - billing: - byWord: - type: TYPE_4 - wordPrice: G_KECCAK_256_WORD - - mnemonic: ADDRESS - value: 0x30 - instructionFamily: CONTEXT - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BASE - - mnemonic: BALANCE - value: 0x31 - instructionFamily: ACCOUNT - stackSettings: - pattern: ONE_ONE - alpha: 1 - delta: 1 - nbAdded: 1 - nbRemoved: 1 - staticGas: S_HUB - addressTrimmingInstruction: true - flag4: true - - mnemonic: ORIGIN - value: 0x32 - instructionFamily: TRANSACTION - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BASE - - mnemonic: CALLER - value: 0x33 - instructionFamily: CONTEXT - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BASE - flag2: true - - mnemonic: CALLVALUE - value: 0x34 - instructionFamily: CONTEXT - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BASE - flag1: true - - mnemonic: CALLDATALOAD - value: 0x35 - instructionFamily: STACK_RAM - stackSettings: - pattern: LOAD_STORE - alpha: 1 - delta: 1 - nbAdded: 1 - nbRemoved: 1 - staticGas: G_VERY_LOW - oobFlag: true - flag1: true - - mnemonic: CALLDATASIZE - value: 0x36 - instructionFamily: CONTEXT - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BASE - flag1: true - flag3: true - - mnemonic: CALLDATACOPY - value: 0x37 - instructionFamily: COPY - stackSettings: - pattern: COPY - alpha: 0 - delta: 3 - nbAdded: 0 - nbRemoved: 3 - staticGas: S_MXP - billing: - byWord: - type: TYPE_4 - wordPrice: G_COPY - - mnemonic: CODESIZE - value: 0x38 - instructionFamily: ACCOUNT - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BASE - flag1: true - - mnemonic: CODECOPY - value: 0x39 - instructionFamily: COPY - stackSettings: - pattern: COPY - alpha: 0 - delta: 3 - nbAdded: 0 - nbRemoved: 3 - staticGas: S_MXP - flag3: true - billing: - byWord: - type: TYPE_4 - wordPrice: G_COPY - - mnemonic: GASPRICE - value: 0x3a - instructionFamily: TRANSACTION - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BASE - flag1: true - - mnemonic: EXTCODESIZE - value: 0x3b - instructionFamily: ACCOUNT - stackSettings: - pattern: ONE_ONE - alpha: 1 - delta: 1 - nbAdded: 1 - nbRemoved: 1 - staticGas: S_HUB - addressTrimmingInstruction: true - flag1: true - flag3: true - - mnemonic: EXTCODECOPY - value: 0x3c - instructionFamily: COPY - stackSettings: - pattern: COPY - alpha: 0 - delta: 4 - nbAdded: 0 - nbRemoved: 4 - staticGas: S_MXP - addressTrimmingInstruction: true - flag4: true - billing: - byWord: - type: TYPE_4 - wordPrice: G_COPY - - mnemonic: RETURNDATASIZE - value: 0x3d - instructionFamily: CONTEXT - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BASE - flag1: true - flag2: true - - mnemonic: RETURNDATACOPY - value: 0x3e - instructionFamily: COPY - stackSettings: - pattern: COPY - alpha: 0 - delta: 3 - nbAdded: 0 - nbRemoved: 3 - oobFlag: true - staticGas: S_MXP - flag2: true - billing: - byWord: - type: TYPE_4 - wordPrice: G_COPY - - mnemonic: EXTCODEHASH - value: 0x3f - instructionFamily: ACCOUNT - stackSettings: - pattern: ONE_ONE - alpha: 1 - delta: 1 - nbAdded: 1 - nbRemoved: 1 - staticGas: S_HUB - addressTrimmingInstruction: true - flag2: true - - mnemonic: BLOCKHASH - value: 0x40 - instructionFamily: BATCH - stackSettings: - pattern: ONE_ONE - alpha: 1 - delta: 1 - nbAdded: 1 - nbRemoved: 1 - staticGas: G_BLOCK_HASH - flag1: true - - mnemonic: COINBASE - value: 0x41 - instructionFamily: BATCH - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BLOCK_HASH - flag1: true - - mnemonic: TIMESTAMP - value: 0x42 - instructionFamily: BATCH - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BLOCK_HASH - flag1: true - - mnemonic: NUMBER - value: 0x43 - instructionFamily: BATCH - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BLOCK_HASH - flag1: true - - mnemonic: DIFFICULTY - value: 0x44 - instructionFamily: BATCH - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BLOCK_HASH - flag1: true - - mnemonic: GASLIMIT - value: 0x45 - instructionFamily: BATCH - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BLOCK_HASH - flag1: true - - mnemonic: CHAINID - value: 0x46 - instructionFamily: BATCH - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BLOCK_HASH - flag1: true - - mnemonic: SELFBALANCE - value: 0x47 - instructionFamily: ACCOUNT - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_LOW - flag1: true - - mnemonic: BASEFEE - value: 0x48 - instructionFamily: BATCH - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BLOCK_HASH - flag1: true - - mnemonic: POP - value: 0x50 - instructionFamily: PUSH_POP - stackSettings: - pattern: ONE_ZERO - alpha: 0 - delta: 1 - nbAdded: 0 - nbRemoved: 1 - staticGas: G_BASE - - mnemonic: MLOAD - value: 0x51 - instructionFamily: STACK_RAM - stackSettings: - pattern: ONE_ONE - alpha: 1 - delta: 1 - nbAdded: 1 - nbRemoved: 1 - staticGas: G_VERY_LOW - flag2: true - billing: - byMxp: - type: TYPE_2 - - mnemonic: MSTORE - value: 0x52 - instructionFamily: STACK_RAM - stackSettings: - pattern: TWO_ZERO - alpha: 0 - delta: 2 - nbAdded: 0 - nbRemoved: 2 - staticGas: G_VERY_LOW - flag3: true - billing: - byMxp: - type: TYPE_2 - - mnemonic: MSTORE8 - value: 0x53 - instructionFamily: STACK_RAM - stackSettings: - pattern: TWO_ZERO - alpha: 0 - delta: 2 - nbAdded: 0 - nbRemoved: 2 - staticGas: G_VERY_LOW - flag4: true - billing: - byMxp: - type: TYPE_3 - - mnemonic: SLOAD - value: 0x54 - instructionFamily: STORAGE - stackSettings: - pattern: ONE_ONE - alpha: 1 - delta: 1 - nbAdded: 1 - nbRemoved: 1 - staticGas: S_HUB - - mnemonic: SSTORE - value: 0x55 - instructionFamily: STORAGE - stackSettings: - pattern: TWO_ZERO - alpha: 0 - delta: 2 - nbAdded: 0 - nbRemoved: 2 - oobFlag: true - staticGas: S_HUB - forbiddenInStatic: true - flag1: true - - mnemonic: JUMP - value: 0x56 - instructionFamily: JUMP - stackSettings: - pattern: ONE_ZERO - alpha: 0 - delta: 1 - nbAdded: 0 - nbRemoved: 1 - staticGas: G_MID - oobFlag: true - flag1: true - - mnemonic: JUMPI - value: 0x57 - instructionFamily: JUMP - stackSettings: - pattern: TWO_ZERO - alpha: 0 - delta: 2 - nbAdded: 0 - nbRemoved: 2 - staticGas: G_MID - oobFlag: true - flag2: true - - mnemonic: PC - value: 0x58 - instructionFamily: MACHINE_STATE - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BASE - flag1: true - - mnemonic: MSIZE - value: 0x59 - instructionFamily: MACHINE_STATE - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BASE - flag2: true - billing: - byMxp: - type: TYPE_1 - - mnemonic: GAS - value: 0x5a - instructionFamily: MACHINE_STATE - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_BASE - flag3: true - - mnemonic: JUMPDEST - value: 0x5b - instructionFamily: MACHINE_STATE - jumpFlag: true - stackSettings: - pattern: ZERO_ZERO - alpha: 0 - delta: 0 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_JUMP_DEST - flag4: true - - mnemonic: PUSH1 - value: 0x60 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH2 - value: 0x61 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH3 - value: 0x62 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH4 - value: 0x63 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH5 - value: 0x64 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH6 - value: 0x65 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH7 - value: 0x66 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH8 - value: 0x67 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH9 - value: 0x68 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH10 - value: 0x69 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH11 - value: 0x6a - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH12 - value: 0x6b - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH13 - value: 0x6c - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH14 - value: 0x6d - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH15 - value: 0x6e - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH16 - value: 0x6f - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH17 - value: 0x70 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH18 - value: 0x71 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH19 - value: 0x72 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH20 - value: 0x73 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH21 - value: 0x74 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH22 - value: 0x75 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH23 - value: 0x76 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH24 - value: 0x77 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH25 - value: 0x78 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH26 - value: 0x79 - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH27 - value: 0x7a - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH28 - value: 0x7b - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH29 - value: 0x7c - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH30 - value: 0x7d - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH31 - value: 0x7e - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: PUSH32 - value: 0x7f - instructionFamily: PUSH_POP - pushFlag: true - stackSettings: - pattern: ZERO_ONE - alpha: 1 - delta: 0 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - flag1: true - - mnemonic: DUP1 - value: 0x80 - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 2 - delta: 1 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP2 - value: 0x81 - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 3 - delta: 2 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP3 - value: 0x82 - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 4 - delta: 3 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP4 - value: 0x83 - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 5 - delta: 4 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP5 - value: 0x84 - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 6 - delta: 5 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP6 - value: 0x85 - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 7 - delta: 6 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP7 - value: 0x86 - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 8 - delta: 7 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP8 - value: 0x87 - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 9 - delta: 8 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP9 - value: 0x88 - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 10 - delta: 9 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP10 - value: 0x89 - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 11 - delta: 10 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP11 - value: 0x8a - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 12 - delta: 11 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP12 - value: 0x8b - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 13 - delta: 12 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP13 - value: 0x8c - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 14 - delta: 13 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP14 - value: 0x8d - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 15 - delta: 14 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP15 - value: 0x8e - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 16 - delta: 15 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: DUP16 - value: 0x8f - instructionFamily: DUP - stackSettings: - pattern: DUP - alpha: 17 - delta: 16 - nbAdded: 1 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP1 - value: 0x90 - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 2 - delta: 2 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP2 - value: 0x91 - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 3 - delta: 3 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP3 - value: 0x92 - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 4 - delta: 4 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP4 - value: 0x93 - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 5 - delta: 5 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP5 - value: 0x94 - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 6 - delta: 6 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP6 - value: 0x95 - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 7 - delta: 7 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP7 - value: 0x96 - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 8 - delta: 8 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP8 - value: 0x97 - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 9 - delta: 9 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP9 - value: 0x98 - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 10 - delta: 10 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP10 - value: 0x99 - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 11 - delta: 11 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP11 - value: 0x9a - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 12 - delta: 12 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP12 - value: 0x9b - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 13 - delta: 13 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP13 - value: 0x9c - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 14 - delta: 14 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP14 - value: 0x9d - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 15 - delta: 15 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP15 - value: 0x9e - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 16 - delta: 16 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: SWAP16 - value: 0x9f - instructionFamily: SWAP - stackSettings: - pattern: SWAP - alpha: 17 - delta: 17 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_VERY_LOW - - mnemonic: LOG0 - value: 0xa0 - instructionFamily: LOG - stackSettings: - pattern: LOG - alpha: 0 - delta: 2 - nbAdded: 0 - nbRemoved: 2 - staticGas: G_LOG_0 - twoLinesInstruction: true - forbiddenInStatic: true - billing: - byByte: - type: TYPE_4 - bytePrice: G_LOG_DATA - - mnemonic: LOG1 - value: 0xa1 - instructionFamily: LOG - stackSettings: - pattern: LOG - alpha: 0 - delta: 3 - nbAdded: 0 - nbRemoved: 3 - staticGas: G_LOG_1 - twoLinesInstruction: true - forbiddenInStatic: true - flag1: true - billing: - byByte: - type: TYPE_4 - bytePrice: G_LOG_DATA - - mnemonic: LOG2 - value: 0xa2 - instructionFamily: LOG - stackSettings: - pattern: LOG - alpha: 0 - delta: 4 - nbAdded: 0 - nbRemoved: 4 - staticGas: G_LOG_2 - twoLinesInstruction: true - forbiddenInStatic: true - flag1: true - flag3: true - billing: - byByte: - type: TYPE_4 - bytePrice: G_LOG_DATA - - mnemonic: LOG3 - value: 0xa3 - instructionFamily: LOG - stackSettings: - pattern: LOG - alpha: 0 - delta: 5 - nbAdded: 0 - nbRemoved: 5 - staticGas: G_LOG_3 - twoLinesInstruction: true - forbiddenInStatic: true - flag1: true - flag3: true - billing: - byByte: - type: TYPE_4 - bytePrice: G_LOG_DATA - - mnemonic: LOG4 - value: 0xa4 - instructionFamily: LOG - stackSettings: - pattern: LOG - alpha: 0 - delta: 6 - nbAdded: 0 - nbRemoved: 6 - staticGas: G_LOG_4 - twoLinesInstruction: true - forbiddenInStatic: true - flag1: true - flag2: true - flag3: true - billing: - byByte: - type: TYPE_4 - bytePrice: G_LOG_DATA - - mnemonic: CREATE - value: 0xf0 - instructionFamily: CREATE - stackSettings: - pattern: CREATE - alpha: 1 - delta: 3 - nbAdded: 1 - nbRemoved: 3 - oobFlag: true - staticGas: G_CREATE - twoLinesInstruction: true - forbiddenInStatic: true - billing: - byMxp: - type: TYPE_4 - - mnemonic: CALL - value: 0xf1 - instructionFamily: CALL - stackSettings: - pattern: CALL - alpha: 1 - delta: 7 - nbAdded: 1 - nbRemoved: 7 - oobFlag: true - staticGas: S_CALL - twoLinesInstruction: true - addressTrimmingInstruction: true - flag1: true - billing: - byMxp: - type: TYPE_5 - - mnemonic: CALLCODE - value: 0xf2 - instructionFamily: CALL - stackSettings: - pattern: CALL - alpha: 1 - delta: 7 - nbAdded: 1 - nbRemoved: 7 - oobFlag: true - staticGas: S_CALL - twoLinesInstruction: true - addressTrimmingInstruction: true - flag2: true - billing: - byMxp: - type: TYPE_5 - - mnemonic: RETURN - value: 0xf3 - instructionFamily: HALT - stackSettings: - pattern: TWO_ZERO - alpha: 0 - delta: 2 - nbAdded: 0 - nbRemoved: 2 - oobFlag: true - staticGas: S_MXP - flag1: true - billing: - byByte: - type: TYPE_4 - bytePrice: G_CODE_DEPOSIT - - mnemonic: DELEGATECALL - value: 0xf4 - instructionFamily: CALL - stackSettings: - pattern: CALL - alpha: 1 - delta: 6 - nbAdded: 1 - nbRemoved: 6 - staticGas: S_CALL - twoLinesInstruction: true - addressTrimmingInstruction: true - flag3: true - billing: - byMxp: - type: TYPE_5 - - mnemonic: CREATE2 - value: 0xf5 - instructionFamily: CREATE - stackSettings: - pattern: CREATE - alpha: 1 - delta: 4 - nbAdded: 1 - nbRemoved: 4 - oobFlag: true - staticGas: G_CREATE - twoLinesInstruction: true - forbiddenInStatic: true - flag1: true - billing: - byWord: - type: TYPE_4 - wordPrice: G_KECCAK_256_WORD - - mnemonic: STATICCALL - value: 0xfa - instructionFamily: CALL - stackSettings: - pattern: CALL - alpha: 1 - delta: 6 - nbAdded: 1 - nbRemoved: 6 - staticGas: S_CALL - twoLinesInstruction: true - addressTrimmingInstruction: true - flag4: true - billing: - byMxp: - type: TYPE_5 - - mnemonic: REVERT - value: 0xfd - instructionFamily: HALT - stackSettings: - pattern: TWO_ZERO - alpha: 0 - delta: 2 - nbAdded: 0 - nbRemoved: 2 - staticGas: S_MXP - flag2: true - billing: - byMxp: - type: TYPE_4 - - mnemonic: INVALID - value: 0xfe - instructionFamily: INVALID - stackSettings: - pattern: ZERO_ZERO - alpha: 0 - delta: 0 - nbAdded: 0 - nbRemoved: 0 - staticGas: G_ZERO - - mnemonic: SELFDESTRUCT - value: 0xff - instructionFamily: HALT - stackSettings: - pattern: ONE_ZERO - alpha: 0 - delta: 1 - nbAdded: 0 - nbRemoved: 1 - staticGas: S_MXP - forbiddenInStatic: true - addressTrimmingInstruction: true - flag4: true diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplaysTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplaysTests.java deleted file mode 100644 index 0afcb0c00..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplaysTests.java +++ /dev/null @@ -1,75 +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; - -import static org.junit.jupiter.api.Assertions.fail; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.zip.GZIPInputStream; - -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; -import org.junit.jupiter.api.Test; - -/** - * Replays are captured on a fully (not snapshot) synchronized Besu node running the plugin: - * - *

{@code
- * curl -X POST 'http://localhost:8545'
- * --data '{
- *    "jsonrpc":"2.0",
- *    "method":"rollup_captureConflation",
- *    "params":["296519", "296521"], "id":"1"
- *  }'
- * | jq '.result.capture' -r
- * | gzip > arithmetization/src/test/resources/replays/my-test-case.json.gz
- * }
- */ -@Slf4j -public class ReplaysTests { - /** - * Loads a .json or .json.gz replay file generated by the {@link - * net.consensys.linea.blockcapture.BlockCapturer} and execute it as a test. - * - * @param filename the file in resources/replays/ containing the replay - */ - public static void replay(String filename) { - final InputStream fileStream = - ReplaysTests.class.getClassLoader().getResourceAsStream("replays/%s".formatted(filename)); - if (fileStream == null) { - fail("unable to find %s in replay resources".formatted(filename)); - } - - final InputStream stream; - try { - stream = filename.toLowerCase().endsWith("gz") ? new GZIPInputStream(fileStream) : fileStream; - } catch (IOException e) { - log.error("while loading {}: {}", filename, e.getMessage()); - throw new RuntimeException(e); - } - ToyExecutionEnvironment.builder() - .build() - .replay(new BufferedReader(new InputStreamReader(stream))); - } - - @Test - void traceTxStartNotTheSameAsTxPrepare() { - replay("start-vs-prepare-tx.json.gz"); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java deleted file mode 100644 index 1ac111f01..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java +++ /dev/null @@ -1,29 +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; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.Test; - -public class ZkTracerTest { - - @Test - public void createNewTracer() { - final ZkTracer zkTracer = new ZkTracer(); - assertThat(zkTracer.isExtendedTracing()).isTrue(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/bytestheta/BaseThetaTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/bytestheta/BaseThetaTest.java deleted file mode 100644 index 2fd4dfa45..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/bytestheta/BaseThetaTest.java +++ /dev/null @@ -1,147 +0,0 @@ -package net.consensys.linea.zktracer.bytestheta; - -/* - * 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 static org.assertj.core.api.Assertions.assertThat; - -import net.consensys.linea.zktracer.types.Bytes16; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; -import org.junit.jupiter.api.Test; - -/** - * Test class related to {@link BaseTheta} data structure, which is an extension of {@link - * BytesArray}, with support for high and low bytes' manipulation. - */ -public class BaseThetaTest { - @Test - public void baseThetaTest() { - Bytes firstByte = Bytes.fromHexString("0x000000000000000a"); - Bytes secondByte = Bytes.fromHexString("0x000000000000000b"); - Bytes thirdByte = Bytes.fromHexString("0x000000000000000c"); - Bytes fourthByte = Bytes.fromHexString("0x000000000000000d"); - Bytes32 bytes32 = Bytes32.wrap(Bytes.concatenate(firstByte, secondByte, thirdByte, fourthByte)); - - BaseTheta baseTheta = BaseTheta.fromBytes32(bytes32); - Bytes32 expectedBytes32 = - Bytes32.wrap(Bytes.concatenate(fourthByte, thirdByte, secondByte, firstByte)); - - assertThat(baseTheta.getBytes32()).isEqualTo(expectedBytes32); - - Bytes16 expectedLow = Bytes16.wrap(Bytes.concatenate(thirdByte, fourthByte)); - Bytes16 expectedHigh = Bytes16.wrap(Bytes.concatenate(firstByte, secondByte)); - - assertThat(baseTheta.getLow()).isEqualTo(expectedLow); - assertThat(baseTheta.getHigh()).isEqualTo(expectedHigh); - - assertThat(baseTheta.get(0)).isEqualTo(fourthByte); - assertThat(baseTheta.get(1)).isEqualTo(thirdByte); - assertThat(baseTheta.get(2)).isEqualTo(secondByte); - assertThat(baseTheta.get(3)).isEqualTo(firstByte); - } - - @Test - public void baseBytesTest() { - Bytes32 bytes32 = - Bytes32.fromHexString("0x000000000000000a000000000000000b000000000000000c000000000000000d"); - BaseBytes baseBytes = BaseBytes.fromBytes32(bytes32); - Bytes16 expectedHigh = Bytes16.fromHexString("0x000000000000000a000000000000000b"); - Bytes16 expectedLow = Bytes16.fromHexString("0x000000000000000c000000000000000d"); - - assertThat(baseBytes.getBytes32()).isEqualTo(bytes32); - assertThat(baseBytes.getLow()).isEqualTo(expectedLow); - assertThat(baseBytes.getHigh()).isEqualTo(expectedHigh); - } - - @Test - public void getRangeTest() { - Bytes firstByte = Bytes.fromHexString("0x000000000000000a"); - Bytes secondByte = Bytes.fromHexString("0x000000000000000b"); - Bytes thirdByte = Bytes.fromHexString("0x000000000000000c"); - Bytes fourthByte = Bytes.fromHexString("0x000000000000000d"); - Bytes32 bytes32 = Bytes32.wrap(Bytes.concatenate(firstByte, secondByte, thirdByte, fourthByte)); - - BaseTheta baseTheta = BaseTheta.fromBytes32(bytes32); - - assertThat(baseTheta.getRange(3, 6, 2)).isEqualTo(Bytes.fromHexString("0x000a")); - assertThat(baseTheta.getRange(1, 5, 3)).isEqualTo(Bytes.fromHexString("0x00000c")); - assertThat(baseTheta.getRange(1, 0, 1)).isEqualTo(Bytes.fromHexString("0x00")); - } - - @Test - public void getTest() { - Bytes firstByte = Bytes.fromHexString("0x000000000000000a"); // baseTheta[3] - Bytes secondByte = Bytes.fromHexString("0x000000000000000b"); // baseTheta[2] - Bytes thirdByte = Bytes.fromHexString("0x000000000000000c"); // baseTheta[1] - Bytes fourthByte = Bytes.fromHexString("0x000000000000000d"); // baseTheta[0] - Bytes32 bytes32 = Bytes32.wrap(Bytes.concatenate(firstByte, secondByte, thirdByte, fourthByte)); - - BaseTheta baseTheta = BaseTheta.fromBytes32(bytes32); - - assertThat(baseTheta.get(0, 7)).isEqualTo(Bytes.fromHexString("0x0d").get(0)); // single byte - assertThat(baseTheta.get(2, 7)).isEqualTo(Bytes.fromHexString("0x0b").get(0)); // single byte - } - - @Test - public void setTest() { - Bytes firstByte = Bytes.fromHexString("0x000000000000000a"); - Bytes secondByte = Bytes.fromHexString("0x000000000000000b"); - Bytes thirdByte = Bytes.fromHexString("0x000000000000000c"); - Bytes fourthByte = Bytes.fromHexString("0x000000000000000d"); - Bytes32 bytes32 = Bytes32.wrap(Bytes.concatenate(firstByte, secondByte, thirdByte, fourthByte)); - - BaseTheta baseTheta = BaseTheta.fromBytes32(bytes32); - - // equal before - baseTheta.set(0, 7, fourthByte.get(0)); // 00 - baseTheta.set(3, 0, fourthByte.get(7)); // 0d - - assertThat(baseTheta.get(0)).isEqualTo(Bytes.fromHexString("0x0000000000000000")); - assertThat(baseTheta.get(3)).isEqualTo(Bytes.fromHexString("0x0d0000000000000a")); - - // equal after modifications - assertThat(baseTheta.get(0, 7)).isZero(); - assertThat(baseTheta.get(2, 7)).isEqualTo(Bytes.fromHexString("0x0b").get(0)); - assertThat(baseTheta.get(3, 0)).isEqualTo(Bytes.fromHexString("0x0d").get(0)); - } - - @Test - public void setBytesTest() { - BaseTheta aBaseTheta = BaseTheta.fromBytes32(UInt256.valueOf(43532)); - - Bytes a0 = Bytes.fromHexString("0x000000000000aa0c"); - assertThat(aBaseTheta.get(0)).isEqualTo(a0); - assertThat(aBaseTheta.get(1).isZero()).isTrue(); - assertThat(aBaseTheta.get(2).isZero()).isTrue(); - assertThat(aBaseTheta.get(3).isZero()).isTrue(); - - Bytes b3 = Bytes.fromHexString("0x533a124790000000"); - Bytes b2 = Bytes.fromHexString("0xfaa47d49bf1d1e67"); - Bytes b1 = Bytes.fromHexString("0x952951f4425bf6f3"); - Bytes b0 = Bytes.fromHexString("0x0000000000d55835"); - Bytes32 bytes32 = Bytes32.wrap(Bytes.concatenate(b3, b2, b1, b0)); - BaseTheta bBaseTheta = BaseTheta.fromBytes32(bytes32); - - assertThat(bBaseTheta.get(3)).isEqualTo(b3); - assertThat(bBaseTheta.get(2)).isEqualTo(b2); - assertThat(bBaseTheta.get(1)).isEqualTo(b1); - assertThat(bBaseTheta.get(0)).isEqualTo(b0); - - bBaseTheta.setChunk(0, b3); - assertThat(bBaseTheta.get(0)).isEqualTo(b3); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/containers/StackedListTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/containers/StackedListTests.java deleted file mode 100644 index ffc0b4be7..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/containers/StackedListTests.java +++ /dev/null @@ -1,100 +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.containers; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.math.BigInteger; - -import com.google.common.collect.ImmutableList; -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.container.stacked.list.StackedList; -import net.consensys.linea.zktracer.module.add.AddOperation; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class StackedListTests { - private static final AddOperation ONE_PLUS_ONE = - new AddOperation( - OpCode.ADD, - Bytes.wrap(BigInteger.ONE.toByteArray()), - Bytes.wrap(BigInteger.ONE.toByteArray())); - - private static final AddOperation ONE_PLUS_TWO = - new AddOperation( - OpCode.ADD, - Bytes.wrap(BigInteger.ONE.toByteArray()), - Bytes.wrap(BigInteger.TWO.toByteArray())); - - @RequiredArgsConstructor - private static class IntegerModuleOperation extends ModuleOperation { - private final int x; - - @Override - protected int computeLineCount() { - return x; - } - } - - @Test - void testAddedToFront() { - final StackedList state = new StackedList<>(); - - state.enter(); - state.add(new IntegerModuleOperation(1)); - assertThat(state.lineCount()).isEqualTo(1); - - state.enter(); - state.add(new IntegerModuleOperation(3)); - assertThat(state.lineCount()).isEqualTo(4); - - state.pop(); - assertThat(state.lineCount()).isEqualTo(1); - } - - @Test - public void push() { - StackedList chunks = new StackedList<>(); - chunks.enter(); - - chunks.add(ONE_PLUS_ONE); - chunks.add(ONE_PLUS_ONE); - chunks.add(ONE_PLUS_ONE); - Assertions.assertEquals(3, chunks.size()); - chunks.pop(); - Assertions.assertEquals(0, chunks.size()); - } - - @Test - public void multiplePushPop() { - StackedList chunks = new StackedList<>(); - chunks.enter(); - chunks.add(ONE_PLUS_ONE); - chunks.add(ONE_PLUS_ONE); - Assertions.assertEquals(2, chunks.size()); - - chunks.enter(); - chunks.add(ONE_PLUS_ONE); - Assertions.assertEquals(3, chunks.size()); - chunks.add(ONE_PLUS_TWO); - Assertions.assertEquals(4, chunks.size()); - chunks.pop(); - Assertions.assertEquals(2, ImmutableList.copyOf(chunks.iterator()).size()); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/containers/StackedSetTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/containers/StackedSetTests.java deleted file mode 100644 index 77e0e1a15..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/containers/StackedSetTests.java +++ /dev/null @@ -1,71 +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.containers; - -import java.math.BigInteger; - -import com.google.common.collect.ImmutableList; -import net.consensys.linea.zktracer.container.stacked.set.StackedSet; -import net.consensys.linea.zktracer.module.add.AddOperation; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class StackedSetTests { - - private static final AddOperation ONE_PLUS_ONE = - new AddOperation( - OpCode.ADD, - Bytes.wrap(BigInteger.ONE.toByteArray()), - Bytes.wrap(BigInteger.ONE.toByteArray())); - - private static final AddOperation ONE_PLUS_TWO = - new AddOperation( - OpCode.ADD, - Bytes.wrap(BigInteger.ONE.toByteArray()), - Bytes.wrap(BigInteger.TWO.toByteArray())); - - @Test - public void push() { - StackedSet chunks = new StackedSet<>(); - chunks.enter(); - - chunks.add(ONE_PLUS_ONE); - chunks.add(ONE_PLUS_ONE); - chunks.add(ONE_PLUS_ONE); - Assertions.assertEquals(1, chunks.size()); - chunks.pop(); - Assertions.assertEquals(0, chunks.size()); - } - - @Test - public void multiplePushPop() { - StackedSet chunks = new StackedSet<>(); - chunks.enter(); - chunks.add(ONE_PLUS_ONE); - chunks.add(ONE_PLUS_ONE); - Assertions.assertEquals(1, chunks.size()); - - chunks.enter(); - chunks.add(ONE_PLUS_ONE); - Assertions.assertEquals(1, chunks.size()); - chunks.add(ONE_PLUS_TWO); - Assertions.assertEquals(2, chunks.size()); - chunks.pop(); - Assertions.assertEquals(1, ImmutableList.copyOf(chunks.iterator()).size()); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/EcDataTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/EcDataTest.java deleted file mode 100644 index 7be7baaca..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/EcDataTest.java +++ /dev/null @@ -1,41 +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; - -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 EcDataTest { - @Test - void testEcData() { - BytecodeRunner.of( - Bytes.fromHexString( - "608060405234801561001057600080fd5b5061004a6001601b6001620f00007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe610b9760201b60201c565b61005757610056610e05565b5b61006f60016019600060016000610b9760201b60201c565b61007c5761007b610e05565b5b6100936001601e6001806000610b9760201b60201c565b6100a05761009f610e05565b5b6100d76001601b60017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000610b9760201b60201c565b6100e4576100e3610e05565b5b610152600160027f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd476101169190610e6d565b600160027f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd476101459190610e6d565b6003610bd260201b60201c565b61015f5761015e610e05565b5b610176600080600160026000610bd260201b60201c565b61018357610182610e05565b5b6101c5600060018060027f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd476101b89190610e6d565b6000610bd260201b60201c565b156101d3576101d2610e05565b5b6102146000806001807f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd476102079190610ea1565b6000610bd260201b60201c565b1561022257610221610e05565b5b610283600160027f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd476102549190610e6d565b610f007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610c0c60201b60201c565b6102905761028f610e05565b5b6102d0600160027f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd476102c29190610e6d565b600080610c0c60201b60201c565b6102dd576102dc610e05565b5b6102f260008060036000610c0c60201b60201c565b6102ff576102fe610e05565b5b6103156000600460036000610c0c60201b60201c565b1561032357610322610e05565b5b61033860006004600080610c0c60201b60201c565b1561034657610345610e05565b5b60006040518060c001604052806001815260200160027f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd476103879190610e6d565b81526020016000815260200160008152602001600081526020016000815250905060006040518060c001604052806001815260200160027f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd476103e99190610e6d565b81526020017f1800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed81526020017f198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c281526020017f12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa81526020017f090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b815250905060006040518060c0016040528060008152602001600081526020017f1800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed81526020017f198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c281526020017f12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa81526020017f090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b815250905060006040518060c001604052806000815260200160008152602001600181526020017f198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c281526020017f12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa81526020017f090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b815250905060006040518060c0016040528060008152602001600c81526020017f1800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed81526020017f198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c281526020017f12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa81526020017f090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b815250905060008067ffffffffffffffff81111561069c5761069b610ed5565b5b6040519080825280602002602001820160405280156106d557816020015b6106c2610dcf565b8152602001906001900390816106ba5790505b5090506106e9816000610c4060201b60201c565b6106f6576106f5610e05565b5b600167ffffffffffffffff81111561071157610710610ed5565b5b60405190808252806020026020018201604052801561074a57816020015b610737610dcf565b81526020019060019003908161072f5790505b509050858160008151811061076257610761610f04565b5b602002602001018190525061077e816000610c4060201b60201c565b61078b5761078a610e05565b5b85816000815181106107a05761079f610f04565b5b6020026020010181905250600267ffffffffffffffff8111156107c6576107c5610ed5565b5b6040519080825280602002602001820160405280156107ff57816020015b6107ec610dcf565b8152602001906001900390816107e45790505b509050858160008151811061081757610816610f04565b5b6020026020010181905250848160018151811061083757610836610f04565b5b6020026020010181905250610853816000610c4060201b60201c565b6108605761085f610e05565b5b61087181600a610c4060201b60201c565b1561087f5761087e610e05565b5b828160018151811061089457610893610f04565b5b60200260200101819052506108b0816000610c4060201b60201c565b156108be576108bd610e05565b5b600367ffffffffffffffff8111156108d9576108d8610ed5565b5b60405190808252806020026020018201604052801561091257816020015b6108ff610dcf565b8152602001906001900390816108f75790505b509050858160008151811061092a57610929610f04565b5b6020026020010181905250848160018151811061094a57610949610f04565b5b6020026020010181905250838160028151811061096a57610969610f04565b5b6020026020010181905250610986816000610c4060201b60201c565b61099357610992610e05565b5b6109a4816001610c4060201b60201c565b156109b2576109b1610e05565b5b6109e2817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610c4060201b60201c565b156109f0576109ef610e05565b5b8181600281518110610a0557610a04610f04565b5b6020026020010181905250610a21816000610c4060201b60201c565b15610a2f57610a2e610e05565b5b600a67ffffffffffffffff811115610a4a57610a49610ed5565b5b604051908082528060200260200182016040528015610a8357816020015b610a70610dcf565b815260200190600190039081610a685790505b50905060005b8151811015610b36576000600382610aa19190610f62565b03610aca5786828281518110610aba57610ab9610f04565b5b6020026020010181905250610b23565b6001600382610ad99190610f62565b03610b025785828281518110610af257610af1610f04565b5b6020026020010181905250610b22565b84828281518110610b1657610b15610f04565b5b60200260200101819052505b5b8080610b2e90610f93565b915050610a89565b50610b48816000610c4060201b60201c565b610b5557610b54610e05565b5b60006040518060400160405280600e81526020017f7a6b2d65766d206973206c6966650000000000000000000000000000000000008152509050805160208201f35b600060405186815285602082015284604082015283606082015260008084608001836001610bb8fa9150608081016040525095945050505050565b6000604051868152856020820152846040820152836060820152600080846080018360066096fa9150608081016040525095945050505050565b600060405185815284602082015283604082015260008084606001836007611770fa91506060810160405250949350505050565b60008061afc884516184d0610c559190610fdb565b610c5f9190610ea1565b90506000604051905060005b8551811015610d91576000868281518110610c8957610c88610f04565b5b60200260200101516000015190506000878381518110610cac57610cab610f04565b5b60200260200101516020015190506000888481518110610ccf57610cce610f04565b5b60200260200101516040015190506000898581518110610cf257610cf1610f04565b5b602002602001015160600151905060008a8681518110610d1557610d14610f04565b5b602002602001015160800151905060008b8781518110610d3857610d37610f04565b5b602002602001015160a0015190508660c00286818a015285602082018a015283604082018a015284606082018a015281608082018a01528260a082018a0152505050505050508080610d8990610f93565b915050610c6b565b50600060c08651610da29190610fdb565b905060008183610db29190610ea1565b905060008087840185600888fa9450806040525050505092915050565b6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052600160045260246000fd5b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610e7882610e34565b9150610e8383610e34565b9250828203905081811115610e9b57610e9a610e3e565b5b92915050565b6000610eac82610e34565b9150610eb783610e34565b9250828201905080821115610ecf57610ece610e3e565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000610f6d82610e34565b9150610f7883610e34565b925082610f8857610f87610f33565b5b828206905092915050565b6000610f9e82610e34565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610fd057610fcf610e3e565b5b600182019050919050565b6000610fe682610e34565b9150610ff183610e34565b9250828202610fff81610e34565b9150828204841483151761101657611015610e3e565b5b509291505056fe")) - .run(); - } - - @Test - void testEcRecoverWithEmptyExt() { - BytecodeRunner.of( - Bytes.fromHexString( - "6080604052348015600f57600080fd5b5060476001601b6001620f00007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe609360201b60201c565b605157605060ce565b5b60006040518060400160405280600e81526020017f7a6b2d65766d206973206c6966650000000000000000000000000000000000008152509050805160208201f35b600060405186815285602082015284604082015283606082015260008084608001836001610bb8fa9150608081016040525095945050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052600160045260246000fdfe")) - .run(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/add/addTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/add/addTest.java deleted file mode 100644 index 77ee5a457..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/add/addTest.java +++ /dev/null @@ -1,106 +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.add; - -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 addTest { - @Test - void testSmallZeroAdd() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.of(0xF1)) - .push(Bytes.EMPTY) - .op(OpCode.ADD) - .compile()) - .run(); - } - - @Test - void testSmallZeroSub() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.of(0xF1)) - .push(Bytes.EMPTY) - .op(OpCode.SUB) - .compile()) - .run(); - } - - @Test - void testOverflowLoAdd() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.fromHexString("0xF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF")) - .push(Bytes.fromHexString("0xE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF")) - .op(OpCode.ADD) - .compile()) - .run(); - } - - @Test - void testHugeSmallAdd() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.repeat((byte) 0xFF, 32)) - .push(Bytes.of(2)) - .op(OpCode.ADD) - .compile()) - .run(); - } - - @Test - void testOverFlowHiAdd() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push( - Bytes.concatenate(Bytes.repeat((byte) 0xFF, 16), Bytes.repeat((byte) 0x01, 16))) - .push( - Bytes.concatenate(Bytes.repeat((byte) 0x02, 16), Bytes.repeat((byte) 0x01, 16))) - .op(OpCode.ADD) - .compile()) - .run(); - } - - @Test - void testSmallHugeSub() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.of(2)) - .push(Bytes.repeat((byte) 0xFF, 32)) - .op(OpCode.SUB) - .compile()) - .run(); - } - - @Test - void testHugeSmallSub() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.repeat((byte) 0xFF, 32)) - .push(Bytes.of(2)) - .op(OpCode.SUB) - .compile()) - .run(); - } -} 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 deleted file mode 100644 index ab361a719..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java +++ /dev/null @@ -1,60 +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.bin; - -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.units.bigints.UInt256; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(EvmExtension.class) -public class BinTest { - @Test - public void edgeCase() { - BytecodeRunner.of(BytecodeCompiler.newProgram().push(0xf0).push(0xf0).op(OpCode.AND).compile()) - .run(); - } - - @Test - void testSignedSignextend() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .immediate(UInt256.MAX_VALUE) - .immediate(UInt256.MAX_VALUE) - .op(OpCode.SIGNEXTEND) - .compile()) - .run(); - - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .immediate(UInt256.valueOf(31)) - .immediate(UInt256.MAX_VALUE) - .op(OpCode.SIGNEXTEND) - .compile()) - .run(); - - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .immediate(UInt256.valueOf(32)) - .immediate(UInt256.MAX_VALUE) - .op(OpCode.SIGNEXTEND) - .compile()) - .run(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ext/TestDuplicatedOperations.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ext/TestDuplicatedOperations.java deleted file mode 100644 index f9a5917f9..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ext/TestDuplicatedOperations.java +++ /dev/null @@ -1,53 +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.ext; - -import static org.assertj.core.api.Assertions.assertThat; - -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 TestDuplicatedOperations { - @Test - void testDuplicate() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push( - Bytes.fromHexString( - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .push(0) - .push(0) - .op(OpCode.MULMOD) - .push( - Bytes.fromHexString( - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .push(0) - .push(0) - .op(OpCode.MULMOD) - .compile()) - .zkTracerValidator( - zkTracer -> { - assertThat(zkTracer.getModulesLineCount().get("EXT")).isEqualTo(9); - }) - .run(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/CallEmptyNoStopTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/CallEmptyNoStopTest.java deleted file mode 100644 index a61f2435c..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/CallEmptyNoStopTest.java +++ /dev/null @@ -1,96 +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 static org.assertj.core.api.Assertions.assertThat; - -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.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.Wei; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -/** Ensure that calling a contract with empty code does not generate a virtual STOP trace */ -@ExtendWith(EvmExtension.class) -public class CallEmptyNoStopTest { - @Test - void test() { - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - - ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); - - ToyAccount receiverAccount = - ToyAccount.builder() - .balance(Wei.fromEth(1)) - .nonce(6) - .address(Address.fromHexString("0x111111")) - .code( - BytecodeCompiler.newProgram() - .push(0) // retSize - .push(0) // retOffset - .push(0) // argsSize - .push(0) // argsOffset - .push(10) // value - .push(0x222222) // address - .push(10000) // gas - .op(OpCode.CALL) - .compile()) - .build(); - - ToyAccount emptyCodeAccount = - ToyAccount.builder() - .balance(Wei.ONE) - .nonce(1) - .address(Address.fromHexString("0x222222")) - .code(Bytes.EMPTY) - .build(); - - Transaction tx = - ToyTransaction.builder().sender(senderAccount).to(receiverAccount).keyPair(keyPair).build(); - - ToyWorld toyWorld = - ToyWorld.builder() - .accounts(List.of(senderAccount, receiverAccount, emptyCodeAccount)) - .build(); - - ToyExecutionEnvironment.builder() - .toyWorld(toyWorld) - .transaction(tx) - .zkTracerValidator( - zkTracer -> { - // Ensure we don't have any superfluous STOP - assertThat(zkTracer.getHub().state().currentTxTrace().getTrace().size()) - .isEqualTo(10); - }) - .build() - .run(); - } -} 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 d69e4066f..000000000 --- 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 deleted file mode 100644 index 70d6a4efa..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TestTwoPlusTwo.java +++ /dev/null @@ -1,52 +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 TestTwoPlusTwo { - @Test - void testAdd() { - BytecodeRunner.of(BytecodeCompiler.newProgram().push(32).push(27).op(OpCode.ADD).compile()) - .run(); - } - - @Test - void testAssembler() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .assemble( - """ - ; Perform some addition - PUSH8 02 - PUSH32 0x1234 - ADD - """) - .compile()) - .run(); - } - - @Test - void testBreakingCall() { - BytecodeRunner.of(BytecodeCompiler.newProgram().push(32).op(OpCode.CALL).compile()).run(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTest.java deleted file mode 100644 index 0e10b9acb..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTest.java +++ /dev/null @@ -1,54 +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.mod; - -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.units.bigints.UInt256; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(EvmExtension.class) -public class ModTest { - @Test - void testSignedSmod() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .immediate(UInt256.MAX_VALUE) - .immediate(UInt256.MAX_VALUE) - .op(OpCode.SMOD) - .compile()) - .run(); - - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .immediate(UInt256.valueOf(132)) - .immediate(UInt256.MAX_VALUE) - .op(OpCode.SMOD) - .compile()) - .run(); - - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .immediate(UInt256.MAX_VALUE) - .immediate(UInt256.valueOf(132)) - .op(OpCode.SMOD) - .compile()) - .run(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTracerTest.java deleted file mode 100644 index ce0dc6695..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTracerTest.java +++ /dev/null @@ -1,48 +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.mod; - -import java.util.List; -import java.util.stream.Stream; - -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.testing.DynamicTests; -import net.consensys.linea.zktracer.testing.OpcodeCall; -import org.apache.tuweni.units.bigints.UInt256; -import org.junit.jupiter.api.DynamicTest; -import org.junit.jupiter.api.TestFactory; - -class ModTracerTest { - private static final Module MODULE = new Mod(); - private static final DynamicTests DYN_TESTS = DynamicTests.forModule(MODULE); - - @TestFactory - Stream runDynamicTests() { - return DYN_TESTS.testCase("non random arguments test", provideNonRandomArguments()).run(); - } - - private List provideNonRandomArguments() { - return DYN_TESTS.newModuleArgumentsProvider( - (testCases, opCode) -> { - for (int k = 1; k <= 4; k++) { - for (int i = 1; i <= 4; i++) { - testCases.add( - new OpcodeCall(opCode, List.of(UInt256.valueOf(i), UInt256.valueOf(k)))); - } - } - }); - } -} 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 deleted file mode 100644 index d71d00310..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java +++ /dev/null @@ -1,594 +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.mxp; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Random; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.MxpType; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; -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.EWord; -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; - -// https://github.com/Consensys/linea-besu-plugin/issues/197 - -@ExtendWith(EvmExtension.class) -public class MxpTest { - private static final Random RAND = new Random(123456789123456L); - public static final EWord TWO_POW_128 = EWord.of(EWord.ONE.shiftLeft(128)); - public static final EWord TWO_POW_32 = EWord.of(EWord.ONE.shiftLeft(32)); - - // Some OpCodes are not interesting with random arguments, so we skip them in random testing part - final OpCode[] opCodesType1 = new OpCode[] {OpCode.MSIZE}; - final OpCode[] opCodesType2 = new OpCode[] {OpCode.MLOAD, OpCode.MSTORE}; - final OpCode[] opCodesType3 = new OpCode[] {OpCode.MSTORE8}; - final OpCode[] opCodesType4 = - new OpCode[] { - OpCode.LOG0, - OpCode.LOG1, - OpCode.LOG2, - OpCode.LOG3, - OpCode.LOG4, - OpCode.SHA3, - OpCode.CODECOPY, - OpCode.CALLDATACOPY, - OpCode.EXTCODECOPY, - OpCode.CREATE, - OpCode.CREATE2 - }; // OpCode.COPY-type (Type 4) and OpCode.CALL-type (Type 5) are tested via TestCall() - // instead of TestMxpRandom - - final OpCode[] opCodesHalting = new OpCode[] {OpCode.RETURN, OpCode.REVERT}; - - @Test - void TestMxpSimple() { - BytecodeRunner.of( - Bytes.fromHexString( - "6080604052600160115260885160ff6101ff2060018060018060876102ffa4600080")) - .run(); - } - - @Test - void TestMxpSimple2() { - BytecodeRunner.of( - Bytes.fromHexString( - "6080604052600060405161001290610097565b604051809103906000f08015801561002e573d6000803e3d6000fd5b5090508073ffffffffffffffffffffffffffffffffffffffff166326121ff06040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561007957600080fd5b505af115801561008d573d6000803e3d6000fd5b50505050506100a3565b60a2806100f083390190565b603f806100b16000396000f3fe6080604052600080fdfea2646970667358221220b4fef08f9e3ab3367b0614cb11cb9ec36fd74ac9fad781c8b011a36f0eb2bb6b64736f6c634300081200336080604052348015600f57600080fd5b5060848061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c806326121ff014602d575b600080fd5b60336035565b005b60018060018060876102ffa46013600f63ffffffff015256fea2646970667358221220dbb28de6633684f549a1b6c2b223dd89447bc213763fd3ae0c0b113d712d4bb164736f6c63430008120033")) - .run(); - } - - @Test - void TestMxpEdgeCaseMXPX() { - BytecodeRunner.of( - Bytes.fromHexString( - "608060405234801561001057600080fd5b50600060405161001f906101c9565b604051809103906000f08015801561003b573d6000803e3d6000fd5b50905060005a905060006014905060005b818110156101c0578373ffffffffffffffffffffffffffffffffffffffff166326121ff083600461007d919061020f565b856100889190610280565b6040518263ffffffff1660e01b8152600401600060405180830381600088803b1580156100b457600080fd5b5087f1935050505080156100c6575060015b508373ffffffffffffffffffffffffffffffffffffffff1663e2179b8e8360046100f0919061020f565b856100fb9190610280565b6040518263ffffffff1660e01b8152600401600060405180830381600088803b15801561012757600080fd5b5087f193505050508015610139575060015b508373ffffffffffffffffffffffffffffffffffffffff1663b8c9d365836004610163919061020f565b8561016e9190610280565b6040518263ffffffff1660e01b8152600401600060405180830381600088803b15801561019a57600080fd5b5087f1935050505080156101ac575060015b5080806101b8906102b1565b91505061004c565b505050506102f9565b6102e58061034683390190565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061021a826101d6565b9150610225836101d6565b9250828202610233816101d6565b9150828204841483151761024a576102496101e0565b5b5092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061028b826101d6565b9150610296836101d6565b9250826102a6576102a5610251565b5b828204905092915050565b60006102bc826101d6565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036102ee576102ed6101e0565b5b600182019050919050565b603f806103076000396000f3fe6080604052600080fdfea264697066735822122033f6db328248c8354d1fe00a403cabce83502d4a3c86a6f7856dcf4f085d972264736f6c63430008120033608060405234801561001057600080fd5b506102c5806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806326121ff014610046578063b8c9d36514610050578063e2179b8e1461005a575b600080fd5b61004e610064565b005b6100586100a4565b005b6100626100b7565b005b600061006e6100dc565b9050600061007a6100dc565b905060006100866100dc565b905060006100926100dc565b9050808284866000805af15050505050565b60006100ae6100dc565b90506013815250565b60006100c16100dc565b905060006100cd6100dc565b90506001806001808486a45050565b6000806100e9600361015a565b905060008103610105576100fd600361015a565b915050610157565b6001810361012c57610117600361015a565b61ffff61012491906101d1565b915050610157565b600281036101555761013e600361015a565b63ffffffff61014d91906101d1565b915050610157565b505b90565b6000815a60405160200161016e9190610214565b6040516020818303038152906040528051906020012060001c610191919061025e565b9050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006101dc82610198565b91506101e783610198565b92508282019050808211156101ff576101fe6101a2565b5b92915050565b61020e81610198565b82525050565b60006020820190506102296000830184610205565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061026982610198565b915061027483610198565b9250826102845761028361022f565b5b82820690509291505056fea26469706673582212204bdb26312b4759dfceb17e8aca627599aafa7fb39df036d87c2077c49f13806b64736f6c63430008120033")) - .run(); - } - - @Test - void TestMxpRandom() { - // Testing a random program - BytecodeCompiler program = BytecodeCompiler.newProgram(); - final int INSTRUCTION_COUNT = 4096; - for (int i = 0; i < INSTRUCTION_COUNT; i++) { - boolean isHalting = i == INSTRUCTION_COUNT - 1; - triggerNonTrivialOrNoop(program, isHalting); - } - BytecodeRunner.of(program.compile()).run(); - } - - @Test - void TestMxpRandomTriggerMxpx() { - // Testing a random program - BytecodeCompiler program = BytecodeCompiler.newProgram(); - final int INSTRUCTION_COUNT = 256; - for (int i = 0; i < INSTRUCTION_COUNT; i++) { - boolean isHalting = i == INSTRUCTION_COUNT - 1; - triggerNonTrivialOrNoop(program, isHalting); - } - triggerNonTrivialButMxpxOrRoob(program, false, false); - BytecodeRunner.of(program.compile()).run(); - } - - @Test - void TestMxpRandomTriggerRoob() { - // Testing a random program - BytecodeCompiler program = BytecodeCompiler.newProgram(); - final int INSTRUCTION_COUNT = 256; - for (int i = 0; i < INSTRUCTION_COUNT; i++) { - boolean isHalting = i == INSTRUCTION_COUNT - 1; - triggerNonTrivialOrNoop(program, isHalting); - } - triggerNonTrivialButMxpxOrRoob(program, false, true); - BytecodeRunner.of(program.compile()).run(); - } - - @Test - void TestMxpxOrRoob() { - final int REPETITIONS = 5; - for (int i = 0; i < REPETITIONS; i++) { - BytecodeCompiler program = BytecodeCompiler.newProgram(); - boolean isHalting = RAND.nextInt(2) == 0; - boolean triggerRoob = RAND.nextInt(2) == 0; - triggerNonTrivialButMxpxOrRoob(program, isHalting, triggerRoob); - BytecodeRunner.of(program.compile()).run(); - } - } - - @Test - void TestMxpRandomAdvanced() { - // Testing a random program that contains creates with meaning random arguments - Bytes INIT = getRandomINITForCreate(); // This is the value given as an argument to CREATE - - BytecodeCompiler program = BytecodeCompiler.newProgram(); - int INSTRUCTION_COUNT = 256; - for (int i = 0; i < INSTRUCTION_COUNT; i++) { - boolean isHalting = i == INSTRUCTION_COUNT - 1; - triggerNonTrivialOrNoop(program, isHalting, INIT); - } - BytecodeRunner.of(program.compile()).run(); - } - - @Test - void TestCall() { - /* NOTE: The contracts in this test 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 = - ToyAccount.builder().balance(Wei.fromEth(100)).nonce(1).address(userAddress).build(); - - // A - ToyAccount contractAAccount = - ToyAccount.builder() - .balance(Wei.fromEth(100)) - .nonce(2) - .address(Address.fromHexString("0x7b96aF9Bd211cBf6BA5b0dd53aa61Dc5806b6AcE")) - .code( - Bytes.fromHexString( - "608060405234801561001057600080fd5b506004361061002b5760003560e01c80631b4d679d14610030575b600080fd5b61004a60048036038101906100459190610380565b61004c565b005b8173ffffffffffffffffffffffffffffffffffffffff1663bcf7277860146104576040518363ffffffff1660e01b815260040161008a929190610459565b600060405180830381600087803b1580156100a457600080fd5b505af11580156100b8573d6000803e3d6000fd5b505050508473ffffffffffffffffffffffffffffffffffffffff1663d602bd5c836040518263ffffffff1660e01b81526004016100f59190610491565b600060405180830381600087803b15801561010f57600080fd5b505af1158015610123573d6000803e3d6000fd5b505050508173ffffffffffffffffffffffffffffffffffffffff1663bcf7277860146108ae6040518363ffffffff1660e01b81526004016101659291906104e7565b600060405180830381600087803b15801561017f57600080fd5b505af1158015610193573d6000803e3d6000fd5b505050508373ffffffffffffffffffffffffffffffffffffffff1663e450cc8c8685856040518463ffffffff1660e01b81526004016101d493929190610510565b600060405180830381600087803b1580156101ee57600080fd5b505af1158015610202573d6000803e3d6000fd5b505050508173ffffffffffffffffffffffffffffffffffffffff1663bcf727786014610d056040518363ffffffff1660e01b8152600401610244929190610582565b600060405180830381600087803b15801561025e57600080fd5b505af1158015610272573d6000803e3d6000fd5b505050508173ffffffffffffffffffffffffffffffffffffffff1663c176f69a826040518263ffffffff1660e01b81526004016102af9190610491565b600060405180830381600087803b1580156102c957600080fd5b505af11580156102dd573d6000803e3d6000fd5b505050507f1e5d1a4c4137b394167b12a8275dfbf8d991f67b2951c477557b8ad000a48cac60405161030e90610608565b60405180910390a15050505050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061034d82610322565b9050919050565b61035d81610342565b811461036857600080fd5b50565b60008135905061037a81610354565b92915050565b600080600080600060a0868803121561039c5761039b61031d565b5b60006103aa8882890161036b565b95505060206103bb8882890161036b565b94505060406103cc8882890161036b565b93505060606103dd8882890161036b565b92505060806103ee8882890161036b565b9150509295509295909350565b6000819050919050565b61040e816103fb565b82525050565b6000819050919050565b6000819050919050565b600061044361043e61043984610414565b61041e565b6103fb565b9050919050565b61045381610428565b82525050565b600060408201905061046e6000830185610405565b61047b602083018461044a565b9392505050565b61048b81610342565b82525050565b60006020820190506104a66000830184610482565b92915050565b6000819050919050565b60006104d16104cc6104c7846104ac565b61041e565b6103fb565b9050919050565b6104e1816104b6565b82525050565b60006040820190506104fc6000830185610405565b61050960208301846104d8565b9392505050565b60006060820190506105256000830186610482565b6105326020830185610482565b61053f6040830184610482565b949350505050565b6000819050919050565b600061056c61056761056284610547565b61041e565b6103fb565b9050919050565b61057c81610551565b82525050565b60006040820190506105976000830185610405565b6105a46020830184610573565b9392505050565b600082825260208201905092915050565b7f656e642041000000000000000000000000000000000000000000000000000000600082015250565b60006105f26005836105ab565b91506105fd826105bc565b602082019050919050565b60006020820190508181036000830152610621816105e5565b905091905056fea2646970667358221220640d751b7d7fe08b426fcc44369630811e36d03ac711145444892f288ee4d4ef64736f6c63430008150033")) - .build(); - - // B - ToyAccount contractBAccount = - ToyAccount.builder() - .balance(Wei.fromEth(100)) - .nonce(3) - .address(Address.fromHexString("0x3328358128832A260C76A4141e19E2A943CD4B6D")) - .code( - Bytes.fromHexString( - "608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d602bd5c14610030575b600080fd5b61004a60048036038101906100459190610157565b61004c565b005b8073ffffffffffffffffffffffffffffffffffffffff1663bcf72778601461115c6040518363ffffffff1660e01b815260040161008a9291906101e2565b600060405180830381600087803b1580156100a457600080fd5b505af11580156100b8573d6000803e3d6000fd5b505050507f1e5d1a4c4137b394167b12a8275dfbf8d991f67b2951c477557b8ad000a48cac6040516100e990610268565b60405180910390a150565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610124826100f9565b9050919050565b61013481610119565b811461013f57600080fd5b50565b6000813590506101518161012b565b92915050565b60006020828403121561016d5761016c6100f4565b5b600061017b84828501610142565b91505092915050565b6000819050919050565b61019781610184565b82525050565b6000819050919050565b6000819050919050565b60006101cc6101c76101c28461019d565b6101a7565b610184565b9050919050565b6101dc816101b1565b82525050565b60006040820190506101f7600083018561018e565b61020460208301846101d3565b9392505050565b600082825260208201905092915050565b7f656e642042000000000000000000000000000000000000000000000000000000600082015250565b600061025260058361020b565b915061025d8261021c565b602082019050919050565b6000602082019050818103600083015261028181610245565b905091905056fea26469706673582212209406457293fbcd172f20479072cec0849029c9cd8a8a20e6ba723917c76bde9464736f6c63430008150033")) - .build(); - - // C - ToyAccount contractCAccount = - ToyAccount.builder() - .balance(Wei.fromEth(100)) - .nonce(4) - .address(Address.fromHexString("0x5e17b14ADd6c386305A32928F985b29bbA34Eff5")) - .code( - Bytes.fromHexString( - "608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e450cc8c14610030575b600080fd5b61004a6004803603810190610045919061030f565b61004c565b005b8073ffffffffffffffffffffffffffffffffffffffff1663bcf7277860146115b36040518363ffffffff1660e01b815260040161008a9291906103c0565b600060405180830381600087803b1580156100a457600080fd5b505af11580156100b8573d6000803e3d6000fd5b505050508273ffffffffffffffffffffffffffffffffffffffff1663d602bd5c826040518263ffffffff1660e01b81526004016100f591906103f8565b600060405180830381600087803b15801561010f57600080fd5b505af1158015610123573d6000803e3d6000fd5b505050508073ffffffffffffffffffffffffffffffffffffffff1663bcf727786014611a0a6040518363ffffffff1660e01b815260040161016592919061044e565b600060405180830381600087803b15801561017f57600080fd5b505af1158015610193573d6000803e3d6000fd5b505050508173ffffffffffffffffffffffffffffffffffffffff1663d602bd5c826040518263ffffffff1660e01b81526004016101d091906103f8565b600060405180830381600087803b1580156101ea57600080fd5b505af11580156101fe573d6000803e3d6000fd5b505050508073ffffffffffffffffffffffffffffffffffffffff1663bcf727786014611e616040518363ffffffff1660e01b81526004016102409291906104b2565b600060405180830381600087803b15801561025a57600080fd5b505af115801561026e573d6000803e3d6000fd5b505050507f1e5d1a4c4137b394167b12a8275dfbf8d991f67b2951c477557b8ad000a48cac60405161029f90610538565b60405180910390a1505050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006102dc826102b1565b9050919050565b6102ec816102d1565b81146102f757600080fd5b50565b600081359050610309816102e3565b92915050565b600080600060608486031215610328576103276102ac565b5b6000610336868287016102fa565b9350506020610347868287016102fa565b9250506040610358868287016102fa565b9150509250925092565b6000819050919050565b61037581610362565b82525050565b6000819050919050565b6000819050919050565b60006103aa6103a56103a08461037b565b610385565b610362565b9050919050565b6103ba8161038f565b82525050565b60006040820190506103d5600083018561036c565b6103e260208301846103b1565b9392505050565b6103f2816102d1565b82525050565b600060208201905061040d60008301846103e9565b92915050565b6000819050919050565b600061043861043361042e84610413565b610385565b610362565b9050919050565b6104488161041d565b82525050565b6000604082019050610463600083018561036c565b610470602083018461043f565b9392505050565b6000819050919050565b600061049c61049761049284610477565b610385565b610362565b9050919050565b6104ac81610481565b82525050565b60006040820190506104c7600083018561036c565b6104d460208301846104a3565b9392505050565b600082825260208201905092915050565b7f656e642043000000000000000000000000000000000000000000000000000000600082015250565b60006105226005836104db565b915061052d826104ec565b602082019050919050565b6000602082019050818103600083015261055181610515565b905091905056fea2646970667358221220515b50fb324aff261b8083b11f8d5e7d0de2e50e0a6f77e3328a7b83aaf1c53864736f6c63430008150033")) - .build(); - - // D - ToyAccount contractDAccount = - ToyAccount.builder() - .balance(Wei.fromEth(100)) - .nonce(5) - .address(Address.fromHexString("0xe2899bddFD890e320e643044c6b95B9B0b84157A")) - .code( - Bytes.fromHexString( - "608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d602bd5c14610030575b600080fd5b61004a60048036038101906100459190610157565b61004c565b005b8073ffffffffffffffffffffffffffffffffffffffff1663bcf7277860146122b86040518363ffffffff1660e01b815260040161008a9291906101e2565b600060405180830381600087803b1580156100a457600080fd5b505af11580156100b8573d6000803e3d6000fd5b505050507f1e5d1a4c4137b394167b12a8275dfbf8d991f67b2951c477557b8ad000a48cac6040516100e990610268565b60405180910390a150565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610124826100f9565b9050919050565b61013481610119565b811461013f57600080fd5b50565b6000813590506101518161012b565b92915050565b60006020828403121561016d5761016c6100f4565b5b600061017b84828501610142565b91505092915050565b6000819050919050565b61019781610184565b82525050565b6000819050919050565b6000819050919050565b60006101cc6101c76101c28461019d565b6101a7565b610184565b9050919050565b6101dc816101b1565b82525050565b60006040820190506101f7600083018561018e565b61020460208301846101d3565b9392505050565b600082825260208201905092915050565b7f656e642044000000000000000000000000000000000000000000000000000000600082015250565b600061025260058361020b565b915061025d8261021c565b602082019050919050565b6000602082019050818103600083015261028181610245565b905091905056fea26469706673582212206f5a584fda0c1021ce78bcaa1e8c737359fbabfb27f80fc8460ee369eae4480864736f6c63430008150033")) - .build(); - - // MO1 - ToyAccount contractMO1Account = - ToyAccount.builder() - .balance(Wei.fromEth(100)) - .nonce(6) - .address(Address.fromHexString("0xD4Fc541236927E2EAf8F27606bD7309C1Fc2cbee")) - .code( - Bytes.fromHexString( - "608060405234801561001057600080fd5b50600436106100935760003560e01c8063c176f69a11610066578063c176f69a1461011e578063c6232f401461013a578063e366cbd214610156578063e79f469514610160578063ed61b8d41461017c57610093565b80633ceea8211461009857806390b02f8f146100b6578063a8f0ab79146100e6578063bcf7277814610102575b600080fd5b6100a06101ac565b6040516100ad9190610775565b60405180910390f35b6100d060048036038101906100cb91906107c1565b6101b9565b6040516100dd919061081a565b60405180910390f35b61010060048036038101906100fb91906107c1565b6101cb565b005b61011c600480360381019061011791906107c1565b6101d2565b005b61013860048036038101906101339190610893565b61045e565b005b610154600480360381019061014f91906108f9565b61054d565b005b61015e610554565b005b61017a60048036038101906101759190610893565b6105fb565b005b61019660048036038101906101919190610939565b6106e4565b6040516101a39190610775565b60405180910390f35b6000805990508091505090565b60008082842090508091505092915050565b8082525050565b8060008190555060018081905550600080600090505b83811015610458576101fa60066106f4565b915060008203610247577fe1b72bde44fcea72169114f1bcc1e99e59744d560e36a6e64a48ebedbcdb47eb604051610231906109c3565b60405180910390a16102416101ac565b50610445565b6001820361029d577fe1b72bde44fcea72169114f1bcc1e99e59744d560e36a6e64a48ebedbcdb47eb60405161027c90610a2f565b60405180910390a16102976102926140006106f4565b6106e4565b50610444565b6002820361031b577fe1b72bde44fcea72169114f1bcc1e99e59744d560e36a6e64a48ebedbcdb47eb6040516102d290610a9b565b60405180910390a16103166102e86140006106f4565b6103117fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6106f4565b6101cb565b610443565b60038203610399577fe1b72bde44fcea72169114f1bcc1e99e59744d560e36a6e64a48ebedbcdb47eb60405161035090610b07565b60405180910390a16103946103666140006106f4565b61038f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6106f4565b61054d565b610442565b600482036103e3577fe1b72bde44fcea72169114f1bcc1e99e59744d560e36a6e64a48ebedbcdb47eb6040516103ce90610b73565b60405180910390a16103de610554565b610441565b60058203610440577fe1b72bde44fcea72169114f1bcc1e99e59744d560e36a6e64a48ebedbcdb47eb60405161041890610bdf565b60405180910390a161043e61042e6140006106f4565b6104396140006106f4565b6101b9565b505b5b5b5b5b5b808061045090610c2e565b9150506101e8565b50505050565b7fe1b72bde44fcea72169114f1bcc1e99e59744d560e36a6e64a48ebedbcdb47eb60405161048b90610ce8565b60405180910390a18073ffffffffffffffffffffffffffffffffffffffff1663b17b2aba60006040518263ffffffff1660e01b81526004016104cd9190610d4d565b60006040518083038186803b1580156104e557600080fd5b505afa1580156104f9573d6000803e3d6000fd5b5050505060003d9050600061050f6140006106f4565b905060006105286001846105239190610d68565b6106f4565b90506000610540828561053b9190610d68565b6106f4565b90508082843e5050505050565b8082535050565b6000604067ffffffffffffffff81111561057157610570610d9c565b5b6040519080825280601f01601f1916602001820160405280156105a35781602001600182028036833780820191505090505b509050604051806060016040528060408152602001610ff16040913990507fafabcf2dd47e06a477a89e49c03f8ebe8e0a7e94f775b25bbb24227c9d0110b2816040516105f09190610e5b565b60405180910390a150565b7fe1b72bde44fcea72169114f1bcc1e99e59744d560e36a6e64a48ebedbcdb47eb60405161062890610eef565b60405180910390a18073ffffffffffffffffffffffffffffffffffffffff16639bbfe3b760006040518263ffffffff1660e01b815260040161066a9190610d4d565b60006040518083038186803b15801561068257600080fd5b505afa925050508015610693575060015b5060003d905060006106a66140006106f4565b905060006106bf6001846106ba9190610d68565b6106f4565b905060006106d782856106d29190610d68565b6106f4565b90508082843e5050505050565b6000808251905080915050919050565b60008060005460015460405160200161070e929190610f30565b60405160208183030381529060405280519060200120905060018060008282546107389190610f5c565b925050819055506000838260001c6107509190610fbf565b90508092505050919050565b6000819050919050565b61076f8161075c565b82525050565b600060208201905061078a6000830184610766565b92915050565b600080fd5b61079e8161075c565b81146107a957600080fd5b50565b6000813590506107bb81610795565b92915050565b600080604083850312156107d8576107d7610790565b5b60006107e6858286016107ac565b92505060206107f7858286016107ac565b9150509250929050565b6000819050919050565b61081481610801565b82525050565b600060208201905061082f600083018461080b565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061086082610835565b9050919050565b61087081610855565b811461087b57600080fd5b50565b60008135905061088d81610867565b92915050565b6000602082840312156108a9576108a8610790565b5b60006108b78482850161087e565b91505092915050565b600060ff82169050919050565b6108d6816108c0565b81146108e157600080fd5b50565b6000813590506108f3816108cd565b92915050565b600080604083850312156109105761090f610790565b5b600061091e858286016107ac565b925050602061092f858286016108e4565b9150509250929050565b60006020828403121561094f5761094e610790565b5b600061095d848285016107ac565b91505092915050565b600082825260208201905092915050565b7f6d73697a65457865630000000000000000000000000000000000000000000000600082015250565b60006109ad600983610966565b91506109b882610977565b602082019050919050565b600060208201905081810360008301526109dc816109a0565b9050919050565b7f6d6c6f6164457865630000000000000000000000000000000000000000000000600082015250565b6000610a19600983610966565b9150610a24826109e3565b602082019050919050565b60006020820190508181036000830152610a4881610a0c565b9050919050565b7f6d73746f72654578656300000000000000000000000000000000000000000000600082015250565b6000610a85600a83610966565b9150610a9082610a4f565b602082019050919050565b60006020820190508181036000830152610ab481610a78565b9050919050565b7f6d73746f72653845786563000000000000000000000000000000000000000000600082015250565b6000610af1600b83610966565b9150610afc82610abb565b602082019050919050565b60006020820190508181036000830152610b2081610ae4565b9050919050565b7f6c6f674578656300000000000000000000000000000000000000000000000000600082015250565b6000610b5d600783610966565b9150610b6882610b27565b602082019050919050565b60006020820190508181036000830152610b8c81610b50565b9050919050565b7f6b656363616b3235364578656300000000000000000000000000000000000000600082015250565b6000610bc9600d83610966565b9150610bd482610b93565b602082019050919050565b60006020820190508181036000830152610bf881610bbc565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610c398261075c565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610c6b57610c6a610bff565b5b600182019050919050565b7f72657475726e64617461636f707945786563202861667465722072657475726e60008201527f2900000000000000000000000000000000000000000000000000000000000000602082015250565b6000610cd2602183610966565b9150610cdd82610c76565b604082019050919050565b60006020820190508181036000830152610d0181610cc5565b9050919050565b6000819050919050565b6000819050919050565b6000610d37610d32610d2d84610d08565b610d12565b61075c565b9050919050565b610d4781610d1c565b82525050565b6000602082019050610d626000830184610d3e565b92915050565b6000610d738261075c565b9150610d7e8361075c565b9250828203905081811115610d9657610d95610bff565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600081519050919050565b600082825260208201905092915050565b60005b83811015610e05578082015181840152602081019050610dea565b60008484015250505050565b6000601f19601f8301169050919050565b6000610e2d82610dcb565b610e378185610dd6565b9350610e47818560208601610de7565b610e5081610e11565b840191505092915050565b60006020820190508181036000830152610e758184610e22565b905092915050565b7f72657475726e64617461636f707945786563202861667465722072657665727460008201527f2900000000000000000000000000000000000000000000000000000000000000602082015250565b6000610ed9602183610966565b9150610ee482610e7d565b604082019050919050565b60006020820190508181036000830152610f0881610ecc565b9050919050565b6000819050919050565b610f2a610f258261075c565b610f0f565b82525050565b6000610f3c8285610f19565b602082019150610f4c8284610f19565b6020820191508190509392505050565b6000610f678261075c565b9150610f728361075c565b9250828201905080821115610f8a57610f89610bff565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000610fca8261075c565b9150610fd58361075c565b925082610fe557610fe4610f90565b5b82820690509291505056feaaaa567890abcdef0123456789abcdef01234567890abcdef0123456789abcde1234567890abcdef0123456789abcdef01234567890abcdef0123456789affffa264697066735822122029ec0e0d1a390205eba0ff239d392c0855e3495413eccca5388bb8ea662dc23864736f6c63430008150033")) - .build(); - - // MO2 - ToyAccount contractMO2Account = - ToyAccount.builder() - .balance(Wei.fromEth(100)) - .nonce(6) - .address(Address.fromHexString("0x5FD6eB55D12E759a21C09eF703fe0CBa1DC9d88D")) - .code( - Bytes.fromHexString( - "608060405234801561001057600080fd5b50600436106100365760003560e01c80639bbfe3b71461003b578063b17b2aba14610057575b600080fd5b610055600480360381019061005091906101e2565b610073565b005b610071600480360381019061006c91906101e2565b61010d565b005b7fffffffffffffffff11111111111111112222222222222222333333333333333381527fffffffffffffffff44444444444444445555555555555555666666666666666660208201527fffffffffffffffff77777777777777778888888888888888999999999999999960408201527fffffffffffffffffaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbcccccccccccccccc6060820152608081fd5b7fffffffffffffffff11111111111111112222222222222222333333333333333381527fffffffffffffffff44444444444444445555555555555555666666666666666660208201527fffffffffffffffff77777777777777778888888888888888999999999999999960408201527fffffffffffffffffaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbcccccccccccccccc6060820152608081f35b600080fd5b6000819050919050565b6101bf816101ac565b81146101ca57600080fd5b50565b6000813590506101dc816101b6565b92915050565b6000602082840312156101f8576101f76101a7565b5b6000610206848285016101cd565b9150509291505056fea2646970667358221220f300591154e39b22544c8d3cb08095fe6bbaa5cfae4910cd3c0cd753f6e43b4764736f6c63430008150033")) - .build(); - - Transaction tx = - ToyTransaction.builder() - .sender(userAccount) - .to(contractAAccount) - .payload( - Bytes.fromHexString( - "0x1b4d679d0000000000000000000000003328358128832a260c76a4141e19e2a943cd4b6d0000000000000000000000005e17b14add6c386305a32928f985b29bba34eff5000000000000000000000000e2899bddfd890e320e643044c6b95b9b0b84157a000000000000000000000000d4fc541236927e2eaf8f27606bd7309c1fc2cbee0000000000000000000000005fd6eb55d12e759a21c09ef703fe0cba1dc9d88d")) - .transactionType(TransactionType.FRONTIER) - .gasLimit(0xffffffffL) - .value(Wei.ZERO) - .keyPair(keyPair) - .build(); - - ToyWorld toyWorld = - ToyWorld.builder() - .accounts( - List.of( - userAccount, - contractAAccount, - contractBAccount, - contractCAccount, - contractDAccount, - contractMO1Account, - contractMO2Account)) - .build(); - - ToyExecutionEnvironment.builder() - .toyWorld(toyWorld) - .transaction(tx) - .testValidator(x -> {}) - .build() - .run(); - } - - private Bytes getRandomINITForCreate() { - final int INSTRUCTION_COUNT_INIT = 256; - BytecodeCompiler INIT = BytecodeCompiler.newProgram(); - for (int i = 0; i < INSTRUCTION_COUNT_INIT; i++) { - boolean isHalting = i == INSTRUCTION_COUNT_INIT - 1; - triggerNonTrivialOrNoop(INIT, isHalting); - } - return INIT.compile(); - } - - private void triggerNonTrivialOrNoop(BytecodeCompiler program, boolean isHalting) { - triggerNonTrivialOrNoop(program, isHalting, Bytes.EMPTY); - } - - private void triggerNonTrivialOrNoop(BytecodeCompiler program, boolean isHalting, Bytes INIT) { - final float NOOP_PROB = 0.3f; - final int MAX_BYTE_SIZE = 2; - MxpType mxpType; - OpCode opCode; - - if (!isHalting) { - mxpType = MxpType.values()[RAND.nextInt(1, 5)]; // Type 1 to 4 excluding opCodeLast - opCode = getRandomOpCodeByType(mxpType); - } else { - mxpType = MxpType.TYPE_4; - opCode = opCodesHalting[RAND.nextInt(opCodesHalting.length)]; // opCodeLast - } - - // Generate as many random values as needed at most - EWord size1; - EWord offset1; - EWord offset2; - boolean roob; - boolean mxpx; - EWord value = EWord.of(getRandomBigIntegerByBytesSize(0, 4)); - Address address = getRandomBigIntegerByBytesSize(20, 20).toAddress(); - EWord salt = EWord.of(getRandomBigIntegerByBytesSize(0, 4)); - - // Keep generating random values until we are in the !roob && !mxpx case - do { - size1 = EWord.of(getRandomBigIntegerByBytesSize(0, MAX_BYTE_SIZE)); - offset1 = EWord.of(getRandomBigIntegerByBytesSize(0, MAX_BYTE_SIZE)); - offset2 = EWord.of(getRandomBigIntegerByBytesSize(0, MAX_BYTE_SIZE)); - - // NOOP case (except for Type2 and Type3 instructions) - if (mxpType != MxpType.TYPE_2 && mxpType != MxpType.TYPE_3) { - if (RAND.nextFloat() < NOOP_PROB) { - // One or both of the size parameters are equal to 0 (each scenario has the same - // probability) - size1 = EWord.ZERO; - final float offsetModifier = RAND.nextFloat(); - if (offsetModifier < 1 / 3f) { - // offset1 remains the same - } else if (offsetModifier > 2 / 3f) { - // offset1 is large - offset1 = EWord.of(getRandomBigIntegerByBytesSize(0, 16)); - } else { - // offset1 is huge - offset1 = EWord.of(getRandomBigIntegerByBytesSize(16, 32)); - } - } - } - - // size2 is irrelevant for this case - mxpx = isMxpx(mxpType, size1, offset1); - roob = isRoob(mxpType, size1, offset1); - if (roob || mxpx) { - throw new RuntimeException("Unexpected ROOB or MXPX"); - } - } while (roob || mxpx); - - switch (opCode) { - case MSIZE: - appendOpCodeCall(opCode, program); - break; - case MLOAD: - appendOpCodeCall(List.of(offset1), opCode, program); - program.op(OpCode.POP); - break; - case MSTORE, MSTORE8: - appendOpCodeCall(List.of(value, offset1), opCode, program); - break; - case LOG0, SHA3, RETURN, REVERT: // RETURN and REVERT are selected only when isHalting is true - appendOpCodeCall(List.of(size1, offset1), opCode, program); - if (opCode == OpCode.SHA3) { - program.op(OpCode.POP); - } - break; - case LOG1: - appendOpCodeCall( - Stream.concat(getRandomUpTo32BytesBigIntegers(1).stream(), Stream.of(size1, offset1)) - .collect(Collectors.toList()), - opCode, - program); - break; - case LOG2: - appendOpCodeCall( - Stream.concat(getRandomUpTo32BytesBigIntegers(2).stream(), Stream.of(size1, offset1)) - .collect(Collectors.toList()), - opCode, - program); - break; - case LOG3: - appendOpCodeCall( - Stream.concat(getRandomUpTo32BytesBigIntegers(3).stream(), Stream.of(size1, offset1)) - .collect(Collectors.toList()), - opCode, - program); - break; - case LOG4: - appendOpCodeCall( - Stream.concat(getRandomUpTo32BytesBigIntegers(4).stream(), Stream.of(size1, offset1)) - .collect(Collectors.toList()), - opCode, - program); - break; - case CODECOPY, CALLDATACOPY: - appendOpCodeCall(List.of(size1, offset2, offset1), opCode, program); - break; - case EXTCODECOPY: - appendOpCodeCall(List.of(size1, offset2, offset1, address), opCode, program); - break; - case CREATE, CREATE2: - // CREATEs are added only if INIT is provided - if (!INIT.isEmpty()) { - EWord INITCODEOFFSET = - getRandomBigIntegerByBytesSize( - 0, MAX_BYTE_SIZE); // roob or mxpx cannot be triggered this way - - size1 = EWord.of(INIT.size()); - offset1 = INITCODEOFFSET; - - for (int i = 0; i < INIT.size(); i += 32) { - // Get chunks of 32 bytes from INIT - Bytes chunk = INIT.slice(i, Math.min(32, INIT.size() - i)); - - // Add right padding so as chunk always contains 32 bytes - if (chunk.size() < 32) { - chunk = Bytes.concatenate(chunk, Bytes.of(new byte[32 - chunk.size()])); - } - - // MSTORE of chunk - appendOpCodeCall( - List.of(EWord.of(chunk), INITCODEOFFSET.add(i)), OpCode.MSTORE, program); - } - if (opCode == OpCode.CREATE) { - // CREATE - appendOpCodeCall(List.of(size1, offset1, value), opCode, program); - } else { - // CREATE2 - appendOpCodeCall(List.of(salt, size1, offset1, value), opCode, program); - } - } else { - /* Otherwise the method is called again (reached only if INIT is not provided and CREATE - or CREATE2 are selected) */ - triggerNonTrivialOrNoop(program, isHalting); - } - break; - default: - break; - } - } - - private void triggerNonTrivialButMxpxOrRoob( - BytecodeCompiler program, boolean isHalting, boolean triggerRoob) { - final int MAX_BYTE_SIZE = - 32; // To trigger MXPX we need at least 5 bytes, while ROOB at least 17 bytes - MxpType mxpType; - OpCode opCode; - - if (!isHalting) { - mxpType = MxpType.values()[RAND.nextInt(2, 5)]; // Type 2 to 4 - opCode = getRandomOpCodeByType(mxpType); - } else { - mxpType = MxpType.TYPE_4; - opCode = opCodesHalting[RAND.nextInt(opCodesHalting.length)]; // opCodeLast - } - - // Generate as many random values as needed at most - EWord size1; - EWord offset1; - EWord offset2; - boolean roob; - boolean mxpx; - EWord value = getRandomBigIntegerByBytesSize(0, 4); - Address address = getRandomBigIntegerByBytesSize(20, 20).toAddress(); - EWord salt = getRandomBigIntegerByBytesSize(0, 4); - - // Keep generating random values until we are in the mxpx && roob case or in the mxpx && !roob - // case - do { - size1 = getRandomBigIntegerByBytesSize(0, MAX_BYTE_SIZE); - offset1 = getRandomBigIntegerByBytesSize(0, MAX_BYTE_SIZE); - offset2 = getRandomBigIntegerByBytesSize(0, MAX_BYTE_SIZE); - - // size2 is irrelevant for this case - mxpx = isMxpx(mxpType, size1, offset1); - roob = isRoob(mxpType, size1, offset1); - } while (!(triggerRoob && mxpx && roob) && !(!triggerRoob && mxpx && !roob)); - - switch (opCode) { - case MLOAD -> appendOpCodeCall(List.of(offset1), opCode, program); - case MSTORE, MSTORE8 -> appendOpCodeCall(List.of(value, offset1), opCode, program); - case LOG0, - SHA3, - RETURN, - REVERT -> // RETURN and REVERT are selected only when isHalting is true - appendOpCodeCall(List.of(size1, offset1), opCode, program); - case LOG1 -> appendOpCodeCall( - Stream.concat(getRandomUpTo32BytesBigIntegers(1).stream(), Stream.of(size1, offset1)) - .collect(Collectors.toList()), - opCode, - program); - case LOG2 -> appendOpCodeCall( - Stream.concat(getRandomUpTo32BytesBigIntegers(2).stream(), Stream.of(size1, offset1)) - .collect(Collectors.toList()), - opCode, - program); - case LOG3 -> appendOpCodeCall( - Stream.concat(getRandomUpTo32BytesBigIntegers(3).stream(), Stream.of(size1, offset1)) - .collect(Collectors.toList()), - opCode, - program); - case LOG4 -> appendOpCodeCall( - Stream.concat(getRandomUpTo32BytesBigIntegers(4).stream(), Stream.of(size1, offset1)) - .collect(Collectors.toList()), - opCode, - program); - case CODECOPY, CALLDATACOPY -> appendOpCodeCall( - List.of(size1, offset2, offset1), opCode, program); - case EXTCODECOPY -> appendOpCodeCall( - List.of(size1, offset2, offset1, EWord.of(address)), opCode, program); - case CREATE, CREATE2 -> { - if (opCode == OpCode.CREATE) { - // CREATE - appendOpCodeCall(List.of(size1, offset1, value), opCode, program); - } else { - // CREATE2 - appendOpCodeCall(List.of(salt, size1, offset1, value), opCode, program); - } - } - default -> {} - } - } - - private boolean isRoob(MxpType randomMxpType, EWord size1, EWord offset1) { - - final boolean condition4And5 = offset1.compareTo(TWO_POW_128) >= 0 && !size1.isZero(); - - return switch (randomMxpType) { - case TYPE_2, TYPE_3 -> offset1.compareTo(TWO_POW_128) >= 0; - case TYPE_4 -> size1.compareTo(TWO_POW_128) >= 0 || condition4And5; - // We never test TYPE_5 in the randomized tests (CALLs) - default -> false; - }; - } - - private boolean isMxpx(MxpType randomMxpType, EWord size1, EWord offset1) { - EWord maxOffset1 = EWord.ZERO; - EWord maxOffset2 = EWord.ZERO; - EWord maxOffset; - - switch (randomMxpType) { - case TYPE_2 -> maxOffset1 = offset1.add(31); - case TYPE_3 -> maxOffset1 = offset1; - case TYPE_4 -> { - if (!size1.isZero()) { - maxOffset1 = offset1.add(size1).subtract(1); - } - } - // We never test TYPE_5 in the randomized tests (CALLs) - } - - maxOffset = maxOffset1.greaterThan(maxOffset2) ? maxOffset1 : maxOffset2; - return maxOffset.compareTo(TWO_POW_32) >= 0; - } - - private void appendOpCodeCall(List args, OpCode opCode, BytecodeCompiler program) { - for (Bytes arg : args) { - program.push(arg); - } - program.op(opCode); - } - - private void appendOpCodeCall(OpCode randomOpCode, BytecodeCompiler program) { - appendOpCodeCall(Collections.emptyList(), randomOpCode, program); - } - - // Generates a BigInteger that requires a random number of bytes to be represented in [minBytes, - // maxBytes) - private EWord getRandomBigIntegerByBytesSize(int minBytes, int maxBytes) { - if (minBytes < 0 || maxBytes > 32 || minBytes > maxBytes) { - throw new IllegalArgumentException("Invalid input values"); - } - int minBits = 8 * minBytes; - int maxBits = 8 * maxBytes; - int numBits = RAND.nextInt(minBits, maxBits + 1); - return EWord.of(new BigInteger(numBits == 0 ? 1 : numBits, RAND)); - } - - private List getRandomUpTo32BytesBigIntegers(int n) { - List randomBigIntegers = new ArrayList<>(); - for (int i = 0; i < n; i++) { - randomBigIntegers.add(EWord.of(getRandomBigIntegerByBytesSize(0, 32))); - } - return randomBigIntegers; - } - - private OpCode getRandomOpCodeByType(MxpType mxpType) { - return switch (mxpType) { - case TYPE_1 -> opCodesType1[RAND.nextInt(opCodesType1.length)]; - case TYPE_2 -> opCodesType2[RAND.nextInt(opCodesType2.length)]; - case TYPE_3 -> opCodesType3[RAND.nextInt(opCodesType3.length)]; - case TYPE_4 -> opCodesType4[RAND.nextInt(opCodesType4.length)]; - default -> OpCode.MSIZE; // We never enter the default case since we skip MxpType.NONE - }; - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTracerTest.java deleted file mode 100644 index 24dc8297d..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTracerTest.java +++ /dev/null @@ -1,77 +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.mxp; - -import static net.consensys.linea.zktracer.opcode.OpCode.MLOAD; -import static net.consensys.linea.zktracer.opcode.OpCode.MSTORE; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Stream; - -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.testing.DynamicTests; -import net.consensys.linea.zktracer.testing.OpcodeCall; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; -import org.junit.jupiter.api.DynamicTest; -import org.junit.jupiter.api.TestFactory; - -public class MxpTracerTest { - // private static final Random RAND = new Random(); - private static final int TEST_REPETITIONS = 2; - private static final Module MODULE = new Mxp(); - private static final DynamicTests DYN_TESTS = DynamicTests.forModule(MODULE); - - @TestFactory - Stream runDynamicTests() { - return DYN_TESTS - .testCase("non random arguments test", provideNonRandomArguments()) - .testCase("simple mload arguments test", simpleMloadArgs()) - .testCase( - "one of each type2 and type3 instruction MLOAD, MSTORE, MSTORE8", simpleType2And3Args()) - .run(); - } - - private List provideNonRandomArguments() { - return DYN_TESTS.newModuleArgumentsProvider( - (arguments, opCode) -> { - for (int i = 0; i < TEST_REPETITIONS; i++) { - final List args = new ArrayList<>(12); - for (int j = 0; j < opCode.getData().numberOfArguments(); j++) { - args.add(UInt256.valueOf(j)); - } - arguments.add(new OpcodeCall(opCode, args)); - } - }); - } - - protected List simpleMloadArgs() { - Bytes32 arg1 = - Bytes32.fromHexString("0xdcd5cf52e4daec5389587d0d0e996e6ce2d0546b63d3ea0a0dc48ad984d180a9"); - return List.of(new OpcodeCall(MLOAD, List.of(arg1))); - } - - protected List simpleType2And3Args() { - // one of each type2 and type3 instruction MLOAD, MSTORE, MSTORE8 - Bytes32 arg1 = - Bytes32.fromHexString("0xdcd5cf52e4daec5389587d0d0e996e6ce2d0546b63d3ea0a0dc48ad984d180a9"); - return List.of( - new OpcodeCall(MLOAD, List.of(arg1)), - new OpcodeCall(MSTORE, List.of(arg1)), - new OpcodeCall(MSTORE, List.of(arg1))); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/precompiles/precTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/precompiles/precTests.java deleted file mode 100644 index 5fef7916e..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/precompiles/precTests.java +++ /dev/null @@ -1,21 +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.precompiles; - -import net.consensys.linea.zktracer.testing.EvmExtension; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(EvmExtension.class) -public class precTests {} 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 deleted file mode 100644 index 1fd170985..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpAddr/TestRlpAddress.java +++ /dev/null @@ -1,163 +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.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; -import net.consensys.linea.zktracer.opcode.OpCodes; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -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; - -public class TestRlpAddress { - private static final int TEST_TX_COUNT = 200; - private final Random rnd = new Random(666); - - @Test - void test() { - OpCodes.load(); - - 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, 0xfffffffffffffL)) - .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, 0xfffffffffffffL)) - .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, 0xfffffffffffffL)) - .build()); - } - } - } - - ToyExecutionEnvironment.builder() - .toyWorld(world.build()) - .transactions(txList) - .testValidator(x -> {}) - .build() - .run(); - } - - private ToyAccount randCreate(int initCodeSize) { - byte[] value = bigIntegerToBytes(BigInteger.valueOf(randLong())).toArray(); - return ToyAccount.builder() - .balance(Wei.MAX_WEI) - .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(); - } - - private ToyAccount randCreateTwo(int initCodeSize) { - byte[] salt = bigIntegerToBytes(randBigInt(false)).toArray(); - byte[] value = bigIntegerToBytes(BigInteger.valueOf(randLong())).toArray(); - - return ToyAccount.builder() - .balance(Wei.MAX_WEI) - .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 ToyAccount randSenderAccount(Address senderAddress) { - return ToyAccount.builder() - .balance(Wei.of(randBigInt(true))) - .nonce(randLong()) - .address(senderAddress) - .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 deleted file mode 100644 index e59ce1e83..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpCommon/rlpRandEdgeCase.java +++ /dev/null @@ -1,68 +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.rlpCommon; - -import java.math.BigInteger; -import java.util.Random; - -import org.apache.tuweni.bytes.Bytes; - -public class rlpRandEdgeCase { - private static Random rnd = new Random(666); - - public static final BigInteger randBigInt(boolean onlyFourteenByte) { - final int selectorBound = onlyFourteenByte ? 4 : 5; - int selector = rnd.nextInt(0, selectorBound); - - return switch (selector) { - case 0 -> BigInteger.ZERO; - case 1 -> BigInteger.valueOf(rnd.nextInt(1, 128)); - case 2 -> BigInteger.valueOf(rnd.nextInt(128, 256)); - case 3 -> new BigInteger(14 * 8, rnd); - case 4 -> new BigInteger(32 * 8, rnd); - default -> throw new IllegalStateException("Unexpected value: " + selector); - }; - } - - public static Bytes randData(boolean nonEmpty) { - final int maxDataSize = 1000; - int selectorOrigin = 0; - if (nonEmpty) { - selectorOrigin += 1; - } - int selector = rnd.nextInt(selectorOrigin, 6); - return switch (selector) { - case 0 -> Bytes.EMPTY; - case 1 -> Bytes.of(0x0); - case 2 -> Bytes.minimalBytes(rnd.nextLong(1, 128)); - case 3 -> Bytes.minimalBytes(rnd.nextLong(128, 256)); - case 4 -> Bytes.random(rnd.nextInt(1, 56), rnd); - case 5 -> Bytes.random(rnd.nextInt(56, maxDataSize), rnd); - default -> throw new IllegalStateException("Unexpected value: " + selector); - }; - } - - public static Long randLong() { - int selector = rnd.nextInt(0, 4); - return switch (selector) { - case 0 -> 0L; - case 1 -> rnd.nextLong(1, 128); - case 2 -> rnd.nextLong(128, 256); - case 3 -> rnd.nextLong(256, 0xfffffffffffffffL); - default -> throw new IllegalStateException("Unexpected value: " + selector); - }; - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlp_txrcpt/RandomTxrcptTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlp_txrcpt/RandomTxrcptTests.java deleted file mode 100644 index 50bd555d8..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlp_txrcpt/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.rlp_txrcpt; - -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/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxn/TestRandomTxns.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxn/TestRandomTxns.java deleted file mode 100644 index 4a9c348bb..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxn/TestRandomTxns.java +++ /dev/null @@ -1,187 +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.rlptxn; - -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 java.util.ArrayList; -import java.util.List; -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.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; - -class TestRandomTxns { - private final Random rnd = new Random(666); - private static final int TEST_TX_COUNT = 200; - - @Test - void test() { - OpCodes.load(); - 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 = randToyAccount(senderAddress); - ToyAccount receiverAccount = receiverAccount(); - - world.account(senderAccount).account(receiverAccount); - txList.add(randTx(senderAccount, keyPair, receiverAccount)); - } - ToyExecutionEnvironment.builder() - .toyWorld(world.build()) - .transactions(txList) - .testValidator(x -> {}) - .build() - .run(); - } - - final Transaction randTx(ToyAccount senderAccount, KeyPair keyPair, ToyAccount receiverAccount) { - - int txType = rnd.nextInt(0, 6); - - return switch (txType) { - case 0 -> ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.FRONTIER) - .gasLimit(rnd.nextLong(21000, 0xfffffffffffffL)) - .value(Wei.of(randBigInt(true))) - .payload(randData(false)) - .build(); - - case 1 -> ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.FRONTIER) - .gasLimit(rnd.nextLong(21000, 0xfffffffffffffL)) - .value(Wei.of(randBigInt(true))) - .to(receiverAccount) - .payload(randData(false)) - .build(); - - case 2 -> ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.ACCESS_LIST) - .gasLimit(rnd.nextLong(21000, 0xfffffffffffffL)) - .value(Wei.of(randLong())) - .payload(randData(false)) - .accessList(randAccessList()) - .build(); - - case 3 -> ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.ACCESS_LIST) - .gasLimit(rnd.nextLong(21000, 0xfffffffffffffL)) - .value(Wei.of(randLong())) - .to(receiverAccount) - .payload(randData(false)) - .accessList(randAccessList()) - .build(); - - case 4 -> ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.EIP1559) - .gasLimit(rnd.nextLong(21000, 0xfffffffffffffL)) - .value(Wei.of(randLong())) - .payload(randData(false)) - .accessList(randAccessList()) - .build(); - - case 5 -> ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.EIP1559) - .gasLimit(rnd.nextLong(21000, 0xfffffffffffffL)) - .value(Wei.of(randLong())) - .to(receiverAccount) - .payload(randData(false)) - .accessList(randAccessList()) - .build(); - - default -> throw new IllegalStateException("Unexpected value: " + txType); - }; - } - - final List randAccessList() { - List accessList = new ArrayList<>(); - boolean entries = rnd.nextBoolean(); - if (entries) { - for (int i = 1; i < 25; i++) { - accessList.add(randAccessListEntry()); - } - } - return accessList; - } - - final AccessListEntry randAccessListEntry() { - List keyList = new ArrayList<>(); - boolean key = rnd.nextBoolean(); - if (key) { - for (int nKey = 1; nKey < rnd.nextInt(1, 20); nKey++) { - keyList.add(Bytes32.random(rnd)); - } - } - return new AccessListEntry(Address.wrap(Bytes.random(20, rnd)), keyList); - } - - final ToyAccount receiverAccount() { - - return ToyAccount.builder() - .balance(Wei.ONE) - .nonce(6) - .address(Address.wrap(Bytes.random(20, rnd))) - .code( - BytecodeCompiler.newProgram() - .push(32, 0xbeef) - .push(32, 0xdead) - .op(OpCode.ADD) - .compile()) - .build(); - } - - final ToyAccount randToyAccount(Address senderAddress) { - - return ToyAccount.builder() - .balance(Wei.wrap(Bytes.random(16, rnd))) - .nonce(randLong()) - .address(senderAddress) - .build(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/shf/ShfRtTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/shf/ShfRtTracerTest.java deleted file mode 100644 index 17f23ad87..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/shf/ShfRtTracerTest.java +++ /dev/null @@ -1,131 +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.shf; - -import java.util.Random; -import java.util.stream.Stream; - -import lombok.extern.slf4j.Slf4j; -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.apache.tuweni.bytes.Bytes32; -import org.junit.jupiter.api.Named; -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; - -@Slf4j -@ExtendWith(EvmExtension.class) -class ShfRtTracerTest { - private static final Random RAND = new Random(); - private static final int TEST_REPETITIONS = 4; - - @ParameterizedTest(name = "{0}") - @MethodSource("provideShiftOperators") - void testFailingBlockchainBlock(final int opCodeValue) { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes32.rightPad(Bytes.fromHexString("0x08"))) - .push(Bytes32.fromHexString("0x01")) - .immediate(opCodeValue) - .compile()) - .run(); - } - - @ParameterizedTest(name = "{0}") - @MethodSource("provideRandomSarArguments") - void testRandomSar(final Bytes32[] payload) { - log.info( - "value: " + payload[0].toShortHexString() + ", shift by: " + payload[1].toShortHexString()); - - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(payload[1]) - .push(payload[0]) - .op(OpCode.SAR) - .compile()) - .run(); - } - - @Test - void testTmp() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .immediate(Bytes32.fromHexStringLenient("0x54fda4f3c1452c8c58df4fb1e9d6de")) - .immediate(Bytes32.fromHexStringLenient("0xb5")) - .op(OpCode.SAR) - .compile()) - .run(); - } - - private static Stream provideRandomSarArguments() { - final Arguments[] arguments = new Arguments[TEST_REPETITIONS]; - - for (int i = 0; i < TEST_REPETITIONS; i++) { - final boolean signBit = RAND.nextInt(2) == 1; - - // leave the first byte untouched - final int k = 1 + RAND.nextInt(31); - - final byte[] randomBytes = new byte[k]; - RAND.nextBytes(randomBytes); - - final byte[] signBytes = new byte[32 - k]; - if (signBit) { - signBytes[0] = (byte) 0x80; // 0b1000_0000, i.e. sign bit == 1 - } - - final byte[] bytes = concatenateArrays(signBytes, randomBytes); - byte shiftBy = (byte) RAND.nextInt(256); - - Bytes32[] payload = new Bytes32[2]; - payload[0] = Bytes32.wrap(bytes); - payload[1] = Bytes32.leftPad(Bytes.of(shiftBy)); - - arguments[i] = - Arguments.of( - Named.of( - "value: " - + payload[0].toHexString() - + ", shiftBy: " - + payload[1].toShortHexString(), - payload)); - } - - return Stream.of(arguments); - } - - public static Stream provideShiftOperators() { - return Stream.of( - Arguments.of(Named.of("SAR", OpCode.SAR.getData().value())), - Arguments.of(Named.of("SHL", OpCode.SHL.getData().value())), - Arguments.of(Named.of("SHR", OpCode.SHR.getData().value()))); - } - - private static byte[] concatenateArrays(byte[] a, byte[] b) { - int length = a.length + b.length; - byte[] result = new byte[length]; - System.arraycopy(a, 0, result, 0, a.length); - System.arraycopy(b, 0, result, a.length, b.length); - - return result; - } -} 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 deleted file mode 100644 index 0f5ae87bd..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/stp/StpTest.java +++ /dev/null @@ -1,286 +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.stp; - -import static net.consensys.linea.zktracer.module.rlpCommon.rlpRandEdgeCase.randBigInt; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.longToBytes; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; -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; -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 StpTest { - private static final Random RAND = new Random(666L); - final int NB_CALL = 200; - final int NB_CREATE = 200; - - @Test - void testCall() { - OpCodes.load(); - ToyWorld.ToyWorldBuilder world = ToyWorld.builder(); - List txList = new ArrayList<>(); - - for (int i = 0; i < NB_CALL; i++) { - final OpCode opcode = randOpCodeCall(); - final boolean toExists = RAND.nextBoolean(); - final boolean toWarm = toExists && RAND.nextBoolean(); - final Wei balance = Wei.of(randBigInt(true)); - final long gasCall = RAND.nextLong(0, 100000L); - final BigInteger value = BigInteger.valueOf(RAND.nextLong(0, 100000L)); - final long gasLimit = RAND.nextLong(23400, 1000000L); - - txList.add(txCall(opcode, toExists, toWarm, balance, value, gasCall, gasLimit, world)); - } - - ToyExecutionEnvironment.builder() - .toyWorld(world.build()) - .transactions(txList) - .testValidator(x -> {}) - .build() - .run(); - } - - @Test - void testCreate() { - OpCodes.load(); - ToyWorld.ToyWorldBuilder world = ToyWorld.builder(); - List txList = new ArrayList<>(); - - for (int i = 0; i < NB_CREATE; i++) { - - final OpCode opcode = RAND.nextBoolean() ? OpCode.CREATE : OpCode.CREATE2; - if (opcode == OpCode.CREATE) { - txList.add(txCreate(world)); - } else { - txList.add(txCreate2(world)); - } - } - - ToyExecutionEnvironment.builder() - .toyWorld(world.build()) - .transactions(txList) - .testValidator(x -> {}) - .build() - .run(); - } - - OpCode randOpCodeCall() { - final int rand = RAND.nextInt(0, 4); - switch (rand) { - case 0 -> { - return OpCode.CALL; - } - case 1 -> { - return OpCode.CALLCODE; - } - case 2 -> { - return OpCode.DELEGATECALL; - } - case 3 -> { - return OpCode.STATICCALL; - } - default -> throw new IllegalArgumentException("Arguments is between 0 and 4"); - } - } - - final Transaction txCall( - OpCode opcode, - boolean toExist, - boolean toWarm, - Wei balance, - BigInteger value, - long gasCall, - long gasLimit, - ToyWorld.ToyWorldBuilder world) { - - // Create the sender account - final KeyPair keyPair = new SECP256K1().generateKeyPair(); - final Address senderAddress = - Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - final ToyAccount senderAccount = - ToyAccount.builder().balance(balance).nonce(1).address(senderAddress).build(); - world.account(senderAccount); - - // Create the callee account and address - final Address calleeAddress = Address.wrap(Bytes.random(20)); - final ToyAccount calleeAccount = - ToyAccount.builder().nonce(1).balance(Wei.ONE).address(calleeAddress).build(); - if (toExist) { - world.account(calleeAccount); - } - - // Create the to account, which contains the bytecode to execute - final Address toAddress = Address.wrap(Bytes.random(20)); - final ToyAccount toAccount = - ToyAccount.builder() - .address(toAddress) - .nonce(1) - .balance(Wei.ONE) - .code(codeCall(opcode, calleeAddress, value, gasCall)) - .build(); - world.account(toAccount); - - AccessListEntry entry = AccessListEntry.createAccessListEntry(senderAddress, List.of()); - if (toWarm) { - entry = AccessListEntry.createAccessListEntry(calleeAddress, List.of()); - } - - return ToyTransaction.builder() - .sender(senderAccount) - .to(toAccount) - .keyPair(keyPair) - .transactionType(TransactionType.ACCESS_LIST) - .value(Wei.of(100000L)) - .gasLimit(gasLimit) - .accessList(List.of(entry)) - .build(); - } - - private Bytes codeCall(OpCode opcode, Address calleeAddress, BigInteger value, long gasCall) { - return switch (opcode) { - case CALL, CALLCODE -> BytecodeCompiler.newProgram() - .push(Bytes.minimalBytes(6)) // retLength - .push(Bytes.minimalBytes(5)) // terOffset - .push(Bytes.minimalBytes(4)) // argsLength - .push(Bytes.minimalBytes(3)) // argsOffset - .push(bigIntegerToBytes(value)) // value - .push(calleeAddress) // address - .push(longToBytes(gasCall)) // gas - .op(opcode) - .compile(); - case DELEGATECALL, STATICCALL -> BytecodeCompiler.newProgram() - .push(Bytes.minimalBytes(5)) // retLength - .push(Bytes.minimalBytes(4)) // terOffset - .push(Bytes.minimalBytes(3)) // argsLength - .push(Bytes.minimalBytes(2)) // argsOffset - .push(calleeAddress) // address - .push(longToBytes(gasCall)) // gas - .op(opcode) - .compile(); - - default -> throw new IllegalStateException("Unexpected value: " + opcode); - }; - } - - final Transaction txCreate(ToyWorld.ToyWorldBuilder world) { - // create sender account - final KeyPair keyPair = new SECP256K1().generateKeyPair(); - final Address senderAddress = - Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - final long value = RAND.nextLong(); - final ToyAccount senderAccount = - ToyAccount.builder() - .balance(Wei.of(randBigInt(true))) - .nonce(Math.abs(RAND.nextInt())) - .address(senderAddress) - .build(); - world.account(senderAccount); - - // create to account - final Address to = Address.wrap(Bytes.random(20)); - final ToyAccount toAccount = - ToyAccount.builder() - .nonce(Math.abs(RAND.nextInt())) - .balance(Wei.ONE) - .address(to) - .code( - BytecodeCompiler.newProgram() - .push(Bytes.fromHexString("0xff")) // length - .push(Bytes.fromHexString("0x80")) // offset - .push(Bytes.minimalBytes(value)) // value - .op(OpCode.CREATE) - .compile()) - .build(); - world.account(toAccount); - - final long gasLimit = RAND.nextLong(21000, 1000000L); - return ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.FRONTIER) - .value(Wei.ONE) - .to(toAccount) - .gasLimit(gasLimit) - .build(); - } - - final Transaction txCreate2(ToyWorld.ToyWorldBuilder world) { - // create senderAccount - final KeyPair keyPair = new SECP256K1().generateKeyPair(); - final Address senderAddress = - Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - final long value = RAND.nextLong(); - final ToyAccount senderAccount = - ToyAccount.builder() - .balance(Wei.of(randBigInt(true))) - .nonce(Math.abs(RAND.nextInt())) - .address(senderAddress) - .build(); - world.account(senderAccount); - - // create to account - final Address to = Address.wrap(Bytes.random(20)); - final ToyAccount toAccount = - ToyAccount.builder() - .nonce(Math.abs(RAND.nextInt())) - .balance(Wei.ONE) - .address(to) - .code( - BytecodeCompiler.newProgram() - .push(Bytes.random(32)) // salt - .push(Bytes.fromHexString("0xff")) // length - .push(Bytes.fromHexString("0x80")) // offset - .push(Bytes.minimalBytes(value)) // value - .op(OpCode.CREATE) - .compile()) - .build(); - world.account(toAccount); - - final long gasLimit = RAND.nextLong(21000, 1000000L); - return ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.FRONTIER) - .to(toAccount) - .gasLimit(gasLimit) - .value(Wei.ONE) - .gasLimit(gasLimit) - .build(); - } -} 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 af922c08a..000000000 --- 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 - } -} 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 deleted file mode 100644 index 44e6e8e68..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java +++ /dev/null @@ -1,138 +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 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.apache.tuweni.bytes.Bytes32; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(EvmExtension.class) -public class TrmTracerTest { - private final Bytes32 RANDOM_STRING_FROM_THE_INTERNET = - Bytes32.fromHexString( - "0x" - + "b18cd834" - + "b6192fcf" - + "9f51322e" - + "a31b31be" - + "bf8fd38b" - + "b3e8d512" - + "3273df51" - + "9650f978"); - private final Bytes32 CLEARING_STRING = - Bytes32.fromHexString( - "0x" - + "00000000" - + "00000000" - + "00000000" - + "ffffffff" - + "ffffffff" - + "ffffffff" - + "ffffffff"); - private final Bytes32 EXTRACT_DISREGARDED_PREFIX_STRING = - Bytes32.fromHexString( - "0x" - + "ffffffff" - + "ffffffff" - + "ffffffff" - + "00000000" - + "00000000" - + "00000000" - + "00000000" - + "00000000"); - - @Test - void testNonCallTinyParamLessThan16() { - for (int tiny = 0; tiny < 16; tiny++) { - nonCall(Bytes32.leftPad(Bytes.of(tiny))); - } - } - - @Test - void testNonCallTinyParamAround256() { - for (int tiny = 0; tiny < 16; tiny++) { - nonCall(Bytes32.leftPad(Bytes.ofUnsignedLong((long) tiny + 248))); - } - } - - @Test - void testNonCallAddressParameterTinyAfterTrimming() { - for (int tiny = 0; tiny < 16; tiny++) { - nonCall( - RANDOM_STRING_FROM_THE_INTERNET - .and(EXTRACT_DISREGARDED_PREFIX_STRING) - .or(Bytes32.leftPad(Bytes.of(tiny)))); - } - } - - @Test - void testNonCallRandomLarge() { - nonCall(RANDOM_STRING_FROM_THE_INTERNET); - } - - @Test - void testSevenArgCall() { - for (int tiny = 0; tiny < 16; tiny++) { - sevenArgCall(tiny); - } - } - - @Test - void testSixArgCall() { - for (long tiny = 0; tiny < 16; tiny++) { - sixArgCall(tiny); - } - } - - void nonCall(Bytes bytes) { - BytecodeRunner.of(BytecodeCompiler.newProgram().push(bytes).op(OpCode.EXTCODEHASH).compile()) - .run(); - } - - void sevenArgCall(long rawAddr) { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.fromHexString("0xff")) // rds - .push(Bytes.fromHexString("0x80")) // rdo - .push(Bytes.fromHexString("0x44")) // cds - .push(Bytes.fromHexString("0x19")) // cdo - .push(Bytes.fromHexString("0xffffffffffff")) // value - .push(Bytes.ofUnsignedLong(rawAddr)) // address - .push(Bytes.fromHexString("0xffff")) // gas - .op(OpCode.CALL) - .compile()) - .run(); - } - - void sixArgCall(long rawAddr) { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.fromHexString("0xff")) // rds - .push(Bytes.fromHexString("0x80")) // rdo - .push(Bytes.fromHexString("0x44")) // cds - .push(Bytes.fromHexString("0x19")) // cdo - .push(Bytes.ofUnsignedLong(rawAddr)) // address - .push(Bytes.fromHexString("0xffff")) // gas - .op(OpCode.DELEGATECALL) - .compile()) - .run(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/wcp/wcpEdgeCaseTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/wcp/wcpEdgeCaseTest.java deleted file mode 100644 index ac91c95ad..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/wcp/wcpEdgeCaseTest.java +++ /dev/null @@ -1,78 +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.wcp; - -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 wcpEdgeCaseTest { - @Test - void testZeroAndHugeArgs() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.repeat((byte) 0xff, 32)) - .push(Bytes.EMPTY) - .op(OpCode.SLT) - .compile()) - .run(); - } - - @Test - void testHugeAndZeroArgs() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.EMPTY) - .push(Bytes.repeat((byte) 0xff, 32)) - .op(OpCode.SLT) - .compile()) - .run(); - } - - @Test - void failingOnShadowNodeBlock916394() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.EMPTY) - .push( - Bytes.concatenate( - Bytes.repeat((byte) 0xff, 29), - Bytes.of(0xfe), - Bytes.of(0x18), - Bytes.of(0x59))) - .op(OpCode.SLT) - .compile()) - .run(); - } - - @Test - void failingOnShadowNodeBlockWhatever() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.EMPTY) - .push( - Bytes.fromHexString( - "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1859")) - .op(OpCode.SLT) - .compile()) - .run(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeCompiler.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeCompiler.java deleted file mode 100644 index fa95bbbfc..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeCompiler.java +++ /dev/null @@ -1,259 +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.testing; - -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.StringReader; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; -import org.junit.platform.commons.util.Preconditions; - -/** Fluent API for constructing custom sequences of EVM bytecode. */ -public class BytecodeCompiler { - private final List byteCode = new ArrayList<>(); - - private BytecodeCompiler() {} - - /** - * Create a new program instance that will contain a new bytecode sequence. - * - * @return an instance of {@link BytecodeCompiler} - */ - public static BytecodeCompiler newProgram() { - return new BytecodeCompiler(); - } - - private static Bytes toBytes(final int x) { - return Bytes.ofUnsignedLong(x).trimLeadingZeros(); - } - - /** - * Assemble an EVM program into bytecode. Requirement are: one instruction per line; `;` mark a - * line as a comment; no more than one word per line, safe for PUSHs. - * - * @param program - * @return the bytecode corresponding to the assembly code - */ - public BytecodeCompiler assemble(final String program) { - BufferedReader bufReader = new BufferedReader(new StringReader(program)); - String line; - while (true) { - try { - if ((line = bufReader.readLine()) == null) break; - if (line.isBlank()) continue; - if (line.startsWith(";")) continue; - - String[] ls = line.split("\\s+"); - final OpCode opCode = OpCode.fromMnemonic(ls[0]); - this.op(opCode); - final int pushSize = opCode.byteValue() - (int) OpCode.PUSH1.byteValue() + 1; - final boolean isPush = pushSize >= 1 && pushSize <= 32; - if (isPush) { - this.immediate(Bytes.fromHexString(ls[1], pushSize)); - } else { - if (ls.length > 1) { - throw new IllegalArgumentException("expected nothing, found" + ls[1]); - } - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - return this; - } - - /** - * Add an {@link OpCode} to the bytecode sequence. - * - * @param opCode opcode to be added - * @return current instance - */ - public BytecodeCompiler op(final OpCode opCode) { - byteCode.add(Bytes.of(opCode.byteValue())); - - return this; - } - - /** - * Add an opcode and a list of {@link Bytes32} opcode arguments to the bytecode sequence. - * - * @param opCode opcode to be added - * @param arguments list of arguments related to the opcode to be added - * @return current instance - */ - public BytecodeCompiler opAnd32ByteArgs(final OpCode opCode, final List arguments) { - for (Bytes32 argument : arguments) { - push(argument); - } - - op(opCode); - - return this; - } - - /** - * Add a byte array as is to the bytecode sequence. - * - * @param bs byte array to be added - * @return current instance - */ - public BytecodeCompiler immediate(final byte[] bs) { - this.byteCode.add(Bytes.wrap(bs)); - - return this; - } - - /** - * Add a {@link Bytes} instance as is to the bytecode sequence. - * - * @param bytes {@link Bytes} to be added - * @return current instance - */ - public BytecodeCompiler immediate(final Bytes bytes) { - return this.immediate(bytes.toArray()); - } - - /** - * Add an int as is to the bytecode sequence. - * - * @param x integer number to be added - * @return current instance - */ - public BytecodeCompiler immediate(final int x) { - return this.immediate(toBytes(x)); - } - - /** - * Add a {@link UInt256} number as is to the bytecode sequence. - * - * @param x {@link UInt256} number to be added - * @return current instance - */ - public BytecodeCompiler immediate(final UInt256 x) { - this.byteCode.add(x); - - return this; - } - - /** - * Add a {@link OpCode#PUSH1} and byte array arguments. - * - * @param xs byte array arguments - * @return current instance - */ - public BytecodeCompiler push(final Bytes xs) { - Preconditions.condition(xs.size() <= 32, "Provided byte array is empty or exceeds 32 bytes"); - - if (xs.isEmpty()) { - return this.immediate(OpCode.PUSH1.byteValue()).immediate(Bytes.of(0)); - } else { - int pushNOpCode = OpCode.PUSH1.byteValue() + xs.size() - 1; - return this.immediate(pushNOpCode).immediate(xs); - } - } - - /** - * Add a {@link OpCode#PUSH1} and a {@link BigInteger} argument. - * - * @param xs BigInteger argument - * @return current instance - */ - public BytecodeCompiler push(final BigInteger xs) { - return this.push(bigIntegerToBytes(xs)); - } - - /** - * Add a {@link OpCode#PUSH1} and int number argument. - * - * @param x int number argument - * @return current instance - */ - public BytecodeCompiler push(final int x) { - return this.push(toBytes(x)); - } - - /** - * Add a PUSH operation of the given width and its (padded) argument - * - * @param w the width to push (in [[1; 32]]) - * @param bs byte array to be added - * @return current instance - */ - public BytecodeCompiler push(final int w, final byte[] bs) { - Preconditions.condition(w > 0 && w <= 32, "Invalid PUSH width"); - Preconditions.condition(bs.length <= w, "PUSH argument must be smaller than the width"); - - final int padding = w - bs.length; - - this.op(OpCode.of(0x5f + w)); - this.byteCode.add(Bytes.repeat((byte) 0, padding)); - this.byteCode.add(Bytes.of(bs)); - - return this; - } - - /** - * Add a PUSH operation of the given width and its (padded) argument - * - * @param w the width to push (in [[1; 32]]) - * @param bytes {@link Bytes} to be added - * @return current instance - */ - public BytecodeCompiler push(final int w, final Bytes bytes) { - - return this.push(w, bytes.toArray()); - } - - /** - * Add an int as is to the bytecode sequence. - * - * @param w the width to push (in [[1; 32]]) - * @param x integer number to be added - * @return current instance - */ - public BytecodeCompiler push(final int w, final int x) { - return this.push(w, toBytes(x)); - } - - /** - * Add a PUSH operation of the given width and its (padded) argument - * - * @param w the width to push (in [[1; 32]]) - * @param x {@link UInt256} number to be added - * @return current instance - */ - public BytecodeCompiler push(final int w, final UInt256 x) { - return this.push(w, x.toArray()); - } - - /** - * Compile bytecode sequence to a single {@link Bytes} instance. - * - * @return a {@link Bytes} instance containing a pre-defined sequence of bytes and {@link OpCode}s - */ - public Bytes compile() { - return Bytes.concatenate(byteCode); - } -} 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 deleted file mode 100644 index ba19d1332..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeRunner.java +++ /dev/null @@ -1,90 +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.testing; - -import java.util.List; -import java.util.function.Consumer; - -import com.google.common.base.Preconditions; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.ZkTracer; -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.Wei; -import org.hyperledger.besu.ethereum.core.Transaction; - -/** - * A BytecodeRunner takes bytecode, then run it in a single transaction in a single block, and - * ensures that it executed correctly. - */ -@Accessors(fluent = true) -public final class BytecodeRunner { - private final Bytes byteCode; - - /** - * @param byteCode the byte code to test - */ - public BytecodeRunner(Bytes byteCode) { - this.byteCode = byteCode; - } - - public static BytecodeRunner of(Bytes byteCode) { - return new BytecodeRunner(byteCode); - } - - @Setter private Consumer zkTracerValidator = zkTracer -> {}; - - public void run() { - Preconditions.checkArgument(byteCode != null, "byteCode cannot be empty"); - - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - - final ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); - - final ToyAccount receiverAccount = - ToyAccount.builder() - .balance(Wei.fromEth(1)) - .nonce(6) - .address(Address.fromHexString("0x111111")) - .code(byteCode) - .build(); - - final Transaction tx = - ToyTransaction.builder() - .sender(senderAccount) - .to(receiverAccount) - .keyPair(keyPair) - .gasLimit(100_000_000L) - .build(); - - final ToyWorld toyWorld = - ToyWorld.builder().accounts(List.of(senderAccount, receiverAccount)).build(); - - ToyExecutionEnvironment.builder() - .testValidator(x -> {}) - .toyWorld(toyWorld) - .zkTracerValidator(zkTracerValidator) - .transaction(tx) - .build() - .run(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTestCase.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTestCase.java deleted file mode 100644 index 2202041a2..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTestCase.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.testing; - -import java.util.List; -import java.util.function.BiConsumer; - -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes32; - -/** - * Dynamic test case data structure. - * - * @param name name of the test case - * @param arguments arguments for the test case - * @param customAssertions optional custom assertions per test case - */ -public record DynamicTestCase( - String name, List arguments, BiConsumer> customAssertions) {} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTests.java deleted file mode 100644 index 9a098f993..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTests.java +++ /dev/null @@ -1,190 +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.testing; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.function.BiConsumer; -import java.util.stream.Stream; - -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.add.Add; -import net.consensys.linea.zktracer.module.ext.Ext; -import net.consensys.linea.zktracer.module.mod.Mod; -import net.consensys.linea.zktracer.module.mul.Mul; -import net.consensys.linea.zktracer.module.mxp.Mxp; -import net.consensys.linea.zktracer.module.shf.Shf; -import net.consensys.linea.zktracer.module.wcp.Wcp; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.OpCodes; -import org.apache.tuweni.bytes.Bytes32; -import org.junit.jupiter.api.DynamicTest; - -/** - * Responsible for executing JUnit 5 dynamic tests for modules with the ability to configure custom - * opcode arguments on a test case basis. - */ -public class DynamicTests { - private static final Random RAND = new Random(); - private static final int TEST_REPETITIONS = 4; - - private final List testCaseRegistry; - - private final Module module; - - private DynamicTests(Module module) { - OpCodes.load(); - this.module = module; - this.testCaseRegistry = new LinkedList<>(); - } - - /** - * Constructor function for initialization of a suite of dynamic tests per module. - * - * @param module module instance for which a dynamic test suite should be run - * @return an instance of {@link DynamicTests} - */ - public static DynamicTests forModule(Module module) { - return new DynamicTests(module); - } - - /** - * Constructs a new dynamically generated test case. - * - * @param testCaseName name of the test case - * @param args arguments of the test case - * @return the current instance - */ - public DynamicTests testCase(final String testCaseName, final List args) { - testCaseRegistry.add(new DynamicTestCase(testCaseName, args, null)); - - return this; - } - - /** - * Constructs a new dynamically generated test case. - * - * @param testCaseName name of the test case - * @param args arguments of the test case - * @param customAssertions custom test case assertions - * @return the current instance - */ - public DynamicTests testCase( - final String testCaseName, - final List args, - final BiConsumer> customAssertions) { - testCaseRegistry.add(new DynamicTestCase(testCaseName, args, customAssertions)); - - return this; - } - - /** - * Runs the suite of dynamic tests per module. - * - * @return a {@link Stream} of {@link DynamicTest} ran by a {@link - * org.junit.jupiter.api.TestFactory} - */ - public Stream run() { - return this.testCaseRegistry.stream() - .flatMap(e -> generateTestCases(e.name(), e.arguments(), e.customAssertions())); - } - - private List supportedOpCodes(Module module) { - if (module instanceof Add) { - return List.of(OpCode.ADD, OpCode.SUB); - } else if (module instanceof Ext) { - return List.of(OpCode.MULMOD, OpCode.ADDMOD); - } else if (module instanceof Mod) { - return List.of(OpCode.DIV, OpCode.SDIV, OpCode.MOD, OpCode.SMOD); - } else if (module instanceof Mul) { - return List.of(OpCode.MUL, OpCode.EXP); - } else if (module instanceof Shf) { - return List.of(OpCode.SHR, OpCode.SHL, OpCode.SAR); - } else if (module instanceof Wcp) { - return List.of(OpCode.LT, OpCode.GT, OpCode.SLT, OpCode.SGT, OpCode.EQ, OpCode.ISZERO); - } else if (module instanceof Mxp) { - return List.of( - OpCode.SHA3, - OpCode.LOG0, - OpCode.LOG1, - OpCode.LOG2, - OpCode.LOG3, - OpCode.LOG4, - OpCode.RETURN, - OpCode.REVERT, - OpCode.MSIZE, - OpCode.CALLDATACOPY, - OpCode.CODECOPY, - OpCode.RETURNDATACOPY, - OpCode.EXTCODECOPY, - OpCode.MLOAD, - OpCode.MSTORE, - OpCode.MSTORE8, - OpCode.CREATE, - OpCode.CREATE2, - OpCode.CALL, - OpCode.CALLCODE, - OpCode.DELEGATECALL, - OpCode.STATICCALL); - } else { - throw new RuntimeException("Unexpected module"); - } - } - - /** - * Abstracts away argument generation per module's supported opcodes. - * - * @param argsGenerationFunc consumer allowing for argument generation specification per module's - * supported opcode - * @return a multimap of generated arguments for the given test case - */ - public List newModuleArgumentsProvider( - final BiConsumer, OpCode> argsGenerationFunc) { - List arguments = new ArrayList<>(); - - for (OpCode opCode : supportedOpCodes(module)) { - argsGenerationFunc.accept(arguments, opCode); - } - - return arguments; - } - - private Stream generateTestCases( - final String testCaseName, - final List args, - final BiConsumer> customAssertions) { - return args.stream() - .map( - e -> { - String testName = - "[%s][%s] Test bytecode for opcode %s with opArgs %s" - .formatted( - module.moduleKey().toUpperCase(), testCaseName, e.opCode(), e.args()); - - return DynamicTest.dynamicTest( - testName, - () -> { - if (customAssertions == null) { - ModuleTests.runTestWithOpCodeArgs(e.opCode(), e.args()); - } else { - customAssertions.accept(e.opCode(), e.args()); - } - }); - }); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/EvmExtension.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/EvmExtension.java deleted file mode 100644 index dd8f5f50a..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/EvmExtension.java +++ /dev/null @@ -1,31 +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.testing; - -import net.consensys.linea.zktracer.opcode.OpCodes; -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.ExtensionContext; - -/** - * A JUnit {@link org.junit.jupiter.api.extension.Extension} handling the test lifecycle for EVM - * tests. - */ -public class EvmExtension implements BeforeAllCallback { - @Override - public void beforeAll(ExtensionContext context) { - OpCodes.load(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ExampleTxTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ExampleTxTest.java deleted file mode 100644 index 873453941..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ExampleTxTest.java +++ /dev/null @@ -1,62 +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.testing; - -import java.util.List; - -import net.consensys.linea.zktracer.opcode.OpCode; -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.Wei; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(EvmExtension.class) -class ExampleTxTest { - - @Test - void test() { - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - - ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); - - ToyAccount receiverAccount = - ToyAccount.builder() - .balance(Wei.ONE) - .nonce(6) - .address(Address.fromHexString("0x111111")) - .code( - BytecodeCompiler.newProgram() - .push(32, 0xbeef) - .push(32, 0xdead) - .op(OpCode.ADD) - .compile()) - .build(); - - Transaction tx = - ToyTransaction.builder().sender(senderAccount).to(receiverAccount).keyPair(keyPair).build(); - - ToyWorld toyWorld = - ToyWorld.builder().accounts(List.of(senderAccount, receiverAccount)).build(); - - ToyExecutionEnvironment.builder().toyWorld(toyWorld).transaction(tx).build().run(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ModuleTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ModuleTests.java deleted file mode 100644 index 5c73bc096..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ModuleTests.java +++ /dev/null @@ -1,38 +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.testing; - -import java.util.List; - -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; - -/** Contains methods that execute module tests. */ -public class ModuleTests { - - /** - * Compiles and runs a predefined sequence of bytecode instructions for testing purposes. - * - * @param opCode opcode for which the test should be run - * @param arguments args of the opcode for which the test should be run - */ - public static void runTestWithOpCodeArgs(final OpCode opCode, final List arguments) { - Bytes bytecode = BytecodeCompiler.newProgram().opAnd32ByteArgs(opCode, arguments).compile(); - - BytecodeRunner.of(bytecode).run(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/OpcodeCall.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/OpcodeCall.java deleted file mode 100644 index 0be875467..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/OpcodeCall.java +++ /dev/null @@ -1,23 +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.testing; - -import java.util.List; - -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes32; - -public record OpcodeCall(OpCode opCode, List args) {} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyAccount.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyAccount.java deleted file mode 100644 index c426c6c91..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyAccount.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright contributors to Hyperledger Besu - * - * 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.testing; - -import java.util.HashMap; -import java.util.Map; -import java.util.NavigableMap; -import java.util.function.Supplier; - -import com.google.common.base.Preconditions; -import com.google.common.base.Suppliers; -import lombok.Builder; -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.Hash; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.ModificationNotAllowedException; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.account.AccountStorageEntry; -import org.hyperledger.besu.evm.account.MutableAccount; - -public class ToyAccount implements MutableAccount { - private final Account parent; - - private boolean mutable = true; - - private Address address; - private final Supplier addressHash = Suppliers.memoize(() -> address.addressHash()); - private long nonce; - private Wei balance; - private Bytes code; - private Supplier codeHash = Suppliers.memoize(() -> Hash.hash(code)); - private final Map storage = new HashMap<>(); - - @Builder - public ToyAccount( - final Account parent, - final Address address, - final long nonce, - final Wei balance, - final Bytes code) { - Preconditions.checkArgument(nonce >= 0); - this.parent = parent; - this.address = address; - this.nonce = nonce; - this.balance = balance; - this.code = code == null ? Bytes.EMPTY : code; - } - - @Override - public Address getAddress() { - return address; - } - - @Override - public Hash getAddressHash() { - return addressHash.get(); - } - - @Override - public long getNonce() { - return nonce; - } - - @Override - public Wei getBalance() { - return balance; - } - - @Override - public Bytes getCode() { - return code; - } - - @Override - public Hash getCodeHash() { - return codeHash.get(); - } - - @Override - public UInt256 getStorageValue(final UInt256 key) { - if (storage.containsKey(key)) { - return storage.get(key); - } else if (parent != null) { - return getOriginalStorageValue(key); - } - - return UInt256.ZERO; - } - - @Override - public UInt256 getOriginalStorageValue(final UInt256 key) { - if (parent != null) { - return parent.getStorageValue(key); - } else { - return getStorageValue(key); - } - } - - @Override - public NavigableMap storageEntriesFrom( - final Bytes32 startKeyHash, final int limit) { - throw new UnsupportedOperationException("Storage iteration not supported in toy evm"); - } - - @Override - public void setNonce(final long value) { - if (!mutable) { - throw new ModificationNotAllowedException(); - } - nonce = value; - } - - @Override - public void setBalance(final Wei value) { - if (!mutable) { - throw new ModificationNotAllowedException(); - } - balance = value; - } - - @Override - public void setCode(final Bytes code) { - if (!mutable) { - throw new ModificationNotAllowedException(); - } - this.code = code; - this.codeHash = Suppliers.memoize(() -> this.code == null ? Hash.EMPTY : Hash.hash(this.code)); - } - - @Override - public void setStorageValue(final UInt256 key, final UInt256 value) { - if (!mutable) { - throw new ModificationNotAllowedException(); - } - storage.put(key, value); - } - - @Override - public void clearStorage() { - if (!mutable) { - throw new ModificationNotAllowedException(); - } - storage.clear(); - } - - @Override - public Map getUpdatedStorage() { - return this.storage; - } - - @Override - public void becomeImmutable() { - mutable = false; - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyBlockValues.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyBlockValues.java deleted file mode 100644 index 792bc6d34..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyBlockValues.java +++ /dev/null @@ -1,89 +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.testing; - -import java.util.Optional; - -import lombok.Builder; -import lombok.RequiredArgsConstructor; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.frame.BlockValues; - -/** An implementation of {@link BlockValues} for testing purposes. */ -@Builder -@RequiredArgsConstructor -public class ToyBlockValues implements BlockValues { - private static final Bytes DEFAULT_DIFFICULTY_BYTES = UInt256.ZERO; - private static final long DEFAULT_NUMBER = 0L; - private static final long DEFAULT_GAS_LIMIT = 30_000_000L; - private static final long DEFAULT_TIMESTAMP = 1234987L; - private static final Optional DEFAULT_BASE_FEE = Optional.empty(); - - private final Long number; - private final Long gasLimit; - private final Long timestamp; - private final Bytes difficultyBytes; - private final Optional baseFee; - - public static ToyBlockValues defaultValues() { - return builder().build(); - } - - @Override - public long getNumber() { - return number; - } - - @Override - public Optional getBaseFee() { - return baseFee; - } - - @Override - public Bytes getDifficultyBytes() { - return difficultyBytes; - } - - @Override - public long getGasLimit() { - return gasLimit; - } - - @Override - public long getTimestamp() { - return timestamp; - } - - /** Customizations applied on the generated Lombok {@link Builder}. */ - public static class ToyBlockValuesBuilder { - - /** - * Customizations applied on the generated Lombok {@link Builder}'s build method. - * - * @return an instance of {@link ToyBlockValues} - */ - public ToyBlockValues build() { - return new ToyBlockValues( - Optional.ofNullable(number).orElse(DEFAULT_NUMBER), - Optional.ofNullable(gasLimit).orElse(DEFAULT_GAS_LIMIT), - Optional.ofNullable(timestamp).orElse(DEFAULT_TIMESTAMP), - Optional.ofNullable(difficultyBytes).orElse(DEFAULT_DIFFICULTY_BYTES), - Optional.ofNullable(baseFee).orElse(DEFAULT_BASE_FEE)); - } - } -} 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 deleted file mode 100644 index 20b688b17..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java +++ /dev/null @@ -1,279 +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.testing; - -import static net.consensys.linea.zktracer.runtime.stack.Stack.MAX_STACK_SIZE; -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; -import java.io.Reader; -import java.math.BigInteger; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.*; -import java.util.function.Consumer; - -import com.google.gson.Gson; -import lombok.Builder; -import lombok.RequiredArgsConstructor; -import lombok.Singular; -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.blockcapture.snapshots.BlockSnapshot; -import net.consensys.linea.blockcapture.snapshots.ConflationSnapshot; -import net.consensys.linea.blockcapture.snapshots.TransactionSnapshot; -import net.consensys.linea.corset.CorsetValidator; -import net.consensys.linea.zktracer.ZkTracer; -import net.consensys.linea.zktracer.module.hub.Exceptions; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.crypto.SECP256K1; -import org.hyperledger.besu.datatypes.*; -import org.hyperledger.besu.ethereum.core.*; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.ethereum.core.feemarket.CoinbaseFeePriceCalculator; -import org.hyperledger.besu.ethereum.mainnet.LondonTargetingGasLimitCalculator; -import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor; -import org.hyperledger.besu.ethereum.mainnet.TransactionValidatorFactory; -import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; -import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket; -import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; -import org.hyperledger.besu.evm.EVM; -import org.hyperledger.besu.evm.MainnetEVMs; -import org.hyperledger.besu.evm.gascalculator.GasCalculator; -import org.hyperledger.besu.evm.internal.EvmConfiguration; -import org.hyperledger.besu.evm.precompile.PrecompileContractRegistry; -import org.hyperledger.besu.evm.processor.ContractCreationProcessor; -import org.hyperledger.besu.evm.processor.MessageCallProcessor; -import org.hyperledger.besu.plugin.data.BlockHeader; - -/** Fluent API for executing EVM transactions in tests. */ -@Builder -@RequiredArgsConstructor -@Slf4j -public class ToyExecutionEnvironment { - public static final BigInteger CHAIN_ID = BigInteger.valueOf(1337); - private static final CorsetValidator corsetValidator = new CorsetValidator(); - - private static final Address DEFAULT_SENDER_ADDRESS = Address.fromHexString("0xe8f1b89"); - private static final Wei DEFAULT_VALUE = Wei.ZERO; - private static final Bytes DEFAULT_INPUT_DATA = Bytes.EMPTY; - private static final Bytes DEFAULT_BYTECODE = Bytes.EMPTY; - private static final long DEFAULT_GAS_LIMIT = 1_000_000; - private static final ToyWorld DEFAULT_TOY_WORLD = ToyWorld.empty(); - private static final Wei DEFAULT_BASE_FEE = Wei.of(1_000_000L); - - private static final GasCalculator gasCalculator = ZkTracer.gasCalculator; - private static final Address minerAddress = Address.fromHexString("0x1234532342"); - - private final ToyWorld toyWorld; - private final EVM evm; - @Builder.Default private BigInteger chainId = CHAIN_ID; - @Singular private final List transactions; - - /** - * A function applied to the {@link TransactionProcessingResult} of each transaction; by default, - * asserts that the transaction is successful. - */ - private final Consumer testValidator; - - private final Consumer zkTracerValidator; - - private static final FeeMarket feeMarket = FeeMarket.london(-1); - private final ZkTracer tracer = new ZkTracer(); - - /** - * Gets the default EVM implementation, i.e. London. - * - * @return default EVM implementation - */ - public static EVM defaultEvm() { - return MainnetEVMs.london(EvmConfiguration.DEFAULT); - } - - public void checkTracer() { - try { - final Path traceFile = Files.createTempFile(null, ".lt"); - this.tracer.writeToFile(traceFile); - log.info("trace written to `{}`", traceFile); - assertThat(corsetValidator.validate(traceFile).isValid()).isTrue(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public void run() { - this.execute(); - this.checkTracer(); - } - - /** - * Given a file containing the JSON serialization of a {@link ConflationSnapshot}, loads it, - * updates this's state to mirror it, and replays it. - * - * @param replayFile the file containing the conflation - */ - public void replay(final Reader replayFile) { - Gson gson = new Gson(); - ConflationSnapshot conflation; - try { - conflation = gson.fromJson(replayFile, ConflationSnapshot.class); - } catch (Exception e) { - log.error(e.getMessage()); - return; - } - this.executeFrom(conflation); - this.checkTracer(); - } - - /** - * Loads the states and the conflation defined in a {@link ConflationSnapshot}, mimick the - * accounts, storage and blocks state as it was on the blockchain before the conflation played - * out, then execute and check it. - * - * @param conflation the conflation to replay - */ - private void executeFrom(final ConflationSnapshot conflation) { - final ToyWorld overridenToyWorld = ToyWorld.of(conflation); - for (BlockSnapshot blockSnapshot : conflation.blocks()) { - for (TransactionSnapshot tx : blockSnapshot.txs()) { - this.chainId = tx.chainId(); - } - } - final MainnetTransactionProcessor transactionProcessor = getMainnetTransactionProcessor(); - - tracer.traceStartConflation(conflation.blocks().size()); - for (BlockSnapshot blockSnapshot : conflation.blocks()) { - BlockHeader header = blockSnapshot.header().toBlockHeader(); - BlockBody body = - new BlockBody( - blockSnapshot.txs().stream().map(TransactionSnapshot::toTransaction).toList(), - new ArrayList<>()); - tracer.traceStartBlock(header, body); - - for (Transaction tx : body.getTransactions()) { - final TransactionProcessingResult result = - transactionProcessor.processTransaction( - null, - overridenToyWorld.updater(), - (ProcessableBlockHeader) header, - tx, - header.getCoinbase(), - tracer, - blockId -> { - throw new RuntimeException("Block hash lookup not yet supported"); - }, - false, - Wei.ZERO); - } - tracer.traceEndBlock(header, body); - } - tracer.traceEndConflation(); - } - - private void execute() { - BlockHeader header = - BlockHeaderBuilder.createDefault() - .baseFee(DEFAULT_BASE_FEE) - .coinbase(minerAddress) - .buildBlockHeader(); - BlockBody mockBlockBody = new BlockBody(transactions, new ArrayList<>()); - - final MainnetTransactionProcessor transactionProcessor = getMainnetTransactionProcessor(); - - tracer.traceStartConflation(1); - tracer.traceStartBlock(header, mockBlockBody); - - for (Transaction tx : mockBlockBody.getTransactions()) { - final TransactionProcessingResult result = - transactionProcessor.processTransaction( - null, - toyWorld.updater(), - (ProcessableBlockHeader) header, - tx, - header.getCoinbase(), - tracer, - blockId -> { - throw new RuntimeException("Block hash lookup not yet supported"); - }, - false, - Wei.ZERO); - - this.testValidator.accept(result); - this.zkTracerValidator.accept(tracer); - } - tracer.traceEndBlock(header, mockBlockBody); - tracer.traceEndConflation(); - } - - private MainnetTransactionProcessor getMainnetTransactionProcessor() { - final MessageCallProcessor messageCallProcessor = - new MessageCallProcessor(evm, new PrecompileContractRegistry()); - - final ContractCreationProcessor contractCreationProcessor = - new ContractCreationProcessor(evm.getGasCalculator(), evm, false, List.of(), 0); - - return new MainnetTransactionProcessor( - gasCalculator, - new TransactionValidatorFactory( - gasCalculator, - new LondonTargetingGasLimitCalculator(0L, new LondonFeeMarket(0, Optional.empty())), - new LondonFeeMarket(0L), - false, - Optional.of(this.chainId), - Set.of(TransactionType.FRONTIER, TransactionType.ACCESS_LIST, TransactionType.EIP1559), - Exceptions.MAX_CODE_SIZE), - contractCreationProcessor, - messageCallProcessor, - true, - true, - MAX_STACK_SIZE, - feeMarket, - CoinbaseFeePriceCalculator.eip1559()); - } - - private static Transaction defaultTransaction() { - return Transaction.builder() - .nonce(123L) - .type(TransactionType.FRONTIER) - .gasPrice(Wei.of(1500)) - .gasLimit(DEFAULT_GAS_LIMIT) - .to(Address.fromHexString("0x1234567890")) - .value(DEFAULT_VALUE) - .payload(DEFAULT_INPUT_DATA) - .sender(DEFAULT_SENDER_ADDRESS) - .chainId(CHAIN_ID) - .signAndBuild(new SECP256K1().generateKeyPair()); - } - - /** Customizations applied to the Lombok generated builder. */ - public static class ToyExecutionEnvironmentBuilder { - /** - * Builder method returning an instance of {@link ToyExecutionEnvironment}. - * - * @return an instance of {@link ToyExecutionEnvironment} - */ - public ToyExecutionEnvironment build() { - var defaultTxList = new ArrayList<>(List.of(defaultTransaction())); - - return new ToyExecutionEnvironment( - Optional.ofNullable(toyWorld).orElse(DEFAULT_TOY_WORLD), - Optional.ofNullable(evm).orElse(defaultEvm()), - Optional.ofNullable(transactions).orElse(defaultTxList), - Optional.ofNullable(testValidator) - .orElse(result -> assertThat(result.isSuccessful()).isTrue()), - Optional.ofNullable(zkTracerValidator).orElse(zkTracer -> {})); - } - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyTransaction.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyTransaction.java deleted file mode 100644 index 8dfe6965d..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyTransaction.java +++ /dev/null @@ -1,93 +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.testing; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import lombok.Builder; -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.TransactionType; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.Transaction; - -@Builder -public class ToyTransaction { - private static final ToyAccount DEFAULT_SENDER = - ToyAccount.builder() - .nonce(1L) - .address(Address.fromHexString("0xe8f1b89")) - .balance(Wei.ONE) - .build(); - - private static final Wei DEFAULT_VALUE = Wei.ZERO; - private static final Bytes DEFAULT_INPUT_DATA = Bytes.EMPTY; - private static final long DEFAULT_GAS_LIMIT = 50_000L; // i.e. 21 000 + a bit - private static final Wei DEFAULT_GAS_PRICE = Wei.of(10_000_000L); - private static final TransactionType DEFAULT_TX_TYPE = TransactionType.FRONTIER; - private static final List DEFAULT_ACCESS_LIST = new ArrayList<>(); - private static final Wei DEFAULT_MAX_FEE_PER_GAS = Wei.of(37_000_000_000L); - private static final Wei DEFAULT_MAX_PRIORITY_FEE_PER_GAS = Wei.of(500_000_000L); - - private final ToyAccount to; - private final ToyAccount sender; - private final Wei gasPrice; - private final Long gasLimit; - private final Wei value; - private final TransactionType transactionType; - private final Bytes payload; - private final BigInteger chainId; - private final KeyPair keyPair; - private final List accessList; - private final Wei maxPriorityFeePerGas; - private final Wei maxFeePerGas; - - /** Customizations applied to the Lombok generated builder. */ - public static class ToyTransactionBuilder { - - /** - * Builder method returning an instance of {@link Transaction}. - * - * @return an instance of {@link Transaction} - */ - public Transaction build() { - final Transaction.Builder builder = - Transaction.builder() - .to(to != null ? to.getAddress() : null) - .nonce(sender.getNonce()) - .accessList(accessList) - .type(Optional.ofNullable(transactionType).orElse(DEFAULT_TX_TYPE)) - .gasPrice(Optional.ofNullable(gasPrice).orElse(DEFAULT_GAS_PRICE)) - .gasLimit(Optional.ofNullable(gasLimit).orElse(DEFAULT_GAS_LIMIT)) - .value(Optional.ofNullable(value).orElse(DEFAULT_VALUE)) - .payload(Optional.ofNullable(payload).orElse(DEFAULT_INPUT_DATA)) - .chainId(Optional.ofNullable(chainId).orElse(ToyExecutionEnvironment.CHAIN_ID)); - - if (transactionType == TransactionType.EIP1559) { - builder.maxPriorityFeePerGas( - Optional.ofNullable(maxPriorityFeePerGas).orElse(DEFAULT_MAX_PRIORITY_FEE_PER_GAS)); - builder.maxFeePerGas(Optional.ofNullable(maxFeePerGas).orElse(DEFAULT_MAX_FEE_PER_GAS)); - } - - return builder.signAndBuild(keyPair); - } - } -} 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 deleted file mode 100644 index b2b291526..000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyWorld.java +++ /dev/null @@ -1,192 +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.testing; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import lombok.Builder; -import lombok.Getter; -import lombok.Singular; -import net.consensys.linea.blockcapture.snapshots.AccountSnapshot; -import net.consensys.linea.blockcapture.snapshots.ConflationSnapshot; -import net.consensys.linea.blockcapture.snapshots.StorageSnapshot; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.internal.Words; -import org.hyperledger.besu.evm.worldstate.WorldUpdater; - -public class ToyWorld implements WorldUpdater { - private ToyWorld parent; - @Getter private List accounts; - private Map addressAccountMap; - - private ToyWorld() { - this(null, new ArrayList<>()); - } - - private ToyWorld(final ToyWorld parent) { - this(parent, new ArrayList<>()); - } - - @Builder - private ToyWorld(final ToyWorld parent, @Singular final List accounts) { - this.parent = parent; - this.accounts = accounts; - this.addressAccountMap = new HashMap<>(); - } - - public static ToyWorld empty() { - return builder().build(); - } - - public static ToyWorld of(final ConflationSnapshot conflation) { - final ToyWorldBuilder protoWorld = builder(); - for (AccountSnapshot account : conflation.accounts()) { - protoWorld.account( - ToyAccount.builder() - .address(Words.toAddress(Address.fromHexString(account.address()))) - .nonce(account.nonce()) - .balance(Wei.fromHexString(account.balance())) - .code(Bytes.fromHexString(account.code())) - .build()); - } - final ToyWorld world = protoWorld.build(); - - for (StorageSnapshot s : conflation.storage()) { - world - .getAccount(Words.toAddress(Bytes.fromHexString(s.address()))) - .setStorageValue(UInt256.fromHexString(s.key()), UInt256.fromHexString(s.value())); - } - - return world; - } - - @Override - public WorldUpdater updater() { - return new ToyWorld(this); - } - - @Override - public Account get(final Address address) { - if (addressAccountMap.containsKey(address)) { - return addressAccountMap.get(address); - } else if (parent != null) { - return parent.get(address); - } - - return null; - } - - @Override - public MutableAccount createAccount(final Address address, final long nonce, final Wei balance) { - return createAccount(null, address, nonce, balance, Bytes.EMPTY); - } - - public MutableAccount createAccount( - final Account parentAccount, - final Address address, - final long nonce, - final Wei balance, - final Bytes code) { - - ToyAccount account = - ToyAccount.builder() - .parent(parentAccount) - .code(code) - .address(address) - .nonce(nonce) - .balance(balance) - .build(); - - accounts.add(account); - addressAccountMap.put(address, account); - - return account; - } - - @Override - public MutableAccount getAccount(final Address address) { - if (addressAccountMap.containsKey(address)) { - return addressAccountMap.get(address); - } else if (parent != null) { - return parent.getAccount(address); - } - - return null; - } - - @Override - public void deleteAccount(final Address address) { - addressAccountMap.put(address, null); - } - - @Override - public Collection getTouchedAccounts() { - return addressAccountMap.values(); - } - - @Override - public Collection
getDeletedAccountAddresses() { - return addressAccountMap.entrySet().stream() - .filter(e -> e.getValue() == null) - .map(Map.Entry::getKey) - .toList(); - } - - @Override - public void revert() { - addressAccountMap = new HashMap<>(); - } - - @Override - public void commit() { - if (parent != null) { - parent.addressAccountMap.putAll(addressAccountMap); - } - } - - @Override - public Optional parentUpdater() { - return Optional.empty(); - } - - public static class ToyWorldBuilder { - public ToyWorld build() { - ToyWorld toyWorld = new ToyWorld(parent); - if (accounts != null) { - for (ToyAccount account : accounts) { - toyWorld.createAccount( - null, - account.getAddress(), - account.getNonce(), - account.getBalance(), - account.getCode()); - } - } - - return toyWorld; - } - } -} diff --git a/gradle.properties b/gradle.properties index ae5f5b73b..528576019 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ releaseVersion=0.1.4-SNAPSHOT besuVersion=24.4-develop-a5a3eb8 besuArtifactGroup=io.consensys.linea-besu -distributionIdentifier=besu-sequencer-plugins +distributionIdentifier=linea-sequencer distributionBaseUrl=https://artifacts.consensys.net/public/linea-besu/raw/names/linea-besu.tar.gz/versions/ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. diff --git a/gradle/dependency-management.gradle b/gradle/dependency-management.gradle index 3ced8b1ee..5cadebce1 100644 --- a/gradle/dependency-management.gradle +++ b/gradle/dependency-management.gradle @@ -16,7 +16,9 @@ repositories { maven { url "https://artifacts.consensys.net/public/linea-besu/maven/" - content { includeGroupByRegex('io\\.consensys\\..*') } + content { + includeGroupByRegex('io\\.consensys\\..*') + } } maven { url 'https://hyperledger.jfrog.io/hyperledger/besu-maven' @@ -24,7 +26,15 @@ repositories { } maven { url 'https://artifacts.consensys.net/public/maven/maven/' - content { includeGroupByRegex('tech\\.pegasys(\\..*)?') } + content { + includeGroupByRegex('tech\\.pegasys(\\..*)?') + } + } + maven { + url "https://artifacts.consensys.net/public/linea-arithmetization/maven/" + content { + includeGroupByRegex('net\\.consensys\\.linea\\..*?') + } } maven { url 'https://splunk.jfrog.io/splunk/ext-releases-local' @@ -48,6 +58,7 @@ dependencyManagement { } dependencies { + dependency 'net.consensys.linea.zktracer:arithmetization:0.1.4-20240421.234102-3' dependencySet(group: 'io.tmio', version: '2.4.2') { entry 'tuweni-bytes' entry 'tuweni-net' diff --git a/native/compress/compress-jni/go.mod b/native/compress/compress-jni/go.mod index c7723b602..0316e0696 100644 --- a/native/compress/compress-jni/go.mod +++ b/native/compress/compress-jni/go.mod @@ -1,4 +1,4 @@ -module github.com/consensys/besu-sequencer-plugins +module github.com/consensys/linea-sequencer go 1.20 diff --git a/reference-tests/build.gradle b/reference-tests/build.gradle deleted file mode 100644 index 4f5366394..000000000 --- a/reference-tests/build.gradle +++ /dev/null @@ -1,104 +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 - */ - -plugins { - id "common-plugins" -} - -apply from: rootProject.file("gradle/corset.gradle") -apply from: rootProject.file("gradle/java.gradle") -apply from: rootProject.file("gradle/tests.gradle") -apply from: rootProject.file("gradle/dependency-management.gradle") -apply from: rootProject.file('gradle/common-dependencies.gradle') -apply from: rootProject.file("gradle/lint.gradle") - -tasks.register("generateBlockchainReferenceTests", RefTestGenerationTask) { - refTestTemplateFilePath = "src/test/resources/templates/BlockchainReferenceTest.java.template" - refTests = "src/test/resources/ethereum-tests/BlockchainTests" - refTestJsonParamsDirectory = "BlockchainTests" - refTestJsonParamsExcludedPath = "BlockchainTests/InvalidBlocks/bcExpectSection" // exclude test for test filling tool - refTestNamePrefix = "BlockchainReferenceTest" - generatedRefTestsOutput = "src/test/java/net/consensys/linea/generated/blockchain" -} - -tasks.register("generateGeneralStateReferenceTests", RefTestGenerationTask) { - refTestTemplateFilePath = "src/test/resources/templates/GeneralStateReferenceTest.java.template" - refTests = "src/test/resources/ethereum-tests/GeneralStateTests" - refTestJsonParamsDirectory = "ethereum-tests/GeneralStateTests" - refTestJsonParamsExcludedPath = "" - refTestNamePrefix = "GeneralStateReferenceTest" - generatedRefTestsOutput = "src/test/java/net/consensys/linea/generated/generalstate" -} - -tasks.register('referenceBlockchainTests', Test) { - description = 'Runs ETH reference blockchain tests.' - - dependsOn generateBlockchainReferenceTests - - minHeapSize = "4g" - maxHeapSize = "20g" - - useJUnitPlatform { - includeTags("BlockchainReferenceTest") - } -} - -tasks.register('referenceGeneralStateTests', Test) { - description = 'Runs ETH reference general state tests.' - - dependsOn generateGeneralStateReferenceTests - - minHeapSize = "4g" - maxHeapSize = "20g" - - useJUnitPlatform { - includeTags("GeneralStateReferenceTest") - } -} - -tasks.register('referenceTests', Test) { - description = 'Runs ETH reference tests.' - - minHeapSize = "4g" - maxHeapSize = "20g" - - useJUnitPlatform { - includeTags("BlockchainReferenceTest") - includeTags("GeneralStateReferenceTest") - } -} - - -dependencies { - testImplementation project(":arithmetization") - testImplementation "${besuArtifactGroup}:besu-datatypes" - testImplementation "${besuArtifactGroup}:evm" - testImplementation "${besuArtifactGroup}.internal:config:${besuVersion}" - testImplementation "${besuArtifactGroup}.internal:core:${besuVersion}" - testImplementation "${besuArtifactGroup}.internal:algorithms:${besuVersion}" - testImplementation "${besuArtifactGroup}.internal:metrics-core:${besuVersion}" - testImplementation "${besuArtifactGroup}.internal:referencetests:${besuVersion}" - testImplementation "${besuArtifactGroup}.internal:rlp:${besuVersion}" - testImplementation "${besuArtifactGroup}.internal:testutil:${besuVersion}" - testImplementation "${besuArtifactGroup}.internal:trie:$besuVersion" - testImplementation "${besuArtifactGroup}.internal:util:${besuVersion}" - testImplementation "${besuArtifactGroup}:plugin-api" - - testImplementation 'io.tmio:tuweni-bytes' - testImplementation 'io.tmio:tuweni-units' - - testImplementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8' - testImplementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml' -} diff --git a/reference-tests/src/test/java/net/consensys/linea/BlockchainReferenceTestTools.java b/reference-tests/src/test/java/net/consensys/linea/BlockchainReferenceTestTools.java deleted file mode 100644 index 79f60e4f2..000000000 --- a/reference-tests/src/test/java/net/consensys/linea/BlockchainReferenceTestTools.java +++ /dev/null @@ -1,169 +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; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import net.consensys.linea.corset.CorsetValidator; -import net.consensys.linea.zktracer.ZkTracer; -import org.hyperledger.besu.ethereum.MainnetBlockValidator; -import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.Block; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MutableWorldState; -import org.hyperledger.besu.ethereum.mainnet.BlockImportResult; -import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; -import org.hyperledger.besu.ethereum.mainnet.MainnetBlockImporter; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; -import org.hyperledger.besu.ethereum.referencetests.BlockchainReferenceTestCaseSpec; -import org.hyperledger.besu.ethereum.referencetests.ReferenceTestProtocolSchedules; -import org.hyperledger.besu.ethereum.rlp.RLPException; -import org.hyperledger.besu.testutil.JsonTestParameters; - -public class BlockchainReferenceTestTools { - private static final ReferenceTestProtocolSchedules REFERENCE_TEST_PROTOCOL_SCHEDULES = - ReferenceTestProtocolSchedules.create(); - - private static final List NETWORKS_TO_RUN = List.of("London"); - - private static final JsonTestParameters PARAMS = - JsonTestParameters.create(BlockchainReferenceTestCaseSpec.class) - .generator( - (testName, fullPath, spec, collector) -> { - final String eip = spec.getNetwork(); - collector.add( - testName + "[" + eip + "]", fullPath, spec, NETWORKS_TO_RUN.contains(eip)); - }); - - private static final CorsetValidator corsetValidator = new CorsetValidator(); - - static { - if (NETWORKS_TO_RUN.isEmpty()) { - PARAMS.ignoreAll(); - } - - // Consumes a huge amount of memory. - PARAMS.ignore("static_Call1MB1024Calldepth_d1g0v0_\\w+"); - PARAMS.ignore("ShanghaiLove_.*"); - PARAMS.ignore("/GeneralStateTests/VMTests/vmPerformance/"); - - // Absurd amount of gas, doesn't run in parallel. - PARAMS.ignore("randomStatetest94_\\w+"); - - // Don't do time-consuming tests. - PARAMS.ignore("CALLBlake2f_MaxRounds.*"); - PARAMS.ignore("loopMul_*"); - - // Inconclusive fork choice rule, since in merge CL should be choosing forks and setting the - // chain head. - // Perfectly valid test pre-merge. - PARAMS.ignore("UncleFromSideChain_(Merge|Shanghai|Cancun|Prague|Osaka|Bogota)"); - - // EOF tests are written against an older version of the spec. - PARAMS.ignore("/stEOF/"); - } - - private BlockchainReferenceTestTools() { - // utility class - } - - public static Collection generateTestParametersForConfig(final String[] filePath) { - return PARAMS.generate( - Arrays.stream(filePath) - .map(f -> Paths.get("src/test/resources/ethereum-tests/" + f).toFile()) - .toList()); - } - - public static void executeTest(final BlockchainReferenceTestCaseSpec spec) { - final BlockHeader genesisBlockHeader = spec.getGenesisBlockHeader(); - final MutableWorldState worldState = - spec.getWorldStateArchive() - .getMutable(genesisBlockHeader.getStateRoot(), genesisBlockHeader.getHash()) - .get(); - assertThat(worldState.rootHash()).isEqualTo(genesisBlockHeader.getStateRoot()); - - final ProtocolSchedule schedule = - REFERENCE_TEST_PROTOCOL_SCHEDULES.getByName(spec.getNetwork()); - - final MutableBlockchain blockchain = spec.getBlockchain(); - final ProtocolContext context = spec.getProtocolContext(); - - for (var candidateBlock : spec.getCandidateBlocks()) { - if (!candidateBlock.isExecutable()) { - return; - } - - final ZkTracer zkTracer = new ZkTracer(); - - try { - final Block block = candidateBlock.getBlock(); - - final ProtocolSpec protocolSpec = schedule.getByBlockHeader(block.getHeader()); - - final MainnetBlockImporter blockImporter = - getMainnetBlockImporter(context, protocolSpec, schedule, zkTracer); - - final HeaderValidationMode validationMode = - "NoProof".equalsIgnoreCase(spec.getSealEngine()) - ? HeaderValidationMode.LIGHT - : HeaderValidationMode.FULL; - - final BlockImportResult importResult = - blockImporter.importBlock(context, block, validationMode, validationMode); - - assertThat(importResult.isImported()).isEqualTo(candidateBlock.isValid()); - } catch (final RLPException e) { - assertThat(candidateBlock.isValid()).isFalse(); - } - - assertThat(corsetValidator.validate(zkTracer.writeToTmpFile()).isValid()).isTrue(); - } - - assertThat(blockchain.getChainHeadHash()).isEqualTo(spec.getLastBlockHash()); - } - - private static MainnetBlockImporter getMainnetBlockImporter( - final ProtocolContext context, - final ProtocolSpec protocolSpec, - final ProtocolSchedule schedule, - final ZkTracer zkTracer) { - CorsetBlockProcessor corsetBlockProcessor = - new CorsetBlockProcessor( - protocolSpec.getTransactionProcessor(), - protocolSpec.getTransactionReceiptFactory(), - protocolSpec.getBlockReward(), - protocolSpec.getMiningBeneficiaryCalculator(), - protocolSpec.isSkipZeroBlockRewards(), - schedule, - zkTracer); - - MainnetBlockValidator blockValidator = - new MainnetBlockValidator( - protocolSpec.getBlockHeaderValidator(), - protocolSpec.getBlockBodyValidator(), - corsetBlockProcessor, - context.getBadBlockManager()); - - return new MainnetBlockImporter(blockValidator); - } -} diff --git a/reference-tests/src/test/java/net/consensys/linea/CorsetBlockProcessor.java b/reference-tests/src/test/java/net/consensys/linea/CorsetBlockProcessor.java deleted file mode 100644 index 2deddabab..000000000 --- a/reference-tests/src/test/java/net/consensys/linea/CorsetBlockProcessor.java +++ /dev/null @@ -1,200 +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; - -import static org.hyperledger.besu.ethereum.mainnet.feemarket.ExcessBlobGasCalculator.calculateExcessBlobGasForParent; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.zktracer.ZkTracer; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.BlockProcessingOutputs; -import org.hyperledger.besu.ethereum.BlockProcessingResult; -import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.BlockBody; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.Deposit; -import org.hyperledger.besu.ethereum.core.MutableWorldState; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.ethereum.core.TransactionReceipt; -import org.hyperledger.besu.ethereum.core.Withdrawal; -import org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor; -import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor; -import org.hyperledger.besu.ethereum.mainnet.MiningBeneficiaryCalculator; -import org.hyperledger.besu.ethereum.mainnet.ParentBeaconBlockRootHelper; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; -import org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams; -import org.hyperledger.besu.ethereum.mainnet.WithdrawalsProcessor; -import org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater; -import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; -import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.worldview.BonsaiWorldState; -import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.worldview.BonsaiWorldStateUpdateAccumulator; -import org.hyperledger.besu.ethereum.vm.BlockHashLookup; -import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup; -import org.hyperledger.besu.evm.worldstate.WorldUpdater; - -@Slf4j -public class CorsetBlockProcessor extends MainnetBlockProcessor { - private final ProtocolSchedule protocolSchedule; - private final ZkTracer zkTracer; - - public CorsetBlockProcessor( - final MainnetTransactionProcessor transactionProcessor, - final TransactionReceiptFactory transactionReceiptFactory, - final Wei blockReward, - final MiningBeneficiaryCalculator miningBeneficiaryCalculator, - final boolean skipZeroBlockRewards, - final ProtocolSchedule protocolSchedule, - final ZkTracer zkTracer) { - super( - transactionProcessor, - transactionReceiptFactory, - blockReward, - miningBeneficiaryCalculator, - skipZeroBlockRewards, - protocolSchedule); - this.protocolSchedule = protocolSchedule; - this.zkTracer = zkTracer; - } - - @Override - public BlockProcessingResult processBlock( - final Blockchain blockchain, - final MutableWorldState worldState, - final BlockHeader blockHeader, - final List transactions, - final List ommers, - final Optional> maybeWithdrawals, - final Optional> maybeDeposits, - final PrivateMetadataUpdater privateMetadataUpdater) { - final List receipts = new ArrayList<>(); - long currentGasUsed = 0; - BlockBody blockBody = new BlockBody(transactions, new ArrayList<>()); - - final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(blockHeader); - - if (blockHeader.getParentBeaconBlockRoot().isPresent()) { - final WorldUpdater updater = worldState.updater(); - ParentBeaconBlockRootHelper.storeParentBeaconBlockRoot( - updater, blockHeader.getTimestamp(), blockHeader.getParentBeaconBlockRoot().get()); - } - - for (final Transaction transaction : transactions) { - if (!hasAvailableBlockBudget(blockHeader, transaction, currentGasUsed)) { - return new BlockProcessingResult(Optional.empty(), "provided gas insufficient"); - } - - final WorldUpdater worldStateUpdater = worldState.updater(); - - final BlockHashLookup blockHashLookup = new CachingBlockHashLookup(blockHeader, blockchain); - final Address miningBeneficiary = - miningBeneficiaryCalculator.calculateBeneficiary(blockHeader); - - Optional maybeParentHeader = - blockchain.getBlockHeader(blockHeader.getParentHash()); - - Wei blobGasPrice = - maybeParentHeader - .map( - (parentHeader) -> - protocolSpec - .getFeeMarket() - .blobGasPricePerGas( - calculateExcessBlobGasForParent(protocolSpec, parentHeader))) - .orElse(Wei.ZERO); - - zkTracer.traceStartConflation(1); - zkTracer.traceStartBlock(blockHeader, blockBody); - final TransactionProcessingResult result = - transactionProcessor.processTransaction( - blockchain, - worldStateUpdater, - blockHeader, - transaction, - miningBeneficiary, - zkTracer, - blockHashLookup, - true, - TransactionValidationParams.processingBlock(), - privateMetadataUpdater, - blobGasPrice); - - if (result.isInvalid()) { - String errorMessage = - MessageFormat.format( - "Block processing error: transaction invalid {0}. Block {1} Transaction {2}", - result.getValidationResult().getErrorMessage(), - blockHeader.getHash().toHexString(), - transaction.getHash().toHexString()); - log.info(errorMessage); - if (worldState instanceof BonsaiWorldState) { - ((BonsaiWorldStateUpdateAccumulator) worldStateUpdater).reset(); - } - return new BlockProcessingResult(Optional.empty(), errorMessage); - } - worldStateUpdater.commit(); - - currentGasUsed += transaction.getGasLimit() - result.getGasRemaining(); - final TransactionReceipt transactionReceipt = - transactionReceiptFactory.create( - transaction.getType(), result, worldState, currentGasUsed); - receipts.add(transactionReceipt); - } - - final Optional maybeWithdrawalsProcessor = - protocolSpec.getWithdrawalsProcessor(); - if (maybeWithdrawalsProcessor.isPresent() && maybeWithdrawals.isPresent()) { - try { - maybeWithdrawalsProcessor - .get() - .processWithdrawals(maybeWithdrawals.get(), worldState.updater()); - } catch (final Exception e) { - log.error("failed processing withdrawals", e); - return new BlockProcessingResult(Optional.empty(), e); - } - } - - if (!rewardCoinbase(worldState, blockHeader, ommers, skipZeroBlockRewards)) { - // no need to log, rewardCoinbase logs the error. - if (worldState instanceof BonsaiWorldState) { - ((BonsaiWorldStateUpdateAccumulator) worldState.updater()).reset(); - } - return new BlockProcessingResult(Optional.empty(), "ommer too old"); - } - - try { - worldState.persist(blockHeader); - // } catch (MerkleTrieException e) { - // if (worldState instanceof BonsaiWorldState) { - // ((BonsaiWorldStateUpdateAccumulator) worldState.updater()).reset(); - // } - // throw e; - } catch (Exception e) { - log.error("failed persisting block", e); - return new BlockProcessingResult(Optional.empty(), e); - } - zkTracer.traceEndBlock(blockHeader, blockBody); - zkTracer.traceEndConflation(); - - return new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(worldState, receipts))); - } -} diff --git a/reference-tests/src/test/java/net/consensys/linea/EvmExtension.java b/reference-tests/src/test/java/net/consensys/linea/EvmExtension.java deleted file mode 100644 index a6159f46f..000000000 --- a/reference-tests/src/test/java/net/consensys/linea/EvmExtension.java +++ /dev/null @@ -1,31 +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; - -import net.consensys.linea.zktracer.opcode.OpCodes; -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.ExtensionContext; - -/** - * A JUnit {@link org.junit.jupiter.api.extension.Extension} handling the test lifecycle for EVM - * tests. - */ -public class EvmExtension implements BeforeAllCallback { - @Override - public void beforeAll(ExtensionContext context) { - OpCodes.load(); - } -} diff --git a/reference-tests/src/test/java/net/consensys/linea/GeneralStateReferenceTestTools.java b/reference-tests/src/test/java/net/consensys/linea/GeneralStateReferenceTestTools.java deleted file mode 100644 index 0aebb4a3d..000000000 --- a/reference-tests/src/test/java/net/consensys/linea/GeneralStateReferenceTestTools.java +++ /dev/null @@ -1,235 +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; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import lombok.SneakyThrows; -import net.consensys.linea.corset.CorsetValidator; -import net.consensys.linea.zktracer.ZkTracer; -import org.hyperledger.besu.datatypes.BlobGas; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.*; -import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; -import org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams; -import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; -import org.hyperledger.besu.ethereum.referencetests.GeneralStateTestCaseEipSpec; -import org.hyperledger.besu.ethereum.referencetests.GeneralStateTestCaseSpec; -import org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain; -import org.hyperledger.besu.ethereum.referencetests.ReferenceTestProtocolSchedules; -import org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState; -import org.hyperledger.besu.ethereum.rlp.RLP; -import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.log.Log; -import org.hyperledger.besu.evm.worldstate.WorldUpdater; -import org.hyperledger.besu.testutil.JsonTestParameters; - -public class GeneralStateReferenceTestTools { - private static final ReferenceTestProtocolSchedules REFERENCE_TEST_PROTOCOL_SCHEDULES = - ReferenceTestProtocolSchedules.create(); - private static final List SPECS_PRIOR_TO_DELETING_EMPTY_ACCOUNTS = - Arrays.asList("Frontier", "Homestead", "EIP150"); - private static final CorsetValidator corsetValidator = new CorsetValidator(); - - private static MainnetTransactionProcessor transactionProcessor(final String name) { - return protocolSpec(name).getTransactionProcessor(); - } - - private static ProtocolSpec protocolSpec(final String name) { - return REFERENCE_TEST_PROTOCOL_SCHEDULES - .getByName(name) - .getByBlockHeader(BlockHeaderBuilder.createDefault().buildBlockHeader()); - } - - private static final List EIPS_TO_RUN; - - static { - final String eips = - System.getProperty( - "test.ethereum.state.eips", - "Frontier,Homestead,EIP150,EIP158,Byzantium,Constantinople,ConstantinopleFix,Istanbul,Berlin," - + "London" /* + ",Merge,Shanghai,Cancun,Prague,Osaka,Bogota"*/); - EIPS_TO_RUN = Arrays.asList(eips.split(",")); - } - - private static final JsonTestParameters PARAMS = - JsonTestParameters.create(GeneralStateTestCaseSpec.class, GeneralStateTestCaseEipSpec.class) - .generator( - (testName, fullPath, stateSpec, collector) -> { - final String prefix = testName + "-"; - for (final Map.Entry> entry : - stateSpec.finalStateSpecs().entrySet().stream() - .filter(e -> e.getKey().equalsIgnoreCase("London")) - .toList()) { - final String eip = entry.getKey(); - final boolean runTest = EIPS_TO_RUN.contains(eip); - final List eipSpecs = entry.getValue(); - if (eipSpecs.size() == 1) { - collector.add(prefix + eip, fullPath, eipSpecs.get(0), runTest); - } else { - for (int i = 0; i < eipSpecs.size(); i++) { - collector.add( - prefix + eip + '[' + i + ']', fullPath, eipSpecs.get(i), runTest); - } - } - } - }); - - static { - if (EIPS_TO_RUN.isEmpty()) { - PARAMS.ignoreAll(); - } - - // Consumes a huge amount of memory - PARAMS.ignore("static_Call1MB1024Calldepth-\\w"); - PARAMS.ignore("ShanghaiLove_.*"); - PARAMS.ignore("VMTests/vmPerformance/"); - - // Don't do time consuming tests - PARAMS.ignore("CALLBlake2f_MaxRounds.*"); - PARAMS.ignore("loopMul-.*"); - - // Reference Tests are old. Max blob count is 6. - PARAMS.ignore("blobhashListBounds5"); - - // EOF tests are written against an older version of the spec - PARAMS.ignore("/stEOF/"); - - // Not compliant with the zkEVM requirements. - PARAMS.ignore("stPreCompiledContracts2/modexpRandomInput.*"); - PARAMS.ignore("tQuadraticComplexityTest/Call50000_ecrec.*"); - PARAMS.ignore("stStaticCall/static_Call50000_ecrec.*"); - PARAMS.ignore("stRandom2/randomStatetest642.*"); - PARAMS.ignore("stRandom2/randomStatetest644.*"); - PARAMS.ignore("stRandom2/randomStatetest645.*"); - } - - private GeneralStateReferenceTestTools() { - // utility class - } - - public static Collection generateTestParametersForConfig(final String[] filePath) { - return PARAMS.generate(filePath); - } - - @SneakyThrows - public static void executeTest(final GeneralStateTestCaseEipSpec spec) { - final BlockHeader blockHeader = spec.getBlockHeader(); - final ReferenceTestWorldState initialWorldState = spec.getInitialWorldState(); - final Transaction transaction = spec.getTransaction(); - final BlockBody blockBody = new BlockBody(List.of(transaction), new ArrayList<>()); - - // Sometimes the tests ask us assemble an invalid transaction. If we have - // no valid transaction then there is no test. GeneralBlockChain tests - // will handle the case where we receive the TXs in a serialized form. - if (transaction == null) { - assertThat(spec.getExpectException()) - .withFailMessage("Transaction was not assembled, but no exception was expected") - .isNotNull(); - return; - } - - final MutableWorldState worldState = initialWorldState.copy(); - // Several of the GeneralStateTests check if the transaction could potentially - // consume more gas than is left for the block it's attempted to be included in. - // This check is performed within the `BlockImporter` rather than inside the - // `TransactionProcessor`, so these tests are skipped. - if (transaction.getGasLimit() > blockHeader.getGasLimit() - blockHeader.getGasUsed()) { - return; - } - - final MainnetTransactionProcessor processor = transactionProcessor(spec.getFork()); - final WorldUpdater worldStateUpdater = worldState.updater(); - final ReferenceTestBlockchain blockchain = new ReferenceTestBlockchain(blockHeader.getNumber()); - final Wei blobGasPrice = - protocolSpec(spec.getFork()) - .getFeeMarket() - .blobGasPricePerGas(blockHeader.getExcessBlobGas().orElse(BlobGas.ZERO)); - - final ZkTracer zkTracer = new ZkTracer(); - zkTracer.traceStartConflation(1); - zkTracer.traceStartBlock(blockHeader, blockBody); - - final TransactionProcessingResult result = - processor.processTransaction( - blockchain, - worldStateUpdater, - blockHeader, - transaction, - blockHeader.getCoinbase(), - zkTracer, - new CachingBlockHashLookup(blockHeader, blockchain), - false, - TransactionValidationParams.processingBlock(), - blobGasPrice); - if (result.isInvalid()) { - assertThat(spec.getExpectException()) - .withFailMessage(() -> result.getValidationResult().getErrorMessage()) - .isNotNull(); - return; - } - - zkTracer.traceEndBlock(blockHeader, blockBody); - zkTracer.traceEndConflation(); - - assertThat(spec.getExpectException()) - .withFailMessage("Exception was expected - " + spec.getExpectException()) - .isNull(); - - final Account coinbase = worldStateUpdater.getOrCreate(spec.getBlockHeader().getCoinbase()); - if (coinbase != null && coinbase.isEmpty() && shouldClearEmptyAccounts(spec.getFork())) { - worldStateUpdater.deleteAccount(coinbase.getAddress()); - } - worldStateUpdater.commit(); - worldState.persist(blockHeader); - - // Check the world state root hash. - final Hash expectedRootHash = spec.getExpectedRootHash(); - assertThat(worldState.rootHash()) - .withFailMessage( - "Unexpected world state root hash; expected state: %s, computed state: %s", - spec.getExpectedRootHash(), worldState.rootHash()) - .isEqualTo(expectedRootHash); - - // Check the logs. - final Hash expectedLogsHash = spec.getExpectedLogsHash(); - Optional.ofNullable(expectedLogsHash) - .ifPresent( - expected -> { - final List logs = result.getLogs(); - - assertThat(Hash.hash(RLP.encode(out -> out.writeList(logs, Log::writeTo)))) - .withFailMessage("Unmatched logs hash. Generated logs: %s", logs) - .isEqualTo(expected); - }); - - assertThat(corsetValidator.validate(zkTracer.writeToTmpFile()).isValid()).isTrue(); - } - - private static boolean shouldClearEmptyAccounts(final String eip) { - return !SPECS_PRIOR_TO_DELETING_EMPTY_ACCOUNTS.contains(eip); - } -} diff --git a/reference-tests/src/test/java/net/consensys/linea/generated/.gitkeep b/reference-tests/src/test/java/net/consensys/linea/generated/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/reference-tests/src/test/resources/ethereum-tests b/reference-tests/src/test/resources/ethereum-tests deleted file mode 160000 index 02c185963..000000000 --- a/reference-tests/src/test/resources/ethereum-tests +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 02c1859633abbdf776956136931ea247485c9f90 diff --git a/reference-tests/src/test/resources/templates/BlockchainReferenceTest.java.template b/reference-tests/src/test/resources/templates/BlockchainReferenceTest.java.template deleted file mode 100644 index 318b5949d..000000000 --- a/reference-tests/src/test/resources/templates/BlockchainReferenceTest.java.template +++ /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.generated.blockchain; - -import static net.consensys.linea.BlockchainReferenceTestTools.executeTest; -import static net.consensys.linea.BlockchainReferenceTestTools.generateTestParametersForConfig; - -import java.util.stream.Stream; - -import net.consensys.linea.EvmExtension; - -import org.hyperledger.besu.ethereum.referencetests.BlockchainReferenceTestCaseSpec; -import org.junit.jupiter.api.Tag; -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; - -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -/** The blockchain test operation testing framework entry point. */ -@Tag("BlockchainReferenceTest") -@ExtendWith(EvmExtension.class) -public class %%TESTS_NAME%% { - - private static final String[] TEST_CONFIG_FILE_DIR_PATH = new String[] {%%TESTS_FILE%%}; - - public static Stream getTestParametersForConfig() { - return generateTestParametersForConfig(TEST_CONFIG_FILE_DIR_PATH).stream().map(params -> - Arguments.of(params[0], params[1], params[2]) - ); - } - - @ParameterizedTest(name = "Name: {0}") - @MethodSource("getTestParametersForConfig") - public void execution( - final String name, - final BlockchainReferenceTestCaseSpec spec, - final boolean runTest) { - assumeTrue(runTest, "Test " + name + " was ignored"); - executeTest(spec); - } -} diff --git a/reference-tests/src/test/resources/templates/GeneralStateReferenceTest.java.template b/reference-tests/src/test/resources/templates/GeneralStateReferenceTest.java.template deleted file mode 100644 index 03a58c424..000000000 --- a/reference-tests/src/test/resources/templates/GeneralStateReferenceTest.java.template +++ /dev/null @@ -1,55 +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.generated.generalstate; - -import static net.consensys.linea.GeneralStateReferenceTestTools.executeTest; -import static net.consensys.linea.GeneralStateReferenceTestTools.generateTestParametersForConfig; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -import net.consensys.linea.EvmExtension; - -import java.util.stream.Stream; - -import org.hyperledger.besu.ethereum.referencetests.GeneralStateTestCaseEipSpec; -import org.junit.jupiter.api.Tag; -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; - -/** The general state test operation testing framework entry point. */ -@Tag("GeneralStateReferenceTest") -@ExtendWith(EvmExtension.class) -public class %%TESTS_NAME%% { - - private static final String[] TEST_CONFIG_FILE_DIR_PATH = new String[] {%%TESTS_FILE%%}; - - public static Stream getTestParametersForConfig() { - return generateTestParametersForConfig(TEST_CONFIG_FILE_DIR_PATH).stream().map(params -> - Arguments.of(params[0], params[1], params[2]) - ); - } - - @ParameterizedTest(name = "Name: {0}") - @MethodSource("getTestParametersForConfig") - public void execution( - final String name, - final GeneralStateTestCaseEipSpec spec, - final boolean runTest) { - assumeTrue(runTest, "Test " + name + " was ignored"); - executeTest(spec); - } -} diff --git a/arithmetization/LICENSE b/sequencer/LICENSE similarity index 100% rename from arithmetization/LICENSE rename to sequencer/LICENSE diff --git a/arithmetization/build.gradle b/sequencer/build.gradle similarity index 97% rename from arithmetization/build.gradle rename to sequencer/build.gradle index 47db86595..2acdc039d 100644 --- a/arithmetization/build.gradle +++ b/sequencer/build.gradle @@ -40,6 +40,7 @@ dependencies { compileOnly 'com.google.auto.service:auto-service' compileOnly 'com.google.auto.service:auto-service-annotations' + implementation 'net.consensys.linea.zktracer:arithmetization:0.1.4-20240421.234102-3' implementation "${besuArtifactGroup}:evm" implementation "${besuArtifactGroup}:plugin-api" implementation "${besuArtifactGroup}:besu-datatypes" diff --git a/arithmetization/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java b/sequencer/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java rename to sequencer/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java diff --git a/arithmetization/src/main/java/net/consensys/linea/AbstractLineaSharedOptionsPlugin.java b/sequencer/src/main/java/net/consensys/linea/AbstractLineaSharedOptionsPlugin.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/AbstractLineaSharedOptionsPlugin.java rename to sequencer/src/main/java/net/consensys/linea/AbstractLineaSharedOptionsPlugin.java diff --git a/arithmetization/src/main/java/net/consensys/linea/bl/TransactionProfitabilityCalculator.java b/sequencer/src/main/java/net/consensys/linea/bl/TransactionProfitabilityCalculator.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/bl/TransactionProfitabilityCalculator.java rename to sequencer/src/main/java/net/consensys/linea/bl/TransactionProfitabilityCalculator.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaL1L2BridgeCliOptions.java b/sequencer/src/main/java/net/consensys/linea/config/LineaL1L2BridgeCliOptions.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaL1L2BridgeCliOptions.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaL1L2BridgeCliOptions.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaL1L2BridgeConfiguration.java b/sequencer/src/main/java/net/consensys/linea/config/LineaL1L2BridgeConfiguration.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaL1L2BridgeConfiguration.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaL1L2BridgeConfiguration.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaProfitabilityCliOptions.java b/sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityCliOptions.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaProfitabilityCliOptions.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityCliOptions.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaProfitabilityConfiguration.java b/sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityConfiguration.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaProfitabilityConfiguration.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityConfiguration.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaRpcCliOptions.java b/sequencer/src/main/java/net/consensys/linea/config/LineaRpcCliOptions.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaRpcCliOptions.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaRpcCliOptions.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaRpcConfiguration.java b/sequencer/src/main/java/net/consensys/linea/config/LineaRpcConfiguration.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaRpcConfiguration.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaRpcConfiguration.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaTracerCliOptions.java b/sequencer/src/main/java/net/consensys/linea/config/LineaTracerCliOptions.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaTracerCliOptions.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaTracerCliOptions.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaTracerConfiguration.java b/sequencer/src/main/java/net/consensys/linea/config/LineaTracerConfiguration.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaTracerConfiguration.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaTracerConfiguration.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaTransactionPoolValidatorCliOptions.java b/sequencer/src/main/java/net/consensys/linea/config/LineaTransactionPoolValidatorCliOptions.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaTransactionPoolValidatorCliOptions.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaTransactionPoolValidatorCliOptions.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaTransactionPoolValidatorConfiguration.java b/sequencer/src/main/java/net/consensys/linea/config/LineaTransactionPoolValidatorConfiguration.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaTransactionPoolValidatorConfiguration.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaTransactionPoolValidatorConfiguration.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaTransactionSelectorCliOptions.java b/sequencer/src/main/java/net/consensys/linea/config/LineaTransactionSelectorCliOptions.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaTransactionSelectorCliOptions.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaTransactionSelectorCliOptions.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/LineaTransactionSelectorConfiguration.java b/sequencer/src/main/java/net/consensys/linea/config/LineaTransactionSelectorConfiguration.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/LineaTransactionSelectorConfiguration.java rename to sequencer/src/main/java/net/consensys/linea/config/LineaTransactionSelectorConfiguration.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/converters/AddressConverter.java b/sequencer/src/main/java/net/consensys/linea/config/converters/AddressConverter.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/converters/AddressConverter.java rename to sequencer/src/main/java/net/consensys/linea/config/converters/AddressConverter.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/converters/BytesConverter.java b/sequencer/src/main/java/net/consensys/linea/config/converters/BytesConverter.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/converters/BytesConverter.java rename to sequencer/src/main/java/net/consensys/linea/config/converters/BytesConverter.java diff --git a/arithmetization/src/main/java/net/consensys/linea/config/converters/WeiConverter.java b/sequencer/src/main/java/net/consensys/linea/config/converters/WeiConverter.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/config/converters/WeiConverter.java rename to sequencer/src/main/java/net/consensys/linea/config/converters/WeiConverter.java diff --git a/arithmetization/src/main/java/net/consensys/linea/continoustracing/ContinuousTracer.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracer.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/continoustracing/ContinuousTracer.java rename to sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracer.java diff --git a/arithmetization/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingBlockAddedListener.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingBlockAddedListener.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingBlockAddedListener.java rename to sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingBlockAddedListener.java diff --git a/arithmetization/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingCliOptions.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingCliOptions.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingCliOptions.java rename to sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingCliOptions.java diff --git a/arithmetization/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingConfiguration.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingConfiguration.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingConfiguration.java rename to sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingConfiguration.java diff --git a/arithmetization/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingPlugin.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingPlugin.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingPlugin.java rename to sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingPlugin.java diff --git a/arithmetization/src/main/java/net/consensys/linea/continoustracing/SlackNotificationService.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/SlackNotificationService.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/continoustracing/SlackNotificationService.java rename to sequencer/src/main/java/net/consensys/linea/continoustracing/SlackNotificationService.java diff --git a/arithmetization/src/main/java/net/consensys/linea/continoustracing/TraceFailureHandler.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/TraceFailureHandler.java similarity index 97% rename from arithmetization/src/main/java/net/consensys/linea/continoustracing/TraceFailureHandler.java rename to sequencer/src/main/java/net/consensys/linea/continoustracing/TraceFailureHandler.java index ed62584ef..434662294 100644 --- a/arithmetization/src/main/java/net/consensys/linea/continoustracing/TraceFailureHandler.java +++ b/sequencer/src/main/java/net/consensys/linea/continoustracing/TraceFailureHandler.java @@ -18,10 +18,10 @@ import lombok.extern.slf4j.Slf4j; import net.consensys.linea.continoustracing.exception.InvalidTraceHandlerException; -import net.consensys.linea.corset.CorsetValidator; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.plugin.data.BlockHeader; + @Slf4j public class TraceFailureHandler { final SlackNotificationService slackNotificationService; diff --git a/arithmetization/src/main/java/net/consensys/linea/continoustracing/exception/InvalidBlockTraceException.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/InvalidBlockTraceException.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/continoustracing/exception/InvalidBlockTraceException.java rename to sequencer/src/main/java/net/consensys/linea/continoustracing/exception/InvalidBlockTraceException.java diff --git a/arithmetization/src/main/java/net/consensys/linea/continoustracing/exception/InvalidTraceHandlerException.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/InvalidTraceHandlerException.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/continoustracing/exception/InvalidTraceHandlerException.java rename to sequencer/src/main/java/net/consensys/linea/continoustracing/exception/InvalidTraceHandlerException.java diff --git a/arithmetization/src/main/java/net/consensys/linea/continoustracing/exception/TraceVerificationException.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/TraceVerificationException.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/continoustracing/exception/TraceVerificationException.java rename to sequencer/src/main/java/net/consensys/linea/continoustracing/exception/TraceVerificationException.java diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/modulelimit/ModuleLimitsValidationResult.java b/sequencer/src/main/java/net/consensys/linea/modulelimit/ModuleLimitsValidationResult.java similarity index 98% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/modulelimit/ModuleLimitsValidationResult.java rename to sequencer/src/main/java/net/consensys/linea/modulelimit/ModuleLimitsValidationResult.java index 69728c9b2..b3a0eefd9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/modulelimit/ModuleLimitsValidationResult.java +++ b/sequencer/src/main/java/net/consensys/linea/modulelimit/ModuleLimitsValidationResult.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.modulelimit; +package net.consensys.linea.modulelimit; import lombok.Getter; diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/modulelimit/ModuleLineCountValidator.java b/sequencer/src/main/java/net/consensys/linea/modulelimit/ModuleLineCountValidator.java similarity index 99% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/modulelimit/ModuleLineCountValidator.java rename to sequencer/src/main/java/net/consensys/linea/modulelimit/ModuleLineCountValidator.java index 5009e3ea5..e6d3d95b2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/modulelimit/ModuleLineCountValidator.java +++ b/sequencer/src/main/java/net/consensys/linea/modulelimit/ModuleLineCountValidator.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.modulelimit; +package net.consensys.linea.modulelimit; import java.io.File; import java.net.URL; diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/capture/Capture.java b/sequencer/src/main/java/net/consensys/linea/rpc/capture/Capture.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/capture/Capture.java rename to sequencer/src/main/java/net/consensys/linea/rpc/capture/Capture.java diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/capture/CaptureEndpointServicePlugin.java b/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureEndpointServicePlugin.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/capture/CaptureEndpointServicePlugin.java rename to sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureEndpointServicePlugin.java diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/capture/CaptureParams.java b/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureParams.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/capture/CaptureParams.java rename to sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureParams.java diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/capture/CaptureToFile.java b/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureToFile.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/capture/CaptureToFile.java rename to sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureToFile.java diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/counters/Counters.java b/sequencer/src/main/java/net/consensys/linea/rpc/counters/Counters.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/counters/Counters.java rename to sequencer/src/main/java/net/consensys/linea/rpc/counters/Counters.java diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/counters/CountersEndpointServicePlugin.java b/sequencer/src/main/java/net/consensys/linea/rpc/counters/CountersEndpointServicePlugin.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/counters/CountersEndpointServicePlugin.java rename to sequencer/src/main/java/net/consensys/linea/rpc/counters/CountersEndpointServicePlugin.java diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/counters/CountersRequestParams.java b/sequencer/src/main/java/net/consensys/linea/rpc/counters/CountersRequestParams.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/counters/CountersRequestParams.java rename to sequencer/src/main/java/net/consensys/linea/rpc/counters/CountersRequestParams.java diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/counters/GenerateCountersV0.java b/sequencer/src/main/java/net/consensys/linea/rpc/counters/GenerateCountersV0.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/counters/GenerateCountersV0.java rename to sequencer/src/main/java/net/consensys/linea/rpc/counters/GenerateCountersV0.java diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/linea/LineaEndpointServicePlugin.java b/sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEndpointServicePlugin.java similarity index 97% rename from arithmetization/src/main/java/net/consensys/linea/rpc/linea/LineaEndpointServicePlugin.java rename to sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEndpointServicePlugin.java index 0aab37ab6..b2c7bf6d4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/rpc/linea/LineaEndpointServicePlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEndpointServicePlugin.java @@ -15,7 +15,7 @@ package net.consensys.linea.rpc.linea; -import static net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator.createLimitModules; +import static net.consensys.linea.modulelimit.ModuleLineCountValidator.createLimitModules; import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/linea/LineaEstimateGas.java b/sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEstimateGas.java similarity index 98% rename from arithmetization/src/main/java/net/consensys/linea/rpc/linea/LineaEstimateGas.java rename to sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEstimateGas.java index e5c388139..67c3a0c11 100644 --- a/arithmetization/src/main/java/net/consensys/linea/rpc/linea/LineaEstimateGas.java +++ b/sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEstimateGas.java @@ -15,8 +15,8 @@ package net.consensys.linea.rpc.linea; -import static net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator.ModuleLineCountResult.MODULE_NOT_DEFINED; -import static net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator.ModuleLineCountResult.TX_MODULE_LINE_COUNT_OVERFLOW; +import static net.consensys.linea.modulelimit.ModuleLineCountValidator.ModuleLineCountResult.MODULE_NOT_DEFINED; +import static net.consensys.linea.modulelimit.ModuleLineCountValidator.ModuleLineCountResult.TX_MODULE_LINE_COUNT_OVERFLOW; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity.create; import java.math.BigDecimal; @@ -33,9 +33,9 @@ import net.consensys.linea.config.LineaProfitabilityConfiguration; import net.consensys.linea.config.LineaRpcConfiguration; import net.consensys.linea.config.LineaTransactionPoolValidatorConfiguration; +import net.consensys.linea.modulelimit.ModuleLimitsValidationResult; +import net.consensys.linea.modulelimit.ModuleLineCountValidator; import net.consensys.linea.sequencer.TracerAggregator; -import net.consensys.linea.sequencer.modulelimit.ModuleLimitsValidationResult; -import net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator; import net.consensys.linea.zktracer.ZkTracer; import org.apache.tuweni.bytes.Bytes; import org.bouncycastle.asn1.sec.SECNamedCurves; diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/GenerateConflatedTracesV0.java b/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/GenerateConflatedTracesV0.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/GenerateConflatedTracesV0.java rename to sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/GenerateConflatedTracesV0.java diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceFile.java b/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceFile.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceFile.java rename to sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceFile.java diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceRequestParams.java b/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceRequestParams.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceRequestParams.java rename to sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceRequestParams.java diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/TracesEndpointServicePlugin.java b/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TracesEndpointServicePlugin.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/TracesEndpointServicePlugin.java rename to sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TracesEndpointServicePlugin.java diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/TracerAggregator.java b/sequencer/src/main/java/net/consensys/linea/sequencer/TracerAggregator.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/TracerAggregator.java rename to sequencer/src/main/java/net/consensys/linea/sequencer/TracerAggregator.java diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorFactory.java b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/LineaTransactionPoolValidatorFactory.java similarity index 88% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorFactory.java rename to sequencer/src/main/java/net/consensys/linea/txpoolvalidation/LineaTransactionPoolValidatorFactory.java index 0873678aa..65fd58025 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorFactory.java +++ b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/LineaTransactionPoolValidatorFactory.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation; +package net.consensys.linea.txpoolvalidation; import java.util.Arrays; import java.util.Map; @@ -23,11 +23,11 @@ import net.consensys.linea.config.LineaL1L2BridgeConfiguration; import net.consensys.linea.config.LineaProfitabilityConfiguration; import net.consensys.linea.config.LineaTransactionPoolValidatorConfiguration; -import net.consensys.linea.sequencer.txpoolvalidation.validators.AllowedAddressValidator; -import net.consensys.linea.sequencer.txpoolvalidation.validators.CalldataValidator; -import net.consensys.linea.sequencer.txpoolvalidation.validators.GasLimitValidator; -import net.consensys.linea.sequencer.txpoolvalidation.validators.ProfitabilityValidator; -import net.consensys.linea.sequencer.txpoolvalidation.validators.SimulationValidator; +import net.consensys.linea.txpoolvalidation.validators.AllowedAddressValidator; +import net.consensys.linea.txpoolvalidation.validators.CalldataValidator; +import net.consensys.linea.txpoolvalidation.validators.GasLimitValidator; +import net.consensys.linea.txpoolvalidation.validators.ProfitabilityValidator; +import net.consensys.linea.txpoolvalidation.validators.SimulationValidator; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.plugin.services.BesuConfiguration; import org.hyperledger.besu.plugin.services.BlockchainService; diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java rename to sequencer/src/main/java/net/consensys/linea/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java index 4d255cb5c..326662d5d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java @@ -13,9 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation; - -import static net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator.createLimitModules; +package net.consensys.linea.txpoolvalidation; import java.io.File; import java.nio.file.Files; @@ -28,6 +26,7 @@ import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.AbstractLineaRequiredPlugin; +import net.consensys.linea.modulelimit.ModuleLineCountValidator; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; @@ -108,7 +107,7 @@ public void beforeExternalServices() { transactionPoolValidatorConfiguration, profitabilityConfiguration, deniedAddresses, - createLimitModules(tracerConfiguration), + ModuleLineCountValidator.createLimitModules(tracerConfiguration), l1L2BridgeConfiguration)); } catch (Exception e) { diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/AllowedAddressValidator.java b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/AllowedAddressValidator.java similarity index 98% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/AllowedAddressValidator.java rename to sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/AllowedAddressValidator.java index 2ec608a5b..b6efa745e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/AllowedAddressValidator.java +++ b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/AllowedAddressValidator.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation.validators; +package net.consensys.linea.txpoolvalidation.validators; import java.util.Optional; import java.util.Set; diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/CalldataValidator.java b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/CalldataValidator.java similarity index 96% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/CalldataValidator.java rename to sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/CalldataValidator.java index ec61c0eac..f34c92aa9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/CalldataValidator.java +++ b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/CalldataValidator.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation.validators; +package net.consensys.linea.txpoolvalidation.validators; import java.util.Optional; diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/GasLimitValidator.java b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/GasLimitValidator.java similarity index 96% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/GasLimitValidator.java rename to sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/GasLimitValidator.java index 4ab3212d6..640a8f56a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/GasLimitValidator.java +++ b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/GasLimitValidator.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation.validators; +package net.consensys.linea.txpoolvalidation.validators; import java.util.Optional; diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/ProfitabilityValidator.java b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/ProfitabilityValidator.java similarity index 97% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/ProfitabilityValidator.java rename to sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/ProfitabilityValidator.java index 97d25fd56..e61e209f4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/ProfitabilityValidator.java +++ b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/ProfitabilityValidator.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation.validators; +package net.consensys.linea.txpoolvalidation.validators; import java.util.Optional; diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidator.java b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/SimulationValidator.java similarity index 89% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidator.java rename to sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/SimulationValidator.java index 0709f4d9b..3b1a8de06 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidator.java +++ b/sequencer/src/main/java/net/consensys/linea/txpoolvalidation/validators/SimulationValidator.java @@ -12,10 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation.validators; - -import static net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator.ModuleLineCountResult.MODULE_NOT_DEFINED; -import static net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator.ModuleLineCountResult.TX_MODULE_LINE_COUNT_OVERFLOW; +package net.consensys.linea.txpoolvalidation.validators; import java.util.Map; import java.util.Optional; @@ -23,8 +20,8 @@ import lombok.extern.slf4j.Slf4j; import net.consensys.linea.config.LineaL1L2BridgeConfiguration; import net.consensys.linea.config.LineaTransactionPoolValidatorConfiguration; -import net.consensys.linea.sequencer.modulelimit.ModuleLimitsValidationResult; -import net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator; +import net.consensys.linea.modulelimit.ModuleLimitsValidationResult; +import net.consensys.linea.modulelimit.ModuleLineCountValidator; import net.consensys.linea.zktracer.ZkTracer; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.plugin.data.BlockHeader; @@ -108,14 +105,16 @@ private ZkTracer createZkTracer(final BlockHeader chainHeadHeader) { } private String handleModuleOverLimit(ModuleLimitsValidationResult moduleLimitResult) { - if (moduleLimitResult.getResult() == MODULE_NOT_DEFINED) { + if (moduleLimitResult.getResult() + == ModuleLineCountValidator.ModuleLineCountResult.MODULE_NOT_DEFINED) { String moduleNotDefinedMsg = String.format( "Module %s does not exist in the limits file.", moduleLimitResult.getModuleName()); log.error(moduleNotDefinedMsg); return moduleNotDefinedMsg; } - if (moduleLimitResult.getResult() == TX_MODULE_LINE_COUNT_OVERFLOW) { + if (moduleLimitResult.getResult() + == ModuleLineCountValidator.ModuleLineCountResult.TX_MODULE_LINE_COUNT_OVERFLOW) { String txOverflowMsg = String.format( "Transaction line count for module %s=%s is above the limit %s", diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectionResult.java b/sequencer/src/main/java/net/consensys/linea/txselection/LineaTransactionSelectionResult.java similarity index 98% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectionResult.java rename to sequencer/src/main/java/net/consensys/linea/txselection/LineaTransactionSelectionResult.java index b55d057ae..e2744e04e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectionResult.java +++ b/sequencer/src/main/java/net/consensys/linea/txselection/LineaTransactionSelectionResult.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txselection; +package net.consensys.linea.txselection; import org.hyperledger.besu.plugin.data.TransactionSelectionResult; diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorFactory.java b/sequencer/src/main/java/net/consensys/linea/txselection/LineaTransactionSelectorFactory.java similarity index 94% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorFactory.java rename to sequencer/src/main/java/net/consensys/linea/txselection/LineaTransactionSelectorFactory.java index cab06d476..a444f00c6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorFactory.java +++ b/sequencer/src/main/java/net/consensys/linea/txselection/LineaTransactionSelectorFactory.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txselection; +package net.consensys.linea.txselection; import java.util.Map; @@ -21,7 +21,7 @@ import net.consensys.linea.config.LineaProfitabilityConfiguration; import net.consensys.linea.config.LineaTracerConfiguration; import net.consensys.linea.config.LineaTransactionSelectorConfiguration; -import net.consensys.linea.sequencer.txselection.selectors.LineaTransactionSelector; +import net.consensys.linea.txselection.selectors.LineaTransactionSelector; import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelector; import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java b/sequencer/src/main/java/net/consensys/linea/txselection/LineaTransactionSelectorPlugin.java similarity index 91% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java rename to sequencer/src/main/java/net/consensys/linea/txselection/LineaTransactionSelectorPlugin.java index edcfeb099..8a6ef9566 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/txselection/LineaTransactionSelectorPlugin.java @@ -13,15 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txselection; - -import static net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator.createLimitModules; +package net.consensys.linea.txselection; import java.util.Optional; import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.AbstractLineaRequiredPlugin; +import net.consensys.linea.modulelimit.ModuleLineCountValidator; import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; import org.hyperledger.besu.plugin.services.TransactionSelectionService; @@ -62,6 +61,6 @@ public void beforeExternalServices() { l1L2BridgeConfiguration, profitabilityConfiguration, tracerConfiguration, - createLimitModules(tracerConfiguration))); + ModuleLineCountValidator.createLimitModules(tracerConfiguration))); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/LineaTransactionSelector.java b/sequencer/src/main/java/net/consensys/linea/txselection/selectors/LineaTransactionSelector.java similarity index 99% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/LineaTransactionSelector.java rename to sequencer/src/main/java/net/consensys/linea/txselection/selectors/LineaTransactionSelector.java index fadb5d783..44010db91 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/LineaTransactionSelector.java +++ b/sequencer/src/main/java/net/consensys/linea/txselection/selectors/LineaTransactionSelector.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txselection.selectors; +package net.consensys.linea.txselection.selectors; import java.util.List; import java.util.Map; diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockCallDataTransactionSelector.java b/sequencer/src/main/java/net/consensys/linea/txselection/selectors/MaxBlockCallDataTransactionSelector.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockCallDataTransactionSelector.java rename to sequencer/src/main/java/net/consensys/linea/txselection/selectors/MaxBlockCallDataTransactionSelector.java index 473629b04..dbe91cc2e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockCallDataTransactionSelector.java +++ b/sequencer/src/main/java/net/consensys/linea/txselection/selectors/MaxBlockCallDataTransactionSelector.java @@ -12,13 +12,13 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txselection.selectors; +package net.consensys.linea.txselection.selectors; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.BLOCK_CALLDATA_OVERFLOW; import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.SELECTED; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import net.consensys.linea.txselection.LineaTransactionSelectionResult; import org.hyperledger.besu.datatypes.PendingTransaction; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.plugin.data.TransactionProcessingResult; @@ -61,7 +61,7 @@ public TransactionSelectionResult evaluateTransactionPreProcessing( .addArgument(() -> cumulativeBlockCallDataSize + transactionCallDataSize) .addArgument(maxBlockCallDataSize) .log(); - return BLOCK_CALLDATA_OVERFLOW; + return LineaTransactionSelectionResult.BLOCK_CALLDATA_OVERFLOW; } log.atTrace() diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockGasTransactionSelector.java b/sequencer/src/main/java/net/consensys/linea/txselection/selectors/MaxBlockGasTransactionSelector.java similarity index 89% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockGasTransactionSelector.java rename to sequencer/src/main/java/net/consensys/linea/txselection/selectors/MaxBlockGasTransactionSelector.java index 5bd7682f7..53e0cae2b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockGasTransactionSelector.java +++ b/sequencer/src/main/java/net/consensys/linea/txselection/selectors/MaxBlockGasTransactionSelector.java @@ -12,14 +12,13 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txselection.selectors; +package net.consensys.linea.txselection.selectors; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_GAS_EXCEEDS_USER_MAX_BLOCK_GAS; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_TOO_LARGE_FOR_REMAINING_USER_GAS; import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.SELECTED; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import net.consensys.linea.txselection.LineaTransactionSelectionResult; import org.hyperledger.besu.datatypes.PendingTransaction; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.plugin.data.TransactionProcessingResult; @@ -51,7 +50,7 @@ public TransactionSelectionResult evaluateTransactionPostProcessing( .addArgument(gasUsedByTransaction) .addArgument(maxGasPerBlock) .log(); - return TX_GAS_EXCEEDS_USER_MAX_BLOCK_GAS; + return LineaTransactionSelectionResult.TX_GAS_EXCEEDS_USER_MAX_BLOCK_GAS; } if (isTransactionExceedingMaxBlockGasLimit(gasUsedByTransaction)) { @@ -63,7 +62,7 @@ public TransactionSelectionResult evaluateTransactionPostProcessing( .addArgument(cumulativeBlockGasUsed) .addArgument(maxGasPerBlock) .log(); - return TX_TOO_LARGE_FOR_REMAINING_USER_GAS; + return LineaTransactionSelectionResult.TX_TOO_LARGE_FOR_REMAINING_USER_GAS; } return SELECTED; } diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelector.java b/sequencer/src/main/java/net/consensys/linea/txselection/selectors/ProfitableTransactionSelector.java similarity index 90% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelector.java rename to sequencer/src/main/java/net/consensys/linea/txselection/selectors/ProfitableTransactionSelector.java index 65e89d74d..179c74c95 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelector.java +++ b/sequencer/src/main/java/net/consensys/linea/txselection/selectors/ProfitableTransactionSelector.java @@ -12,12 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txselection.selectors; +package net.consensys.linea.txselection.selectors; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE_MIN_GAS_PRICE_NOT_DECREASED; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE_RETRY_LIMIT; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE_UPFRONT; import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.SELECTED; import java.util.LinkedHashSet; @@ -28,6 +24,7 @@ import net.consensys.linea.bl.TransactionProfitabilityCalculator; import net.consensys.linea.config.LineaProfitabilityConfiguration; import net.consensys.linea.config.LineaTransactionSelectorConfiguration; +import net.consensys.linea.txselection.LineaTransactionSelectionResult; import org.apache.commons.lang3.mutable.MutableBoolean; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.PendingTransaction; @@ -83,7 +80,7 @@ public TransactionSelectionResult evaluateTransactionPreProcessing( minGasPrice, evaluationContext.getTransactionGasPrice(), gasLimit)) { - return TX_UNPROFITABLE_UPFRONT; + return LineaTransactionSelectionResult.TX_UNPROFITABLE_UPFRONT; } if (unprofitableCache.contains(transaction.getHash())) { @@ -95,7 +92,7 @@ public TransactionSelectionResult evaluateTransactionPreProcessing( .setMessage("Limit of unprofitable tx retries reached: {}/{}") .addArgument(unprofitableRetries) .addArgument(txSelectorConf.unprofitableRetryLimit()); - return TX_UNPROFITABLE_RETRY_LIMIT; + return LineaTransactionSelectionResult.TX_UNPROFITABLE_RETRY_LIMIT; } log.atTrace() @@ -112,7 +109,7 @@ public TransactionSelectionResult evaluateTransactionPreProcessing( .addArgument(minGasPrice::toHumanReadableString) .addArgument(prevMinGasPrice::toHumanReadableString) .log(); - return TX_UNPROFITABLE_MIN_GAS_PRICE_NOT_DECREASED; + return LineaTransactionSelectionResult.TX_UNPROFITABLE_MIN_GAS_PRICE_NOT_DECREASED; } } } @@ -137,7 +134,7 @@ public TransactionSelectionResult evaluateTransactionPostProcessing( evaluationContext.getTransactionGasPrice(), gasUsed)) { rememberUnprofitable(transaction); - return TX_UNPROFITABLE; + return LineaTransactionSelectionResult.TX_UNPROFITABLE; } } return SELECTED; diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelector.java b/sequencer/src/main/java/net/consensys/linea/txselection/selectors/TraceLineLimitTransactionSelector.java similarity index 93% rename from arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelector.java rename to sequencer/src/main/java/net/consensys/linea/txselection/selectors/TraceLineLimitTransactionSelector.java index 44c1cd74e..d3afec861 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelector.java +++ b/sequencer/src/main/java/net/consensys/linea/txselection/selectors/TraceLineLimitTransactionSelector.java @@ -12,11 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txselection.selectors; +package net.consensys.linea.txselection.selectors; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.BLOCK_MODULE_LINE_COUNT_FULL; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_MODULE_LINE_COUNT_OVERFLOW; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_MODULE_LINE_COUNT_OVERFLOW_CACHED; import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.SELECTED; import java.util.LinkedHashSet; @@ -29,8 +26,9 @@ import net.consensys.linea.config.LineaL1L2BridgeConfiguration; import net.consensys.linea.config.LineaTracerConfiguration; import net.consensys.linea.config.LineaTransactionSelectorConfiguration; -import net.consensys.linea.sequencer.modulelimit.ModuleLimitsValidationResult; -import net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator; +import net.consensys.linea.modulelimit.ModuleLimitsValidationResult; +import net.consensys.linea.modulelimit.ModuleLineCountValidator; +import net.consensys.linea.txselection.LineaTransactionSelectionResult; import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.module.Module; import org.hyperledger.besu.datatypes.Hash; @@ -103,7 +101,7 @@ public TransactionSelectionResult evaluateTransactionPreProcessing( "Transaction {} was already identified to go over line count limit, dropping it") .addArgument(evaluationContext.getPendingTransaction().getTransaction()::getHash) .log(); - return TX_MODULE_LINE_COUNT_OVERFLOW_CACHED; + return LineaTransactionSelectionResult.TX_MODULE_LINE_COUNT_OVERFLOW_CACHED; } return SELECTED; } @@ -161,7 +159,7 @@ public TransactionSelectionResult evaluateTransactionPostProcessing( result.getModuleLineCount(), result.getModuleLineCount()); rememberOverLineCountLimitTransaction(transaction); - return TX_MODULE_LINE_COUNT_OVERFLOW; + return LineaTransactionSelectionResult.TX_MODULE_LINE_COUNT_OVERFLOW; case BLOCK_MODULE_LINE_COUNT_FULL: log.atTrace() .setMessage( @@ -170,7 +168,7 @@ public TransactionSelectionResult evaluateTransactionPostProcessing( .addArgument(result.getCumulativeModuleLineCount()) .addArgument(result.getCumulativeModuleLineLimit()) .log(); - return BLOCK_MODULE_LINE_COUNT_FULL; + return LineaTransactionSelectionResult.BLOCK_MODULE_LINE_COUNT_FULL; default: break; } diff --git a/arithmetization/src/main/resources/spillings.toml b/sequencer/src/main/resources/spillings.toml similarity index 100% rename from arithmetization/src/main/resources/spillings.toml rename to sequencer/src/main/resources/spillings.toml diff --git a/arithmetization/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java b/sequencer/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java similarity index 100% rename from arithmetization/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java rename to sequencer/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java diff --git a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/AllowedAddressValidatorTest.java b/sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/AllowedAddressValidatorTest.java similarity index 98% rename from arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/AllowedAddressValidatorTest.java rename to sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/AllowedAddressValidatorTest.java index c2f25f68c..2b215d768 100644 --- a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/AllowedAddressValidatorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/AllowedAddressValidatorTest.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation.validators; +package net.consensys.linea.txpoolvalidation.validators; import java.util.Optional; import java.util.Set; diff --git a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/CalldataValidatorTest.java b/sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/CalldataValidatorTest.java similarity index 97% rename from arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/CalldataValidatorTest.java rename to sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/CalldataValidatorTest.java index fc775580d..8f258d8ef 100644 --- a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/CalldataValidatorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/CalldataValidatorTest.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation.validators; +package net.consensys.linea.txpoolvalidation.validators; import java.util.Optional; diff --git a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/GasLimitValidatorTest.java b/sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/GasLimitValidatorTest.java similarity index 97% rename from arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/GasLimitValidatorTest.java rename to sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/GasLimitValidatorTest.java index 219e62f46..6a0728366 100644 --- a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/GasLimitValidatorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/GasLimitValidatorTest.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation.validators; +package net.consensys.linea.txpoolvalidation.validators; import java.util.Optional; diff --git a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/ProfitabilityValidatorTest.java b/sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/ProfitabilityValidatorTest.java similarity index 99% rename from arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/ProfitabilityValidatorTest.java rename to sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/ProfitabilityValidatorTest.java index 5a8a11438..27180614e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/ProfitabilityValidatorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/ProfitabilityValidatorTest.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation.validators; +package net.consensys.linea.txpoolvalidation.validators; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; diff --git a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidatorTest.java b/sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/SimulationValidatorTest.java similarity index 97% rename from arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidatorTest.java rename to sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/SimulationValidatorTest.java index 477ca7c45..88c4892c5 100644 --- a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidatorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/txpoolvalidation/validators/SimulationValidatorTest.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.sequencer.txpoolvalidation.validators; +package net.consensys.linea.txpoolvalidation.validators; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -32,7 +32,7 @@ import net.consensys.linea.config.LineaL1L2BridgeConfiguration; import net.consensys.linea.config.LineaTracerConfiguration; import net.consensys.linea.config.LineaTransactionPoolValidatorConfiguration; -import net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator; +import net.consensys.linea.modulelimit.ModuleLineCountValidator; import net.consensys.linea.sequencer.txselection.selectors.TraceLineLimitTransactionSelectorTest; import org.apache.tuweni.bytes.Bytes; import org.bouncycastle.asn1.sec.SECNamedCurves; diff --git a/arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockCallDataSizeTransactionSelectorTest.java b/sequencer/src/test/java/net/consensys/linea/txselection/selectors/MaxBlockCallDataSizeTransactionSelectorTest.java similarity index 96% rename from arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockCallDataSizeTransactionSelectorTest.java rename to sequencer/src/test/java/net/consensys/linea/txselection/selectors/MaxBlockCallDataSizeTransactionSelectorTest.java index 230e3f0d9..052787fb4 100644 --- a/arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockCallDataSizeTransactionSelectorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/txselection/selectors/MaxBlockCallDataSizeTransactionSelectorTest.java @@ -14,12 +14,13 @@ */ package net.consensys.linea.sequencer.txselection.selectors; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.BLOCK_CALLDATA_OVERFLOW; +import static net.consensys.linea.txselection.LineaTransactionSelectionResult.BLOCK_CALLDATA_OVERFLOW; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.SELECTED; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import net.consensys.linea.txselection.selectors.MaxBlockCallDataTransactionSelector; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.PendingTransaction; import org.hyperledger.besu.datatypes.Transaction; diff --git a/arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockGasTransactionSelectorTest.java b/sequencer/src/test/java/net/consensys/linea/txselection/selectors/MaxBlockGasTransactionSelectorTest.java similarity index 94% rename from arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockGasTransactionSelectorTest.java rename to sequencer/src/test/java/net/consensys/linea/txselection/selectors/MaxBlockGasTransactionSelectorTest.java index 65d32111e..9e80da01e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/MaxBlockGasTransactionSelectorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/txselection/selectors/MaxBlockGasTransactionSelectorTest.java @@ -14,13 +14,14 @@ */ package net.consensys.linea.sequencer.txselection.selectors; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_GAS_EXCEEDS_USER_MAX_BLOCK_GAS; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_TOO_LARGE_FOR_REMAINING_USER_GAS; +import static net.consensys.linea.txselection.LineaTransactionSelectionResult.TX_GAS_EXCEEDS_USER_MAX_BLOCK_GAS; +import static net.consensys.linea.txselection.LineaTransactionSelectionResult.TX_TOO_LARGE_FOR_REMAINING_USER_GAS; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.SELECTED; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import net.consensys.linea.txselection.selectors.MaxBlockGasTransactionSelector; import org.hyperledger.besu.datatypes.PendingTransaction; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.plugin.data.TransactionProcessingResult; diff --git a/arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelectorTest.java b/sequencer/src/test/java/net/consensys/linea/txselection/selectors/ProfitableTransactionSelectorTest.java similarity index 97% rename from arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelectorTest.java rename to sequencer/src/test/java/net/consensys/linea/txselection/selectors/ProfitableTransactionSelectorTest.java index a4ce76aee..a38c7f21d 100644 --- a/arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelectorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/txselection/selectors/ProfitableTransactionSelectorTest.java @@ -14,10 +14,10 @@ */ package net.consensys.linea.sequencer.txselection.selectors; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE_MIN_GAS_PRICE_NOT_DECREASED; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE_RETRY_LIMIT; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE_UPFRONT; +import static net.consensys.linea.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE; +import static net.consensys.linea.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE_MIN_GAS_PRICE_NOT_DECREASED; +import static net.consensys.linea.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE_RETRY_LIMIT; +import static net.consensys.linea.txselection.LineaTransactionSelectionResult.TX_UNPROFITABLE_UPFRONT; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.SELECTED; import static org.mockito.Mockito.mock; @@ -27,6 +27,7 @@ import net.consensys.linea.config.LineaProfitabilityConfiguration; import net.consensys.linea.config.LineaTransactionSelectorCliOptions; import net.consensys.linea.config.LineaTransactionSelectorConfiguration; +import net.consensys.linea.txselection.selectors.ProfitableTransactionSelector; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.bouncycastle.crypto.digests.KeccakDigest; diff --git a/arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/TestTransactionEvaluationContext.java b/sequencer/src/test/java/net/consensys/linea/txselection/selectors/TestTransactionEvaluationContext.java similarity index 100% rename from arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/TestTransactionEvaluationContext.java rename to sequencer/src/test/java/net/consensys/linea/txselection/selectors/TestTransactionEvaluationContext.java diff --git a/arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelectorTest.java b/sequencer/src/test/java/net/consensys/linea/txselection/selectors/TraceLineLimitTransactionSelectorTest.java similarity index 96% rename from arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelectorTest.java rename to sequencer/src/test/java/net/consensys/linea/txselection/selectors/TraceLineLimitTransactionSelectorTest.java index eb9fb9830..1d7a305a6 100644 --- a/arithmetization/src/test/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelectorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/txselection/selectors/TraceLineLimitTransactionSelectorTest.java @@ -14,8 +14,8 @@ */ package net.consensys.linea.sequencer.txselection.selectors; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_MODULE_LINE_COUNT_OVERFLOW; -import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_MODULE_LINE_COUNT_OVERFLOW_CACHED; +import static net.consensys.linea.txselection.LineaTransactionSelectionResult.TX_MODULE_LINE_COUNT_OVERFLOW; +import static net.consensys.linea.txselection.LineaTransactionSelectionResult.TX_MODULE_LINE_COUNT_OVERFLOW_CACHED; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.SELECTED; import static org.mockito.Mockito.mock; @@ -30,7 +30,8 @@ import net.consensys.linea.config.LineaL1L2BridgeConfiguration; import net.consensys.linea.config.LineaTracerConfiguration; import net.consensys.linea.config.LineaTransactionSelectorConfiguration; -import net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator; +import net.consensys.linea.modulelimit.ModuleLineCountValidator; +import net.consensys.linea.txselection.selectors.TraceLineLimitTransactionSelector; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; diff --git a/arithmetization/src/test/resources/contracts/ec_data/EcDataBigTest.sol b/sequencer/src/test/resources/contracts/ec_data/EcDataBigTest.sol similarity index 100% rename from arithmetization/src/test/resources/contracts/ec_data/EcDataBigTest.sol rename to sequencer/src/test/resources/contracts/ec_data/EcDataBigTest.sol diff --git a/arithmetization/src/test/resources/contracts/mxp/A.sol b/sequencer/src/test/resources/contracts/mxp/A.sol similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/A.sol rename to sequencer/src/test/resources/contracts/mxp/A.sol diff --git a/arithmetization/src/test/resources/contracts/mxp/B.sol b/sequencer/src/test/resources/contracts/mxp/B.sol similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/B.sol rename to sequencer/src/test/resources/contracts/mxp/B.sol diff --git a/arithmetization/src/test/resources/contracts/mxp/C.sol b/sequencer/src/test/resources/contracts/mxp/C.sol similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/C.sol rename to sequencer/src/test/resources/contracts/mxp/C.sol diff --git a/arithmetization/src/test/resources/contracts/mxp/D.sol b/sequencer/src/test/resources/contracts/mxp/D.sol similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/D.sol rename to sequencer/src/test/resources/contracts/mxp/D.sol diff --git a/arithmetization/src/test/resources/contracts/mxp/MemoryOperations1.sol b/sequencer/src/test/resources/contracts/mxp/MemoryOperations1.sol similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/MemoryOperations1.sol rename to sequencer/src/test/resources/contracts/mxp/MemoryOperations1.sol diff --git a/arithmetization/src/test/resources/contracts/mxp/MemoryOperations2.sol b/sequencer/src/test/resources/contracts/mxp/MemoryOperations2.sol similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/MemoryOperations2.sol rename to sequencer/src/test/resources/contracts/mxp/MemoryOperations2.sol diff --git a/arithmetization/src/test/resources/contracts/mxp/compiledContracts/A.bin-runtime b/sequencer/src/test/resources/contracts/mxp/compiledContracts/A.bin-runtime similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/compiledContracts/A.bin-runtime rename to sequencer/src/test/resources/contracts/mxp/compiledContracts/A.bin-runtime diff --git a/arithmetization/src/test/resources/contracts/mxp/compiledContracts/B.bin-runtime b/sequencer/src/test/resources/contracts/mxp/compiledContracts/B.bin-runtime similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/compiledContracts/B.bin-runtime rename to sequencer/src/test/resources/contracts/mxp/compiledContracts/B.bin-runtime diff --git a/arithmetization/src/test/resources/contracts/mxp/compiledContracts/C.bin-runtime b/sequencer/src/test/resources/contracts/mxp/compiledContracts/C.bin-runtime similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/compiledContracts/C.bin-runtime rename to sequencer/src/test/resources/contracts/mxp/compiledContracts/C.bin-runtime diff --git a/arithmetization/src/test/resources/contracts/mxp/compiledContracts/D.bin-runtime b/sequencer/src/test/resources/contracts/mxp/compiledContracts/D.bin-runtime similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/compiledContracts/D.bin-runtime rename to sequencer/src/test/resources/contracts/mxp/compiledContracts/D.bin-runtime diff --git a/arithmetization/src/test/resources/contracts/mxp/compiledContracts/MemoryOperations1.bin-runtime b/sequencer/src/test/resources/contracts/mxp/compiledContracts/MemoryOperations1.bin-runtime similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/compiledContracts/MemoryOperations1.bin-runtime rename to sequencer/src/test/resources/contracts/mxp/compiledContracts/MemoryOperations1.bin-runtime diff --git a/arithmetization/src/test/resources/contracts/mxp/compiledContracts/MemoryOperations2.bin-runtime b/sequencer/src/test/resources/contracts/mxp/compiledContracts/MemoryOperations2.bin-runtime similarity index 100% rename from arithmetization/src/test/resources/contracts/mxp/compiledContracts/MemoryOperations2.bin-runtime rename to sequencer/src/test/resources/contracts/mxp/compiledContracts/MemoryOperations2.bin-runtime diff --git a/arithmetization/src/test/resources/log4j2.xml b/sequencer/src/test/resources/log4j2.xml similarity index 89% rename from arithmetization/src/test/resources/log4j2.xml rename to sequencer/src/test/resources/log4j2.xml index 28584299d..50ff57c4a 100644 --- a/arithmetization/src/test/resources/log4j2.xml +++ b/sequencer/src/test/resources/log4j2.xml @@ -20,7 +20,7 @@ - + diff --git a/arithmetization/src/test/resources/replays/start-vs-prepare-tx.json.gz b/sequencer/src/test/resources/replays/start-vs-prepare-tx.json.gz similarity index 100% rename from arithmetization/src/test/resources/replays/start-vs-prepare-tx.json.gz rename to sequencer/src/test/resources/replays/start-vs-prepare-tx.json.gz diff --git a/arithmetization/src/test/resources/sequencer/line-limits.toml b/sequencer/src/test/resources/sequencer/line-limits.toml similarity index 100% rename from arithmetization/src/test/resources/sequencer/line-limits.toml rename to sequencer/src/test/resources/sequencer/line-limits.toml diff --git a/arithmetization/src/test/resources/specs/add/trace-add-0x01-0x02.json b/sequencer/src/test/resources/specs/add/trace-add-0x01-0x02.json similarity index 100% rename from arithmetization/src/test/resources/specs/add/trace-add-0x01-0x02.json rename to sequencer/src/test/resources/specs/add/trace-add-0x01-0x02.json diff --git a/arithmetization/src/test/resources/specs/add/trace-add-0xff-0xff.json b/sequencer/src/test/resources/specs/add/trace-add-0xff-0xff.json similarity index 100% rename from arithmetization/src/test/resources/specs/add/trace-add-0xff-0xff.json rename to sequencer/src/test/resources/specs/add/trace-add-0xff-0xff.json diff --git a/arithmetization/src/test/resources/specs/mod/trace-mod-0x01-0x02.json b/sequencer/src/test/resources/specs/mod/trace-mod-0x01-0x02.json similarity index 100% rename from arithmetization/src/test/resources/specs/mod/trace-mod-0x01-0x02.json rename to sequencer/src/test/resources/specs/mod/trace-mod-0x01-0x02.json diff --git a/settings.gradle b/settings.gradle index 79ffc767d..05a8cc851 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,9 +22,8 @@ * in the user manual at https://docs.gradle.org/5.2.1/userguide/multi_project_builds.html */ -rootProject.name = 'besu-sequencer-plugins' -include 'arithmetization' +rootProject.name = 'linea-sequencer' +include 'sequencer' include 'acceptance-tests' -include 'reference-tests' include 'native' include 'native:compress'