@aztec/pxe 0.0.1-commit.e61ad554 → 0.0.1-commit.ec5f612
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/dest/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts +5 -3
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +11 -5
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +54 -30
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +174 -70
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +3 -3
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +10 -10
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +5 -5
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +38 -26
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +36 -36
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +74 -29
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +53 -29
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +84 -63
- package/dest/contract_logging.d.ts +22 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +23 -0
- package/dest/contract_sync/contract_sync_service.d.ts +43 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +97 -0
- package/dest/contract_sync/helpers.d.ts +29 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/{index.js → helpers.js} +13 -12
- package/dest/debug/pxe_debug_utils.d.ts +24 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +28 -18
- package/dest/entrypoints/client/bundle/index.d.ts +4 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +3 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +21 -7
- package/dest/entrypoints/client/lazy/index.d.ts +4 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +3 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +22 -8
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +4 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +3 -1
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +28 -9
- package/dest/events/event_service.d.ts +4 -5
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +5 -6
- package/dest/job_coordinator/job_coordinator.d.ts +3 -2
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
- package/dest/job_coordinator/job_coordinator.js +3 -2
- package/dest/logs/log_service.d.ts +7 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +19 -29
- package/dest/notes/note_service.d.ts +7 -7
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +9 -9
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +2 -2
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +203 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +21 -13
- package/dest/private_kernel/private_kernel_oracle.d.ts +8 -4
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +7 -3
- package/dest/pxe.d.ts +69 -23
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +98 -63
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
- package/dest/storage/capsule_store/capsule_store.js +6 -8
- package/dest/storage/contract_store/contract_store.d.ts +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +157 -72
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +13 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +147 -107
- package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +84 -61
- package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
- package/dest/storage/private_event_store/stored_private_event.js +2 -2
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +5 -5
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +184 -114
- package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/index.d.ts +2 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -6
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -8
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -9
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +3 -6
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -8
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +14 -15
- package/package.json +25 -16
- package/src/access_scopes.ts +9 -0
- package/src/block_synchronizer/block_synchronizer.ts +23 -19
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +323 -128
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +12 -12
- package/src/contract_function_simulator/oracle/oracle.ts +41 -24
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +100 -110
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +139 -70
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +152 -0
- package/src/contract_sync/{index.ts → helpers.ts} +21 -21
- package/src/debug/pxe_debug_utils.ts +63 -19
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +16 -15
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/client/lazy/utils.ts +17 -15
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +3 -1
- package/src/entrypoints/server/utils.ts +22 -26
- package/src/events/event_service.ts +4 -6
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +31 -38
- package/src/notes/note_service.ts +9 -10
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +2 -2
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +25 -15
- package/src/private_kernel/private_kernel_oracle.ts +9 -9
- package/src/pxe.ts +191 -115
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
- package/src/storage/capsule_store/capsule_store.ts +8 -8
- package/src/storage/contract_store/contract_store.ts +186 -76
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +169 -132
- package/src/storage/private_event_store/private_event_store.ts +102 -81
- package/src/storage/private_event_store/stored_private_event.ts +3 -3
- package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +214 -130
- package/src/tagging/get_all_logs_by_tags.ts +31 -7
- package/src/tagging/index.ts +1 -1
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +9 -12
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +12 -17
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +6 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +14 -23
- package/dest/contract_sync/index.d.ts +0 -23
- package/dest/contract_sync/index.d.ts.map +0 -1
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
|
@@ -57,14 +57,14 @@ export class CapsuleStore implements StagedStore {
|
|
|
57
57
|
*/
|
|
58
58
|
async #getFromStage(jobId: string, dbSlotKey: string): Promise<Buffer | null | undefined> {
|
|
59
59
|
const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return staged;
|
|
60
|
+
const staged: Buffer | null | undefined = jobStagedCapsules.get(dbSlotKey);
|
|
61
|
+
|
|
62
|
+
// Always issue DB read to keep IndexedDB transaction alive, even if the value is in the job staged data. This
|
|
63
|
+
// keeps IndexedDB transactions alive (they auto-commit when a new micro-task starts and there are no pending read
|
|
64
|
+
// requests). The staged value still takes precedence if it exists (including null for deletions).
|
|
65
|
+
const dbValue = await this.#loadCapsuleFromDb(dbSlotKey);
|
|
66
|
+
|
|
67
|
+
return staged !== undefined ? staged : dbValue;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { FUNCTION_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
4
|
+
import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
5
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
5
6
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
6
7
|
import {
|
|
@@ -19,7 +20,8 @@ import {
|
|
|
19
20
|
} from '@aztec/stdlib/abi';
|
|
20
21
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
22
|
import {
|
|
22
|
-
type
|
|
23
|
+
type ContractClassIdPreimage,
|
|
24
|
+
type ContractClassWithId,
|
|
23
25
|
type ContractInstanceWithAddress,
|
|
24
26
|
SerializableContractInstance,
|
|
25
27
|
getContractClassFromArtifact,
|
|
@@ -27,6 +29,68 @@ import {
|
|
|
27
29
|
|
|
28
30
|
import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
29
31
|
|
|
32
|
+
const VERSION = 1 as const;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* All contract class data except the large packedBytecode.
|
|
36
|
+
* The expensive data from the ContractClass is precomputed and stored in this format to avoid redundant hashing.
|
|
37
|
+
* Since we have to store the artifacts anyway, the final ContractClass is reconstructed by combining this data
|
|
38
|
+
* with the packedBytecode obtained from the former. That way we can have quick class lookups without wasted storage.
|
|
39
|
+
*/
|
|
40
|
+
export class SerializableContractClassData {
|
|
41
|
+
public readonly version = VERSION;
|
|
42
|
+
public readonly id: Fr;
|
|
43
|
+
public readonly artifactHash: Fr;
|
|
44
|
+
public readonly privateFunctionsRoot: Fr;
|
|
45
|
+
public readonly publicBytecodeCommitment: Fr;
|
|
46
|
+
public readonly privateFunctions: { selector: FunctionSelector; vkHash: Fr }[];
|
|
47
|
+
|
|
48
|
+
constructor(
|
|
49
|
+
data: ContractClassIdPreimage & {
|
|
50
|
+
id: Fr;
|
|
51
|
+
privateFunctions: { selector: FunctionSelector; vkHash: Fr }[];
|
|
52
|
+
},
|
|
53
|
+
) {
|
|
54
|
+
this.id = data.id;
|
|
55
|
+
this.artifactHash = data.artifactHash;
|
|
56
|
+
this.privateFunctionsRoot = data.privateFunctionsRoot;
|
|
57
|
+
this.publicBytecodeCommitment = data.publicBytecodeCommitment;
|
|
58
|
+
this.privateFunctions = data.privateFunctions;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
toBuffer(): Buffer {
|
|
62
|
+
return serializeToBuffer(
|
|
63
|
+
numToUInt8(this.version),
|
|
64
|
+
this.id,
|
|
65
|
+
this.artifactHash,
|
|
66
|
+
this.privateFunctionsRoot,
|
|
67
|
+
this.publicBytecodeCommitment,
|
|
68
|
+
this.privateFunctions.length,
|
|
69
|
+
...this.privateFunctions.map(fn => serializeToBuffer(fn.selector, fn.vkHash)),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static fromBuffer(bufferOrReader: Buffer | BufferReader): SerializableContractClassData {
|
|
74
|
+
const reader = BufferReader.asReader(bufferOrReader);
|
|
75
|
+
const version = reader.readUInt8();
|
|
76
|
+
if (version !== VERSION) {
|
|
77
|
+
throw new Error(`Unexpected contract class data version ${version}`);
|
|
78
|
+
}
|
|
79
|
+
return new SerializableContractClassData({
|
|
80
|
+
id: reader.readObject(Fr),
|
|
81
|
+
artifactHash: reader.readObject(Fr),
|
|
82
|
+
privateFunctionsRoot: reader.readObject(Fr),
|
|
83
|
+
publicBytecodeCommitment: reader.readObject(Fr),
|
|
84
|
+
privateFunctions: reader.readVector({
|
|
85
|
+
fromBuffer: (r: BufferReader) => ({
|
|
86
|
+
selector: r.readObject(FunctionSelector),
|
|
87
|
+
vkHash: r.readObject(Fr),
|
|
88
|
+
}),
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
30
94
|
/**
|
|
31
95
|
* ContractStore serves as a data manager and retriever for Aztec.nr contracts.
|
|
32
96
|
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
|
|
@@ -39,37 +103,68 @@ export class ContractStore {
|
|
|
39
103
|
// TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
40
104
|
#privateFunctionTrees: Map<string, PrivateFunctionsTree> = new Map();
|
|
41
105
|
|
|
42
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* In-memory cache of deserialized ContractArtifact objects, keyed by class id string.
|
|
108
|
+
* Avoids repeated LMDB reads + JSON.parse + Zod validation on every oracle call.
|
|
109
|
+
* Artifacts are large but immutable after registration — safe to cache for the lifetime of the store.
|
|
110
|
+
*/
|
|
111
|
+
// TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
112
|
+
#contractArtifactCache: Map<string, ContractArtifact> = new Map();
|
|
113
|
+
|
|
114
|
+
/** Map from contract address to contract class id (avoids KV round-trip on hot path). */
|
|
43
115
|
#contractClassIdMap: Map<string, Fr> = new Map();
|
|
44
116
|
|
|
117
|
+
#store: AztecAsyncKVStore;
|
|
45
118
|
#contractArtifacts: AztecAsyncMap<string, Buffer>;
|
|
119
|
+
#contractClassData: AztecAsyncMap<string, Buffer>;
|
|
46
120
|
#contractInstances: AztecAsyncMap<string, Buffer>;
|
|
47
121
|
|
|
48
122
|
constructor(store: AztecAsyncKVStore) {
|
|
123
|
+
this.#store = store;
|
|
49
124
|
this.#contractArtifacts = store.openMap('contract_artifacts');
|
|
125
|
+
this.#contractClassData = store.openMap('contract_classes');
|
|
50
126
|
this.#contractInstances = store.openMap('contracts_instances');
|
|
51
127
|
}
|
|
52
128
|
|
|
53
129
|
// Setters
|
|
54
130
|
|
|
55
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Registers a new contract artifact and its corresponding class data.
|
|
133
|
+
* IMPORTANT: This method does not verify that the provided artifact matches the class data or that the class id matches the artifact.
|
|
134
|
+
* It is the caller's responsibility to ensure the consistency and correctness of the provided data.
|
|
135
|
+
* This is done to avoid redundant, expensive contract class computations
|
|
136
|
+
*/
|
|
137
|
+
public async addContractArtifact(
|
|
138
|
+
contract: ContractArtifact,
|
|
139
|
+
contractClassWithIdAndPreimage?: ContractClassWithId & ContractClassIdPreimage,
|
|
140
|
+
): Promise<Fr> {
|
|
141
|
+
const contractClass = contractClassWithIdAndPreimage ?? (await getContractClassFromArtifact(contract));
|
|
142
|
+
const key = contractClass.id.toString();
|
|
143
|
+
|
|
144
|
+
if (this.#contractArtifactCache.has(key)) {
|
|
145
|
+
return contractClass.id;
|
|
146
|
+
}
|
|
147
|
+
|
|
56
148
|
const privateFunctions = contract.functions.filter(
|
|
57
149
|
functionArtifact => functionArtifact.functionType === FunctionType.PRIVATE,
|
|
58
150
|
);
|
|
59
|
-
|
|
60
151
|
const privateSelectors = await Promise.all(
|
|
61
|
-
privateFunctions.map(async
|
|
62
|
-
(
|
|
63
|
-
await FunctionSelector.fromNameAndParameters(privateFunctionArtifact.name, privateFunctionArtifact.parameters)
|
|
64
|
-
).toString(),
|
|
152
|
+
privateFunctions.map(async fn =>
|
|
153
|
+
(await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)).toString(),
|
|
65
154
|
),
|
|
66
155
|
);
|
|
67
|
-
|
|
68
156
|
if (privateSelectors.length !== new Set(privateSelectors).size) {
|
|
69
157
|
throw new Error('Repeated function selectors of private functions');
|
|
70
158
|
}
|
|
71
159
|
|
|
72
|
-
|
|
160
|
+
this.#contractArtifactCache.set(key, contract);
|
|
161
|
+
|
|
162
|
+
await this.#store.transactionAsync(async () => {
|
|
163
|
+
await this.#contractArtifacts.set(key, contractArtifactToBuffer(contract));
|
|
164
|
+
await this.#contractClassData.set(key, new SerializableContractClassData(contractClass).toBuffer());
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return contractClass.id;
|
|
73
168
|
}
|
|
74
169
|
|
|
75
170
|
async addContractInstance(contract: ContractInstanceWithAddress): Promise<void> {
|
|
@@ -84,26 +179,17 @@ export class ContractStore {
|
|
|
84
179
|
// Private getters
|
|
85
180
|
|
|
86
181
|
async #getContractClassId(contractAddress: AztecAddress): Promise<Fr | undefined> {
|
|
87
|
-
|
|
182
|
+
const key = contractAddress.toString();
|
|
183
|
+
if (!this.#contractClassIdMap.has(key)) {
|
|
88
184
|
const instance = await this.getContractInstance(contractAddress);
|
|
89
185
|
if (!instance) {
|
|
90
186
|
return;
|
|
91
187
|
}
|
|
92
|
-
this.#contractClassIdMap.set(
|
|
188
|
+
this.#contractClassIdMap.set(key, instance.currentContractClassId);
|
|
93
189
|
}
|
|
94
|
-
return this.#contractClassIdMap.get(
|
|
190
|
+
return this.#contractClassIdMap.get(key);
|
|
95
191
|
}
|
|
96
192
|
|
|
97
|
-
/**
|
|
98
|
-
* Retrieve or create a ContractTree instance based on the provided class id.
|
|
99
|
-
* If an existing tree with the same class id is found in the cache, it will be returned.
|
|
100
|
-
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
101
|
-
* and added to the cache before returning.
|
|
102
|
-
*
|
|
103
|
-
* @param classId - The class id of the contract for which the ContractTree is required.
|
|
104
|
-
* @returns A ContractTree instance associated with the specified contract address.
|
|
105
|
-
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
106
|
-
*/
|
|
107
193
|
async #getPrivateFunctionTreeForClassId(classId: Fr): Promise<PrivateFunctionsTree | undefined> {
|
|
108
194
|
if (!this.#privateFunctionTrees.has(classId.toString())) {
|
|
109
195
|
const artifact = await this.getContractArtifact(classId);
|
|
@@ -116,34 +202,61 @@ export class ContractStore {
|
|
|
116
202
|
return this.#privateFunctionTrees.get(classId.toString())!;
|
|
117
203
|
}
|
|
118
204
|
|
|
119
|
-
async #
|
|
120
|
-
const
|
|
121
|
-
return
|
|
205
|
+
async #getArtifactByAddress(contractAddress: AztecAddress): Promise<ContractArtifact | undefined> {
|
|
206
|
+
const classId = await this.#getContractClassId(contractAddress);
|
|
207
|
+
return classId && this.getContractArtifact(classId);
|
|
122
208
|
}
|
|
123
209
|
|
|
124
210
|
// Public getters
|
|
125
211
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
212
|
+
getContractsAddresses(): Promise<AztecAddress[]> {
|
|
213
|
+
return this.#store.transactionAsync(async () => {
|
|
214
|
+
const keys = await toArray(this.#contractInstances.keysAsync());
|
|
215
|
+
return keys.map(AztecAddress.fromString);
|
|
216
|
+
});
|
|
129
217
|
}
|
|
130
218
|
|
|
131
|
-
/** Returns a contract instance for a given address.
|
|
132
|
-
public
|
|
133
|
-
|
|
134
|
-
|
|
219
|
+
/** Returns a contract instance for a given address. */
|
|
220
|
+
public getContractInstance(contractAddress: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
221
|
+
return this.#store.transactionAsync(async () => {
|
|
222
|
+
const contract = await this.#contractInstances.getAsync(contractAddress.toString());
|
|
223
|
+
return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
|
|
224
|
+
});
|
|
135
225
|
}
|
|
136
226
|
|
|
227
|
+
/** Returns the raw contract artifact for a given class id. */
|
|
137
228
|
public async getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | undefined> {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
229
|
+
const key = contractClassId.toString();
|
|
230
|
+
const cached = this.#contractArtifactCache.get(key);
|
|
231
|
+
if (cached) {
|
|
232
|
+
return cached;
|
|
233
|
+
}
|
|
234
|
+
const artifact = await this.#store.transactionAsync(async () => {
|
|
235
|
+
const buf = await this.#contractArtifacts.getAsync(key);
|
|
236
|
+
return buf && contractArtifactFromBuffer(buf);
|
|
237
|
+
});
|
|
238
|
+
if (artifact) {
|
|
239
|
+
this.#contractArtifactCache.set(key, artifact);
|
|
240
|
+
}
|
|
241
|
+
return artifact;
|
|
141
242
|
}
|
|
142
243
|
|
|
143
|
-
/** Returns a contract class for a given class id.
|
|
144
|
-
public async
|
|
244
|
+
/** Returns a contract class for a given class id. */
|
|
245
|
+
public async getContractClassWithPreimage(
|
|
246
|
+
contractClassId: Fr,
|
|
247
|
+
): Promise<(ContractClassWithId & ContractClassIdPreimage) | undefined> {
|
|
248
|
+
const key = contractClassId.toString();
|
|
249
|
+
const buf = await this.#contractClassData.getAsync(key);
|
|
250
|
+
if (!buf) {
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
const classData = SerializableContractClassData.fromBuffer(buf);
|
|
145
254
|
const artifact = await this.getContractArtifact(contractClassId);
|
|
146
|
-
|
|
255
|
+
if (!artifact) {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
const packedBytecode = artifact.functions.find(f => f.name === 'public_dispatch')?.bytecode ?? Buffer.alloc(0);
|
|
259
|
+
return { ...classData, packedBytecode };
|
|
147
260
|
}
|
|
148
261
|
|
|
149
262
|
public async getContract(
|
|
@@ -162,8 +275,6 @@ export class ContractStore {
|
|
|
162
275
|
|
|
163
276
|
/**
|
|
164
277
|
* Retrieves the artifact of a specified function within a given contract.
|
|
165
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
166
|
-
* Throws an error if the contract address or function selector are invalid or not found.
|
|
167
278
|
*
|
|
168
279
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
169
280
|
* @param selector - The function selector.
|
|
@@ -173,9 +284,12 @@ export class ContractStore {
|
|
|
173
284
|
contractAddress: AztecAddress,
|
|
174
285
|
selector: FunctionSelector,
|
|
175
286
|
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
176
|
-
const artifact = await this.#
|
|
177
|
-
|
|
178
|
-
|
|
287
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
288
|
+
if (!artifact) {
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
const fn = await this.#findFunctionArtifactBySelector(artifact, selector);
|
|
292
|
+
return fn && { ...fn, contractName: artifact.name };
|
|
179
293
|
}
|
|
180
294
|
|
|
181
295
|
public async getFunctionArtifactWithDebugMetadata(
|
|
@@ -196,50 +310,48 @@ export class ContractStore {
|
|
|
196
310
|
public async getPublicFunctionArtifact(
|
|
197
311
|
contractAddress: AztecAddress,
|
|
198
312
|
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
199
|
-
const artifact = await this.#
|
|
200
|
-
const
|
|
201
|
-
return
|
|
313
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
314
|
+
const fn = artifact && artifact.functions.find(f => f.functionType === FunctionType.PUBLIC);
|
|
315
|
+
return fn && { ...fn, contractName: artifact.name };
|
|
202
316
|
}
|
|
203
317
|
|
|
204
318
|
public async getFunctionAbi(
|
|
205
319
|
contractAddress: AztecAddress,
|
|
206
320
|
selector: FunctionSelector,
|
|
207
321
|
): Promise<FunctionAbi | undefined> {
|
|
208
|
-
const artifact = await this.#
|
|
322
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
209
323
|
return artifact && (await this.#findFunctionAbiBySelector(artifact, selector));
|
|
210
324
|
}
|
|
211
325
|
|
|
212
326
|
/**
|
|
213
327
|
* Retrieves the debug metadata of a specified function within a given contract.
|
|
214
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
215
|
-
* Returns undefined if the debug metadata for the given function is not found.
|
|
216
|
-
* Throws if the contract has not been added to the database.
|
|
217
328
|
*
|
|
218
329
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
219
330
|
* @param selector - The function selector.
|
|
220
|
-
* @returns The corresponding function's
|
|
331
|
+
* @returns The corresponding function's debug metadata, or undefined.
|
|
221
332
|
*/
|
|
222
333
|
public async getFunctionDebugMetadata(
|
|
223
334
|
contractAddress: AztecAddress,
|
|
224
335
|
selector: FunctionSelector,
|
|
225
336
|
): Promise<FunctionDebugMetadata | undefined> {
|
|
226
|
-
const artifact = await this.#
|
|
227
|
-
|
|
228
|
-
|
|
337
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
338
|
+
if (!artifact) {
|
|
339
|
+
return undefined;
|
|
340
|
+
}
|
|
341
|
+
const fn = await this.#findFunctionArtifactBySelector(artifact, selector);
|
|
342
|
+
return fn && getFunctionDebugMetadata(artifact, fn);
|
|
229
343
|
}
|
|
230
344
|
|
|
231
345
|
public async getPublicFunctionDebugMetadata(
|
|
232
346
|
contractAddress: AztecAddress,
|
|
233
347
|
): Promise<FunctionDebugMetadata | undefined> {
|
|
234
|
-
const artifact = await this.#
|
|
235
|
-
const
|
|
236
|
-
return
|
|
348
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
349
|
+
const fn = artifact && artifact.functions.find(f => f.functionType === FunctionType.PUBLIC);
|
|
350
|
+
return fn && getFunctionDebugMetadata(artifact, fn);
|
|
237
351
|
}
|
|
238
352
|
|
|
239
353
|
/**
|
|
240
354
|
* Retrieve the function membership witness for the given contract class and function selector.
|
|
241
|
-
* The function membership witness represents a proof that the function belongs to the specified contract.
|
|
242
|
-
* Throws an error if the contract address or function selector is unknown.
|
|
243
355
|
*
|
|
244
356
|
* @param contractClassId - The id of the class.
|
|
245
357
|
* @param selector - The function selector.
|
|
@@ -254,23 +366,21 @@ export class ContractStore {
|
|
|
254
366
|
}
|
|
255
367
|
|
|
256
368
|
public async getDebugContractName(contractAddress: AztecAddress) {
|
|
257
|
-
const artifact = await this.#
|
|
369
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
258
370
|
return artifact?.name;
|
|
259
371
|
}
|
|
260
372
|
|
|
261
373
|
public async getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector) {
|
|
262
|
-
const artifact = await this.#
|
|
263
|
-
const
|
|
264
|
-
return `${artifact?.name ?? contractAddress}:${
|
|
374
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
375
|
+
const fn = artifact && (await this.#findFunctionAbiBySelector(artifact, selector));
|
|
376
|
+
return `${artifact?.name ?? contractAddress}:${fn?.name ?? selector}`;
|
|
265
377
|
}
|
|
266
378
|
|
|
267
379
|
async #findFunctionArtifactBySelector(
|
|
268
380
|
artifact: ContractArtifact,
|
|
269
381
|
selector: FunctionSelector,
|
|
270
382
|
): Promise<FunctionArtifact | undefined> {
|
|
271
|
-
const
|
|
272
|
-
for (let i = 0; i < functions.length; i++) {
|
|
273
|
-
const fn = functions[i];
|
|
383
|
+
for (const fn of artifact.functions) {
|
|
274
384
|
const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
275
385
|
if (fnSelector.equals(selector)) {
|
|
276
386
|
return fn;
|
|
@@ -282,9 +392,7 @@ export class ContractStore {
|
|
|
282
392
|
artifact: ContractArtifact,
|
|
283
393
|
selector: FunctionSelector,
|
|
284
394
|
): Promise<FunctionAbi | undefined> {
|
|
285
|
-
const
|
|
286
|
-
for (let i = 0; i < functions.length; i++) {
|
|
287
|
-
const fn = functions[i];
|
|
395
|
+
for (const fn of [...artifact.functions, ...(artifact.nonDispatchPublicFunctions ?? [])]) {
|
|
288
396
|
const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
289
397
|
if (fnSelector.equals(selector)) {
|
|
290
398
|
return fn;
|
|
@@ -305,15 +413,17 @@ export class ContractStore {
|
|
|
305
413
|
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
|
|
306
414
|
}
|
|
307
415
|
|
|
308
|
-
|
|
416
|
+
const selector = await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters);
|
|
417
|
+
|
|
418
|
+
return FunctionCall.from({
|
|
309
419
|
name: functionDao.name,
|
|
310
|
-
args: encodeArguments(functionDao, args),
|
|
311
|
-
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
312
|
-
type: functionDao.functionType,
|
|
313
420
|
to,
|
|
421
|
+
selector,
|
|
422
|
+
type: functionDao.functionType,
|
|
314
423
|
hideMsgSender: false,
|
|
315
424
|
isStatic: functionDao.isStatic,
|
|
425
|
+
args: encodeArguments(functionDao, args),
|
|
316
426
|
returnTypes: functionDao.returnTypes,
|
|
317
|
-
};
|
|
427
|
+
});
|
|
318
428
|
}
|
|
319
429
|
}
|
package/src/storage/metadata.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PXE_DATA_SCHEMA_VERSION =
|
|
1
|
+
export const PXE_DATA_SCHEMA_VERSION = 3;
|