Skip to content

Commit

Permalink
getPublicDataTreeSiblingPath
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Nov 28, 2023
1 parent 2d5e038 commit c99870b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
19 changes: 15 additions & 4 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
L1_TO_L2_MSG_TREE_HEIGHT,
NOTE_HASH_TREE_HEIGHT,
NULLIFIER_TREE_HEIGHT,
PUBLIC_DATA_TREE_HEIGHT,
} from '@aztec/circuits.js';
import { computePublicDataTreeIndex } from '@aztec/circuits.js/abis';
import { L1ContractAddresses, createEthereumChain } from '@aztec/ethereum';
Expand Down Expand Up @@ -300,7 +301,7 @@ export class AztecNodeService implements AztecNode {
}

/**
* Returns the sibling path for the given index in the contract tree.
* Returns a 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.
*/
Expand All @@ -310,7 +311,7 @@ export class AztecNodeService implements AztecNode {
}

/**
* Returns the sibling path for the given index in the data tree.
* Returns a sibling path for the given index in the data tree.
* @param leafIndex - The index of the leaf for which the sibling path is required.
* @returns The sibling path for the leaf index.
*/
Expand All @@ -333,7 +334,7 @@ export class AztecNodeService implements AztecNode {
}

/**
* Returns the sibling path for a leaf in the committed l1 to l2 data tree.
* Returns a 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.
*/
Expand All @@ -343,7 +344,7 @@ export class AztecNodeService implements AztecNode {
}

/**
* Returns the sibling path for a leaf in the committed historic blocks tree.
* Returns a sibling path for a leaf in the committed historic blocks tree.
* @param leafIndex - Index of the leaf in the tree.
* @returns The sibling path.
*/
Expand All @@ -354,6 +355,16 @@ export class AztecNodeService implements AztecNode {
return committedDb.getSiblingPath(MerkleTreeId.BLOCKS_TREE, leafIndex);
}

/**
* Returns a sibling path for a leaf in the committed public data tree.
* @param leafIndex - Index of the leaf in the tree.
* @returns The sibling path.
*/
public async getPublicDataTreeSiblingPath(leafIndex: bigint): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
const committedDb = await this.#getWorldState();
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
}

/**
* Returns a low nullifier membership witness for a given nullifier at a given block.
* @param blockNumber - The block number at which to get the index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ contract InclusionProofs {

// 8)
assert(
block_data.note_hash_tree_root == compute_merkle_root(public_value, public_value_leaf_index, path),
block_data.public_data_tree_root == compute_merkle_root(public_value, public_value_leaf_index, path),
"Proving membership of a value in public data tree failed"
);
}
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/pxe/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export class SimulatorOracle implements DBOracle {
return (await this.stateInfoProvider.getNoteHashSiblingPath(leafIndex)).toFieldArray();
case MerkleTreeId.BLOCKS_TREE:
return (await this.stateInfoProvider.getHistoricBlocksTreeSiblingPath(leafIndex)).toFieldArray();
case MerkleTreeId.PUBLIC_DATA_TREE:
return (await this.stateInfoProvider.getPublicDataTreeSiblingPath(leafIndex)).toFieldArray();
default:
throw new Error('Not implemented');
}
Expand Down
17 changes: 13 additions & 4 deletions yarn-project/types/src/interfaces/state_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
HISTORIC_BLOCKS_TREE_HEIGHT,
L1_TO_L2_MSG_TREE_HEIGHT,
NOTE_HASH_TREE_HEIGHT,
PUBLIC_DATA_TREE_HEIGHT,
} from '@aztec/circuits.js';

import { L1ToL2MessageAndIndex } from '../l1_to_l2_message.js';
Expand All @@ -25,15 +26,15 @@ export interface StateInfoProvider {
findLeafIndex(treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined>;

/**
* Returns the sibling path for the given index in the contract tree.
* Returns a 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.
* Returns a 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
Expand All @@ -49,21 +50,29 @@ export interface StateInfoProvider {
getL1ToL2MessageAndIndex(messageKey: Fr): Promise<L1ToL2MessageAndIndex>;

/**
* Returns the sibling path for a leaf in the committed l1 to l2 data tree.
* Returns a 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.
* Returns a 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>>;

/**
* Returns a sibling path for a leaf in the committed public data tree.
* @param leafIndex - Index of the leaf in the tree.
* @returns The sibling path.
* TODO: https://github.com/AztecProtocol/aztec-packages/issues/3414
*/
getPublicDataTreeSiblingPath(leafIndex: bigint): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>>;

/**
* Returns a low nullifier membership witness for a given nullifier at a given block.
* @param blockNumber - The block number at which to get the index.
Expand Down

0 comments on commit c99870b

Please sign in to comment.