@aztec/pxe 0.0.1-commit.6d3c34e → 0.0.1-commit.7cf39cb55
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 +11 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +72 -21
- 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/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 +55 -34
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +193 -79
- 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 +1 -1
- 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 +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 +0 -35
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +43 -35
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +90 -25
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +65 -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 -109
- package/dest/contract_sync/contract_sync_service.d.ts +42 -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 +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 +21 -7
- 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 +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 +28 -9
- 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 +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 +27 -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 +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} +12 -6
- 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 +3 -3
- package/dest/private_kernel/private_kernel_oracle.d.ts +23 -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 +74 -58
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +100 -114
- 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 +50 -52
- 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 +43 -8
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +226 -111
- 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 +252 -100
- 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 +2 -1
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -0
- 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 +6 -6
- 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 +7 -7
- 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 +91 -33
- package/src/config/index.ts +14 -0
- package/src/contract_function_simulator/benchmarked_node.ts +103 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +341 -139
- 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 +1 -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 -67
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +125 -103
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +195 -116
- package/src/contract_sync/contract_sync_service.ts +145 -0
- package/src/contract_sync/helpers.ts +93 -0
- package/src/debug/pxe_debug_utils.ts +61 -17
- package/src/entrypoints/client/bundle/utils.ts +16 -15
- package/src/entrypoints/client/lazy/utils.ts +17 -15
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +2 -0
- package/src/entrypoints/server/utils.ts +22 -26
- package/src/events/event_service.ts +17 -25
- package/src/events/private_event_filter_validator.ts +3 -5
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +38 -29
- 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} +32 -20
- package/src/private_kernel/private_kernel_execution_prover.ts +7 -4
- package/src/private_kernel/private_kernel_oracle.ts +116 -37
- package/src/pxe.ts +205 -183
- 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 -319
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +292 -124
- 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 +293 -108
- package/src/tagging/get_all_logs_by_tags.ts +68 -0
- package/src/tagging/index.ts +1 -0
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +16 -5
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +9 -6
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
- 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 -85
- 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 -127
- 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,13 +54,14 @@ 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 {
|
|
63
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
64
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
64
65
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
65
66
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
66
67
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
@@ -69,7 +70,7 @@ import {
|
|
|
69
70
|
PrivateKernelExecutionProver,
|
|
70
71
|
type PrivateKernelExecutionProverConfig,
|
|
71
72
|
} from './private_kernel/private_kernel_execution_prover.js';
|
|
72
|
-
import {
|
|
73
|
+
import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
|
|
73
74
|
import { AddressStore } from './storage/address_store/address_store.js';
|
|
74
75
|
import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
|
|
75
76
|
import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
|
|
@@ -85,6 +86,56 @@ export type PackedPrivateEvent = InTx & {
|
|
|
85
86
|
eventSelector: EventSelector;
|
|
86
87
|
};
|
|
87
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
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
96
|
+
scopes?: AztecAddress[];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** Options for PXE.simulateTx. */
|
|
100
|
+
export type SimulateTxOpts = {
|
|
101
|
+
/** Whether to simulate the public part of the transaction. */
|
|
102
|
+
simulatePublic: boolean;
|
|
103
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
104
|
+
skipTxValidation?: boolean;
|
|
105
|
+
/** If false, fees are enforced. */
|
|
106
|
+
skipFeeEnforcement?: boolean;
|
|
107
|
+
/** State overrides for the simulation, such as contract instances and artifacts. */
|
|
108
|
+
overrides?: SimulationOverrides;
|
|
109
|
+
/** Addresses whose private state and keys are accessible during private execution. Defaults to all. */
|
|
110
|
+
scopes?: AztecAddress[];
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** Options for PXE.simulateUtility. */
|
|
114
|
+
export type SimulateUtilityOpts = {
|
|
115
|
+
/** The authentication witnesses required for the function call. */
|
|
116
|
+
authwits?: AuthWitness[];
|
|
117
|
+
/** The accounts whose notes we can access in this call. Defaults to all. */
|
|
118
|
+
scopes?: AztecAddress[];
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** Args for PXE.create. */
|
|
122
|
+
export type PXECreateArgs = {
|
|
123
|
+
/** The Aztec node to connect to. */
|
|
124
|
+
node: AztecNode;
|
|
125
|
+
/** The key-value store for persisting PXE state. */
|
|
126
|
+
store: AztecAsyncKVStore;
|
|
127
|
+
/** The prover for generating private kernel proofs. */
|
|
128
|
+
proofCreator: PrivateKernelProver;
|
|
129
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
130
|
+
simulator: CircuitSimulator;
|
|
131
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
132
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
133
|
+
/** PXE configuration options. */
|
|
134
|
+
config: PXEConfig;
|
|
135
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
136
|
+
loggerOrSuffix?: string | Logger;
|
|
137
|
+
};
|
|
138
|
+
|
|
88
139
|
/**
|
|
89
140
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
90
141
|
* manage private state of users.
|
|
@@ -103,6 +154,7 @@ export class PXE {
|
|
|
103
154
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
104
155
|
private addressStore: AddressStore,
|
|
105
156
|
private privateEventStore: PrivateEventStore,
|
|
157
|
+
private contractSyncService: ContractSyncService,
|
|
106
158
|
private simulator: CircuitSimulator,
|
|
107
159
|
private proverEnabled: boolean,
|
|
108
160
|
private proofCreator: PrivateKernelProver,
|
|
@@ -120,25 +172,31 @@ export class PXE {
|
|
|
120
172
|
*
|
|
121
173
|
* @returns A promise that resolves PXE is ready to be used.
|
|
122
174
|
*/
|
|
123
|
-
public static async create(
|
|
124
|
-
node
|
|
125
|
-
store
|
|
126
|
-
proofCreator
|
|
127
|
-
simulator
|
|
128
|
-
protocolContractsProvider
|
|
129
|
-
config
|
|
130
|
-
loggerOrSuffix
|
|
131
|
-
) {
|
|
175
|
+
public static async create({
|
|
176
|
+
node,
|
|
177
|
+
store,
|
|
178
|
+
proofCreator,
|
|
179
|
+
simulator,
|
|
180
|
+
protocolContractsProvider,
|
|
181
|
+
config,
|
|
182
|
+
loggerOrSuffix,
|
|
183
|
+
}: PXECreateArgs) {
|
|
184
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
185
|
+
const bindings: LoggerBindings | undefined =
|
|
186
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
187
|
+
|
|
132
188
|
const log =
|
|
133
189
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
134
190
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
135
191
|
: loggerOrSuffix;
|
|
136
192
|
|
|
137
|
-
const
|
|
193
|
+
const info = await node.getNodeInfo();
|
|
194
|
+
|
|
195
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
138
196
|
const addressStore = new AddressStore(store);
|
|
139
197
|
const privateEventStore = new PrivateEventStore(store);
|
|
140
198
|
const contractStore = new ContractStore(store);
|
|
141
|
-
const noteStore =
|
|
199
|
+
const noteStore = new NoteStore(store);
|
|
142
200
|
const anchorBlockStore = new AnchorBlockStore(store);
|
|
143
201
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
144
202
|
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
@@ -146,19 +204,35 @@ export class PXE {
|
|
|
146
204
|
const capsuleStore = new CapsuleStore(store);
|
|
147
205
|
const keyStore = new KeyStore(store);
|
|
148
206
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
207
|
+
const contractSyncService = new ContractSyncService(
|
|
208
|
+
node,
|
|
209
|
+
contractStore,
|
|
210
|
+
noteStore,
|
|
211
|
+
createLogger('pxe:contract_sync', bindings),
|
|
212
|
+
);
|
|
149
213
|
const synchronizer = new BlockSynchronizer(
|
|
150
214
|
node,
|
|
215
|
+
store,
|
|
151
216
|
anchorBlockStore,
|
|
152
217
|
noteStore,
|
|
153
218
|
privateEventStore,
|
|
154
219
|
tipsStore,
|
|
220
|
+
contractSyncService,
|
|
155
221
|
config,
|
|
156
|
-
|
|
222
|
+
bindings,
|
|
157
223
|
);
|
|
158
224
|
|
|
159
|
-
const jobCoordinator = new JobCoordinator(store);
|
|
225
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
226
|
+
jobCoordinator.registerStores([
|
|
227
|
+
capsuleStore,
|
|
228
|
+
senderTaggingStore,
|
|
229
|
+
recipientTaggingStore,
|
|
230
|
+
privateEventStore,
|
|
231
|
+
noteStore,
|
|
232
|
+
contractSyncService,
|
|
233
|
+
]);
|
|
160
234
|
|
|
161
|
-
const debugUtils = new PXEDebugUtils(
|
|
235
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
162
236
|
|
|
163
237
|
const jobQueue = new SerialQueue();
|
|
164
238
|
|
|
@@ -175,6 +249,7 @@ export class PXE {
|
|
|
175
249
|
recipientTaggingStore,
|
|
176
250
|
addressStore,
|
|
177
251
|
privateEventStore,
|
|
252
|
+
contractSyncService,
|
|
178
253
|
simulator,
|
|
179
254
|
proverEnabled,
|
|
180
255
|
proofCreator,
|
|
@@ -185,12 +260,15 @@ export class PXE {
|
|
|
185
260
|
debugUtils,
|
|
186
261
|
);
|
|
187
262
|
|
|
188
|
-
debugUtils.
|
|
263
|
+
debugUtils.setPXEHelpers(
|
|
264
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
265
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
266
|
+
pxe.#simulateUtility.bind(pxe),
|
|
267
|
+
);
|
|
189
268
|
|
|
190
269
|
pxe.jobQueue.start();
|
|
191
270
|
|
|
192
271
|
await pxe.#registerProtocolContracts();
|
|
193
|
-
const info = await node.getNodeInfo();
|
|
194
272
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
195
273
|
return pxe;
|
|
196
274
|
}
|
|
@@ -200,20 +278,20 @@ export class PXE {
|
|
|
200
278
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
201
279
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
202
280
|
|
|
203
|
-
return new ContractFunctionSimulator(
|
|
204
|
-
proxyContractStore,
|
|
205
|
-
this.noteStore,
|
|
206
|
-
this.keyStore,
|
|
207
|
-
this.addressStore,
|
|
208
|
-
|
|
209
|
-
this.
|
|
210
|
-
this.
|
|
211
|
-
this.
|
|
212
|
-
this.
|
|
213
|
-
this.
|
|
214
|
-
this.
|
|
215
|
-
this.
|
|
216
|
-
);
|
|
281
|
+
return new ContractFunctionSimulator({
|
|
282
|
+
contractStore: proxyContractStore,
|
|
283
|
+
noteStore: this.noteStore,
|
|
284
|
+
keyStore: this.keyStore,
|
|
285
|
+
addressStore: this.addressStore,
|
|
286
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
287
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
288
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
289
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
290
|
+
capsuleStore: this.capsuleStore,
|
|
291
|
+
privateEventStore: this.privateEventStore,
|
|
292
|
+
simulator: this.simulator,
|
|
293
|
+
contractSyncService: this.contractSyncService,
|
|
294
|
+
});
|
|
217
295
|
}
|
|
218
296
|
|
|
219
297
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -274,19 +352,6 @@ export class PXE {
|
|
|
274
352
|
this.log.verbose(`Registered protocol contracts in pxe`, registered);
|
|
275
353
|
}
|
|
276
354
|
|
|
277
|
-
async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
|
|
278
|
-
return !!(await this.node.getContractClass(id));
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
async #isContractPublished(address: AztecAddress): Promise<boolean> {
|
|
282
|
-
return !!(await this.node.getContract(address));
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
async #isContractInitialized(address: AztecAddress): Promise<boolean> {
|
|
286
|
-
const initNullifier = await siloNullifier(address, address.toField());
|
|
287
|
-
return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
|
|
288
|
-
}
|
|
289
|
-
|
|
290
355
|
// Executes the entrypoint private function, as well as all nested private
|
|
291
356
|
// functions that might arise.
|
|
292
357
|
async #executePrivate(
|
|
@@ -300,18 +365,23 @@ export class PXE {
|
|
|
300
365
|
try {
|
|
301
366
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
302
367
|
|
|
303
|
-
|
|
304
|
-
txRequest,
|
|
368
|
+
await this.contractSyncService.ensureContractSynced(
|
|
305
369
|
contractAddress,
|
|
306
370
|
functionSelector,
|
|
307
|
-
|
|
371
|
+
(privateSyncCall, execScopes) =>
|
|
372
|
+
this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
308
373
|
anchorBlockHeader,
|
|
309
|
-
// The sender for tags is set by contracts, typically by an account
|
|
310
|
-
// contract entrypoint
|
|
311
|
-
undefined, // senderForTags
|
|
312
|
-
scopes,
|
|
313
374
|
jobId,
|
|
375
|
+
scopes,
|
|
314
376
|
);
|
|
377
|
+
|
|
378
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
379
|
+
contractAddress,
|
|
380
|
+
selector: functionSelector,
|
|
381
|
+
anchorBlockHeader,
|
|
382
|
+
scopes,
|
|
383
|
+
jobId,
|
|
384
|
+
});
|
|
315
385
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
316
386
|
return result;
|
|
317
387
|
} catch (err) {
|
|
@@ -394,85 +464,45 @@ export class PXE {
|
|
|
394
464
|
privateExecutionResult: PrivateExecutionResult,
|
|
395
465
|
config: PrivateKernelExecutionProverConfig,
|
|
396
466
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
397
|
-
const
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
467
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
468
|
+
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
469
|
+
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
470
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
471
|
+
kernelOracle,
|
|
472
|
+
proofCreator,
|
|
473
|
+
!this.proverEnabled,
|
|
474
|
+
this.log.getBindings(),
|
|
403
475
|
);
|
|
404
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
|
|
405
476
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
406
477
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
407
478
|
}
|
|
408
479
|
|
|
409
480
|
// Public API
|
|
410
481
|
|
|
411
|
-
|
|
412
|
-
|
|
482
|
+
/**
|
|
483
|
+
* Returns the block header up to which the PXE has synced.
|
|
484
|
+
* @returns The synced block header
|
|
485
|
+
*/
|
|
486
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
487
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
413
488
|
}
|
|
414
489
|
|
|
415
490
|
/**
|
|
416
|
-
* Returns the contract
|
|
417
|
-
*
|
|
418
|
-
* @
|
|
419
|
-
* @param id - Identifier of the class.
|
|
420
|
-
* @param includeArtifact - Identifier of the class.
|
|
421
|
-
* @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
|
|
422
|
-
* for `includeArtifact`
|
|
423
|
-
* TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
|
|
424
|
-
* should the pxe query the node for contract public info, and merge it with its own definitions?
|
|
425
|
-
* TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
|
|
426
|
-
* during a public deployment. We probably want a nicer and more general API for this, but it'll have to
|
|
427
|
-
* do for the time being.
|
|
491
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
492
|
+
* @param address - The contract address.
|
|
493
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
428
494
|
*/
|
|
429
|
-
public
|
|
430
|
-
|
|
431
|
-
includeArtifact: boolean = false,
|
|
432
|
-
): Promise<{
|
|
433
|
-
contractClass: ContractClassWithId | undefined;
|
|
434
|
-
isContractClassPubliclyRegistered: boolean;
|
|
435
|
-
artifact: ContractArtifact | undefined;
|
|
436
|
-
}> {
|
|
437
|
-
const artifact = await this.contractStore.getContractArtifact(id);
|
|
438
|
-
if (!artifact) {
|
|
439
|
-
this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
return {
|
|
443
|
-
contractClass: artifact && (await getContractClassFromArtifact(artifact)),
|
|
444
|
-
isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
|
|
445
|
-
artifact: includeArtifact ? artifact : undefined,
|
|
446
|
-
};
|
|
495
|
+
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
496
|
+
return this.contractStore.getContractInstance(address);
|
|
447
497
|
}
|
|
448
498
|
|
|
449
499
|
/**
|
|
450
|
-
* Returns the contract
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
* and whether the contract instance with the given address has been publicly deployed.
|
|
454
|
-
* @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
|
|
455
|
-
* This query is not dependent on the PXE.
|
|
456
|
-
* @param address - The address that the contract instance resides at.
|
|
457
|
-
* @returns - It returns the contract metadata
|
|
458
|
-
* TODO(@spalladino): Should we return the public keys in plain as well here?
|
|
500
|
+
* Returns the contract artifact for a given contract class id, if it's registered in the PXE.
|
|
501
|
+
* @param id - Identifier of the contract class.
|
|
502
|
+
* @returns The contract artifact if found, undefined otherwise.
|
|
459
503
|
*/
|
|
460
|
-
public async
|
|
461
|
-
|
|
462
|
-
isContractInitialized: boolean;
|
|
463
|
-
isContractPublished: boolean;
|
|
464
|
-
}> {
|
|
465
|
-
let instance;
|
|
466
|
-
try {
|
|
467
|
-
instance = await this.contractStore.getContractInstance(address);
|
|
468
|
-
} catch {
|
|
469
|
-
this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
|
|
470
|
-
}
|
|
471
|
-
return {
|
|
472
|
-
contractInstance: instance,
|
|
473
|
-
isContractInitialized: await this.#isContractInitialized(address),
|
|
474
|
-
isContractPublished: await this.#isContractPublished(address),
|
|
475
|
-
};
|
|
504
|
+
public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
|
|
505
|
+
return await this.contractStore.getContractArtifact(id);
|
|
476
506
|
}
|
|
477
507
|
|
|
478
508
|
/**
|
|
@@ -497,7 +527,6 @@ export class PXE {
|
|
|
497
527
|
}
|
|
498
528
|
|
|
499
529
|
await this.addressStore.addCompleteAddress(accountCompleteAddress);
|
|
500
|
-
await this.noteStore.addScope(accountCompleteAddress.address);
|
|
501
530
|
return accountCompleteAddress;
|
|
502
531
|
}
|
|
503
532
|
|
|
@@ -645,13 +674,7 @@ export class PXE {
|
|
|
645
674
|
|
|
646
675
|
const header = await this.anchorBlockStore.getBlockHeader();
|
|
647
676
|
|
|
648
|
-
const currentClassId = await readCurrentClassId(
|
|
649
|
-
contractAddress,
|
|
650
|
-
currentInstance,
|
|
651
|
-
this.node,
|
|
652
|
-
header.globalVariables.blockNumber,
|
|
653
|
-
header.globalVariables.timestamp,
|
|
654
|
-
);
|
|
677
|
+
const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
|
|
655
678
|
if (!contractClass.id.equals(currentClassId)) {
|
|
656
679
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
657
680
|
}
|
|
@@ -682,11 +705,12 @@ export class PXE {
|
|
|
682
705
|
* (where validators prove the public portion).
|
|
683
706
|
*
|
|
684
707
|
* @param txRequest - An authenticated tx request ready for proving
|
|
708
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
685
709
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
686
710
|
* @throws If contract code not found, or public simulation reverts.
|
|
687
711
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
688
712
|
*/
|
|
689
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
713
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
690
714
|
let privateExecutionResult: PrivateExecutionResult;
|
|
691
715
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
692
716
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -697,7 +721,7 @@ export class PXE {
|
|
|
697
721
|
await this.blockStateSynchronizer.sync();
|
|
698
722
|
const syncTime = syncTimer.ms();
|
|
699
723
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
700
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
724
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
701
725
|
|
|
702
726
|
const {
|
|
703
727
|
publicInputs,
|
|
@@ -744,7 +768,7 @@ export class PXE {
|
|
|
744
768
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
745
769
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
746
770
|
|
|
747
|
-
await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
|
|
771
|
+
await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
|
|
748
772
|
this.log.debug(`Stored used pre-tags as sender for the tx`, {
|
|
749
773
|
preTagsUsedInTheTx,
|
|
750
774
|
});
|
|
@@ -761,17 +785,13 @@ export class PXE {
|
|
|
761
785
|
|
|
762
786
|
/**
|
|
763
787
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
764
|
-
*
|
|
765
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
766
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
767
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
788
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
768
789
|
* @returns A trace of the program execution with gate counts.
|
|
769
790
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
770
791
|
*/
|
|
771
792
|
public profileTx(
|
|
772
793
|
txRequest: TxExecutionRequest,
|
|
773
|
-
profileMode
|
|
774
|
-
skipProofGeneration: boolean = true,
|
|
794
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
775
795
|
): Promise<TxProfileResult> {
|
|
776
796
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
777
797
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -794,12 +814,7 @@ export class PXE {
|
|
|
794
814
|
const syncTime = syncTimer.ms();
|
|
795
815
|
|
|
796
816
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
797
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
798
|
-
contractFunctionSimulator,
|
|
799
|
-
txRequest,
|
|
800
|
-
undefined,
|
|
801
|
-
jobId,
|
|
802
|
-
);
|
|
817
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
803
818
|
|
|
804
819
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
805
820
|
txRequest,
|
|
@@ -856,12 +871,7 @@ export class PXE {
|
|
|
856
871
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
857
872
|
*
|
|
858
873
|
*
|
|
859
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
860
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
861
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
862
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
863
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
864
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
874
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
865
875
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
866
876
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
867
877
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -870,11 +880,7 @@ export class PXE {
|
|
|
870
880
|
*/
|
|
871
881
|
public simulateTx(
|
|
872
882
|
txRequest: TxExecutionRequest,
|
|
873
|
-
simulatePublic:
|
|
874
|
-
skipTxValidation: boolean = false,
|
|
875
|
-
skipFeeEnforcement: boolean = false,
|
|
876
|
-
overrides?: SimulationOverrides,
|
|
877
|
-
scopes?: AztecAddress[],
|
|
883
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
878
884
|
): Promise<TxSimulationResult> {
|
|
879
885
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
880
886
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -902,7 +908,14 @@ export class PXE {
|
|
|
902
908
|
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
903
909
|
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
904
910
|
// or not.
|
|
905
|
-
const
|
|
911
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
912
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
913
|
+
const skipKernels = hasOverriddenContracts;
|
|
914
|
+
|
|
915
|
+
// Set overridden contracts on the sync service so it knows to skip syncing them
|
|
916
|
+
if (hasOverriddenContracts) {
|
|
917
|
+
this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
|
|
918
|
+
}
|
|
906
919
|
|
|
907
920
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
908
921
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -911,15 +924,10 @@ export class PXE {
|
|
|
911
924
|
let executionSteps: PrivateExecutionStep[] = [];
|
|
912
925
|
|
|
913
926
|
if (skipKernels) {
|
|
914
|
-
// According to the protocol rules, the nonce generator for the note hashes
|
|
915
|
-
// can either be the first nullifier in the tx or the protocol nullifier if there are none.
|
|
916
|
-
const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
|
|
917
|
-
? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
|
|
918
|
-
: privateExecutionResult.firstNullifier;
|
|
919
927
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
920
928
|
privateExecutionResult,
|
|
921
|
-
|
|
922
|
-
this.
|
|
929
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
930
|
+
this.node,
|
|
923
931
|
));
|
|
924
932
|
} else {
|
|
925
933
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -1004,18 +1012,12 @@ export class PXE {
|
|
|
1004
1012
|
}
|
|
1005
1013
|
|
|
1006
1014
|
/**
|
|
1007
|
-
*
|
|
1008
|
-
*
|
|
1015
|
+
* Simulates the execution of a contract utility function.
|
|
1009
1016
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
1010
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
1011
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
1012
|
-
* default to all.
|
|
1013
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
1014
1017
|
*/
|
|
1015
1018
|
public simulateUtility(
|
|
1016
1019
|
call: FunctionCall,
|
|
1017
|
-
authwits
|
|
1018
|
-
scopes?: AztecAddress[],
|
|
1020
|
+
{ authwits, scopes }: SimulateUtilityOpts = {},
|
|
1019
1021
|
): Promise<UtilitySimulationResult> {
|
|
1020
1022
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1021
1023
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -1029,8 +1031,15 @@ export class PXE {
|
|
|
1029
1031
|
const functionTimer = new Timer();
|
|
1030
1032
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1031
1033
|
|
|
1032
|
-
await this.
|
|
1033
|
-
|
|
1034
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1035
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1036
|
+
call.to,
|
|
1037
|
+
call.selector,
|
|
1038
|
+
(privateSyncCall, execScopes) =>
|
|
1039
|
+
this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1040
|
+
anchorBlockHeader,
|
|
1041
|
+
jobId,
|
|
1042
|
+
scopes,
|
|
1034
1043
|
);
|
|
1035
1044
|
|
|
1036
1045
|
const executionResult = await this.#simulateUtility(
|
|
@@ -1080,26 +1089,39 @@ export class PXE {
|
|
|
1080
1089
|
* Defaults to the latest known block to PXE + 1.
|
|
1081
1090
|
* @returns - The packed events with block and tx metadata.
|
|
1082
1091
|
*/
|
|
1083
|
-
public getPrivateEvents(
|
|
1084
|
-
|
|
1092
|
+
public async getPrivateEvents(
|
|
1093
|
+
eventSelector: EventSelector,
|
|
1094
|
+
filter: PrivateEventFilter,
|
|
1095
|
+
): Promise<PackedPrivateEvent[]> {
|
|
1096
|
+
let anchorBlockNumber: BlockNumber;
|
|
1097
|
+
|
|
1098
|
+
await this.#putInJobQueue(async jobId => {
|
|
1085
1099
|
await this.blockStateSynchronizer.sync();
|
|
1100
|
+
|
|
1101
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1102
|
+
anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
1103
|
+
|
|
1086
1104
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1087
1105
|
|
|
1088
|
-
await this.
|
|
1106
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1089
1107
|
filter.contractAddress,
|
|
1090
1108
|
null,
|
|
1091
|
-
async privateSyncCall =>
|
|
1092
|
-
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [],
|
|
1109
|
+
async (privateSyncCall, execScopes) =>
|
|
1110
|
+
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1111
|
+
anchorBlockHeader,
|
|
1112
|
+
jobId,
|
|
1113
|
+
filter.scopes,
|
|
1093
1114
|
);
|
|
1115
|
+
});
|
|
1094
1116
|
|
|
1095
|
-
|
|
1117
|
+
// anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
|
|
1118
|
+
const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
|
|
1096
1119
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1120
|
+
this.log.debug(
|
|
1121
|
+
`Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
|
|
1122
|
+
);
|
|
1100
1123
|
|
|
1101
|
-
|
|
1102
|
-
});
|
|
1124
|
+
return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
|
|
1103
1125
|
}
|
|
1104
1126
|
|
|
1105
1127
|
/**
|