From 0c3abb08b5c9d23953d5c9f2714f7776c4eab200 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Tue, 1 Aug 2023 15:52:12 -0300 Subject: [PATCH] Move docs around! --- .../acir-simulator/src/client/db_oracle.ts | 43 ++++++ yarn-project/acir-simulator/src/public/db.ts | 19 +++ .../src/aztec_rpc_server/aztec_rpc_server.ts | 139 ----------------- .../aztec-rpc/src/database/database.ts | 110 +++++++++++++ .../aztec-rpc/src/database/memory_db.ts | 81 ---------- .../aztec-rpc/src/kernel_oracle/index.ts | 39 ----- .../src/kernel_prover/proof_creator.ts | 57 +++---- .../src/kernel_prover/proving_data_oracle.ts | 43 ++++++ .../aztec-rpc/src/simulator_oracle/index.ts | 39 ----- .../src/account_impl/account_collection.ts | 6 - .../aztec.js/src/account_impl/index.ts | 12 +- .../barretenberg/crypto/signature/index.ts | 14 ++ .../foundation/src/mutex/mutex_database.ts | 3 + .../src/transport/interface/connector.ts | 1 + .../src/transport/interface/listener.ts | 5 +- .../src/transport/interface/socket.ts | 3 + .../src/transport/transport_client.ts | 6 +- .../foundation/src/wasm/worker/data_store.ts | 12 ++ .../src/wasm/worker/node/node_data_store.ts | 10 -- yarn-project/key-store/src/key_pair.ts | 12 -- yarn-project/key-store/src/test_key_store.ts | 27 ---- yarn-project/merkle-tree/src/pedersen.ts | 27 ---- yarn-project/p2p/src/client/p2p_client.ts | 5 +- .../global_variable_builder/global_builder.ts | 17 ++ .../global_variable_builder/viem-reader.ts | 12 -- .../sequencer-client/src/prover/index.ts | 26 ++++ .../sequencer-client/src/simulator/index.ts | 4 +- .../src/simulator/public_executor.ts | 16 -- yarn-project/types/src/contract_database.ts | 15 ++ .../types/src/interfaces/aztec-node.ts | 1 + .../types/src/interfaces/aztec_rpc.ts | 145 +++++++++++++++++- yarn-project/types/src/interfaces/hasher.ts | 30 ++++ yarn-project/types/src/keys/key_pair.ts | 10 ++ yarn-project/types/src/keys/key_store.ts | 27 ++++ .../server_world_state_synchroniser.ts | 19 --- .../synchroniser/world_state_synchroniser.ts | 23 +++ 36 files changed, 596 insertions(+), 462 deletions(-) diff --git a/yarn-project/acir-simulator/src/client/db_oracle.ts b/yarn-project/acir-simulator/src/client/db_oracle.ts index 7110525be8cb..37a6270f5792 100644 --- a/yarn-project/acir-simulator/src/client/db_oracle.ts +++ b/yarn-project/acir-simulator/src/client/db_oracle.ts @@ -71,9 +71,52 @@ export interface CommitmentDataOracleInputs { * The database oracle interface. */ export interface DBOracle extends CommitmentsDB { + /** + * Retrieve the public key associated to a given address. + * @param address - Address to fetch the pubkey for. + * @returns A public key and the corresponding partial contract address, such that the hash of the two resolves to the input address. + */ getPublicKey(address: AztecAddress): Promise<[PublicKey, PartialContractAddress]>; + + /** + * Retrieve the secret key associated with a specific public key. + * The function only allows access to the secret keys of the transaction creator, + * and throws an error if the address does not match the public key address of the key pair. + * + * @param contractAddress - The contract address. Ignored here. But we might want to return different keys for different contracts. + * @param pubKey - The public key of an account. + * @returns A Promise that resolves to the secret key as a Buffer. + * @throws An Error if the input address does not match the public key address of the key pair. + */ getSecretKey(contractAddress: AztecAddress, pubKey: PublicKey): Promise; + + /** + * Retrieves a set of notes stored in the database for a given contract address and storage slot. + * The query result is paginated using 'limit' and 'offset' values. + * Returns an object containing an array of note data, including preimage, nonce, and index for each note. + * + * @param contractAddress - The AztecAddress instance representing the contract address. + * @param storageSlot - The Fr instance representing the storage slot of the notes. + * @returns A Promise that resolves to an array of note data. + */ getNotes(contractAddress: AztecAddress, storageSlot: Fr): Promise; + + /** + * Retrieve the ABI information of a specific function within a contract. + * The function is identified by its selector, which is a unique identifier generated from the function signature. + * + * @param contractAddress - The contract address. + * @param functionSelector - The Buffer containing the function selector bytes. + * @returns A Promise that resolves to a FunctionAbi object containing the ABI information of the target function. + */ getFunctionABI(contractAddress: AztecAddress, functionSelector: Buffer): Promise; + + /** + * Retrieves the portal contract address associated with the given contract address. + * Throws an error if the input contract address is not found or invalid. + * + * @param contractAddress - The address of the contract whose portal address is to be fetched. + * @returns A Promise that resolves to an EthAddress instance, representing the portal contract address. + */ getPortalContractAddress(contractAddress: AztecAddress): Promise; } diff --git a/yarn-project/acir-simulator/src/public/db.ts b/yarn-project/acir-simulator/src/public/db.ts index dd3f94a2ae70..f03c075b4240 100644 --- a/yarn-project/acir-simulator/src/public/db.ts +++ b/yarn-project/acir-simulator/src/public/db.ts @@ -21,6 +21,7 @@ export interface PublicStateDB { * @param contract - Owner of the storage. * @param slot - Slot to read in the contract storage. * @param newValue - The new value to store. + * @returns Nothing. */ storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise; } @@ -55,7 +56,25 @@ export interface PublicContractsDB { /** Database interface for providing access to commitment tree and l1 to l2 messages tree (append only data trees). */ export interface CommitmentsDB { + /** + * Gets a confirmed L1 to L2 message for the given message key. + * TODO(Maddiaa): Can be combined with aztec-node method that does the same thing. + * @param msgKey - The message Key. + * @returns - The l1 to l2 message object + */ getL1ToL2Message(msgKey: Fr): Promise; + + /** + * Gets a message index and sibling path to some commitment in the private data tree. + * @param address - The contract address owning storage. + * @param commitment - The preimage of the siloed data. + * @returns - The Commitment data oracle object + */ getCommitmentOracle(address: AztecAddress, commitment: Fr): Promise; + + /** + * Gets the current tree roots from the merkle db. + * @returns current tree roots. + */ getTreeRoots(): PrivateHistoricTreeRoots; } diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts index 625b57abcfce..375b388919ed 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts @@ -86,14 +86,6 @@ export class AztecRPCServer implements AztecRPC { this.log.info('Stopped'); } - /** - * Registers an account backed by an account contract. - * - * @param privKey - Private key of the corresponding user master public key. - * @param address - Address of the account contract. - * @param partialContractAddress - The partially computed address of the account contract. - * @returns The address of the account contract. - */ public async addAccount(privKey: PrivateKey, address: AztecAddress, partialContractAddress: PartialContractAddress) { const pubKey = this.keyStore.addAccount(privKey); // TODO(#1007): ECDSA contract breaks this check, since the ecdsa public key does not match the one derived from the keystore. @@ -111,13 +103,6 @@ export class AztecRPCServer implements AztecRPC { return address; } - /** - * Adds public key and partial address to a database. - * @param address - Address of the account to add public key and partial address for. - * @param publicKey - Public key of the corresponding user. - * @param partialAddress - The partially computed address of the account contract. - * @returns A Promise that resolves once the public key has been added to the database. - */ public async addPublicKeyAndPartialAddress( address: AztecAddress, publicKey: PublicKey, @@ -127,13 +112,6 @@ export class AztecRPCServer implements AztecRPC { this.log.info(`Added public key for ${address.toString()}`); } - /** - * Add an array of deployed contracts to the database. - * Each contract should contain ABI, address, and portalContract information. - * - * @param contracts - An array of DeployedContract objects containing contract ABI, address, and portalContract. - * @returns A Promise that resolves once all the contracts have been added to the database. - */ public async addContracts(contracts: DeployedContract[]) { const contractDaos = contracts.map(c => toContractDao(c.abi, c.address, c.portalContract)); await Promise.all(contractDaos.map(c => this.db.addContract(c))); @@ -144,23 +122,10 @@ export class AztecRPCServer implements AztecRPC { } } - /** - * Retrieves the list of Aztec addresses added to this rpc server - * The addresses are returned as a promise that resolves to an array of AztecAddress objects. - * - * @returns A promise that resolves to an array of AztecAddress instances. - */ public async getAccounts(): Promise { return await this.db.getAccounts(); } - /** - * Retrieve the public key associated with an address. - * Throws an error if the account is not found in the key store. - * - * @param address - The AztecAddress instance representing the account to get public key for. - * @returns A Promise resolving to the PublicKey instance representing the public key. - */ public async getPublicKey(address: AztecAddress): Promise { const result = await this.db.getPublicKeyAndPartialAddress(address); if (!result) { @@ -169,13 +134,6 @@ export class AztecRPCServer implements AztecRPC { return Promise.resolve(result[0]); } - /** - * Retrieve the public key and partial contract address associated with an address. - * Throws an error if the account is not found in the key store. - * - * @param address - The AztecAddress instance representing the account to get public key and partial address for. - * @returns A Promise resolving to the PublicKey instance representing the public key. - */ public async getPublicKeyAndPartialAddress(address: AztecAddress): Promise<[PublicKey, PartialContractAddress]> { const result = await this.db.getPublicKeyAndPartialAddress(address); if (!result) { @@ -184,27 +142,11 @@ export class AztecRPCServer implements AztecRPC { return Promise.resolve(result); } - /** - * Retrieves the storage data at a specified contract address and storage slot. - * The returned data is an array of note preimage items, with each item containing its value. - * - * @param contract - The AztecAddress of the target contract. - * @param storageSlot - The Fr representing the storage slot to be fetched. - * @returns A promise that resolves to an array of note preimage items, each containing its value. - */ public async getStorageAt(contract: AztecAddress, storageSlot: Fr) { const noteSpendingInfo = await this.db.getNoteSpendingInfo(contract, storageSlot); return noteSpendingInfo.map(d => d.notePreimage.items.map(item => item.value)); } - /** - * Retrieves the public storage data at a specified contract address and storage slot. - * The returned data is an array of note preimage items, with each item containing its value. - * - * @param contract - The AztecAddress of the target contract. - * @param storageSlot - The Fr representing the storage slot to be fetched. - * @returns A promise that resolves to an array of note preimage items, each containing its value. - */ public async getPublicStorageAt(contract: AztecAddress, storageSlot: Fr) { if (!(await this.isContractDeployed(contract))) { throw new Error(`Contract ${contract.toString()} is not deployed`); @@ -212,23 +154,10 @@ export class AztecRPCServer implements AztecRPC { return await this.node.getStorageAt(contract, storageSlot.value); } - /** - * Is an L2 contract deployed at this address? - * @param contractAddress - The contract data address. - * @returns Whether the contract was deployed. - */ public async isContractDeployed(contractAddress: AztecAddress): Promise { return !!(await this.node.getContractInfo(contractAddress)); } - /** - * Create a transaction for a contract function call with the provided arguments. - * Throws an error if the contract or function is unknown. - * - * @param txRequest - An authenticated tx request ready for simulation - * @param optionalFromAddress - The address to simulate from - * @returns A Tx ready to send to the p2p pool for execution. - */ public async simulateTx(txRequest: TxExecutionRequest) { if (!txRequest.functionData.isPrivate) { throw new Error(`Public entrypoints are not allowed`); @@ -256,11 +185,6 @@ export class AztecRPCServer implements AztecRPC { return tx; } - /** - * Send a transaction. - * @param tx - The transaction. - * @returns A hash of the transaction, used to identify it. - */ public async sendTx(tx: Tx): Promise { const txHash = await tx.getTxHash(); this.log.info(`Sending transaction ${txHash}`); @@ -268,18 +192,6 @@ export class AztecRPCServer implements AztecRPC { return txHash; } - /** - * Simulate the execution of a view (read-only) function on a deployed contract without actually modifying state. - * This is useful to inspect contract state, for example fetching a variable value or calling a getter function. - * The function takes function name and arguments as parameters, along with the contract address - * and optionally the sender's address. - * - * @param functionName - The name of the function to be called in the contract. - * @param args - The arguments to be provided to the function. - * @param to - The address of the contract to be called. - * @param from - (Optional) The caller of the transaction. - * @returns The result of the view function call, structured based on the function ABI. - */ public async viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress) { const txRequest = await this.#getExecutionRequest(functionName, args, to, from ?? AztecAddress.ZERO); @@ -289,11 +201,6 @@ export class AztecRPCServer implements AztecRPC { return executionResult; } - /** - * Fetches a transaction receipt for a tx. - * @param txHash - The transaction hash. - * @returns A receipt of the transaction. - */ public async getTxReceipt(txHash: TxHash): Promise { const localTx = await this.#getTxByHash(txHash); const partialReceipt = new TxReceipt( @@ -331,40 +238,18 @@ export class AztecRPCServer implements AztecRPC { return partialReceipt; } - /** - * Get latest L2 block number. - * @returns The latest block number. - */ async getBlockNum(): Promise { return await this.node.getBlockHeight(); } - /** - * Lookup the L2 contract data for this contract. - * Contains the ethereum portal address and bytecode. - * @param contractAddress - The contract data address. - * @returns The complete contract data including portal address & bytecode (if we didn't throw an error). - */ public async getContractData(contractAddress: AztecAddress): Promise { return await this.node.getContractData(contractAddress); } - /** - * Lookup the L2 contract info for this contract. - * Contains the ethereum portal address . - * @param contractAddress - The contract data address. - * @returns The contract's address & portal address. - */ public async getContractInfo(contractAddress: AztecAddress): Promise { return await this.node.getContractInfo(contractAddress); } - /** - * Gets L2 block unencrypted logs. - * @param from - Number of the L2 block to which corresponds the first unencrypted logs to be returned. - * @param take - The number of unencrypted logs to return. - * @returns The requested unencrypted logs. - */ public async getUnencryptedLogs(from: number, take: number): Promise { return await this.node.getLogs(from, take, LogType.UNENCRYPTED); } @@ -393,10 +278,6 @@ export class AztecRPCServer implements AztecRPC { }; } - /** - * Returns the information about the server's node - * @returns - The node information. - */ public async getNodeInfo(): Promise { const [version, chainId] = await Promise.all([this.node.getVersion(), this.node.getChainId()]); @@ -458,16 +339,6 @@ export class AztecRPCServer implements AztecRPC { }; } - /** - * Simulate the execution of a transaction request. - * This function computes the expected state changes resulting from the transaction - * without actually submitting it to the blockchain. The result will be used for creating the kernel proofs, - * as well as for estimating gas costs. - * - * @param txRequest - The transaction request object containing the necessary data for simulation. - * @param contractDataOracle - Optional parameter, an instance of ContractDataOracle class for retrieving contract data. - * @returns A promise that resolves to an object containing the simulation results, including expected output notes and any error messages. - */ async #simulate(txRequest: TxExecutionRequest, contractDataOracle?: ContractDataOracle) { // TODO - Pause syncing while simulating. if (!contractDataOracle) { @@ -567,20 +438,10 @@ export class AztecRPCServer implements AztecRPC { ); } - /** - * Return true if the top level block synchronisation is up to date - * This indicates that blocks and transactions are synched even if notes are not - * @returns True if there are no outstanding blocks to be synched - */ public async isSynchronised() { return await this.synchroniser.isSynchronised(); } - /** - * Returns true if the account specified by the given address is synched to the latest block - * @param account - The aztec address for which to query the sync status - * @returns True if the account is fully synched, false otherwise - */ public async isAccountSynchronised(account: AztecAddress) { return await this.synchroniser.isAccountSynchronised(account); } diff --git a/yarn-project/aztec-rpc/src/database/database.ts b/yarn-project/aztec-rpc/src/database/database.ts index 1da0ad3ef9bb..069f27ee7d45 100644 --- a/yarn-project/aztec-rpc/src/database/database.ts +++ b/yarn-project/aztec-rpc/src/database/database.ts @@ -11,24 +11,134 @@ import { TxDao } from './tx_dao.js'; * addresses, storage slots, and nullifiers. */ export interface Database extends ContractDatabase { + /** + * Retrieve a transaction from the MemoryDB using its transaction hash. + * The function searches for the transaction with the given hash in the txTable and returns it as a Promise. + * Returns 'undefined' if the transaction is not found in the database. + * + * @param txHash - The TxHash of the transaction to be retrieved. + * @returns A Promise that resolves to the found TxDao instance, or undefined if not found. + */ getTx(txHash: TxHash): Promise; + + /** + * Retrieve all transactions associated with a given AztecAddress. + * + * @param origin - The sender's address. + * @returns A Promise resolving to an array of TxDao objects associated with the sender. + */ getTxsByAddress(origin: AztecAddress): Promise; + + /** + * Adds a TxDao instance to the transaction table. + * If a transaction with the same hash already exists in the table, it replaces the existing one. + * Otherwise, it pushes the new transaction to the table. + * + * @param tx - The TxDao instance representing the transaction to be added. + * @returns A Promise that resolves when the transaction is successfully added/updated in the table. + */ addTx(tx: TxDao): Promise; + + /** + * Add an array of transaction data objects. + * If a transaction with the same hash already exists in the database, it will be updated + * with the new transaction data. Otherwise, the new transaction will be added to the database. + * + * @param txs - An array of TxDao instances representing the transactions to be added to the database. + * @returns A Promise that resolves when all the transactions have been added or updated. + */ addTxs(txs: TxDao[]): Promise; + /** + * Get auxiliary transaction data based on contract address and storage slot. + * It searches for matching NoteSpendingInfoDao objects in the MemoryDB's noteSpendingInfoTable + * where both the contractAddress and storageSlot properties match the given inputs. + * + * @param contract - The contract address. + * @param storageSlot - A Fr object representing the storage slot to search for in the auxiliary data. + * @returns An array of NoteSpendingInfoDao objects that fulfill the contract address and storage slot criteria. + */ getNoteSpendingInfo(contract: AztecAddress, storageSlot: Fr): Promise; + + /** + * Add a NoteSpendingInfoDao instance to the noteSpendingInfoTable. + * This function is used to store auxiliary data related to a transaction, + * such as contract address and storage slot, in the database. + * + * @param noteSpendingInfoDao - The NoteSpendingInfoDao instance containing the auxiliary data of a transaction. + * @returns A promise that resolves when the auxiliary data is added to the database. + */ addNoteSpendingInfo(noteSpendingInfoDao: NoteSpendingInfoDao): Promise; + + /** + * Adds an array of NoteSpendingInfoDaos to the noteSpendingInfoTable. + * This function is used to insert multiple transaction auxiliary data objects into the database at once, + * which can improve performance when dealing with large numbers of transactions. + * + * @param noteSpendingInfoDaos - An array of NoteSpendingInfoDao instances representing the auxiliary data of transactions. + * @returns A Promise that resolves when all NoteSpendingInfoDaos have been successfully added to the noteSpendingInfoTable. + */ addNoteSpendingInfoBatch(noteSpendingInfoDaos: NoteSpendingInfoDao[]): Promise; + + /** + * Remove nullified transaction auxiliary data records associated with the given account and nullifiers. + * The function filters the records based on matching account and nullifier values, and updates the + * noteSpendingInfoTable with the remaining records. It returns an array of removed NoteSpendingInfoDao instances. + * + * @param nullifiers - An array of Fr instances representing nullifiers to be matched. + * @param account - A PublicKey instance representing the account for which the records are being removed. + * @returns A Promise resolved with an array of removed NoteSpendingInfoDao instances. + */ removeNullifiedNoteSpendingInfo(nullifiers: Fr[], account: PublicKey): Promise; + /** + * Retrieve the stored Merkle tree roots from the database. + * The function returns a Promise that resolves to an object containing the MerkleTreeId as keys + * and their corresponding Fr values as roots. Throws an error if the tree roots are not set in the + * memory database. + * + * @returns An object containing the Merkle tree roots for each merkle tree id. + */ getTreeRoots(): Record; + + /** + * Set the tree roots for the Merkle trees in the database. + * This function updates the 'treeRoots' property of the instance + * with the provided 'roots' object containing MerkleTreeId and Fr pairs. + * Note that this will overwrite any existing tree roots in the database. + * + * @param roots - A Record object mapping MerkleTreeIds to their corresponding Fr root values. + * @returns A Promise that resolves when the tree roots have been successfully updated in the database. + */ setTreeRoots(roots: Record): Promise; + /** + * Adds public key and partial address to a database. + * @param address - Address of the account to add public key and partial address for. + * @param publicKey - Public key of the corresponding user. + * @param partialAddress - The partially computed address of the account contract. + * @returns A Promise that resolves once the public key has been added to the database. + */ addPublicKeyAndPartialAddress( address: AztecAddress, publicKey: PublicKey, partialAddress: PartialContractAddress, ): Promise; + + /** + * Retrieve the public key and partial contract address associated with an address. + * Throws an error if the account is not found in the key store. + * + * @param address - The AztecAddress instance representing the account to get public key and partial address for. + * @returns A Promise resolving to the PublicKey instance representing the public key. + */ getPublicKeyAndPartialAddress(address: AztecAddress): Promise<[PublicKey, PartialContractAddress] | undefined>; + + /** + * Retrieves the list of Aztec addresses added to this database + * The addresses are returned as a promise that resolves to an array of AztecAddress objects. + * + * @returns A promise that resolves to an array of AztecAddress instances. + */ getAccounts(): Promise; } diff --git a/yarn-project/aztec-rpc/src/database/memory_db.ts b/yarn-project/aztec-rpc/src/database/memory_db.ts index 949c31bde47e..756e7b6c8a03 100644 --- a/yarn-project/aztec-rpc/src/database/memory_db.ts +++ b/yarn-project/aztec-rpc/src/database/memory_db.ts @@ -25,36 +25,14 @@ export class MemoryDB extends MemoryContractDatabase implements Database { super(createDebugLogger(logSuffix ? 'aztec:memory_db_' + logSuffix : 'aztec:memory_db')); } - /** - * Retrieve a transaction from the MemoryDB using its transaction hash. - * The function searches for the transaction with the given hash in the txTable and returns it as a Promise. - * Returns 'undefined' if the transaction is not found in the database. - * - * @param txHash - The TxHash of the transaction to be retrieved. - * @returns A Promise that resolves to the found TxDao instance, or undefined if not found. - */ public getTx(txHash: TxHash) { return Promise.resolve(this.txTable.find(tx => tx.txHash.equals(txHash))); } - /** - * Retrieve all transactions associated with a given AztecAddress. - * - * @param origin - The sender's address. - * @returns A Promise resolving to an array of TxDao objects associated with the sender. - */ public getTxsByAddress(origin: AztecAddress) { return Promise.resolve(this.txTable.filter(tx => tx.origin.equals(origin))); } - /** - * Adds a TxDao instance to the transaction table. - * If a transaction with the same hash already exists in the table, it replaces the existing one. - * Otherwise, it pushes the new transaction to the table. - * - * @param tx - The TxDao instance representing the transaction to be added. - * @returns A Promise that resolves when the transaction is successfully added/updated in the table. - */ public addTx(tx: TxDao) { const index = this.txTable.findIndex(t => t.txHash.equals(tx.txHash)); if (index === -1) { @@ -65,53 +43,20 @@ export class MemoryDB extends MemoryContractDatabase implements Database { return Promise.resolve(); } - /** - * Add an array of transaction data objects. - * If a transaction with the same hash already exists in the database, it will be updated - * with the new transaction data. Otherwise, the new transaction will be added to the database. - * - * @param txs - An array of TxDao instances representing the transactions to be added to the database. - * @returns A Promise that resolves when all the transactions have been added or updated. - */ public async addTxs(txs: TxDao[]) { await Promise.all(txs.map(tx => this.addTx(tx))); } - /** - * Add a NoteSpendingInfoDao instance to the noteSpendingInfoTable. - * This function is used to store auxiliary data related to a transaction, - * such as contract address and storage slot, in the database. - * - * @param noteSpendingInfoDao - The NoteSpendingInfoDao instance containing the auxiliary data of a transaction. - * @returns A promise that resolves when the auxiliary data is added to the database. - */ public addNoteSpendingInfo(noteSpendingInfoDao: NoteSpendingInfoDao) { this.noteSpendingInfoTable.push(noteSpendingInfoDao); return Promise.resolve(); } - /** - * Adds an array of NoteSpendingInfoDaos to the noteSpendingInfoTable. - * This function is used to insert multiple transaction auxiliary data objects into the database at once, - * which can improve performance when dealing with large numbers of transactions. - * - * @param noteSpendingInfoDaos - An array of NoteSpendingInfoDao instances representing the auxiliary data of transactions. - * @returns A Promise that resolves when all NoteSpendingInfoDaos have been successfully added to the noteSpendingInfoTable. - */ public addNoteSpendingInfoBatch(noteSpendingInfoDaos: NoteSpendingInfoDao[]) { this.noteSpendingInfoTable.push(...noteSpendingInfoDaos); return Promise.resolve(); } - /** - * Get auxiliary transaction data based on contract address and storage slot. - * It searches for matching NoteSpendingInfoDao objects in the MemoryDB's noteSpendingInfoTable - * where both the contractAddress and storageSlot properties match the given inputs. - * - * @param contract - The contract address. - * @param storageSlot - A Fr object representing the storage slot to search for in the auxiliary data. - * @returns An array of NoteSpendingInfoDao objects that fulfill the contract address and storage slot criteria. - */ public getNoteSpendingInfo(contract: AztecAddress, storageSlot: Fr) { const res = this.noteSpendingInfoTable.filter( noteSpendingInfo => @@ -121,15 +66,6 @@ export class MemoryDB extends MemoryContractDatabase implements Database { return Promise.resolve(res); } - /** - * Remove nullified transaction auxiliary data records associated with the given account and nullifiers. - * The function filters the records based on matching account and nullifier values, and updates the - * noteSpendingInfoTable with the remaining records. It returns an array of removed NoteSpendingInfoDao instances. - * - * @param nullifiers - An array of Fr instances representing nullifiers to be matched. - * @param account - A PublicKey instance representing the account for which the records are being removed. - * @returns A Promise resolved with an array of removed NoteSpendingInfoDao instances. - */ public removeNullifiedNoteSpendingInfo(nullifiers: Fr[], account: PublicKey) { const nullifierSet = new Set(nullifiers.map(nullifier => nullifier.toString())); const [remaining, removed] = this.noteSpendingInfoTable.reduce( @@ -150,29 +86,12 @@ export class MemoryDB extends MemoryContractDatabase implements Database { return Promise.resolve(removed); } - /** - * Retrieve the stored Merkle tree roots from the database. - * The function returns a Promise that resolves to an object containing the MerkleTreeId as keys - * and their corresponding Fr values as roots. Throws an error if the tree roots are not set in the - * memory database. - * - * @returns An object containing the Merkle tree roots for each merkle tree id. - */ public getTreeRoots(): Record { const roots = this.treeRoots; if (!roots) throw new Error(`Tree roots not set in memory database`); return roots; } - /** - * Set the tree roots for the Merkle trees in the database. - * This function updates the 'treeRoots' property of the instance - * with the provided 'roots' object containing MerkleTreeId and Fr pairs. - * Note that this will overwrite any existing tree roots in the database. - * - * @param roots - A Record object mapping MerkleTreeIds to their corresponding Fr root values. - * @returns A Promise that resolves when the tree roots have been successfully updated in the database. - */ public setTreeRoots(roots: Record) { this.treeRoots = roots; return Promise.resolve(); diff --git a/yarn-project/aztec-rpc/src/kernel_oracle/index.ts b/yarn-project/aztec-rpc/src/kernel_oracle/index.ts index 778a25dd230c..a52a160f0298 100644 --- a/yarn-project/aztec-rpc/src/kernel_oracle/index.ts +++ b/yarn-project/aztec-rpc/src/kernel_oracle/index.ts @@ -11,52 +11,18 @@ import { ProvingDataOracle } from './../kernel_prover/proving_data_oracle.js'; export class KernelOracle implements ProvingDataOracle { constructor(private contractDataOracle: ContractDataOracle, private node: AztecNode) {} - /** - * Retrieves the contract membership witness for a given contract address. - * A contract membership witness is a cryptographic proof that the contract exists in the Aztec network. - * This function will search for an existing contract tree associated with the contract address and obtain its - * membership witness. If no such contract tree exists, it will throw an error. - * - * @param contractAddress - The contract address. - * @returns A promise that resolves to a MembershipWitness instance representing the contract membership witness. - * @throws Error if the contract address is unknown or not found. - */ public async getContractMembershipWitness(contractAddress: AztecAddress) { return await this.contractDataOracle.getContractMembershipWitness(contractAddress); } - /** - * Retrieve the function membership witness for the given contract address and function selector. - * The function membership witness represents a proof that the function belongs to the specified contract. - * Throws an error if the contract address or function selector is unknown. - * - * @param contractAddress - The contract address. - * @param functionSelector - The buffer containing the function selector. - * @returns A promise that resolves with the MembershipWitness instance for the specified contract's function. - */ public async getFunctionMembershipWitness(contractAddress: AztecAddress, functionSelector: Buffer) { return await this.contractDataOracle.getFunctionMembershipWitness(contractAddress, functionSelector); } - /** - * Retrieve the membership witness corresponding to a verification key. - * This function currently returns a random membership witness of the specified height, - * which is a placeholder implementation until a concrete membership witness calculation - * is implemented. - * - * @param vk - The VerificationKey for which the membership witness is needed. - * @returns A Promise that resolves to the MembershipWitness instance. - */ public async getVkMembershipWitness() { return await this.contractDataOracle.getVkMembershipWitness(); } - /** - * Get the note membership witness for a note in the private data tree at the given leaf index. - * - * @param leafIndex - The leaf index of the note in the private data tree. - * @returns the MembershipWitness for the note. - */ async getNoteMembershipWitness(leafIndex: bigint): Promise> { const path = await this.node.getDataTreePath(leafIndex); return new MembershipWitness( @@ -66,11 +32,6 @@ export class KernelOracle implements ProvingDataOracle { ); } - /** - * Get the root of the private data tree. - * - * @returns the root of the private data tree. - */ async getPrivateDataRoot(): Promise { const roots = await this.node.getTreeRoots(); return roots[MerkleTreeId.PRIVATE_DATA_TREE]; diff --git a/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts b/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts index d7ae36ee9826..fe6ce191bd8b 100644 --- a/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts +++ b/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts @@ -36,9 +36,38 @@ export interface ProofOutput { * siloed commitments necessary for maintaining transaction privacy and security on the network. */ export interface ProofCreator { + /** + * Computes the siloed commitments for a given set of public inputs. + * + * @param publicInputs - The public inputs containing the contract address and new commitments to be used in generating siloed commitments. + * @returns An array of Fr (finite field) elements representing the siloed commitments. + */ getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs): Promise; + + /** + * Creates a proof output for a given signed transaction request and private call data for the first iteration. + * + * @param txRequest - The signed transaction request object. + * @param privateCallData - The private call data object. + * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. + */ createProofInit(txRequest: TxRequest, privateCallData: PrivateCallData): Promise; + + /** + * Creates a proof output for a given previous kernel data and private call data for an inner iteration. + * + * @param previousKernelData - The previous kernel data object. + * @param privateCallData - The private call data object. + * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. + */ createProofInner(previousKernelData: PreviousKernelData, privateCallData: PrivateCallData): Promise; + + /** + * Creates a proof output based on the last inner kernel iteration kernel data for the final ordering iteration. + * + * @param previousKernelData - The previous kernel data object. + * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. + */ createProofOrdering(previousKernelData: PreviousKernelData): Promise; } @@ -49,15 +78,9 @@ export interface ProofCreator { * based on the given public inputs and to generate proofs based on signed transaction requests, previous kernel * data, private call data, and a flag indicating whether it's the first iteration or not. */ -export class KernelProofCreator { +export class KernelProofCreator implements ProofCreator { constructor(private log = createDebugLogger('aztec:kernel_proof_creator')) {} - /** - * Computes the siloed commitments for a given set of public inputs. - * - * @param publicInputs - The public inputs containing the contract address and new commitments to be used in generating siloed commitments. - * @returns An array of Fr (finite field) elements representing the siloed commitments. - */ public async getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs) { const wasm = await CircuitsWasm.get(); const contractAddress = publicInputs.callContext.storageContractAddress; @@ -65,13 +88,6 @@ export class KernelProofCreator { return publicInputs.newCommitments.map(commitment => siloCommitment(wasm, contractAddress, commitment)); } - /** - * Creates a proof output for a given signed transaction request and private call data for the first iteration. - * - * @param txRequest - The signed transaction request object. - * @param privateCallData - The private call data object. - * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. - */ public async createProofInit(txRequest: TxRequest, privateCallData: PrivateCallData): Promise { const wasm = await CircuitsWasm.get(); this.log('Executing private kernel simulation init...'); @@ -87,13 +103,6 @@ export class KernelProofCreator { }; } - /** - * Creates a proof output for a given previous kernel data and private call data for an inner iteration. - * - * @param previousKernelData - The previous kernel data object. - * @param privateCallData - The private call data object. - * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. - */ public async createProofInner( previousKernelData: PreviousKernelData, privateCallData: PrivateCallData, @@ -112,12 +121,6 @@ export class KernelProofCreator { }; } - /** - * Creates a proof output based on the last inner kernel iteration kernel data for the final ordering iteration. - * - * @param previousKernelData - The previous kernel data object. - * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof. - */ public async createProofOrdering(previousKernelData: PreviousKernelData): Promise { const wasm = await CircuitsWasm.get(); this.log('Executing private kernel simulation ordering...'); diff --git a/yarn-project/aztec-rpc/src/kernel_prover/proving_data_oracle.ts b/yarn-project/aztec-rpc/src/kernel_prover/proving_data_oracle.ts index 9df4bdcf6020..16e90f9ca1ae 100644 --- a/yarn-project/aztec-rpc/src/kernel_prover/proving_data_oracle.ts +++ b/yarn-project/aztec-rpc/src/kernel_prover/proving_data_oracle.ts @@ -14,12 +14,55 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; * contract addresses, and function selectors in their respective merkle trees. */ export interface ProvingDataOracle { + /** + * Retrieves the contract membership witness for a given contract address. + * A contract membership witness is a cryptographic proof that the contract exists in the Aztec network. + * This function will search for an existing contract tree associated with the contract address and obtain its + * membership witness. If no such contract tree exists, it will throw an error. + * + * @param contractAddress - The contract address. + * @returns A promise that resolves to a MembershipWitness instance representing the contract membership witness. + * @throws Error if the contract address is unknown or not found. + */ getContractMembershipWitness(contractAddress: AztecAddress): Promise>; + + /** + * Retrieve the function membership witness for the given contract address and function selector. + * The function membership witness represents a proof that the function belongs to the specified contract. + * Throws an error if the contract address or function selector is unknown. + * + * @param contractAddress - The contract address. + * @param functionSelector - The buffer containing the function selector. + * @returns A promise that resolves with the MembershipWitness instance for the specified contract's function. + */ getFunctionMembershipWitness( contractAddress: AztecAddress, functionSelector: Buffer, ): Promise>; + + /** + * Retrieve the membership witness corresponding to a verification key. + * This function currently returns a random membership witness of the specified height, + * which is a placeholder implementation until a concrete membership witness calculation + * is implemented. + * + * @param vk - The VerificationKey for which the membership witness is needed. + * @returns A Promise that resolves to the MembershipWitness instance. + */ getVkMembershipWitness(vk: VerificationKey): Promise>; + + /** + * Get the note membership witness for a note in the private data tree at the given leaf index. + * + * @param leafIndex - The leaf index of the note in the private data tree. + * @returns the MembershipWitness for the note. + */ getNoteMembershipWitness(leafIndex: bigint): Promise>; + + /** + * Get the root of the private data tree. + * + * @returns the root of the private data tree. + */ getPrivateDataRoot(): Promise; } diff --git a/yarn-project/aztec-rpc/src/simulator_oracle/index.ts b/yarn-project/aztec-rpc/src/simulator_oracle/index.ts index aafe648eceb6..267ea532c160 100644 --- a/yarn-project/aztec-rpc/src/simulator_oracle/index.ts +++ b/yarn-project/aztec-rpc/src/simulator_oracle/index.ts @@ -28,25 +28,10 @@ export class SimulatorOracle implements DBOracle { private dataTreeProvider: DataCommitmentProvider, ) {} - /** - * Retrieve the secret key associated with a specific public key. - * The function only allows access to the secret keys of the transaction creator, - * and throws an error if the address does not match the public key address of the key pair. - * - * @param _contractAddress - The contract address. Ignored here. But we might want to return different keys for different contracts. - * @param pubKey - The public key of an account. - * @returns A Promise that resolves to the secret key as a Buffer. - * @throws An Error if the input address does not match the public key address of the key pair. - */ getSecretKey(_contractAddress: AztecAddress, pubKey: PublicKey): Promise { return this.keyStore.getAccountPrivateKey(pubKey); } - /** - * Retrieve the public key associated to a given address. - * @param address - Address to fetch the pubkey for. - * @returns A public key and the corresponding partial contract address, such that the hash of the two resolves to the input address. - */ async getPublicKey(address: AztecAddress): Promise<[PublicKey, PartialContractAddress]> { const result = await this.db.getPublicKeyAndPartialAddress(address); if (!result) @@ -56,15 +41,6 @@ export class SimulatorOracle implements DBOracle { return result; } - /** - * Retrieves a set of notes stored in the database for a given contract address and storage slot. - * The query result is paginated using 'limit' and 'offset' values. - * Returns an object containing an array of note data, including preimage, nonce, and index for each note. - * - * @param contractAddress - The AztecAddress instance representing the contract address. - * @param storageSlot - The Fr instance representing the storage slot of the notes. - * @returns A Promise that resolves to an array of note data. - */ async getNotes(contractAddress: AztecAddress, storageSlot: Fr) { const noteDaos = await this.db.getNoteSpendingInfo(contractAddress, storageSlot); return noteDaos.map(({ contractAddress, storageSlot, nonce, notePreimage, nullifier, index }) => ({ @@ -78,25 +54,10 @@ export class SimulatorOracle implements DBOracle { })); } - /** - * Retrieve the ABI information of a specific function within a contract. - * The function is identified by its selector, which is a unique identifier generated from the function signature. - * - * @param contractAddress - The contract address. - * @param functionSelector - The Buffer containing the function selector bytes. - * @returns A Promise that resolves to a FunctionAbi object containing the ABI information of the target function. - */ async getFunctionABI(contractAddress: AztecAddress, functionSelector: Buffer): Promise { return await this.contractDataOracle.getFunctionAbi(contractAddress, functionSelector); } - /** - * Retrieves the portal contract address associated with the given contract address. - * Throws an error if the input contract address is not found or invalid. - * - * @param contractAddress - The address of the contract whose portal address is to be fetched. - * @returns A Promise that resolves to an EthAddress instance, representing the portal contract address. - */ async getPortalContractAddress(contractAddress: AztecAddress): Promise { return await this.contractDataOracle.getPortalContractAddress(contractAddress); } diff --git a/yarn-project/aztec.js/src/account_impl/account_collection.ts b/yarn-project/aztec.js/src/account_impl/account_collection.ts index b7d606db2c52..29309d027d05 100644 --- a/yarn-project/aztec.js/src/account_impl/account_collection.ts +++ b/yarn-project/aztec.js/src/account_impl/account_collection.ts @@ -23,12 +23,6 @@ export class AccountCollection implements AccountImplementation { return AztecAddress.fromString(this.accounts.keys().next().value as string); } - /** - * Uses a registered account implementation to generate an authenticated request - * @param executions - The execution intent to be authenticated. - * @param txContext - The tx context under with the execution is to be made. - * @returns - The authenticated transaction execution request. - */ public createAuthenticatedTxRequest( executions: ExecutionRequest[], txContext: TxContext, diff --git a/yarn-project/aztec.js/src/account_impl/index.ts b/yarn-project/aztec.js/src/account_impl/index.ts index fef49cc80968..9d9858d49fb6 100644 --- a/yarn-project/aztec.js/src/account_impl/index.ts +++ b/yarn-project/aztec.js/src/account_impl/index.ts @@ -7,7 +7,17 @@ export * from './account_collection.js'; /** Represents an implementation for a user account contract. Knows how to encode and sign a tx for that particular implementation. */ export interface AccountImplementation { + /** + * Returns the address for the account contract used by this implementation. + * @returns The address. + */ getAddress(): AztecAddress; - /** Creates a tx to be sent from a given account contract given a set of execution requests. */ + + /** + * Generates an authenticated request out of set of intents + * @param executions - The execution intent to be authenticated. + * @param txContext - The tx context under with the execution is to be made. + * @returns The authenticated transaction execution request. + */ createAuthenticatedTxRequest(executions: ExecutionRequest[], txContext: TxContext): Promise; } diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/signature/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/signature/index.ts index 842d606d1182..506fc08c57a3 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/signature/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/signature/index.ts @@ -6,7 +6,15 @@ import { PrivateKey } from '../../../types/private_key.js'; * Interface to represent a signature. */ export interface Signature { + /** + * Serializes to a buffer. + * @returns A buffer. + */ toBuffer(): Buffer; + /** + * Serializes to an array of fields. + * @returns Fields. + */ toFields(): Fr[]; } @@ -14,5 +22,11 @@ export interface Signature { * Interface to represent a signer. */ export interface Signer { + /** + * Signs the given message with the given private key. + * @param message - What to sign. + * @param privateKey - The private key. + * @returns A signature. + */ constructSignature(message: Uint8Array, privateKey: PrivateKey): Signature; } diff --git a/yarn-project/foundation/src/mutex/mutex_database.ts b/yarn-project/foundation/src/mutex/mutex_database.ts index a6b3c2cbf647..a3b1d053bada 100644 --- a/yarn-project/foundation/src/mutex/mutex_database.ts +++ b/yarn-project/foundation/src/mutex/mutex_database.ts @@ -3,7 +3,10 @@ * Provides functionality for acquiring, extending, and releasing locks on resources to ensure exclusive access and prevent conflicts in concurrent applications. */ export interface MutexDatabase { + // eslint-disable-next-line jsdoc/require-jsdoc acquireLock(name: string, timeout: number): Promise; + // eslint-disable-next-line jsdoc/require-jsdoc extendLock(name: string, timeout: number): Promise; + // eslint-disable-next-line jsdoc/require-jsdoc releaseLock(name: string): Promise; } diff --git a/yarn-project/foundation/src/transport/interface/connector.ts b/yarn-project/foundation/src/transport/interface/connector.ts index 9d72f6574f72..af01fd19520d 100644 --- a/yarn-project/foundation/src/transport/interface/connector.ts +++ b/yarn-project/foundation/src/transport/interface/connector.ts @@ -4,5 +4,6 @@ import { Socket } from './socket.js'; * Opens a socket with corresponding TransportListener. */ export interface Connector { + // eslint-disable-next-line jsdoc/require-jsdoc createSocket(): Promise; } diff --git a/yarn-project/foundation/src/transport/interface/listener.ts b/yarn-project/foundation/src/transport/interface/listener.ts index f4e31e928b87..d71b3ffb1a85 100644 --- a/yarn-project/foundation/src/transport/interface/listener.ts +++ b/yarn-project/foundation/src/transport/interface/listener.ts @@ -7,9 +7,10 @@ import { Socket } from './socket.js'; * Possible implementations could include MessageChannels or WebSockets. */ export interface Listener extends EventEmitter { + // eslint-disable-next-line jsdoc/require-jsdoc open(): void; - + // eslint-disable-next-line jsdoc/require-jsdoc close(): void; - + // eslint-disable-next-line jsdoc/require-jsdoc on(name: 'new_socket', cb: (client: Socket) => void): this; } diff --git a/yarn-project/foundation/src/transport/interface/socket.ts b/yarn-project/foundation/src/transport/interface/socket.ts index 6da7ca436ed9..a862ad4eb2dd 100644 --- a/yarn-project/foundation/src/transport/interface/socket.ts +++ b/yarn-project/foundation/src/transport/interface/socket.ts @@ -6,7 +6,10 @@ * If `registerHandler` callback receives `undefined` that signals the other end closed. */ export interface Socket { + // eslint-disable-next-line jsdoc/require-jsdoc send(msg: any, transfer?: Transferable[]): Promise; + // eslint-disable-next-line jsdoc/require-jsdoc registerHandler(cb: (msg: any) => any): void; + // eslint-disable-next-line jsdoc/require-jsdoc close(): void; } diff --git a/yarn-project/foundation/src/transport/transport_client.ts b/yarn-project/foundation/src/transport/transport_client.ts index 373d0f74f87c..5fc5b631da24 100644 --- a/yarn-project/foundation/src/transport/transport_client.ts +++ b/yarn-project/foundation/src/transport/transport_client.ts @@ -17,7 +17,9 @@ interface PendingRequest { * The unique message identifier used for tracking and matching request/response pairs. */ msgId: number; + // eslint-disable-next-line jsdoc/require-jsdoc resolve(data: any): void; + // eslint-disable-next-line jsdoc/require-jsdoc reject(error: Error): void; } @@ -26,8 +28,10 @@ interface PendingRequest { * Provides request/response functionality, event handling, and multiplexing support * for efficient and concurrent communication with a corresponding TransportServer. */ -export interface TransportClient extends EventEmitter { +export interface ITransportClient extends EventEmitter { + // eslint-disable-next-line jsdoc/require-jsdoc on(name: 'event_msg', handler: (payload: Payload) => void): this; + // eslint-disable-next-line jsdoc/require-jsdoc emit(name: 'event_msg', payload: Payload): boolean; } diff --git a/yarn-project/foundation/src/wasm/worker/data_store.ts b/yarn-project/foundation/src/wasm/worker/data_store.ts index 4390b2775eeb..afa4b4d47584 100644 --- a/yarn-project/foundation/src/wasm/worker/data_store.ts +++ b/yarn-project/foundation/src/wasm/worker/data_store.ts @@ -2,6 +2,18 @@ * Simple read/write interface for wasm modules. */ export interface DataStore { + /** + * Get a value from our DB. + * @param key - The key to look up. + * @returns The value. + */ get(key: string): Promise; + + /** + * Set a value in our DB. + * @param key - The key to update. + * @param value - The value to set. + * @returns Nothing. + */ set(key: string, value: Buffer): Promise; } diff --git a/yarn-project/foundation/src/wasm/worker/node/node_data_store.ts b/yarn-project/foundation/src/wasm/worker/node/node_data_store.ts index 007e4bc643d2..24bb39747bf9 100644 --- a/yarn-project/foundation/src/wasm/worker/node/node_data_store.ts +++ b/yarn-project/foundation/src/wasm/worker/node/node_data_store.ts @@ -17,20 +17,10 @@ export class NodeDataStore implements DataStore { this.db = levelup(path ? (leveldown as any)(path) : (memdown as any)()); } - /** - * Get a value from our DB. - * @param key - The key to look up. - * @returns The value. - */ async get(key: string): Promise { return await this.db.get(key).catch(() => {}); } - /** - * Set a value in our DB. - * @param key - The key to update. - * @param value - The value to set. - */ async set(key: string, value: Buffer): Promise { await this.db.put(key, value); } diff --git a/yarn-project/key-store/src/key_pair.ts b/yarn-project/key-store/src/key_pair.ts index 59960d0753b1..2a27127707f9 100644 --- a/yarn-project/key-store/src/key_pair.ts +++ b/yarn-project/key-store/src/key_pair.ts @@ -35,22 +35,10 @@ export class ConstantKeyPair implements KeyPair { constructor(private publicKey: PublicKey, private privateKey: PrivateKey) {} - /** - * Retrieve the public key from the KeyPair instance. - * The returned public key is a PublicKey object which represents a point on the elliptic curve secp256k1. - * - * @returns The public key as an elliptic curve point. - */ public getPublicKey(): PublicKey { return this.publicKey; } - /** - * Retrieves the private key of the KeyPair instance. - * The function returns a Promise that resolves to a Buffer containing the private key. - * - * @returns A Promise that resolves to a Buffer containing the private key. - */ public getPrivateKey() { return Promise.resolve(this.privateKey); } diff --git a/yarn-project/key-store/src/test_key_store.ts b/yarn-project/key-store/src/test_key_store.ts index 85e93ecc4d1f..cea6fc3a3b82 100644 --- a/yarn-project/key-store/src/test_key_store.ts +++ b/yarn-project/key-store/src/test_key_store.ts @@ -12,12 +12,6 @@ export class TestKeyStore implements KeyStore { private accounts: KeyPair[] = []; constructor(private curve: Grumpkin) {} - /** - * Adds an account to the key store from the provided private key. - * @param curve - The curve to use for generating the public key. - * @param privKey - The private key of the account. - * @returns - The account's public key. - */ public addAccount(privKey: PrivateKey): PublicKey { const keyPair = ConstantKeyPair.fromPrivateKey(this.curve, privKey); @@ -31,37 +25,16 @@ export class TestKeyStore implements KeyStore { return keyPair.getPublicKey(); } - /** - * Adds a new account to the TestKeyStore with a randomly generated ConstantKeyPair. - * The account will have its own private and public key pair, which can be used for signing transactions. - * @param curve - The curve to use for generating the public key. - * @returns A promise that resolves to the newly created account's AztecAddress. - */ public createAccount(): Promise { const keyPair = ConstantKeyPair.random(this.curve); this.accounts.push(keyPair); return Promise.resolve(keyPair.getPublicKey()); } - /** - * Retrieves the public keys of all accounts stored in the TestKeyStore. - * The returned addresses are instances of `PublicKey` and can be used for subsequent operations - * such as signing transactions or fetching public/private keys. - * - * @returns A Promise that resolves to an array of public keys instances. - */ public getAccounts(): Promise { return Promise.resolve(this.accounts.map(a => a.getPublicKey())); } - /** - * Retrieves the private key of the account associated with the specified AztecAddress. - * Throws an error if the provided address is not found in the list of registered accounts. - * - * @param pubKey - The AztecAddress instance representing the account for which the private key is requested. - * @returns A Promise that resolves to a Buffer containing the private key. - * @deprecated We should not require a keystore to expose private keys in plain. - */ public getAccountPrivateKey(pubKey: PublicKey): Promise { const account = this.getAccount(pubKey); return account.getPrivateKey(); diff --git a/yarn-project/merkle-tree/src/pedersen.ts b/yarn-project/merkle-tree/src/pedersen.ts index b4c3b19124dc..376f2708d3ae 100644 --- a/yarn-project/merkle-tree/src/pedersen.ts +++ b/yarn-project/merkle-tree/src/pedersen.ts @@ -13,45 +13,18 @@ import { Hasher } from '@aztec/types'; export class Pedersen implements Hasher { constructor(private wasm: IWasmModule) {} - /** - * Compresses two 32-byte hashes. - * @param lhs - The first hash. - * @param rhs - The second hash. - * @returns The new 32-byte hash. - */ public compress(lhs: Uint8Array, rhs: Uint8Array): Buffer { return pedersenCompress(this.wasm, lhs, rhs); } - /** - * Compresses an array of buffers. - * @param inputs - The array of buffers to compress. - * @returns The resulting 32-byte hash. - */ public compressInputs(inputs: Buffer[]): Buffer { return pedersenHashInputs(this.wasm, inputs); } - /** - * Get a 32-byte pedersen hash from a buffer. - * @param data - The data buffer. - * @returns The resulting hash buffer. - */ public hashToField(data: Uint8Array): Buffer { return pedersenGetHash(this.wasm, Buffer.from(data)); } - /** - * Given a buffer containing 32 byte pedersen leaves, return a new buffer containing the leaves and all pairs of - * nodes that define a merkle tree. - * - * E.g. - * Input: [1][2][3][4] - * Output: [1][2][3][4][compress(1,2)][compress(3,4)][compress(5,6)]. - * - * @param leaves - The 32 byte pedersen leaves. - * @returns A tree represented by an array. - */ public hashToTree(leaves: Buffer[]): Promise { return Promise.resolve(pedersenGetHashTree(this.wasm, leaves)); } diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index a390a4c70244..009efca161b5 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -35,12 +35,14 @@ export interface P2PSyncState { export interface P2P { /** * Verifies the 'tx' and, if valid, adds it to local tx pool and forwards it to other peers. + * @param tx - The transaction. **/ sendTx(tx: Tx): Promise; /** * Deletes 'txs' from the pool, given hashes. * NOT used if we use sendTx as reconcileTxPool will handle this. + * @param txHashes - Hashes to check. **/ deleteTxs(txHashes: TxHash[]): Promise; @@ -52,6 +54,7 @@ export interface P2P { /** * Returns a transaction in the transaction pool by its hash. + * @param txHash - Hash of tx to return. * @returns A single tx or undefined. */ getTxByhash(txHash: TxHash): Promise; @@ -74,7 +77,7 @@ export interface P2P { */ isReady(): Promise; - /* + /** * Returns the current status of the p2p client. */ getStatus(): Promise; diff --git a/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts b/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts index 26ddbd28b9a3..4b878107284b 100644 --- a/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts +++ b/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts @@ -5,8 +5,20 @@ import { createDebugLogger } from '@aztec/foundation/log'; * Reads values from L1 state that is used for the global values. */ export interface L1GlobalReader { + /** + * Fetches the last timestamp that a block was processed by the contract. + * @returns The last timestamp that a block was processed by the contract. + */ getLastTimestamp(): Promise; + /** + * Fetches the version of the rollup contract. + * @returns The version of the rollup contract. + */ getVersion(): Promise; + /** + * Gets the chain id. + * @returns The chain id. + */ getChainId(): Promise; } @@ -14,6 +26,11 @@ export interface L1GlobalReader { * Builds global variables from L1 state. */ export interface GlobalVariableBuilder { + /** + * Builds global variables. + * @param blockNumber - The block number to build global variables for. + * @returns The global variables for the given block number. + */ buildGlobalVariables(blockNumber: Fr): Promise; } diff --git a/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts b/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts index d7ffbad0f403..54328f78c3a0 100644 --- a/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts +++ b/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts @@ -39,26 +39,14 @@ export class ViemReader implements L1GlobalReader { }); } - /** - * Fetches the last timestamp that a block was processed by the contract. - * @returns The last timestamp that a block was processed by the contract. - */ public async getLastTimestamp(): Promise { return BigInt(await this.rollupContract.read.lastBlockTs()); } - /** - * Fetches the version of the rollup contract. - * @returns The version of the rollup contract. - */ public async getVersion(): Promise { return BigInt(await this.rollupContract.read.VERSION()); } - /** - * Gets the chain id. - * @returns The chain id. - */ public async getChainId(): Promise { return await Promise.resolve(BigInt(this.publicClient.chain.id)); } diff --git a/yarn-project/sequencer-client/src/prover/index.ts b/yarn-project/sequencer-client/src/prover/index.ts index 984cd01682de..02125db9dff2 100644 --- a/yarn-project/sequencer-client/src/prover/index.ts +++ b/yarn-project/sequencer-client/src/prover/index.ts @@ -13,8 +13,25 @@ import { * Generates proofs for the base, merge, and root rollup circuits. */ export interface RollupProver { + /** + * Creates a proof for the given input. + * @param input - Input to the circuit. + * @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call. + */ getBaseRollupProof(input: BaseRollupInputs, publicInputs: BaseOrMergeRollupPublicInputs): Promise; + + /** + * Creates a proof for the given input. + * @param input - Input to the circuit. + * @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call. + */ getMergeRollupProof(input: MergeRollupInputs, publicInputs: BaseOrMergeRollupPublicInputs): Promise; + + /** + * Creates a proof for the given input. + * @param input - Input to the circuit. + * @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call. + */ getRootRollupProof(input: RootRollupInputs, publicInputs: RootRollupPublicInputs): Promise; } @@ -22,6 +39,15 @@ export interface RollupProver { * Generates proofs for the public and public kernel circuits. */ export interface PublicProver { + /** + * Creates a proof for the given input. + * @param publicInputs - Public inputs obtained via simulation. + */ getPublicCircuitProof(publicInputs: PublicCircuitPublicInputs): Promise; + + /** + * Creates a proof for the given input. + * @param publicInputs - Public inputs obtained via simulation. + */ getPublicKernelCircuitProof(publicInputs: PublicKernelPublicInputs): Promise; } diff --git a/yarn-project/sequencer-client/src/simulator/index.ts b/yarn-project/sequencer-client/src/simulator/index.ts index 35cff20445f6..a9ede5663766 100644 --- a/yarn-project/sequencer-client/src/simulator/index.ts +++ b/yarn-project/sequencer-client/src/simulator/index.ts @@ -38,13 +38,13 @@ export interface RollupSimulator { export interface PublicKernelCircuitSimulator { /** * Simulates the public kernel circuit (with a previous private kernel circuit run) from its inputs. - * @param input - Inputs to the circuit. + * @param inputs - Inputs to the circuit. * @returns The public inputs as outputs of the simulation. */ publicKernelCircuitPrivateInput(inputs: PublicKernelInputs): Promise; /** * Simulates the public kernel circuit (with no previous public kernel circuit run) from its inputs. - * @param input - Inputs to the circuit. + * @param inputs - Inputs to the circuit. * @returns The public inputs as outputs of the simulation. */ publicKernelCircuitNonFirstIteration(inputs: PublicKernelInputs): Promise; diff --git a/yarn-project/sequencer-client/src/simulator/public_executor.ts b/yarn-project/sequencer-client/src/simulator/public_executor.ts index 0a96592344eb..1949f13b9c39 100644 --- a/yarn-project/sequencer-client/src/simulator/public_executor.ts +++ b/yarn-project/sequencer-client/src/simulator/public_executor.ts @@ -85,12 +85,6 @@ class WorldStatePublicDB implements PublicStateDB { export class WorldStateDB implements CommitmentsDB { constructor(private db: MerkleTreeOperations, private l1ToL2MessageSource: L1ToL2MessageSource) {} - /** - * Gets a confirmed L1 to L2 message for the given message key. - * TODO(Maddiaa): Can be combined with aztec-node method that does the same thing. - * @param messageKey - The message Key. - * @returns - The l1 to l2 message object - */ public async getL1ToL2Message(messageKey: Fr): Promise { // todo: #697 - make this one lookup. const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(messageKey); @@ -104,12 +98,6 @@ export class WorldStateDB implements CommitmentsDB { }; } - /** - * Gets a message index and sibling path to some commitment in the private data tree. - * @param address - The contract address owning storage. - * @param commitment - The preimage of the siloed data. - * @returns - The Commitment data oracle object - */ public async getCommitmentOracle(address: AztecAddress, commitment: Fr): Promise { const siloedCommitment = siloCommitment(await CircuitsWasm.get(), address, commitment); const index = (await this.db.findLeafIndex(MerkleTreeId.PRIVATE_DATA_TREE, siloedCommitment.toBuffer()))!; @@ -122,10 +110,6 @@ export class WorldStateDB implements CommitmentsDB { }; } - /** - * Gets the current tree roots from the merkle db. - * @returns current tree roots. - */ public getTreeRoots(): PrivateHistoricTreeRoots { const roots = this.db.getCommitmentTreeRoots(); diff --git a/yarn-project/types/src/contract_database.ts b/yarn-project/types/src/contract_database.ts index c2928be91a77..3a8a81bb01ad 100644 --- a/yarn-project/types/src/contract_database.ts +++ b/yarn-project/types/src/contract_database.ts @@ -7,6 +7,21 @@ import { ContractDao } from './contract_dao.js'; * Provides methods for adding and retrieving ContractDao objects by their associated addresses. */ export interface ContractDatabase { + /** + * Adds a new ContractDao instance to the contract database. + * The function stores the contract in an array and returns a resolved promise indicating successful addition. + * + * @param contract - The ContractDao instance to be added. + * @returns A Promise that resolves when the contract is successfully added. + */ addContract(contract: ContractDao): Promise; + + /** + * Retrieve a ContractDao instance with the specified AztecAddress. + * Returns the first match found or undefined if no contract with the given address is found. + * + * @param address - The AztecAddress to search for in the stored contracts. + * @returns A Promise resolving to the ContractDao instance matching the given address or undefined. + */ getContract(address: AztecAddress): Promise; } diff --git a/yarn-project/types/src/interfaces/aztec-node.ts b/yarn-project/types/src/interfaces/aztec-node.ts index a46a2fc7a4da..bc1b4018011f 100644 --- a/yarn-project/types/src/interfaces/aztec-node.ts +++ b/yarn-project/types/src/interfaces/aztec-node.ts @@ -80,6 +80,7 @@ export interface AztecNode extends DataCommitmentProvider, L1ToL2MessageProvider /** * Method to submit a transaction to the p2p pool. * @param tx - The transaction to be submitted. + * @returns Nothing. */ sendTx(tx: Tx): Promise; diff --git a/yarn-project/types/src/interfaces/aztec_rpc.ts b/yarn-project/types/src/interfaces/aztec_rpc.ts index 7edd9dd79510..584d1d0c6a60 100644 --- a/yarn-project/types/src/interfaces/aztec_rpc.ts +++ b/yarn-project/types/src/interfaces/aztec_rpc.ts @@ -50,37 +50,180 @@ export type NodeInfo = { * as well as storage and view functions for smart contracts. */ export interface AztecRPC { + /** + * Registers an account backed by an account contract. + * + * @param privKey - Private key of the corresponding user master public key. + * @param address - Address of the account contract. + * @param partialContractAddress - The partially computed address of the account contract. + * @returns The address of the account contract. + */ addAccount( privKey: PrivateKey, address: AztecAddress, partialContractAddress: PartialContractAddress, ): Promise; + + /** + * Retrieves the list of Aztec addresses added to this rpc server + * The addresses are returned as a promise that resolves to an array of AztecAddress objects. + * + * @returns A promise that resolves to an array of AztecAddress instances. + */ getAccounts(): Promise; + + /** + * Retrieve the public key associated with an address. + * Throws an error if the account is not found in the key store. + * + * @param address - The AztecAddress instance representing the account to get public key for. + * @returns A Promise resolving to the PublicKey instance representing the public key. + */ getPublicKey(address: AztecAddress): Promise; + + /** + * Add an array of deployed contracts to the database. + * Each contract should contain ABI, address, and portalContract information. + * + * @param contracts - An array of DeployedContract objects containing contract ABI, address, and portalContract. + * @returns A Promise that resolves once all the contracts have been added to the database. + */ addContracts(contracts: DeployedContract[]): Promise; + /** * Is an L2 contract deployed at this address? - * @param contractAddress - The contract data address. + * @param contract - The contract data address. * @returns Whether the contract was deployed. */ isContractDeployed(contract: AztecAddress): Promise; + + /** + * Create a transaction for a contract function call with the provided arguments. + * Throws an error if the contract or function is unknown. + * + * @param txRequest - An authenticated tx request ready for simulation + * @param optionalFromAddress - The address to simulate from + * @returns A Tx ready to send to the p2p pool for execution. + */ simulateTx(txRequest: TxExecutionRequest): Promise; + + /** + * Send a transaction. + * @param tx - The transaction. + * @returns A hash of the transaction, used to identify it. + */ sendTx(tx: Tx): Promise; + + /** + * Fetches a transaction receipt for a tx. + * @param txHash - The transaction hash. + * @returns A receipt of the transaction. + */ getTxReceipt(txHash: TxHash): Promise; + + /** + * Retrieves the storage data at a specified contract address and storage slot. + * The returned data is an array of note preimage items, with each item containing its value. + * + * @param contract - The AztecAddress of the target contract. + * @param storageSlot - The Fr representing the storage slot to be fetched. + * @returns A promise that resolves to an array of note preimage items, each containing its value. + */ getStorageAt(contract: AztecAddress, storageSlot: Fr): Promise; + + /** + * Retrieves the public storage data at a specified contract address and storage slot. + * The returned data is an array of note preimage items, with each item containing its value. + * + * @param contract - The AztecAddress of the target contract. + * @param storageSlot - The Fr representing the storage slot to be fetched. + * @returns A promise that resolves to an array of note preimage items, each containing its value. + */ getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise; + + /** + * Simulate the execution of a view (read-only) function on a deployed contract without actually modifying state. + * This is useful to inspect contract state, for example fetching a variable value or calling a getter function. + * The function takes function name and arguments as parameters, along with the contract address + * and optionally the sender's address. + * + * @param functionName - The name of the function to be called in the contract. + * @param args - The arguments to be provided to the function. + * @param to - The address of the contract to be called. + * @param from - (Optional) The caller of the transaction. + * @returns The result of the view function call, structured based on the function ABI. + */ viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress): Promise; + + /** + * Lookup the L2 contract data for this contract. + * Contains the ethereum portal address and bytecode. + * @param contractAddress - The contract data address. + * @returns The complete contract data including portal address & bytecode (if we didn't throw an error). + */ getContractData(contractAddress: AztecAddress): Promise; + + /** + * Lookup the L2 contract info for this contract. + * Contains the ethereum portal address . + * @param contractAddress - The contract data address. + * @returns The contract's address & portal address. + */ getContractInfo(contractAddress: AztecAddress): Promise; + + /** + * Gets L2 block unencrypted logs. + * @param from - Number of the L2 block to which corresponds the first unencrypted logs to be returned. + * @param take - The number of unencrypted logs to return. + * @returns The requested unencrypted logs. + */ getUnencryptedLogs(from: number, take: number): Promise; + + /** + * Get latest L2 block number. + * @returns The latest block number. + */ getBlockNum(): Promise; + + /** + * Returns the information about the server's node + * @returns - The node information. + */ getNodeInfo(): Promise; + + /** + * Adds public key and partial address to a database. + * @param address - Address of the account to add public key and partial address for. + * @param publicKey - Public key of the corresponding user. + * @param partialAddress - The partially computed address of the account contract. + * @returns A Promise that resolves once the public key has been added to the database. + */ addPublicKeyAndPartialAddress( address: AztecAddress, publicKey: PublicKey, partialAddress: PartialContractAddress, ): Promise; + + /** + * Retrieve the public key and partial contract address associated with an address. + * Throws an error if the account is not found in the key store. + * + * @param address - The AztecAddress instance representing the account to get public key and partial address for. + * @returns A Promise resolving to the PublicKey instance representing the public key. + */ getPublicKeyAndPartialAddress(address: AztecAddress): Promise<[PublicKey, PartialContractAddress]>; + + /** + * Return true if the top level block synchronisation is up to date + * This indicates that blocks and transactions are synched even if notes are not + * @returns True if there are no outstanding blocks to be synched + */ isSynchronised(): Promise; + + /** + * Returns true if the account specified by the given address is synched to the latest block + * @param account - The aztec address for which to query the sync status + * @returns True if the account is fully synched, false otherwise + */ isAccountSynchronised(account: AztecAddress): Promise; } diff --git a/yarn-project/types/src/interfaces/hasher.ts b/yarn-project/types/src/interfaces/hasher.ts index f457839d9ff5..aea50dc0ae10 100644 --- a/yarn-project/types/src/interfaces/hasher.ts +++ b/yarn-project/types/src/interfaces/hasher.ts @@ -2,8 +2,38 @@ * Defines hasher interface used by Merkle trees. */ export interface Hasher { + /** + * Compresses two 32-byte hashes. + * @param lhs - The first hash. + * @param rhs - The second hash. + * @returns The new 32-byte hash. + */ compress(lhs: Uint8Array, rhs: Uint8Array): Buffer; + + /** + * Compresses an array of buffers. + * @param inputs - The array of buffers to compress. + * @returns The resulting 32-byte hash. + */ compressInputs(inputs: Buffer[]): Buffer; + + /** + * Get a 32-byte hash from a buffer. + * @param data - The data buffer. + * @returns The resulting hash buffer. + */ hashToField(data: Uint8Array): Buffer; + + /** + * Given a buffer containing 32 byte leaves, return a new buffer containing the leaves and all pairs of + * nodes that define a merkle tree. + * + * E.g. + * Input: [1][2][3][4] + * Output: [1][2][3][4][compress(1,2)][compress(3,4)][compress(5,6)]. + * + * @param leaves - The 32 byte leaves. + * @returns A tree represented by an array. + */ hashToTree(leaves: Buffer[]): Promise; } diff --git a/yarn-project/types/src/keys/key_pair.ts b/yarn-project/types/src/keys/key_pair.ts index 9a59b455026f..63c8994ff14f 100644 --- a/yarn-project/types/src/keys/key_pair.ts +++ b/yarn-project/types/src/keys/key_pair.ts @@ -5,6 +5,16 @@ import { PrivateKey, PublicKey } from '@aztec/circuits.js'; * Provides functionality to generate, access, and sign messages using the key pair. */ export interface KeyPair { + /** + * Retrieve the public key from the KeyPair instance. + * The returned public key is a PublicKey object which represents a point on an elliptic curve. + * @returns The public key as an elliptic curve point. + */ getPublicKey(): PublicKey; + /** + * Retrieves the private key of the KeyPair instance. + * The function returns a Promise that resolves to a Buffer containing the private key. + * @returns A Promise that resolves to a Buffer containing the private key. + */ getPrivateKey(): Promise; } diff --git a/yarn-project/types/src/keys/key_store.ts b/yarn-project/types/src/keys/key_store.ts index 4826dc0f41c9..f39c43b4ae8a 100644 --- a/yarn-project/types/src/keys/key_store.ts +++ b/yarn-project/types/src/keys/key_store.ts @@ -5,8 +5,35 @@ import { PrivateKey, PublicKey } from '@aztec/circuits.js'; * Provides functionality to create and retrieve accounts, private and public keys, */ export interface KeyStore { + /** + * Adds a new account with a randomly generated key pair. + * The account will have its own private and public key pair, which can be used for signing transactions. + * @returns A promise that resolves to the newly created account's AztecAddress. + */ createAccount(): Promise; + + /** + * Adds an account to the key store from the provided private key. + * @param curve - The curve to use for generating the public key. + * @param privKey - The private key of the account. + * @returns - The account's public key. + */ addAccount(privKey: PrivateKey): PublicKey; + + /** + * Retrieves the public keys of all accounts stored. + * The returned addresses are instances of `PublicKey` and can be used for subsequent operations + * such as signing transactions or fetching public/private keys. + * @returns A Promise that resolves to an array of public keys instances. + */ getAccounts(): Promise; + + /** + * Retrieves the private key of the account associated with the specified AztecAddress. + * Throws an error if the provided address is not found in the list of registered accounts. + * @param pubKey - The AztecAddress instance representing the account for which the private key is requested. + * @returns A Promise that resolves to a Buffer containing the private key. + * @deprecated We should not require a keystore to expose private keys in plain. + */ getAccountPrivateKey(pubKey: PublicKey): Promise; } diff --git a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts index 79fda0599c9d..a1665ec17c2e 100644 --- a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts +++ b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts @@ -34,26 +34,14 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser { ); } - /** - * Returns an instance of MerkleTreeOperations that will include uncommitted data. - * @returns An instance of MerkleTreeOperations that will include uncommitted data. - */ public getLatest(): MerkleTreeOperations { return new MerkleTreeOperationsFacade(this.merkleTreeDb, true); } - /** - * Returns an instance of MerkleTreeOperations that will not include uncommitted data. - * @returns An instance of MerkleTreeOperations that will not include uncommitted data. - */ public getCommitted(): MerkleTreeOperations { return new MerkleTreeOperationsFacade(this.merkleTreeDb, false); } - /** - * Starts the synchroniser. - * @returns A promise that resolves once the initial sync is completed. - */ public async start() { if (this.currentState === WorldStateRunningState.STOPPED) { throw new Error('Synchroniser already stopped'); @@ -94,9 +82,6 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser { return this.syncPromise; } - /** - * Stops the synchroniser. - */ public async stop() { this.log('Stopping world state...'); this.stopping = true; @@ -105,10 +90,6 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser { this.setCurrentState(WorldStateRunningState.STOPPED); } - /** - * Returns the current status of the synchroniser. - * @returns The current status of the synchroniser. - */ public status(): Promise { const status = { syncedToL2Block: this.currentL2BlockNum, diff --git a/yarn-project/world-state/src/synchroniser/world_state_synchroniser.ts b/yarn-project/world-state/src/synchroniser/world_state_synchroniser.ts index c760bfd1ce39..e7a14ee6d4e2 100644 --- a/yarn-project/world-state/src/synchroniser/world_state_synchroniser.ts +++ b/yarn-project/world-state/src/synchroniser/world_state_synchroniser.ts @@ -28,9 +28,32 @@ export interface WorldStateStatus { * Defines the interface for a world state synchroniser. */ export interface WorldStateSynchroniser { + /** + * Starts the synchroniser. + * @returns A promise that resolves once the initial sync is completed. + */ start(): void; + + /** + * Returns the current status of the synchroniser. + * @returns The current status of the synchroniser. + */ status(): Promise; + + /** + * Stops the synchroniser. + */ stop(): Promise; + + /** + * Returns an instance of MerkleTreeOperations that will include uncommitted data. + * @returns An instance of MerkleTreeOperations that will include uncommitted data. + */ getLatest(): MerkleTreeOperations; + + /** + * Returns an instance of MerkleTreeOperations that will not include uncommitted data. + * @returns An instance of MerkleTreeOperations that will not include uncommitted data. + */ getCommitted(): MerkleTreeOperations; }