From a6a4bcaf826b28fbf97d9d25cc19d31239a3de5d Mon Sep 17 00:00:00 2001
From: benesjan <janbenes1234@gmail.com>
Date: Thu, 23 Nov 2023 13:47:42 +0000
Subject: [PATCH] fix

---
 .../aztec-node/src/aztec-node/server.ts       | 13 +++++++++++++
 .../pxe/src/simulator_oracle/index.ts         | 11 ++++-------
 .../types/src/interfaces/state_provider.ts    | 19 ++++++++++++++++++-
 3 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts
index b528a699343d..b1cd9fc93467 100644
--- a/yarn-project/aztec-node/src/aztec-node/server.ts
+++ b/yarn-project/aztec-node/src/aztec-node/server.ts
@@ -3,6 +3,7 @@ import {
   CONTRACT_TREE_HEIGHT,
   Fr,
   GlobalVariables,
+  HISTORIC_BLOCKS_TREE_HEIGHT,
   HistoricBlockData,
   L1_TO_L2_MSG_TREE_HEIGHT,
   NOTE_HASH_TREE_HEIGHT,
@@ -339,6 +340,18 @@ export class AztecNodeService implements AztecNode {
     return committedDb.getSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGES_TREE, leafIndex);
   }
 
+  /**
+   * Returns the sibling path for a leaf in the committed historic blocks tree.
+   * @param leafIndex - Index of the leaf in the tree.
+   * @returns The sibling path.
+   */
+  public async getHistoricBlocksTreeSiblingPath(
+    leafIndex: bigint,
+  ): Promise<SiblingPath<typeof HISTORIC_BLOCKS_TREE_HEIGHT>> {
+    const committedDb = await this.#getWorldState();
+    return committedDb.getSiblingPath(MerkleTreeId.BLOCKS_TREE, leafIndex);
+  }
+
   /**
    * Gets the storage value at the given contract storage slot.
    *
diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts
index faf2129b5ceb..15502abd0111 100644
--- a/yarn-project/pxe/src/simulator_oracle/index.ts
+++ b/yarn-project/pxe/src/simulator_oracle/index.ts
@@ -138,22 +138,19 @@ export class SimulatorOracle implements DBOracle {
 
   public async findLeafIndex(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined> {
     this.log.warn('Block number ignored in SimulatorOracle.findLeafIndex because archival node is not yet implemented');
-    switch (treeId) {
-      case MerkleTreeId.NOTE_HASH_TREE:
-        return await this.stateInfoProvider.findLeafIndex(treeId, leafValue);
-      default:
-        throw new Error('Not implemented');
-    }
+    return await this.stateInfoProvider.findLeafIndex(treeId, leafValue);
   }
 
   public async getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: bigint): Promise<Fr[]> {
     this.log.warn(
       'Block number ignored in SimulatorOracle.getSiblingPath because archival node is not yet implemented',
     );
-    // @todo This is doing a nasty workaround as http_rpc_client was not happy about a generic `getSiblingPath` function being exposed.
+    // @todo Doing a nasty workaround here because of https://github.com/AztecProtocol/aztec-packages/issues/3414
     switch (treeId) {
       case MerkleTreeId.NOTE_HASH_TREE:
         return (await this.stateInfoProvider.getNoteHashSiblingPath(leafIndex)).toFieldArray();
+      case MerkleTreeId.BLOCKS_TREE:
+        return (await this.stateInfoProvider.getHistoricBlocksTreeSiblingPath(leafIndex)).toFieldArray();
       default:
         throw new Error('Not implemented');
     }
diff --git a/yarn-project/types/src/interfaces/state_provider.ts b/yarn-project/types/src/interfaces/state_provider.ts
index a08347cee397..bfef6db4d9ee 100644
--- a/yarn-project/types/src/interfaces/state_provider.ts
+++ b/yarn-project/types/src/interfaces/state_provider.ts
@@ -1,4 +1,10 @@
-import { CONTRACT_TREE_HEIGHT, Fr, L1_TO_L2_MSG_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT } from '@aztec/circuits.js';
+import {
+  CONTRACT_TREE_HEIGHT,
+  Fr,
+  HISTORIC_BLOCKS_TREE_HEIGHT,
+  L1_TO_L2_MSG_TREE_HEIGHT,
+  NOTE_HASH_TREE_HEIGHT,
+} from '@aztec/circuits.js';
 
 import { L1ToL2MessageAndIndex } from '../l1_to_l2_message.js';
 import { MerkleTreeId } from '../merkle_tree_id.js';
@@ -20,6 +26,7 @@ export interface StateInfoProvider {
    * Returns the sibling path for the given index in the contract tree.
    * @param leafIndex - The index of the leaf for which the sibling path is required.
    * @returns The sibling path for the leaf index.
+   * TODO: https://github.com/AztecProtocol/aztec-packages/issues/3414
    */
   getContractSiblingPath(leafIndex: bigint): Promise<SiblingPath<typeof CONTRACT_TREE_HEIGHT>>;
 
@@ -27,6 +34,7 @@ export interface StateInfoProvider {
    * Returns the sibling path for the given index in the note hash tree.
    * @param leafIndex - The index of the leaf for which the sibling path is required.
    * @returns The sibling path for the leaf index.
+   * TODO: https://github.com/AztecProtocol/aztec-packages/issues/3414
    */
   getNoteHashSiblingPath(leafIndex: bigint): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>>;
 
@@ -42,6 +50,15 @@ export interface StateInfoProvider {
    * Returns the sibling path for a leaf in the committed l1 to l2 data tree.
    * @param leafIndex - Index of the leaf in the tree.
    * @returns The sibling path.
+   * TODO: https://github.com/AztecProtocol/aztec-packages/issues/3414
    */
   getL1ToL2MessageSiblingPath(leafIndex: bigint): Promise<SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>>;
+
+  /**
+   * Returns the sibling path for a leaf in the committed historic blocks tree.
+   * @param leafIndex - Index of the leaf in the tree.
+   * @returns The sibling path.
+   * TODO: https://github.com/AztecProtocol/aztec-packages/issues/3414
+   */
+  getHistoricBlocksTreeSiblingPath(leafIndex: bigint): Promise<SiblingPath<typeof HISTORIC_BLOCKS_TREE_HEIGHT>>;
 }