@layerzerolabs/lz-proof-utility 2.1.24 → 2.1.26
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 +6 -0
- package/dist/index.cjs +3 -9
- 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 +2 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -6,20 +6,15 @@ var ethereumjsUtil = require('ethereumjs-util');
|
|
|
6
6
|
var nibbles = require('merkle-patricia-tree/util/nibbles');
|
|
7
7
|
var ethObject = require('eth-object');
|
|
8
8
|
var ethUtilLite = require('eth-util-lite');
|
|
9
|
+
var CheckpointTrie = require('merkle-patricia-tree');
|
|
9
10
|
var promisfy = require('promisfy');
|
|
10
11
|
|
|
11
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
13
|
|
|
13
14
|
var invariant2__default = /*#__PURE__*/_interopDefault(invariant2);
|
|
15
|
+
var CheckpointTrie__default = /*#__PURE__*/_interopDefault(CheckpointTrie);
|
|
14
16
|
|
|
15
17
|
var __defProp = Object.defineProperty;
|
|
16
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
17
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
18
|
-
}) : x)(function(x) {
|
|
19
|
-
if (typeof require !== "undefined")
|
|
20
|
-
return require.apply(this, arguments);
|
|
21
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
22
|
-
});
|
|
23
18
|
var __export = (target, all) => {
|
|
24
19
|
for (var name in all)
|
|
25
20
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -127,7 +122,6 @@ __export(proof_exports, {
|
|
|
127
122
|
getLayerZeroPacket: () => getLayerZeroPacket,
|
|
128
123
|
getReceiptProof: () => getReceiptProof3
|
|
129
124
|
});
|
|
130
|
-
var Tree = __require("merkle-patricia-tree");
|
|
131
125
|
function getPolygonStateSyncTxHash(block) {
|
|
132
126
|
const prefix = Buffer.from("matic-bor-receipt-");
|
|
133
127
|
const blockNumberBytes = ethers.utils.zeroPad(ethers.utils.arrayify(ethers.BigNumber.from(block.number)), 8);
|
|
@@ -143,7 +137,7 @@ async function receiptProofFrom(network, block, transactionReceipts, transaction
|
|
|
143
137
|
const ignoredTxnHash = getPolygonStateSyncTxHash(block);
|
|
144
138
|
transactionReceipts = transactionReceipts.filter((receipt) => receipt.transactionHash !== ignoredTxnHash);
|
|
145
139
|
}
|
|
146
|
-
const tree = new
|
|
140
|
+
const tree = new CheckpointTrie__default.default();
|
|
147
141
|
await Promise.all(
|
|
148
142
|
transactionReceipts.map((siblingReceipt, index) => {
|
|
149
143
|
const siblingPath = ethUtilLite.encode(index);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/proof.ts","../src/mpt/v1.ts","../src/mpt/common.ts","../src/mpt/v2.ts"],"names":["getReceiptProof","ethers","invariant","rlp","matchingNibbleLength","stringToNibbles","assembleMPTProof","assertReceiptInclusion"],"mappings":";;;;;;;;;;;;;;AAAO,IAAM,WAAW,CAAC,WAAW,WAAW,YAAY,WAAW,SAAS;AAExE,IAAM,oBAAoB;AAAA,EAC7B,KAAK;AAAA,EACL,IAAI;AACR;AAEO,IAAM,oBAAoB;AAAA,EAC7B,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACR;AAEO,IAAM,uBAAuB;AAAA,EAChC,UAAU;AAAA,IACN,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,EAClD;AAAA,EACA,WAAW;AAAA,IACP,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,E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M;AAEjD,QAAM,SAASA,QAAO,MAAM,gBAAgB,OAAO,CAAC,UAAU,OAAO,GAAG,KAAK,IAAI;AACjF,QAAM,OAAO,OAAO,CAAC,EAAE,MAAM,CAAC;AAG9B,QAAM,aAAa,SAAS,OAAO,CAAC,CAAC;AACrC,QAAM,QAAQA,QAAO,UAAU,KAAK,OAAO,KAAK,MAAM,GAAG,EAAE,CAAC,EAAE,SAAS;AACvE,QAAM,aAAa,OAAO,KAAK,MAAM,IAAI,EAAE;AAC3C,QAAM,aAAa,OAAO,KAAK,MAAM,IAAI,EAAE;AAE3C,MAAI,UAAU;AACd,MAAI,KAAK,SAAS,IAAI;AAElB,cAAU,OAAO,KAAK,MAAM,IAAI,KAAK,MAAM;AAAA,EAC/C;AAEA,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAYA,QAAO,MAAM,gBAAgB,OAAO,CAAC,SAAS,GAAG,CAAC,KAAK,OAAO,CAAC;AAAA,IAC3E;AAAA,EACJ;AACJ","sourcesContent":["export const NETWORKS = ['default', 'hardhat', 'arbitrum', 'polygon', 'harmony']\n\nexport const OutboundProofType = {\n MPT: 1,\n FP: 2,\n}\n\nexport const EVMUtilityVersion = {\n V1: 1,\n V2: 2,\n V3: 3,\n V4: 4,\n}\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\nexport function getFeatherProof(utilsVersion, emitterAddress, packetPayload) {\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\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 await getReceiptProofV1(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V2:\n case EVMUtilityVersion.V4: {\n return await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V3: {\n const proof = await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n proof['blockHash'] = block.hash\n return proof\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\nexport function encodeParams(proof, outboundProofType, utilsVersion, logIndex, srcEndpointId = undefined) {\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\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","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\nfunction findPointer(fullBytes, currentNodeElement) {\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 */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, pointers) {\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\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const stack = proof.stack\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\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","// 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 { promisfy } from 'promisfy'\nimport invariant from 'tiny-invariant'\n\nconst Tree = require('merkle-patricia-tree')\n\nexport function getPolygonStateSyncTxHash(block) {\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\nexport function buffer2hex(buffer) {\n return '0x' + buffer.toString('hex')\n}\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 Tree()\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\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const stack = proof.stack\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 */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, path, stack) {\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\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/v1.ts","../src/mpt/common.ts","../src/mpt/v2.ts"],"names":["getReceiptProof","ethers","invariant","rlp","matchingNibbleLength","stringToNibbles","assembleMPTProof","assertReceiptInclusion"],"mappings":";;;;;;;AAAO,IAAM,WAAW,CAAC,WAAW,WAAW,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QACJ;AAAA,QACA,KAAK,kBAAkB,IAAI;AACvB,iBAAOA,QAAO,MAAM,gBAAgB;AAAA,YAChC,CAAC,WAAW,aAAa,SAAS;AAAA,YAClC,CAAC,MAAM,OAAO,MAAM,kBAAkB,QAAQ;AAAA,UAClD;AAAA,QACJ;AAAA,QACA;AACI,gBAAM,IAAI,MAAM,+BAA+B,YAAY,EAAE;AAAA,MACrE;AAAA,IACJ;AAAA,IACA;AACI,YAAM,IAAI,MAAM,mCAAmC,iBAAiB,EAAE;AAAA,EAC9E;AACJ;AAEO,SAAS,mBAAmB,YAAY,MAAM;AAEjD,QAAM,SAASA,QAAO,MAAM,gBAAgB,OAAO,CAAC,UAAU,OAAO,GAAG,KAAK,IAAI;AACjF,QAAM,OAAO,OAAO,CAAC,EAAE,MAAM,CAAC;AAG9B,QAAM,aAAa,SAAS,OAAO,CAAC,CAAC;AACrC,QAAM,QAAQA,QAAO,UAAU,KAAK,OAAO,KAAK,MAAM,GAAG,EAAE,CAAC,EAAE,SAAS;AACvE,QAAM,aAAa,OAAO,KAAK,MAAM,IAAI,EAAE;AAC3C,QAAM,aAAa,OAAO,KAAK,MAAM,IAAI,EAAE;AAE3C,MAAI,UAAU;AACd,MAAI,KAAK,SAAS,IAAI;AAElB,cAAU,OAAO,KAAK,MAAM,IAAI,KAAK,MAAM;AAAA,EAC/C;AAEA,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAYA,QAAO,MAAM,gBAAgB,OAAO,CAAC,SAAS,GAAG,CAAC,KAAK,OAAO,CAAC;AAAA,IAC3E;AAAA,EACJ;AACJ","sourcesContent":["export const NETWORKS = ['default', 'hardhat', 'arbitrum', 'polygon', 'harmony']\n\nexport const OutboundProofType = {\n MPT: 1,\n FP: 2,\n}\n\nexport const EVMUtilityVersion = {\n V1: 1,\n V2: 2,\n V3: 3,\n V4: 4,\n}\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\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\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 await getReceiptProofV1(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V2:\n case EVMUtilityVersion.V4: {\n return await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V3: {\n const proof = await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n proof['blockHash'] = block.hash\n return proof\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\nexport function encodeParams(proof, outboundProofType, utilsVersion, logIndex, srcEndpointId = undefined): 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\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","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\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 */\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\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const stack = proof.stack\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\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","// 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\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\nexport function buffer2hex(buffer): string {\n return '0x' + buffer.toString('hex')\n}\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\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const stack = proof.stack\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 */\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\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
|
@@ -92,7 +92,7 @@ declare const UTILS_VERSION_LOOKUP: {
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
declare function getFeatherProof(utilsVersion: any, emitterAddress: any, packetPayload: any): {
|
|
95
|
-
proof:
|
|
95
|
+
proof: string;
|
|
96
96
|
};
|
|
97
97
|
declare function getReceiptProof(network: any, block: any, transactionReceipts: any, transactionIndex: any, outboundProofType: any, utilsVersion: any): Promise<{
|
|
98
98
|
receiptRoot: any;
|
package/dist/index.d.ts
CHANGED
|
@@ -92,7 +92,7 @@ declare const UTILS_VERSION_LOOKUP: {
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
declare function getFeatherProof(utilsVersion: any, emitterAddress: any, packetPayload: any): {
|
|
95
|
-
proof:
|
|
95
|
+
proof: string;
|
|
96
96
|
};
|
|
97
97
|
declare function getReceiptProof(network: any, block: any, transactionReceipts: any, transactionIndex: any, outboundProofType: any, utilsVersion: any): Promise<{
|
|
98
98
|
receiptRoot: any;
|
package/dist/index.mjs
CHANGED
|
@@ -4,16 +4,10 @@ import { rlp } from 'ethereumjs-util';
|
|
|
4
4
|
import { stringToNibbles, matchingNibbleLength } from 'merkle-patricia-tree/util/nibbles';
|
|
5
5
|
import { Receipt, Proof } from 'eth-object';
|
|
6
6
|
import { encode, toBuffer } from 'eth-util-lite';
|
|
7
|
+
import CheckpointTrie from 'merkle-patricia-tree';
|
|
7
8
|
import { promisfy } from 'promisfy';
|
|
8
9
|
|
|
9
10
|
var __defProp = Object.defineProperty;
|
|
10
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
11
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
12
|
-
}) : x)(function(x) {
|
|
13
|
-
if (typeof require !== "undefined")
|
|
14
|
-
return require.apply(this, arguments);
|
|
15
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
16
|
-
});
|
|
17
11
|
var __export = (target, all) => {
|
|
18
12
|
for (var name in all)
|
|
19
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -121,7 +115,6 @@ __export(proof_exports, {
|
|
|
121
115
|
getLayerZeroPacket: () => getLayerZeroPacket,
|
|
122
116
|
getReceiptProof: () => getReceiptProof3
|
|
123
117
|
});
|
|
124
|
-
var Tree = __require("merkle-patricia-tree");
|
|
125
118
|
function getPolygonStateSyncTxHash(block) {
|
|
126
119
|
const prefix = Buffer.from("matic-bor-receipt-");
|
|
127
120
|
const blockNumberBytes = utils.zeroPad(utils.arrayify(BigNumber.from(block.number)), 8);
|
|
@@ -137,7 +130,7 @@ async function receiptProofFrom(network, block, transactionReceipts, transaction
|
|
|
137
130
|
const ignoredTxnHash = getPolygonStateSyncTxHash(block);
|
|
138
131
|
transactionReceipts = transactionReceipts.filter((receipt) => receipt.transactionHash !== ignoredTxnHash);
|
|
139
132
|
}
|
|
140
|
-
const tree = new
|
|
133
|
+
const tree = new CheckpointTrie();
|
|
141
134
|
await Promise.all(
|
|
142
135
|
transactionReceipts.map((siblingReceipt, index) => {
|
|
143
136
|
const siblingPath = encode(index);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/proof.ts","../src/mpt/v1.ts","../src/mpt/common.ts","../src/mpt/v2.ts"],"names":["getReceiptProof","ethers","invariant","rlp","matchingNibbleLength","stringToNibbles","assembleMPTProof","assertReceiptInclusion"],"mappings":";;;;;;;;;;;;;;AAAO,IAAM,WAAW,CAAC,WAAW,WAAW,YAAY,WAAW,SAAS;AAExE,IAAM,oBAAoB;AAAA,EAC7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B,iBAAOA,QAAO,MAAM,gBAAgB;AAAA,YAChC,CAAC,WAAW,aAAa,SAAS;AAAA,YAClC,CAAC,MAAM,OAAO,MAAM,kBAAkB,QAAQ;AAAA,UAClD;AAAA,QACJ;AAAA,QACA;AACI,gBAAM,IAAI,MAAM,+BAA+B,YAAY,EAAE;AAAA,MACrE;AAAA,IACJ;AAAA,IACA;AACI,YAAM,IAAI,MAAM,mCAAmC,iBAAiB,EAAE;AAAA,EAC9E;AACJ;AAEO,SAAS,mBAAmB,YAAY,MAAM;AAEjD,QAAM,SAASA,QAAO,MAAM,gBAAgB,OAAO,CAAC,UAAU,OAAO,GAAG,KAAK,IAAI;AACjF,QAAM,OAAO,OAAO,CAAC,EAAE,MAAM,CAAC;AAG9B,QAAM,aAAa,SAAS,OAAO,CAAC,CAAC;AACrC,QAAM,QAAQA,QAAO,UAAU,KAAK,OAAO,KAAK,MAAM,GAAG,EAAE,CAAC,EAAE,SAAS;AACvE,QAAM,aAAa,OAAO,KAAK,MAAM,IAAI,EAAE;AAC3C,QAAM,aAAa,OAAO,KAAK,MAAM,IAAI,EAAE;AAE3C,MAAI,UAAU;AACd,MAAI,KAAK,SAAS,IAAI;AAElB,cAAU,OAAO,KAAK,MAAM,IAAI,KAAK,MAAM;AAAA,EAC/C;AAEA,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAYA,QAAO,MAAM,gBAAgB,OAAO,CAAC,SAAS,GAAG,CAAC,KAAK,OAAO,CAAC;AAAA,IAC3E;AAAA,EACJ;AACJ","sourcesContent":["export const NETWORKS = ['default', 'hardhat', 'arbitrum', 'polygon', 'harmony']\n\nexport const OutboundProofType = {\n MPT: 1,\n FP: 2,\n}\n\nexport const EVMUtilityVersion = {\n V1: 1,\n V2: 2,\n V3: 3,\n V4: 4,\n}\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\nexport function getFeatherProof(utilsVersion, emitterAddress, packetPayload) {\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\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 await getReceiptProofV1(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V2:\n case EVMUtilityVersion.V4: {\n return await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V3: {\n const proof = await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n proof['blockHash'] = block.hash\n return proof\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\nexport function encodeParams(proof, outboundProofType, utilsVersion, logIndex, srcEndpointId = undefined) {\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\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","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\nfunction findPointer(fullBytes, currentNodeElement) {\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 */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, pointers) {\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\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const stack = proof.stack\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\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","// 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 { promisfy } from 'promisfy'\nimport invariant from 'tiny-invariant'\n\nconst Tree = require('merkle-patricia-tree')\n\nexport function getPolygonStateSyncTxHash(block) {\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\nexport function buffer2hex(buffer) {\n return '0x' + buffer.toString('hex')\n}\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 Tree()\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\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const stack = proof.stack\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 */\nfunction assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, path, stack) {\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\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/v1.ts","../src/mpt/common.ts","../src/mpt/v2.ts"],"names":["getReceiptProof","ethers","invariant","rlp","matchingNibbleLength","stringToNibbles","assembleMPTProof","assertReceiptInclusion"],"mappings":";;;;;;;AAAO,IAAM,WAAW,CAAC,WAAW,WAAW,YAAY,WAAW,SAAS;AAExE,IAAM,oBAAoB;AAAA,EAC7B,KAAK;AAAA,EACL,IAAI;AACR;AAEO,IAAM,oBAAoB;AAAA,EAC7B,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACR;AAEO,IAAM,uBAAuB;AAAA,EAChC,UAAU;AAAA,IACN,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,EAClD;AAAA,EACA,WAAW;AAAA,IACP,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,EAClD;AAAA,EACA,KAAK;AAAA,IACD,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,EAClD;AAAA,EACA,eAAe;AAAA,IACX,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,EAClD;AAAA,EACA,eAAe;AAAA,IACX,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,EAClD;AAAA,EACA,UAAU;AAAA,IACN,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,EAClD;AAAA,EACA,QAAQ;AAAA,IACJ,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,IAC9C,8CAA8C;AAAA,EAClD;AAAA,EACA,kBAAkB;AAAA,IACd,8CAA8C;A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AAAA,IACA,YAAYA,QAAO,MAAM,gBAAgB,OAAO,CAAC,SAAS,GAAG,CAAC,KAAK,OAAO,CAAC;AAAA,IAC3E;AAAA,EACJ;AACJ","sourcesContent":["export const NETWORKS = ['default', 'hardhat', 'arbitrum', 'polygon', 'harmony']\n\nexport const OutboundProofType = {\n MPT: 1,\n FP: 2,\n}\n\nexport const EVMUtilityVersion = {\n V1: 1,\n V2: 2,\n V3: 3,\n V4: 4,\n}\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\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\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 await getReceiptProofV1(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V2:\n case EVMUtilityVersion.V4: {\n return await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n }\n case EVMUtilityVersion.V3: {\n const proof = await getReceiptProofV2(network, block, transactionReceipts, transactionIndex)\n proof['blockHash'] = block.hash\n return proof\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\nexport function encodeParams(proof, outboundProofType, utilsVersion, logIndex, srcEndpointId = undefined): 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\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","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\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 */\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\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const stack = proof.stack\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\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","// 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\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\nexport function buffer2hex(buffer): string {\n return '0x' + buffer.toString('hex')\n}\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\nfunction assembleMPTProof(proof, block, transactionIndex) {\n const stack = proof.stack\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 */\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\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": "2.1.
|
|
3
|
+
"version": "2.1.26",
|
|
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": "^2.1.
|
|
34
|
-
"@layerzerolabs/typescript-config-next": "^2.1.
|
|
33
|
+
"@layerzerolabs/tsup-config-next": "^2.1.26",
|
|
34
|
+
"@layerzerolabs/typescript-config-next": "^2.1.26",
|
|
35
35
|
"@types/safer-buffer": "^2.1.3",
|
|
36
36
|
"rimraf": "^5.0.5",
|
|
37
37
|
"tsup": "^8.0.1",
|