Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Mar 17, 2024
1 parent fef5549 commit ee492ca
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
20 changes: 10 additions & 10 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export class AztecNodeService implements AztecNode {
* @returns The index of the given leaf in the given tree or undefined if not found.
*/
public async findLeafIndex(
blockNumber: number | 'latest',
blockNumber: BlockNumber,
treeId: MerkleTreeId,
leafValue: Fr,
): Promise<bigint | undefined> {
Expand All @@ -342,7 +342,7 @@ export class AztecNodeService implements AztecNode {
* @returns The sibling path for the leaf index.
*/
public async getNullifierSiblingPath(
blockNumber: number | 'latest',
blockNumber: BlockNumber,
leafIndex: bigint,
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
const committedDb = await this.#getWorldState(blockNumber);
Expand All @@ -356,7 +356,7 @@ export class AztecNodeService implements AztecNode {
* @returns The sibling path for the leaf index.
*/
public async getNoteHashSiblingPath(
blockNumber: number | 'latest',
blockNumber: BlockNumber,
leafIndex: bigint,
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
const committedDb = await this.#getWorldState(blockNumber);
Expand Down Expand Up @@ -393,7 +393,7 @@ export class AztecNodeService implements AztecNode {
* @returns A tuple of the index and the sibling path of the L2ToL1Message.
*/
public async getL2ToL1MessageIndexAndSiblingPath(
blockNumber: number | 'latest',
blockNumber: BlockNumber,
l2ToL1Message: Fr,
): Promise<[number, SiblingPath<number>]> {
const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
Expand Down Expand Up @@ -431,7 +431,7 @@ export class AztecNodeService implements AztecNode {
* @returns The sibling path.
*/
public async getArchiveSiblingPath(
blockNumber: number | 'latest',
blockNumber: BlockNumber,
leafIndex: bigint,
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
const committedDb = await this.#getWorldState(blockNumber);
Expand All @@ -445,7 +445,7 @@ export class AztecNodeService implements AztecNode {
* @returns The sibling path.
*/
public async getPublicDataSiblingPath(
blockNumber: number | 'latest',
blockNumber: BlockNumber,
leafIndex: bigint,
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
const committedDb = await this.#getWorldState(blockNumber);
Expand All @@ -459,7 +459,7 @@ export class AztecNodeService implements AztecNode {
* @returns The nullifier membership witness (if found).
*/
public async getNullifierMembershipWitness(
blockNumber: number | 'latest',
blockNumber: BlockNumber,
nullifier: Fr,
): Promise<NullifierMembershipWitness | undefined> {
const db = await this.#getWorldState(blockNumber);
Expand Down Expand Up @@ -498,7 +498,7 @@ export class AztecNodeService implements AztecNode {
* TODO: This is a confusing behavior and we should eventually address that.
*/
public async getLowNullifierMembershipWitness(
blockNumber: number | 'latest',
blockNumber: BlockNumber,
nullifier: Fr,
): Promise<NullifierMembershipWitness | undefined> {
const committedDb = await this.#getWorldState(blockNumber);
Expand All @@ -519,7 +519,7 @@ export class AztecNodeService implements AztecNode {
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
}

async getPublicDataTreeWitness(blockNumber: number | 'latest', leafSlot: Fr): Promise<PublicDataWitness | undefined> {
async getPublicDataTreeWitness(blockNumber: BlockNumber, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
const committedDb = await this.#getWorldState(blockNumber);
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
if (!lowLeafResult) {
Expand Down Expand Up @@ -631,7 +631,7 @@ export class AztecNodeService implements AztecNode {
* @param blockNumber - The block number at which to get the data.
* @returns An instance of a committed MerkleTreeOperations
*/
async #getWorldState(blockNumber: number | 'latest') {
async #getWorldState(blockNumber: BlockNumber) {
if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM) {
throw new Error('Invalid block number to get world state for: ' + blockNumber);
}
Expand Down
4 changes: 1 addition & 3 deletions yarn-project/circuit-types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import { MerkleTreeId } from '../merkle_tree_id.js';
import { SiblingPath } from '../sibling_path/index.js';
import { Tx, TxHash, TxReceipt } from '../tx/index.js';
import { TxEffect } from '../tx_effect.js';
import { BlockNumber } from './block_number.js';
import { SequencerConfig } from './configs.js';
import { NullifierMembershipWitness } from './nullifier_tree.js';
import { PublicDataWitness } from './public_data_tree.js';

/** Helper type for a specific L2 block number or the latest block number */
export type BlockNumber = number | 'latest';

/**
* The aztec node.
* We will probably implement the additional interfaces by means other than Aztec Node as it's currently a privacy leak
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/circuit-types/src/interfaces/block_number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** Helper type for a specific L2 block number or the latest block number */
export type BlockNumber = number | 'latest';
1 change: 1 addition & 0 deletions yarn-project/circuit-types/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './aztec-node.js';
export * from './block_number.js';
export * from './pxe.js';
export * from './deployed-contract.js';
export * from './sync-status.js';
Expand Down

0 comments on commit ee492ca

Please sign in to comment.