@aztec/pxe 0.0.1-commit.fcb71a6 → 0.0.1-commit.ff7989d6c
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/bin/check_oracle_version.js +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts +13 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +74 -20
- package/dest/config/index.d.ts +3 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -0
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
- package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/benchmarked_node.js +77 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +57 -34
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +197 -82
- package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +45 -28
- package/dest/contract_function_simulator/index.d.ts +2 -2
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -3
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -3
- 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 +2 -2
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +17 -13
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
- package/dest/contract_function_simulator/oracle/oracle.d.ts +12 -10
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +67 -44
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +1 -37
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +44 -50
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +83 -54
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +67 -33
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +131 -110
- 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/helpers.js +55 -0
- 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 -17
- 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 +31 -8
- 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 +32 -9
- package/dest/entrypoints/pxe_creation_options.d.ts +5 -3
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +5 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +4 -0
- 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 +39 -16
- package/dest/events/event_service.d.ts +6 -6
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +19 -22
- package/dest/events/private_event_filter_validator.d.ts +5 -5
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +5 -6
- package/dest/job_coordinator/job_coordinator.d.ts +75 -0
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
- package/dest/job_coordinator/job_coordinator.js +94 -0
- package/dest/logs/log_service.d.ts +8 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +28 -30
- package/dest/notes/note_service.d.ts +10 -9
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +34 -38
- 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 +4 -3
- 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 +3 -3
- package/dest/private_kernel/hints/index.d.ts.map +1 -1
- package/dest/private_kernel/hints/index.js +2 -2
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
- package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +16 -10
- 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 +12 -13
- package/dest/private_kernel/private_kernel_oracle.d.ts +24 -24
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +94 -2
- package/dest/pxe.d.ts +76 -58
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +149 -138
- 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.d.ts +24 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +130 -23
- package/dest/storage/contract_store/contract_store.d.ts +42 -16
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +157 -84
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +50 -51
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +284 -263
- package/dest/storage/note_store/stored_note.d.ts +16 -0
- package/dest/storage/note_store/stored_note.d.ts.map +1 -0
- package/dest/storage/note_store/stored_note.js +43 -0
- package/dest/storage/private_event_store/private_event_store.d.ts +47 -7
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +231 -73
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +88 -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 +19 -9
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +253 -101
- package/dest/tagging/constants.d.ts +2 -0
- package/dest/tagging/constants.d.ts.map +1 -0
- package/dest/tagging/constants.js +10 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +60 -0
- package/dest/tagging/index.d.ts +3 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +2 -10
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
- 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 +12 -12
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
- 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 +5 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +8 -8
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -2
- 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 +10 -5
- package/package.json +27 -18
- package/src/access_scopes.ts +9 -0
- package/src/bin/check_oracle_version.ts +1 -0
- package/src/block_synchronizer/block_synchronizer.ts +93 -32
- package/src/config/index.ts +14 -0
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/benchmarked_node.ts +103 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +350 -143
- package/src/contract_function_simulator/execution_note_cache.ts +44 -25
- package/src/contract_function_simulator/index.ts +1 -1
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +6 -2
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
- package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
- package/src/contract_function_simulator/oracle/interfaces.ts +22 -12
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
- package/src/contract_function_simulator/oracle/oracle.ts +79 -47
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -69
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +119 -137
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +198 -115
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +152 -0
- package/src/contract_sync/helpers.ts +98 -0
- package/src/debug/pxe_debug_utils.ts +63 -18
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +23 -16
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/client/lazy/utils.ts +24 -17
- package/src/entrypoints/pxe_creation_options.ts +4 -2
- package/src/entrypoints/server/index.ts +4 -0
- package/src/entrypoints/server/utils.ts +33 -41
- package/src/events/event_service.ts +19 -25
- package/src/events/private_event_filter_validator.ts +3 -5
- package/src/job_coordinator/job_coordinator.ts +150 -0
- package/src/logs/log_service.ts +40 -34
- package/src/notes/note_service.ts +41 -45
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +4 -3
- 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 +2 -2
- package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +39 -28
- package/src/private_kernel/private_kernel_execution_prover.ts +15 -14
- package/src/private_kernel/private_kernel_oracle.ts +116 -36
- package/src/pxe.ts +280 -209
- 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 +159 -23
- package/src/storage/contract_store/contract_store.ts +186 -96
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +326 -320
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +301 -79
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +106 -20
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +294 -109
- package/src/tagging/constants.ts +10 -0
- package/src/tagging/get_all_logs_by_tags.ts +92 -0
- package/src/tagging/index.ts +2 -11
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +25 -11
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +10 -7
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -13
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
- package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
- package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
- package/dest/contract_function_simulator/proxied_node.js +0 -27
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.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
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
- package/dest/public_storage/public_storage_service.d.ts +0 -24
- package/dest/public_storage/public_storage_service.d.ts.map +0 -1
- package/dest/public_storage/public_storage_service.js +0 -26
- package/dest/tree_membership/tree_membership_service.d.ts +0 -52
- package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.js +0 -84
- package/src/contract_function_simulator/proxied_node.ts +0 -33
- package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
- package/src/public_storage/public_storage_service.ts +0 -33
- package/src/tree_membership/tree_membership_service.ts +0 -112
|
@@ -1,9 +1,9 @@
|
|
|
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
|
-
import { isProtocolContract } from '@aztec/protocol-contracts';
|
|
7
7
|
import {
|
|
8
8
|
type ContractArtifact,
|
|
9
9
|
type FunctionAbi,
|
|
@@ -20,7 +20,8 @@ import {
|
|
|
20
20
|
} from '@aztec/stdlib/abi';
|
|
21
21
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
22
22
|
import {
|
|
23
|
-
type
|
|
23
|
+
type ContractClassIdPreimage,
|
|
24
|
+
type ContractClassWithId,
|
|
24
25
|
type ContractInstanceWithAddress,
|
|
25
26
|
SerializableContractInstance,
|
|
26
27
|
getContractClassFromArtifact,
|
|
@@ -28,6 +29,68 @@ import {
|
|
|
28
29
|
|
|
29
30
|
import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
30
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
|
+
|
|
31
94
|
/**
|
|
32
95
|
* ContractStore serves as a data manager and retriever for Aztec.nr contracts.
|
|
33
96
|
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
|
|
@@ -40,37 +103,68 @@ export class ContractStore {
|
|
|
40
103
|
// TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
41
104
|
#privateFunctionTrees: Map<string, PrivateFunctionsTree> = new Map();
|
|
42
105
|
|
|
43
|
-
/**
|
|
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). */
|
|
44
115
|
#contractClassIdMap: Map<string, Fr> = new Map();
|
|
45
116
|
|
|
117
|
+
#store: AztecAsyncKVStore;
|
|
46
118
|
#contractArtifacts: AztecAsyncMap<string, Buffer>;
|
|
119
|
+
#contractClassData: AztecAsyncMap<string, Buffer>;
|
|
47
120
|
#contractInstances: AztecAsyncMap<string, Buffer>;
|
|
48
121
|
|
|
49
122
|
constructor(store: AztecAsyncKVStore) {
|
|
123
|
+
this.#store = store;
|
|
50
124
|
this.#contractArtifacts = store.openMap('contract_artifacts');
|
|
125
|
+
this.#contractClassData = store.openMap('contract_classes');
|
|
51
126
|
this.#contractInstances = store.openMap('contracts_instances');
|
|
52
127
|
}
|
|
53
128
|
|
|
54
129
|
// Setters
|
|
55
130
|
|
|
56
|
-
|
|
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
|
+
|
|
57
148
|
const privateFunctions = contract.functions.filter(
|
|
58
149
|
functionArtifact => functionArtifact.functionType === FunctionType.PRIVATE,
|
|
59
150
|
);
|
|
60
|
-
|
|
61
151
|
const privateSelectors = await Promise.all(
|
|
62
|
-
privateFunctions.map(async
|
|
63
|
-
(
|
|
64
|
-
await FunctionSelector.fromNameAndParameters(privateFunctionArtifact.name, privateFunctionArtifact.parameters)
|
|
65
|
-
).toString(),
|
|
152
|
+
privateFunctions.map(async fn =>
|
|
153
|
+
(await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)).toString(),
|
|
66
154
|
),
|
|
67
155
|
);
|
|
68
|
-
|
|
69
156
|
if (privateSelectors.length !== new Set(privateSelectors).size) {
|
|
70
157
|
throw new Error('Repeated function selectors of private functions');
|
|
71
158
|
}
|
|
72
159
|
|
|
73
|
-
|
|
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;
|
|
74
168
|
}
|
|
75
169
|
|
|
76
170
|
async addContractInstance(contract: ContractInstanceWithAddress): Promise<void> {
|
|
@@ -85,26 +179,17 @@ export class ContractStore {
|
|
|
85
179
|
// Private getters
|
|
86
180
|
|
|
87
181
|
async #getContractClassId(contractAddress: AztecAddress): Promise<Fr | undefined> {
|
|
88
|
-
|
|
182
|
+
const key = contractAddress.toString();
|
|
183
|
+
if (!this.#contractClassIdMap.has(key)) {
|
|
89
184
|
const instance = await this.getContractInstance(contractAddress);
|
|
90
185
|
if (!instance) {
|
|
91
186
|
return;
|
|
92
187
|
}
|
|
93
|
-
this.#contractClassIdMap.set(
|
|
188
|
+
this.#contractClassIdMap.set(key, instance.currentContractClassId);
|
|
94
189
|
}
|
|
95
|
-
return this.#contractClassIdMap.get(
|
|
190
|
+
return this.#contractClassIdMap.get(key);
|
|
96
191
|
}
|
|
97
192
|
|
|
98
|
-
/**
|
|
99
|
-
* Retrieve or create a ContractTree instance based on the provided class id.
|
|
100
|
-
* If an existing tree with the same class id is found in the cache, it will be returned.
|
|
101
|
-
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
102
|
-
* and added to the cache before returning.
|
|
103
|
-
*
|
|
104
|
-
* @param classId - The class id of the contract for which the ContractTree is required.
|
|
105
|
-
* @returns A ContractTree instance associated with the specified contract address.
|
|
106
|
-
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
107
|
-
*/
|
|
108
193
|
async #getPrivateFunctionTreeForClassId(classId: Fr): Promise<PrivateFunctionsTree | undefined> {
|
|
109
194
|
if (!this.#privateFunctionTrees.has(classId.toString())) {
|
|
110
195
|
const artifact = await this.getContractArtifact(classId);
|
|
@@ -117,34 +202,61 @@ export class ContractStore {
|
|
|
117
202
|
return this.#privateFunctionTrees.get(classId.toString())!;
|
|
118
203
|
}
|
|
119
204
|
|
|
120
|
-
async #
|
|
121
|
-
const
|
|
122
|
-
return
|
|
205
|
+
async #getArtifactByAddress(contractAddress: AztecAddress): Promise<ContractArtifact | undefined> {
|
|
206
|
+
const classId = await this.#getContractClassId(contractAddress);
|
|
207
|
+
return classId && this.getContractArtifact(classId);
|
|
123
208
|
}
|
|
124
209
|
|
|
125
210
|
// Public getters
|
|
126
211
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
+
});
|
|
130
217
|
}
|
|
131
218
|
|
|
132
|
-
/** Returns a contract instance for a given address.
|
|
133
|
-
public
|
|
134
|
-
|
|
135
|
-
|
|
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
|
+
});
|
|
136
225
|
}
|
|
137
226
|
|
|
227
|
+
/** Returns the raw contract artifact for a given class id. */
|
|
138
228
|
public async getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | undefined> {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
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;
|
|
142
242
|
}
|
|
143
243
|
|
|
144
|
-
/** Returns a contract class for a given class id.
|
|
145
|
-
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);
|
|
146
254
|
const artifact = await this.getContractArtifact(contractClassId);
|
|
147
|
-
|
|
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 };
|
|
148
260
|
}
|
|
149
261
|
|
|
150
262
|
public async getContract(
|
|
@@ -163,8 +275,6 @@ export class ContractStore {
|
|
|
163
275
|
|
|
164
276
|
/**
|
|
165
277
|
* Retrieves the artifact of a specified function within a given contract.
|
|
166
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
167
|
-
* Throws an error if the contract address or function selector are invalid or not found.
|
|
168
278
|
*
|
|
169
279
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
170
280
|
* @param selector - The function selector.
|
|
@@ -174,9 +284,12 @@ export class ContractStore {
|
|
|
174
284
|
contractAddress: AztecAddress,
|
|
175
285
|
selector: FunctionSelector,
|
|
176
286
|
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
177
|
-
const artifact = await this.#
|
|
178
|
-
|
|
179
|
-
|
|
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 };
|
|
180
293
|
}
|
|
181
294
|
|
|
182
295
|
public async getFunctionArtifactWithDebugMetadata(
|
|
@@ -197,50 +310,48 @@ export class ContractStore {
|
|
|
197
310
|
public async getPublicFunctionArtifact(
|
|
198
311
|
contractAddress: AztecAddress,
|
|
199
312
|
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
200
|
-
const artifact = await this.#
|
|
201
|
-
const
|
|
202
|
-
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 };
|
|
203
316
|
}
|
|
204
317
|
|
|
205
318
|
public async getFunctionAbi(
|
|
206
319
|
contractAddress: AztecAddress,
|
|
207
320
|
selector: FunctionSelector,
|
|
208
321
|
): Promise<FunctionAbi | undefined> {
|
|
209
|
-
const artifact = await this.#
|
|
322
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
210
323
|
return artifact && (await this.#findFunctionAbiBySelector(artifact, selector));
|
|
211
324
|
}
|
|
212
325
|
|
|
213
326
|
/**
|
|
214
327
|
* Retrieves the debug metadata of a specified function within a given contract.
|
|
215
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
216
|
-
* Returns undefined if the debug metadata for the given function is not found.
|
|
217
|
-
* Throws if the contract has not been added to the database.
|
|
218
328
|
*
|
|
219
329
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
220
330
|
* @param selector - The function selector.
|
|
221
|
-
* @returns The corresponding function's
|
|
331
|
+
* @returns The corresponding function's debug metadata, or undefined.
|
|
222
332
|
*/
|
|
223
333
|
public async getFunctionDebugMetadata(
|
|
224
334
|
contractAddress: AztecAddress,
|
|
225
335
|
selector: FunctionSelector,
|
|
226
336
|
): Promise<FunctionDebugMetadata | undefined> {
|
|
227
|
-
const artifact = await this.#
|
|
228
|
-
|
|
229
|
-
|
|
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);
|
|
230
343
|
}
|
|
231
344
|
|
|
232
345
|
public async getPublicFunctionDebugMetadata(
|
|
233
346
|
contractAddress: AztecAddress,
|
|
234
347
|
): Promise<FunctionDebugMetadata | undefined> {
|
|
235
|
-
const artifact = await this.#
|
|
236
|
-
const
|
|
237
|
-
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);
|
|
238
351
|
}
|
|
239
352
|
|
|
240
353
|
/**
|
|
241
354
|
* Retrieve the function membership witness for the given contract class and function selector.
|
|
242
|
-
* The function membership witness represents a proof that the function belongs to the specified contract.
|
|
243
|
-
* Throws an error if the contract address or function selector is unknown.
|
|
244
355
|
*
|
|
245
356
|
* @param contractClassId - The id of the class.
|
|
246
357
|
* @param selector - The function selector.
|
|
@@ -255,23 +366,21 @@ export class ContractStore {
|
|
|
255
366
|
}
|
|
256
367
|
|
|
257
368
|
public async getDebugContractName(contractAddress: AztecAddress) {
|
|
258
|
-
const artifact = await this.#
|
|
369
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
259
370
|
return artifact?.name;
|
|
260
371
|
}
|
|
261
372
|
|
|
262
373
|
public async getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector) {
|
|
263
|
-
const artifact = await this.#
|
|
264
|
-
const
|
|
265
|
-
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}`;
|
|
266
377
|
}
|
|
267
378
|
|
|
268
379
|
async #findFunctionArtifactBySelector(
|
|
269
380
|
artifact: ContractArtifact,
|
|
270
381
|
selector: FunctionSelector,
|
|
271
382
|
): Promise<FunctionArtifact | undefined> {
|
|
272
|
-
const
|
|
273
|
-
for (let i = 0; i < functions.length; i++) {
|
|
274
|
-
const fn = functions[i];
|
|
383
|
+
for (const fn of artifact.functions) {
|
|
275
384
|
const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
276
385
|
if (fnSelector.equals(selector)) {
|
|
277
386
|
return fn;
|
|
@@ -283,9 +392,7 @@ export class ContractStore {
|
|
|
283
392
|
artifact: ContractArtifact,
|
|
284
393
|
selector: FunctionSelector,
|
|
285
394
|
): Promise<FunctionAbi | undefined> {
|
|
286
|
-
const
|
|
287
|
-
for (let i = 0; i < functions.length; i++) {
|
|
288
|
-
const fn = functions[i];
|
|
395
|
+
for (const fn of [...artifact.functions, ...(artifact.nonDispatchPublicFunctions ?? [])]) {
|
|
289
396
|
const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
290
397
|
if (fnSelector.equals(selector)) {
|
|
291
398
|
return fn;
|
|
@@ -306,34 +413,17 @@ export class ContractStore {
|
|
|
306
413
|
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
|
|
307
414
|
}
|
|
308
415
|
|
|
309
|
-
|
|
416
|
+
const selector = await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters);
|
|
417
|
+
|
|
418
|
+
return FunctionCall.from({
|
|
310
419
|
name: functionDao.name,
|
|
311
|
-
args: encodeArguments(functionDao, args),
|
|
312
|
-
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
313
|
-
type: functionDao.functionType,
|
|
314
420
|
to,
|
|
421
|
+
selector,
|
|
422
|
+
type: functionDao.functionType,
|
|
315
423
|
hideMsgSender: false,
|
|
316
424
|
isStatic: functionDao.isStatic,
|
|
425
|
+
args: encodeArguments(functionDao, args),
|
|
317
426
|
returnTypes: functionDao.returnTypes,
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Synchronize target contract data
|
|
322
|
-
public async syncPrivateState(
|
|
323
|
-
contractAddress: AztecAddress,
|
|
324
|
-
functionToInvokeAfterSync: FunctionSelector | null,
|
|
325
|
-
utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>,
|
|
326
|
-
) {
|
|
327
|
-
// Protocol contracts don't have private state to sync
|
|
328
|
-
if (!isProtocolContract(contractAddress)) {
|
|
329
|
-
const syncPrivateStateFunctionCall = await this.getFunctionCall('sync_private_state', [], contractAddress);
|
|
330
|
-
if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncPrivateStateFunctionCall.selector)) {
|
|
331
|
-
throw new Error(
|
|
332
|
-
'Forbidden `sync_private_state` invocation. `sync_private_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return utilityExecutor(syncPrivateStateFunctionCall);
|
|
337
|
-
}
|
|
427
|
+
});
|
|
338
428
|
}
|
|
339
429
|
}
|
package/src/storage/metadata.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PXE_DATA_SCHEMA_VERSION =
|
|
1
|
+
export const PXE_DATA_SCHEMA_VERSION = 3;
|