@aztec/pxe 0.0.1-commit.3d8f95d → 0.0.1-commit.3fd054f6
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 +137 -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 +50 -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 +42 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +45 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +163 -94
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +24 -48
- 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 -71
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +56 -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 +115 -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 +8 -4
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +61 -29
- 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 +78 -53
- 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 +254 -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 +54 -54
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +135 -0
- package/src/contract_function_simulator/oracle/oracle.ts +176 -138
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +47 -90
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +157 -67
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +87 -35
- 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 +117 -71
- 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);
|
|
@@ -546,6 +569,9 @@ export class PXE {
|
|
|
546
569
|
|
|
547
570
|
if (wasAdded) {
|
|
548
571
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
572
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
573
|
+
// all contracts must re-sync to discover them.
|
|
574
|
+
this.contractSyncService.wipe();
|
|
549
575
|
} else {
|
|
550
576
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
551
577
|
}
|
|
@@ -595,8 +621,7 @@ export class PXE {
|
|
|
595
621
|
* @param artifact - The build artifact for the contract class.
|
|
596
622
|
*/
|
|
597
623
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
598
|
-
const
|
|
599
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
624
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
600
625
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
601
626
|
}
|
|
602
627
|
|
|
@@ -615,17 +640,17 @@ export class PXE {
|
|
|
615
640
|
if (artifact) {
|
|
616
641
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
617
642
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
618
|
-
|
|
619
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
643
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
620
644
|
throw new Error(
|
|
621
|
-
`Artifact does not match expected class id (computed ${
|
|
645
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
622
646
|
);
|
|
623
647
|
}
|
|
624
648
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
625
649
|
if (!computedAddress.equals(instance.address)) {
|
|
626
650
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
627
651
|
}
|
|
628
|
-
|
|
652
|
+
|
|
653
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
629
654
|
|
|
630
655
|
const publicFunctionSignatures = artifact.functions
|
|
631
656
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -674,15 +699,16 @@ export class PXE {
|
|
|
674
699
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
675
700
|
}
|
|
676
701
|
|
|
677
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
678
|
-
|
|
679
702
|
const publicFunctionSignatures = artifact.functions
|
|
680
703
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
681
704
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
682
705
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
683
706
|
|
|
684
707
|
currentInstance.currentContractClassId = contractClass.id;
|
|
685
|
-
await
|
|
708
|
+
await Promise.all([
|
|
709
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
710
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
711
|
+
]);
|
|
686
712
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
687
713
|
});
|
|
688
714
|
}
|
|
@@ -700,11 +726,12 @@ export class PXE {
|
|
|
700
726
|
* (where validators prove the public portion).
|
|
701
727
|
*
|
|
702
728
|
* @param txRequest - An authenticated tx request ready for proving
|
|
729
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
703
730
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
704
731
|
* @throws If contract code not found, or public simulation reverts.
|
|
705
732
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
706
733
|
*/
|
|
707
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
734
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
708
735
|
let privateExecutionResult: PrivateExecutionResult;
|
|
709
736
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
710
737
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -715,7 +742,7 @@ export class PXE {
|
|
|
715
742
|
await this.blockStateSynchronizer.sync();
|
|
716
743
|
const syncTime = syncTimer.ms();
|
|
717
744
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
718
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
745
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
719
746
|
|
|
720
747
|
const {
|
|
721
748
|
publicInputs,
|
|
@@ -757,17 +784,17 @@ export class PXE {
|
|
|
757
784
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
758
785
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
759
786
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
760
|
-
const
|
|
761
|
-
if (
|
|
787
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
788
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
762
789
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
763
790
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
764
791
|
|
|
765
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
766
|
-
this.log.debug(`Stored used
|
|
767
|
-
|
|
792
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
793
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
794
|
+
taggingIndexRangesUsedInTheTx,
|
|
768
795
|
});
|
|
769
796
|
} else {
|
|
770
|
-
this.log.debug(`No
|
|
797
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
771
798
|
}
|
|
772
799
|
|
|
773
800
|
return txProvingResult;
|
|
@@ -785,7 +812,7 @@ export class PXE {
|
|
|
785
812
|
*/
|
|
786
813
|
public profileTx(
|
|
787
814
|
txRequest: TxExecutionRequest,
|
|
788
|
-
{ profileMode, skipProofGeneration = true }: ProfileTxOpts,
|
|
815
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
789
816
|
): Promise<TxProfileResult> {
|
|
790
817
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
791
818
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -808,12 +835,7 @@ export class PXE {
|
|
|
808
835
|
const syncTime = syncTimer.ms();
|
|
809
836
|
|
|
810
837
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
811
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
812
|
-
contractFunctionSimulator,
|
|
813
|
-
txRequest,
|
|
814
|
-
undefined,
|
|
815
|
-
jobId,
|
|
816
|
-
);
|
|
838
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
817
839
|
|
|
818
840
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
819
841
|
txRequest,
|
|
@@ -879,7 +901,14 @@ export class PXE {
|
|
|
879
901
|
*/
|
|
880
902
|
public simulateTx(
|
|
881
903
|
txRequest: TxExecutionRequest,
|
|
882
|
-
{
|
|
904
|
+
{
|
|
905
|
+
simulatePublic,
|
|
906
|
+
skipTxValidation = false,
|
|
907
|
+
skipFeeEnforcement = false,
|
|
908
|
+
skipKernels = true,
|
|
909
|
+
overrides,
|
|
910
|
+
scopes,
|
|
911
|
+
}: SimulateTxOpts,
|
|
883
912
|
): Promise<TxSimulationResult> {
|
|
884
913
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
885
914
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -903,17 +932,20 @@ export class PXE {
|
|
|
903
932
|
await this.blockStateSynchronizer.sync();
|
|
904
933
|
const syncTime = syncTimer.ms();
|
|
905
934
|
|
|
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
935
|
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
911
936
|
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
912
|
-
const skipKernels = hasOverriddenContracts;
|
|
913
937
|
|
|
914
|
-
|
|
938
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
939
|
+
throw new Error(
|
|
940
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
944
|
+
|
|
915
945
|
if (hasOverriddenContracts) {
|
|
916
|
-
|
|
946
|
+
// Overridden contracts don't have a sync function, so calling sync on them would fail.
|
|
947
|
+
// We exclude them so the sync service skips them entirely.
|
|
948
|
+
this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
|
|
917
949
|
}
|
|
918
950
|
|
|
919
951
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
@@ -926,6 +958,7 @@ export class PXE {
|
|
|
926
958
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
927
959
|
privateExecutionResult,
|
|
928
960
|
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
961
|
+
this.node,
|
|
929
962
|
));
|
|
930
963
|
} else {
|
|
931
964
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -944,6 +977,9 @@ export class PXE {
|
|
|
944
977
|
const publicSimulationTimer = new Timer();
|
|
945
978
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
946
979
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
980
|
+
if (publicOutput?.debugLogs?.length) {
|
|
981
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
982
|
+
}
|
|
947
983
|
}
|
|
948
984
|
|
|
949
985
|
let validationTime: number | undefined;
|
|
@@ -952,7 +988,8 @@ export class PXE {
|
|
|
952
988
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
953
989
|
validationTime = validationTimer.ms();
|
|
954
990
|
if (validationResult.result === 'invalid') {
|
|
955
|
-
|
|
991
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
992
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
956
993
|
}
|
|
957
994
|
}
|
|
958
995
|
|
|
@@ -1003,23 +1040,23 @@ export class PXE {
|
|
|
1003
1040
|
inspect(txRequest),
|
|
1004
1041
|
`simulatePublic=${simulatePublic}`,
|
|
1005
1042
|
`skipTxValidation=${skipTxValidation}`,
|
|
1006
|
-
`scopes=${scopes
|
|
1043
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1007
1044
|
);
|
|
1008
1045
|
}
|
|
1009
1046
|
});
|
|
1010
1047
|
}
|
|
1011
1048
|
|
|
1012
1049
|
/**
|
|
1013
|
-
*
|
|
1050
|
+
* Executes a contract utility function.
|
|
1014
1051
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
1015
1052
|
*/
|
|
1016
|
-
public
|
|
1053
|
+
public executeUtility(
|
|
1017
1054
|
call: FunctionCall,
|
|
1018
|
-
{ authwits, scopes }:
|
|
1019
|
-
): Promise<
|
|
1020
|
-
// We disable concurrent
|
|
1055
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
1056
|
+
): Promise<UtilityExecutionResult> {
|
|
1057
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1021
1058
|
// 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
|
|
1059
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
1023
1060
|
return this.#putInJobQueue(async jobId => {
|
|
1024
1061
|
try {
|
|
1025
1062
|
const totalTimer = new Timer();
|
|
@@ -1033,12 +1070,14 @@ export class PXE {
|
|
|
1033
1070
|
await this.contractSyncService.ensureContractSynced(
|
|
1034
1071
|
call.to,
|
|
1035
1072
|
call.selector,
|
|
1036
|
-
|
|
1073
|
+
(privateSyncCall, execScopes) =>
|
|
1074
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1037
1075
|
anchorBlockHeader,
|
|
1038
1076
|
jobId,
|
|
1077
|
+
scopes,
|
|
1039
1078
|
);
|
|
1040
1079
|
|
|
1041
|
-
const executionResult = await this.#
|
|
1080
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
1042
1081
|
contractFunctionSimulator,
|
|
1043
1082
|
call,
|
|
1044
1083
|
authwits ?? [],
|
|
@@ -1059,14 +1098,19 @@ export class PXE {
|
|
|
1059
1098
|
};
|
|
1060
1099
|
|
|
1061
1100
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
1062
|
-
return {
|
|
1101
|
+
return {
|
|
1102
|
+
result: executionResult,
|
|
1103
|
+
offchainEffects,
|
|
1104
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1105
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1106
|
+
};
|
|
1063
1107
|
} catch (err: any) {
|
|
1064
1108
|
const { to, name, args } = call;
|
|
1065
1109
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1066
1110
|
throw this.#contextualizeError(
|
|
1067
1111
|
err,
|
|
1068
|
-
`
|
|
1069
|
-
`scopes=${scopes
|
|
1112
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1113
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1070
1114
|
);
|
|
1071
1115
|
}
|
|
1072
1116
|
});
|
|
@@ -1102,10 +1146,11 @@ export class PXE {
|
|
|
1102
1146
|
await this.contractSyncService.ensureContractSynced(
|
|
1103
1147
|
filter.contractAddress,
|
|
1104
1148
|
null,
|
|
1105
|
-
async privateSyncCall =>
|
|
1106
|
-
await this.#
|
|
1149
|
+
async (privateSyncCall, execScopes) =>
|
|
1150
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1107
1151
|
anchorBlockHeader,
|
|
1108
1152
|
jobId,
|
|
1153
|
+
filter.scopes,
|
|
1109
1154
|
);
|
|
1110
1155
|
});
|
|
1111
1156
|
|
|
@@ -1120,9 +1165,10 @@ export class PXE {
|
|
|
1120
1165
|
}
|
|
1121
1166
|
|
|
1122
1167
|
/**
|
|
1123
|
-
* Stops the PXE's job queue.
|
|
1168
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1124
1169
|
*/
|
|
1125
|
-
public stop(): Promise<void> {
|
|
1126
|
-
|
|
1170
|
+
public async stop(): Promise<void> {
|
|
1171
|
+
await this.jobQueue.end();
|
|
1172
|
+
await this.db.close();
|
|
1127
1173
|
}
|
|
1128
1174
|
}
|