diff --git a/docs/docs/aztec/smart_contracts/functions/attributes.md b/docs/docs/aztec/smart_contracts/functions/attributes.md index e7dc10e8d77..707241b7946 100644 --- a/docs/docs/aztec/smart_contracts/functions/attributes.md +++ b/docs/docs/aztec/smart_contracts/functions/attributes.md @@ -232,8 +232,8 @@ impl CustomNote { } fn get_note_type_id() -> Field { - // Automatically generated unique ID based on Keccak hash of the struct name - 0xd2de93eaab1d59abddf06134e737665f076f556feb7b6d3d72ca557b430b14d2 + // Assigned by macros by incrementing a counter + 2 } fn get_header(note: CustomNote) -> aztec::note::note_header::NoteHeader { diff --git a/docs/docs/migration_notes.md b/docs/docs/migration_notes.md index 2181a6c6785..667276a9fb0 100644 --- a/docs/docs/migration_notes.md +++ b/docs/docs/migration_notes.md @@ -5,6 +5,11 @@ keywords: [sandbox, aztec, notes, migration, updating, upgrading] --- Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them. + +## TBD +### [Aztec.nr] Removal of `getSiblingPath` oracle +Use `getMembershipWitness` oracle instead that returns both the sibling path and index. + ## 0.68.0 ### [archiver, node, pxe] Remove contract artifacts in node and archiver and store function names instead Contract artifacts were only in the archiver for debugging purposes. Instead function names are now (optionally) emitted diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_sibling_path.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_sibling_path.nr deleted file mode 100644 index 6e8edfaa305..00000000000 --- a/noir-projects/aztec-nr/aztec/src/oracle/get_sibling_path.nr +++ /dev/null @@ -1,15 +0,0 @@ -#[oracle(getSiblingPath)] -unconstrained fn get_sibling_path_oracle( - _block_number: u32, - _tree_id: Field, - _leaf_index: Field, -) -> [Field; N] {} - -pub unconstrained fn get_sibling_path( - block_number: u32, - tree_id: Field, - leaf_index: Field, -) -> [Field; N] { - let value: [Field; N] = get_sibling_path_oracle(block_number, tree_id, leaf_index); - value -} diff --git a/noir-projects/aztec-nr/aztec/src/oracle/mod.nr b/noir-projects/aztec-nr/aztec/src/oracle/mod.nr index 8e9d8e1399e..dfbc4d3139b 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/mod.nr @@ -12,7 +12,6 @@ pub mod get_public_data_witness; pub mod get_membership_witness; pub mod keys; pub mod key_validation_request; -pub mod get_sibling_path; pub mod random; pub mod enqueue_public_function_call; pub mod block_header; diff --git a/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr b/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr index 9f371ce0054..2210d7b9210 100644 --- a/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr +++ b/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr @@ -64,8 +64,8 @@ impl NoteInterface for MockNote { } fn get_note_type_id() -> Field { - // randomly chose note type id - 4135 + // randomly chosen note type id --> has to fit within 7 bits + 76 } fn to_be_bytes(self, storage_slot: Field) -> [u8; MOCK_NOTE_LENGTH * 32 + 64] { diff --git a/noir-projects/noir-contracts/contracts/ecdsa_public_key_note/src/lib.nr b/noir-projects/noir-contracts/contracts/ecdsa_public_key_note/src/lib.nr index d571cc6328b..add0bf318a0 100644 --- a/noir-projects/noir-contracts/contracts/ecdsa_public_key_note/src/lib.nr +++ b/noir-projects/noir-contracts/contracts/ecdsa_public_key_note/src/lib.nr @@ -89,13 +89,8 @@ impl NoteInterface for EcdsaPublicKeyNote { } fn get_note_type_id() -> Field { - comptime - { - let bytes = "EcdsaPublicKeyNote".as_bytes(); - let hash = aztec::protocol_types::hash::poseidon2_hash_bytes(bytes); - let hash_bytes = hash.to_be_bytes::<4>(); - aztec::protocol_types::utils::field::field_from_bytes(hash_bytes, true) - } + // randomly chosen note type id --> has to fit within 7 bits + 76 } fn get_header(self) -> NoteHeader { diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts index 55726855a04..b55f7275803 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts @@ -48,7 +48,7 @@ import { TxReceipt } from '../tx/tx_receipt.js'; import { TxEffect } from '../tx_effect.js'; import { type AztecNode, AztecNodeApiSchema } from './aztec-node.js'; import { type SequencerConfig } from './configs.js'; -import { NullifierMembershipWitness } from './nullifier_tree.js'; +import { NullifierMembershipWitness } from './nullifier_membership_witness.js'; import { type ProverConfig } from './prover-client.js'; describe('AztecNodeApiSchema', () => { diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index 9b877575949..621c3636e44 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -49,7 +49,7 @@ import { import { TxEffect } from '../tx_effect.js'; import { type SequencerConfig, SequencerConfigSchema } from './configs.js'; import { type L2BlockNumber, L2BlockNumberSchema } from './l2_block_number.js'; -import { NullifierMembershipWitness } from './nullifier_tree.js'; +import { NullifierMembershipWitness } from './nullifier_membership_witness.js'; import { type ProverConfig, ProverConfigSchema } from './prover-client.js'; import { type ProverCoordination, ProverCoordinationApiSchema } from './prover-coordination.js'; diff --git a/yarn-project/circuit-types/src/interfaces/index.ts b/yarn-project/circuit-types/src/interfaces/index.ts index 2b880ad7550..86380b3b9bb 100644 --- a/yarn-project/circuit-types/src/interfaces/index.ts +++ b/yarn-project/circuit-types/src/interfaces/index.ts @@ -6,7 +6,7 @@ export * from './configs.js'; export * from './epoch-prover.js'; export * from './l2_block_number.js'; export * from './merkle_tree_operations.js'; -export * from './nullifier_tree.js'; +export * from './nullifier_membership_witness.js'; export * from './private_kernel_prover.js'; export * from './processed-tx-handler.js'; export * from './prover-agent.js'; diff --git a/yarn-project/circuit-types/src/interfaces/nullifier_tree.ts b/yarn-project/circuit-types/src/interfaces/nullifier_membership_witness.ts similarity index 100% rename from yarn-project/circuit-types/src/interfaces/nullifier_tree.ts rename to yarn-project/circuit-types/src/interfaces/nullifier_membership_witness.ts diff --git a/yarn-project/foundation/src/abi/note_selector.ts b/yarn-project/foundation/src/abi/note_selector.ts index d02e0601a8d..862ee55d700 100644 --- a/yarn-project/foundation/src/abi/note_selector.ts +++ b/yarn-project/foundation/src/abi/note_selector.ts @@ -28,7 +28,7 @@ export class NoteSelector extends Selector { const reader = BufferReader.asReader(buffer); const value = Number(toBigIntBE(reader.readBytes(Selector.SIZE))); if (value >= 1 << 7) { - throw new Error('Invalid note selector'); + throw new Error(`Invalid note selector: ${value}`); } return new NoteSelector(value); } diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 61c578ec8ba..7b3d332738e 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -163,7 +163,7 @@ export class SimulatorOracle implements DBOracle { * @returns - The index of the commitment. Undefined if it does not exist in the tree. */ async getCommitmentIndex(commitment: Fr) { - return await this.findLeafIndex('latest', MerkleTreeId.NOTE_HASH_TREE, commitment); + return await this.#findLeafIndex('latest', MerkleTreeId.NOTE_HASH_TREE, commitment); } // We need this in public as part of the EXISTS calls - but isn't used in private @@ -172,19 +172,26 @@ export class SimulatorOracle implements DBOracle { } async getNullifierIndex(nullifier: Fr) { - return await this.findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier); + return await this.#findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier); } - public async findLeafIndex( - blockNumber: L2BlockNumber, - treeId: MerkleTreeId, - leafValue: Fr, - ): Promise { + async #findLeafIndex(blockNumber: L2BlockNumber, treeId: MerkleTreeId, leafValue: Fr): Promise { const [leafIndex] = await this.aztecNode.findLeavesIndexes(blockNumber, treeId, [leafValue]); return leafIndex; } - public async getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: bigint): Promise { + public async getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise { + const leafIndex = await this.#findLeafIndex(blockNumber, treeId, leafValue); + if (!leafIndex) { + throw new Error(`Leaf value: ${leafValue} not found in ${MerkleTreeId[treeId]}`); + } + + const siblingPath = await this.#getSiblingPath(blockNumber, treeId, leafIndex); + + return [new Fr(leafIndex), ...siblingPath]; + } + + async #getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: bigint): Promise { switch (treeId) { case MerkleTreeId.NULLIFIER_TREE: return (await this.aztecNode.getNullifierSiblingPath(blockNumber, leafIndex)).toFields(); diff --git a/yarn-project/simulator/src/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index 9aa79e9a288..2e16f58535c 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -95,19 +95,6 @@ export class Oracle { return witness.map(toACVMField); } - async getSiblingPath( - [blockNumber]: ACVMField[], - [treeId]: ACVMField[], - [leafIndex]: ACVMField[], - ): Promise { - const parsedBlockNumber = frToNumber(fromACVMField(blockNumber)); - const parsedTreeId = frToNumber(fromACVMField(treeId)); - const parsedLeafIndex = fromACVMField(leafIndex); - - const path = await this.typedOracle.getSiblingPath(parsedBlockNumber, parsedTreeId, parsedLeafIndex); - return path.map(toACVMField); - } - async getNullifierMembershipWitness( [blockNumber]: ACVMField[], [nullifier]: ACVMField[], // nullifier, we try to find the witness for (to prove inclusion) diff --git a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts index 21085bd6ab8..cd529fdd3ac 100644 --- a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts @@ -108,10 +108,6 @@ export abstract class TypedOracle { throw new OracleMethodNotAvailableError('getMembershipWitness'); } - getSiblingPath(_blockNumber: number, _treeId: MerkleTreeId, _leafIndex: Fr): Promise { - throw new OracleMethodNotAvailableError('getSiblingPath'); - } - getNullifierMembershipWitness(_blockNumber: number, _nullifier: Fr): Promise { throw new OracleMethodNotAvailableError('getNullifierMembershipWitness'); } diff --git a/yarn-project/simulator/src/client/db_oracle.ts b/yarn-project/simulator/src/client/db_oracle.ts index 65cd0108f38..1cc2e565009 100644 --- a/yarn-project/simulator/src/client/db_oracle.ts +++ b/yarn-project/simulator/src/client/db_oracle.ts @@ -1,6 +1,5 @@ import { type L2Block, - type L2BlockNumber, type MerkleTreeId, type NoteStatus, type NullifierMembershipWitness, @@ -141,22 +140,13 @@ export interface DBOracle extends CommitmentsDB { getBlockHeader(): Promise; /** - * Fetch the index of the leaf in the respective tree - * @param blockNumber - The block number at which to get the leaf index. - * @param treeId - The id of the tree to search. - * @param leafValue - The leaf value buffer. - * @returns - The index of the leaf. Undefined if it does not exist in the tree. + * Fetches the index and sibling path of a leaf at a given block from a given tree. + * @param blockNumber - The block number at which to get the membership witness. + * @param treeId - Id of the tree to get the sibling path from. + * @param leafValue - The leaf value + * @returns The index and sibling path concatenated [index, sibling_path] */ - findLeafIndex(blockNumber: L2BlockNumber, treeId: MerkleTreeId, leafValue: Fr): Promise; - - /** - * Fetch the sibling path of the leaf in the respective tree - * @param blockNumber - The block number at which to get the sibling path. - * @param treeId - The id of the tree to search. - * @param leafIndex - The index of the leaf. - * @returns - The sibling path of the leaf. - */ - getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: bigint): Promise; + getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise; /** * Returns a nullifier membership witness for a given nullifier at a given block. diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index 869ee86984e..90c27681434 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -2,7 +2,7 @@ import { type AuthWitness, type AztecNode, type CompleteAddress, - MerkleTreeId, + type MerkleTreeId, type NoteStatus, type NullifierMembershipWitness, type PublicDataWitness, @@ -72,24 +72,8 @@ export class ViewDataOracle extends TypedOracle { * @param leafValue - The leaf value * @returns The index and sibling path concatenated [index, sibling_path] */ - public override async getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise { - const index = await this.db.findLeafIndex(blockNumber, treeId, leafValue); - if (!index) { - throw new Error(`Leaf value: ${leafValue} not found in ${MerkleTreeId[treeId]}`); - } - const siblingPath = await this.db.getSiblingPath(blockNumber, treeId, index); - return [new Fr(index), ...siblingPath]; - } - - /** - * Fetches a sibling path at a given block and index from a tree specified by `treeId`. - * @param blockNumber - The block number at which to get the membership witness. - * @param treeId - Id of the tree to get the sibling path from. - * @param leafIndex - Index of the leaf to get sibling path for - * @returns The sibling path. - */ - public override getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: Fr): Promise { - return this.db.getSiblingPath(blockNumber, treeId, leafIndex.toBigInt()); + public override getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise { + return this.db.getMembershipWitness(blockNumber, treeId, leafValue); } /** diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index 983f6f27df7..e0b46aa45b5 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -334,15 +334,6 @@ export class TXEService { return toForeignCallResult([toArray(witness.toFields())]); } - async getSiblingPath(blockNumber: ForeignCallSingle, treeId: ForeignCallSingle, leafIndex: ForeignCallSingle) { - const result = await this.typedOracle.getSiblingPath( - fromSingle(blockNumber).toNumber(), - fromSingle(treeId).toNumber(), - fromSingle(leafIndex), - ); - return toForeignCallResult([toArray(result)]); - } - async getNotes( storageSlot: ForeignCallSingle, numSelects: ForeignCallSingle,