@aztec/pxe 0.0.1-commit.6230efd → 0.0.1-commit.64b6bbb
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/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 +54 -33
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +96 -51
- 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 +6 -3
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
- 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 +43 -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 +66 -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 +127 -108
- package/dest/contract_sync/contract_sync_service.d.ts +41 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +82 -0
- package/dest/contract_sync/helpers.d.ts +28 -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 +22 -9
- 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/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/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 +3 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -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 +7 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +23 -20
- 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 +31 -36
- 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/index.d.ts +2 -2
- package/dest/private_kernel/hints/index.d.ts.map +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- 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} +13 -7
- 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 +6 -7
- package/dest/private_kernel/private_kernel_oracle.d.ts +24 -28
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +90 -2
- package/dest/pxe.d.ts +71 -57
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +123 -119
- 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 +1 -2
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +27 -30
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +51 -52
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +285 -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 +46 -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 +8 -8
- 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/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 +148 -99
- 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 +5 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
- 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 +117 -137
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +191 -115
- package/src/contract_sync/contract_sync_service.ts +129 -0
- package/src/contract_sync/helpers.ts +93 -0
- package/src/debug/pxe_debug_utils.ts +60 -17
- package/src/entrypoints/client/bundle/utils.ts +23 -16
- package/src/entrypoints/client/lazy/utils.ts +24 -17
- package/src/entrypoints/pxe_creation_options.ts +4 -2
- package/src/entrypoints/server/index.ts +2 -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 +34 -16
- package/src/notes/note_service.ts +38 -43
- package/src/oracle_version.ts +4 -3
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +33 -22
- package/src/private_kernel/private_kernel_execution_prover.ts +9 -8
- package/src/private_kernel/private_kernel_oracle.ts +116 -36
- package/src/pxe.ts +246 -184
- 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 +26 -35
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +321 -318
- 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 +68 -0
- package/src/tagging/index.ts +2 -11
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +21 -7
- 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/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
package/src/pxe.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
5
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
6
7
|
import { KeyStore } from '@aztec/key-store';
|
|
@@ -19,14 +20,12 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
|
19
20
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
20
21
|
import {
|
|
21
22
|
CompleteAddress,
|
|
22
|
-
type ContractClassWithId,
|
|
23
23
|
type ContractInstanceWithAddress,
|
|
24
24
|
type PartialAddress,
|
|
25
25
|
computeContractAddressFromInstance,
|
|
26
26
|
getContractClassFromArtifact,
|
|
27
27
|
} from '@aztec/stdlib/contract';
|
|
28
28
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
29
|
-
import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
|
|
30
29
|
import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
|
|
31
30
|
import type {
|
|
32
31
|
PrivateExecutionStep,
|
|
@@ -34,6 +33,7 @@ import type {
|
|
|
34
33
|
PrivateKernelTailCircuitPublicInputs,
|
|
35
34
|
} from '@aztec/stdlib/kernel';
|
|
36
35
|
import {
|
|
36
|
+
BlockHeader,
|
|
37
37
|
type ContractOverrides,
|
|
38
38
|
type InTx,
|
|
39
39
|
PrivateExecutionResult,
|
|
@@ -54,20 +54,23 @@ import { inspect } from 'util';
|
|
|
54
54
|
|
|
55
55
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
56
56
|
import type { PXEConfig } from './config/index.js';
|
|
57
|
+
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
57
58
|
import {
|
|
58
59
|
ContractFunctionSimulator,
|
|
59
60
|
generateSimulatedProvingResult,
|
|
60
61
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
61
|
-
import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
|
|
62
62
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
63
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
64
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
63
65
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
64
66
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
65
67
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
68
|
+
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
66
69
|
import {
|
|
67
70
|
PrivateKernelExecutionProver,
|
|
68
71
|
type PrivateKernelExecutionProverConfig,
|
|
69
72
|
} from './private_kernel/private_kernel_execution_prover.js';
|
|
70
|
-
import {
|
|
73
|
+
import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
|
|
71
74
|
import { AddressStore } from './storage/address_store/address_store.js';
|
|
72
75
|
import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
|
|
73
76
|
import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
|
|
@@ -83,6 +86,54 @@ export type PackedPrivateEvent = InTx & {
|
|
|
83
86
|
eventSelector: EventSelector;
|
|
84
87
|
};
|
|
85
88
|
|
|
89
|
+
/** Options for PXE.profileTx. */
|
|
90
|
+
export type ProfileTxOpts = {
|
|
91
|
+
/** The profiling mode to use. */
|
|
92
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
93
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
94
|
+
skipProofGeneration?: boolean;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** Options for PXE.simulateTx. */
|
|
98
|
+
export type SimulateTxOpts = {
|
|
99
|
+
/** Whether to simulate the public part of the transaction. */
|
|
100
|
+
simulatePublic: boolean;
|
|
101
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
102
|
+
skipTxValidation?: boolean;
|
|
103
|
+
/** If false, fees are enforced. */
|
|
104
|
+
skipFeeEnforcement?: boolean;
|
|
105
|
+
/** State overrides for the simulation, such as contract instances and artifacts. */
|
|
106
|
+
overrides?: SimulationOverrides;
|
|
107
|
+
/** The accounts whose notes we can access in this call. Defaults to all. */
|
|
108
|
+
scopes?: AztecAddress[];
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/** Options for PXE.simulateUtility. */
|
|
112
|
+
export type SimulateUtilityOpts = {
|
|
113
|
+
/** The authentication witnesses required for the function call. */
|
|
114
|
+
authwits?: AuthWitness[];
|
|
115
|
+
/** The accounts whose notes we can access in this call. Defaults to all. */
|
|
116
|
+
scopes?: AztecAddress[];
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** Args for PXE.create. */
|
|
120
|
+
export type PXECreateArgs = {
|
|
121
|
+
/** The Aztec node to connect to. */
|
|
122
|
+
node: AztecNode;
|
|
123
|
+
/** The key-value store for persisting PXE state. */
|
|
124
|
+
store: AztecAsyncKVStore;
|
|
125
|
+
/** The prover for generating private kernel proofs. */
|
|
126
|
+
proofCreator: PrivateKernelProver;
|
|
127
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
128
|
+
simulator: CircuitSimulator;
|
|
129
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
130
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
131
|
+
/** PXE configuration options. */
|
|
132
|
+
config: PXEConfig;
|
|
133
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
134
|
+
loggerOrSuffix?: string | Logger;
|
|
135
|
+
};
|
|
136
|
+
|
|
86
137
|
/**
|
|
87
138
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
88
139
|
* manage private state of users.
|
|
@@ -101,12 +152,14 @@ export class PXE {
|
|
|
101
152
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
102
153
|
private addressStore: AddressStore,
|
|
103
154
|
private privateEventStore: PrivateEventStore,
|
|
155
|
+
private contractSyncService: ContractSyncService,
|
|
104
156
|
private simulator: CircuitSimulator,
|
|
105
157
|
private proverEnabled: boolean,
|
|
106
158
|
private proofCreator: PrivateKernelProver,
|
|
107
159
|
private protocolContractsProvider: ProtocolContractsProvider,
|
|
108
160
|
private log: Logger,
|
|
109
161
|
private jobQueue: SerialQueue,
|
|
162
|
+
private jobCoordinator: JobCoordinator,
|
|
110
163
|
public debug: PXEDebugUtils,
|
|
111
164
|
) {}
|
|
112
165
|
|
|
@@ -117,15 +170,19 @@ export class PXE {
|
|
|
117
170
|
*
|
|
118
171
|
* @returns A promise that resolves PXE is ready to be used.
|
|
119
172
|
*/
|
|
120
|
-
public static async create(
|
|
121
|
-
node
|
|
122
|
-
store
|
|
123
|
-
proofCreator
|
|
124
|
-
simulator
|
|
125
|
-
protocolContractsProvider
|
|
126
|
-
config
|
|
127
|
-
loggerOrSuffix
|
|
128
|
-
) {
|
|
173
|
+
public static async create({
|
|
174
|
+
node,
|
|
175
|
+
store,
|
|
176
|
+
proofCreator,
|
|
177
|
+
simulator,
|
|
178
|
+
protocolContractsProvider,
|
|
179
|
+
config,
|
|
180
|
+
loggerOrSuffix,
|
|
181
|
+
}: PXECreateArgs) {
|
|
182
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
183
|
+
const bindings: LoggerBindings | undefined =
|
|
184
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
185
|
+
|
|
129
186
|
const log =
|
|
130
187
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
131
188
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
@@ -135,7 +192,7 @@ export class PXE {
|
|
|
135
192
|
const addressStore = new AddressStore(store);
|
|
136
193
|
const privateEventStore = new PrivateEventStore(store);
|
|
137
194
|
const contractStore = new ContractStore(store);
|
|
138
|
-
const noteStore =
|
|
195
|
+
const noteStore = new NoteStore(store);
|
|
139
196
|
const anchorBlockStore = new AnchorBlockStore(store);
|
|
140
197
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
141
198
|
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
@@ -143,9 +200,35 @@ export class PXE {
|
|
|
143
200
|
const capsuleStore = new CapsuleStore(store);
|
|
144
201
|
const keyStore = new KeyStore(store);
|
|
145
202
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
146
|
-
const
|
|
203
|
+
const contractSyncService = new ContractSyncService(
|
|
204
|
+
node,
|
|
205
|
+
contractStore,
|
|
206
|
+
noteStore,
|
|
207
|
+
createLogger('pxe:contract_sync', bindings),
|
|
208
|
+
);
|
|
209
|
+
const synchronizer = new BlockSynchronizer(
|
|
210
|
+
node,
|
|
211
|
+
store,
|
|
212
|
+
anchorBlockStore,
|
|
213
|
+
noteStore,
|
|
214
|
+
privateEventStore,
|
|
215
|
+
tipsStore,
|
|
216
|
+
contractSyncService,
|
|
217
|
+
config,
|
|
218
|
+
bindings,
|
|
219
|
+
);
|
|
147
220
|
|
|
148
|
-
const
|
|
221
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
222
|
+
jobCoordinator.registerStores([
|
|
223
|
+
capsuleStore,
|
|
224
|
+
senderTaggingStore,
|
|
225
|
+
recipientTaggingStore,
|
|
226
|
+
privateEventStore,
|
|
227
|
+
noteStore,
|
|
228
|
+
contractSyncService,
|
|
229
|
+
]);
|
|
230
|
+
|
|
231
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
149
232
|
|
|
150
233
|
const jobQueue = new SerialQueue();
|
|
151
234
|
|
|
@@ -162,16 +245,22 @@ export class PXE {
|
|
|
162
245
|
recipientTaggingStore,
|
|
163
246
|
addressStore,
|
|
164
247
|
privateEventStore,
|
|
248
|
+
contractSyncService,
|
|
165
249
|
simulator,
|
|
166
250
|
proverEnabled,
|
|
167
251
|
proofCreator,
|
|
168
252
|
protocolContractsProvider,
|
|
169
253
|
log,
|
|
170
254
|
jobQueue,
|
|
255
|
+
jobCoordinator,
|
|
171
256
|
debugUtils,
|
|
172
257
|
);
|
|
173
258
|
|
|
174
|
-
debugUtils.
|
|
259
|
+
debugUtils.setPXEHelpers(
|
|
260
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
261
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
262
|
+
pxe.#simulateUtility.bind(pxe),
|
|
263
|
+
);
|
|
175
264
|
|
|
176
265
|
pxe.jobQueue.start();
|
|
177
266
|
|
|
@@ -186,20 +275,20 @@ export class PXE {
|
|
|
186
275
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
187
276
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
188
277
|
|
|
189
|
-
return new ContractFunctionSimulator(
|
|
190
|
-
proxyContractStore,
|
|
191
|
-
this.noteStore,
|
|
192
|
-
this.keyStore,
|
|
193
|
-
this.addressStore,
|
|
194
|
-
this.node,
|
|
195
|
-
this.
|
|
196
|
-
this.
|
|
197
|
-
this.
|
|
198
|
-
this.
|
|
199
|
-
this.
|
|
200
|
-
this.
|
|
201
|
-
this.
|
|
202
|
-
);
|
|
278
|
+
return new ContractFunctionSimulator({
|
|
279
|
+
contractStore: proxyContractStore,
|
|
280
|
+
noteStore: this.noteStore,
|
|
281
|
+
keyStore: this.keyStore,
|
|
282
|
+
addressStore: this.addressStore,
|
|
283
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
284
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
285
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
286
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
287
|
+
capsuleStore: this.capsuleStore,
|
|
288
|
+
privateEventStore: this.privateEventStore,
|
|
289
|
+
simulator: this.simulator,
|
|
290
|
+
contractSyncService: this.contractSyncService,
|
|
291
|
+
});
|
|
203
292
|
}
|
|
204
293
|
|
|
205
294
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -222,7 +311,7 @@ export class PXE {
|
|
|
222
311
|
*
|
|
223
312
|
* Useful for tasks that cannot run concurrently, such as contract function simulation.
|
|
224
313
|
*/
|
|
225
|
-
#putInJobQueue<T>(fn: () => Promise<T>): Promise<T> {
|
|
314
|
+
#putInJobQueue<T>(fn: (jobId: string) => Promise<T>): Promise<T> {
|
|
226
315
|
// TODO(#12636): relax the conditions under which we forbid concurrency.
|
|
227
316
|
if (this.jobQueue.length() != 0) {
|
|
228
317
|
this.log.warn(
|
|
@@ -230,7 +319,22 @@ export class PXE {
|
|
|
230
319
|
);
|
|
231
320
|
}
|
|
232
321
|
|
|
233
|
-
return this.jobQueue.put(
|
|
322
|
+
return this.jobQueue.put(async () => {
|
|
323
|
+
const jobId = this.jobCoordinator.beginJob();
|
|
324
|
+
this.log.verbose(`Beginning job ${jobId}`);
|
|
325
|
+
|
|
326
|
+
try {
|
|
327
|
+
const result = await fn(jobId);
|
|
328
|
+
this.log.verbose(`Committing job ${jobId}`);
|
|
329
|
+
|
|
330
|
+
await this.jobCoordinator.commitJob(jobId);
|
|
331
|
+
return result;
|
|
332
|
+
} catch (err) {
|
|
333
|
+
this.log.verbose(`Aborting job ${jobId}`);
|
|
334
|
+
await this.jobCoordinator.abortJob(jobId);
|
|
335
|
+
throw err;
|
|
336
|
+
}
|
|
337
|
+
});
|
|
234
338
|
}
|
|
235
339
|
|
|
236
340
|
async #registerProtocolContracts() {
|
|
@@ -245,42 +349,34 @@ export class PXE {
|
|
|
245
349
|
this.log.verbose(`Registered protocol contracts in pxe`, registered);
|
|
246
350
|
}
|
|
247
351
|
|
|
248
|
-
async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
|
|
249
|
-
return !!(await this.node.getContractClass(id));
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
async #isContractPublished(address: AztecAddress): Promise<boolean> {
|
|
253
|
-
return !!(await this.node.getContract(address));
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async #isContractInitialized(address: AztecAddress): Promise<boolean> {
|
|
257
|
-
const initNullifier = await siloNullifier(address, address.toField());
|
|
258
|
-
return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
|
|
259
|
-
}
|
|
260
|
-
|
|
261
352
|
// Executes the entrypoint private function, as well as all nested private
|
|
262
353
|
// functions that might arise.
|
|
263
354
|
async #executePrivate(
|
|
264
355
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
265
356
|
txRequest: TxExecutionRequest,
|
|
266
|
-
scopes
|
|
357
|
+
scopes: AztecAddress[] | undefined,
|
|
358
|
+
jobId: string,
|
|
267
359
|
): Promise<PrivateExecutionResult> {
|
|
268
360
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
269
361
|
|
|
270
362
|
try {
|
|
271
363
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
272
364
|
|
|
273
|
-
|
|
274
|
-
txRequest,
|
|
365
|
+
await this.contractSyncService.ensureContractSynced(
|
|
275
366
|
contractAddress,
|
|
276
367
|
functionSelector,
|
|
277
|
-
undefined,
|
|
368
|
+
privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
|
|
278
369
|
anchorBlockHeader,
|
|
279
|
-
|
|
280
|
-
// contract entrypoint
|
|
281
|
-
undefined, // senderForTags
|
|
282
|
-
scopes,
|
|
370
|
+
jobId,
|
|
283
371
|
);
|
|
372
|
+
|
|
373
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
374
|
+
contractAddress,
|
|
375
|
+
selector: functionSelector,
|
|
376
|
+
anchorBlockHeader,
|
|
377
|
+
scopes,
|
|
378
|
+
jobId,
|
|
379
|
+
});
|
|
284
380
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
285
381
|
return result;
|
|
286
382
|
} catch (err) {
|
|
@@ -298,17 +394,19 @@ export class PXE {
|
|
|
298
394
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
299
395
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
300
396
|
* accounts if not specified.
|
|
397
|
+
* @param jobId - The job ID for staged writes.
|
|
301
398
|
* @returns The simulation result containing the outputs of the utility function.
|
|
302
399
|
*/
|
|
303
400
|
async #simulateUtility(
|
|
304
401
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
305
402
|
call: FunctionCall,
|
|
306
|
-
authWitnesses
|
|
307
|
-
scopes
|
|
403
|
+
authWitnesses: AuthWitness[] | undefined,
|
|
404
|
+
scopes: AztecAddress[] | undefined,
|
|
405
|
+
jobId: string,
|
|
308
406
|
) {
|
|
309
407
|
try {
|
|
310
408
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
311
|
-
return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes);
|
|
409
|
+
return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
|
|
312
410
|
} catch (err) {
|
|
313
411
|
if (err instanceof SimulationError) {
|
|
314
412
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -361,85 +459,45 @@ export class PXE {
|
|
|
361
459
|
privateExecutionResult: PrivateExecutionResult,
|
|
362
460
|
config: PrivateKernelExecutionProverConfig,
|
|
363
461
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
364
|
-
const
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
462
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
463
|
+
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
464
|
+
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
465
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
466
|
+
kernelOracle,
|
|
467
|
+
proofCreator,
|
|
468
|
+
!this.proverEnabled,
|
|
469
|
+
this.log.getBindings(),
|
|
370
470
|
);
|
|
371
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
|
|
372
471
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
373
472
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
374
473
|
}
|
|
375
474
|
|
|
376
475
|
// Public API
|
|
377
476
|
|
|
378
|
-
|
|
379
|
-
|
|
477
|
+
/**
|
|
478
|
+
* Returns the block header up to which the PXE has synced.
|
|
479
|
+
* @returns The synced block header
|
|
480
|
+
*/
|
|
481
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
482
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
380
483
|
}
|
|
381
484
|
|
|
382
485
|
/**
|
|
383
|
-
* Returns the contract
|
|
384
|
-
*
|
|
385
|
-
* @
|
|
386
|
-
* @param id - Identifier of the class.
|
|
387
|
-
* @param includeArtifact - Identifier of the class.
|
|
388
|
-
* @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
|
|
389
|
-
* for `includeArtifact`
|
|
390
|
-
* TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
|
|
391
|
-
* should the pxe query the node for contract public info, and merge it with its own definitions?
|
|
392
|
-
* TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
|
|
393
|
-
* during a public deployment. We probably want a nicer and more general API for this, but it'll have to
|
|
394
|
-
* do for the time being.
|
|
486
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
487
|
+
* @param address - The contract address.
|
|
488
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
395
489
|
*/
|
|
396
|
-
public
|
|
397
|
-
|
|
398
|
-
includeArtifact: boolean = false,
|
|
399
|
-
): Promise<{
|
|
400
|
-
contractClass: ContractClassWithId | undefined;
|
|
401
|
-
isContractClassPubliclyRegistered: boolean;
|
|
402
|
-
artifact: ContractArtifact | undefined;
|
|
403
|
-
}> {
|
|
404
|
-
const artifact = await this.contractStore.getContractArtifact(id);
|
|
405
|
-
if (!artifact) {
|
|
406
|
-
this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return {
|
|
410
|
-
contractClass: artifact && (await getContractClassFromArtifact(artifact)),
|
|
411
|
-
isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
|
|
412
|
-
artifact: includeArtifact ? artifact : undefined,
|
|
413
|
-
};
|
|
490
|
+
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
491
|
+
return this.contractStore.getContractInstance(address);
|
|
414
492
|
}
|
|
415
493
|
|
|
416
494
|
/**
|
|
417
|
-
* Returns the contract
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* and whether the contract instance with the given address has been publicly deployed.
|
|
421
|
-
* @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
|
|
422
|
-
* This query is not dependent on the PXE.
|
|
423
|
-
* @param address - The address that the contract instance resides at.
|
|
424
|
-
* @returns - It returns the contract metadata
|
|
425
|
-
* TODO(@spalladino): Should we return the public keys in plain as well here?
|
|
495
|
+
* Returns the contract artifact for a given contract class id, if it's registered in the PXE.
|
|
496
|
+
* @param id - Identifier of the contract class.
|
|
497
|
+
* @returns The contract artifact if found, undefined otherwise.
|
|
426
498
|
*/
|
|
427
|
-
public async
|
|
428
|
-
|
|
429
|
-
isContractInitialized: boolean;
|
|
430
|
-
isContractPublished: boolean;
|
|
431
|
-
}> {
|
|
432
|
-
let instance;
|
|
433
|
-
try {
|
|
434
|
-
instance = await this.contractStore.getContractInstance(address);
|
|
435
|
-
} catch {
|
|
436
|
-
this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
|
|
437
|
-
}
|
|
438
|
-
return {
|
|
439
|
-
contractInstance: instance,
|
|
440
|
-
isContractInitialized: await this.#isContractInitialized(address),
|
|
441
|
-
isContractPublished: await this.#isContractPublished(address),
|
|
442
|
-
};
|
|
499
|
+
public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
|
|
500
|
+
return await this.contractStore.getContractArtifact(id);
|
|
443
501
|
}
|
|
444
502
|
|
|
445
503
|
/**
|
|
@@ -464,7 +522,6 @@ export class PXE {
|
|
|
464
522
|
}
|
|
465
523
|
|
|
466
524
|
await this.addressStore.addCompleteAddress(accountCompleteAddress);
|
|
467
|
-
await this.noteStore.addScope(accountCompleteAddress.address);
|
|
468
525
|
return accountCompleteAddress;
|
|
469
526
|
}
|
|
470
527
|
|
|
@@ -612,13 +669,7 @@ export class PXE {
|
|
|
612
669
|
|
|
613
670
|
const header = await this.anchorBlockStore.getBlockHeader();
|
|
614
671
|
|
|
615
|
-
const currentClassId = await readCurrentClassId(
|
|
616
|
-
contractAddress,
|
|
617
|
-
currentInstance,
|
|
618
|
-
this.node,
|
|
619
|
-
header.globalVariables.blockNumber,
|
|
620
|
-
header.globalVariables.timestamp,
|
|
621
|
-
);
|
|
672
|
+
const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
|
|
622
673
|
if (!contractClass.id.equals(currentClassId)) {
|
|
623
674
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
624
675
|
}
|
|
@@ -657,14 +708,14 @@ export class PXE {
|
|
|
657
708
|
let privateExecutionResult: PrivateExecutionResult;
|
|
658
709
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
659
710
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
660
|
-
return this.#putInJobQueue(async
|
|
711
|
+
return this.#putInJobQueue(async jobId => {
|
|
661
712
|
const totalTimer = new Timer();
|
|
662
713
|
try {
|
|
663
714
|
const syncTimer = new Timer();
|
|
664
715
|
await this.blockStateSynchronizer.sync();
|
|
665
716
|
const syncTime = syncTimer.ms();
|
|
666
717
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
667
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
|
|
718
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
|
|
668
719
|
|
|
669
720
|
const {
|
|
670
721
|
publicInputs,
|
|
@@ -711,7 +762,7 @@ export class PXE {
|
|
|
711
762
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
712
763
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
713
764
|
|
|
714
|
-
await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
|
|
765
|
+
await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
|
|
715
766
|
this.log.debug(`Stored used pre-tags as sender for the tx`, {
|
|
716
767
|
preTagsUsedInTheTx,
|
|
717
768
|
});
|
|
@@ -728,20 +779,16 @@ export class PXE {
|
|
|
728
779
|
|
|
729
780
|
/**
|
|
730
781
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
731
|
-
*
|
|
732
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
733
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
734
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
782
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
735
783
|
* @returns A trace of the program execution with gate counts.
|
|
736
784
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
737
785
|
*/
|
|
738
786
|
public profileTx(
|
|
739
787
|
txRequest: TxExecutionRequest,
|
|
740
|
-
profileMode
|
|
741
|
-
skipProofGeneration: boolean = true,
|
|
788
|
+
{ profileMode, skipProofGeneration = true }: ProfileTxOpts,
|
|
742
789
|
): Promise<TxProfileResult> {
|
|
743
790
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
744
|
-
return this.#putInJobQueue(async
|
|
791
|
+
return this.#putInJobQueue(async jobId => {
|
|
745
792
|
const totalTimer = new Timer();
|
|
746
793
|
try {
|
|
747
794
|
const txInfo = {
|
|
@@ -761,7 +808,12 @@ export class PXE {
|
|
|
761
808
|
const syncTime = syncTimer.ms();
|
|
762
809
|
|
|
763
810
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
764
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
811
|
+
const privateExecutionResult = await this.#executePrivate(
|
|
812
|
+
contractFunctionSimulator,
|
|
813
|
+
txRequest,
|
|
814
|
+
undefined,
|
|
815
|
+
jobId,
|
|
816
|
+
);
|
|
765
817
|
|
|
766
818
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
767
819
|
txRequest,
|
|
@@ -818,12 +870,7 @@ export class PXE {
|
|
|
818
870
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
819
871
|
*
|
|
820
872
|
*
|
|
821
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
822
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
823
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
824
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
825
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
826
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
873
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
827
874
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
828
875
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
829
876
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -832,16 +879,12 @@ export class PXE {
|
|
|
832
879
|
*/
|
|
833
880
|
public simulateTx(
|
|
834
881
|
txRequest: TxExecutionRequest,
|
|
835
|
-
simulatePublic:
|
|
836
|
-
skipTxValidation: boolean = false,
|
|
837
|
-
skipFeeEnforcement: boolean = false,
|
|
838
|
-
overrides?: SimulationOverrides,
|
|
839
|
-
scopes?: AztecAddress[],
|
|
882
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
840
883
|
): Promise<TxSimulationResult> {
|
|
841
884
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
842
885
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
843
886
|
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
844
|
-
return this.#putInJobQueue(async
|
|
887
|
+
return this.#putInJobQueue(async jobId => {
|
|
845
888
|
try {
|
|
846
889
|
const totalTimer = new Timer();
|
|
847
890
|
const txInfo = {
|
|
@@ -864,24 +907,25 @@ export class PXE {
|
|
|
864
907
|
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
865
908
|
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
866
909
|
// or not.
|
|
867
|
-
const
|
|
910
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
911
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
912
|
+
const skipKernels = hasOverriddenContracts;
|
|
913
|
+
|
|
914
|
+
// Set overridden contracts on the sync service so it knows to skip syncing them
|
|
915
|
+
if (hasOverriddenContracts) {
|
|
916
|
+
this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
|
|
917
|
+
}
|
|
868
918
|
|
|
869
919
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
870
|
-
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes);
|
|
920
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
871
921
|
|
|
872
922
|
let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
|
|
873
923
|
let executionSteps: PrivateExecutionStep[] = [];
|
|
874
924
|
|
|
875
925
|
if (skipKernels) {
|
|
876
|
-
// According to the protocol rules, the nonce generator for the note hashes
|
|
877
|
-
// can either be the first nullifier in the tx or the protocol nullifier if there are none.
|
|
878
|
-
const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
|
|
879
|
-
? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
|
|
880
|
-
: privateExecutionResult.firstNullifier;
|
|
881
926
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
882
927
|
privateExecutionResult,
|
|
883
|
-
|
|
884
|
-
this.contractStore,
|
|
928
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
885
929
|
));
|
|
886
930
|
} else {
|
|
887
931
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -966,23 +1010,17 @@ export class PXE {
|
|
|
966
1010
|
}
|
|
967
1011
|
|
|
968
1012
|
/**
|
|
969
|
-
*
|
|
970
|
-
*
|
|
1013
|
+
* Simulates the execution of a contract utility function.
|
|
971
1014
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
972
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
973
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
974
|
-
* default to all.
|
|
975
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
976
1015
|
*/
|
|
977
1016
|
public simulateUtility(
|
|
978
1017
|
call: FunctionCall,
|
|
979
|
-
authwits
|
|
980
|
-
scopes?: AztecAddress[],
|
|
1018
|
+
{ authwits, scopes }: SimulateUtilityOpts = {},
|
|
981
1019
|
): Promise<UtilitySimulationResult> {
|
|
982
1020
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
983
1021
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
984
1022
|
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
985
|
-
return this.#putInJobQueue(async
|
|
1023
|
+
return this.#putInJobQueue(async jobId => {
|
|
986
1024
|
try {
|
|
987
1025
|
const totalTimer = new Timer();
|
|
988
1026
|
const syncTimer = new Timer();
|
|
@@ -991,11 +1029,22 @@ export class PXE {
|
|
|
991
1029
|
const functionTimer = new Timer();
|
|
992
1030
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
993
1031
|
|
|
994
|
-
await this.
|
|
995
|
-
|
|
1032
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1033
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1034
|
+
call.to,
|
|
1035
|
+
call.selector,
|
|
1036
|
+
privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
|
|
1037
|
+
anchorBlockHeader,
|
|
1038
|
+
jobId,
|
|
996
1039
|
);
|
|
997
1040
|
|
|
998
|
-
const executionResult = await this.#simulateUtility(
|
|
1041
|
+
const executionResult = await this.#simulateUtility(
|
|
1042
|
+
contractFunctionSimulator,
|
|
1043
|
+
call,
|
|
1044
|
+
authwits ?? [],
|
|
1045
|
+
scopes,
|
|
1046
|
+
jobId,
|
|
1047
|
+
);
|
|
999
1048
|
const functionTime = functionTimer.ms();
|
|
1000
1049
|
|
|
1001
1050
|
const totalTime = totalTimer.ms();
|
|
@@ -1036,25 +1085,38 @@ export class PXE {
|
|
|
1036
1085
|
* Defaults to the latest known block to PXE + 1.
|
|
1037
1086
|
* @returns - The packed events with block and tx metadata.
|
|
1038
1087
|
*/
|
|
1039
|
-
public getPrivateEvents(
|
|
1040
|
-
|
|
1088
|
+
public async getPrivateEvents(
|
|
1089
|
+
eventSelector: EventSelector,
|
|
1090
|
+
filter: PrivateEventFilter,
|
|
1091
|
+
): Promise<PackedPrivateEvent[]> {
|
|
1092
|
+
let anchorBlockNumber: BlockNumber;
|
|
1093
|
+
|
|
1094
|
+
await this.#putInJobQueue(async jobId => {
|
|
1041
1095
|
await this.blockStateSynchronizer.sync();
|
|
1096
|
+
|
|
1097
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1098
|
+
anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
1099
|
+
|
|
1042
1100
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1043
1101
|
|
|
1044
|
-
await this.
|
|
1102
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1045
1103
|
filter.contractAddress,
|
|
1046
1104
|
null,
|
|
1047
|
-
async privateSyncCall =>
|
|
1105
|
+
async privateSyncCall =>
|
|
1106
|
+
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
|
|
1107
|
+
anchorBlockHeader,
|
|
1108
|
+
jobId,
|
|
1048
1109
|
);
|
|
1110
|
+
});
|
|
1049
1111
|
|
|
1050
|
-
|
|
1112
|
+
// anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
|
|
1113
|
+
const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
|
|
1051
1114
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1115
|
+
this.log.debug(
|
|
1116
|
+
`Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
|
|
1117
|
+
);
|
|
1055
1118
|
|
|
1056
|
-
|
|
1057
|
-
});
|
|
1119
|
+
return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
|
|
1058
1120
|
}
|
|
1059
1121
|
|
|
1060
1122
|
/**
|