@aztec/aztec-node 0.87.0 → 0.87.2

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.
@@ -218,14 +218,20 @@ export declare class AztecNodeService implements AztecNode, AztecNodeAdmin, Trac
218
218
  */
219
219
  isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean>;
220
220
  /**
221
- * Returns the index of a l2ToL1Message in a ephemeral l2 to l1 data tree as well as its sibling path.
222
- * @remarks This tree is considered ephemeral because it is created on-demand by: taking all the l2ToL1 messages
223
- * in a single block, and then using them to make a variable depth append-only tree with these messages as leaves.
224
- * The tree is discarded immediately after calculating what we need from it.
221
+ * Returns the index and sibling path for a L2->L1 message in a block's message tree.
222
+ * @remarks The message tree is constructed on-demand by taking all L2->L1 messages in a block
223
+ * and creating a variable depth append-only tree with the messages as leaves.
224
+ * The tree is constructed in two layers:
225
+ * 1. Subtree - For each transaction in the block, a subtree is created containing all L2->L1 messages from that
226
+ * transaction.
227
+ * 2. Top tree - A tree containing the roots of all the subtrees as leaves
228
+ * The final path is constructed by concatenating the path in the subtree with the path in the top tree.
229
+ * When there is only one transaction in the block, the subtree itself becomes the block's L2->L1 message tree,
230
+ * and no top tree is needed. The out hash is the root of the the block's L2->L1 message tree.
225
231
  * TODO: Handle the case where two messages in the same tx have the same hash.
226
- * @param blockNumber - The block number at which to get the data.
227
- * @param l2ToL1Message - The l2ToL1Message get the index / sibling path for.
228
- * @returns A tuple of the index and the sibling path of the L2ToL1Message.
232
+ * @param blockNumber - Block number to get data from
233
+ * @param l2ToL1Message - Message to get index/path for
234
+ * @returns [index, siblingPath] for the message
229
235
  */
230
236
  getL2ToL1MessageMembershipWitness(blockNumber: L2BlockNumber, l2ToL1Message: Fr): Promise<[bigint, SiblingPath<number>]>;
231
237
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/aztec-node/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE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EAAE,EACN,EAAE,YAAY,EAAE,kBAAkB,EAAE,GAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,kBAAkB,CAAC,EAAE,OAAO,CAAA;KAAO,GAClG,OAAO,CAAC,kBAAkB,CAAC;IAgBjB,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,GAAG,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/E,4BAA4B,IAAI,OAAO,CAAC,yBAAyB,CAAC;IASlE,kCAAkC,CAAC,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/F,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAQzB,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC;IAIxC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqCpD,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC/D,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAMhC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CA6CnC"}
@@ -495,65 +495,89 @@ import { NodeMetrics } from './node_metrics.js';
495
495
  return await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message) !== undefined;
496
496
  }
