@aztec/pxe 0.0.1-commit.6d63667d → 0.0.1-commit.7b97ef96e
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/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +53 -29
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +171 -67
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -2
- 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 +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +3 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +35 -36
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +63 -18
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +31 -11
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +53 -35
- 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 +6 -7
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +4 -7
- 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 +9 -1
- 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 +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +9 -1
- package/dest/entrypoints/server/index.d.ts +3 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -0
- package/dest/entrypoints/server/utils.js +9 -1
- 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 +5 -10
- 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 +2 -2
- 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.js +4 -4
- package/dest/private_kernel/private_kernel_execution_prover.js +6 -6
- 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 +68 -23
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +74 -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 +145 -69
- 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 +6 -4
- 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/recipient_sync/load_private_logs_for_sender_recipient_pair.js +4 -4
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/package.json +16 -16
- package/src/access_scopes.ts +9 -0
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +320 -127
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
- package/src/contract_function_simulator/oracle/oracle.ts +3 -3
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +83 -93
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +98 -33
- 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 +12 -15
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/index.ts +2 -0
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/logs/log_service.ts +7 -19
- package/src/notes/note_service.ts +4 -3
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +2 -2
- 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 +7 -7
- package/src/private_kernel/private_kernel_execution_prover.ts +6 -6
- package/src/private_kernel/private_kernel_oracle.ts +7 -7
- package/src/pxe.ts +145 -98
- package/src/storage/contract_store/contract_store.ts +174 -75
- package/src/storage/note_store/note_store.ts +12 -5
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +4 -4
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- 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
|
@@ -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,6 +61,7 @@ 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';
|
|
64
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
62
65
|
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
63
66
|
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
64
67
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
@@ -85,6 +88,56 @@ export type PackedPrivateEvent = InTx & {
|
|
|
85
88
|
eventSelector: EventSelector;
|
|
86
89
|
};
|
|
87
90
|
|
|
91
|
+
/** Options for PXE.profileTx. */
|
|
92
|
+
export type ProfileTxOpts = {
|
|
93
|
+
/** The profiling mode to use. */
|
|
94
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
95
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
96
|
+
skipProofGeneration?: boolean;
|
|
97
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
98
|
+
scopes: AccessScopes;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** Options for PXE.simulateTx. */
|
|
102
|
+
export type SimulateTxOpts = {
|
|
103
|
+
/** Whether to simulate the public part of the transaction. */
|
|
104
|
+
simulatePublic: boolean;
|
|
105
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
106
|
+
skipTxValidation?: boolean;
|
|
107
|
+
/** If false, fees are enforced. */
|
|
108
|
+
skipFeeEnforcement?: boolean;
|
|
109
|
+
/** State overrides for the simulation, such as contract instances and artifacts. */
|
|
110
|
+
overrides?: SimulationOverrides;
|
|
111
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
112
|
+
scopes: AccessScopes;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** Options for PXE.executeUtility. */
|
|
116
|
+
export type ExecuteUtilityOpts = {
|
|
117
|
+
/** The authentication witnesses required for the function call. */
|
|
118
|
+
authwits?: AuthWitness[];
|
|
119
|
+
/** The accounts whose notes we can access in this call */
|
|
120
|
+
scopes: AccessScopes;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** Args for PXE.create. */
|
|
124
|
+
export type PXECreateArgs = {
|
|
125
|
+
/** The Aztec node to connect to. */
|
|
126
|
+
node: AztecNode;
|
|
127
|
+
/** The key-value store for persisting PXE state. */
|
|
128
|
+
store: AztecAsyncKVStore;
|
|
129
|
+
/** The prover for generating private kernel proofs. */
|
|
130
|
+
proofCreator: PrivateKernelProver;
|
|
131
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
132
|
+
simulator: CircuitSimulator;
|
|
133
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
134
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
135
|
+
/** PXE configuration options. */
|
|
136
|
+
config: PXEConfig;
|
|
137
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
138
|
+
loggerOrSuffix?: string | Logger;
|
|
139
|
+
};
|
|
140
|
+
|
|
88
141
|
/**
|
|
89
142
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
90
143
|
* manage private state of users.
|
|
@@ -121,15 +174,15 @@ export class PXE {
|
|
|
121
174
|
*
|
|
122
175
|
* @returns A promise that resolves PXE is ready to be used.
|
|
123
176
|
*/
|
|
124
|
-
public static async create(
|
|
125
|
-
node
|
|
126
|
-
store
|
|
127
|
-
proofCreator
|
|
128
|
-
simulator
|
|
129
|
-
protocolContractsProvider
|
|
130
|
-
config
|
|
131
|
-
loggerOrSuffix
|
|
132
|
-
) {
|
|
177
|
+
public static async create({
|
|
178
|
+
node,
|
|
179
|
+
store,
|
|
180
|
+
proofCreator,
|
|
181
|
+
simulator,
|
|
182
|
+
protocolContractsProvider,
|
|
183
|
+
config,
|
|
184
|
+
loggerOrSuffix,
|
|
185
|
+
}: PXECreateArgs) {
|
|
133
186
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
134
187
|
const bindings: LoggerBindings | undefined =
|
|
135
188
|
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
@@ -139,7 +192,9 @@ export class PXE {
|
|
|
139
192
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
140
193
|
: loggerOrSuffix;
|
|
141
194
|
|
|
142
|
-
const
|
|
195
|
+
const info = await node.getNodeInfo();
|
|
196
|
+
|
|
197
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
143
198
|
const addressStore = new AddressStore(store);
|
|
144
199
|
const privateEventStore = new PrivateEventStore(store);
|
|
145
200
|
const contractStore = new ContractStore(store);
|
|
@@ -210,13 +265,12 @@ export class PXE {
|
|
|
210
265
|
debugUtils.setPXEHelpers(
|
|
211
266
|
pxe.#putInJobQueue.bind(pxe),
|
|
212
267
|
pxe.#getSimulatorForTx.bind(pxe),
|
|
213
|
-
pxe.#
|
|
268
|
+
pxe.#executeUtility.bind(pxe),
|
|
214
269
|
);
|
|
215
270
|
|
|
216
271
|
pxe.jobQueue.start();
|
|
217
272
|
|
|
218
273
|
await pxe.#registerProtocolContracts();
|
|
219
|
-
const info = await node.getNodeInfo();
|
|
220
274
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
221
275
|
return pxe;
|
|
222
276
|
}
|
|
@@ -226,20 +280,20 @@ export class PXE {
|
|
|
226
280
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
227
281
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
228
282
|
|
|
229
|
-
return new ContractFunctionSimulator(
|
|
230
|
-
proxyContractStore,
|
|
231
|
-
this.noteStore,
|
|
232
|
-
this.keyStore,
|
|
233
|
-
this.addressStore,
|
|
234
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
235
|
-
this.senderTaggingStore,
|
|
236
|
-
this.recipientTaggingStore,
|
|
237
|
-
this.senderAddressBookStore,
|
|
238
|
-
this.capsuleStore,
|
|
239
|
-
this.privateEventStore,
|
|
240
|
-
this.simulator,
|
|
241
|
-
this.contractSyncService,
|
|
242
|
-
);
|
|
283
|
+
return new ContractFunctionSimulator({
|
|
284
|
+
contractStore: proxyContractStore,
|
|
285
|
+
noteStore: this.noteStore,
|
|
286
|
+
keyStore: this.keyStore,
|
|
287
|
+
addressStore: this.addressStore,
|
|
288
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
289
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
290
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
291
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
292
|
+
capsuleStore: this.capsuleStore,
|
|
293
|
+
privateEventStore: this.privateEventStore,
|
|
294
|
+
simulator: this.simulator,
|
|
295
|
+
contractSyncService: this.contractSyncService,
|
|
296
|
+
});
|
|
243
297
|
}
|
|
244
298
|
|
|
245
299
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -291,9 +345,8 @@ export class PXE {
|
|
|
291
345
|
async #registerProtocolContracts() {
|
|
292
346
|
const registered: Record<string, string> = {};
|
|
293
347
|
for (const name of protocolContractNames) {
|
|
294
|
-
const { address,
|
|
295
|
-
|
|
296
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
348
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
349
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
297
350
|
await this.contractStore.addContractInstance(instance);
|
|
298
351
|
registered[name] = address.toString();
|
|
299
352
|
}
|
|
@@ -305,7 +358,7 @@ export class PXE {
|
|
|
305
358
|
async #executePrivate(
|
|
306
359
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
307
360
|
txRequest: TxExecutionRequest,
|
|
308
|
-
scopes:
|
|
361
|
+
scopes: AccessScopes,
|
|
309
362
|
jobId: string,
|
|
310
363
|
): Promise<PrivateExecutionResult> {
|
|
311
364
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -316,23 +369,20 @@ export class PXE {
|
|
|
316
369
|
await this.contractSyncService.ensureContractSynced(
|
|
317
370
|
contractAddress,
|
|
318
371
|
functionSelector,
|
|
319
|
-
|
|
372
|
+
(privateSyncCall, execScopes) =>
|
|
373
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
320
374
|
anchorBlockHeader,
|
|
321
375
|
jobId,
|
|
376
|
+
scopes,
|
|
322
377
|
);
|
|
323
378
|
|
|
324
|
-
const result = await contractFunctionSimulator.run(
|
|
325
|
-
txRequest,
|
|
379
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
326
380
|
contractAddress,
|
|
327
|
-
functionSelector,
|
|
328
|
-
undefined,
|
|
381
|
+
selector: functionSelector,
|
|
329
382
|
anchorBlockHeader,
|
|
330
|
-
// The sender for tags is set by contracts, typically by an account
|
|
331
|
-
// contract entrypoint
|
|
332
|
-
undefined, // senderForTags
|
|
333
383
|
scopes,
|
|
334
384
|
jobId,
|
|
335
|
-
);
|
|
385
|
+
});
|
|
336
386
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
337
387
|
return result;
|
|
338
388
|
} catch (err) {
|
|
@@ -344,20 +394,20 @@ export class PXE {
|
|
|
344
394
|
}
|
|
345
395
|
|
|
346
396
|
/**
|
|
347
|
-
*
|
|
397
|
+
* Execute a utility function call on the given contract.
|
|
348
398
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
349
399
|
* @param call - The function call to execute.
|
|
350
400
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
351
401
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
352
402
|
* accounts if not specified.
|
|
353
403
|
* @param jobId - The job ID for staged writes.
|
|
354
|
-
* @returns The
|
|
404
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
355
405
|
*/
|
|
356
|
-
async #
|
|
406
|
+
async #executeUtility(
|
|
357
407
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
358
408
|
call: FunctionCall,
|
|
359
409
|
authWitnesses: AuthWitness[] | undefined,
|
|
360
|
-
scopes:
|
|
410
|
+
scopes: AccessScopes,
|
|
361
411
|
jobId: string,
|
|
362
412
|
) {
|
|
363
413
|
try {
|
|
@@ -430,6 +480,19 @@ export class PXE {
|
|
|
430
480
|
|
|
431
481
|
// Public API
|
|
432
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Returns the block header up to which the PXE has synced.
|
|
485
|
+
* @returns The synced block header
|
|
486
|
+
*/
|
|
487
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
488
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
493
|
+
* @param address - The contract address.
|
|
494
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
495
|
+
*/
|
|
433
496
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
434
497
|
return this.contractStore.getContractInstance(address);
|
|
435
498
|
}
|
|
@@ -538,8 +601,7 @@ export class PXE {
|
|
|
538
601
|
* @param artifact - The build artifact for the contract class.
|
|
539
602
|
*/
|
|
540
603
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
541
|
-
const
|
|
542
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
604
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
543
605
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
544
606
|
}
|
|
545
607
|
|
|
@@ -558,17 +620,17 @@ export class PXE {
|
|
|
558
620
|
if (artifact) {
|
|
559
621
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
560
622
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
561
|
-
|
|
562
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
623
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
563
624
|
throw new Error(
|
|
564
|
-
`Artifact does not match expected class id (computed ${
|
|
625
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
565
626
|
);
|
|
566
627
|
}
|
|
567
628
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
568
629
|
if (!computedAddress.equals(instance.address)) {
|
|
569
630
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
570
631
|
}
|
|
571
|
-
|
|
632
|
+
|
|
633
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
572
634
|
|
|
573
635
|
const publicFunctionSignatures = artifact.functions
|
|
574
636
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -617,15 +679,16 @@ export class PXE {
|
|
|
617
679
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
618
680
|
}
|
|
619
681
|
|
|
620
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
621
|
-
|
|
622
682
|
const publicFunctionSignatures = artifact.functions
|
|
623
683
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
624
684
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
625
685
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
626
686
|
|
|
627
687
|
currentInstance.currentContractClassId = contractClass.id;
|
|
628
|
-
await
|
|
688
|
+
await Promise.all([
|
|
689
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
690
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
691
|
+
]);
|
|
629
692
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
630
693
|
});
|
|
631
694
|
}
|
|
@@ -643,11 +706,12 @@ export class PXE {
|
|
|
643
706
|
* (where validators prove the public portion).
|
|
644
707
|
*
|
|
645
708
|
* @param txRequest - An authenticated tx request ready for proving
|
|
709
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
646
710
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
647
711
|
* @throws If contract code not found, or public simulation reverts.
|
|
648
712
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
649
713
|
*/
|
|
650
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
714
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
651
715
|
let privateExecutionResult: PrivateExecutionResult;
|
|
652
716
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
653
717
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -658,7 +722,7 @@ export class PXE {
|
|
|
658
722
|
await this.blockStateSynchronizer.sync();
|
|
659
723
|
const syncTime = syncTimer.ms();
|
|
660
724
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
661
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
725
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
662
726
|
|
|
663
727
|
const {
|
|
664
728
|
publicInputs,
|
|
@@ -722,17 +786,13 @@ export class PXE {
|
|
|
722
786
|
|
|
723
787
|
/**
|
|
724
788
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
725
|
-
*
|
|
726
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
727
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
728
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
789
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
729
790
|
* @returns A trace of the program execution with gate counts.
|
|
730
791
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
731
792
|
*/
|
|
732
793
|
public profileTx(
|
|
733
794
|
txRequest: TxExecutionRequest,
|
|
734
|
-
profileMode
|
|
735
|
-
skipProofGeneration: boolean = true,
|
|
795
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
736
796
|
): Promise<TxProfileResult> {
|
|
737
797
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
738
798
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -755,12 +815,7 @@ export class PXE {
|
|
|
755
815
|
const syncTime = syncTimer.ms();
|
|
756
816
|
|
|
757
817
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
758
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
759
|
-
contractFunctionSimulator,
|
|
760
|
-
txRequest,
|
|
761
|
-
undefined,
|
|
762
|
-
jobId,
|
|
763
|
-
);
|
|
818
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
764
819
|
|
|
765
820
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
766
821
|
txRequest,
|
|
@@ -817,12 +872,7 @@ export class PXE {
|
|
|
817
872
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
818
873
|
*
|
|
819
874
|
*
|
|
820
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
821
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
822
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
823
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
824
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
825
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
875
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
826
876
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
827
877
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
828
878
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -831,11 +881,7 @@ export class PXE {
|
|
|
831
881
|
*/
|
|
832
882
|
public simulateTx(
|
|
833
883
|
txRequest: TxExecutionRequest,
|
|
834
|
-
simulatePublic:
|
|
835
|
-
skipTxValidation: boolean = false,
|
|
836
|
-
skipFeeEnforcement: boolean = false,
|
|
837
|
-
overrides?: SimulationOverrides,
|
|
838
|
-
scopes?: AztecAddress[],
|
|
884
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
839
885
|
): Promise<TxSimulationResult> {
|
|
840
886
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
841
887
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -881,7 +927,8 @@ export class PXE {
|
|
|
881
927
|
if (skipKernels) {
|
|
882
928
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
883
929
|
privateExecutionResult,
|
|
884
|
-
this.contractStore,
|
|
930
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
931
|
+
this.node,
|
|
885
932
|
));
|
|
886
933
|
} else {
|
|
887
934
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -900,6 +947,9 @@ export class PXE {
|
|
|
900
947
|
const publicSimulationTimer = new Timer();
|
|
901
948
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
902
949
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
950
|
+
if (publicOutput?.debugLogs?.length) {
|
|
951
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
952
|
+
}
|
|
903
953
|
}
|
|
904
954
|
|
|
905
955
|
let validationTime: number | undefined;
|
|
@@ -959,29 +1009,23 @@ export class PXE {
|
|
|
959
1009
|
inspect(txRequest),
|
|
960
1010
|
`simulatePublic=${simulatePublic}`,
|
|
961
1011
|
`skipTxValidation=${skipTxValidation}`,
|
|
962
|
-
`scopes=${scopes
|
|
1012
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
963
1013
|
);
|
|
964
1014
|
}
|
|
965
1015
|
});
|
|
966
1016
|
}
|
|
967
1017
|
|
|
968
1018
|
/**
|
|
969
|
-
*
|
|
970
|
-
*
|
|
1019
|
+
* Executes a contract utility function.
|
|
971
1020
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
972
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
973
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
974
|
-
* default to all.
|
|
975
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
976
1021
|
*/
|
|
977
|
-
public
|
|
1022
|
+
public executeUtility(
|
|
978
1023
|
call: FunctionCall,
|
|
979
|
-
authwits
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1024
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
1025
|
+
): Promise<UtilityExecutionResult> {
|
|
1026
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
983
1027
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
984
|
-
// delete the same read value, or reading values that another
|
|
1028
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
985
1029
|
return this.#putInJobQueue(async jobId => {
|
|
986
1030
|
try {
|
|
987
1031
|
const totalTimer = new Timer();
|
|
@@ -995,12 +1039,14 @@ export class PXE {
|
|
|
995
1039
|
await this.contractSyncService.ensureContractSynced(
|
|
996
1040
|
call.to,
|
|
997
1041
|
call.selector,
|
|
998
|
-
|
|
1042
|
+
(privateSyncCall, execScopes) =>
|
|
1043
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
999
1044
|
anchorBlockHeader,
|
|
1000
1045
|
jobId,
|
|
1046
|
+
scopes,
|
|
1001
1047
|
);
|
|
1002
1048
|
|
|
1003
|
-
const executionResult = await this.#
|
|
1049
|
+
const executionResult = await this.#executeUtility(
|
|
1004
1050
|
contractFunctionSimulator,
|
|
1005
1051
|
call,
|
|
1006
1052
|
authwits ?? [],
|
|
@@ -1027,8 +1073,8 @@ export class PXE {
|
|
|
1027
1073
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1028
1074
|
throw this.#contextualizeError(
|
|
1029
1075
|
err,
|
|
1030
|
-
`
|
|
1031
|
-
`scopes=${scopes
|
|
1076
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1077
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1032
1078
|
);
|
|
1033
1079
|
}
|
|
1034
1080
|
});
|
|
@@ -1064,10 +1110,11 @@ export class PXE {
|
|
|
1064
1110
|
await this.contractSyncService.ensureContractSynced(
|
|
1065
1111
|
filter.contractAddress,
|
|
1066
1112
|
null,
|
|
1067
|
-
async privateSyncCall =>
|
|
1068
|
-
await this.#
|
|
1113
|
+
async (privateSyncCall, execScopes) =>
|
|
1114
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1069
1115
|
anchorBlockHeader,
|
|
1070
1116
|
jobId,
|
|
1117
|
+
filter.scopes,
|
|
1071
1118
|
);
|
|
1072
1119
|
});
|
|
1073
1120
|
|