Skip to content

Commit

Permalink
refactor: nuke unused getSiblingPath oracle (#11090)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Jan 8, 2025
1 parent 137ade8 commit 36b640a
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 100 deletions.
4 changes: 2 additions & 2 deletions docs/docs/aztec/smart_contracts/functions/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions noir-projects/aztec-nr/aztec/src/oracle/get_sibling_path.nr

This file was deleted.

1 change: 0 additions & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ impl NoteInterface<MOCK_NOTE_LENGTH> 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] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,8 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/abi/note_selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
23 changes: 15 additions & 8 deletions yarn-project/pxe/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<bigint | undefined> {
async #findLeafIndex(blockNumber: L2BlockNumber, treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined> {
const [leafIndex] = await this.aztecNode.findLeavesIndexes(blockNumber, treeId, [leafValue]);
return leafIndex;
}

public async getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: bigint): Promise<Fr[]> {
public async getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
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<Fr[]> {
switch (treeId) {
case MerkleTreeId.NULLIFIER_TREE:
return (await this.aztecNode.getNullifierSiblingPath(blockNumber, leafIndex)).toFields();
Expand Down
13 changes: 0 additions & 13 deletions yarn-project/simulator/src/acvm/oracle/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,6 @@ export class Oracle {
return witness.map(toACVMField);
}

async getSiblingPath(
[blockNumber]: ACVMField[],
[treeId]: ACVMField[],
[leafIndex]: ACVMField[],
): Promise<ACVMField[]> {
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)
Expand Down
4 changes: 0 additions & 4 deletions yarn-project/simulator/src/acvm/oracle/typed_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ export abstract class TypedOracle {
throw new OracleMethodNotAvailableError('getMembershipWitness');
}

getSiblingPath(_blockNumber: number, _treeId: MerkleTreeId, _leafIndex: Fr): Promise<Fr[]> {
throw new OracleMethodNotAvailableError('getSiblingPath');
}

getNullifierMembershipWitness(_blockNumber: number, _nullifier: Fr): Promise<NullifierMembershipWitness | undefined> {
throw new OracleMethodNotAvailableError('getNullifierMembershipWitness');
}
Expand Down
22 changes: 6 additions & 16 deletions yarn-project/simulator/src/client/db_oracle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
type L2Block,
type L2BlockNumber,
type MerkleTreeId,
type NoteStatus,
type NullifierMembershipWitness,
Expand Down Expand Up @@ -141,22 +140,13 @@ export interface DBOracle extends CommitmentsDB {
getBlockHeader(): Promise<BlockHeader>;

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

/**
* 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<Fr[]>;
getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]>;

/**
* Returns a nullifier membership witness for a given nullifier at a given block.
Expand Down
22 changes: 3 additions & 19 deletions yarn-project/simulator/src/client/view_data_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
type AuthWitness,
type AztecNode,
type CompleteAddress,
MerkleTreeId,
type MerkleTreeId,
type NoteStatus,
type NullifierMembershipWitness,
type PublicDataWitness,
Expand Down Expand Up @@ -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<Fr[]> {
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<Fr[]> {
return this.db.getSiblingPath(blockNumber, treeId, leafIndex.toBigInt());
public override getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
return this.db.getMembershipWitness(blockNumber, treeId, leafValue);
}

/**
Expand Down
9 changes: 0 additions & 9 deletions yarn-project/txe/src/txe_service/txe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 36b640a

Please sign in to comment.