497
497
  /**
498
- * Returns the index of a l2ToL1Message in a ephemeral l2 to l1 data tree as well as its sibling path.
499
- * @remarks This tree is considered ephemeral because it is created on-demand by: taking all the l2ToL1 messages
500
- * in a single block, and then using them to make a variable depth append-only tree with these messages as leaves.
501
- * The tree is discarded immediately after calculating what we need from it.
498
+ * Returns the index and sibling path for a L2->L1 message in a block's message tree.
499
+ * @remarks The message tree is constructed on-demand by taking all L2->L1 messages in a block
500
+ * and creating a variable depth append-only tree with the messages as leaves.
501
+ * The tree is constructed in two layers:
502
+ * 1. Subtree - For each transaction in the block, a subtree is created containing all L2->L1 messages from that
503
+ * transaction.
504
+ * 2. Top tree - A tree containing the roots of all the subtrees as leaves
505
+ * The final path is constructed by concatenating the path in the subtree with the path in the top tree.
506
+ * When there is only one transaction in the block, the subtree itself becomes the block's L2->L1 message tree,
507
+ * and no top tree is needed. The out hash is the root of the the block's L2->L1 message tree.
502
508
  * TODO: Handle the case where two messages in the same tx have the same hash.
503
- * @param blockNumber - The block number at which to get the data.
504
- * @param l2ToL1Message - The l2ToL1Message get the index / sibling path for.
505
- * @returns A tuple of the index and the sibling path of the L2ToL1Message.
509
+ * @param blockNumber - Block number to get data from
510
+ * @param l2ToL1Message - Message to get index/path for
511
+ * @returns [index, siblingPath] for the message
506
512
  */ async getL2ToL1MessageMembershipWitness(blockNumber, l2ToL1Message) {
507
513
  const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
508
514
  if (block === undefined) {
509
- throw new Error('Block is not defined');
510
- }
511
- const l2ToL1Messages = block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs);
512
- // Find index of message
513
- let indexOfMsgInSubtree = -1;
514
- const indexOfMsgTx = l2ToL1Messages.findIndex((msgs)=>{
515
- const idx = msgs.findIndex((msg)=>msg.equals(l2ToL1Message));
516
- indexOfMsgInSubtree = Math.max(indexOfMsgInSubtree, idx);
517
- return idx !== -1;
518
- });
519
- if (indexOfMsgTx === -1) {
515
+ throw new Error('Block not found in getL2ToL1MessageMembershipWitness');
516
+ }
517
+ const messagesPerTx = block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs);
518
+ // Find index of message in subtree and index of tx in a block
519
+ let messageIndexInTx = -1, txIndex = -1;
520
+ {
521
+ txIndex = messagesPerTx.findIndex((messages)=>{
522
+ const idx = messages.findIndex((msg)=>msg.equals(l2ToL1Message));
523
+ messageIndexInTx = Math.max(messageIndexInTx, idx);
524
+ return idx !== -1;
525
+ });
526
+ }
527
+ if (txIndex === -1) {
520
528
  throw new Error('The L2ToL1Message you are trying to prove inclusion of does not exist');
521
529
  }
