@aztec/pxe 0.0.1-commit.0b941701 → 0.0.1-commit.10bd49492
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts +5 -3
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +11 -5
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +57 -30
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +181 -73
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
- package/dest/contract_function_simulator/index.d.ts +2 -1
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -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 +5 -4
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
- package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts +16 -0
- package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/message_tx_context.js +57 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +3 -5
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -46
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +52 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +44 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +170 -110
- package/dest/contract_function_simulator/oracle/private_execution.js +3 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +58 -72
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +104 -77
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +82 -52
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +153 -96
- package/dest/contract_logging.d.ts +22 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +23 -0
- package/dest/contract_sync/contract_sync_service.d.ts +43 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +97 -0
- package/dest/contract_sync/helpers.d.ts +29 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/{index.js → helpers.js} +13 -12
- package/dest/debug/pxe_debug_utils.d.ts +24 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +28 -18
- package/dest/entrypoints/client/bundle/index.d.ts +4 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +3 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +21 -7
- package/dest/entrypoints/client/lazy/index.d.ts +4 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +3 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +22 -8
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +4 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +3 -1
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +28 -9
- package/dest/events/event_service.d.ts +4 -5
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +5 -6
- package/dest/job_coordinator/job_coordinator.d.ts +3 -2
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
- package/dest/job_coordinator/job_coordinator.js +3 -2
- package/dest/logs/log_service.d.ts +7 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +19 -29
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/notes/note_service.d.ts +7 -7
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +9 -9
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +3 -3
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +203 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +21 -13
- package/dest/private_kernel/private_kernel_oracle.d.ts +8 -4
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +7 -3
- package/dest/pxe.d.ts +72 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +115 -72
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
- package/dest/storage/capsule_store/capsule_store.js +6 -8
- package/dest/storage/contract_store/contract_store.d.ts +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +157 -72
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +13 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +147 -107
- package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +84 -61
- package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
- package/dest/storage/private_event_store/stored_private_event.js +2 -2
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +233 -137
- package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/index.d.ts +3 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -6
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -8
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -9
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- 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 +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +6 -8
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
- package/package.json +25 -16
- package/src/access_scopes.ts +9 -0
- package/src/block_synchronizer/block_synchronizer.ts +23 -19
- package/src/config/index.ts +1 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +332 -131
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -5
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
- package/src/contract_function_simulator/noir-structs/message_tx_context.ts +55 -0
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -6
- package/src/contract_function_simulator/oracle/interfaces.ts +61 -62
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +77 -0
- package/src/contract_function_simulator/oracle/oracle.ts +182 -148
- package/src/contract_function_simulator/oracle/private_execution.ts +3 -3
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +131 -172
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +238 -112
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +152 -0
- package/src/contract_sync/{index.ts → helpers.ts} +21 -21
- package/src/debug/pxe_debug_utils.ts +63 -19
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +16 -15
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/client/lazy/utils.ts +17 -15
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +3 -1
- package/src/entrypoints/server/utils.ts +22 -26
- package/src/events/event_service.ts +4 -6
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +31 -38
- package/src/messages/message_context_service.ts +45 -0
- package/src/notes/note_service.ts +9 -10
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +3 -3
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +25 -15
- package/src/private_kernel/private_kernel_oracle.ts +9 -9
- package/src/pxe.ts +209 -124
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
- package/src/storage/capsule_store/capsule_store.ts +8 -8
- package/src/storage/contract_store/contract_store.ts +186 -76
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +169 -132
- package/src/storage/private_event_store/private_event_store.ts +102 -81
- package/src/storage/private_event_store/stored_private_event.ts +3 -3
- package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +287 -156
- package/src/tagging/get_all_logs_by_tags.ts +31 -7
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +9 -12
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +12 -17
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +25 -12
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +30 -29
- package/dest/contract_sync/index.d.ts +0 -23
- package/dest/contract_sync/index.d.ts.map +0 -1
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
|
|
2
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
6
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
7
7
|
import { KeyStore } from '@aztec/key-store';
|
|
@@ -33,6 +33,7 @@ import type {
|
|
|
33
33
|
PrivateKernelTailCircuitPublicInputs,
|
|
34
34
|
} from '@aztec/stdlib/kernel';
|
|
35
35
|
import {
|
|
36
|
+
BlockHeader,
|
|
36
37
|
type ContractOverrides,
|
|
37
38
|
type InTx,
|
|
38
39
|
PrivateExecutionResult,
|
|
@@ -46,11 +47,12 @@ import {
|
|
|
46
47
|
TxProfileResult,
|
|
47
48
|
TxProvingResult,
|
|
48
49
|
TxSimulationResult,
|
|
49
|
-
|
|
50
|
+
UtilityExecutionResult,
|
|
50
51
|
} from '@aztec/stdlib/tx';
|
|
51
52
|
|
|
52
53
|
import { inspect } from 'util';
|
|
53
54
|
|
|
55
|
+
import type { AccessScopes } from './access_scopes.js';
|
|
54
56
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
55
57
|
import type { PXEConfig } from './config/index.js';
|
|
56
58
|
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
@@ -59,11 +61,14 @@ import {
|
|
|
59
61
|
generateSimulatedProvingResult,
|
|
60
62
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
61
63
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
62
|
-
import {
|
|
64
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
65
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
66
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
63
67
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
64
68
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
65
69
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
66
70
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
71
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
67
72
|
import {
|
|
68
73
|
PrivateKernelExecutionProver,
|
|
69
74
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -84,6 +89,56 @@ export type PackedPrivateEvent = InTx & {
|
|
|
84
89
|
eventSelector: EventSelector;
|
|
85
90
|
};
|
|
86
91
|
|
|
92
|
+
/** Options for PXE.profileTx. */
|
|
93
|
+
export type ProfileTxOpts = {
|
|
94
|
+
/** The profiling mode to use. */
|
|
95
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
96
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
97
|
+
skipProofGeneration?: boolean;
|
|
98
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
99
|
+
scopes: AccessScopes;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** Options for PXE.simulateTx. */
|
|
103
|
+
export type SimulateTxOpts = {
|
|
104
|
+
/** Whether to simulate the public part of the transaction. */
|
|
105
|
+
simulatePublic: boolean;
|
|
106
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
107
|
+
skipTxValidation?: boolean;
|
|
108
|
+
/** If false, fees are enforced. */
|
|
109
|
+
skipFeeEnforcement?: boolean;
|
|
110
|
+
/** State overrides for the simulation, such as contract instances and artifacts. */
|
|
111
|
+
overrides?: SimulationOverrides;
|
|
112
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
113
|
+
scopes: AccessScopes;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** Options for PXE.executeUtility. */
|
|
117
|
+
export type ExecuteUtilityOpts = {
|
|
118
|
+
/** The authentication witnesses required for the function call. */
|
|
119
|
+
authwits?: AuthWitness[];
|
|
120
|
+
/** The accounts whose notes we can access in this call */
|
|
121
|
+
scopes: AccessScopes;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/** Args for PXE.create. */
|
|
125
|
+
export type PXECreateArgs = {
|
|
126
|
+
/** The Aztec node to connect to. */
|
|
127
|
+
node: AztecNode;
|
|
128
|
+
/** The key-value store for persisting PXE state. */
|
|
129
|
+
store: AztecAsyncKVStore;
|
|
130
|
+
/** The prover for generating private kernel proofs. */
|
|
131
|
+
proofCreator: PrivateKernelProver;
|
|
132
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
133
|
+
simulator: CircuitSimulator;
|
|
134
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
135
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
136
|
+
/** PXE configuration options. */
|
|
137
|
+
config: PXEConfig;
|
|
138
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
139
|
+
loggerOrSuffix?: string | Logger;
|
|
140
|
+
};
|
|
141
|
+
|
|
87
142
|
/**
|
|
88
143
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
89
144
|
* manage private state of users.
|
|
@@ -91,6 +146,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
91
146
|
export class PXE {
|
|
92
147
|
private constructor(
|
|
93
148
|
private node: AztecNode,
|
|
149
|
+
private db: AztecAsyncKVStore,
|
|
94
150
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
95
151
|
private keyStore: KeyStore,
|
|
96
152
|
private contractStore: ContractStore,
|
|
@@ -102,6 +158,8 @@ export class PXE {
|
|
|
102
158
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
103
159
|
private addressStore: AddressStore,
|
|
104
160
|
private privateEventStore: PrivateEventStore,
|
|
161
|
+
private contractSyncService: ContractSyncService,
|
|
162
|
+
private messageContextService: MessageContextService,
|
|
105
163
|
private simulator: CircuitSimulator,
|
|
106
164
|
private proverEnabled: boolean,
|
|
107
165
|
private proofCreator: PrivateKernelProver,
|
|
@@ -119,21 +177,27 @@ export class PXE {
|
|
|
119
177
|
*
|
|
120
178
|
* @returns A promise that resolves PXE is ready to be used.
|
|
121
179
|
*/
|
|
122
|
-
public static async create(
|
|
123
|
-
node
|
|
124
|
-
store
|
|
125
|
-
proofCreator
|
|
126
|
-
simulator
|
|
127
|
-
protocolContractsProvider
|
|
128
|
-
config
|
|
129
|
-
loggerOrSuffix
|
|
130
|
-
) {
|
|
180
|
+
public static async create({
|
|
181
|
+
node,
|
|
182
|
+
store,
|
|
183
|
+
proofCreator,
|
|
184
|
+
simulator,
|
|
185
|
+
protocolContractsProvider,
|
|
186
|
+
config,
|
|
187
|
+
loggerOrSuffix,
|
|
188
|
+
}: PXECreateArgs) {
|
|
189
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
190
|
+
const bindings: LoggerBindings | undefined =
|
|
191
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
192
|
+
|
|
131
193
|
const log =
|
|
132
194
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
133
195
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
134
196
|
: loggerOrSuffix;
|
|
135
197
|
|
|
136
|
-
const
|
|
198
|
+
const info = await node.getNodeInfo();
|
|
199
|
+
|
|
200
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
137
201
|
const addressStore = new AddressStore(store);
|
|
138
202
|
const privateEventStore = new PrivateEventStore(store);
|
|
139
203
|
const contractStore = new ContractStore(store);
|
|
@@ -145,6 +209,14 @@ export class PXE {
|
|
|
145
209
|
const capsuleStore = new CapsuleStore(store);
|
|
146
210
|
const keyStore = new KeyStore(store);
|
|
147
211
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
212
|
+
const contractSyncService = new ContractSyncService(
|
|
213
|
+
node,
|
|
214
|
+
contractStore,
|
|
215
|
+
noteStore,
|
|
216
|
+
createLogger('pxe:contract_sync', bindings),
|
|
217
|
+
);
|
|
218
|
+
const messageContextService = new MessageContextService(node);
|
|
219
|
+
|
|
148
220
|
const synchronizer = new BlockSynchronizer(
|
|
149
221
|
node,
|
|
150
222
|
store,
|
|
@@ -152,25 +224,28 @@ export class PXE {
|
|
|
152
224
|
noteStore,
|
|
153
225
|
privateEventStore,
|
|
154
226
|
tipsStore,
|
|
227
|
+
contractSyncService,
|
|
155
228
|
config,
|
|
156
|
-
|
|
229
|
+
bindings,
|
|
157
230
|
);
|
|
158
231
|
|
|
159
|
-
const jobCoordinator = new JobCoordinator(store);
|
|
232
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
160
233
|
jobCoordinator.registerStores([
|
|
161
234
|
capsuleStore,
|
|
162
235
|
senderTaggingStore,
|
|
163
236
|
recipientTaggingStore,
|
|
164
237
|
privateEventStore,
|
|
165
238
|
noteStore,
|
|
239
|
+
contractSyncService,
|
|
166
240
|
]);
|
|
167
241
|
|
|
168
|
-
const debugUtils = new PXEDebugUtils(
|
|
242
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
169
243
|
|
|
170
244
|
const jobQueue = new SerialQueue();
|
|
171
245
|
|
|
172
246
|
const pxe = new PXE(
|
|
173
247
|
node,
|
|
248
|
+
store,
|
|
174
249
|
synchronizer,
|
|
175
250
|
keyStore,
|
|
176
251
|
contractStore,
|
|
@@ -182,6 +257,8 @@ export class PXE {
|
|
|
182
257
|
recipientTaggingStore,
|
|
183
258
|
addressStore,
|
|
184
259
|
privateEventStore,
|
|
260
|
+
contractSyncService,
|
|
261
|
+
messageContextService,
|
|
185
262
|
simulator,
|
|
186
263
|
proverEnabled,
|
|
187
264
|
proofCreator,
|
|
@@ -192,12 +269,15 @@ export class PXE {
|
|
|
192
269
|
debugUtils,
|
|
193
270
|
);
|
|
194
271
|
|
|
195
|
-
debugUtils.
|
|
272
|
+
debugUtils.setPXEHelpers(
|
|
273
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
274
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
275
|
+
pxe.#executeUtility.bind(pxe),
|
|
276
|
+
);
|
|
196
277
|
|
|
197
278
|
pxe.jobQueue.start();
|
|
198
279
|
|
|
199
280
|
await pxe.#registerProtocolContracts();
|
|
200
|
-
const info = await node.getNodeInfo();
|
|
201
281
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
202
282
|
return pxe;
|
|
203
283
|
}
|
|
@@ -207,20 +287,21 @@ export class PXE {
|
|
|
207
287
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
208
288
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
209
289
|
|
|
210
|
-
return new ContractFunctionSimulator(
|
|
211
|
-
proxyContractStore,
|
|
212
|
-
this.noteStore,
|
|
213
|
-
this.keyStore,
|
|
214
|
-
this.addressStore,
|
|
215
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
216
|
-
this.
|
|
217
|
-
this.
|
|
218
|
-
this.
|
|
219
|
-
this.
|
|
220
|
-
this.
|
|
221
|
-
this.
|
|
222
|
-
this.
|
|
223
|
-
|
|
290
|
+
return new ContractFunctionSimulator({
|
|
291
|
+
contractStore: proxyContractStore,
|
|
292
|
+
noteStore: this.noteStore,
|
|
293
|
+
keyStore: this.keyStore,
|
|
294
|
+
addressStore: this.addressStore,
|
|
295
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
296
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
297
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
298
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
299
|
+
capsuleStore: this.capsuleStore,
|
|
300
|
+
privateEventStore: this.privateEventStore,
|
|
301
|
+
simulator: this.simulator,
|
|
302
|
+
contractSyncService: this.contractSyncService,
|
|
303
|
+
messageContextService: this.messageContextService,
|
|
304
|
+
});
|
|
224
305
|
}
|
|
225
306
|
|
|
226
307
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -272,9 +353,8 @@ export class PXE {
|
|
|
272
353
|
async #registerProtocolContracts() {
|
|
273
354
|
const registered: Record<string, string> = {};
|
|
274
355
|
for (const name of protocolContractNames) {
|
|
275
|
-
const { address,
|
|
276
|
-
|
|
277
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
356
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
357
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
278
358
|
await this.contractStore.addContractInstance(instance);
|
|
279
359
|
registered[name] = address.toString();
|
|
280
360
|
}
|
|
@@ -286,7 +366,7 @@ export class PXE {
|
|
|
286
366
|
async #executePrivate(
|
|
287
367
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
288
368
|
txRequest: TxExecutionRequest,
|
|
289
|
-
scopes:
|
|
369
|
+
scopes: AccessScopes,
|
|
290
370
|
jobId: string,
|
|
291
371
|
): Promise<PrivateExecutionResult> {
|
|
292
372
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -294,27 +374,23 @@ export class PXE {
|
|
|
294
374
|
try {
|
|
295
375
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
296
376
|
|
|
297
|
-
await ensureContractSynced(
|
|
377
|
+
await this.contractSyncService.ensureContractSynced(
|
|
298
378
|
contractAddress,
|
|
299
379
|
functionSelector,
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
this.contractStore,
|
|
380
|
+
(privateSyncCall, execScopes) =>
|
|
381
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
303
382
|
anchorBlockHeader,
|
|
383
|
+
jobId,
|
|
384
|
+
scopes,
|
|
304
385
|
);
|
|
305
386
|
|
|
306
|
-
const result = await contractFunctionSimulator.run(
|
|
307
|
-
txRequest,
|
|
387
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
308
388
|
contractAddress,
|
|
309
|
-
functionSelector,
|
|
310
|
-
undefined,
|
|
389
|
+
selector: functionSelector,
|
|
311
390
|
anchorBlockHeader,
|
|
312
|
-
// The sender for tags is set by contracts, typically by an account
|
|
313
|
-
// contract entrypoint
|
|
314
|
-
undefined, // senderForTags
|
|
315
391
|
scopes,
|
|
316
392
|
jobId,
|
|
317
|
-
);
|
|
393
|
+
});
|
|
318
394
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
319
395
|
return result;
|
|
320
396
|
} catch (err) {
|
|
@@ -326,20 +402,20 @@ export class PXE {
|
|
|
326
402
|
}
|
|
327
403
|
|
|
328
404
|
/**
|
|
329
|
-
*
|
|
405
|
+
* Execute a utility function call on the given contract.
|
|
330
406
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
331
407
|
* @param call - The function call to execute.
|
|
332
408
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
333
409
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
334
410
|
* accounts if not specified.
|
|
335
411
|
* @param jobId - The job ID for staged writes.
|
|
336
|
-
* @returns The
|
|
412
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
337
413
|
*/
|
|
338
|
-
async #
|
|
414
|
+
async #executeUtility(
|
|
339
415
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
340
416
|
call: FunctionCall,
|
|
341
417
|
authWitnesses: AuthWitness[] | undefined,
|
|
342
|
-
scopes:
|
|
418
|
+
scopes: AccessScopes,
|
|
343
419
|
jobId: string,
|
|
344
420
|
) {
|
|
345
421
|
try {
|
|
@@ -400,13 +476,31 @@ export class PXE {
|
|
|
400
476
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
401
477
|
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
402
478
|
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
403
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
479
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
480
|
+
kernelOracle,
|
|
481
|
+
proofCreator,
|
|
482
|
+
!this.proverEnabled,
|
|
483
|
+
this.log.getBindings(),
|
|
484
|
+
);
|
|
404
485
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
405
486
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
406
487
|
}
|
|
407
488
|
|
|
408
489
|
// Public API
|
|
409
490
|
|
|
491
|
+
/**
|
|
492
|
+
* Returns the block header up to which the PXE has synced.
|
|
493
|
+
* @returns The synced block header
|
|
494
|
+
*/
|
|
495
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
496
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
501
|
+
* @param address - The contract address.
|
|
502
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
503
|
+
*/
|
|
410
504
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
411
505
|
return this.contractStore.getContractInstance(address);
|
|
412
506
|
}
|
|
@@ -515,8 +609,7 @@ export class PXE {
|
|
|
515
609
|
* @param artifact - The build artifact for the contract class.
|
|
516
610
|
*/
|
|
517
611
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
518
|
-
const
|
|
519
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
612
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
520
613
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
521
614
|
}
|
|
522
615
|
|
|
@@ -535,17 +628,17 @@ export class PXE {
|
|
|
535
628
|
if (artifact) {
|
|
536
629
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
537
630
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
538
|
-
|
|
539
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
631
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
540
632
|
throw new Error(
|
|
541
|
-
`Artifact does not match expected class id (computed ${
|
|
633
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
542
634
|
);
|
|
543
635
|
}
|
|
544
636
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
545
637
|
if (!computedAddress.equals(instance.address)) {
|
|
546
638
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
547
639
|
}
|
|
548
|
-
|
|
640
|
+
|
|
641
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
549
642
|
|
|
550
643
|
const publicFunctionSignatures = artifact.functions
|
|
551
644
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -594,15 +687,16 @@ export class PXE {
|
|
|
594
687
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
595
688
|
}
|
|
596
689
|
|
|
597
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
598
|
-
|
|
599
690
|
const publicFunctionSignatures = artifact.functions
|
|
600
691
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
601
692
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
602
693
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
603
694
|
|
|
604
695
|
currentInstance.currentContractClassId = contractClass.id;
|
|
605
|
-
await
|
|
696
|
+
await Promise.all([
|
|
697
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
698
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
699
|
+
]);
|
|
606
700
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
607
701
|
});
|
|
608
702
|
}
|
|
@@ -620,11 +714,12 @@ export class PXE {
|
|
|
620
714
|
* (where validators prove the public portion).
|
|
621
715
|
*
|
|
622
716
|
* @param txRequest - An authenticated tx request ready for proving
|
|
717
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
623
718
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
624
719
|
* @throws If contract code not found, or public simulation reverts.
|
|
625
720
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
626
721
|
*/
|
|
627
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
722
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
628
723
|
let privateExecutionResult: PrivateExecutionResult;
|
|
629
724
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
630
725
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -635,7 +730,7 @@ export class PXE {
|
|
|
635
730
|
await this.blockStateSynchronizer.sync();
|
|
636
731
|
const syncTime = syncTimer.ms();
|
|
637
732
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
638
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
733
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
639
734
|
|
|
640
735
|
const {
|
|
641
736
|
publicInputs,
|
|
@@ -677,17 +772,17 @@ export class PXE {
|
|
|
677
772
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
678
773
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
679
774
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
680
|
-
const
|
|
681
|
-
if (
|
|
775
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
776
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
682
777
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
683
778
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
684
779
|
|
|
685
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
686
|
-
this.log.debug(`Stored used
|
|
687
|
-
|
|
780
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
781
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
782
|
+
taggingIndexRangesUsedInTheTx,
|
|
688
783
|
});
|
|
689
784
|
} else {
|
|
690
|
-
this.log.debug(`No
|
|
785
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
691
786
|
}
|
|
692
787
|
|
|
693
788
|
return txProvingResult;
|
|
@@ -699,17 +794,13 @@ export class PXE {
|
|
|
699
794
|
|
|
700
795
|
/**
|
|
701
796
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
702
|
-
*
|
|
703
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
704
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
705
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
797
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
706
798
|
* @returns A trace of the program execution with gate counts.
|
|
707
799
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
708
800
|
*/
|
|
709
801
|
public profileTx(
|
|
710
802
|
txRequest: TxExecutionRequest,
|
|
711
|
-
profileMode
|
|
712
|
-
skipProofGeneration: boolean = true,
|
|
803
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
713
804
|
): Promise<TxProfileResult> {
|
|
714
805
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
715
806
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -732,12 +823,7 @@ export class PXE {
|
|
|
732
823
|
const syncTime = syncTimer.ms();
|
|
733
824
|
|
|
734
825
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
735
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
736
|
-
contractFunctionSimulator,
|
|
737
|
-
txRequest,
|
|
738
|
-
undefined,
|
|
739
|
-
jobId,
|
|
740
|
-
);
|
|
826
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
741
827
|
|
|
742
828
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
743
829
|
txRequest,
|
|
@@ -794,12 +880,7 @@ export class PXE {
|
|
|
794
880
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
795
881
|
*
|
|
796
882
|
*
|
|
797
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
798
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
799
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
800
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
801
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
802
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
883
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
803
884
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
804
885
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
805
886
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -808,11 +889,7 @@ export class PXE {
|
|
|
808
889
|
*/
|
|
809
890
|
public simulateTx(
|
|
810
891
|
txRequest: TxExecutionRequest,
|
|
811
|
-
simulatePublic:
|
|
812
|
-
skipTxValidation: boolean = false,
|
|
813
|
-
skipFeeEnforcement: boolean = false,
|
|
814
|
-
overrides?: SimulationOverrides,
|
|
815
|
-
scopes?: AztecAddress[],
|
|
892
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
816
893
|
): Promise<TxSimulationResult> {
|
|
817
894
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
818
895
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -840,7 +917,14 @@ export class PXE {
|
|
|
840
917
|
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
841
918
|
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
842
919
|
// or not.
|
|
843
|
-
const
|
|
920
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
921
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
922
|
+
const skipKernels = hasOverriddenContracts;
|
|
923
|
+
|
|
924
|
+
// Set overridden contracts on the sync service so it knows to skip syncing them
|
|
925
|
+
if (hasOverriddenContracts) {
|
|
926
|
+
this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
|
|
927
|
+
}
|
|
844
928
|
|
|
845
929
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
846
930
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -851,7 +935,8 @@ export class PXE {
|
|
|
851
935
|
if (skipKernels) {
|
|
852
936
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
853
937
|
privateExecutionResult,
|
|
854
|
-
this.contractStore,
|
|
938
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
939
|
+
this.node,
|
|
855
940
|
));
|
|
856
941
|
} else {
|
|
857
942
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -870,6 +955,9 @@ export class PXE {
|
|
|
870
955
|
const publicSimulationTimer = new Timer();
|
|
871
956
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
872
957
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
958
|
+
if (publicOutput?.debugLogs?.length) {
|
|
959
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
960
|
+
}
|
|
873
961
|
}
|
|
874
962
|
|
|
875
963
|
let validationTime: number | undefined;
|
|
@@ -878,7 +966,8 @@ export class PXE {
|
|
|
878
966
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
879
967
|
validationTime = validationTimer.ms();
|
|
880
968
|
if (validationResult.result === 'invalid') {
|
|
881
|
-
|
|
969
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
970
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
882
971
|
}
|
|
883
972
|
}
|
|
884
973
|
|
|
@@ -929,29 +1018,23 @@ export class PXE {
|
|
|
929
1018
|
inspect(txRequest),
|
|
930
1019
|
`simulatePublic=${simulatePublic}`,
|
|
931
1020
|
`skipTxValidation=${skipTxValidation}`,
|
|
932
|
-
`scopes=${scopes
|
|
1021
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
933
1022
|
);
|
|
934
1023
|
}
|
|
935
1024
|
});
|
|
936
1025
|
}
|
|
937
1026
|
|
|
938
1027
|
/**
|
|
939
|
-
*
|
|
940
|
-
*
|
|
1028
|
+
* Executes a contract utility function.
|
|
941
1029
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
942
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
943
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
944
|
-
* default to all.
|
|
945
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
946
1030
|
*/
|
|
947
|
-
public
|
|
1031
|
+
public executeUtility(
|
|
948
1032
|
call: FunctionCall,
|
|
949
|
-
authwits
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1033
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
1034
|
+
): Promise<UtilityExecutionResult> {
|
|
1035
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
953
1036
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
954
|
-
// delete the same read value, or reading values that another
|
|
1037
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
955
1038
|
return this.#putInJobQueue(async jobId => {
|
|
956
1039
|
try {
|
|
957
1040
|
const totalTimer = new Timer();
|
|
@@ -962,16 +1045,17 @@ export class PXE {
|
|
|
962
1045
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
963
1046
|
|
|
964
1047
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
965
|
-
await ensureContractSynced(
|
|
1048
|
+
await this.contractSyncService.ensureContractSynced(
|
|
966
1049
|
call.to,
|
|
967
1050
|
call.selector,
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
this.contractStore,
|
|
1051
|
+
(privateSyncCall, execScopes) =>
|
|
1052
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
971
1053
|
anchorBlockHeader,
|
|
1054
|
+
jobId,
|
|
1055
|
+
scopes,
|
|
972
1056
|
);
|
|
973
1057
|
|
|
974
|
-
const executionResult = await this.#
|
|
1058
|
+
const executionResult = await this.#executeUtility(
|
|
975
1059
|
contractFunctionSimulator,
|
|
976
1060
|
call,
|
|
977
1061
|
authwits ?? [],
|
|
@@ -998,8 +1082,8 @@ export class PXE {
|
|
|
998
1082
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
999
1083
|
throw this.#contextualizeError(
|
|
1000
1084
|
err,
|
|
1001
|
-
`
|
|
1002
|
-
`scopes=${scopes
|
|
1085
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1086
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1003
1087
|
);
|
|
1004
1088
|
}
|
|
1005
1089
|
});
|
|
@@ -1032,14 +1116,14 @@ export class PXE {
|
|
|
1032
1116
|
|
|
1033
1117
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1034
1118
|
|
|
1035
|
-
await ensureContractSynced(
|
|
1119
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1036
1120
|
filter.contractAddress,
|
|
1037
1121
|
null,
|
|
1038
|
-
async privateSyncCall =>
|
|
1039
|
-
await this.#
|
|
1040
|
-
this.node,
|
|
1041
|
-
this.contractStore,
|
|
1122
|
+
async (privateSyncCall, execScopes) =>
|
|
1123
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1042
1124
|
anchorBlockHeader,
|
|
1125
|
+
jobId,
|
|
1126
|
+
filter.scopes,
|
|
1043
1127
|
);
|
|
1044
1128
|
});
|
|
1045
1129
|
|
|
@@ -1054,9 +1138,10 @@ export class PXE {
|
|
|
1054
1138
|
}
|
|
1055
1139
|
|
|
1056
1140
|
/**
|
|
1057
|
-
* Stops the PXE's job queue.
|
|
1141
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1058
1142
|
*/
|
|
1059
|
-
public stop(): Promise<void> {
|
|
1060
|
-
|
|
1143
|
+
public async stop(): Promise<void> {
|
|
1144
|
+
await this.jobQueue.end();
|
|
1145
|
+
await this.db.close();
|
|
1061
1146
|
}
|
|
1062
1147
|
}
|