@aztec/pxe 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dest/bin/index.d.ts +3 -0
- package/dest/bin/index.d.ts.map +1 -0
- package/dest/bin/index.js +31 -0
- package/dest/config/index.d.ts +21 -0
- package/dest/config/index.d.ts.map +1 -0
- package/dest/config/index.js +21 -0
- package/dest/contract_data_oracle/index.d.ts +99 -0
- package/dest/contract_data_oracle/index.d.ts.map +1 -0
- package/dest/contract_data_oracle/index.js +137 -0
- package/dest/contract_database/index.d.ts +2 -0
- package/dest/contract_database/index.d.ts.map +1 -0
- package/dest/contract_database/index.js +2 -0
- package/dest/contract_database/memory_contract_database.d.ts +43 -0
- package/dest/contract_database/memory_contract_database.d.ts.map +1 -0
- package/dest/contract_database/memory_contract_database.js +51 -0
- package/dest/contract_tree/index.d.ts +107 -0
- package/dest/contract_tree/index.d.ts.map +1 -0
- package/dest/contract_tree/index.js +181 -0
- package/dest/database/database.d.ts +118 -0
- package/dest/database/database.d.ts.map +1 -0
- package/dest/database/database.js +2 -0
- package/dest/database/index.d.ts +4 -0
- package/dest/database/index.d.ts.map +1 -0
- package/dest/database/index.js +4 -0
- package/dest/database/memory_db.d.ts +45 -0
- package/dest/database/memory_db.d.ts.map +1 -0
- package/dest/database/memory_db.js +111 -0
- package/dest/database/note_spending_info_dao.d.ts +44 -0
- package/dest/database/note_spending_info_dao.d.ts.map +1 -0
- package/dest/database/note_spending_info_dao.js +14 -0
- package/dest/index.d.ts +10 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +10 -0
- package/dest/kernel_oracle/index.d.ts +18 -0
- package/dest/kernel_oracle/index.d.ts.map +1 -0
- package/dest/kernel_oracle/index.js +29 -0
- package/dest/kernel_prover/index.d.ts +3 -0
- package/dest/kernel_prover/index.d.ts.map +1 -0
- package/dest/kernel_prover/index.js +3 -0
- package/dest/kernel_prover/kernel_prover.d.ts +89 -0
- package/dest/kernel_prover/kernel_prover.d.ts.map +1 -0
- package/dest/kernel_prover/kernel_prover.js +175 -0
- package/dest/kernel_prover/proof_creator.d.ts +84 -0
- package/dest/kernel_prover/proof_creator.d.ts.map +1 -0
- package/dest/kernel_prover/proof_creator.js +83 -0
- package/dest/kernel_prover/proving_data_oracle.d.ts +53 -0
- package/dest/kernel_prover/proving_data_oracle.d.ts.map +1 -0
- package/dest/kernel_prover/proving_data_oracle.js +2 -0
- package/dest/note_processor/index.d.ts +2 -0
- package/dest/note_processor/index.d.ts.map +1 -0
- package/dest/note_processor/index.js +2 -0
- package/dest/note_processor/note_processor.d.ts +78 -0
- package/dest/note_processor/note_processor.d.ts.map +1 -0
- package/dest/note_processor/note_processor.js +206 -0
- package/dest/pxe_http/index.d.ts +2 -0
- package/dest/pxe_http/index.d.ts.map +1 -0
- package/dest/pxe_http/index.js +2 -0
- package/dest/pxe_http/pxe_http_server.d.ts +40 -0
- package/dest/pxe_http/pxe_http_server.d.ts.map +1 -0
- package/dest/pxe_http/pxe_http_server.js +44 -0
- package/dest/pxe_service/create_pxe_service.d.ts +30 -0
- package/dest/pxe_service/create_pxe_service.d.ts.map +1 -0
- package/dest/pxe_service/create_pxe_service.js +27 -0
- package/dest/pxe_service/index.d.ts +4 -0
- package/dest/pxe_service/index.d.ts.map +1 -0
- package/dest/pxe_service/index.js +4 -0
- package/dest/pxe_service/pxe_service.d.ts +70 -0
- package/dest/pxe_service/pxe_service.d.ts.map +1 -0
- package/dest/pxe_service/pxe_service.js +470 -0
- package/dest/pxe_service/test/pxe_test_suite.d.ts +3 -0
- package/dest/pxe_service/test/pxe_test_suite.d.ts.map +1 -0
- package/dest/pxe_service/test/pxe_test_suite.js +100 -0
- package/dest/simulator/index.d.ts +9 -0
- package/dest/simulator/index.d.ts.map +1 -0
- package/dest/simulator/index.js +11 -0
- package/dest/simulator_oracle/index.d.ts +53 -0
- package/dest/simulator_oracle/index.d.ts.map +1 -0
- package/dest/simulator_oracle/index.js +91 -0
- package/dest/synchronizer/index.d.ts +2 -0
- package/dest/synchronizer/index.d.ts.map +1 -0
- package/dest/synchronizer/index.js +2 -0
- package/dest/synchronizer/synchronizer.d.ts +82 -0
- package/dest/synchronizer/synchronizer.d.ts.map +1 -0
- package/dest/synchronizer/synchronizer.js +241 -0
- package/package.json +74 -0
- package/src/bin/index.ts +39 -0
- package/src/config/index.ts +34 -0
- package/src/contract_data_oracle/index.ts +151 -0
- package/src/contract_database/index.ts +1 -0
- package/src/contract_database/memory_contract_database.ts +58 -0
- package/src/contract_tree/index.ts +245 -0
- package/src/database/database.ts +131 -0
- package/src/database/index.ts +3 -0
- package/src/database/memory_db.ts +147 -0
- package/src/database/note_spending_info_dao.ts +64 -0
- package/src/index.ts +11 -0
- package/src/kernel_oracle/index.ts +39 -0
- package/src/kernel_prover/index.ts +2 -0
- package/src/kernel_prover/kernel_prover.ts +317 -0
- package/src/kernel_prover/proof_creator.ts +176 -0
- package/src/kernel_prover/proving_data_oracle.ts +69 -0
- package/src/note_processor/index.ts +1 -0
- package/src/note_processor/note_processor.ts +267 -0
- package/src/pxe_http/index.ts +1 -0
- package/src/pxe_http/pxe_http_server.ts +70 -0
- package/src/pxe_service/create_pxe_service.ts +52 -0
- package/src/pxe_service/index.ts +3 -0
- package/src/pxe_service/pxe_service.ts +650 -0
- package/src/pxe_service/test/pxe_test_suite.ts +138 -0
- package/src/simulator/index.ts +24 -0
- package/src/simulator_oracle/index.ts +121 -0
- package/src/synchronizer/index.ts +1 -0
- package/src/synchronizer/synchronizer.ts +285 -0
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# PXE Service & PXE
|
|
2
|
+
|
|
3
|
+
`PXE Service` (pronounced "pixie service") is a server-side software that provides a set of apis for interacting with the Aztec network. It acts as a bridge between the network and client applications by exposing methods to manage accounts, deploy contracts, create transactions, and retrieve public and account-specific information. It provides a secure environment for the execution of sensitive operations, ensuring private information and decrypted data are not accessible to unauthorized applications. The PXE Service is a critical component of the Aztec network, and its security and reliability are essential to the overall trustworthiness of user's data.
|
|
4
|
+
|
|
5
|
+
`PXE` is the interface the PXE Service and every client-side instance implement. Various implementations of the client-side can exist, including those for different platforms such as mobile apps and web browsers. It is a relay between the dApps and the actual PXE Service.
|
|
6
|
+
|
|
7
|
+
### Main Components in an PXE Service
|
|
8
|
+
|
|
9
|
+
- [Acir Simulator](../acir-simulator/)
|
|
10
|
+
- [Key Store](../key-store/)
|
|
11
|
+
- [Account State](./src/account_state/account_state.ts): It coordinates other components to synchronize and decrypt data, simulate transactions, and generate kernel proofs, for a specific account.
|
|
12
|
+
|
|
13
|
+

