From c99870bf058789888ce3a177d562ccff00210337 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 28 Nov 2023 08:25:28 +0000 Subject: [PATCH] getPublicDataTreeSiblingPath --- .../aztec-node/src/aztec-node/server.ts | 19 +++++++++++++++---- .../inclusion_proofs_contract/src/main.nr | 2 +- .../pxe/src/simulator_oracle/index.ts | 2 ++ .../types/src/interfaces/state_provider.ts | 17 +++++++++++++---- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index adf07a88e49a..99d46bcb797e 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -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'; @@ -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. */ @@ -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. */ @@ -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. */ @@ -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. */ @@ -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> { + 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. diff --git a/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr index a41aeebba0e1..ae5419ff862f 100644 --- a/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr @@ -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" ); } diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 27c415b2706e..475be717d07a 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -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'); } diff --git a/yarn-project/types/src/interfaces/state_provider.ts b/yarn-project/types/src/interfaces/state_provider.ts index 958750eb6911..f26c3d56b254 100644 --- a/yarn-project/types/src/interfaces/state_provider.ts +++ b/yarn-project/types/src/interfaces/state_provider.ts @@ -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'; @@ -25,7 +26,7 @@ export interface StateInfoProvider { findLeafIndex(treeId: MerkleTreeId, leafValue: Fr): Promise; /** - * 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 @@ -33,7 +34,7 @@ export interface StateInfoProvider { getContractSiblingPath(leafIndex: bigint): Promise>; /** - * 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 @@ -49,7 +50,7 @@ export interface StateInfoProvider { getL1ToL2MessageAndIndex(messageKey: Fr): Promise; /** - * 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 @@ -57,13 +58,21 @@ export interface StateInfoProvider { getL1ToL2MessageSiblingPath(leafIndex: bigint): Promise>; /** - * 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>; + /** + * 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>; + /** * 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.