522
- const tempStores = [];
523
- // Construct message subtrees
524
- const l2toL1Subtrees = l2ToL1Messages.map((msgs, i)=>{
525
- const store = openTmpStore(true);
526
- tempStores.push(store);
527
- const treeHeight = msgs.length <= 1 ? 1 : Math.ceil(Math.log2(msgs.length));
528
- const tree = new StandardTree(store, new SHA256Trunc(), `temp_msgs_subtrees_${i}`, treeHeight, 0n, Fr);
529
- tree.appendLeaves(msgs);
530
- return tree;
531
- });
532
- // path of the input msg from leaf -> first out hash calculated in base rolllup
533
- const subtreePathOfL2ToL1Message = await l2toL1Subtrees[indexOfMsgTx].getSiblingPath(BigInt(indexOfMsgInSubtree), true);
534
- const numTxs = block.body.txEffects.length;
535
- if (numTxs === 1) {
530
+ // Get the message path in subtree and message subtree height
531
+ let messagePathInSubtree;
532
+ let messageSubtreeHeight;
533
+ {
534
+ const subtreeStore = openTmpStore(true);
535
+ const txMessages = messagesPerTx[txIndex];
536
+ messageSubtreeHeight = txMessages.length <= 1 ? 1 : Math.ceil(Math.log2(txMessages.length));
537
+ const subtree = new StandardTree(subtreeStore, new SHA256Trunc(), `subtree_${txIndex}`, messageSubtreeHeight, 0n, Fr);
538
+ subtree.appendLeaves(txMessages);
539
+ messagePathInSubtree = await subtree.getSiblingPath(BigInt(messageIndexInTx), true);
540
+ await subtreeStore.delete();
541
+ }
542
+ // If the number of txs is 1 we are dealing with a special case where the tx subtree itself is the whole block's
543
+ // l2 to l1 message tree.
544
+ const numTransactions = block.body.txEffects.length;
545
+ if (numTransactions === 1) {
536
546
  return [
537
- BigInt(indexOfMsgInSubtree),
538
- subtreePathOfL2ToL1Message
547
+ BigInt(messageIndexInTx),
548
+ messagePathInSubtree
539
549
  ];
540
550
  }
541
- // For a tx with no messages, we have to set an out hash of 0 to match the circuit/contract behavior
542
- const l2toL1SubtreeRoots = l2toL1Subtrees.map((t)=>t.getNumLeaves(true) == 0n ? Fr.ZERO : Fr.fromBuffer(t.getRoot(true)));
543
- const maxTreeHeight = Math.ceil(Math.log2(l2toL1SubtreeRoots.length));
544
- // The root of this tree is the out_hash calculated in Noir => we truncate to match Noir's SHA
545
- const outHashTree = new UnbalancedTree(new SHA256Trunc(), 'temp_outhash_sibling_path', maxTreeHeight, Fr);
546
- await outHashTree.appendLeaves(l2toL1SubtreeRoots);
547
- const pathOfTxInOutHashTree = await outHashTree.getSiblingPath(l2toL1SubtreeRoots[indexOfMsgTx].toBigInt());
548
- // Append subtree path to out hash tree path
549
- const mergedPath = subtreePathOfL2ToL1Message.toBufferArray().concat(pathOfTxInOutHashTree.toBufferArray());
550
- // Append binary index of subtree path to binary index of out hash tree path
551
- const mergedIndex = parseInt(indexOfMsgTx.toString(2).concat(indexOfMsgInSubtree.toString(2).padStart(l2toL1Subtrees[indexOfMsgTx].getDepth(), '0')), 2);
552
- // clear the tmp stores
553
- await Promise.all(tempStores.map((store)=>store.delete()));
551
+ // Calculate roots for all tx subtrees
552
+ const txSubtreeRoots = await Promise.all(messagesPerTx.map(async (messages, txIdx)=>{
553
+ // For a tx with no messages, we have to set an out hash of 0 to match what the circuit does.
554
+ if (messages.length === 0) {
555
+ return Fr.ZERO;
556
+ }
557
+ const txStore = openTmpStore(true);
558
+ const txTreeHeight = messages.length <= 1 ? 1 : Math.ceil(Math.log2(messages.length));
559
+ const txTree = new StandardTree(txStore, new SHA256Trunc(), `tx_messages_subtree_${txIdx}`, txTreeHeight, 0n, Fr);
560
+ txTree.appendLeaves(messages);
561
+ const root = Fr.fromBuffer(txTree.getRoot(true));
562
+ await txStore.delete();
563
+ return root;
564
+ }));
565
+ // Construct the top tree and compute the combined path
566
+ let combinedPath;
567
+ {
568
+ const topTreeHeight = Math.ceil(Math.log2(txSubtreeRoots.length));
569
+ // The root of this tree is the out_hash calculated in Noir => we truncate to match Noir's SHA
570
+ const topTree = new UnbalancedTree(new SHA256Trunc(), 'top_tree', topTreeHeight, Fr);
571
+ await topTree.appendLeaves(txSubtreeRoots);
572
+ const txPathInTopTree = await topTree.getSiblingPath(txSubtreeRoots[txIndex].toBigInt());
573
+ // Append subtree path to top tree path
574
+ combinedPath = messagePathInSubtree.toBufferArray().concat(txPathInTopTree.toBufferArray());
575
+ }
576
+ // Append binary index of subtree path to binary index of top tree path
577
+ const combinedIndex = parseInt(txIndex.toString(2).concat(messageIndexInTx.toString(2).padStart(messageSubtreeHeight, '0')), 2);
554
578
  return [
555
- BigInt(mergedIndex),
556
- new SiblingPath(mergedPath.length, mergedPath)
579
+ BigInt(combinedIndex),
580
+ new SiblingPath(combinedPath.length, combinedPath)
557
581
  ];
558
582
  }
559
583
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/aztec-node",
3
- "version": "0.87.0",
3
+ "version": "0.87.2",
4
4
  "main": "dest/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -61,27 +61,27 @@
61
61
  ]
62
62
  },
