diff --git a/abis/IExecutor.json b/abis/IExecutor.json new file mode 100644 index 0000000..36f3fbb --- /dev/null +++ b/abis/IExecutor.json @@ -0,0 +1,211 @@ +[ + { + "type": "function", + "name": "commitBatchesSharedBridge", + "inputs": [ + { + "name": "_chainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processFrom", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processTo", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_commitData", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "executeBatchesSharedBridge", + "inputs": [ + { + "name": "_chainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processFrom", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processTo", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_executeData", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "getName", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "string", + "internalType": "string" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "proveBatchesSharedBridge", + "inputs": [ + { + "name": "_chainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processBatchFrom", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processBatchTo", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_proofData", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "revertBatchesSharedBridge", + "inputs": [ + { + "name": "_chainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_newLastBatch", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "event", + "name": "BlockCommit", + "inputs": [ + { + "name": "batchNumber", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + }, + { + "name": "batchHash", + "type": "bytes32", + "indexed": true, + "internalType": "bytes32" + }, + { + "name": "commitment", + "type": "bytes32", + "indexed": true, + "internalType": "bytes32" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "BlockExecution", + "inputs": [ + { + "name": "batchNumber", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + }, + { + "name": "batchHash", + "type": "bytes32", + "indexed": true, + "internalType": "bytes32" + }, + { + "name": "commitment", + "type": "bytes32", + "indexed": true, + "internalType": "bytes32" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "BlocksRevert", + "inputs": [ + { + "name": "totalBatchesCommitted", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + }, + { + "name": "totalBatchesVerified", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + }, + { + "name": "totalBatchesExecuted", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "BlocksVerification", + "inputs": [ + { + "name": "previousLastVerifiedBatch", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + }, + { + "name": "currentLastVerifiedBatch", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + } + ], + "anonymous": false + } +] \ No newline at end of file diff --git a/abis/IZKChain.json b/abis/IZKChain.json new file mode 100644 index 0000000..826ee5f --- /dev/null +++ b/abis/IZKChain.json @@ -0,0 +1,2306 @@ +[ + { + "type": "function", + "name": "acceptAdmin", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "baseTokenGasPriceMultiplierDenominator", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint128", + "internalType": "uint128" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "baseTokenGasPriceMultiplierNominator", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint128", + "internalType": "uint128" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "bridgehubRequestL2Transaction", + "inputs": [ + { + "name": "_request", + "type": "tuple", + "internalType": "struct BridgehubL2TransactionRequest", + "components": [ + { + "name": "sender", + "type": "address", + "internalType": "address" + }, + { + "name": "contractL2", + "type": "address", + "internalType": "address" + }, + { + "name": "mintValue", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "l2Value", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "l2Calldata", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "l2GasLimit", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "l2GasPerPubdataByteLimit", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "factoryDeps", + "type": "bytes[]", + "internalType": "bytes[]" + }, + { + "name": "refundRecipient", + "type": "address", + "internalType": "address" + } + ] + } + ], + "outputs": [ + { + "name": "canonicalTxHash", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "bridgehubRequestL2TransactionOnGateway", + "inputs": [ + { + "name": "_canonicalTxHash", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "_expirationTimestamp", + "type": "uint64", + "internalType": "uint64" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "changeFeeParams", + "inputs": [ + { + "name": "_newFeeParams", + "type": "tuple", + "internalType": "struct FeeParams", + "components": [ + { + "name": "pubdataPricingMode", + "type": "uint8", + "internalType": "enum PubdataPricingMode" + }, + { + "name": "batchOverheadL1Gas", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "maxPubdataPerBatch", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "maxL2GasPerBatch", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "priorityTxMaxPubdata", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "minimalL2GasPrice", + "type": "uint64", + "internalType": "uint64" + } + ] + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "commitBatchesSharedBridge", + "inputs": [ + { + "name": "_chainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processFrom", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processTo", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_commitData", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "executeBatchesSharedBridge", + "inputs": [ + { + "name": "_chainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processFrom", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processTo", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_executeData", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "executeUpgrade", + "inputs": [ + { + "name": "_diamondCut", + "type": "tuple", + "internalType": "struct Diamond.DiamondCutData", + "components": [ + { + "name": "facetCuts", + "type": "tuple[]", + "internalType": "struct Diamond.FacetCut[]", + "components": [ + { + "name": "facet", + "type": "address", + "internalType": "address" + }, + { + "name": "action", + "type": "uint8", + "internalType": "enum Diamond.Action" + }, + { + "name": "isFreezable", + "type": "bool", + "internalType": "bool" + }, + { + "name": "selectors", + "type": "bytes4[]", + "internalType": "bytes4[]" + } + ] + }, + { + "name": "initAddress", + "type": "address", + "internalType": "address" + }, + { + "name": "initCalldata", + "type": "bytes", + "internalType": "bytes" + } + ] + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "facetAddress", + "inputs": [ + { + "name": "_selector", + "type": "bytes4", + "internalType": "bytes4" + } + ], + "outputs": [ + { + "name": "facet", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "facetAddresses", + "inputs": [], + "outputs": [ + { + "name": "facets", + "type": "address[]", + "internalType": "address[]" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "facetFunctionSelectors", + "inputs": [ + { + "name": "_facet", + "type": "address", + "internalType": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "bytes4[]", + "internalType": "bytes4[]" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "facets", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "tuple[]", + "internalType": "struct IGetters.Facet[]", + "components": [ + { + "name": "addr", + "type": "address", + "internalType": "address" + }, + { + "name": "selectors", + "type": "bytes4[]", + "internalType": "bytes4[]" + } + ] + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "finalizeEthWithdrawal", + "inputs": [ + { + "name": "_l2BatchNumber", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_l2MessageIndex", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_l2TxNumberInBatch", + "type": "uint16", + "internalType": "uint16" + }, + { + "name": "_message", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "_merkleProof", + "type": "bytes32[]", + "internalType": "bytes32[]" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "forwardedBridgeBurn", + "inputs": [ + { + "name": "_settlementLayer", + "type": "address", + "internalType": "address" + }, + { + "name": "_originalCaller", + "type": "address", + "internalType": "address" + }, + { + "name": "_data", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [ + { + "name": "_bridgeMintData", + "type": "bytes", + "internalType": "bytes" + } + ], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "forwardedBridgeMint", + "inputs": [ + { + "name": "_data", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "_contractAlreadyDeployed", + "type": "bool", + "internalType": "bool" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "forwardedBridgeRecoverFailedTransfer", + "inputs": [ + { + "name": "_chainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_assetInfo", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "_originalCaller", + "type": "address", + "internalType": "address" + }, + { + "name": "_chainData", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "freezeDiamond", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "genesisUpgrade", + "inputs": [ + { + "name": "_l1GenesisUpgrade", + "type": "address", + "internalType": "address" + }, + { + "name": "_ctmDeployer", + "type": "address", + "internalType": "address" + }, + { + "name": "_forceDeploymentData", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "_factoryDeps", + "type": "bytes[]", + "internalType": "bytes[]" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "getAdmin", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getBaseToken", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getBaseTokenAssetId", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getBridgehub", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getChainId", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getChainTypeManager", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getFirstUnprocessedPriorityTx", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getL2BootloaderBytecodeHash", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getL2DefaultAccountBytecodeHash", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getL2SystemContractsUpgradeBatchNumber", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getL2SystemContractsUpgradeTxHash", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getName", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "string", + "internalType": "string" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getPendingAdmin", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getPriorityQueueSize", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getPriorityTreeRoot", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getPriorityTreeStartIndex", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getPriorityTxMaxGasLimit", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getProtocolVersion", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getPubdataPricingMode", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint8", + "internalType": "enum PubdataPricingMode" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getSemverProtocolVersion", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "", + "type": "uint32", + "internalType": "uint32" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getSettlementLayer", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getTotalBatchesCommitted", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getTotalBatchesExecuted", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getTotalBatchesVerified", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getTotalPriorityTxs", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getTransactionFilterer", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getVerifier", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getVerifierParams", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "tuple", + "internalType": "struct VerifierParams", + "components": [ + { + "name": "recursionNodeLevelVkHash", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "recursionLeafLevelVkHash", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "recursionCircuitsSetVksHash", + "type": "bytes32", + "internalType": "bytes32" + } + ] + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "isDiamondStorageFrozen", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "isEthWithdrawalFinalized", + "inputs": [ + { + "name": "_l2BatchNumber", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_l2MessageIndex", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "isFacetFreezable", + "inputs": [ + { + "name": "_facet", + "type": "address", + "internalType": "address" + } + ], + "outputs": [ + { + "name": "isFreezable", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "isFunctionFreezable", + "inputs": [ + { + "name": "_selector", + "type": "bytes4", + "internalType": "bytes4" + } + ], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "isPriorityQueueActive", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "isValidator", + "inputs": [ + { + "name": "_address", + "type": "address", + "internalType": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "l2LogsRootHash", + "inputs": [ + { + "name": "_batchNumber", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [ + { + "name": "merkleRoot", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "l2TransactionBaseCost", + "inputs": [ + { + "name": "_gasPrice", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_l2GasLimit", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_l2GasPerPubdataByteLimit", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "makePermanentRollup", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "prepareChainCommitment", + "inputs": [], + "outputs": [ + { + "name": "commitment", + "type": "tuple", + "internalType": "struct ZKChainCommitment", + "components": [ + { + "name": "totalBatchesExecuted", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "totalBatchesVerified", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "totalBatchesCommitted", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "l2SystemContractsUpgradeTxHash", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "l2SystemContractsUpgradeBatchNumber", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "batchHashes", + "type": "bytes32[]", + "internalType": "bytes32[]" + }, + { + "name": "priorityTree", + "type": "tuple", + "internalType": "struct PriorityTreeCommitment", + "components": [ + { + "name": "nextLeafIndex", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "startIndex", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "unprocessedIndex", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "sides", + "type": "bytes32[]", + "internalType": "bytes32[]" + } + ] + }, + { + "name": "isPermanentRollup", + "type": "bool", + "internalType": "bool" + } + ] + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "proveBatchesSharedBridge", + "inputs": [ + { + "name": "_chainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processBatchFrom", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_processBatchTo", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_proofData", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "proveL1ToL2TransactionStatus", + "inputs": [ + { + "name": "_l2TxHash", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "_l2BatchNumber", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_l2MessageIndex", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_l2TxNumberInBatch", + "type": "uint16", + "internalType": "uint16" + }, + { + "name": "_merkleProof", + "type": "bytes32[]", + "internalType": "bytes32[]" + }, + { + "name": "_status", + "type": "uint8", + "internalType": "enum TxStatus" + } + ], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "proveL2LeafInclusion", + "inputs": [ + { + "name": "_batchNumber", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_batchRootMask", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_leaf", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "_proof", + "type": "bytes32[]", + "internalType": "bytes32[]" + } + ], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "proveL2LogInclusion", + "inputs": [ + { + "name": "_batchNumber", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_index", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_log", + "type": "tuple", + "internalType": "struct L2Log", + "components": [ + { + "name": "l2ShardId", + "type": "uint8", + "internalType": "uint8" + }, + { + "name": "isService", + "type": "bool", + "internalType": "bool" + }, + { + "name": "txNumberInBatch", + "type": "uint16", + "internalType": "uint16" + }, + { + "name": "sender", + "type": "address", + "internalType": "address" + }, + { + "name": "key", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "value", + "type": "bytes32", + "internalType": "bytes32" + } + ] + }, + { + "name": "_proof", + "type": "bytes32[]", + "internalType": "bytes32[]" + } + ], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "proveL2MessageInclusion", + "inputs": [ + { + "name": "_batchNumber", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_index", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_message", + "type": "tuple", + "internalType": "struct L2Message", + "components": [ + { + "name": "txNumberInBatch", + "type": "uint16", + "internalType": "uint16" + }, + { + "name": "sender", + "type": "address", + "internalType": "address" + }, + { + "name": "data", + "type": "bytes", + "internalType": "bytes" + } + ] + }, + { + "name": "_proof", + "type": "bytes32[]", + "internalType": "bytes32[]" + } + ], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "requestL2Transaction", + "inputs": [ + { + "name": "_contractL2", + "type": "address", + "internalType": "address" + }, + { + "name": "_l2Value", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_calldata", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "_l2GasLimit", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_l2GasPerPubdataByteLimit", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_factoryDeps", + "type": "bytes[]", + "internalType": "bytes[]" + }, + { + "name": "_refundRecipient", + "type": "address", + "internalType": "address" + } + ], + "outputs": [ + { + "name": "canonicalTxHash", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "requestL2TransactionToGatewayMailbox", + "inputs": [ + { + "name": "_chainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_canonicalTxHash", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "_expirationTimestamp", + "type": "uint64", + "internalType": "uint64" + } + ], + "outputs": [ + { + "name": "canonicalTxHash", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "revertBatchesSharedBridge", + "inputs": [ + { + "name": "_chainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_newLastBatch", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setDAValidatorPair", + "inputs": [ + { + "name": "_l1DAValidator", + "type": "address", + "internalType": "address" + }, + { + "name": "_l2DAValidator", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setPendingAdmin", + "inputs": [ + { + "name": "_newPendingAdmin", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setPorterAvailability", + "inputs": [ + { + "name": "_zkPorterIsAvailable", + "type": "bool", + "internalType": "bool" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setPriorityTxMaxGasLimit", + "inputs": [ + { + "name": "_newPriorityTxMaxGasLimit", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setPubdataPricingMode", + "inputs": [ + { + "name": "_pricingMode", + "type": "uint8", + "internalType": "enum PubdataPricingMode" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setTokenMultiplier", + "inputs": [ + { + "name": "_nominator", + "type": "uint128", + "internalType": "uint128" + }, + { + "name": "_denominator", + "type": "uint128", + "internalType": "uint128" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setTransactionFilterer", + "inputs": [ + { + "name": "_transactionFilterer", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setValidator", + "inputs": [ + { + "name": "_validator", + "type": "address", + "internalType": "address" + }, + { + "name": "_active", + "type": "bool", + "internalType": "bool" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "storedBatchHash", + "inputs": [ + { + "name": "_batchNumber", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "unfreezeDiamond", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "upgradeChainFromVersion", + "inputs": [ + { + "name": "_protocolVersion", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_cutData", + "type": "tuple", + "internalType": "struct Diamond.DiamondCutData", + "components": [ + { + "name": "facetCuts", + "type": "tuple[]", + "internalType": "struct Diamond.FacetCut[]", + "components": [ + { + "name": "facet", + "type": "address", + "internalType": "address" + }, + { + "name": "action", + "type": "uint8", + "internalType": "enum Diamond.Action" + }, + { + "name": "isFreezable", + "type": "bool", + "internalType": "bool" + }, + { + "name": "selectors", + "type": "bytes4[]", + "internalType": "bytes4[]" + } + ] + }, + { + "name": "initAddress", + "type": "address", + "internalType": "address" + }, + { + "name": "initCalldata", + "type": "bytes", + "internalType": "bytes" + } + ] + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "event", + "name": "BlockCommit", + "inputs": [ + { + "name": "batchNumber", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + }, + { + "name": "batchHash", + "type": "bytes32", + "indexed": true, + "internalType": "bytes32" + }, + { + "name": "commitment", + "type": "bytes32", + "indexed": true, + "internalType": "bytes32" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "BlockExecution", + "inputs": [ + { + "name": "batchNumber", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + }, + { + "name": "batchHash", + "type": "bytes32", + "indexed": true, + "internalType": "bytes32" + }, + { + "name": "commitment", + "type": "bytes32", + "indexed": true, + "internalType": "bytes32" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "BlocksRevert", + "inputs": [ + { + "name": "totalBatchesCommitted", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + }, + { + "name": "totalBatchesVerified", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + }, + { + "name": "totalBatchesExecuted", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "BlocksVerification", + "inputs": [ + { + "name": "previousLastVerifiedBatch", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + }, + { + "name": "currentLastVerifiedBatch", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "BridgeMint", + "inputs": [ + { + "name": "_account", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "_amount", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "ExecuteUpgrade", + "inputs": [ + { + "name": "diamondCut", + "type": "tuple", + "indexed": false, + "internalType": "struct Diamond.DiamondCutData", + "components": [ + { + "name": "facetCuts", + "type": "tuple[]", + "internalType": "struct Diamond.FacetCut[]", + "components": [ + { + "name": "facet", + "type": "address", + "internalType": "address" + }, + { + "name": "action", + "type": "uint8", + "internalType": "enum Diamond.Action" + }, + { + "name": "isFreezable", + "type": "bool", + "internalType": "bool" + }, + { + "name": "selectors", + "type": "bytes4[]", + "internalType": "bytes4[]" + } + ] + }, + { + "name": "initAddress", + "type": "address", + "internalType": "address" + }, + { + "name": "initCalldata", + "type": "bytes", + "internalType": "bytes" + } + ] + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Freeze", + "inputs": [], + "anonymous": false + }, + { + "type": "event", + "name": "IsPorterAvailableStatusUpdate", + "inputs": [ + { + "name": "isPorterAvailable", + "type": "bool", + "indexed": false, + "internalType": "bool" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "MigrationComplete", + "inputs": [], + "anonymous": false + }, + { + "type": "event", + "name": "NewAdmin", + "inputs": [ + { + "name": "oldAdmin", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newAdmin", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "NewBaseTokenMultiplier", + "inputs": [ + { + "name": "oldNominator", + "type": "uint128", + "indexed": false, + "internalType": "uint128" + }, + { + "name": "oldDenominator", + "type": "uint128", + "indexed": false, + "internalType": "uint128" + }, + { + "name": "newNominator", + "type": "uint128", + "indexed": false, + "internalType": "uint128" + }, + { + "name": "newDenominator", + "type": "uint128", + "indexed": false, + "internalType": "uint128" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "NewFeeParams", + "inputs": [ + { + "name": "oldFeeParams", + "type": "tuple", + "indexed": false, + "internalType": "struct FeeParams", + "components": [ + { + "name": "pubdataPricingMode", + "type": "uint8", + "internalType": "enum PubdataPricingMode" + }, + { + "name": "batchOverheadL1Gas", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "maxPubdataPerBatch", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "maxL2GasPerBatch", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "priorityTxMaxPubdata", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "minimalL2GasPrice", + "type": "uint64", + "internalType": "uint64" + } + ] + }, + { + "name": "newFeeParams", + "type": "tuple", + "indexed": false, + "internalType": "struct FeeParams", + "components": [ + { + "name": "pubdataPricingMode", + "type": "uint8", + "internalType": "enum PubdataPricingMode" + }, + { + "name": "batchOverheadL1Gas", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "maxPubdataPerBatch", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "maxL2GasPerBatch", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "priorityTxMaxPubdata", + "type": "uint32", + "internalType": "uint32" + }, + { + "name": "minimalL2GasPrice", + "type": "uint64", + "internalType": "uint64" + } + ] + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "NewL1DAValidator", + "inputs": [ + { + "name": "oldL1DAValidator", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newL1DAValidator", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "NewL2DAValidator", + "inputs": [ + { + "name": "oldL2DAValidator", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newL2DAValidator", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "NewPendingAdmin", + "inputs": [ + { + "name": "oldPendingAdmin", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newPendingAdmin", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "NewPriorityRequest", + "inputs": [ + { + "name": "txId", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + }, + { + "name": "txHash", + "type": "bytes32", + "indexed": false, + "internalType": "bytes32" + }, + { + "name": "expirationTimestamp", + "type": "uint64", + "indexed": false, + "internalType": "uint64" + }, + { + "name": "transaction", + "type": "tuple", + "indexed": false, + "internalType": "struct L2CanonicalTransaction", + "components": [ + { + "name": "txType", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "from", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "to", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "gasLimit", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "gasPerPubdataByteLimit", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "maxFeePerGas", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "maxPriorityFeePerGas", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "paymaster", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "nonce", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "value", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "reserved", + "type": "uint256[4]", + "internalType": "uint256[4]" + }, + { + "name": "data", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "signature", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "factoryDeps", + "type": "uint256[]", + "internalType": "uint256[]" + }, + { + "name": "paymasterInput", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "reservedDynamic", + "type": "bytes", + "internalType": "bytes" + } + ] + }, + { + "name": "factoryDeps", + "type": "bytes[]", + "indexed": false, + "internalType": "bytes[]" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "NewPriorityTxMaxGasLimit", + "inputs": [ + { + "name": "oldPriorityTxMaxGasLimit", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + }, + { + "name": "newPriorityTxMaxGasLimit", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "NewRelayedPriorityTransaction", + "inputs": [ + { + "name": "txId", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + }, + { + "name": "txHash", + "type": "bytes32", + "indexed": false, + "internalType": "bytes32" + }, + { + "name": "expirationTimestamp", + "type": "uint64", + "indexed": false, + "internalType": "uint64" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "NewTransactionFilterer", + "inputs": [ + { + "name": "oldTransactionFilterer", + "type": "address", + "indexed": false, + "internalType": "address" + }, + { + "name": "newTransactionFilterer", + "type": "address", + "indexed": false, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "ProposeTransparentUpgrade", + "inputs": [ + { + "name": "diamondCut", + "type": "tuple", + "indexed": false, + "internalType": "struct Diamond.DiamondCutData", + "components": [ + { + "name": "facetCuts", + "type": "tuple[]", + "internalType": "struct Diamond.FacetCut[]", + "components": [ + { + "name": "facet", + "type": "address", + "internalType": "address" + }, + { + "name": "action", + "type": "uint8", + "internalType": "enum Diamond.Action" + }, + { + "name": "isFreezable", + "type": "bool", + "internalType": "bool" + }, + { + "name": "selectors", + "type": "bytes4[]", + "internalType": "bytes4[]" + } + ] + }, + { + "name": "initAddress", + "type": "address", + "internalType": "address" + }, + { + "name": "initCalldata", + "type": "bytes", + "internalType": "bytes" + } + ] + }, + { + "name": "proposalId", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + }, + { + "name": "proposalSalt", + "type": "bytes32", + "indexed": false, + "internalType": "bytes32" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "PubdataPricingModeUpdate", + "inputs": [ + { + "name": "validiumMode", + "type": "uint8", + "indexed": false, + "internalType": "enum PubdataPricingMode" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Unfreeze", + "inputs": [], + "anonymous": false + }, + { + "type": "event", + "name": "ValidatorStatusUpdate", + "inputs": [ + { + "name": "validatorAddress", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "isActive", + "type": "bool", + "indexed": false, + "internalType": "bool" + } + ], + "anonymous": false + } +] \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 54fb3e3..3c324b0 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,3 @@ [toolchain] channel = "nightly-2023-08-21" +components = [ "rustfmt", "clippy", "rust-analyzer" ] \ No newline at end of file diff --git a/src/batch.rs b/src/batch.rs new file mode 100644 index 0000000..7fa051a --- /dev/null +++ b/src/batch.rs @@ -0,0 +1,245 @@ +use circuit_definitions::circuit_definitions::aux_layer::ZkSyncSnarkWrapperCircuit; +use circuit_definitions::snark_wrapper::franklin_crypto::bellman::bn256::Bn256; +use circuit_definitions::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::proof::Proof; +use crypto::deserialize_proof; +use ethers::abi::{Function, ParamType, Token}; +use once_cell::sync::Lazy; +use primitive_types::U256; + +static COMMIT_BATCH_INFO_PARAMS: Lazy = Lazy::new(|| { + ParamType::Tuple(vec![ + ParamType::Uint(64), + ParamType::Uint(64), + ParamType::Uint(64), + ParamType::FixedBytes(32), + ParamType::Uint(256), + ParamType::FixedBytes(32), + ParamType::FixedBytes(32), + ParamType::FixedBytes(32), + ParamType::Bytes, + ParamType::Bytes, + ]) +}); + +static STORED_BATCH_INFO_PARAMS: Lazy = Lazy::new(|| { + ParamType::Tuple(vec![ + ParamType::Uint(64), + ParamType::FixedBytes(32), + ParamType::Uint(64), + ParamType::Uint(256), + ParamType::FixedBytes(32), + ParamType::FixedBytes(32), + ParamType::Uint(256), + ParamType::FixedBytes(32), + ]) +}); + +pub struct CommitBatchInfo { + pub batch_number: U256, + pub timestamp: U256, + pub index_repeated_storage_changes: U256, + pub new_state_root: Vec, + pub number_l1_txns: U256, + pub priority_operations_hash: Vec, + pub bootloader_contents_hash: Vec, + pub event_queue_state_hash: Vec, + pub sys_logs: Vec, + pub total_pubdata: Vec, +} + +pub fn parse_commit_batch_info( + func: &Function, + calldata: &[u8], + protocol_version: u16, +) -> Option { + use ethers::abi; + + if calldata.len() < 5 { + return None; + } + + let mut parsed_input = func.decode_input(&calldata[4..]).unwrap(); + + if protocol_version < 26 { + let second_param = parsed_input.pop().unwrap(); + + let abi::Token::Array(inner) = second_param else { + return None; + }; + + let mut batch = None; + + for inner in inner.into_iter() { + let abi::Token::Tuple(inner) = inner else { + return None; + }; + + let [abi::Token::Uint(batch_number), abi::Token::Uint(timestamp), abi::Token::Uint(index_repeated_storage_changes), abi::Token::FixedBytes(new_state_root), abi::Token::Uint(number_l1_txns), abi::Token::FixedBytes(priority_operations_hash), abi::Token::FixedBytes(bootloader_contents_hash), abi::Token::FixedBytes(event_queue_state_hash), abi::Token::Bytes(sys_logs), abi::Token::Bytes(total_pubdata)] = + inner.as_slice() + else { + return None; + }; + + batch = Some(CommitBatchInfo { + batch_number: batch_number.clone(), + timestamp: timestamp.clone(), + index_repeated_storage_changes: index_repeated_storage_changes.clone(), + new_state_root: new_state_root.clone(), + number_l1_txns: number_l1_txns.clone(), + priority_operations_hash: priority_operations_hash.clone(), + bootloader_contents_hash: bootloader_contents_hash.clone(), + event_queue_state_hash: event_queue_state_hash.clone(), + sys_logs: sys_logs.clone(), + total_pubdata: total_pubdata.clone(), + }); + } + + return batch; + } else { + assert_eq!(parsed_input.len(), 4); + + let commit_data = parsed_input.pop().unwrap(); + + let abi::Token::Bytes(mut commit_data_bytes) = commit_data else { + return None; + }; + + commit_data_bytes = commit_data_bytes[1..].to_vec(); + + let combined_params = vec![ + (*STORED_BATCH_INFO_PARAMS).clone(), + ParamType::Array(Box::new((*COMMIT_BATCH_INFO_PARAMS).clone())), + ]; + + let res = ethers::core::abi::decode(&combined_params, &commit_data_bytes); + + if res.is_err() { + return None; + } + + let decoded_input = res.unwrap(); + + if decoded_input.len() != 2 { + return None; + } + + let abi::Token::Array(commit_batches) = decoded_input[1].clone() else { + return None; + }; + + if commit_batches.len() != 1 { + return None; + } + + let abi::Token::Tuple(commit_batch) = commit_batches[0].clone() else { + return None; + }; + + if commit_batch.len() != 10 { + return None; + }; + + let [abi::Token::Uint(batch_number), abi::Token::Uint(timestamp), abi::Token::Uint(index_repeated_storage_changes), abi::Token::FixedBytes(new_state_root), abi::Token::Uint(number_l1_txns), abi::Token::FixedBytes(priority_operations_hash), abi::Token::FixedBytes(bootloader_contents_hash), abi::Token::FixedBytes(event_queue_state_hash), abi::Token::Bytes(sys_logs), abi::Token::Bytes(total_pubdata)] = + commit_batch.as_slice() + else { + return None; + }; + + return Some(CommitBatchInfo { + batch_number: batch_number.clone(), + timestamp: timestamp.clone(), + index_repeated_storage_changes: index_repeated_storage_changes.clone(), + new_state_root: new_state_root.clone(), + number_l1_txns: number_l1_txns.clone(), + priority_operations_hash: priority_operations_hash.clone(), + bootloader_contents_hash: bootloader_contents_hash.clone(), + event_queue_state_hash: event_queue_state_hash.clone(), + sys_logs: sys_logs.clone(), + total_pubdata: total_pubdata.clone(), + }); + } +} + +pub fn parse_batch_proof( + function: &Function, + calldata: &[u8], + protocol_version: u16, + network: &str, +) -> Option> { + let parsed_input = function.decode_input(&calldata[4..]).unwrap(); + + if protocol_version < 26 { + let Token::Tuple(proof) = parsed_input.as_slice().last().unwrap() else { + return None; + }; + + assert_eq!(proof.len(), 2); + + let Token::Array(serialized_proof) = proof[1].clone() else { + return None; + }; + + let proof = serialized_proof + .iter() + .filter_map(|e| { + if let Token::Uint(x) = e { + Some(x.clone()) + } else { + None + } + }) + .collect::>(); + + if network != "mainnet" && serialized_proof.len() == 0 { + return None; + } + + Some(deserialize_proof(proof)) + } else { + let Token::Bytes(proof_data) = parsed_input.as_slice().last().unwrap() else { + return None; + }; + + let stored_batch_info_params = ParamType::Tuple(vec![ + ParamType::Uint(64), + ParamType::FixedBytes(32), + ParamType::Uint(64), + ParamType::Uint(256), + ParamType::FixedBytes(32), + ParamType::FixedBytes(32), + ParamType::Uint(256), + ParamType::FixedBytes(32), + ]); + + let combined_params = vec![ + stored_batch_info_params.clone(), + ParamType::Array(Box::new(stored_batch_info_params)), + ParamType::Array(Box::new(ParamType::Uint(256))), + ]; + + let proof = ethers::core::abi::decode(&combined_params, &proof_data[1..]).unwrap(); + + assert_eq!(proof.len(), 3); + + let Token::Array(serialized_proof) = proof[2].clone() else { + return None; + }; + + let proof = serialized_proof + .iter() + .filter_map(|e| { + if let Token::Uint(x) = e { + Some(x.clone()) + } else { + None + } + }) + .collect::>(); + + if network != "mainnet" && serialized_proof.len() == 0 { + return None; + } + + Some(deserialize_proof(proof)) + } +} diff --git a/src/block_header.rs b/src/block_header.rs index c770250..838332f 100644 --- a/src/block_header.rs +++ b/src/block_header.rs @@ -1,7 +1,10 @@ use ethers::{abi::Function, utils::keccak256}; use zksync_types::{commitment::SerializeCommitment, l2_to_l1_log::L2ToL1Log, H256}; -use crate::outputs::StatusCode; +use crate::{ + batch::{parse_commit_batch_info, CommitBatchInfo}, + outputs::StatusCode, +}; #[derive(Debug, Clone)] pub struct BlockAuxilaryOutput { @@ -33,60 +36,60 @@ impl BlockAuxilaryOutput { } } -pub fn parse_aux_data(func: &Function, calldata: &[u8]) -> Result { - use ethers::abi; - - if calldata.len() < 5 { - return Err(StatusCode::BadCalldataLength); +pub async fn parse_aux_data( + func: &Function, + calldata: &[u8], + protocol_version: u16, +) -> Result { + let batch = parse_commit_batch_info(func, calldata, protocol_version); + + match batch { + None => Err(StatusCode::FailedToDeconstruct), + Some(batch_commit) => { + let CommitBatchInfo { + batch_number: _, + timestamp: _, + index_repeated_storage_changes: _, + new_state_root: _, + number_l1_txns: _, + priority_operations_hash: _, + bootloader_contents_hash, + event_queue_state_hash, + sys_logs, + total_pubdata: _, + } = batch_commit; + + assert_eq!(bootloader_contents_hash.len(), 32); + assert_eq!(event_queue_state_hash.len(), 32); + + let mut bootloader_contents_hash_buffer = [0u8; 32]; + bootloader_contents_hash_buffer.copy_from_slice(&bootloader_contents_hash); + + let mut event_queue_state_hash_buffer = [0u8; 32]; + event_queue_state_hash_buffer.copy_from_slice(&event_queue_state_hash); + + assert!( + sys_logs.len() % L2ToL1Log::SERIALIZED_SIZE == 0, + "sys logs length should be a factor of serialized size" + ); + let state_diff_hash_sys_log = sys_logs + .chunks(L2ToL1Log::SERIALIZED_SIZE) + .into_iter() + .map(L2ToL1Log::from_slice) + // The value 2 comes from the key in this enum https://github.com/matter-labs/era-system-contracts/blob/d42f707cbe6938a76fa29f4bf76203af1e13f51f/contracts/Constants.sol#L90 + .find(|log| log.key == H256::from_low_u64_be(2_u64)) + .unwrap(); + + let system_logs_hash = keccak256(sys_logs); + + Ok(BlockAuxilaryOutput { + system_logs_hash, + state_diff_hash: state_diff_hash_sys_log.value.to_fixed_bytes(), + bootloader_heap_initial_content_hash: bootloader_contents_hash_buffer, + event_queue_state_hash: event_queue_state_hash_buffer, + }) + } } - - let mut parsed_calldata = func.decode_input(&calldata[4..]).unwrap(); - - let committed_batch = parsed_calldata.pop().unwrap(); - - let abi::Token::Array(committed_batch) = committed_batch else { - return Err(StatusCode::FailedToDeconstruct); - }; - - let abi::Token::Tuple(committed_batch) = committed_batch[0].clone() else { - return Err(StatusCode::FailedToDeconstruct); - }; - - let [abi::Token::Uint(_batch_number), abi::Token::Uint(_timestamp), abi::Token::Uint(_index_repeated_storage_changes), abi::Token::FixedBytes(_new_state_root), abi::Token::Uint(_number_l1_txns), abi::Token::FixedBytes(_priority_operations_hash), abi::Token::FixedBytes(bootloader_contents_hash), abi::Token::FixedBytes(event_queue_state_hash), abi::Token::Bytes(sys_logs), abi::Token::Bytes(_total_pubdata)] = - committed_batch.as_slice() - else { - return Err(StatusCode::FailedToDeconstruct); - }; - - assert_eq!(bootloader_contents_hash.len(), 32); - assert_eq!(event_queue_state_hash.len(), 32); - - let mut bootloader_contents_hash_buffer = [0u8; 32]; - bootloader_contents_hash_buffer.copy_from_slice(bootloader_contents_hash); - - let mut event_queue_state_hash_buffer = [0u8; 32]; - event_queue_state_hash_buffer.copy_from_slice(event_queue_state_hash); - - assert!( - sys_logs.len() % L2ToL1Log::SERIALIZED_SIZE == 0, - "sys logs length should be a factor of serialized size" - ); - let state_diff_hash_sys_log = sys_logs - .chunks(L2ToL1Log::SERIALIZED_SIZE) - .into_iter() - .map(L2ToL1Log::from_slice) - // The value 2 comes from the key in this enum https://github.com/matter-labs/era-system-contracts/blob/d42f707cbe6938a76fa29f4bf76203af1e13f51f/contracts/Constants.sol#L90 - .find(|log| log.key == H256::from_low_u64_be(2_u64)) - .unwrap(); - - let system_logs_hash = keccak256(sys_logs); - - Ok(BlockAuxilaryOutput { - system_logs_hash, - state_diff_hash: state_diff_hash_sys_log.value.to_fixed_bytes(), - bootloader_heap_initial_content_hash: bootloader_contents_hash_buffer, - event_queue_state_hash: event_queue_state_hash_buffer, - }) } pub fn to_fixed_bytes(ins: &[u8]) -> [u8; 32] { diff --git a/src/inputs.rs b/src/inputs.rs index 787630f..8bb575d 100644 --- a/src/inputs.rs +++ b/src/inputs.rs @@ -18,20 +18,19 @@ pub fn generate_inputs( use self::block_header::to_fixed_bytes; use sha3::{Digest, Keccak256}; - let input_fields = - if protocol_version.is_some() && protocol_version.unwrap() <= 22 { - vec![ - batch_l1_data.prev_batch_commitment.to_fixed_bytes(), - batch_l1_data.curr_batch_commitment.to_fixed_bytes(), - verifier_params.recursion_node_level_vk_hash, - verifier_params.recursion_leaf_level_vk_hash, - ] - } else { - vec![ - batch_l1_data.prev_batch_commitment.to_fixed_bytes(), - batch_l1_data.curr_batch_commitment.to_fixed_bytes(), - ] - }; + let input_fields = if protocol_version.is_some() && protocol_version.unwrap() <= 22 { + vec![ + batch_l1_data.prev_batch_commitment.to_fixed_bytes(), + batch_l1_data.curr_batch_commitment.to_fixed_bytes(), + verifier_params.recursion_node_level_vk_hash, + verifier_params.recursion_leaf_level_vk_hash, + ] + } else { + vec![ + batch_l1_data.prev_batch_commitment.to_fixed_bytes(), + batch_l1_data.curr_batch_commitment.to_fixed_bytes(), + ] + }; let encoded_input_params = input_fields.flatten(); let input_keccak_hash = to_fixed_bytes(Keccak256::digest(&encoded_input_params).as_slice()); diff --git a/src/keys/protocol_version/26/scheduler_key.json b/src/keys/protocol_version/26/scheduler_key.json new file mode 100644 index 0000000..a4aeb77 --- /dev/null +++ b/src/keys/protocol_version/26/scheduler_key.json @@ -0,0 +1,399 @@ +{ + "n": 16777215, + "num_inputs": 1, + "state_width": 4, + "num_witness_polys": 0, + "gate_setup_commitments": [ + { + "x": [ + 14543631136906534221, + 11532161447842416044, + 11114175029926010938, + 1228896787564295039 + ], + "y": [ + 13293602262342424489, + 8897930584356943159, + 13256028170406220369, + 3214939367598363288 + ], + "infinity": false + }, + { + "x": [ + 11488992528554025682, + 12016824828223971094, + 11942004360057333370, + 316831626296641307 + ], + "y": [ + 304673622018339856, + 7139037552557818730, + 12475560967982555143, + 1055588351918295250 + ], + "infinity": false + }, + { + "x": [ + 2274984630539920017, + 5398167177582250136, + 16440396753384808945, + 1037682586893548769 + ], + "y": [ + 10168660308952593373, + 16526369642614237721, + 569062739734175056, + 155645558476901406 + ], + "infinity": false + }, + { + "x": [ + 14005362797509427677, + 2662603874351919260, + 14261489165672308143, + 1470528288349794782 + ], + "y": [ + 11144229651170108862, + 11439490264313454962, + 114993091474760680, + 1037267173208738614 + ], + "infinity": false + }, + { + "x": [ + 10726125240955612787, + 1916320162213728495, + 1058608086768277905, + 1651114031905829493 + ], + "y": [ + 13237242732587628574, + 4774776044666137690, + 14401013098807103799, + 2514139699916115771 + ], + "infinity": false + }, + { + "x": [ + 14434760601334248377, + 5316938318287831815, + 6221098547630910324, + 980422841280734466 + ], + "y": [ + 9201886393750447942, + 3840149540273146267, + 18179910191622136829, + 1563809864380914603 + ], + "infinity": false + }, + { + "x": [ + 9586697317366528906, + 2325800863365957883, + 1243781259615311278, + 3048012003267036960 + ], + "y": [ + 612821620743617231, + 1510385666449513894, + 9368337288452385056, + 2949736812933507034 + ], + "infinity": false + }, + { + "x": [ + 11830690209042008764, + 11761396005838073769, + 18271188400274886574, + 2896734446482773484 + ], + "y": [ + 1890606551566554401, + 10220931290312275762, + 3256711195869515344, + 2466626485328709457 + ], + "infinity": false + } + ], + "gate_selectors_commitments": [ + { + "x": [ + 10865727529243127085, + 4083978853392244827, + 14303622309482785753, + 2263042021033673595 + ], + "y": [ + 3019601017411802529, + 880444282195426618, + 9998743525359587628, + 2891421025832200233 + ], + "infinity": false + }, + { + "x": [ + 5208608554346323426, + 8575970970223832576, + 2966209169082345602, + 239576408267301488 + ], + "y": [ + 17715084817752316452, + 2726293100894160682, + 17920596859559317135, + 3485576345363305439 + ], + "infinity": false + } + ], + "permutation_commitments": [ + { + "x": [ + 14761045450946573029, + 17157644513453531531, + 2555518804134782053, + 1415819224310783987 + ], + "y": [ + 17265629196749977462, + 4128711855633066822, + 8435602817910411328, + 1408116296902303196 + ], + "infinity": false + }, + { + "x": [ + 3307267823832528482, + 2406249680085831639, + 9091964031261402109, + 2846274000290842933 + ], + "y": [ + 17374905554931807856, + 6690578002079222163, + 11809376320193686210, + 2676076649992974574 + ], + "infinity": false + }, + { + "x": [ + 3159118708748226574, + 5508845413629697013, + 13350869305506486049, + 689297560178790472 + ], + "y": [ + 15696011303896469684, + 12551611148155235140, + 14438660833518031207, + 425021756161657108 + ], + "infinity": false + }, + { + "x": [ + 18349397811516917436, + 4473982696343317918, + 13070312540813307819, + 2109468484629113245 + ], + "y": [ + 13254534552549721008, + 17388411854346636521, + 17875890960520499518, + 1062184221180884481 + ], + "infinity": false + } + ], + "total_lookup_entries_length": 1787472, + "lookup_selector_commitment": { + "x": [ + 9324906502432882695, + 14977861238256290580, + 12538013124354067293, + 3408438202312564138 + ], + "y": [ + 14942105932194201701, + 12210090881357612547, + 14774705021036784261, + 2531694948512337448 + ], + "infinity": false + }, + "lookup_tables_commitments": [ + { + "x": [ + 10873859091125335643, + 3906092213625635374, + 17046157606087980048, + 3193402705223440293 + ], + "y": [ + 10158946293873382504, + 2171386304067884865, + 6918663094168980658, + 350601565475975409 + ], + "infinity": false + }, + { + "x": [ + 12822112641313049260, + 3646552465186399021, + 10324071010773924047, + 2209084192380614662 + ], + "y": [ + 11045141628975531869, + 12589678537679955590, + 3065046617868727674, + 2099447669854151830 + ], + "infinity": false + }, + { + "x": [ + 11395032673621937545, + 3000063650268118516, + 7857619430005721792, + 805706808484810738 + ], + "y": [ + 6817063666434679427, + 1646386051225388537, + 4677946977082722827, + 1369650305976868514 + ], + "infinity": false + }, + { + "x": [ + 2885179371868476351, + 159944842081142878, + 6092294387055034894, + 213843603626505240 + ], + "y": [ + 11868113133779277990, + 8509646480531194854, + 14088068011597639414, + 707070630614027545 + ], + "infinity": false + } + ], + "lookup_table_type_commitment": { + "x": [ + 1732877442096985191, + 7537030715658833452, + 14073502080301311448, + 2178792007727681099 + ], + "y": [ + 8513095304113652904, + 6581396660744182779, + 13939755637576387431, + 2477157044961106453 + ], + "infinity": false + }, + "non_residues": [ + [ + 5, + 0, + 0, + 0 + ], + [ + 7, + 0, + 0, + 0 + ], + [ + 10, + 0, + 0, + 0 + ] + ], + "g2_elements": [ + { + "x": { + "c0": [ + 5106727233969649389, + 7440829307424791261, + 4785637993704342649, + 1729627375292849782 + ], + "c1": [ + 10945020018377822914, + 17413811393473931026, + 8241798111626485029, + 1841571559660931130 + ] + }, + "y": { + "c0": [ + 5541340697920699818, + 16416156555105522555, + 5380518976772849807, + 1353435754470862315 + ], + "c1": [ + 6173549831154472795, + 13567992399387660019, + 17050234209342075797, + 650358724130500725 + ] + }, + "infinity": false + }, + { + "x": { + "c0": [ + 9089143573911733168, + 11482283522806384523, + 13585589533905622862, + 79029415676722370 + ], + "c1": [ + 5692040832573735873, + 16884514497384809355, + 16717166481813659368, + 2742131088506155463 + ] + }, + "y": { + "c0": [ + 9604638503594647125, + 1289961608472612514, + 6217038149984805214, + 2521661352385209130 + ], + "c1": [ + 17168069778630926308, + 11309277837895768996, + 15154989611154567813, + 359271377050603491 + ] + }, + "infinity": false + } + ] +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index c95c084..4c6ab08 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use serde::Deserialize; use std::io::Read; use std::{fs::File, process}; +mod batch; mod contract; mod inputs; mod outputs; @@ -186,6 +187,11 @@ async fn main() { .await .unwrap(); + let previous_batch_protocol_version = + requests::fetch_batch_protocol_version(batch_number - 1, &network) + .await + .unwrap(); + println!("{}", "Fetching and validating the proof itself".on_blue()); if l1_rpc.is_none() { println!( @@ -212,12 +218,14 @@ async fn main() { } let protocol_version_id = protocol_version.parse::().unwrap(); + let previous_protocol_version_id = previous_batch_protocol_version.parse::().unwrap(); let contract = ContractConfig::new(l1_rpc.clone().unwrap(), network.clone()); let resp = requests::fetch_l1_data( batch_number, protocol_version_id, + previous_protocol_version_id, &network, &l1_rpc.clone().unwrap(), ) diff --git a/src/outputs.rs b/src/outputs.rs index 2c72ef1..618e469 100644 --- a/src/outputs.rs +++ b/src/outputs.rs @@ -32,6 +32,7 @@ pub enum StatusCode { BadCalldataLength, FailedToCallRPCJsonError, FailedToCallRPCResponseError, + FailedToParseProof, } #[derive(Default)] diff --git a/src/requests.rs b/src/requests.rs index 8235fc9..f0be793 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -5,19 +5,22 @@ use circuit_definitions::circuit_definitions::aux_layer::ZkSyncSnarkWrapperCircu use circuit_definitions::snark_wrapper::franklin_crypto::bellman::bn256::Bn256; use circuit_definitions::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::proof::Proof; use colored::Colorize; -use crypto::deserialize_proof; -use ethers::abi::{Abi, Function, Token}; +use ethers::abi::{Abi, Function}; use ethers::contract::BaseContract; use ethers::providers::{Http, Middleware, Provider}; use ethers::types::TxHash; use once_cell::sync::Lazy; -use primitive_types::U256; use zksync_types::{ethabi, H256}; +use crate::batch::{parse_batch_proof, parse_commit_batch_info, CommitBatchInfo}; use crate::block_header::{self, BlockAuxilaryOutput, VerifierParams}; use crate::contract::get_diamond_proxy_address; use crate::outputs::StatusCode; use crate::snark_wrapper_verifier::L1BatchProofForL1; +use crate::utils::{ + get_abi_for_protocol_version, get_commit_function_for_protocol_version, + get_prove_function_for_protocol_version, +}; pub static BLOCK_COMMIT_EVENT_SIGNATURE: Lazy = Lazy::new(|| { ethabi::long_signature( @@ -64,18 +67,27 @@ pub struct AuxOutputWitnessWrapper( pub async fn fetch_l1_data( batch_number: u64, - protocol_version: u16, + current_protocol_version: u16, + previous_protocol_version: u16, network: &str, rpc_url: &str, ) -> Result { - let commit_data = fetch_l1_commit_data(batch_number, protocol_version, network, rpc_url).await; + let commit_data = fetch_l1_commit_data( + batch_number, + current_protocol_version, + previous_protocol_version, + network, + rpc_url, + ) + .await; if commit_data.is_err() { return Err(commit_data.err().unwrap()); } let (batch_l1_data, aux_output) = commit_data.unwrap(); - let proof_info = fetch_proof_from_l1(batch_number, network, rpc_url, protocol_version).await; + let proof_info = + fetch_proof_from_l1(batch_number, network, rpc_url, current_protocol_version).await; if proof_info.is_err() { return Err(proof_info.err().unwrap()); @@ -96,26 +108,13 @@ pub async fn fetch_l1_data( pub async fn fetch_l1_commit_data( batch_number: u64, - protocol_version: u16, + current_protocol_version: u16, + previous_protocol_version: u16, network: &str, rpc_url: &str, ) -> Result<(BatchL1Data, BlockAuxilaryOutput), StatusCode> { let client = Provider::::try_from(rpc_url).expect("Failed to connect to provider"); - let contract_abi: Abi = Abi::load(&include_bytes!("../abis/IZkSync.json")[..]).unwrap(); - - let (function_name, fallback_fn_name) = if protocol_version < 23 { - ("commitBatches", None) - } else { - ("commitBatchesSharedBridge", Some("commitBatches")) - }; - - let function = contract_abi.functions_by_name(&function_name).unwrap()[0].clone(); - let fallback_function = match fallback_fn_name { - None => None, - Some(fn_name) => Some(contract_abi.functions_by_name(&fn_name).unwrap()[0].clone()), - }; - let previous_batch_number = batch_number - 1; let address = get_diamond_proxy_address(network.to_string()); @@ -124,7 +123,12 @@ pub async fn fetch_l1_commit_data( let mut calldata = vec![]; let mut prev_batch_commitment = H256::default(); let mut curr_batch_commitment = H256::default(); - for b_number in [previous_batch_number, batch_number] { + for (b_number, protocol_version) in [ + (previous_batch_number, previous_protocol_version), + (batch_number, current_protocol_version), + ] { + let (function, _) = get_commit_function_for_protocol_version(protocol_version); + let commit_tx = fetch_batch_commit_tx(b_number, network).await; if commit_tx.is_err() { @@ -146,8 +150,7 @@ pub async fn fetch_l1_commit_data( l1_block_number = tx.block_number.unwrap().as_u64(); calldata = tx.input.to_vec(); - let found_data = - find_state_data_from_log(b_number, &function, fallback_function.clone(), &calldata); + let found_data = find_state_data_from_log(protocol_version, &function, &calldata); if found_data.is_err() || found_data.clone().unwrap().is_none() { return Err(StatusCode::InvalidLog); @@ -183,7 +186,9 @@ pub async fn fetch_l1_commit_data( roots.push(found_data.unwrap()); } - let aux_output = block_header::parse_aux_data(&function, &calldata); + let (function, _) = get_commit_function_for_protocol_version(current_protocol_version); + let aux_output = + block_header::parse_aux_data(&function, &calldata, current_protocol_version).await; if aux_output.is_err() { return Err(aux_output.err().unwrap()); @@ -200,6 +205,7 @@ pub async fn fetch_l1_commit_data( format!("0x{}", hex::encode(&new_root)).yellow() ); + let contract_abi = get_abi_for_protocol_version(current_protocol_version); let base_contract: BaseContract = contract_abi.into(); let contract_instance = base_contract.into_contract::>(address, client); let bootloader_code_hash = contract_instance @@ -245,15 +251,7 @@ pub async fn fetch_proof_from_l1( ) -> Result<(L1BatchProofForL1, u64), StatusCode> { let client = Provider::::try_from(rpc_url).expect("Failed to connect to provider"); - let contract_abi: Abi = Abi::load(&include_bytes!("../abis/IZkSync.json")[..]).unwrap(); - - let function_name = if protocol_version < 23 { - "proveBatches" - } else { - "proveBatchesSharedBridge" - }; - - let function = contract_abi.functions_by_name(function_name).unwrap()[0].clone(); + let (function, _) = get_prove_function_for_protocol_version(protocol_version); let (_, prove_tx) = fetch_batch_commit_tx(batch_number, network) .await @@ -280,47 +278,18 @@ pub async fn fetch_proof_from_l1( let l1_block_number = tx.block_number.unwrap().as_u64(); let calldata = tx.input.to_vec(); - let parsed_input = function.decode_input(&calldata[4..]).unwrap(); - - let Token::Tuple(proof) = parsed_input.as_slice().last().unwrap() else { - return Err(StatusCode::InvalidTupleTypes); - }; - - assert_eq!(proof.len(), 2); - - let Token::Array(serialized_proof) = proof[1].clone() else { - return Err(StatusCode::InvalidTupleTypes); - }; - - let proof = serialized_proof - .iter() - .filter_map(|e| { - if let Token::Uint(x) = e { - Some(x.clone()) - } else { - None - } - }) - .collect::>(); - - if network != "mainnet" && serialized_proof.len() == 0 { - let msg = format!( - "Proof doesn't exist for batch {} on network {}, exiting...", - batch_number.to_string().red(), - network.red() - ); - println!("{}", msg); - return Err(StatusCode::ProofDoesntExist); + let proof = parse_batch_proof(&function, &calldata, protocol_version, network); + + match proof { + None => Err(StatusCode::FailedToParseProof), + Some(proof) => Ok(( + L1BatchProofForL1 { + aggregation_result_coords: [[0u8; 32]; 4], + scheduler_proof: proof, + }, + l1_block_number, + )), } - - let x: Proof = deserialize_proof(proof); - Ok(( - L1BatchProofForL1 { - aggregation_result_coords: [[0u8; 32]; 4], - scheduler_proof: x, - }, - l1_block_number, - )) } #[derive(serde::Serialize, serde::Deserialize)] @@ -506,75 +475,34 @@ pub async fn fetch_batch_protocol_version( } fn find_state_data_from_log( - batch_number: u64, + protocol_version: u16, function: &Function, - fallback_function: Option, calldata: &[u8], ) -> Result)>, StatusCode> { - use ethers::abi; - - if calldata.len() < 5 { - return Err(StatusCode::BadCalldataLength); - } - - let mut parsed_input = function.decode_input(&calldata[4..]).unwrap_or_else(|_| { - fallback_function - .unwrap() - .decode_input(&calldata[4..]) - .unwrap() - }); - - let second_param = parsed_input.pop().unwrap(); - let first_param = parsed_input.pop().unwrap(); - - let abi::Token::Tuple(first_param) = first_param else { - return Err(StatusCode::FailedToDeconstruct); - }; - - let abi::Token::Uint(previous_l2_block_number) = first_param[0].clone() else { - return Err(StatusCode::FailedToDeconstruct); - }; - if previous_l2_block_number.as_u64() >= batch_number { - return Err(StatusCode::InvalidLog); - } - let abi::Token::Uint(previous_enumeration_index) = first_param[2].clone() else { - return Err(StatusCode::FailedToDeconstruct); - }; - let _previous_enumeration_index = previous_enumeration_index.0[0]; - - let abi::Token::Array(inner) = second_param else { - return Err(StatusCode::FailedToDeconstruct); - }; - - let mut found_params = None; - - for inner in inner.into_iter() { - let abi::Token::Tuple(inner) = inner else { - return Err(StatusCode::FailedToDeconstruct); - }; - let abi::Token::Uint(new_l2_block_number) = inner[0].clone() else { - return Err(StatusCode::FailedToDeconstruct); - }; - let new_l2_block_number = new_l2_block_number.0[0]; - if new_l2_block_number == batch_number { - let abi::Token::Uint(new_enumeration_index) = inner[2].clone() else { - return Err(StatusCode::FailedToDeconstruct); - }; - let new_enumeration_index = new_enumeration_index.0[0]; - - let abi::Token::FixedBytes(state_root) = inner[3].clone() else { - return Err(StatusCode::FailedToDeconstruct); - }; - - assert_eq!(state_root.len(), 32); - - found_params = Some((new_enumeration_index, state_root)); - } else { - continue; + let batch = parse_commit_batch_info(function, calldata, protocol_version); + + match batch { + None => Err(StatusCode::FailedToDeconstruct), + Some(batch_commit) => { + let CommitBatchInfo { + batch_number: _, + timestamp: _, + index_repeated_storage_changes, + new_state_root, + number_l1_txns: _, + priority_operations_hash: _, + bootloader_contents_hash: _, + event_queue_state_hash: _, + sys_logs: _, + total_pubdata: _, + } = batch_commit; + + Ok(Some(( + index_repeated_storage_changes.as_u64(), + new_state_root, + ))) } } - - Ok(found_params) } async fn fetch_verifier_param_from_l1( diff --git a/src/utils.rs b/src/utils.rs index 6a00d76..22af5a1 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,7 @@ use std::env; +use ethers::abi::{Abi, Function}; + /// Checks to see if the verification key exists for a given protocol version or an update has been requested and downloads it from github if needed. pub async fn check_verification_key(protocol_version: String) { let file_path = format!( @@ -30,7 +32,7 @@ pub fn get_scheduler_key_override( batch_number: u64, ) -> Option { // This override is needed because we discovered a deviation between our in and out of circuit - // vms. The choice was made to update the verifier vs bumping the protocol version as it would have + // vms. The choice was made to update the verifier vs bumping the protocol version as it would have // required a batch rollback. if network == "sepolia" { if protocol_version == "24" { @@ -45,3 +47,41 @@ pub fn get_scheduler_key_override( } None } + +pub fn get_abi_for_protocol_version(protocol_version: u16) -> Abi { + if protocol_version < 26 { + Abi::load(&include_bytes!("../abis/IZkSync.json")[..]).unwrap() + } else { + Abi::load(&include_bytes!("../abis/IZKChain.json")[..]).unwrap() + } +} + +pub fn get_commit_function_for_protocol_version( + protocol_version: u16, +) -> (Function, Option) { + let contract_abi = get_abi_for_protocol_version(protocol_version); + let function_name = if protocol_version < 23 { + "commitBatches" + } else { + "commitBatchesSharedBridge" + }; + + let function = contract_abi.functions_by_name(&function_name).unwrap()[0].clone(); + + (function, None) +} + +pub fn get_prove_function_for_protocol_version( + protocol_version: u16, +) -> (Function, Option) { + let contract_abi = get_abi_for_protocol_version(protocol_version); + let function_name = if protocol_version < 23 { + "proveBatches" + } else { + "proveBatchesSharedBridge" + }; + + let function = contract_abi.functions_by_name(&function_name).unwrap()[0].clone(); + + (function, None) +}