@aztec/pxe 0.0.1-commit.3d8f95d → 0.0.1-commit.3e3d0c9cd
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/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 +15 -7
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +129 -45
- 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 +49 -45
- 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 +43 -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 +142 -93
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +24 -45
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +39 -69
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +48 -37
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +104 -55
- 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 +4 -2
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +34 -19
- package/dest/contract_sync/helpers.d.ts +3 -2
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +3 -3
- package/dest/debug/pxe_debug_utils.d.ts +5 -4
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +4 -4
- 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/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/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/logs/log_service.d.ts +3 -2
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +9 -14
- 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 +4 -3
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +3 -2
- 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 +2 -2
- 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 +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
- package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
- 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 +23 -15
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +72 -51
- 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 +140 -64
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +3 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +3 -4
- 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/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 +141 -115
- package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
- 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 +4 -5
- 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 +6 -7
- 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 +4 -8
- 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 +5 -7
- 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 +16 -16
- package/src/access_scopes.ts +9 -0
- package/src/config/index.ts +1 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +244 -65
- 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 +53 -54
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +142 -0
- package/src/contract_function_simulator/oracle/oracle.ts +155 -137
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +47 -86
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +142 -67
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +49 -26
- package/src/contract_sync/helpers.ts +7 -2
- package/src/debug/pxe_debug_utils.ts +11 -9
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/server/index.ts +2 -0
- package/src/logs/log_service.ts +17 -24
- package/src/messages/message_context_service.ts +45 -0
- package/src/notes/note_service.ts +4 -3
- 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 +19 -12
- package/src/private_kernel/private_kernel_oracle.ts +7 -7
- package/src/pxe.ts +111 -69
- package/src/storage/contract_store/contract_store.ts +170 -71
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +8 -5
- package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
- package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
- 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 +27 -26
- 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
|
@@ -47,11 +47,12 @@ import {
|
|
|
47
47
|
TxProfileResult,
|
|
48
48
|
TxProvingResult,
|
|
49
49
|
TxSimulationResult,
|
|
50
|
-
|
|
50
|
+
UtilityExecutionResult,
|
|
51
51
|
} from '@aztec/stdlib/tx';
|
|
52
52
|
|
|
53
53
|
import { inspect } from 'util';
|
|
54
54
|
|
|
55
|
+
import type { AccessScopes } from './access_scopes.js';
|
|
55
56
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
56
57
|
import type { PXEConfig } from './config/index.js';
|
|
57
58
|
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
@@ -60,12 +61,14 @@ import {
|
|
|
60
61
|
generateSimulatedProvingResult,
|
|
61
62
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
62
63
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
64
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
63
65
|
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
64
66
|
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
65
67
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
66
68
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
67
69
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
68
70
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
71
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
69
72
|
import {
|
|
70
73
|
PrivateKernelExecutionProver,
|
|
71
74
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -92,6 +95,8 @@ export type ProfileTxOpts = {
|
|
|
92
95
|
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
93
96
|
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
94
97
|
skipProofGeneration?: boolean;
|
|
98
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
99
|
+
scopes: AccessScopes;
|
|
95
100
|
};
|
|
96
101
|
|
|
97
102
|
/** Options for PXE.simulateTx. */
|
|
@@ -102,18 +107,20 @@ export type SimulateTxOpts = {
|
|
|
102
107
|
skipTxValidation?: boolean;
|
|
103
108
|
/** If false, fees are enforced. */
|
|
104
109
|
skipFeeEnforcement?: boolean;
|
|
105
|
-
/**
|
|
110
|
+
/** If true, kernel logic is emulated in TS for simulation */
|
|
111
|
+
skipKernels?: boolean;
|
|
112
|
+
/** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
|
|
106
113
|
overrides?: SimulationOverrides;
|
|
107
|
-
/**
|
|
108
|
-
scopes
|
|
114
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
115
|
+
scopes: AccessScopes;
|
|
109
116
|
};
|
|
110
117
|
|
|
111
|
-
/** Options for PXE.
|
|
112
|
-
export type
|
|
118
|
+
/** Options for PXE.executeUtility. */
|
|
119
|
+
export type ExecuteUtilityOpts = {
|
|
113
120
|
/** The authentication witnesses required for the function call. */
|
|
114
121
|
authwits?: AuthWitness[];
|
|
115
|
-
/** The accounts whose notes we can access in this call
|
|
116
|
-
scopes
|
|
122
|
+
/** The accounts whose notes we can access in this call */
|
|
123
|
+
scopes: AccessScopes;
|
|
117
124
|
};
|
|
118
125
|
|
|
119
126
|
/** Args for PXE.create. */
|
|
@@ -141,6 +148,7 @@ export type PXECreateArgs = {
|
|
|
141
148
|
export class PXE {
|
|
142
149
|
private constructor(
|
|
143
150
|
private node: AztecNode,
|
|
151
|
+
private db: AztecAsyncKVStore,
|
|
144
152
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
145
153
|
private keyStore: KeyStore,
|
|
146
154
|
private contractStore: ContractStore,
|
|
@@ -153,6 +161,7 @@ export class PXE {
|
|
|
153
161
|
private addressStore: AddressStore,
|
|
154
162
|
private privateEventStore: PrivateEventStore,
|
|
155
163
|
private contractSyncService: ContractSyncService,
|
|
164
|
+
private messageContextService: MessageContextService,
|
|
156
165
|
private simulator: CircuitSimulator,
|
|
157
166
|
private proverEnabled: boolean,
|
|
158
167
|
private proofCreator: PrivateKernelProver,
|
|
@@ -188,7 +197,9 @@ export class PXE {
|
|
|
188
197
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
189
198
|
: loggerOrSuffix;
|
|
190
199
|
|
|
191
|
-
const
|
|
200
|
+
const info = await node.getNodeInfo();
|
|
201
|
+
|
|
202
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
192
203
|
const addressStore = new AddressStore(store);
|
|
193
204
|
const privateEventStore = new PrivateEventStore(store);
|
|
194
205
|
const contractStore = new ContractStore(store);
|
|
@@ -206,6 +217,8 @@ export class PXE {
|
|
|
206
217
|
noteStore,
|
|
207
218
|
createLogger('pxe:contract_sync', bindings),
|
|
208
219
|
);
|
|
220
|
+
const messageContextService = new MessageContextService(node);
|
|
221
|
+
|
|
209
222
|
const synchronizer = new BlockSynchronizer(
|
|
210
223
|
node,
|
|
211
224
|
store,
|
|
@@ -234,6 +247,7 @@ export class PXE {
|
|
|
234
247
|
|
|
235
248
|
const pxe = new PXE(
|
|
236
249
|
node,
|
|
250
|
+
store,
|
|
237
251
|
synchronizer,
|
|
238
252
|
keyStore,
|
|
239
253
|
contractStore,
|
|
@@ -246,6 +260,7 @@ export class PXE {
|
|
|
246
260
|
addressStore,
|
|
247
261
|
privateEventStore,
|
|
248
262
|
contractSyncService,
|
|
263
|
+
messageContextService,
|
|
249
264
|
simulator,
|
|
250
265
|
proverEnabled,
|
|
251
266
|
proofCreator,
|
|
@@ -259,13 +274,12 @@ export class PXE {
|
|
|
259
274
|
debugUtils.setPXEHelpers(
|
|
260
275
|
pxe.#putInJobQueue.bind(pxe),
|
|
261
276
|
pxe.#getSimulatorForTx.bind(pxe),
|
|
262
|
-
pxe.#
|
|
277
|
+
pxe.#executeUtility.bind(pxe),
|
|
263
278
|
);
|
|
264
279
|
|
|
265
280
|
pxe.jobQueue.start();
|
|
266
281
|
|
|
267
282
|
await pxe.#registerProtocolContracts();
|
|
268
|
-
const info = await node.getNodeInfo();
|
|
269
283
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
270
284
|
return pxe;
|
|
271
285
|
}
|
|
@@ -288,6 +302,7 @@ export class PXE {
|
|
|
288
302
|
privateEventStore: this.privateEventStore,
|
|
289
303
|
simulator: this.simulator,
|
|
290
304
|
contractSyncService: this.contractSyncService,
|
|
305
|
+
messageContextService: this.messageContextService,
|
|
291
306
|
});
|
|
292
307
|
}
|
|
293
308
|
|
|
@@ -340,9 +355,8 @@ export class PXE {
|
|
|
340
355
|
async #registerProtocolContracts() {
|
|
341
356
|
const registered: Record<string, string> = {};
|
|
342
357
|
for (const name of protocolContractNames) {
|
|
343
|
-
const { address,
|
|
344
|
-
|
|
345
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
358
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
359
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
346
360
|
await this.contractStore.addContractInstance(instance);
|
|
347
361
|
registered[name] = address.toString();
|
|
348
362
|
}
|
|
@@ -354,7 +368,7 @@ export class PXE {
|
|
|
354
368
|
async #executePrivate(
|
|
355
369
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
356
370
|
txRequest: TxExecutionRequest,
|
|
357
|
-
scopes:
|
|
371
|
+
scopes: AccessScopes,
|
|
358
372
|
jobId: string,
|
|
359
373
|
): Promise<PrivateExecutionResult> {
|
|
360
374
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -365,9 +379,11 @@ export class PXE {
|
|
|
365
379
|
await this.contractSyncService.ensureContractSynced(
|
|
366
380
|
contractAddress,
|
|
367
381
|
functionSelector,
|
|
368
|
-
|
|
382
|
+
(privateSyncCall, execScopes) =>
|
|
383
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
369
384
|
anchorBlockHeader,
|
|
370
385
|
jobId,
|
|
386
|
+
scopes,
|
|
371
387
|
);
|
|
372
388
|
|
|
373
389
|
const result = await contractFunctionSimulator.run(txRequest, {
|
|
@@ -388,25 +404,32 @@ export class PXE {
|
|
|
388
404
|
}
|
|
389
405
|
|
|
390
406
|
/**
|
|
391
|
-
*
|
|
407
|
+
* Execute a utility function call on the given contract.
|
|
392
408
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
393
409
|
* @param call - The function call to execute.
|
|
394
410
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
395
411
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
396
412
|
* accounts if not specified.
|
|
397
413
|
* @param jobId - The job ID for staged writes.
|
|
398
|
-
* @returns The
|
|
414
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
399
415
|
*/
|
|
400
|
-
async #
|
|
416
|
+
async #executeUtility(
|
|
401
417
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
402
418
|
call: FunctionCall,
|
|
403
419
|
authWitnesses: AuthWitness[] | undefined,
|
|
404
|
-
scopes:
|
|
420
|
+
scopes: AccessScopes,
|
|
405
421
|
jobId: string,
|
|
406
422
|
) {
|
|
407
423
|
try {
|
|
408
424
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
409
|
-
|
|
425
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
426
|
+
call,
|
|
427
|
+
authWitnesses ?? [],
|
|
428
|
+
anchorBlockHeader,
|
|
429
|
+
scopes,
|
|
430
|
+
jobId,
|
|
431
|
+
);
|
|
432
|
+
return { result, offchainEffects };
|
|
410
433
|
} catch (err) {
|
|
411
434
|
if (err instanceof SimulationError) {
|
|
412
435
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -595,8 +618,7 @@ export class PXE {
|
|
|
595
618
|
* @param artifact - The build artifact for the contract class.
|
|
596
619
|
*/
|
|
597
620
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
598
|
-
const
|
|
599
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
621
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
600
622
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
601
623
|
}
|
|
602
624
|
|
|
@@ -615,17 +637,17 @@ export class PXE {
|
|
|
615
637
|
if (artifact) {
|
|
616
638
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
617
639
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
618
|
-
|
|
619
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
640
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
620
641
|
throw new Error(
|
|
621
|
-
`Artifact does not match expected class id (computed ${
|
|
642
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
622
643
|
);
|
|
623
644
|
}
|
|
624
645
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
625
646
|
if (!computedAddress.equals(instance.address)) {
|
|
626
647
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
627
648
|
}
|
|
628
|
-
|
|
649
|
+
|
|
650
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
629
651
|
|
|
630
652
|
const publicFunctionSignatures = artifact.functions
|
|
631
653
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -674,15 +696,16 @@ export class PXE {
|
|
|
674
696
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
675
697
|
}
|
|
676
698
|
|
|
677
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
678
|
-
|
|
679
699
|
const publicFunctionSignatures = artifact.functions
|
|
680
700
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
681
701
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
682
702
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
683
703
|
|
|
684
704
|
currentInstance.currentContractClassId = contractClass.id;
|
|
685
|
-
await
|
|
705
|
+
await Promise.all([
|
|
706
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
707
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
708
|
+
]);
|
|
686
709
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
687
710
|
});
|
|
688
711
|
}
|
|
@@ -700,11 +723,12 @@ export class PXE {
|
|
|
700
723
|
* (where validators prove the public portion).
|
|
701
724
|
*
|
|
702
725
|
* @param txRequest - An authenticated tx request ready for proving
|
|
726
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
703
727
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
704
728
|
* @throws If contract code not found, or public simulation reverts.
|
|
705
729
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
706
730
|
*/
|
|
707
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
731
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
708
732
|
let privateExecutionResult: PrivateExecutionResult;
|
|
709
733
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
710
734
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -715,7 +739,7 @@ export class PXE {
|
|
|
715
739
|
await this.blockStateSynchronizer.sync();
|
|
716
740
|
const syncTime = syncTimer.ms();
|
|
717
741
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
718
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
742
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
719
743
|
|
|
720
744
|
const {
|
|
721
745
|
publicInputs,
|
|
@@ -757,17 +781,17 @@ export class PXE {
|
|
|
757
781
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
758
782
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
759
783
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
760
|
-
const
|
|
761
|
-
if (
|
|
784
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
785
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
762
786
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
763
787
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
764
788
|
|
|
765
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
766
|
-
this.log.debug(`Stored used
|
|
767
|
-
|
|
789
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
790
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
791
|
+
taggingIndexRangesUsedInTheTx,
|
|
768
792
|
});
|
|
769
793
|
} else {
|
|
770
|
-
this.log.debug(`No
|
|
794
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
771
795
|
}
|
|
772
796
|
|
|
773
797
|
return txProvingResult;
|
|
@@ -785,7 +809,7 @@ export class PXE {
|
|
|
785
809
|
*/
|
|
786
810
|
public profileTx(
|
|
787
811
|
txRequest: TxExecutionRequest,
|
|
788
|
-
{ profileMode, skipProofGeneration = true }: ProfileTxOpts,
|
|
812
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
789
813
|
): Promise<TxProfileResult> {
|
|
790
814
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
791
815
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -808,12 +832,7 @@ export class PXE {
|
|
|
808
832
|
const syncTime = syncTimer.ms();
|
|
809
833
|
|
|
810
834
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
811
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
812
|
-
contractFunctionSimulator,
|
|
813
|
-
txRequest,
|
|
814
|
-
undefined,
|
|
815
|
-
jobId,
|
|
816
|
-
);
|
|
835
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
817
836
|
|
|
818
837
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
819
838
|
txRequest,
|
|
@@ -879,7 +898,14 @@ export class PXE {
|
|
|
879
898
|
*/
|
|
880
899
|
public simulateTx(
|
|
881
900
|
txRequest: TxExecutionRequest,
|
|
882
|
-
{
|
|
901
|
+
{
|
|
902
|
+
simulatePublic,
|
|
903
|
+
skipTxValidation = false,
|
|
904
|
+
skipFeeEnforcement = false,
|
|
905
|
+
skipKernels = true,
|
|
906
|
+
overrides,
|
|
907
|
+
scopes,
|
|
908
|
+
}: SimulateTxOpts,
|
|
883
909
|
): Promise<TxSimulationResult> {
|
|
884
910
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
885
911
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -903,13 +929,15 @@ export class PXE {
|
|
|
903
929
|
await this.blockStateSynchronizer.sync();
|
|
904
930
|
const syncTime = syncTimer.ms();
|
|
905
931
|
|
|
906
|
-
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
907
|
-
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
908
|
-
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
909
|
-
// or not.
|
|
910
932
|
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
911
933
|
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
912
|
-
|
|
934
|
+
|
|
935
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
936
|
+
throw new Error(
|
|
937
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
913
941
|
|
|
914
942
|
// Set overridden contracts on the sync service so it knows to skip syncing them
|
|
915
943
|
if (hasOverriddenContracts) {
|
|
@@ -926,6 +954,7 @@ export class PXE {
|
|
|
926
954
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
927
955
|
privateExecutionResult,
|
|
928
956
|
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
957
|
+
this.node,
|
|
929
958
|
));
|
|
930
959
|
} else {
|
|
931
960
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -944,6 +973,9 @@ export class PXE {
|
|
|
944
973
|
const publicSimulationTimer = new Timer();
|
|
945
974
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
946
975
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
976
|
+
if (publicOutput?.debugLogs?.length) {
|
|
977
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
978
|
+
}
|
|
947
979
|
}
|
|
948
980
|
|
|
949
981
|
let validationTime: number | undefined;
|
|
@@ -952,7 +984,8 @@ export class PXE {
|
|
|
952
984
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
953
985
|
validationTime = validationTimer.ms();
|
|
954
986
|
if (validationResult.result === 'invalid') {
|
|
955
|
-
|
|
987
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
988
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
956
989
|
}
|
|
957
990
|
}
|
|
958
991
|
|
|
@@ -1003,23 +1036,23 @@ export class PXE {
|
|
|
1003
1036
|
inspect(txRequest),
|
|
1004
1037
|
`simulatePublic=${simulatePublic}`,
|
|
1005
1038
|
`skipTxValidation=${skipTxValidation}`,
|
|
1006
|
-
`scopes=${scopes
|
|
1039
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1007
1040
|
);
|
|
1008
1041
|
}
|
|
1009
1042
|
});
|
|
1010
1043
|
}
|
|
1011
1044
|
|
|
1012
1045
|
/**
|
|
1013
|
-
*
|
|
1046
|
+
* Executes a contract utility function.
|
|
1014
1047
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
1015
1048
|
*/
|
|
1016
|
-
public
|
|
1049
|
+
public executeUtility(
|
|
1017
1050
|
call: FunctionCall,
|
|
1018
|
-
{ authwits, scopes }:
|
|
1019
|
-
): Promise<
|
|
1020
|
-
// We disable concurrent
|
|
1051
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
1052
|
+
): Promise<UtilityExecutionResult> {
|
|
1053
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1021
1054
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
1022
|
-
// delete the same read value, or reading values that another
|
|
1055
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
1023
1056
|
return this.#putInJobQueue(async jobId => {
|
|
1024
1057
|
try {
|
|
1025
1058
|
const totalTimer = new Timer();
|
|
@@ -1033,12 +1066,14 @@ export class PXE {
|
|
|
1033
1066
|
await this.contractSyncService.ensureContractSynced(
|
|
1034
1067
|
call.to,
|
|
1035
1068
|
call.selector,
|
|
1036
|
-
|
|
1069
|
+
(privateSyncCall, execScopes) =>
|
|
1070
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1037
1071
|
anchorBlockHeader,
|
|
1038
1072
|
jobId,
|
|
1073
|
+
scopes,
|
|
1039
1074
|
);
|
|
1040
1075
|
|
|
1041
|
-
const executionResult = await this.#
|
|
1076
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
1042
1077
|
contractFunctionSimulator,
|
|
1043
1078
|
call,
|
|
1044
1079
|
authwits ?? [],
|
|
@@ -1059,14 +1094,19 @@ export class PXE {
|
|
|
1059
1094
|
};
|
|
1060
1095
|
|
|
1061
1096
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
1062
|
-
return {
|
|
1097
|
+
return {
|
|
1098
|
+
result: executionResult,
|
|
1099
|
+
offchainEffects,
|
|
1100
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1101
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1102
|
+
};
|
|
1063
1103
|
} catch (err: any) {
|
|
1064
1104
|
const { to, name, args } = call;
|
|
1065
1105
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1066
1106
|
throw this.#contextualizeError(
|
|
1067
1107
|
err,
|
|
1068
|
-
`
|
|
1069
|
-
`scopes=${scopes
|
|
1108
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1109
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1070
1110
|
);
|
|
1071
1111
|
}
|
|
1072
1112
|
});
|
|
@@ -1102,10 +1142,11 @@ export class PXE {
|
|
|
1102
1142
|
await this.contractSyncService.ensureContractSynced(
|
|
1103
1143
|
filter.contractAddress,
|
|
1104
1144
|
null,
|
|
1105
|
-
async privateSyncCall =>
|
|
1106
|
-
await this.#
|
|
1145
|
+
async (privateSyncCall, execScopes) =>
|
|
1146
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1107
1147
|
anchorBlockHeader,
|
|
1108
1148
|
jobId,
|
|
1149
|
+
filter.scopes,
|
|
1109
1150
|
);
|
|
1110
1151
|
});
|
|
1111
1152
|
|
|
@@ -1120,9 +1161,10 @@ export class PXE {
|
|
|
1120
1161
|
}
|
|
1121
1162
|
|
|
1122
1163
|
/**
|
|
1123
|
-
* Stops the PXE's job queue.
|
|
1164
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1124
1165
|
*/
|
|
1125
|
-
public stop(): Promise<void> {
|
|
1126
|
-
|
|
1166
|
+
public async stop(): Promise<void> {
|
|
1167
|
+
await this.jobQueue.end();
|
|
1168
|
+
await this.db.close();
|
|
1127
1169
|
}
|
|
1128
1170
|
}
|