63
63
  "dependencies": {
64
- "@aztec/archiver": "0.87.0",
65
- "@aztec/bb-prover": "0.87.0",
66
- "@aztec/blob-sink": "0.87.0",
67
- "@aztec/constants": "0.87.0",
68
- "@aztec/epoch-cache": "0.87.0",
69
- "@aztec/ethereum": "0.87.0",
70
- "@aztec/foundation": "0.87.0",
71
- "@aztec/kv-store": "0.87.0",
72
- "@aztec/l1-artifacts": "0.87.0",
73
- "@aztec/merkle-tree": "0.87.0",
74
- "@aztec/node-lib": "0.87.0",
75
- "@aztec/noir-protocol-circuits-types": "0.87.0",
76
- "@aztec/p2p": "0.87.0",
77
- "@aztec/protocol-contracts": "0.87.0",
78
- "@aztec/prover-client": "0.87.0",
79
- "@aztec/sequencer-client": "0.87.0",
80
- "@aztec/simulator": "0.87.0",
81
- "@aztec/stdlib": "0.87.0",
82
- "@aztec/telemetry-client": "0.87.0",
83
- "@aztec/validator-client": "0.87.0",
84
- "@aztec/world-state": "0.87.0",
64
+ "@aztec/archiver": "0.87.2",
65
+ "@aztec/bb-prover": "0.87.2",
66
+ "@aztec/blob-sink": "0.87.2",
67
+ "@aztec/constants": "0.87.2",
68
+ "@aztec/epoch-cache": "0.87.2",
69
+ "@aztec/ethereum": "0.87.2",
70
+ "@aztec/foundation": "0.87.2",
71
+ "@aztec/kv-store": "0.87.2",
72
+ "@aztec/l1-artifacts": "0.87.2",
73
+ "@aztec/merkle-tree": "0.87.2",
74
+ "@aztec/node-lib": "0.87.2",
75
+ "@aztec/noir-protocol-circuits-types": "0.87.2",
76
+ "@aztec/p2p": "0.87.2",
77
+ "@aztec/protocol-contracts": "0.87.2",
78
+ "@aztec/prover-client": "0.87.2",
79
+ "@aztec/sequencer-client": "0.87.2",
80
+ "@aztec/simulator": "0.87.2",
81
+ "@aztec/stdlib": "0.87.2",
82
+ "@aztec/telemetry-client": "0.87.2",
83
+ "@aztec/validator-client": "0.87.2",
84
+ "@aztec/world-state": "0.87.2",
85
85
  "koa": "^2.16.1",
86
86
  "koa-router": "^12.0.0",
87
87
  "tslib": "^2.4.0",
@@ -20,7 +20,6 @@ import { SerialQueue } from '@aztec/foundation/queue';
20
20
  import { count } from '@aztec/foundation/string';
21
21
  import { DateProvider, Timer } from '@aztec/foundation/timer';
22
22
  import { SiblingPath } from '@aztec/foundation/trees';
23
- import type { AztecKVStore } from '@aztec/kv-store';
24
23
  import { openTmpStore } from '@aztec/kv-store/lmdb';
25
24
  import { RollupAbi } from '@aztec/l1-artifacts';
26
25
  import { SHA256Trunc, StandardTree, UnbalancedTree } from '@aztec/merkle-tree';
@@ -699,14 +698,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
699
698
  }
700
699
 
701
700
  /**
702
- * Returns the index of a l2ToL1Message in a ephemeral l2 to l1 data tree as well as its sibling path.
703
- * @remarks This tree is considered ephemeral because it is created on-demand by: taking all the l2ToL1 messages
704
- * in a single block, and then using them to make a variable depth append-only tree with these messages as leaves.
705
- * The tree is discarded immediately after calculating what we need from it.
701
+ * Returns the index and sibling path for a L2->L1 message in a block's message tree.
702
+ * @remarks The message tree is constructed on-demand by taking all L2->L1 messages in a block
703
+ * and creating a variable depth append-only tree with the messages as leaves.
704
+ * The tree is constructed in two layers:
705
+ * 1. Subtree - For each transaction in the block, a subtree is created containing all L2->L1 messages from that
706
+ * transaction.
707
+ * 2. Top tree - A tree containing the roots of all the subtrees as leaves
708
+ * The final path is constructed by concatenating the path in the subtree with the path in the top tree.
709
+ * When there is only one transaction in the block, the subtree itself becomes the block's L2->L1 message tree,
710
+ * and no top tree is needed. The out hash is the root of the the block's L2->L1 message tree.
706
711
  * TODO: Handle the case where two messages in the same tx have the same hash.
707
- * @param blockNumber - The block number at which to get the data.
708
- * @param l2ToL1Message - The l2ToL1Message get the index / sibling path for.
709
- * @returns A tuple of the index and the sibling path of the L2ToL1Message.
712
+ * @param blockNumber - Block number to get data from
713
+ * @param l2ToL1Message - Message to get index/path for
714
+ * @returns [index, siblingPath] for the message
710
715
  */
