@layerzerolabs/lz-proof-utility 3.0.72 → 3.0.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/proof.ts","../src/mpt/common.ts","../src/mpt/v1.ts","../src/mpt/v2.ts"],"names":["getReceiptProof","utils","BigNumber","CheckpointTrie","encode","Receipt","toBuffer","promisfy","invariant","Proof","ethers","rlp","stringToNibbles","matchingNibbleLength","assembleMPTProof","assertReceiptInclusion"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,WAAW,CAAC,SAAA,EAAW,SAAW,EAAA,UAAA,EAAY,WAAW,SAAS;AAKxE,IAAM,iBAAoB,GAAA;AAAA;AAAA;AAAA;AAAA,EAI7B,GAAK,EAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAIL,EAAI,EAAA;AACR;AAKO,IAAM,iBAAoB,GAAA;AAAA,EAC7B,EAAI,EAAA,CAAA;AAAA,EACJ,EAAI,EAAA,CAAA;AAAA,EACJ,EAAI,EAAA,CAAA;AAAA,EACJ,EAAI,EAAA;AACR;AAKO,IAAM,oBAAuB,GAAA;AAAA,EAChC,QAAU,EAAA;AAAA,IACN,4CAA8C,EAAA,CAAA;AAAA,IAC9C,4CAA8C,EAAA,CAAA;AAAA,IAC9C,4CAA8C,EAAA;AAAA,GAClD;AAAA,EACA,SAAW,EAAA;AAAA,IACP,4CAA8C,EAAA,CAAA;AAAA,IAC9C,4CAA8C,EAAA,CAAA;AAAA,IAC9C,4CAA8C,EAAA;AAAA,GAClD;AAAA,EACA,GAAK,EAAA;AAAA,IACD,4CAA8C,E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AgB,CAAA,MAAA,CAAO,CAAC,SAAS,CAAG,EAAA,CAAC,IAAK,CAAA,OAAO,CAAC,CAAA;AAAA,IAC3E;AAAA,GACJ;AACJ","file":"index.cjs","sourcesContent":["/**\n * Supported networks.\n */\nexport const NETWORKS = ['default', 'hardhat', 'arbitrum', 'polygon', 'harmony']\n\n/**\n * Enum representing outbound proof types.\n */\nexport const OutboundProofType = {\n /**\n * Merkle Patricia Trie proof type.\n */\n MPT: 1,\n /**\n * Feather proof type.\n */\n FP: 2,\n}\n\n/**\n * Enum representing EVM utility versions.\n */\nexport const EVMUtilityVersion = {\n V1: 1,\n V2: 2,\n V3: 3,\n V4: 4,\n}\n\n/**\n * Lookup table for utility versions by network and address.\n */\nexport const UTILS_VERSION_LOOKUP = {\n arbitrum: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': 2,\n },\n avalanche: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xcbd35a9b849342ad34a71e072d9947d4afb4e164': 2,\n },\n bsc: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xcff08a35a5f27f306e2da99ff198db90f13def77': 2,\n },\n 'bsc-testnet': {\n '0xfc256f1007e67abbd027536818142823b4596a24': 1,\n '0x1de92e6b8e8b6b150ea8588fe387a4f5fb4da778': 2,\n '0x76860669184330e6966a61188cfbd13486c7a6a6': 2,\n '0x4652b61781f5ee79dad354ab5d249aa2b99b4def': 2,\n },\n 'bsc-sandbox': {\n '0xf96093134adf151889ed72517979b2cd7144a831': 1,\n '0x1751181f9af72b37934006bbe989238498067563': 2,\n '0x8953031e74a172586e89ddb40b7d269b9186e74c': 2,\n },\n ethereum: {\n '0x2d61dcdd36f10b22176e0433b86f74567d529aaa': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xe9ae261d3aff7d3fccf38fa2d612dd3897e07b2d': 2,\n },\n fantom: {\n '0x3c2269811836af69497e5f486a85d7316753cf62': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': 2,\n },\n 'fantom-testnet': {\n '0x0c3d09a7d86652f5599b836ce3db685a86513487': 1,\n '0x7669ac2bb50d567fd4bfb1cb5154b79c1e5e4a92': 2,\n '0xdafbd7a68e4ddcaa864c6a1171bd6030d0ca9a43': 2,\n '0x843986e31e0e3fea5eaf01086f36e7d85c458bb1': 2,\n },\n 'fantom-sandbox': {\n '0x54f51642779b9dbf48cc653c40499c82b8f261b3': 1,\n '0x01de566a13dc4be329351d930b0d9a569a495e46': 2,\n '0xf96093134adf151889ed72517979b2cd7144a831': 2,\n },\n 'avalanche-testnet': {\n '0xa7ac9fadbe9f51e7aa96751aa53f4cbb8a07b9ba': 1,\n '0x08c2e2b98d35973a4b2ca7ce8815cdb7c6f474f0': 2,\n '0x0a833b15305ce8b64946098db286710ace7bbe94': 2,\n '0xd81a1c5c52495a23f75d7269c17c73cebea61233': 2,\n },\n 'avalanche-sandbox': {\n '0x8953031e74a172586e89ddb40b7d269b9186e74c': 1,\n '0x4d7248986395d24ec777b16ca3fa32de64ec0330': 2,\n '0x4489a462f812d6dca0bde380ebdac12eb5a9e85a': 2,\n },\n 'polygon-testnet': {\n '0x2c7b02ffbc9602e8c04901609ef17cb1c4c2a7f7': 1,\n '0x3f6055024105d22b9400e025a1ca3259bd8b1893': 2,\n '0xcb97d107a87c5e172e075de94d7ef4498f6f06d2': 2,\n '0xd8b2de57ccfbbd5cd1713542cb6790fd2e33fed6': 2,\n },\n 'polygon-sandbox': {\n '0x369cc088dcedaaad27df0185c4f78caae42ff942': 1,\n '0x46f703c2a92874d5d526878a2ccc44e9431720a5': 2,\n '0xee404727abfca5d08a2480b0b881745f25362828': 2,\n },\n optimism: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': 2,\n },\n polygon: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': 2,\n },\n}\n","import { ethers } from 'ethers'\nimport invariant from 'tiny-invariant'\n\nimport { EVMUtilityVersion, NETWORKS, OutboundProofType } from './constants'\nimport { getReceiptProof as getReceiptProofV1 } from './mpt/v1'\nimport { getReceiptProof as getReceiptProofV2 } from './mpt/v2'\n\n/**\n * Generates a feather proof based on the utility version.\n *\n * @param {number} utilsVersion - The utility version.\n * @param {string} emitterAddress - The emitter address.\n * @param {string} packetPayload - The packet payload.\n * @returns {{ proof: string }} The generated proof.\n */\nexport function getFeatherProof(utilsVersion, emitterAddress, packetPayload): { proof: string } {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n const contractAddrByte32 = ethers.utils.hexZeroPad(emitterAddress, 32)\n return {\n proof: ethers.utils.solidityPack(['bytes32', 'bytes'], [contractAddrByte32, packetPayload]),\n }\n }\n case EVMUtilityVersion.V2: {\n return {\n proof: packetPayload,\n }\n }\n default:\n throw new Error(`Unknown utility version ${utilsVersion}`)\n }\n}\n\n/**\n * Retrieves the receipt proof based on the provided parameters.\n *\n * @param {string} network - The network name.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @param {number} outboundProofType - The outbound proof type.\n * @param {number} utilsVersion - The utility version.\n * @returns {Promise<object>} The receipt proof.\n */\nexport async function getReceiptProof(\n network,\n block,\n transactionReceipts,\n transactionIndex,\n outboundProofType,\n utilsVersion\n) {\n invariant(NETWORKS.includes(network), `Unsupported network: ${network}`)\n\n switch (outboundProofType) {\n case OutboundProofType.MPT: {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n return getReceiptProofV1(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V2:\n case EVMUtilityVersion.V4: {\n return getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V3: {\n const proof = await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n return {\n ...proof,\n blockHash: block.hash,\n }\n }\n default:\n throw new Error(`Unsupported utility version ${utilsVersion}`)\n }\n }\n default:\n throw new Error(`Unsupported Outbound Proof Type ${outboundProofType}`)\n }\n}\n\n/**\n * Encodes the parameters for the proof.\n *\n * @param {object} proof - The proof object.\n * @param {number} outboundProofType - The outbound proof type.\n * @param {number} utilsVersion - The utility version.\n * @param {number} logIndex - The log index.\n * @param {number} [srcEndpointId] - The source endpoint ID.\n * @returns {string} The encoded parameters.\n */\nexport function encodeParams(proof, outboundProofType, utilsVersion, logIndex, srcEndpointId?: number): string {\n switch (outboundProofType) {\n case OutboundProofType.MPT: {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes[]', 'uint256[]', 'uint256', 'uint256'],\n [srcEndpointId, proof.proof, proof.pointers, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V2: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes[]', 'uint256[]', 'uint256'],\n [srcEndpointId, proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V3: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes32', 'bytes[]', 'uint256[]', 'uint256'],\n [srcEndpointId, proof.blockHash, proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V4: {\n return ethers.utils.defaultAbiCoder.encode(\n ['bytes[]', 'uint256[]', 'uint256'],\n [proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n default:\n throw new Error(`Unsupported utility version ${utilsVersion}`)\n }\n }\n default:\n throw new Error(`Unsupported Outbound Proof Type ${outboundProofType}`)\n }\n}\n\n/**\n * Retrieves the LayerZero packet from the log data.\n *\n * @param {number} srcChainId - The source chain ID.\n * @param {object} _log - The log object.\n * @returns {object} The LayerZero packet.\n */\nexport function getLayerZeroPacket(srcChainId, _log) {\n //todo: what if src address differs from 20 bytes\n const packet = ethers.utils.defaultAbiCoder.decode(['uint16', 'bytes'], _log.data)\n const data = packet[1].slice(2)\n\n //todo: what if dst address differs from 20 bytes\n const dstChainId = parseInt(packet[0])\n const nonce = ethers.BigNumber.from('0x' + data.slice(0, 16)).toNumber()\n const srcAddress = '0x' + data.slice(16, 56)\n const dstAddress = '0x' + data.slice(56, 96)\n\n let payload = '0x'\n if (data.length > 96) {\n //has payload\n payload = '0x' + data.slice(96, data.length)\n }\n\n return {\n srcChainId,\n dstChainId,\n nonce,\n dstAddress,\n srcAddress,\n ulnAddress: ethers.utils.defaultAbiCoder.encode(['address'], [_log.address]),\n payload,\n }\n}\n","// getStateSyncTxHash returns block's tx hash for state-sync receipt\n// Bor blockchain includes extra receipt/tx for state-sync logs,\n// but it is not included in transactionRoot or receiptRoot.\n// So, while calculating proof, we have to exclude them.\n//\n// This is derived from block's hash and number\n// state-sync tx hash = keccak256(\"matic-bor-receipt-\" + block.number + block.hash)\nimport { Proof, Receipt } from 'eth-object'\nimport { encode, toBuffer } from 'eth-util-lite'\nimport { BigNumber, utils } from 'ethers'\nimport CheckpointTrie from 'merkle-patricia-tree'\nimport { promisfy } from 'promisfy'\nimport invariant from 'tiny-invariant'\n\n/**\n * Returns the transaction hash for the state-sync receipt in a Polygon block.\n *\n * @param {object} block - The block object.\n * @returns {string} The transaction hash for the state-sync receipt.\n */\nexport function getPolygonStateSyncTxHash(block): string {\n const prefix = Buffer.from('matic-bor-receipt-')\n const blockNumberBytes = utils.zeroPad(utils.arrayify(BigNumber.from(block.number)), 8)\n const blockHashBytes = utils.arrayify(block.hash)\n\n const hash = utils.keccak256(utils.concat([prefix, blockNumberBytes, blockHashBytes]))\n\n return hash\n}\n\n/**\n * Converts a buffer to a hex string.\n *\n * @param {Buffer} buffer - The buffer to convert.\n * @returns {string} The hex string.\n */\nexport function buffer2hex(buffer): string {\n return '0x' + buffer.toString('hex')\n}\n\n/**\n * Generates a receipt proof from the given network, block, transaction receipts, and transaction index.\n *\n * @param {string} network - The network name.\n * @param {object} block - The block object.\n * @param {object[]} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to an object containing the receipt proof and stack.\n * @throws {Error} If the receipt root from the RPC block does not match the receipt root built.\n */\nexport async function receiptProofFrom(network, block, transactionReceipts, transactionIndex) {\n // handle the polygon special receipt\n if (network === 'polygon') {\n const ignoredTxnHash = getPolygonStateSyncTxHash(block)\n transactionReceipts = transactionReceipts.filter((receipt) => receipt.transactionHash !== ignoredTxnHash)\n }\n\n const tree = new CheckpointTrie()\n await Promise.all(\n transactionReceipts.map((siblingReceipt, index) => {\n const siblingPath = encode(index)\n\n if (network === 'harmony' && index >= block.transactions.length) {\n // void staking receipt type, which works differently from EIP2718\n siblingReceipt.type = 0\n }\n\n let serializedReceipt = Receipt.fromRpc(siblingReceipt)\n\n //handles the arbitrum receipt\n if (network === 'arbitrum') {\n //todo: will not need this in aribtrum nitro\n serializedReceipt[0] = toBuffer(0)\n }\n serializedReceipt = serializedReceipt.serialize()\n\n // if type is defined, concat type and RLP buffer seperately (for receipts/transactions following EIP2718)\n if (siblingReceipt.type) {\n serializedReceipt = Buffer.concat([toBuffer(siblingReceipt.type), serializedReceipt])\n }\n\n return promisfy(tree.put, tree)(siblingPath, serializedReceipt)\n })\n )\n\n const [_, __, stack] = await promisfy(tree.findPath, tree)(encode(transactionIndex))\n\n // assert the tree root\n const receiptRootFromBlock = block.receiptsRoot.slice(2)\n invariant(\n receiptRootFromBlock === tree._root.toString('hex'),\n 'receiptRoot from rpc block != receipt root we built'\n )\n\n return {\n stack: stack,\n receiptProof: Proof.fromStack(stack),\n }\n}\n","import { rlp } from 'ethereumjs-util'\nimport { ethers } from 'ethers'\nimport { matchingNibbleLength, stringToNibbles } from 'merkle-patricia-tree/util/nibbles'\nimport invariant from 'tiny-invariant'\n\nimport { buffer2hex, receiptProofFrom } from './common'\n\n/**\n * Finds the pointer in the full bytes.\n *\n * @param {Buffer} fullBytes - The full bytes.\n * @param {Buffer} currentNodeElement - The current node element.\n * @returns {number} The pointer.\n */\nfunction findPointer(fullBytes, currentNodeElement): number {\n const fullBytesHex = fullBytes.toString('hex')\n const slicedBytesHex = currentNodeElement.toString('hex')\n const result = fullBytesHex.indexOf(slicedBytesHex)\n invariant(result >= 0, 'wrong index')\n return (result - 2) / 2\n}\n\n/*\nrunning MPT locally, strictly the same as solidity file\n */\n\n/**\n * Asserts the inclusion of a receipt in the MPT.\n *\n * @param {string} receiptsRoot - The root of the receipts.\n * @param {string} expectedLogValue - The expected log value.\n * @param {Array} rlpProof - The RLP encoded proof.\n * @param {Array} pointers - The pointers in the MPT.\n * @returns {boolean} True if the receipt is included, false otherwise.\n */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, pointers): boolean {\n let nextRoot = receiptsRoot\n const proofDepth = rlpProof.length\n let pointer\n let proofBytes\n for (let i = 0; i < proofDepth; i++) {\n proofBytes = rlpProof[i]\n if (nextRoot !== ethers.utils.keccak256(proofBytes)) return false\n // load 32 bytes from the proofBytes\n if (i < pointers.length) {\n pointer = 2 + pointers[i] * 2\n nextRoot = '0x' + proofBytes.substring(pointer, pointer + 64)\n }\n }\n return true\n}\n\n/**\n * Assembles a Merkle Patricia Tree (MPT) proof.\n *\n * @param {object} proof - The proof object.\n * @param {object} block - The block object.\n * @param {number} transactionIndex - The transaction index.\n * @returns {object} The assembled MPT proof.\n */\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const { stack } = proof\n\n // convert receipt Proof L2 nested contents into hex\n const rlpNestedProof = [...proof.receiptProof].map((node) => node.map((elem) => buffer2hex(elem)))\n const rlpProof = rlpNestedProof.map((node) => buffer2hex(rlp.encode(node)))\n\n // decimal of transaction index\n const receiptIndexDeci = ethers.BigNumber.from(transactionIndex).toNumber()\n const encodedMerklePath = stringToNibbles(rlp.encode(receiptIndexDeci)) // if index = 252, encoded = 81fc\n\n // prepare the data for offline traversal\n let hashRoot = block.receiptsRoot\n const proofDepth = stack.length\n // const targetReceipt = stack[proofDepth - 1].value;\n const targetReceipt = rlpNestedProof[rlpNestedProof.length - 1][1]\n let proofPathCounter = 0\n const totalPathLength = encodedMerklePath.length\n const pointers: number[] = []\n let receiptSlotIndex\n for (let i = 0; i < proofDepth; i++) {\n // assert the path depth constaints\n invariant(\n proofPathCounter <= totalPathLength,\n `proofPathCounter wrong at ${proofPathCounter}, where totalPathLength = ${totalPathLength}`\n )\n\n // thisNodeValue in array form, easier to retrieve data\n const thisNode = stack[i]\n const thisNodeValue = thisNode.raw\n // convert the elem first then hex again, it is == rlpNestedProof[i]\n const thisNodeRlp = rlpProof[i]\n invariant(\n ethers.utils.keccak256(thisNodeRlp) === hashRoot,\n `invalid hashlink at depth ${i} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n\n if (thisNode.type === 'branch') {\n // branch node\n if (proofPathCounter === totalPathLength) {\n // has reach the end, assert targetReceipt ==\n invariant(ethers.utils.keccak256(thisNodeValue[16]) === targetReceipt, 'invalid branch value node')\n receiptSlotIndex = 16\n } else {\n // a normal branch node, step down\n const nextNibble = encodedMerklePath[proofPathCounter]\n invariant(\n nextNibble <= 16,\n `invalid nibble at ${nextNibble} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n // hashRoot = buffer2hex(thisNode._branches[nextNibble])\n hashRoot = buffer2hex(thisNodeValue[nextNibble])\n proofPathCounter += 1\n // retrieve the pointer for the branch value\n pointers.push(findPointer(thisNodeRlp, thisNodeValue[nextNibble]))\n }\n } else if (thisNode.type === 'leaf' || thisNode.type === 'extention') {\n const progressKey = encodedMerklePath.slice(0, proofPathCounter)\n const keyRemainder = encodedMerklePath.slice(matchingNibbleLength(progressKey, encodedMerklePath))\n proofPathCounter += matchingNibbleLength(keyRemainder, stack[i].key)\n if (thisNode.type === 'leaf') {\n invariant(proofPathCounter === totalPathLength, 'invalid leaf node')\n invariant(\n ethers.utils.keccak256(thisNodeValue[1]) === ethers.utils.keccak256(targetReceipt),\n 'wrong leaf value'\n )\n receiptSlotIndex = 1\n } else if (thisNode.type === 'extention') {\n hashRoot = buffer2hex(thisNodeValue[1])\n // retrieve the pointer for the leaf node\n pointers.push(findPointer(thisNodeRlp, thisNodeValue[1]))\n }\n } else {\n throw `unsupported node type in MPT ${thisNode} ${encodedMerklePath}`\n }\n }\n\n invariant(assertReceiptInclusion(block.receiptsRoot, targetReceipt, rlpProof, pointers), 'MPTLite local fails')\n\n return {\n receiptRoot: block.receiptsRoot,\n proof: rlpProof,\n pointers: pointers,\n receiptSlotIndex: receiptSlotIndex,\n }\n}\n\n/**\n * Retrieves the receipt proof.\n *\n * @param {string} network - The network.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to the receipt proof.\n */\nexport async function getReceiptProof(network, block, transactionReceipts, transactionIndex) {\n const proof = await receiptProofFrom(network, block, transactionReceipts, transactionIndex)\n return assembleMPTProof(proof, block, transactionIndex)\n}\n","import { rlp } from 'ethereumjs-util'\nimport { ethers } from 'ethers'\nimport { matchingNibbleLength, stringToNibbles } from 'merkle-patricia-tree/util/nibbles'\nimport invariant from 'tiny-invariant'\n\nimport { buffer2hex, receiptProofFrom } from './common'\n\n/**\n * Assembles a Merkle Patricia Tree (MPT) proof.\n *\n * @param {object} proof - The proof object.\n * @param {object} block - The block object.\n * @param {number} transactionIndex - The transaction index.\n * @returns {object} The assembled MPT proof.\n */\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const { stack } = proof\n\n // convert receipt Proof L2 nested contents into hex\n const rlpNestedProof = [...proof.receiptProof].map((node) => node.map((elem) => buffer2hex(elem)))\n const rlpProof = rlpNestedProof.map((node) => buffer2hex(rlp.encode(node)))\n\n // decimal of transaction index\n const receiptIndexDeci = ethers.BigNumber.from(transactionIndex).toNumber()\n const encodedMerklePath = stringToNibbles(rlp.encode(receiptIndexDeci)) // if index = 252, encoded = 81fc\n\n // prepare the data for offline traversal\n let hashRoot = block.receiptsRoot\n const proofDepth = stack.length\n // const targetReceipt = stack[proofDepth - 1].value;\n const targetReceipt = rlpNestedProof[rlpNestedProof.length - 1][1]\n let proofPathCounter = 0\n const totalPathLength = encodedMerklePath.length\n const path: number[] = []\n for (let i = 0; i < proofDepth; i++) {\n // console.log(`hashroot at ${i} : ${hashRoot}`)\n // console.log(` rlpProof at ${rlpProof[i]}`)\n\n // assert the path depth constraints\n invariant(\n proofPathCounter <= totalPathLength,\n `proofPathCounter wrong at ${proofPathCounter}, where totalPathLength = ${totalPathLength}`\n )\n\n // thisNodeValue in array form, easier to retrieve data\n const thisNode = stack[i]\n const thisNodeValue = thisNode.raw\n // convert the elem first then hex again, it is == rlpNestedProof[i]\n const thisNodeRlp = rlpProof[i]\n invariant(\n ethers.utils.keccak256(thisNodeRlp) === hashRoot,\n `invalid hashlink at depth ${i} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n\n if (thisNode.type === 'branch') {\n // branch node\n if (proofPathCounter === totalPathLength) {\n // has reach the end, assert targetReceipt ==\n invariant(ethers.utils.keccak256(thisNodeValue[16]) === targetReceipt, 'invalid branch value node')\n path[i] = 16\n console.warn(`a branch node 16 value type ${transactionIndex} receipt root ${block.receiptsRoot}`)\n } else {\n // a normal branch node, step down\n const nextNibble = encodedMerklePath[proofPathCounter]\n invariant(\n nextNibble <= 16,\n `invalid nibble at ${nextNibble} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n // hashRoot = buffer2hex(thisNode._branches[nextNibble])\n hashRoot = buffer2hex(thisNodeValue[nextNibble])\n proofPathCounter += 1\n // retrieve the pointer for the branch value\n path[i] = nextNibble\n }\n } else if (thisNode.type === 'leaf' || thisNode.type === 'extention') {\n const progressKey = encodedMerklePath.slice(0, proofPathCounter)\n const keyRemainder = encodedMerklePath.slice(matchingNibbleLength(progressKey, encodedMerklePath))\n proofPathCounter += matchingNibbleLength(keyRemainder, stack[i].key)\n if (thisNode.type === 'leaf') {\n invariant(proofPathCounter === totalPathLength, 'invalid leaf node')\n invariant(\n ethers.utils.keccak256(thisNodeValue[1]) === ethers.utils.keccak256(targetReceipt),\n 'wrong leaf value'\n )\n path[i] = 1\n } else if (thisNode.type === 'extention') {\n path[i] = 1\n hashRoot = buffer2hex(thisNodeValue[1])\n // retrieve the pointer for the leaf node\n }\n } else {\n throw `unsupported node type in MPT ${thisNode} ${encodedMerklePath}`\n }\n }\n\n invariant(assertReceiptInclusion(block.receiptsRoot, targetReceipt, rlpProof, path, stack), 'MPTLite local fails')\n\n return {\n receiptRoot: block.receiptsRoot,\n proof: rlpProof,\n receiptSlotIndex: path,\n }\n}\n\n/*\nrunning MPT locally, strictly the same as solidity file\n */\n\n/**\n * Asserts the inclusion of a receipt in the MPT.\n *\n * @param {string} receiptsRoot - The root of the receipts.\n * @param {string} expectedLogValue - The expected log value.\n * @param {Array} rlpProof - The RLP encoded proof.\n * @param {Array} path - The path in the MPT.\n * @param {Array} stack - The stack of nodes.\n * @returns {boolean} True if the receipt is included, false otherwise.\n */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, path, stack): boolean {\n let nextRoot = receiptsRoot\n const proofDepth = rlpProof.length\n for (let i = 0; i < proofDepth; i++) {\n const proofBytes = rlpProof[i]\n const thisNodeValue = stack[i].raw\n if (nextRoot !== ethers.utils.keccak256(proofBytes)) return false\n if (i < proofDepth - 1) {\n nextRoot = buffer2hex(thisNodeValue[path[i]])\n }\n }\n return true\n}\n\n/**\n * Retrieves the receipt proof.\n *\n * @param {string} network - The network.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to the receipt proof.\n */\nexport async function getReceiptProof(network, block, transactionReceipts, transactionIndex) {\n const proof = await receiptProofFrom(network, block, transactionReceipts, transactionIndex)\n return assembleMPTProof(proof, block, transactionIndex)\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/proof.ts","../src/mpt/common.ts","../src/mpt/v1.ts","../src/mpt/v2.ts"],"names":["getReceiptProof","utils","BigNumber","CheckpointTrie","encode","Receipt","toBuffer","promisfy","invariant","Proof","ethers","rlp","stringToNibbles","matchingNibbleLength","assembleMPTProof","assertReceiptInclusion"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,WAAW,CAAC,SAAA,EAAW,SAAW,EAAA,UAAA,EAAY,WAAW,SAAS;AAKxE,IAAM,iBAAoB,GAAA;AAAA;AAAA;AAAA;AAAA,EAI7B,GAAK,EAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAIL,EAAI,EAAA;AACR;AAKO,IAAM,iBAAoB,GAAA;AAAA,EAC7B,EAAI,EAAA,CAAA;AAAA,EACJ,EAAI,EAAA,CAAA;AAAA,EACJ,EAAI,EAAA,CAAA;AAAA,EACJ,EAAI,EAAA;AACR;AAKO,IAAM,oBAAuB,GAAA;AAAA,EAChC,QAAU,EAAA;AAAA,IACN,4CAA8C,EAAA,CAAA;AAAA,IAC9C,4CAA8C,EAAA,CAAA;AAAA,IAC9C,4CAA8C,EAAA;AAAA,GAClD;AAAA,EACA,SAAW,EAAA;AAAA,IACP,4CAA8C,EAAA,CAAA;AAAA,IAC9C,4CAA8C,EAAA,CAAA;AAAA,IAC9C,4CAA8C,EAAA;AAAA,GAClD;AAAA,EACA,GAAK,EAAA;AAAA,IACD,4CAA8C,EAAA,CAAA;AAAA,IAC9C,4CAA8C,EAA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AA,CAAC,IAAK,CAAA,OAAO,CAAC,CAAA;AAAA,IAC3E;AAAA,GACJ;AACJ","file":"index.cjs","sourcesContent":["/**\n * Supported networks.\n */\nexport const NETWORKS = ['default', 'hardhat', 'arbitrum', 'polygon', 'harmony']\n\n/**\n * Enum representing outbound proof types.\n */\nexport const OutboundProofType = {\n /**\n * Merkle Patricia Trie proof type.\n */\n MPT: 1,\n /**\n * Feather proof type.\n */\n FP: 2,\n}\n\n/**\n * Enum representing EVM utility versions.\n */\nexport const EVMUtilityVersion = {\n V1: 1,\n V2: 2,\n V3: 3,\n V4: 4,\n}\n\n/**\n * Lookup table for utility versions by network and address.\n */\nexport const UTILS_VERSION_LOOKUP = {\n arbitrum: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': 2,\n },\n avalanche: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xcbd35a9b849342ad34a71e072d9947d4afb4e164': 2,\n },\n bsc: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xcff08a35a5f27f306e2da99ff198db90f13def77': 2,\n },\n 'bsc-testnet': {\n '0xfc256f1007e67abbd027536818142823b4596a24': 1,\n '0x1de92e6b8e8b6b150ea8588fe387a4f5fb4da778': 2,\n '0x76860669184330e6966a61188cfbd13486c7a6a6': 2,\n '0x4652b61781f5ee79dad354ab5d249aa2b99b4def': 2,\n },\n 'bsc-sandbox': {\n '0xf96093134adf151889ed72517979b2cd7144a831': 1,\n '0x1751181f9af72b37934006bbe989238498067563': 2,\n '0x8953031e74a172586e89ddb40b7d269b9186e74c': 2,\n },\n ethereum: {\n '0x2d61dcdd36f10b22176e0433b86f74567d529aaa': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xe9ae261d3aff7d3fccf38fa2d612dd3897e07b2d': 2,\n },\n fantom: {\n '0x3c2269811836af69497e5f486a85d7316753cf62': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': 2,\n },\n 'fantom-testnet': {\n '0x0c3d09a7d86652f5599b836ce3db685a86513487': 1,\n '0x7669ac2bb50d567fd4bfb1cb5154b79c1e5e4a92': 2,\n '0xdafbd7a68e4ddcaa864c6a1171bd6030d0ca9a43': 2,\n '0x843986e31e0e3fea5eaf01086f36e7d85c458bb1': 2,\n },\n 'fantom-sandbox': {\n '0x54f51642779b9dbf48cc653c40499c82b8f261b3': 1,\n '0x01de566a13dc4be329351d930b0d9a569a495e46': 2,\n '0xf96093134adf151889ed72517979b2cd7144a831': 2,\n },\n 'avalanche-testnet': {\n '0xa7ac9fadbe9f51e7aa96751aa53f4cbb8a07b9ba': 1,\n '0x08c2e2b98d35973a4b2ca7ce8815cdb7c6f474f0': 2,\n '0x0a833b15305ce8b64946098db286710ace7bbe94': 2,\n '0xd81a1c5c52495a23f75d7269c17c73cebea61233': 2,\n },\n 'avalanche-sandbox': {\n '0x8953031e74a172586e89ddb40b7d269b9186e74c': 1,\n '0x4d7248986395d24ec777b16ca3fa32de64ec0330': 2,\n '0x4489a462f812d6dca0bde380ebdac12eb5a9e85a': 2,\n },\n 'polygon-testnet': {\n '0x2c7b02ffbc9602e8c04901609ef17cb1c4c2a7f7': 1,\n '0x3f6055024105d22b9400e025a1ca3259bd8b1893': 2,\n '0xcb97d107a87c5e172e075de94d7ef4498f6f06d2': 2,\n '0xd8b2de57ccfbbd5cd1713542cb6790fd2e33fed6': 2,\n },\n 'polygon-sandbox': {\n '0x369cc088dcedaaad27df0185c4f78caae42ff942': 1,\n '0x46f703c2a92874d5d526878a2ccc44e9431720a5': 2,\n '0xee404727abfca5d08a2480b0b881745f25362828': 2,\n },\n optimism: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': 2,\n },\n polygon: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': 2,\n },\n}\n","import { ethers } from 'ethers'\nimport invariant from 'tiny-invariant'\n\nimport { EVMUtilityVersion, NETWORKS, OutboundProofType } from './constants'\nimport { getReceiptProof as getReceiptProofV1 } from './mpt/v1'\nimport { getReceiptProof as getReceiptProofV2 } from './mpt/v2'\n\n/**\n * Generates a feather proof based on the utility version.\n *\n * @param {number} utilsVersion - The utility version.\n * @param {string} emitterAddress - The emitter address.\n * @param {string} packetPayload - The packet payload.\n * @returns {{ proof: string }} The generated proof.\n */\nexport function getFeatherProof(\n utilsVersion: number,\n emitterAddress: string,\n packetPayload: string\n): { proof: string } {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n const contractAddrByte32 = ethers.utils.hexZeroPad(emitterAddress, 32)\n return {\n proof: ethers.utils.solidityPack(['bytes32', 'bytes'], [contractAddrByte32, packetPayload]),\n }\n }\n case EVMUtilityVersion.V2: {\n return {\n proof: packetPayload,\n }\n }\n default:\n throw new Error(`Unknown utility version ${utilsVersion}`)\n }\n}\n\n/**\n * Retrieves the receipt proof based on the provided parameters.\n *\n * @param {string} network - The network name.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @param {number} outboundProofType - The outbound proof type.\n * @param {number} utilsVersion - The utility version.\n * @returns {Promise<object>} The receipt proof.\n */\nexport async function getReceiptProof(\n network,\n block,\n transactionReceipts,\n transactionIndex,\n outboundProofType,\n utilsVersion\n) {\n invariant(NETWORKS.includes(network), `Unsupported network: ${network}`)\n\n switch (outboundProofType) {\n case OutboundProofType.MPT: {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n return getReceiptProofV1(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V2:\n case EVMUtilityVersion.V4: {\n return getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V3: {\n const proof = await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n return {\n ...proof,\n blockHash: block.hash,\n }\n }\n default:\n throw new Error(`Unsupported utility version ${utilsVersion}`)\n }\n }\n default:\n throw new Error(`Unsupported Outbound Proof Type ${outboundProofType}`)\n }\n}\n\n/**\n * Encodes the parameters for the proof.\n *\n * @param {object} proof - The proof object.\n * @param {number} outboundProofType - The outbound proof type.\n * @param {number} utilsVersion - The utility version.\n * @param {number} logIndex - The log index.\n * @param {number} [srcEndpointId] - The source endpoint ID.\n * @returns {string} The encoded parameters.\n */\nexport function encodeParams(proof, outboundProofType, utilsVersion, logIndex, srcEndpointId?: number): string {\n switch (outboundProofType) {\n case OutboundProofType.MPT: {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes[]', 'uint256[]', 'uint256', 'uint256'],\n [srcEndpointId, proof.proof, proof.pointers, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V2: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes[]', 'uint256[]', 'uint256'],\n [srcEndpointId, proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V3: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes32', 'bytes[]', 'uint256[]', 'uint256'],\n [srcEndpointId, proof.blockHash, proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V4: {\n return ethers.utils.defaultAbiCoder.encode(\n ['bytes[]', 'uint256[]', 'uint256'],\n [proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n default:\n throw new Error(`Unsupported utility version ${utilsVersion}`)\n }\n }\n default:\n throw new Error(`Unsupported Outbound Proof Type ${outboundProofType}`)\n }\n}\n\n/**\n * Retrieves the LayerZero packet from the log data.\n *\n * @param {number} srcChainId - The source chain ID.\n * @param {object} _log - The log object.\n * @returns {object} The LayerZero packet.\n */\nexport function getLayerZeroPacket(srcChainId, _log) {\n //todo: what if src address differs from 20 bytes\n const packet = ethers.utils.defaultAbiCoder.decode(['uint16', 'bytes'], _log.data)\n const data = packet[1].slice(2)\n\n //todo: what if dst address differs from 20 bytes\n const dstChainId = parseInt(packet[0])\n const nonce = ethers.BigNumber.from('0x' + data.slice(0, 16)).toNumber()\n const srcAddress = '0x' + data.slice(16, 56)\n const dstAddress = '0x' + data.slice(56, 96)\n\n let payload = '0x'\n if (data.length > 96) {\n //has payload\n payload = '0x' + data.slice(96, data.length)\n }\n\n return {\n srcChainId,\n dstChainId,\n nonce,\n dstAddress,\n srcAddress,\n ulnAddress: ethers.utils.defaultAbiCoder.encode(['address'], [_log.address]),\n payload,\n }\n}\n","// getStateSyncTxHash returns block's tx hash for state-sync receipt\n// Bor blockchain includes extra receipt/tx for state-sync logs,\n// but it is not included in transactionRoot or receiptRoot.\n// So, while calculating proof, we have to exclude them.\n//\n// This is derived from block's hash and number\n// state-sync tx hash = keccak256(\"matic-bor-receipt-\" + block.number + block.hash)\nimport { Proof, Receipt } from 'eth-object'\nimport { encode, toBuffer } from 'eth-util-lite'\nimport { BigNumber, utils } from 'ethers'\nimport CheckpointTrie from 'merkle-patricia-tree'\nimport { promisfy } from 'promisfy'\nimport invariant from 'tiny-invariant'\n\n/**\n * Returns the transaction hash for the state-sync receipt in a Polygon block.\n *\n * @param {object} block - The block object.\n * @returns {string} The transaction hash for the state-sync receipt.\n */\nexport function getPolygonStateSyncTxHash(block): string {\n const prefix = Buffer.from('matic-bor-receipt-')\n const blockNumberBytes = utils.zeroPad(utils.arrayify(BigNumber.from(block.number)), 8)\n const blockHashBytes = utils.arrayify(block.hash)\n\n const hash = utils.keccak256(utils.concat([prefix, blockNumberBytes, blockHashBytes]))\n\n return hash\n}\n\n/**\n * Converts a buffer to a hex string.\n *\n * @param {Buffer} buffer - The buffer to convert.\n * @returns {string} The hex string.\n */\nexport function buffer2hex(buffer): string {\n return '0x' + buffer.toString('hex')\n}\n\n/**\n * Generates a receipt proof from the given network, block, transaction receipts, and transaction index.\n *\n * @param {string} network - The network name.\n * @param {object} block - The block object.\n * @param {object[]} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to an object containing the receipt proof and stack.\n * @throws {Error} If the receipt root from the RPC block does not match the receipt root built.\n */\nexport async function receiptProofFrom(network, block, transactionReceipts, transactionIndex) {\n // handle the polygon special receipt\n if (network === 'polygon') {\n const ignoredTxnHash = getPolygonStateSyncTxHash(block)\n transactionReceipts = transactionReceipts.filter((receipt) => receipt.transactionHash !== ignoredTxnHash)\n }\n\n const tree = new CheckpointTrie()\n await Promise.all(\n transactionReceipts.map((siblingReceipt, index) => {\n const siblingPath = encode(index)\n\n if (network === 'harmony' && index >= block.transactions.length) {\n // void staking receipt type, which works differently from EIP2718\n siblingReceipt.type = 0\n }\n\n let serializedReceipt = Receipt.fromRpc(siblingReceipt)\n\n //handles the arbitrum receipt\n if (network === 'arbitrum') {\n //todo: will not need this in aribtrum nitro\n serializedReceipt[0] = toBuffer(0)\n }\n serializedReceipt = serializedReceipt.serialize()\n\n // if type is defined, concat type and RLP buffer seperately (for receipts/transactions following EIP2718)\n if (siblingReceipt.type) {\n serializedReceipt = Buffer.concat([toBuffer(siblingReceipt.type), serializedReceipt])\n }\n\n return promisfy(tree.put, tree)(siblingPath, serializedReceipt)\n })\n )\n\n const [_, __, stack] = await promisfy(tree.findPath, tree)(encode(transactionIndex))\n\n // assert the tree root\n const receiptRootFromBlock = block.receiptsRoot.slice(2)\n invariant(\n receiptRootFromBlock === tree._root.toString('hex'),\n 'receiptRoot from rpc block != receipt root we built'\n )\n\n return {\n stack: stack,\n receiptProof: Proof.fromStack(stack),\n }\n}\n","import { rlp } from 'ethereumjs-util'\nimport { ethers } from 'ethers'\nimport { matchingNibbleLength, stringToNibbles } from 'merkle-patricia-tree/util/nibbles'\nimport invariant from 'tiny-invariant'\n\nimport { buffer2hex, receiptProofFrom } from './common'\n\n/**\n * Finds the pointer in the full bytes.\n *\n * @param {Buffer} fullBytes - The full bytes.\n * @param {Buffer} currentNodeElement - The current node element.\n * @returns {number} The pointer.\n */\nfunction findPointer(fullBytes, currentNodeElement): number {\n const fullBytesHex = fullBytes.toString('hex')\n const slicedBytesHex = currentNodeElement.toString('hex')\n const result = fullBytesHex.indexOf(slicedBytesHex)\n invariant(result >= 0, 'wrong index')\n return (result - 2) / 2\n}\n\n/*\nrunning MPT locally, strictly the same as solidity file\n */\n\n/**\n * Asserts the inclusion of a receipt in the MPT.\n *\n * @param {string} receiptsRoot - The root of the receipts.\n * @param {string} expectedLogValue - The expected log value.\n * @param {Array} rlpProof - The RLP encoded proof.\n * @param {Array} pointers - The pointers in the MPT.\n * @returns {boolean} True if the receipt is included, false otherwise.\n */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, pointers): boolean {\n let nextRoot = receiptsRoot\n const proofDepth = rlpProof.length\n let pointer\n let proofBytes\n for (let i = 0; i < proofDepth; i++) {\n proofBytes = rlpProof[i]\n if (nextRoot !== ethers.utils.keccak256(proofBytes)) return false\n // load 32 bytes from the proofBytes\n if (i < pointers.length) {\n pointer = 2 + pointers[i] * 2\n nextRoot = '0x' + proofBytes.substring(pointer, pointer + 64)\n }\n }\n return true\n}\n\n/**\n * Assembles a Merkle Patricia Tree (MPT) proof.\n *\n * @param {object} proof - The proof object.\n * @param {object} block - The block object.\n * @param {number} transactionIndex - The transaction index.\n * @returns {object} The assembled MPT proof.\n */\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const { stack } = proof\n\n // convert receipt Proof L2 nested contents into hex\n const rlpNestedProof = [...proof.receiptProof].map((node) => node.map((elem) => buffer2hex(elem)))\n const rlpProof = rlpNestedProof.map((node) => buffer2hex(rlp.encode(node)))\n\n // decimal of transaction index\n const receiptIndexDeci = ethers.BigNumber.from(transactionIndex).toNumber()\n const encodedMerklePath = stringToNibbles(rlp.encode(receiptIndexDeci)) // if index = 252, encoded = 81fc\n\n // prepare the data for offline traversal\n let hashRoot = block.receiptsRoot\n const proofDepth = stack.length\n // const targetReceipt = stack[proofDepth - 1].value;\n const targetReceipt = rlpNestedProof[rlpNestedProof.length - 1][1]\n let proofPathCounter = 0\n const totalPathLength = encodedMerklePath.length\n const pointers: number[] = []\n let receiptSlotIndex\n for (let i = 0; i < proofDepth; i++) {\n // assert the path depth constaints\n invariant(\n proofPathCounter <= totalPathLength,\n `proofPathCounter wrong at ${proofPathCounter}, where totalPathLength = ${totalPathLength}`\n )\n\n // thisNodeValue in array form, easier to retrieve data\n const thisNode = stack[i]\n const thisNodeValue = thisNode.raw\n // convert the elem first then hex again, it is == rlpNestedProof[i]\n const thisNodeRlp = rlpProof[i]\n invariant(\n ethers.utils.keccak256(thisNodeRlp) === hashRoot,\n `invalid hashlink at depth ${i} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n\n if (thisNode.type === 'branch') {\n // branch node\n if (proofPathCounter === totalPathLength) {\n // has reach the end, assert targetReceipt ==\n invariant(ethers.utils.keccak256(thisNodeValue[16]) === targetReceipt, 'invalid branch value node')\n receiptSlotIndex = 16\n } else {\n // a normal branch node, step down\n const nextNibble = encodedMerklePath[proofPathCounter]\n invariant(\n nextNibble <= 16,\n `invalid nibble at ${nextNibble} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n // hashRoot = buffer2hex(thisNode._branches[nextNibble])\n hashRoot = buffer2hex(thisNodeValue[nextNibble])\n proofPathCounter += 1\n // retrieve the pointer for the branch value\n pointers.push(findPointer(thisNodeRlp, thisNodeValue[nextNibble]))\n }\n } else if (thisNode.type === 'leaf' || thisNode.type === 'extention') {\n const progressKey = encodedMerklePath.slice(0, proofPathCounter)\n const keyRemainder = encodedMerklePath.slice(matchingNibbleLength(progressKey, encodedMerklePath))\n proofPathCounter += matchingNibbleLength(keyRemainder, stack[i].key)\n if (thisNode.type === 'leaf') {\n invariant(proofPathCounter === totalPathLength, 'invalid leaf node')\n invariant(\n ethers.utils.keccak256(thisNodeValue[1]) === ethers.utils.keccak256(targetReceipt),\n 'wrong leaf value'\n )\n receiptSlotIndex = 1\n } else if (thisNode.type === 'extention') {\n hashRoot = buffer2hex(thisNodeValue[1])\n // retrieve the pointer for the leaf node\n pointers.push(findPointer(thisNodeRlp, thisNodeValue[1]))\n }\n } else {\n throw `unsupported node type in MPT ${thisNode} ${encodedMerklePath}`\n }\n }\n\n invariant(assertReceiptInclusion(block.receiptsRoot, targetReceipt, rlpProof, pointers), 'MPTLite local fails')\n\n return {\n receiptRoot: block.receiptsRoot,\n proof: rlpProof,\n pointers: pointers,\n receiptSlotIndex: receiptSlotIndex,\n }\n}\n\n/**\n * Retrieves the receipt proof.\n *\n * @param {string} network - The network.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to the receipt proof.\n */\nexport async function getReceiptProof(network, block, transactionReceipts, transactionIndex) {\n const proof = await receiptProofFrom(network, block, transactionReceipts, transactionIndex)\n return assembleMPTProof(proof, block, transactionIndex)\n}\n","import { rlp } from 'ethereumjs-util'\nimport { ethers } from 'ethers'\nimport { matchingNibbleLength, stringToNibbles } from 'merkle-patricia-tree/util/nibbles'\nimport invariant from 'tiny-invariant'\n\nimport { buffer2hex, receiptProofFrom } from './common'\n\n/**\n * Assembles a Merkle Patricia Tree (MPT) proof.\n *\n * @param {object} proof - The proof object.\n * @param {object} block - The block object.\n * @param {number} transactionIndex - The transaction index.\n * @returns {object} The assembled MPT proof.\n */\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const { stack } = proof\n\n // convert receipt Proof L2 nested contents into hex\n const rlpNestedProof = [...proof.receiptProof].map((node) => node.map((elem) => buffer2hex(elem)))\n const rlpProof = rlpNestedProof.map((node) => buffer2hex(rlp.encode(node)))\n\n // decimal of transaction index\n const receiptIndexDeci = ethers.BigNumber.from(transactionIndex).toNumber()\n const encodedMerklePath = stringToNibbles(rlp.encode(receiptIndexDeci)) // if index = 252, encoded = 81fc\n\n // prepare the data for offline traversal\n let hashRoot = block.receiptsRoot\n const proofDepth = stack.length\n // const targetReceipt = stack[proofDepth - 1].value;\n const targetReceipt = rlpNestedProof[rlpNestedProof.length - 1][1]\n let proofPathCounter = 0\n const totalPathLength = encodedMerklePath.length\n const path: number[] = []\n for (let i = 0; i < proofDepth; i++) {\n // console.log(`hashroot at ${i} : ${hashRoot}`)\n // console.log(` rlpProof at ${rlpProof[i]}`)\n\n // assert the path depth constraints\n invariant(\n proofPathCounter <= totalPathLength,\n `proofPathCounter wrong at ${proofPathCounter}, where totalPathLength = ${totalPathLength}`\n )\n\n // thisNodeValue in array form, easier to retrieve data\n const thisNode = stack[i]\n const thisNodeValue = thisNode.raw\n // convert the elem first then hex again, it is == rlpNestedProof[i]\n const thisNodeRlp = rlpProof[i]\n invariant(\n ethers.utils.keccak256(thisNodeRlp) === hashRoot,\n `invalid hashlink at depth ${i} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n\n if (thisNode.type === 'branch') {\n // branch node\n if (proofPathCounter === totalPathLength) {\n // has reach the end, assert targetReceipt ==\n invariant(ethers.utils.keccak256(thisNodeValue[16]) === targetReceipt, 'invalid branch value node')\n path[i] = 16\n console.warn(`a branch node 16 value type ${transactionIndex} receipt root ${block.receiptsRoot}`)\n } else {\n // a normal branch node, step down\n const nextNibble = encodedMerklePath[proofPathCounter]\n invariant(\n nextNibble <= 16,\n `invalid nibble at ${nextNibble} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n // hashRoot = buffer2hex(thisNode._branches[nextNibble])\n hashRoot = buffer2hex(thisNodeValue[nextNibble])\n proofPathCounter += 1\n // retrieve the pointer for the branch value\n path[i] = nextNibble\n }\n } else if (thisNode.type === 'leaf' || thisNode.type === 'extention') {\n const progressKey = encodedMerklePath.slice(0, proofPathCounter)\n const keyRemainder = encodedMerklePath.slice(matchingNibbleLength(progressKey, encodedMerklePath))\n proofPathCounter += matchingNibbleLength(keyRemainder, stack[i].key)\n if (thisNode.type === 'leaf') {\n invariant(proofPathCounter === totalPathLength, 'invalid leaf node')\n invariant(\n ethers.utils.keccak256(thisNodeValue[1]) === ethers.utils.keccak256(targetReceipt),\n 'wrong leaf value'\n )\n path[i] = 1\n } else if (thisNode.type === 'extention') {\n path[i] = 1\n hashRoot = buffer2hex(thisNodeValue[1])\n // retrieve the pointer for the leaf node\n }\n } else {\n throw `unsupported node type in MPT ${thisNode} ${encodedMerklePath}`\n }\n }\n\n invariant(assertReceiptInclusion(block.receiptsRoot, targetReceipt, rlpProof, path, stack), 'MPTLite local fails')\n\n return {\n receiptRoot: block.receiptsRoot,\n proof: rlpProof,\n receiptSlotIndex: path,\n }\n}\n\n/*\nrunning MPT locally, strictly the same as solidity file\n */\n\n/**\n * Asserts the inclusion of a receipt in the MPT.\n *\n * @param {string} receiptsRoot - The root of the receipts.\n * @param {string} expectedLogValue - The expected log value.\n * @param {Array} rlpProof - The RLP encoded proof.\n * @param {Array} path - The path in the MPT.\n * @param {Array} stack - The stack of nodes.\n * @returns {boolean} True if the receipt is included, false otherwise.\n */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, path, stack): boolean {\n let nextRoot = receiptsRoot\n const proofDepth = rlpProof.length\n for (let i = 0; i < proofDepth; i++) {\n const proofBytes = rlpProof[i]\n const thisNodeValue = stack[i].raw\n if (nextRoot !== ethers.utils.keccak256(proofBytes)) return false\n if (i < proofDepth - 1) {\n nextRoot = buffer2hex(thisNodeValue[path[i]])\n }\n }\n return true\n}\n\n/**\n * Retrieves the receipt proof.\n *\n * @param {string} network - The network.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to the receipt proof.\n */\nexport async function getReceiptProof(network, block, transactionReceipts, transactionIndex) {\n const proof = await receiptProofFrom(network, block, transactionReceipts, transactionIndex)\n return assembleMPTProof(proof, block, transactionIndex)\n}\n"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -117,7 +117,7 @@ declare const UTILS_VERSION_LOOKUP: {
|
|
|
117
117
|
* @param {string} packetPayload - The packet payload.
|
|
118
118
|
* @returns {{ proof: string }} The generated proof.
|
|
119
119
|
*/
|
|
120
|
-
declare function getFeatherProof(utilsVersion:
|
|
120
|
+
declare function getFeatherProof(utilsVersion: number, emitterAddress: string, packetPayload: string): {
|
|
121
121
|
proof: string;
|
|
122
122
|
};
|
|
123
123
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -117,7 +117,7 @@ declare const UTILS_VERSION_LOOKUP: {
|
|
|
117
117
|
* @param {string} packetPayload - The packet payload.
|
|
118
118
|
* @returns {{ proof: string }} The generated proof.
|
|
119
119
|
*/
|
|
120
|
-
declare function getFeatherProof(utilsVersion:
|
|
120
|
+
declare function getFeatherProof(utilsVersion: number, emitterAddress: string, packetPayload: string): {
|
|
121
121
|
proof: string;
|
|
122
122
|
};
|
|
123
123
|
/**
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/proof.ts","../src/mpt/common.ts","../src/mpt/v1.ts","../src/mpt/v2.ts"],"names":["getReceiptProof","invariant","assembleMPTProof","rlp","ethers","stringToNibbles","matchingNibbleLength","assertReceiptInclusion"],"mappings":";;;;;;;;;;;;;;;;AAGO,IAAM,WAAW,CAAC,SAAA,EAAW,SAAW,EAAA,UAAA,EAAY,WAAW,SAAS;AAKxE,IAAM,iBAAoB,GAAA;AAAA;AAAA;AAAA;AAAA,EAI7B,GAAK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AAO,IAAK,CAAA,KAAA,CAAM,IAAI,EAAE,CAAA;AAC3C,EAAA,MAAM,UAAa,GAAA,IAAA,GAAO,IAAK,CAAA,KAAA,CAAM,IAAI,EAAE,CAAA;AAE3C,EAAA,IAAI,OAAU,GAAA,IAAA;AACd,EAAI,IAAA,IAAA,CAAK,SAAS,EAAI,EAAA;AAElB,IAAA,OAAA,GAAU,IAAO,GAAA,IAAA,CAAK,KAAM,CAAA,EAAA,EAAI,KAAK,MAAM,CAAA;AAAA;AAG/C,EAAO,OAAA;AAAA,IACH,UAAA;AAAA,IACA,UAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA,EAAYA,MAAO,CAAA,KAAA,CAAM,eAAgB,CAAA,MAAA,CAAO,CAAC,SAAS,CAAG,EAAA,CAAC,IAAK,CAAA,OAAO,CAAC,CAAA;AAAA,IAC3E;AAAA,GACJ;AACJ","file":"index.mjs","sourcesContent":["/**\n * Supported networks.\n */\nexport const NETWORKS = ['default', 'hardhat', 'arbitrum', 'polygon', 'harmony']\n\n/**\n * Enum representing outbound proof types.\n */\nexport const OutboundProofType = {\n /**\n * Merkle Patricia Trie proof type.\n */\n MPT: 1,\n /**\n * Feather proof type.\n */\n FP: 2,\n}\n\n/**\n * Enum representing EVM utility versions.\n */\nexport const EVMUtilityVersion = {\n V1: 1,\n V2: 2,\n V3: 3,\n V4: 4,\n}\n\n/**\n * Lookup table for utility versions by network and address.\n */\nexport const UTILS_VERSION_LOOKUP = {\n arbitrum: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': 2,\n },\n avalanche: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xcbd35a9b849342ad34a71e072d9947d4afb4e164': 2,\n },\n bsc: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xcff08a35a5f27f306e2da99ff198db90f13def77': 2,\n },\n 'bsc-testnet': {\n '0xfc256f1007e67abbd027536818142823b4596a24': 1,\n '0x1de92e6b8e8b6b150ea8588fe387a4f5fb4da778': 2,\n '0x76860669184330e6966a61188cfbd13486c7a6a6': 2,\n '0x4652b61781f5ee79dad354ab5d249aa2b99b4def': 2,\n },\n 'bsc-sandbox': {\n '0xf96093134adf151889ed72517979b2cd7144a831': 1,\n '0x1751181f9af72b37934006bbe989238498067563': 2,\n '0x8953031e74a172586e89ddb40b7d269b9186e74c': 2,\n },\n ethereum: {\n '0x2d61dcdd36f10b22176e0433b86f74567d529aaa': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xe9ae261d3aff7d3fccf38fa2d612dd3897e07b2d': 2,\n },\n fantom: {\n '0x3c2269811836af69497e5f486a85d7316753cf62': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': 2,\n },\n 'fantom-testnet': {\n '0x0c3d09a7d86652f5599b836ce3db685a86513487': 1,\n '0x7669ac2bb50d567fd4bfb1cb5154b79c1e5e4a92': 2,\n '0xdafbd7a68e4ddcaa864c6a1171bd6030d0ca9a43': 2,\n '0x843986e31e0e3fea5eaf01086f36e7d85c458bb1': 2,\n },\n 'fantom-sandbox': {\n '0x54f51642779b9dbf48cc653c40499c82b8f261b3': 1,\n '0x01de566a13dc4be329351d930b0d9a569a495e46': 2,\n '0xf96093134adf151889ed72517979b2cd7144a831': 2,\n },\n 'avalanche-testnet': {\n '0xa7ac9fadbe9f51e7aa96751aa53f4cbb8a07b9ba': 1,\n '0x08c2e2b98d35973a4b2ca7ce8815cdb7c6f474f0': 2,\n '0x0a833b15305ce8b64946098db286710ace7bbe94': 2,\n '0xd81a1c5c52495a23f75d7269c17c73cebea61233': 2,\n },\n 'avalanche-sandbox': {\n '0x8953031e74a172586e89ddb40b7d269b9186e74c': 1,\n '0x4d7248986395d24ec777b16ca3fa32de64ec0330': 2,\n '0x4489a462f812d6dca0bde380ebdac12eb5a9e85a': 2,\n },\n 'polygon-testnet': {\n '0x2c7b02ffbc9602e8c04901609ef17cb1c4c2a7f7': 1,\n '0x3f6055024105d22b9400e025a1ca3259bd8b1893': 2,\n '0xcb97d107a87c5e172e075de94d7ef4498f6f06d2': 2,\n '0xd8b2de57ccfbbd5cd1713542cb6790fd2e33fed6': 2,\n },\n 'polygon-sandbox': {\n '0x369cc088dcedaaad27df0185c4f78caae42ff942': 1,\n '0x46f703c2a92874d5d526878a2ccc44e9431720a5': 2,\n '0xee404727abfca5d08a2480b0b881745f25362828': 2,\n },\n optimism: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': 2,\n },\n polygon: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': 2,\n },\n}\n","import { ethers } from 'ethers'\nimport invariant from 'tiny-invariant'\n\nimport { EVMUtilityVersion, NETWORKS, OutboundProofType } from './constants'\nimport { getReceiptProof as getReceiptProofV1 } from './mpt/v1'\nimport { getReceiptProof as getReceiptProofV2 } from './mpt/v2'\n\n/**\n * Generates a feather proof based on the utility version.\n *\n * @param {number} utilsVersion - The utility version.\n * @param {string} emitterAddress - The emitter address.\n * @param {string} packetPayload - The packet payload.\n * @returns {{ proof: string }} The generated proof.\n */\nexport function getFeatherProof(utilsVersion, emitterAddress, packetPayload): { proof: string } {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n const contractAddrByte32 = ethers.utils.hexZeroPad(emitterAddress, 32)\n return {\n proof: ethers.utils.solidityPack(['bytes32', 'bytes'], [contractAddrByte32, packetPayload]),\n }\n }\n case EVMUtilityVersion.V2: {\n return {\n proof: packetPayload,\n }\n }\n default:\n throw new Error(`Unknown utility version ${utilsVersion}`)\n }\n}\n\n/**\n * Retrieves the receipt proof based on the provided parameters.\n *\n * @param {string} network - The network name.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @param {number} outboundProofType - The outbound proof type.\n * @param {number} utilsVersion - The utility version.\n * @returns {Promise<object>} The receipt proof.\n */\nexport async function getReceiptProof(\n network,\n block,\n transactionReceipts,\n transactionIndex,\n outboundProofType,\n utilsVersion\n) {\n invariant(NETWORKS.includes(network), `Unsupported network: ${network}`)\n\n switch (outboundProofType) {\n case OutboundProofType.MPT: {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n return getReceiptProofV1(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V2:\n case EVMUtilityVersion.V4: {\n return getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V3: {\n const proof = await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n return {\n ...proof,\n blockHash: block.hash,\n }\n }\n default:\n throw new Error(`Unsupported utility version ${utilsVersion}`)\n }\n }\n default:\n throw new Error(`Unsupported Outbound Proof Type ${outboundProofType}`)\n }\n}\n\n/**\n * Encodes the parameters for the proof.\n *\n * @param {object} proof - The proof object.\n * @param {number} outboundProofType - The outbound proof type.\n * @param {number} utilsVersion - The utility version.\n * @param {number} logIndex - The log index.\n * @param {number} [srcEndpointId] - The source endpoint ID.\n * @returns {string} The encoded parameters.\n */\nexport function encodeParams(proof, outboundProofType, utilsVersion, logIndex, srcEndpointId?: number): string {\n switch (outboundProofType) {\n case OutboundProofType.MPT: {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes[]', 'uint256[]', 'uint256', 'uint256'],\n [srcEndpointId, proof.proof, proof.pointers, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V2: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes[]', 'uint256[]', 'uint256'],\n [srcEndpointId, proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V3: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes32', 'bytes[]', 'uint256[]', 'uint256'],\n [srcEndpointId, proof.blockHash, proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V4: {\n return ethers.utils.defaultAbiCoder.encode(\n ['bytes[]', 'uint256[]', 'uint256'],\n [proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n default:\n throw new Error(`Unsupported utility version ${utilsVersion}`)\n }\n }\n default:\n throw new Error(`Unsupported Outbound Proof Type ${outboundProofType}`)\n }\n}\n\n/**\n * Retrieves the LayerZero packet from the log data.\n *\n * @param {number} srcChainId - The source chain ID.\n * @param {object} _log - The log object.\n * @returns {object} The LayerZero packet.\n */\nexport function getLayerZeroPacket(srcChainId, _log) {\n //todo: what if src address differs from 20 bytes\n const packet = ethers.utils.defaultAbiCoder.decode(['uint16', 'bytes'], _log.data)\n const data = packet[1].slice(2)\n\n //todo: what if dst address differs from 20 bytes\n const dstChainId = parseInt(packet[0])\n const nonce = ethers.BigNumber.from('0x' + data.slice(0, 16)).toNumber()\n const srcAddress = '0x' + data.slice(16, 56)\n const dstAddress = '0x' + data.slice(56, 96)\n\n let payload = '0x'\n if (data.length > 96) {\n //has payload\n payload = '0x' + data.slice(96, data.length)\n }\n\n return {\n srcChainId,\n dstChainId,\n nonce,\n dstAddress,\n srcAddress,\n ulnAddress: ethers.utils.defaultAbiCoder.encode(['address'], [_log.address]),\n payload,\n }\n}\n","// getStateSyncTxHash returns block's tx hash for state-sync receipt\n// Bor blockchain includes extra receipt/tx for state-sync logs,\n// but it is not included in transactionRoot or receiptRoot.\n// So, while calculating proof, we have to exclude them.\n//\n// This is derived from block's hash and number\n// state-sync tx hash = keccak256(\"matic-bor-receipt-\" + block.number + block.hash)\nimport { Proof, Receipt } from 'eth-object'\nimport { encode, toBuffer } from 'eth-util-lite'\nimport { BigNumber, utils } from 'ethers'\nimport CheckpointTrie from 'merkle-patricia-tree'\nimport { promisfy } from 'promisfy'\nimport invariant from 'tiny-invariant'\n\n/**\n * Returns the transaction hash for the state-sync receipt in a Polygon block.\n *\n * @param {object} block - The block object.\n * @returns {string} The transaction hash for the state-sync receipt.\n */\nexport function getPolygonStateSyncTxHash(block): string {\n const prefix = Buffer.from('matic-bor-receipt-')\n const blockNumberBytes = utils.zeroPad(utils.arrayify(BigNumber.from(block.number)), 8)\n const blockHashBytes = utils.arrayify(block.hash)\n\n const hash = utils.keccak256(utils.concat([prefix, blockNumberBytes, blockHashBytes]))\n\n return hash\n}\n\n/**\n * Converts a buffer to a hex string.\n *\n * @param {Buffer} buffer - The buffer to convert.\n * @returns {string} The hex string.\n */\nexport function buffer2hex(buffer): string {\n return '0x' + buffer.toString('hex')\n}\n\n/**\n * Generates a receipt proof from the given network, block, transaction receipts, and transaction index.\n *\n * @param {string} network - The network name.\n * @param {object} block - The block object.\n * @param {object[]} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to an object containing the receipt proof and stack.\n * @throws {Error} If the receipt root from the RPC block does not match the receipt root built.\n */\nexport async function receiptProofFrom(network, block, transactionReceipts, transactionIndex) {\n // handle the polygon special receipt\n if (network === 'polygon') {\n const ignoredTxnHash = getPolygonStateSyncTxHash(block)\n transactionReceipts = transactionReceipts.filter((receipt) => receipt.transactionHash !== ignoredTxnHash)\n }\n\n const tree = new CheckpointTrie()\n await Promise.all(\n transactionReceipts.map((siblingReceipt, index) => {\n const siblingPath = encode(index)\n\n if (network === 'harmony' && index >= block.transactions.length) {\n // void staking receipt type, which works differently from EIP2718\n siblingReceipt.type = 0\n }\n\n let serializedReceipt = Receipt.fromRpc(siblingReceipt)\n\n //handles the arbitrum receipt\n if (network === 'arbitrum') {\n //todo: will not need this in aribtrum nitro\n serializedReceipt[0] = toBuffer(0)\n }\n serializedReceipt = serializedReceipt.serialize()\n\n // if type is defined, concat type and RLP buffer seperately (for receipts/transactions following EIP2718)\n if (siblingReceipt.type) {\n serializedReceipt = Buffer.concat([toBuffer(siblingReceipt.type), serializedReceipt])\n }\n\n return promisfy(tree.put, tree)(siblingPath, serializedReceipt)\n })\n )\n\n const [_, __, stack] = await promisfy(tree.findPath, tree)(encode(transactionIndex))\n\n // assert the tree root\n const receiptRootFromBlock = block.receiptsRoot.slice(2)\n invariant(\n receiptRootFromBlock === tree._root.toString('hex'),\n 'receiptRoot from rpc block != receipt root we built'\n )\n\n return {\n stack: stack,\n receiptProof: Proof.fromStack(stack),\n }\n}\n","import { rlp } from 'ethereumjs-util'\nimport { ethers } from 'ethers'\nimport { matchingNibbleLength, stringToNibbles } from 'merkle-patricia-tree/util/nibbles'\nimport invariant from 'tiny-invariant'\n\nimport { buffer2hex, receiptProofFrom } from './common'\n\n/**\n * Finds the pointer in the full bytes.\n *\n * @param {Buffer} fullBytes - The full bytes.\n * @param {Buffer} currentNodeElement - The current node element.\n * @returns {number} The pointer.\n */\nfunction findPointer(fullBytes, currentNodeElement): number {\n const fullBytesHex = fullBytes.toString('hex')\n const slicedBytesHex = currentNodeElement.toString('hex')\n const result = fullBytesHex.indexOf(slicedBytesHex)\n invariant(result >= 0, 'wrong index')\n return (result - 2) / 2\n}\n\n/*\nrunning MPT locally, strictly the same as solidity file\n */\n\n/**\n * Asserts the inclusion of a receipt in the MPT.\n *\n * @param {string} receiptsRoot - The root of the receipts.\n * @param {string} expectedLogValue - The expected log value.\n * @param {Array} rlpProof - The RLP encoded proof.\n * @param {Array} pointers - The pointers in the MPT.\n * @returns {boolean} True if the receipt is included, false otherwise.\n */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, pointers): boolean {\n let nextRoot = receiptsRoot\n const proofDepth = rlpProof.length\n let pointer\n let proofBytes\n for (let i = 0; i < proofDepth; i++) {\n proofBytes = rlpProof[i]\n if (nextRoot !== ethers.utils.keccak256(proofBytes)) return false\n // load 32 bytes from the proofBytes\n if (i < pointers.length) {\n pointer = 2 + pointers[i] * 2\n nextRoot = '0x' + proofBytes.substring(pointer, pointer + 64)\n }\n }\n return true\n}\n\n/**\n * Assembles a Merkle Patricia Tree (MPT) proof.\n *\n * @param {object} proof - The proof object.\n * @param {object} block - The block object.\n * @param {number} transactionIndex - The transaction index.\n * @returns {object} The assembled MPT proof.\n */\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const { stack } = proof\n\n // convert receipt Proof L2 nested contents into hex\n const rlpNestedProof = [...proof.receiptProof].map((node) => node.map((elem) => buffer2hex(elem)))\n const rlpProof = rlpNestedProof.map((node) => buffer2hex(rlp.encode(node)))\n\n // decimal of transaction index\n const receiptIndexDeci = ethers.BigNumber.from(transactionIndex).toNumber()\n const encodedMerklePath = stringToNibbles(rlp.encode(receiptIndexDeci)) // if index = 252, encoded = 81fc\n\n // prepare the data for offline traversal\n let hashRoot = block.receiptsRoot\n const proofDepth = stack.length\n // const targetReceipt = stack[proofDepth - 1].value;\n const targetReceipt = rlpNestedProof[rlpNestedProof.length - 1][1]\n let proofPathCounter = 0\n const totalPathLength = encodedMerklePath.length\n const pointers: number[] = []\n let receiptSlotIndex\n for (let i = 0; i < proofDepth; i++) {\n // assert the path depth constaints\n invariant(\n proofPathCounter <= totalPathLength,\n `proofPathCounter wrong at ${proofPathCounter}, where totalPathLength = ${totalPathLength}`\n )\n\n // thisNodeValue in array form, easier to retrieve data\n const thisNode = stack[i]\n const thisNodeValue = thisNode.raw\n // convert the elem first then hex again, it is == rlpNestedProof[i]\n const thisNodeRlp = rlpProof[i]\n invariant(\n ethers.utils.keccak256(thisNodeRlp) === hashRoot,\n `invalid hashlink at depth ${i} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n\n if (thisNode.type === 'branch') {\n // branch node\n if (proofPathCounter === totalPathLength) {\n // has reach the end, assert targetReceipt ==\n invariant(ethers.utils.keccak256(thisNodeValue[16]) === targetReceipt, 'invalid branch value node')\n receiptSlotIndex = 16\n } else {\n // a normal branch node, step down\n const nextNibble = encodedMerklePath[proofPathCounter]\n invariant(\n nextNibble <= 16,\n `invalid nibble at ${nextNibble} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n // hashRoot = buffer2hex(thisNode._branches[nextNibble])\n hashRoot = buffer2hex(thisNodeValue[nextNibble])\n proofPathCounter += 1\n // retrieve the pointer for the branch value\n pointers.push(findPointer(thisNodeRlp, thisNodeValue[nextNibble]))\n }\n } else if (thisNode.type === 'leaf' || thisNode.type === 'extention') {\n const progressKey = encodedMerklePath.slice(0, proofPathCounter)\n const keyRemainder = encodedMerklePath.slice(matchingNibbleLength(progressKey, encodedMerklePath))\n proofPathCounter += matchingNibbleLength(keyRemainder, stack[i].key)\n if (thisNode.type === 'leaf') {\n invariant(proofPathCounter === totalPathLength, 'invalid leaf node')\n invariant(\n ethers.utils.keccak256(thisNodeValue[1]) === ethers.utils.keccak256(targetReceipt),\n 'wrong leaf value'\n )\n receiptSlotIndex = 1\n } else if (thisNode.type === 'extention') {\n hashRoot = buffer2hex(thisNodeValue[1])\n // retrieve the pointer for the leaf node\n pointers.push(findPointer(thisNodeRlp, thisNodeValue[1]))\n }\n } else {\n throw `unsupported node type in MPT ${thisNode} ${encodedMerklePath}`\n }\n }\n\n invariant(assertReceiptInclusion(block.receiptsRoot, targetReceipt, rlpProof, pointers), 'MPTLite local fails')\n\n return {\n receiptRoot: block.receiptsRoot,\n proof: rlpProof,\n pointers: pointers,\n receiptSlotIndex: receiptSlotIndex,\n }\n}\n\n/**\n * Retrieves the receipt proof.\n *\n * @param {string} network - The network.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to the receipt proof.\n */\nexport async function getReceiptProof(network, block, transactionReceipts, transactionIndex) {\n const proof = await receiptProofFrom(network, block, transactionReceipts, transactionIndex)\n return assembleMPTProof(proof, block, transactionIndex)\n}\n","import { rlp } from 'ethereumjs-util'\nimport { ethers } from 'ethers'\nimport { matchingNibbleLength, stringToNibbles } from 'merkle-patricia-tree/util/nibbles'\nimport invariant from 'tiny-invariant'\n\nimport { buffer2hex, receiptProofFrom } from './common'\n\n/**\n * Assembles a Merkle Patricia Tree (MPT) proof.\n *\n * @param {object} proof - The proof object.\n * @param {object} block - The block object.\n * @param {number} transactionIndex - The transaction index.\n * @returns {object} The assembled MPT proof.\n */\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const { stack } = proof\n\n // convert receipt Proof L2 nested contents into hex\n const rlpNestedProof = [...proof.receiptProof].map((node) => node.map((elem) => buffer2hex(elem)))\n const rlpProof = rlpNestedProof.map((node) => buffer2hex(rlp.encode(node)))\n\n // decimal of transaction index\n const receiptIndexDeci = ethers.BigNumber.from(transactionIndex).toNumber()\n const encodedMerklePath = stringToNibbles(rlp.encode(receiptIndexDeci)) // if index = 252, encoded = 81fc\n\n // prepare the data for offline traversal\n let hashRoot = block.receiptsRoot\n const proofDepth = stack.length\n // const targetReceipt = stack[proofDepth - 1].value;\n const targetReceipt = rlpNestedProof[rlpNestedProof.length - 1][1]\n let proofPathCounter = 0\n const totalPathLength = encodedMerklePath.length\n const path: number[] = []\n for (let i = 0; i < proofDepth; i++) {\n // console.log(`hashroot at ${i} : ${hashRoot}`)\n // console.log(` rlpProof at ${rlpProof[i]}`)\n\n // assert the path depth constraints\n invariant(\n proofPathCounter <= totalPathLength,\n `proofPathCounter wrong at ${proofPathCounter}, where totalPathLength = ${totalPathLength}`\n )\n\n // thisNodeValue in array form, easier to retrieve data\n const thisNode = stack[i]\n const thisNodeValue = thisNode.raw\n // convert the elem first then hex again, it is == rlpNestedProof[i]\n const thisNodeRlp = rlpProof[i]\n invariant(\n ethers.utils.keccak256(thisNodeRlp) === hashRoot,\n `invalid hashlink at depth ${i} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n\n if (thisNode.type === 'branch') {\n // branch node\n if (proofPathCounter === totalPathLength) {\n // has reach the end, assert targetReceipt ==\n invariant(ethers.utils.keccak256(thisNodeValue[16]) === targetReceipt, 'invalid branch value node')\n path[i] = 16\n console.warn(`a branch node 16 value type ${transactionIndex} receipt root ${block.receiptsRoot}`)\n } else {\n // a normal branch node, step down\n const nextNibble = encodedMerklePath[proofPathCounter]\n invariant(\n nextNibble <= 16,\n `invalid nibble at ${nextNibble} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n // hashRoot = buffer2hex(thisNode._branches[nextNibble])\n hashRoot = buffer2hex(thisNodeValue[nextNibble])\n proofPathCounter += 1\n // retrieve the pointer for the branch value\n path[i] = nextNibble\n }\n } else if (thisNode.type === 'leaf' || thisNode.type === 'extention') {\n const progressKey = encodedMerklePath.slice(0, proofPathCounter)\n const keyRemainder = encodedMerklePath.slice(matchingNibbleLength(progressKey, encodedMerklePath))\n proofPathCounter += matchingNibbleLength(keyRemainder, stack[i].key)\n if (thisNode.type === 'leaf') {\n invariant(proofPathCounter === totalPathLength, 'invalid leaf node')\n invariant(\n ethers.utils.keccak256(thisNodeValue[1]) === ethers.utils.keccak256(targetReceipt),\n 'wrong leaf value'\n )\n path[i] = 1\n } else if (thisNode.type === 'extention') {\n path[i] = 1\n hashRoot = buffer2hex(thisNodeValue[1])\n // retrieve the pointer for the leaf node\n }\n } else {\n throw `unsupported node type in MPT ${thisNode} ${encodedMerklePath}`\n }\n }\n\n invariant(assertReceiptInclusion(block.receiptsRoot, targetReceipt, rlpProof, path, stack), 'MPTLite local fails')\n\n return {\n receiptRoot: block.receiptsRoot,\n proof: rlpProof,\n receiptSlotIndex: path,\n }\n}\n\n/*\nrunning MPT locally, strictly the same as solidity file\n */\n\n/**\n * Asserts the inclusion of a receipt in the MPT.\n *\n * @param {string} receiptsRoot - The root of the receipts.\n * @param {string} expectedLogValue - The expected log value.\n * @param {Array} rlpProof - The RLP encoded proof.\n * @param {Array} path - The path in the MPT.\n * @param {Array} stack - The stack of nodes.\n * @returns {boolean} True if the receipt is included, false otherwise.\n */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, path, stack): boolean {\n let nextRoot = receiptsRoot\n const proofDepth = rlpProof.length\n for (let i = 0; i < proofDepth; i++) {\n const proofBytes = rlpProof[i]\n const thisNodeValue = stack[i].raw\n if (nextRoot !== ethers.utils.keccak256(proofBytes)) return false\n if (i < proofDepth - 1) {\n nextRoot = buffer2hex(thisNodeValue[path[i]])\n }\n }\n return true\n}\n\n/**\n * Retrieves the receipt proof.\n *\n * @param {string} network - The network.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to the receipt proof.\n */\nexport async function getReceiptProof(network, block, transactionReceipts, transactionIndex) {\n const proof = await receiptProofFrom(network, block, transactionReceipts, transactionIndex)\n return assembleMPTProof(proof, block, transactionIndex)\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/proof.ts","../src/mpt/common.ts","../src/mpt/v1.ts","../src/mpt/v2.ts"],"names":["getReceiptProof","invariant","assembleMPTProof","rlp","ethers","stringToNibbles","matchingNibbleLength","assertReceiptInclusion"],"mappings":";;;;;;;;;;;;;;;;AAGO,IAAM,WAAW,CAAC,SAAA,EAAW,SAAW,EAAA,UAAA,EAAY,WAAW,SAAS;AAKxE,IAAM,iBAAoB,GAAA;AAAA;AAAA;AAAA;AAAA,EAI7B,GAAK,EAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAIL,EAAI,EAAA;AACR;AAKO,IAAM,iBAAoB,GAAA;AAAA,EAC7B,EAAI,EAAA,CAAA;AAAA,EACJ,EAAI,EAAA,CAAA;AAAA,EACJ,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A;AACd,EAAI,IAAA,IAAA,CAAK,SAAS,EAAI,EAAA;AAElB,IAAA,OAAA,GAAU,IAAO,GAAA,IAAA,CAAK,KAAM,CAAA,EAAA,EAAI,KAAK,MAAM,CAAA;AAAA;AAG/C,EAAO,OAAA;AAAA,IACH,UAAA;AAAA,IACA,UAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA,EAAYA,MAAO,CAAA,KAAA,CAAM,eAAgB,CAAA,MAAA,CAAO,CAAC,SAAS,CAAG,EAAA,CAAC,IAAK,CAAA,OAAO,CAAC,CAAA;AAAA,IAC3E;AAAA,GACJ;AACJ","file":"index.mjs","sourcesContent":["/**\n * Supported networks.\n */\nexport const NETWORKS = ['default', 'hardhat', 'arbitrum', 'polygon', 'harmony']\n\n/**\n * Enum representing outbound proof types.\n */\nexport const OutboundProofType = {\n /**\n * Merkle Patricia Trie proof type.\n */\n MPT: 1,\n /**\n * Feather proof type.\n */\n FP: 2,\n}\n\n/**\n * Enum representing EVM utility versions.\n */\nexport const EVMUtilityVersion = {\n V1: 1,\n V2: 2,\n V3: 3,\n V4: 4,\n}\n\n/**\n * Lookup table for utility versions by network and address.\n */\nexport const UTILS_VERSION_LOOKUP = {\n arbitrum: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': 2,\n },\n avalanche: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xcbd35a9b849342ad34a71e072d9947d4afb4e164': 2,\n },\n bsc: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xcff08a35a5f27f306e2da99ff198db90f13def77': 2,\n },\n 'bsc-testnet': {\n '0xfc256f1007e67abbd027536818142823b4596a24': 1,\n '0x1de92e6b8e8b6b150ea8588fe387a4f5fb4da778': 2,\n '0x76860669184330e6966a61188cfbd13486c7a6a6': 2,\n '0x4652b61781f5ee79dad354ab5d249aa2b99b4def': 2,\n },\n 'bsc-sandbox': {\n '0xf96093134adf151889ed72517979b2cd7144a831': 1,\n '0x1751181f9af72b37934006bbe989238498067563': 2,\n '0x8953031e74a172586e89ddb40b7d269b9186e74c': 2,\n },\n ethereum: {\n '0x2d61dcdd36f10b22176e0433b86f74567d529aaa': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0xe9ae261d3aff7d3fccf38fa2d612dd3897e07b2d': 2,\n },\n fantom: {\n '0x3c2269811836af69497e5f486a85d7316753cf62': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': 2,\n },\n 'fantom-testnet': {\n '0x0c3d09a7d86652f5599b836ce3db685a86513487': 1,\n '0x7669ac2bb50d567fd4bfb1cb5154b79c1e5e4a92': 2,\n '0xdafbd7a68e4ddcaa864c6a1171bd6030d0ca9a43': 2,\n '0x843986e31e0e3fea5eaf01086f36e7d85c458bb1': 2,\n },\n 'fantom-sandbox': {\n '0x54f51642779b9dbf48cc653c40499c82b8f261b3': 1,\n '0x01de566a13dc4be329351d930b0d9a569a495e46': 2,\n '0xf96093134adf151889ed72517979b2cd7144a831': 2,\n },\n 'avalanche-testnet': {\n '0xa7ac9fadbe9f51e7aa96751aa53f4cbb8a07b9ba': 1,\n '0x08c2e2b98d35973a4b2ca7ce8815cdb7c6f474f0': 2,\n '0x0a833b15305ce8b64946098db286710ace7bbe94': 2,\n '0xd81a1c5c52495a23f75d7269c17c73cebea61233': 2,\n },\n 'avalanche-sandbox': {\n '0x8953031e74a172586e89ddb40b7d269b9186e74c': 1,\n '0x4d7248986395d24ec777b16ca3fa32de64ec0330': 2,\n '0x4489a462f812d6dca0bde380ebdac12eb5a9e85a': 2,\n },\n 'polygon-testnet': {\n '0x2c7b02ffbc9602e8c04901609ef17cb1c4c2a7f7': 1,\n '0x3f6055024105d22b9400e025a1ca3259bd8b1893': 2,\n '0xcb97d107a87c5e172e075de94d7ef4498f6f06d2': 2,\n '0xd8b2de57ccfbbd5cd1713542cb6790fd2e33fed6': 2,\n },\n 'polygon-sandbox': {\n '0x369cc088dcedaaad27df0185c4f78caae42ff942': 1,\n '0x46f703c2a92874d5d526878a2ccc44e9431720a5': 2,\n '0xee404727abfca5d08a2480b0b881745f25362828': 2,\n },\n optimism: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': 2,\n },\n polygon: {\n '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,\n '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,\n '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': 2,\n },\n}\n","import { ethers } from 'ethers'\nimport invariant from 'tiny-invariant'\n\nimport { EVMUtilityVersion, NETWORKS, OutboundProofType } from './constants'\nimport { getReceiptProof as getReceiptProofV1 } from './mpt/v1'\nimport { getReceiptProof as getReceiptProofV2 } from './mpt/v2'\n\n/**\n * Generates a feather proof based on the utility version.\n *\n * @param {number} utilsVersion - The utility version.\n * @param {string} emitterAddress - The emitter address.\n * @param {string} packetPayload - The packet payload.\n * @returns {{ proof: string }} The generated proof.\n */\nexport function getFeatherProof(\n utilsVersion: number,\n emitterAddress: string,\n packetPayload: string\n): { proof: string } {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n const contractAddrByte32 = ethers.utils.hexZeroPad(emitterAddress, 32)\n return {\n proof: ethers.utils.solidityPack(['bytes32', 'bytes'], [contractAddrByte32, packetPayload]),\n }\n }\n case EVMUtilityVersion.V2: {\n return {\n proof: packetPayload,\n }\n }\n default:\n throw new Error(`Unknown utility version ${utilsVersion}`)\n }\n}\n\n/**\n * Retrieves the receipt proof based on the provided parameters.\n *\n * @param {string} network - The network name.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @param {number} outboundProofType - The outbound proof type.\n * @param {number} utilsVersion - The utility version.\n * @returns {Promise<object>} The receipt proof.\n */\nexport async function getReceiptProof(\n network,\n block,\n transactionReceipts,\n transactionIndex,\n outboundProofType,\n utilsVersion\n) {\n invariant(NETWORKS.includes(network), `Unsupported network: ${network}`)\n\n switch (outboundProofType) {\n case OutboundProofType.MPT: {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n return getReceiptProofV1(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V2:\n case EVMUtilityVersion.V4: {\n return getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V3: {\n const proof = await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n return {\n ...proof,\n blockHash: block.hash,\n }\n }\n default:\n throw new Error(`Unsupported utility version ${utilsVersion}`)\n }\n }\n default:\n throw new Error(`Unsupported Outbound Proof Type ${outboundProofType}`)\n }\n}\n\n/**\n * Encodes the parameters for the proof.\n *\n * @param {object} proof - The proof object.\n * @param {number} outboundProofType - The outbound proof type.\n * @param {number} utilsVersion - The utility version.\n * @param {number} logIndex - The log index.\n * @param {number} [srcEndpointId] - The source endpoint ID.\n * @returns {string} The encoded parameters.\n */\nexport function encodeParams(proof, outboundProofType, utilsVersion, logIndex, srcEndpointId?: number): string {\n switch (outboundProofType) {\n case OutboundProofType.MPT: {\n switch (utilsVersion) {\n case EVMUtilityVersion.V1: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes[]', 'uint256[]', 'uint256', 'uint256'],\n [srcEndpointId, proof.proof, proof.pointers, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V2: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes[]', 'uint256[]', 'uint256'],\n [srcEndpointId, proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V3: {\n return ethers.utils.defaultAbiCoder.encode(\n ['uint16', 'bytes32', 'bytes[]', 'uint256[]', 'uint256'],\n [srcEndpointId, proof.blockHash, proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n case EVMUtilityVersion.V4: {\n return ethers.utils.defaultAbiCoder.encode(\n ['bytes[]', 'uint256[]', 'uint256'],\n [proof.proof, proof.receiptSlotIndex, logIndex]\n )\n }\n default:\n throw new Error(`Unsupported utility version ${utilsVersion}`)\n }\n }\n default:\n throw new Error(`Unsupported Outbound Proof Type ${outboundProofType}`)\n }\n}\n\n/**\n * Retrieves the LayerZero packet from the log data.\n *\n * @param {number} srcChainId - The source chain ID.\n * @param {object} _log - The log object.\n * @returns {object} The LayerZero packet.\n */\nexport function getLayerZeroPacket(srcChainId, _log) {\n //todo: what if src address differs from 20 bytes\n const packet = ethers.utils.defaultAbiCoder.decode(['uint16', 'bytes'], _log.data)\n const data = packet[1].slice(2)\n\n //todo: what if dst address differs from 20 bytes\n const dstChainId = parseInt(packet[0])\n const nonce = ethers.BigNumber.from('0x' + data.slice(0, 16)).toNumber()\n const srcAddress = '0x' + data.slice(16, 56)\n const dstAddress = '0x' + data.slice(56, 96)\n\n let payload = '0x'\n if (data.length > 96) {\n //has payload\n payload = '0x' + data.slice(96, data.length)\n }\n\n return {\n srcChainId,\n dstChainId,\n nonce,\n dstAddress,\n srcAddress,\n ulnAddress: ethers.utils.defaultAbiCoder.encode(['address'], [_log.address]),\n payload,\n }\n}\n","// getStateSyncTxHash returns block's tx hash for state-sync receipt\n// Bor blockchain includes extra receipt/tx for state-sync logs,\n// but it is not included in transactionRoot or receiptRoot.\n// So, while calculating proof, we have to exclude them.\n//\n// This is derived from block's hash and number\n// state-sync tx hash = keccak256(\"matic-bor-receipt-\" + block.number + block.hash)\nimport { Proof, Receipt } from 'eth-object'\nimport { encode, toBuffer } from 'eth-util-lite'\nimport { BigNumber, utils } from 'ethers'\nimport CheckpointTrie from 'merkle-patricia-tree'\nimport { promisfy } from 'promisfy'\nimport invariant from 'tiny-invariant'\n\n/**\n * Returns the transaction hash for the state-sync receipt in a Polygon block.\n *\n * @param {object} block - The block object.\n * @returns {string} The transaction hash for the state-sync receipt.\n */\nexport function getPolygonStateSyncTxHash(block): string {\n const prefix = Buffer.from('matic-bor-receipt-')\n const blockNumberBytes = utils.zeroPad(utils.arrayify(BigNumber.from(block.number)), 8)\n const blockHashBytes = utils.arrayify(block.hash)\n\n const hash = utils.keccak256(utils.concat([prefix, blockNumberBytes, blockHashBytes]))\n\n return hash\n}\n\n/**\n * Converts a buffer to a hex string.\n *\n * @param {Buffer} buffer - The buffer to convert.\n * @returns {string} The hex string.\n */\nexport function buffer2hex(buffer): string {\n return '0x' + buffer.toString('hex')\n}\n\n/**\n * Generates a receipt proof from the given network, block, transaction receipts, and transaction index.\n *\n * @param {string} network - The network name.\n * @param {object} block - The block object.\n * @param {object[]} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to an object containing the receipt proof and stack.\n * @throws {Error} If the receipt root from the RPC block does not match the receipt root built.\n */\nexport async function receiptProofFrom(network, block, transactionReceipts, transactionIndex) {\n // handle the polygon special receipt\n if (network === 'polygon') {\n const ignoredTxnHash = getPolygonStateSyncTxHash(block)\n transactionReceipts = transactionReceipts.filter((receipt) => receipt.transactionHash !== ignoredTxnHash)\n }\n\n const tree = new CheckpointTrie()\n await Promise.all(\n transactionReceipts.map((siblingReceipt, index) => {\n const siblingPath = encode(index)\n\n if (network === 'harmony' && index >= block.transactions.length) {\n // void staking receipt type, which works differently from EIP2718\n siblingReceipt.type = 0\n }\n\n let serializedReceipt = Receipt.fromRpc(siblingReceipt)\n\n //handles the arbitrum receipt\n if (network === 'arbitrum') {\n //todo: will not need this in aribtrum nitro\n serializedReceipt[0] = toBuffer(0)\n }\n serializedReceipt = serializedReceipt.serialize()\n\n // if type is defined, concat type and RLP buffer seperately (for receipts/transactions following EIP2718)\n if (siblingReceipt.type) {\n serializedReceipt = Buffer.concat([toBuffer(siblingReceipt.type), serializedReceipt])\n }\n\n return promisfy(tree.put, tree)(siblingPath, serializedReceipt)\n })\n )\n\n const [_, __, stack] = await promisfy(tree.findPath, tree)(encode(transactionIndex))\n\n // assert the tree root\n const receiptRootFromBlock = block.receiptsRoot.slice(2)\n invariant(\n receiptRootFromBlock === tree._root.toString('hex'),\n 'receiptRoot from rpc block != receipt root we built'\n )\n\n return {\n stack: stack,\n receiptProof: Proof.fromStack(stack),\n }\n}\n","import { rlp } from 'ethereumjs-util'\nimport { ethers } from 'ethers'\nimport { matchingNibbleLength, stringToNibbles } from 'merkle-patricia-tree/util/nibbles'\nimport invariant from 'tiny-invariant'\n\nimport { buffer2hex, receiptProofFrom } from './common'\n\n/**\n * Finds the pointer in the full bytes.\n *\n * @param {Buffer} fullBytes - The full bytes.\n * @param {Buffer} currentNodeElement - The current node element.\n * @returns {number} The pointer.\n */\nfunction findPointer(fullBytes, currentNodeElement): number {\n const fullBytesHex = fullBytes.toString('hex')\n const slicedBytesHex = currentNodeElement.toString('hex')\n const result = fullBytesHex.indexOf(slicedBytesHex)\n invariant(result >= 0, 'wrong index')\n return (result - 2) / 2\n}\n\n/*\nrunning MPT locally, strictly the same as solidity file\n */\n\n/**\n * Asserts the inclusion of a receipt in the MPT.\n *\n * @param {string} receiptsRoot - The root of the receipts.\n * @param {string} expectedLogValue - The expected log value.\n * @param {Array} rlpProof - The RLP encoded proof.\n * @param {Array} pointers - The pointers in the MPT.\n * @returns {boolean} True if the receipt is included, false otherwise.\n */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, pointers): boolean {\n let nextRoot = receiptsRoot\n const proofDepth = rlpProof.length\n let pointer\n let proofBytes\n for (let i = 0; i < proofDepth; i++) {\n proofBytes = rlpProof[i]\n if (nextRoot !== ethers.utils.keccak256(proofBytes)) return false\n // load 32 bytes from the proofBytes\n if (i < pointers.length) {\n pointer = 2 + pointers[i] * 2\n nextRoot = '0x' + proofBytes.substring(pointer, pointer + 64)\n }\n }\n return true\n}\n\n/**\n * Assembles a Merkle Patricia Tree (MPT) proof.\n *\n * @param {object} proof - The proof object.\n * @param {object} block - The block object.\n * @param {number} transactionIndex - The transaction index.\n * @returns {object} The assembled MPT proof.\n */\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const { stack } = proof\n\n // convert receipt Proof L2 nested contents into hex\n const rlpNestedProof = [...proof.receiptProof].map((node) => node.map((elem) => buffer2hex(elem)))\n const rlpProof = rlpNestedProof.map((node) => buffer2hex(rlp.encode(node)))\n\n // decimal of transaction index\n const receiptIndexDeci = ethers.BigNumber.from(transactionIndex).toNumber()\n const encodedMerklePath = stringToNibbles(rlp.encode(receiptIndexDeci)) // if index = 252, encoded = 81fc\n\n // prepare the data for offline traversal\n let hashRoot = block.receiptsRoot\n const proofDepth = stack.length\n // const targetReceipt = stack[proofDepth - 1].value;\n const targetReceipt = rlpNestedProof[rlpNestedProof.length - 1][1]\n let proofPathCounter = 0\n const totalPathLength = encodedMerklePath.length\n const pointers: number[] = []\n let receiptSlotIndex\n for (let i = 0; i < proofDepth; i++) {\n // assert the path depth constaints\n invariant(\n proofPathCounter <= totalPathLength,\n `proofPathCounter wrong at ${proofPathCounter}, where totalPathLength = ${totalPathLength}`\n )\n\n // thisNodeValue in array form, easier to retrieve data\n const thisNode = stack[i]\n const thisNodeValue = thisNode.raw\n // convert the elem first then hex again, it is == rlpNestedProof[i]\n const thisNodeRlp = rlpProof[i]\n invariant(\n ethers.utils.keccak256(thisNodeRlp) === hashRoot,\n `invalid hashlink at depth ${i} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n\n if (thisNode.type === 'branch') {\n // branch node\n if (proofPathCounter === totalPathLength) {\n // has reach the end, assert targetReceipt ==\n invariant(ethers.utils.keccak256(thisNodeValue[16]) === targetReceipt, 'invalid branch value node')\n receiptSlotIndex = 16\n } else {\n // a normal branch node, step down\n const nextNibble = encodedMerklePath[proofPathCounter]\n invariant(\n nextNibble <= 16,\n `invalid nibble at ${nextNibble} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n // hashRoot = buffer2hex(thisNode._branches[nextNibble])\n hashRoot = buffer2hex(thisNodeValue[nextNibble])\n proofPathCounter += 1\n // retrieve the pointer for the branch value\n pointers.push(findPointer(thisNodeRlp, thisNodeValue[nextNibble]))\n }\n } else if (thisNode.type === 'leaf' || thisNode.type === 'extention') {\n const progressKey = encodedMerklePath.slice(0, proofPathCounter)\n const keyRemainder = encodedMerklePath.slice(matchingNibbleLength(progressKey, encodedMerklePath))\n proofPathCounter += matchingNibbleLength(keyRemainder, stack[i].key)\n if (thisNode.type === 'leaf') {\n invariant(proofPathCounter === totalPathLength, 'invalid leaf node')\n invariant(\n ethers.utils.keccak256(thisNodeValue[1]) === ethers.utils.keccak256(targetReceipt),\n 'wrong leaf value'\n )\n receiptSlotIndex = 1\n } else if (thisNode.type === 'extention') {\n hashRoot = buffer2hex(thisNodeValue[1])\n // retrieve the pointer for the leaf node\n pointers.push(findPointer(thisNodeRlp, thisNodeValue[1]))\n }\n } else {\n throw `unsupported node type in MPT ${thisNode} ${encodedMerklePath}`\n }\n }\n\n invariant(assertReceiptInclusion(block.receiptsRoot, targetReceipt, rlpProof, pointers), 'MPTLite local fails')\n\n return {\n receiptRoot: block.receiptsRoot,\n proof: rlpProof,\n pointers: pointers,\n receiptSlotIndex: receiptSlotIndex,\n }\n}\n\n/**\n * Retrieves the receipt proof.\n *\n * @param {string} network - The network.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to the receipt proof.\n */\nexport async function getReceiptProof(network, block, transactionReceipts, transactionIndex) {\n const proof = await receiptProofFrom(network, block, transactionReceipts, transactionIndex)\n return assembleMPTProof(proof, block, transactionIndex)\n}\n","import { rlp } from 'ethereumjs-util'\nimport { ethers } from 'ethers'\nimport { matchingNibbleLength, stringToNibbles } from 'merkle-patricia-tree/util/nibbles'\nimport invariant from 'tiny-invariant'\n\nimport { buffer2hex, receiptProofFrom } from './common'\n\n/**\n * Assembles a Merkle Patricia Tree (MPT) proof.\n *\n * @param {object} proof - The proof object.\n * @param {object} block - The block object.\n * @param {number} transactionIndex - The transaction index.\n * @returns {object} The assembled MPT proof.\n */\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const { stack } = proof\n\n // convert receipt Proof L2 nested contents into hex\n const rlpNestedProof = [...proof.receiptProof].map((node) => node.map((elem) => buffer2hex(elem)))\n const rlpProof = rlpNestedProof.map((node) => buffer2hex(rlp.encode(node)))\n\n // decimal of transaction index\n const receiptIndexDeci = ethers.BigNumber.from(transactionIndex).toNumber()\n const encodedMerklePath = stringToNibbles(rlp.encode(receiptIndexDeci)) // if index = 252, encoded = 81fc\n\n // prepare the data for offline traversal\n let hashRoot = block.receiptsRoot\n const proofDepth = stack.length\n // const targetReceipt = stack[proofDepth - 1].value;\n const targetReceipt = rlpNestedProof[rlpNestedProof.length - 1][1]\n let proofPathCounter = 0\n const totalPathLength = encodedMerklePath.length\n const path: number[] = []\n for (let i = 0; i < proofDepth; i++) {\n // console.log(`hashroot at ${i} : ${hashRoot}`)\n // console.log(` rlpProof at ${rlpProof[i]}`)\n\n // assert the path depth constraints\n invariant(\n proofPathCounter <= totalPathLength,\n `proofPathCounter wrong at ${proofPathCounter}, where totalPathLength = ${totalPathLength}`\n )\n\n // thisNodeValue in array form, easier to retrieve data\n const thisNode = stack[i]\n const thisNodeValue = thisNode.raw\n // convert the elem first then hex again, it is == rlpNestedProof[i]\n const thisNodeRlp = rlpProof[i]\n invariant(\n ethers.utils.keccak256(thisNodeRlp) === hashRoot,\n `invalid hashlink at depth ${i} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n\n if (thisNode.type === 'branch') {\n // branch node\n if (proofPathCounter === totalPathLength) {\n // has reach the end, assert targetReceipt ==\n invariant(ethers.utils.keccak256(thisNodeValue[16]) === targetReceipt, 'invalid branch value node')\n path[i] = 16\n console.warn(`a branch node 16 value type ${transactionIndex} receipt root ${block.receiptsRoot}`)\n } else {\n // a normal branch node, step down\n const nextNibble = encodedMerklePath[proofPathCounter]\n invariant(\n nextNibble <= 16,\n `invalid nibble at ${nextNibble} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`\n )\n // hashRoot = buffer2hex(thisNode._branches[nextNibble])\n hashRoot = buffer2hex(thisNodeValue[nextNibble])\n proofPathCounter += 1\n // retrieve the pointer for the branch value\n path[i] = nextNibble\n }\n } else if (thisNode.type === 'leaf' || thisNode.type === 'extention') {\n const progressKey = encodedMerklePath.slice(0, proofPathCounter)\n const keyRemainder = encodedMerklePath.slice(matchingNibbleLength(progressKey, encodedMerklePath))\n proofPathCounter += matchingNibbleLength(keyRemainder, stack[i].key)\n if (thisNode.type === 'leaf') {\n invariant(proofPathCounter === totalPathLength, 'invalid leaf node')\n invariant(\n ethers.utils.keccak256(thisNodeValue[1]) === ethers.utils.keccak256(targetReceipt),\n 'wrong leaf value'\n )\n path[i] = 1\n } else if (thisNode.type === 'extention') {\n path[i] = 1\n hashRoot = buffer2hex(thisNodeValue[1])\n // retrieve the pointer for the leaf node\n }\n } else {\n throw `unsupported node type in MPT ${thisNode} ${encodedMerklePath}`\n }\n }\n\n invariant(assertReceiptInclusion(block.receiptsRoot, targetReceipt, rlpProof, path, stack), 'MPTLite local fails')\n\n return {\n receiptRoot: block.receiptsRoot,\n proof: rlpProof,\n receiptSlotIndex: path,\n }\n}\n\n/*\nrunning MPT locally, strictly the same as solidity file\n */\n\n/**\n * Asserts the inclusion of a receipt in the MPT.\n *\n * @param {string} receiptsRoot - The root of the receipts.\n * @param {string} expectedLogValue - The expected log value.\n * @param {Array} rlpProof - The RLP encoded proof.\n * @param {Array} path - The path in the MPT.\n * @param {Array} stack - The stack of nodes.\n * @returns {boolean} True if the receipt is included, false otherwise.\n */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, path, stack): boolean {\n let nextRoot = receiptsRoot\n const proofDepth = rlpProof.length\n for (let i = 0; i < proofDepth; i++) {\n const proofBytes = rlpProof[i]\n const thisNodeValue = stack[i].raw\n if (nextRoot !== ethers.utils.keccak256(proofBytes)) return false\n if (i < proofDepth - 1) {\n nextRoot = buffer2hex(thisNodeValue[path[i]])\n }\n }\n return true\n}\n\n/**\n * Retrieves the receipt proof.\n *\n * @param {string} network - The network.\n * @param {object} block - The block object.\n * @param {Array} transactionReceipts - The transaction receipts.\n * @param {number} transactionIndex - The transaction index.\n * @returns {Promise<object>} A promise that resolves to the receipt proof.\n */\nexport async function getReceiptProof(network, block, transactionReceipts, transactionIndex) {\n const proof = await receiptProofFrom(network, block, transactionReceipts, transactionIndex)\n return assembleMPTProof(proof, block, transactionIndex)\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/lz-proof-utility",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.74",
|
|
4
4
|
"description": "LayerZero Proof Utility",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"exports": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"tiny-invariant": "^1.3.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@layerzerolabs/tsup-config-next": "^3.0.
|
|
34
|
-
"@layerzerolabs/typescript-config-next": "^3.0.
|
|
33
|
+
"@layerzerolabs/tsup-config-next": "^3.0.74",
|
|
34
|
+
"@layerzerolabs/typescript-config-next": "^3.0.74",
|
|
35
35
|
"@types/safer-buffer": "^2.1.3",
|
|
36
36
|
"rimraf": "^5.0.5",
|
|
37
37
|
"tsup": "^8.3.5",
|