|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env -S node --no-warnings
|
|
2
|
+
import { createDebugLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { createAztecNodeRpcClient } from '@aztec/types';
|
|
4
|
+
import { getPXEServiceConfig } from '../config/index.js';
|
|
5
|
+
import { startPXEHttpServer } from '../pxe_http/index.js';
|
|
6
|
+
import { createPXEService } from '../pxe_service/index.js';
|
|
7
|
+
const { PXE_PORT = 8080, AZTEC_NODE_URL = 'http://localhost:8079' } = process.env;
|
|
8
|
+
const logger = createDebugLogger('aztec:pxe_service');
|
|
9
|
+
/**
|
|
10
|
+
* Create and start a new PXE HTTP Server
|
|
11
|
+
*/
|
|
12
|
+
async function main() {
|
|
13
|
+
logger.info(`Setting up PXE...`);
|
|
14
|
+
const pxeConfig = getPXEServiceConfig();
|
|
15
|
+
const nodeRpcClient = createAztecNodeRpcClient(AZTEC_NODE_URL);
|
|
16
|
+
const pxeService = await createPXEService(nodeRpcClient, pxeConfig);
|
|
17
|
+
const shutdown = async () => {
|
|
18
|
+
logger.info('Shutting down...');
|
|
19
|
+
await pxeService.stop();
|
|
20
|
+
process.exit(0);
|
|
21
|
+
};
|
|
22
|
+
process.once('SIGINT', shutdown);
|
|
23
|
+
process.once('SIGTERM', shutdown);
|
|
24
|
+
startPXEHttpServer(pxeService, PXE_PORT);
|
|
25
|
+
logger.info(`PXE listening on port ${PXE_PORT}`);
|
|
26
|
+
}
|
|
27
|
+
main().catch(err => {
|
|
28
|
+
logger.error(err);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYmluL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFDQSxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUMxRCxPQUFPLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSxjQUFjLENBQUM7QUFFeEQsT0FBTyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDekQsT0FBTyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDMUQsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFM0QsTUFBTSxFQUFFLFFBQVEsR0FBRyxJQUFJLEVBQUUsY0FBYyxHQUFHLHVCQUF1QixFQUFFLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQztBQUVsRixNQUFNLE1BQU0sR0FBRyxpQkFBaUIsQ0FBQyxtQkFBbUIsQ0FBQyxDQUFDO0FBRXREOztHQUVHO0FBQ0gsS0FBSyxVQUFVLElBQUk7SUFDakIsTUFBTSxDQUFDLElBQUksQ0FBQyxtQkFBbUIsQ0FBQyxDQUFDO0lBRWpDLE1BQU0sU0FBUyxHQUFHLG1CQUFtQixFQUFFLENBQUM7SUFDeEMsTUFBTSxhQUFhLEdBQUcsd0JBQXdCLENBQUMsY0FBYyxDQUFDLENBQUM7SUFDL0QsTUFBTSxVQUFVLEdBQUcsTUFBTSxnQkFBZ0IsQ0FBQyxhQUFhLEVBQUUsU0FBUyxDQUFDLENBQUM7SUFFcEUsTUFBTSxRQUFRLEdBQUcsS0FBSyxJQUFJLEVBQUU7UUFDMUIsTUFBTSxDQUFDLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDO1FBQ2hDLE1BQU0sVUFBVSxDQUFDLElBQUksRUFBRSxDQUFDO1FBQ3hCLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDbEIsQ0FBQyxDQUFDO0lBRUYsT0FBTyxDQUFDLElBQUksQ0FBQyxRQUFRLEVBQUUsUUFBUSxDQUFDLENBQUM7SUFDakMsT0FBTyxDQUFDLElBQUksQ0FBQyxTQUFTLEVBQUUsUUFBUSxDQUFDLENBQUM7SUFFbEMsa0JBQWtCLENBQUMsVUFBVSxFQUFFLFFBQVEsQ0FBQyxDQUFDO0lBQ3pDLE1BQU0sQ0FBQyxJQUFJLENBQUMseUJBQXlCLFFBQVEsRUFBRSxDQUFDLENBQUM7QUFDbkQsQ0FBQztBQUVELElBQUksRUFBRSxDQUFDLEtBQUssQ0FBQyxHQUFHLENBQUMsRUFBRTtJQUNqQixNQUFNLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0lBQ2xCLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUM7QUFDbEIsQ0FBQyxDQUFDLENBQUMifQ==
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration settings for the PXE Service.
|
|
3
|
+
*/
|
|
4
|
+
export interface PXEServiceConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The interval to wait between polling for new blocks.
|
|
7
|
+
*/
|
|
8
|
+
l2BlockPollingIntervalMS: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of PXEServiceConfig out of environment variables using sensible defaults for integration testing if not set.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getPXEServiceConfig(): PXEServiceConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Returns package name and version.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getPackageInfo(): {
|
|
18
|
+
version: any;
|
|
19
|
+
name: any;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,wBAAwB,EAAE,MAAM,CAAC;CAClC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,CAMtD;AAED;;GAEG;AACH,wBAAgB,cAAc;;;EAK7B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { dirname, resolve } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
/**
|
|
5
|
+
* Creates an instance of PXEServiceConfig out of environment variables using sensible defaults for integration testing if not set.
|
|
6
|
+
*/
|
|
7
|
+
export function getPXEServiceConfig() {
|
|
8
|
+
const { PXE_BLOCK_POLLING_INTERVAL_MS } = process.env;
|
|
9
|
+
return {
|
|
10
|
+
l2BlockPollingIntervalMS: PXE_BLOCK_POLLING_INTERVAL_MS ? +PXE_BLOCK_POLLING_INTERVAL_MS : 1000,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns package name and version.
|
|
15
|
+
*/
|
|
16
|
+
export function getPackageInfo() {
|
|
17
|
+
const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json');
|
|
18
|
+
const { version, name } = JSON.parse(readFileSync(packageJsonPath).toString());
|
|
19
|
+
return { version, name };
|
|
20
|
+
}
|
|
21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from '@aztec/circuits.js';
|
|
2
|
+
import { FunctionDebugMetadata, FunctionSelector } from '@aztec/foundation/abi';
|
|
3
|
+
import { ContractDatabase, StateInfoProvider } from '@aztec/types';
|
|
4
|
+
/**
|
|
5
|
+
* ContractDataOracle serves as a data manager and retriever for Aztec.nr contracts.
|
|
6
|
+
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
|
|
7
|
+
* from a given contract address and function selector. The class maintains a cache of ContractTree instances
|
|
8
|
+
* to efficiently serve the requested data. It interacts with the ContractDatabase and AztecNode to fetch
|
|
9
|
+
* the required information and facilitate cryptographic proof generation.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ContractDataOracle {
|
|
12
|
+
private db;
|
|
13
|
+
private stateProvider;
|
|
14
|
+
private trees;
|
|
15
|
+
constructor(db: ContractDatabase, stateProvider: StateInfoProvider);
|
|
16
|
+
/**
|
|
17
|
+
* Retrieve the portal contract address associated with the given contract address.
|
|
18
|
+
* This function searches for the corresponding contract tree in the local cache and returns the portal contract address.
|
|
19
|
+
* If the contract tree is not found in the cache, it fetches the contract data from the database and creates a new ContractTree instance.
|
|
20
|
+
* Throws an error if the contract address is not found in the database.
|
|
21
|
+
*
|
|
22
|
+
* @param contractAddress - The AztecAddress of the contract whose portal contract address needs to be retrieved.
|
|
23
|
+
* @returns A Promise that resolves to the portal contract address.
|
|
24
|
+
*/
|
|
25
|
+
getPortalContractAddress(contractAddress: AztecAddress): Promise<import("@aztec/circuits.js").EthAddress>;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the ABI of a specified function within a given contract.
|
|
28
|
+
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
29
|
+
* Throws an error if the contract address or function selector are invalid or not found.
|
|
30
|
+
*
|
|
31
|
+
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
32
|
+
* @param selector - The function selector.
|
|
33
|
+
* @returns The corresponding function's ABI as an object.
|
|
34
|
+
*/
|
|
35
|
+
getFunctionAbi(contractAddress: AztecAddress, selector: FunctionSelector): Promise<import("@aztec/circuits.js").ContractFunctionDao>;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves the debug metadata of a specified function within a given contract.
|
|
38
|
+
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
39
|
+
* Returns undefined if the debug metadata for the given function is not found.
|
|
40
|
+
*
|
|
41
|
+
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
42
|
+
* @param selector - The function selector.
|
|
43
|
+
* @returns The corresponding function's ABI as an object.
|
|
44
|
+
*/
|
|
45
|
+
getFunctionDebugMetadata(contractAddress: AztecAddress, selector: FunctionSelector): Promise<FunctionDebugMetadata | undefined>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieve the bytecode of a specific function in a contract at the given address.
|
|
48
|
+
* The returned bytecode is required for executing and verifying the function's behavior
|
|
49
|
+
* in the Aztec network. Throws an error if the contract or function cannot be found.
|
|
50
|
+
*
|
|
51
|
+
* @param contractAddress - The contract's address.
|
|
52
|
+
* @param selector - The function selector.
|
|
53
|
+
* @returns A Promise that resolves to a Buffer containing the bytecode of the specified function.
|
|
54
|
+
*/
|
|
55
|
+
getBytecode(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Retrieves the contract membership witness for a given contract address.
|
|
58
|
+
* A contract membership witness is a cryptographic proof that the contract exists in the Aztec network.
|
|
59
|
+
* This function will search for an existing contract tree associated with the contract address and obtain its
|
|
60
|
+
* membership witness. If no such contract tree exists, it will throw an error.
|
|
61
|
+
*
|
|
62
|
+
* @param contractAddress - The contract address.
|
|
63
|
+
* @returns A promise that resolves to a MembershipWitness instance representing the contract membership witness.
|
|
64
|
+
* @throws Error if the contract address is unknown or not found.
|
|
65
|
+
*/
|
|
66
|
+
getContractMembershipWitness(contractAddress: AztecAddress): Promise<MembershipWitness<16>>;
|
|
67
|
+
/**
|
|
68
|
+
* Retrieve the function membership witness for the given contract address and function selector.
|
|
69
|
+
* The function membership witness represents a proof that the function belongs to the specified contract.
|
|
70
|
+
* Throws an error if the contract address or function selector is unknown.
|
|
71
|
+
*
|
|
72
|
+
* @param contractAddress - The contract address.
|
|
73
|
+
* @param selector - The function selector.
|
|
74
|
+
* @returns A promise that resolves with the MembershipWitness instance for the specified contract's function.
|
|
75
|
+
*/
|
|
76
|
+
getFunctionMembershipWitness(contractAddress: AztecAddress, selector: FunctionSelector): Promise<MembershipWitness<4>>;
|
|
77
|
+
/**
|
|
78
|
+
* Retrieve the membership witness corresponding to a verification key.
|
|
79
|
+
* This function currently returns a random membership witness of the specified height,
|
|
80
|
+
* which is a placeholder implementation until a concrete membership witness calculation
|
|
81
|
+
* is implemented.
|
|
82
|
+
*
|
|
83
|
+
* @param vk - The VerificationKey for which the membership witness is needed.
|
|
84
|
+
* @returns A Promise that resolves to the MembershipWitness instance.
|
|
85
|
+
*/
|
|
86
|
+
getVkMembershipWitness(): Promise<MembershipWitness<3>>;
|
|
87
|
+
/**
|
|
88
|
+
* Retrieve or create a ContractTree instance based on the provided AztecAddress.
|
|
89
|
+
* If an existing tree with the same contract address is found in the cache, it will be returned.
|
|
90
|
+
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
91
|
+
* and added to the cache before returning.
|
|
92
|
+
*
|
|
93
|
+
* @param contractAddress - The AztecAddress of the contract for which the ContractTree is required.
|
|
94
|
+
* @returns A ContractTree instance associated with the specified contract address.
|
|
95
|
+
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
96
|
+
*/
|
|
97
|
+
private getTree;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contract_data_oracle/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,iBAAiB,EAAkB,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAA4B,MAAM,uBAAuB,CAAC;AAC1G,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAInE;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAGjB,OAAO,CAAC,EAAE;IAAoB,OAAO,CAAC,aAAa;IAF/D,OAAO,CAAC,KAAK,CAAsB;gBAEf,EAAE,EAAE,gBAAgB,EAAU,aAAa,EAAE,iBAAiB;IAElF;;;;;;;;OAQG;IACU,wBAAwB,CAAC,eAAe,EAAE,YAAY;IAKnE;;;;;;;;OAQG;IACU,cAAc,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB;IAKrF;;;;;;;;OAQG;IACU,wBAAwB,CACnC,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IAW7C;;;;;;;;OAQG;IACU,WAAW,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB;IAKlF;;;;;;;;;OASG;IACU,4BAA4B,CAAC,eAAe,EAAE,YAAY;IAKvE;;;;;;;;OAQG;IACU,4BAA4B,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB;IAKnG;;;;;;;;OAQG;IACU,sBAAsB;IAKnC;;;;;;;;;OASG;YACW,OAAO;CActB"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { CircuitsWasm, MembershipWitness, VK_TREE_HEIGHT } from '@aztec/circuits.js';
|
|
2
|
+
import { getFunctionDebugMetadata } from '@aztec/foundation/abi';
|
|
3
|
+
import { ContractTree } from '../contract_tree/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* ContractDataOracle serves as a data manager and retriever for Aztec.nr contracts.
|
|
6
|
+
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
|
|
7
|
+
* from a given contract address and function selector. The class maintains a cache of ContractTree instances
|
|
8
|
+
* to efficiently serve the requested data. It interacts with the ContractDatabase and AztecNode to fetch
|
|
9
|
+
* the required information and facilitate cryptographic proof generation.
|
|
10
|
+
*/
|
|
11
|
+
export class ContractDataOracle {
|
|
12
|
+
constructor(db, stateProvider) {
|
|
13
|
+
this.db = db;
|
|
14
|
+
this.stateProvider = stateProvider;
|
|
15
|
+
this.trees = [];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Retrieve the portal contract address associated with the given contract address.
|
|
19
|
+
* This function searches for the corresponding contract tree in the local cache and returns the portal contract address.
|
|
20
|
+
* If the contract tree is not found in the cache, it fetches the contract data from the database and creates a new ContractTree instance.
|
|
21
|
+
* Throws an error if the contract address is not found in the database.
|
|
22
|
+
*
|
|
23
|
+
* @param contractAddress - The AztecAddress of the contract whose portal contract address needs to be retrieved.
|
|
24
|
+
* @returns A Promise that resolves to the portal contract address.
|
|
25
|
+
*/
|
|
26
|
+
async getPortalContractAddress(contractAddress) {
|
|
27
|
+
const tree = await this.getTree(contractAddress);
|
|
28
|
+
return tree.contract.portalContract;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves the ABI of a specified function within a given contract.
|
|
32
|
+
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
33
|
+
* Throws an error if the contract address or function selector are invalid or not found.
|
|
34
|
+
*
|
|
35
|
+
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
36
|
+
* @param selector - The function selector.
|
|
37
|
+
* @returns The corresponding function's ABI as an object.
|
|
38
|
+
*/
|
|
39
|
+
async getFunctionAbi(contractAddress, selector) {
|
|
40
|
+
const tree = await this.getTree(contractAddress);
|
|
41
|
+
return tree.getFunctionAbi(selector);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Retrieves the debug metadata of a specified function within a given contract.
|
|
45
|
+
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
46
|
+
* Returns undefined if the debug metadata for the given function is not found.
|
|
47
|
+
*
|
|
48
|
+
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
49
|
+
* @param selector - The function selector.
|
|
50
|
+
* @returns The corresponding function's ABI as an object.
|
|
51
|
+
*/
|
|
52
|
+
async getFunctionDebugMetadata(contractAddress, selector) {
|
|
53
|
+
const contract = await this.db.getContract(contractAddress);
|
|
54
|
+
const functionAbi = contract?.functions.find(f => f.selector.equals(selector));
|
|
55
|
+
if (!contract || !functionAbi) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
return getFunctionDebugMetadata(contract, functionAbi.name);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Retrieve the bytecode of a specific function in a contract at the given address.
|
|
62
|
+
* The returned bytecode is required for executing and verifying the function's behavior
|
|
63
|
+
* in the Aztec network. Throws an error if the contract or function cannot be found.
|
|
64
|
+
*
|
|
65
|
+
* @param contractAddress - The contract's address.
|
|
66
|
+
* @param selector - The function selector.
|
|
67
|
+
* @returns A Promise that resolves to a Buffer containing the bytecode of the specified function.
|
|
68
|
+
*/
|
|
69
|
+
async getBytecode(contractAddress, selector) {
|
|
70
|
+
const tree = await this.getTree(contractAddress);
|
|
71
|
+
return tree.getBytecode(selector);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves the contract membership witness for a given contract address.
|
|
75
|
+
* A contract membership witness is a cryptographic proof that the contract exists in the Aztec network.
|
|
76
|
+
* This function will search for an existing contract tree associated with the contract address and obtain its
|
|
77
|
+
* membership witness. If no such contract tree exists, it will throw an error.
|
|
78
|
+
*
|
|
79
|
+
* @param contractAddress - The contract address.
|
|
80
|
+
* @returns A promise that resolves to a MembershipWitness instance representing the contract membership witness.
|
|
81
|
+
* @throws Error if the contract address is unknown or not found.
|
|
82
|
+
*/
|
|
83
|
+
async getContractMembershipWitness(contractAddress) {
|
|
84
|
+
const tree = await this.getTree(contractAddress);
|
|
85
|
+
return tree.getContractMembershipWitness();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Retrieve the function membership witness for the given contract address and function selector.
|
|
89
|
+
* The function membership witness represents a proof that the function belongs to the specified contract.
|
|
90
|
+
* Throws an error if the contract address or function selector is unknown.
|
|
91
|
+
*
|
|
92
|
+
* @param contractAddress - The contract address.
|
|
93
|
+
* @param selector - The function selector.
|
|
94
|
+
* @returns A promise that resolves with the MembershipWitness instance for the specified contract's function.
|
|
95
|
+
*/
|
|
96
|
+
async getFunctionMembershipWitness(contractAddress, selector) {
|
|
97
|
+
const tree = await this.getTree(contractAddress);
|
|
98
|
+
return tree.getFunctionMembershipWitness(selector);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Retrieve the membership witness corresponding to a verification key.
|
|
102
|
+
* This function currently returns a random membership witness of the specified height,
|
|
103
|
+
* which is a placeholder implementation until a concrete membership witness calculation
|
|
104
|
+
* is implemented.
|
|
105
|
+
*
|
|
106
|
+
* @param vk - The VerificationKey for which the membership witness is needed.
|
|
107
|
+
* @returns A Promise that resolves to the MembershipWitness instance.
|
|
108
|
+
*/
|
|
109
|
+
async getVkMembershipWitness() {
|
|
110
|
+
// TODO
|
|
111
|
+
return await Promise.resolve(MembershipWitness.random(VK_TREE_HEIGHT));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Retrieve or create a ContractTree instance based on the provided AztecAddress.
|
|
115
|
+
* If an existing tree with the same contract address is found in the cache, it will be returned.
|
|
116
|
+
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
117
|
+
* and added to the cache before returning.
|
|
118
|
+
*
|
|
119
|
+
* @param contractAddress - The AztecAddress of the contract for which the ContractTree is required.
|
|
120
|
+
* @returns A ContractTree instance associated with the specified contract address.
|
|
121
|
+
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
122
|
+
*/
|
|
123
|
+
async getTree(contractAddress) {
|
|
124
|
+
let tree = this.trees.find(t => t.contract.completeAddress.address.equals(contractAddress));
|
|
125
|
+
if (!tree) {
|
|
126
|
+
const contract = await this.db.getContract(contractAddress);
|
|
127
|
+
if (!contract) {
|
|
128
|
+
throw new Error(`Unknown contract: ${contractAddress}`);
|
|
129
|
+
}
|
|
130
|
+
const wasm = await CircuitsWasm.get();
|
|
131
|
+
tree = new ContractTree(contract, this.stateProvider, wasm);
|
|
132
|
+
this.trees.push(tree);
|
|
133
|
+
}
|
|
134
|
+
return tree;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3RfZGF0YV9vcmFjbGUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFnQixZQUFZLEVBQUUsaUJBQWlCLEVBQUUsY0FBYyxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDbkcsT0FBTyxFQUEyQyx3QkFBd0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRzFHLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUV6RDs7Ozs7O0dBTUc7QUFDSCxNQUFNLE9BQU8sa0JBQWtCO0lBRzdCLFlBQW9CLEVBQW9CLEVBQVUsYUFBZ0M7UUFBOUQsT0FBRSxHQUFGLEVBQUUsQ0FBa0I7UUFBVSxrQkFBYSxHQUFiLGFBQWEsQ0FBbUI7UUFGMUUsVUFBSyxHQUFtQixFQUFFLENBQUM7SUFFa0QsQ0FBQztJQUV0Rjs7Ozs7Ozs7T0FRRztJQUNJLEtBQUssQ0FBQyx3QkFBd0IsQ0FBQyxlQUE2QjtRQUNqRSxNQUFNLElBQUksR0FBRyxNQUFNLElBQUksQ0FBQyxPQUFPLENBQUMsZUFBZSxDQUFDLENBQUM7UUFDakQsT0FBTyxJQUFJLENBQUMsUUFBUSxDQUFDLGNBQWMsQ0FBQztJQUN0QyxDQUFDO0lBRUQ7Ozs7Ozs7O09BUUc7SUFDSSxLQUFLLENBQUM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O2FBQ3pEO1lBRUQsTUFBTSxJQUFJLEdBQUcsTUFBTSxZQUFZLENBQUMsR0FBRyxFQUFFLENBQUM7WUFDdEMsSUFBSSxHQUFHLElBQUksWUFBWSxDQUFDLFFBQVEsRUFBRSxJQUFJLENBQUMsYUFBYSxFQUFFLElBQUksQ0FBQyxDQUFDO1lBQzVELElBQUksQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFDO1NBQ3ZCO1FBQ0QsT0FBTyxJQUFJLENBQUM7SUFDZCxDQUFDO0NBQ0YifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contract_database/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export * from './memory_contract_database.js';
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3RfZGF0YWJhc2UvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYywrQkFBK0IsQ0FBQyJ9
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FunctionSelector } from '@aztec/circuits.js';
|
|
2
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
|
+
import { DebugLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { ContractDao, ContractDatabase } from '@aztec/types';
|
|
5
|
+
/**
|
|
6
|
+
* The MemoryContractDatabase class serves as an in-memory implementation of the ContractDatabase interface.
|
|
7
|
+
* It allows for storing and retrieving contract data, such as ContractDao objects and associated function bytecodes,
|
|
8
|
+
* within a contracts array. This class is particularly useful for testing and development purposes where a
|
|
9
|
+
* persistent storage may not be required.
|
|
10
|
+
*/
|
|
11
|
+
export declare class MemoryContractDatabase implements ContractDatabase {
|
|
12
|
+
protected log: DebugLogger;
|
|
13
|
+
private contracts;
|
|
14
|
+
constructor(log: DebugLogger);
|
|
15
|
+
/**
|
|
16
|
+
* Adds a new ContractDao instance to the memory-based contract database.
|
|
17
|
+
* The function stores the contract in an array and returns a resolved promise indicating successful addition.
|
|
18
|
+
*
|
|
19
|
+
* @param contract - The ContractDao instance to be added to the memory database.
|
|
20
|
+
* @returns A Promise that resolves when the contract is successfully added.
|
|
21
|
+
*/
|
|
22
|
+
addContract(contract: ContractDao): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Retrieve a ContractDao instance with the specified AztecAddress from the in-memory contracts list.
|
|
25
|
+
* Returns the first match found or undefined if no contract with the given address is found.
|
|
26
|
+
*
|
|
27
|
+
* @param address - The AztecAddress to search for in the stored contracts.
|
|
28
|
+
* @returns A Promise resolving to the ContractDao instance matching the given address or undefined.
|
|
29
|
+
*/
|
|
30
|
+
getContract(address: AztecAddress): Promise<ContractDao | undefined>;
|
|
31
|
+
getContracts(): Promise<ContractDao[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve the bytecode associated with a given contract address and function selector.
|
|
34
|
+
* This function searches through the stored contracts to find a matching contract and function,
|
|
35
|
+
* then returns the corresponding bytecode. If no match is found, it returns undefined.
|
|
36
|
+
*
|
|
37
|
+
* @param contractAddress - The AztecAddress representing the contract address to look for.
|
|
38
|
+
* @param selector - The function selector.
|
|
39
|
+
* @returns A Promise that resolves to the bytecode of the matching function or undefined if not found.
|
|
40
|
+
*/
|
|
41
|
+
getCode(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=memory_contract_database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory_contract_database.d.ts","sourceRoot":"","sources":["../../src/contract_database/memory_contract_database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE7D;;;;;GAKG;AACH,qBAAa,sBAAuB,YAAW,gBAAgB;IAGjD,SAAS,CAAC,GAAG,EAAE,WAAW;IAFtC,OAAO,CAAC,SAAS,CAAqB;gBAEhB,GAAG,EAAE,WAAW;IAEtC;;;;;;OAMG;IACI,WAAW,CAAC,QAAQ,EAAE,WAAW;IAMxC;;;;;;OAMG;IACI,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAIpE,YAAY,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAI7C;;;;;;;;OAQG;IACU,OAAO,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB;CAI/E"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MemoryContractDatabase class serves as an in-memory implementation of the ContractDatabase interface.
|
|
3
|
+
* It allows for storing and retrieving contract data, such as ContractDao objects and associated function bytecodes,
|
|
4
|
+
* within a contracts array. This class is particularly useful for testing and development purposes where a
|
|
5
|
+
* persistent storage may not be required.
|
|
6
|
+
*/
|
|
7
|
+
export class MemoryContractDatabase {
|
|
8
|
+
constructor(log) {
|
|
9
|
+
this.log = log;
|
|
10
|
+
this.contracts = [];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Adds a new ContractDao instance to the memory-based contract database.
|
|
14
|
+
* The function stores the contract in an array and returns a resolved promise indicating successful addition.
|
|
15
|
+
*
|
|
16
|
+
* @param contract - The ContractDao instance to be added to the memory database.
|
|
17
|
+
* @returns A Promise that resolves when the contract is successfully added.
|
|
18
|
+
*/
|
|
19
|
+
addContract(contract) {
|
|
20
|
+
this.log(`Adding contract ${contract.completeAddress.address.toString()}`);
|
|
21
|
+
this.contracts.push(contract);
|
|
22
|
+
return Promise.resolve();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Retrieve a ContractDao instance with the specified AztecAddress from the in-memory contracts list.
|
|
26
|
+
* Returns the first match found or undefined if no contract with the given address is found.
|
|
27
|
+
*
|
|
28
|
+
* @param address - The AztecAddress to search for in the stored contracts.
|
|
29
|
+
* @returns A Promise resolving to the ContractDao instance matching the given address or undefined.
|
|
30
|
+
*/
|
|
31
|
+
getContract(address) {
|
|
32
|
+
return Promise.resolve(this.contracts.find(c => c.completeAddress.address.equals(address)));
|
|
33
|
+
}
|
|
34
|
+
getContracts() {
|
|
35
|
+
return Promise.resolve(this.contracts);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Retrieve the bytecode associated with a given contract address and function selector.
|
|
39
|
+
* This function searches through the stored contracts to find a matching contract and function,
|
|
40
|
+
* then returns the corresponding bytecode. If no match is found, it returns undefined.
|
|
41
|
+
*
|
|
42
|
+
* @param contractAddress - The AztecAddress representing the contract address to look for.
|
|
43
|
+
* @param selector - The function selector.
|
|
44
|
+
* @returns A Promise that resolves to the bytecode of the matching function or undefined if not found.
|
|
45
|
+
*/
|
|
46
|
+
async getCode(contractAddress, selector) {
|
|
47
|
+
const contract = await this.getContract(contractAddress);
|
|
48
|
+
return contract?.functions.find(f => f.selector.equals(selector))?.bytecode;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVtb3J5X2NvbnRyYWN0X2RhdGFiYXNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnRyYWN0X2RhdGFiYXNlL21lbW9yeV9jb250cmFjdF9kYXRhYmFzZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFLQTs7Ozs7R0FLRztBQUNILE1B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LENBQUMsUUFBUSxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQyxFQUFFLFFBQVEsQ0FBQztJQUM5RSxDQUFDO0NBQ0YifQ==
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { CircuitsWasm, EthAddress, FUNCTION_TREE_HEIGHT, Fr, MembershipWitness, NewContractConstructor } from '@aztec/circuits.js';
|
|
2
|
+
import { ContractAbi, FunctionSelector } from '@aztec/foundation/abi';
|
|
3
|
+
import { AztecNode, ContractDao, PublicKey, StateInfoProvider } from '@aztec/types';
|
|
4
|
+
/**
|
|
5
|
+
* The ContractTree class represents a Merkle tree of functions for a particular contract.
|
|
6
|
+
* It manages the construction of the function tree, computes its root, and generates membership witnesses
|
|
7
|
+
* for constrained functions. This class also enables lookup of specific function ABI and bytecode using selectors.
|
|
8
|
+
* It is used in combination with the AztecNode to compute various data for executing private transactions.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ContractTree {
|
|
11
|
+
/**
|
|
12
|
+
* The contract data object containing the ABI and contract address.
|
|
13
|
+
*/
|
|
14
|
+
readonly contract: ContractDao;
|
|
15
|
+
private stateInfoProvider;
|
|
16
|
+
private wasm;
|
|
17
|
+
/**
|
|
18
|
+
* Data associated with the contract constructor for a new contract.
|
|
19
|
+
*/
|
|
20
|
+
readonly newContractConstructor?: NewContractConstructor | undefined;
|
|
21
|
+
private functionLeaves?;
|
|
22
|
+
private functionTree?;
|
|
23
|
+
private functionTreeRoot?;
|
|
24
|
+
private contractIndex?;
|
|
25
|
+
constructor(
|
|
26
|
+
/**
|
|
27
|
+
* The contract data object containing the ABI and contract address.
|
|
28
|
+
*/
|
|
29
|
+
contract: ContractDao, stateInfoProvider: StateInfoProvider, wasm: CircuitsWasm,
|
|
30
|
+
/**
|
|
31
|
+
* Data associated with the contract constructor for a new contract.
|
|
32
|
+
*/
|
|
33
|
+
newContractConstructor?: NewContractConstructor | undefined);
|
|
34
|
+
/**
|
|
35
|
+
* Create a new ContractTree instance from the provided contract ABI, constructor arguments, and related data.
|
|
36
|
+
* The function generates function leaves for constrained functions, computes the function tree root,
|
|
37
|
+
* and hashes the constructor's verification key. It then computes the contract address using the contract
|
|
38
|
+
* and portal contract addresses, contract address salt, and generated data. Finally, it returns a new
|
|
39
|
+
* ContractTree instance containing the contract data and computed values.
|
|
40
|
+
*
|
|
41
|
+
* @param abi - The contract's ABI containing the functions and their metadata.
|
|
42
|
+
* @param args - An array of Fr elements representing the constructor's arguments.
|
|
43
|
+
* @param portalContract - The Ethereum address of the portal smart contract.
|
|
44
|
+
* @param contractAddressSalt - An Fr element representing the salt used to compute the contract address.
|
|
45
|
+
* @param from - The public key of the contract deployer.
|
|
46
|
+
* @param node - An instance of the AztecNode class representing the current node.
|
|
47
|
+
* @returns A new ContractTree instance containing the contract data and computed values.
|
|
48
|
+
*/
|
|
49
|
+
static new(abi: ContractAbi, args: Fr[], portalContract: EthAddress, contractAddressSalt: Fr, from: PublicKey, node: AztecNode): Promise<ContractTree>;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieve the ABI of a given function.
|
|
52
|
+
* The function is identified by its selector, which represents a unique identifier for the function's signature.
|
|
53
|
+
* Throws an error if the function with the provided selector is not found in the contract.
|
|
54
|
+
*
|
|
55
|
+
* @param selector - The function selector.
|
|
56
|
+
* @returns The ABI object containing relevant information about the targeted function.
|
|
57
|
+
*/
|
|
58
|
+
getFunctionAbi(selector: FunctionSelector): import("@aztec/circuits.js").ContractFunctionDao;
|
|
59
|
+
/**
|
|
60
|
+
* Retrieve the bytecode of a function in the contract by its function selector.
|
|
61
|
+
* The function selector is a unique identifier for each function in a contract.
|
|
62
|
+
* Throws an error if the function with the given selector is not found in the contract.
|
|
63
|
+
*
|
|
64
|
+
* @param selector - The selector of a function to get bytecode for.
|
|
65
|
+
* @returns The bytecode of the function as a string.
|
|
66
|
+
*/
|
|
67
|
+
getBytecode(selector: FunctionSelector): string;
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves the contract membership witness for the current contract tree instance.
|
|
70
|
+
* The contract membership witness is a proof that demonstrates the existence of the contract
|
|
71
|
+
* in the global contract merkle tree. This proof contains the index of the contract's leaf
|
|
72
|
+
* in the tree and the sibling path needed to construct the root of the merkle tree.
|
|
73
|
+
* If the witness hasn't been previously computed, this function will request the contract node
|
|
74
|
+
* to find the contract's index and path in order to create the membership witness.
|
|
75
|
+
*
|
|
76
|
+
* @returns A Promise that resolves to the MembershipWitness object for the given contract tree.
|
|
77
|
+
*/
|
|
78
|
+
getContractMembershipWitness(): Promise<MembershipWitness<16>>;
|
|
79
|
+
/**
|
|
80
|
+
* Calculate and return the root of the function tree for the current contract.
|
|
81
|
+
* This root is a cryptographic commitment to the set of constrained functions within the contract,
|
|
82
|
+
* which is used in the Aztec node's proof system. The root will be cached after the first call.
|
|
83
|
+
*
|
|
84
|
+
* @returns A promise that resolves to the Fr (finite field element) representation of the function tree root.
|
|
85
|
+
*/
|
|
86
|
+
getFunctionTreeRoot(): Promise<Fr>;
|
|
87
|
+
/**
|
|
88
|
+
* Retrieve the membership witness of a function within a contract's function tree.
|
|
89
|
+
* A membership witness represents the position and authentication path of a target function
|
|
90
|
+
* in the Merkle tree of constrained functions. It is required to prove the existence of the
|
|
91
|
+
* function within the contract during execution.
|
|
92
|
+
*
|
|
93
|
+
* @param selector - The function selector.
|
|
94
|
+
* @returns A MembershipWitness instance representing the position and authentication path of the function in the function tree.
|
|
95
|
+
*/
|
|
96
|
+
getFunctionMembershipWitness(selector: FunctionSelector): Promise<MembershipWitness<typeof FUNCTION_TREE_HEIGHT>>;
|
|
97
|
+
/**
|
|
98
|
+
* Retrieve the function leaves for the contract tree.
|
|
99
|
+
* Function leaves are computed based on constrained functions present in the contract.
|
|
100
|
+
* It caches the computed function leaves and returns them if already calculated.
|
|
101
|
+
*
|
|
102
|
+
* @returns An array of Fr representing the function leaves.
|
|
103
|
+
*/
|
|
104
|
+
private getFunctionLeaves;
|
|
105
|
+
private getContractIndex;
|
|
106
|
+
}
|
|
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