711
716
  public async getL2ToL1MessageMembershipWitness(
712
717
  blockNumber: L2BlockNumber,
@@ -715,70 +720,98 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
715
720
  const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
716
721
 
717
722
  if (block === undefined) {
718
- throw new Error('Block is not defined');
723
+ throw new Error('Block not found in getL2ToL1MessageMembershipWitness');
719
724
  }
720
725
 
721
- const l2ToL1Messages = block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
726
+ const messagesPerTx = block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
722
727
 
723
- // Find index of message
724
- let indexOfMsgInSubtree = -1;
725
- const indexOfMsgTx = l2ToL1Messages.findIndex(msgs => {
726
- const idx = msgs.findIndex(msg => msg.equals(l2ToL1Message));
727
- indexOfMsgInSubtree = Math.max(indexOfMsgInSubtree, idx);
728
- return idx !== -1;
729
- });
728
+ // Find index of message in subtree and index of tx in a block
729
+ let messageIndexInTx = -1,
730
+ txIndex = -1;
731
+ {
732
+ txIndex = messagesPerTx.findIndex(messages => {
733
+ const idx = messages.findIndex(msg => msg.equals(l2ToL1Message));
734
+ messageIndexInTx = Math.max(messageIndexInTx, idx);
735
+ return idx !== -1;
736
+ });
737
+ }
730
738
 
731
- if (indexOfMsgTx === -1) {
739
+ if (txIndex === -1) {
732
740
  throw new Error('The L2ToL1Message you are trying to prove inclusion of does not exist');
733
741
  }
734
742
 
735
- const tempStores: AztecKVStore[] = [];
743
+ // Get the message path in subtree and message subtree height
744
+ let messagePathInSubtree: SiblingPath<number>;
745
+ let messageSubtreeHeight: number;
746
+ {
747
+ const subtreeStore = openTmpStore(true);
748
+ const txMessages = messagesPerTx[txIndex];
749
+ messageSubtreeHeight = txMessages.length <= 1 ? 1 : Math.ceil(Math.log2(txMessages.length));
750
+ const subtree = new StandardTree(
751
+ subtreeStore,
752
+ new SHA256Trunc(),
753
+ `subtree_${txIndex}`,
754
+ messageSubtreeHeight,
755
+ 0n,
756
+ Fr,
757
+ );
758
+ subtree.appendLeaves(txMessages);
759
+ messagePathInSubtree = await subtree.getSiblingPath(BigInt(messageIndexInTx), true);
760
+ await subtreeStore.delete();
761
+ }
736
762
 
737
- // Construct message subtrees
738
- const l2toL1Subtrees = l2ToL1Messages.map((msgs, i) => {
739
- const store = openTmpStore(true);
740
- tempStores.push(store);
741
- const treeHeight = msgs.length <= 1 ? 1 : Math.ceil(Math.log2(msgs.length));
742
- const tree = new StandardTree(store, new SHA256Trunc(), `temp_msgs_subtrees_${i}`, treeHeight, 0n, Fr);
743
- tree.appendLeaves(msgs);
744
- return tree;
745
- });
763
+ // If the number of txs is 1 we are dealing with a special case where the tx subtree itself is the whole block's
764
+ // l2 to l1 message tree.
765
+ const numTransactions = block.body.txEffects.length;
766
+ if (numTransactions === 1) {
767
+ return [BigInt(messageIndexInTx), messagePathInSubtree];
768
+ }
746
769
 
747
- // path of the input msg from leaf -> first out hash calculated in base rolllup
748
- const subtreePathOfL2ToL1Message = await l2toL1Subtrees[indexOfMsgTx].getSiblingPath(
749
- BigInt(indexOfMsgInSubtree),
750
- true,
770
+ // Calculate roots for all tx subtrees
771
+ const txSubtreeRoots = await Promise.all(
772
+ messagesPerTx.map(async (messages, txIdx) => {
773
+ // For a tx with no messages, we have to set an out hash of 0 to match what the circuit does.
774
+ if (messages.length === 0) {
775
+ return Fr.ZERO;
776
+ }
777
+
778
+ const txStore = openTmpStore(true);
779
+ const txTreeHeight = messages.length <= 1 ? 1 : Math.ceil(Math.log2(messages.length));
780
+ const txTree = new StandardTree(
781
+ txStore,
782
+ new SHA256Trunc(),
783
+ `tx_messages_subtree_${txIdx}`,
784
+ txTreeHeight,
785
+ 0n,
786
+ Fr,
787
+ );
788
+ txTree.appendLeaves(messages);
789
+ const root = Fr.fromBuffer(txTree.getRoot(true));
790
+ await txStore.delete();
791
+ return root;
792
+ }),
751
793
  );
752
794
 
753
- const numTxs = block.body.txEffects.length;
754
- if (numTxs === 1) {
755
- return [BigInt(indexOfMsgInSubtree), subtreePathOfL2ToL1Message];
795
+ // Construct the top tree and compute the combined path
796
+ let combinedPath: Buffer[];
797
+ {
798
+ const topTreeHeight = Math.ceil(Math.log2(txSubtreeRoots.length));
799
+ // The root of this tree is the out_hash calculated in Noir => we truncate to match Noir's SHA
800
+ const topTree = new UnbalancedTree(new SHA256Trunc(), 'top_tree', topTreeHeight, Fr);
801
+ await topTree.appendLeaves(txSubtreeRoots);
802
+
803
+ const txPathInTopTree = await topTree.getSiblingPath(txSubtreeRoots[txIndex].toBigInt());
804
+ // Append subtree path to top tree path
805
+ combinedPath = messagePathInSubtree.toBufferArray().concat(txPathInTopTree.toBufferArray());
756
806
  }
757
807
 
758
- // For a tx with no messages, we have to set an out hash of 0 to match the circuit/contract behavior
759
- const l2toL1SubtreeRoots = l2toL1Subtrees.map(t =>
760
- t.getNumLeaves(true) == 0n ? Fr.ZERO : Fr.fromBuffer(t.getRoot(true)),
761
- );
762
- const maxTreeHeight = Math.ceil(Math.log2(l2toL1SubtreeRoots.length));
763
- // The root of this tree is the out_hash calculated in Noir => we truncate to match Noir's SHA
764
- const outHashTree = new UnbalancedTree(new SHA256Trunc(), 'temp_outhash_sibling_path', maxTreeHeight, Fr);
765
- await outHashTree.appendLeaves(l2toL1SubtreeRoots);
766
-
767
- const pathOfTxInOutHashTree = await outHashTree.getSiblingPath(l2toL1SubtreeRoots[indexOfMsgTx].toBigInt());
768
- // Append subtree path to out hash tree path
769
- const mergedPath = subtreePathOfL2ToL1Message.toBufferArray().concat(pathOfTxInOutHashTree.toBufferArray());
770
- // Append binary index of subtree path to binary index of out hash tree path
771
- const mergedIndex = parseInt(
772
- indexOfMsgTx
773
- .toString(2)
774
- .concat(indexOfMsgInSubtree.toString(2).padStart(l2toL1Subtrees[indexOfMsgTx].getDepth(), '0')),
808
+ // Append binary index of subtree path to binary index of top tree path
809
+ const combinedIndex = parseInt(
810
+ txIndex.toString(2).concat(messageIndexInTx.toString(2).padStart(messageSubtreeHeight, '0')),
775
811
  2,
776
812
  );
777
813
 
778
- // clear the tmp stores
779
- await Promise.all(tempStores.map(store => store.delete()));
780
-
781
- return [BigInt(mergedIndex), new SiblingPath(mergedPath.length, mergedPath)];
814
+ return [BigInt(combinedIndex), new SiblingPath(combinedPath.length, combinedPath)];
782
815
  }
783
816
 
784
817
  /**