Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Nov 23, 2023
1 parent db350b0 commit a6a4bca
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
13 changes: 13 additions & 0 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
*
Expand Down
11 changes: 4 additions & 7 deletions yarn-project/pxe/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
19 changes: 18 additions & 1 deletion yarn-project/types/src/interfaces/state_provider.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,13 +26,15 @@ 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>>;

/**
* 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>>;

Expand All @@ -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>>;
}

0 comments on commit a6a4bca

Please sign in to comment.