@aztec/pxe 0.0.1-commit.f2ce05ee → 0.0.1-commit.f504929
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 +175 -71
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +3 -3
- 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 +44 -44
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- 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 +132 -89
- package/dest/contract_function_simulator/oracle/private_execution.js +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +54 -55
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +98 -53
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +56 -40
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +67 -73
- 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/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 +9 -14
- 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 +60 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +73 -58
- 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/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 +5 -5
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +4 -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/index.d.ts +2 -2
- 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 +3 -6
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +4 -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 +14 -15
- 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 +323 -131
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
- 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 +43 -43
- package/src/contract_function_simulator/oracle/oracle.ts +135 -107
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -1
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +122 -129
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +107 -76
- 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/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 +17 -24
- 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 +138 -101
- package/src/storage/contract_store/contract_store.ts +170 -71
- 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 +8 -8
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/index.ts +1 -1
- 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 +4 -9
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +11 -20
- 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,6 +61,7 @@ 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';
|
|
@@ -86,6 +88,56 @@ export type PackedPrivateEvent = InTx & {
|
|
|
86
88
|
eventSelector: EventSelector;
|
|
87
89
|
};
|
|
88
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
|
+
|
|
89
141
|
/**
|
|
90
142
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
91
143
|
* manage private state of users.
|
|
@@ -93,6 +145,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
93
145
|
export class PXE {
|
|
94
146
|
private constructor(
|
|
95
147
|
private node: AztecNode,
|
|
148
|
+
private db: AztecAsyncKVStore,
|
|
96
149
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
97
150
|
private keyStore: KeyStore,
|
|
98
151
|
private contractStore: ContractStore,
|
|
@@ -122,15 +175,15 @@ export class PXE {
|
|
|
122
175
|
*
|
|
123
176
|
* @returns A promise that resolves PXE is ready to be used.
|
|
124
177
|
*/
|
|
125
|
-
public static async create(
|
|
126
|
-
node
|
|
127
|
-
store
|
|
128
|
-
proofCreator
|
|
129
|
-
simulator
|
|
130
|
-
protocolContractsProvider
|
|
131
|
-
config
|
|
132
|
-
loggerOrSuffix
|
|
133
|
-
) {
|
|
178
|
+
public static async create({
|
|
179
|
+
node,
|
|
180
|
+
store,
|
|
181
|
+
proofCreator,
|
|
182
|
+
simulator,
|
|
183
|
+
protocolContractsProvider,
|
|
184
|
+
config,
|
|
185
|
+
loggerOrSuffix,
|
|
186
|
+
}: PXECreateArgs) {
|
|
134
187
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
135
188
|
const bindings: LoggerBindings | undefined =
|
|
136
189
|
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
@@ -140,7 +193,9 @@ export class PXE {
|
|
|
140
193
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
141
194
|
: loggerOrSuffix;
|
|
142
195
|
|
|
143
|
-
const
|
|
196
|
+
const info = await node.getNodeInfo();
|
|
197
|
+
|
|
198
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
144
199
|
const addressStore = new AddressStore(store);
|
|
145
200
|
const privateEventStore = new PrivateEventStore(store);
|
|
146
201
|
const contractStore = new ContractStore(store);
|
|
@@ -186,6 +241,7 @@ export class PXE {
|
|
|
186
241
|
|
|
187
242
|
const pxe = new PXE(
|
|
188
243
|
node,
|
|
244
|
+
store,
|
|
189
245
|
synchronizer,
|
|
190
246
|
keyStore,
|
|
191
247
|
contractStore,
|
|
@@ -211,13 +267,12 @@ export class PXE {
|
|
|
211
267
|
debugUtils.setPXEHelpers(
|
|
212
268
|
pxe.#putInJobQueue.bind(pxe),
|
|
213
269
|
pxe.#getSimulatorForTx.bind(pxe),
|
|
214
|
-
pxe.#
|
|
270
|
+
pxe.#executeUtility.bind(pxe),
|
|
215
271
|
);
|
|
216
272
|
|
|
217
273
|
pxe.jobQueue.start();
|
|
218
274
|
|
|
219
275
|
await pxe.#registerProtocolContracts();
|
|
220
|
-
const info = await node.getNodeInfo();
|
|
221
276
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
222
277
|
return pxe;
|
|
223
278
|
}
|
|
@@ -227,20 +282,20 @@ export class PXE {
|
|
|
227
282
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
228
283
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
229
284
|
|
|
230
|
-
return new ContractFunctionSimulator(
|
|
231
|
-
proxyContractStore,
|
|
232
|
-
this.noteStore,
|
|
233
|
-
this.keyStore,
|
|
234
|
-
this.addressStore,
|
|
235
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
236
|
-
this.senderTaggingStore,
|
|
237
|
-
this.recipientTaggingStore,
|
|
238
|
-
this.senderAddressBookStore,
|
|
239
|
-
this.capsuleStore,
|
|
240
|
-
this.privateEventStore,
|
|
241
|
-
this.simulator,
|
|
242
|
-
this.contractSyncService,
|
|
243
|
-
);
|
|
285
|
+
return new ContractFunctionSimulator({
|
|
286
|
+
contractStore: proxyContractStore,
|
|
287
|
+
noteStore: this.noteStore,
|
|
288
|
+
keyStore: this.keyStore,
|
|
289
|
+
addressStore: this.addressStore,
|
|
290
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
291
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
292
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
293
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
294
|
+
capsuleStore: this.capsuleStore,
|
|
295
|
+
privateEventStore: this.privateEventStore,
|
|
296
|
+
simulator: this.simulator,
|
|
297
|
+
contractSyncService: this.contractSyncService,
|
|
298
|
+
});
|
|
244
299
|
}
|
|
245
300
|
|
|
246
301
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -292,9 +347,8 @@ export class PXE {
|
|
|
292
347
|
async #registerProtocolContracts() {
|
|
293
348
|
const registered: Record<string, string> = {};
|
|
294
349
|
for (const name of protocolContractNames) {
|
|
295
|
-
const { address,
|
|
296
|
-
|
|
297
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
350
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
351
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
298
352
|
await this.contractStore.addContractInstance(instance);
|
|
299
353
|
registered[name] = address.toString();
|
|
300
354
|
}
|
|
@@ -306,7 +360,7 @@ export class PXE {
|
|
|
306
360
|
async #executePrivate(
|
|
307
361
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
308
362
|
txRequest: TxExecutionRequest,
|
|
309
|
-
scopes:
|
|
363
|
+
scopes: AccessScopes,
|
|
310
364
|
jobId: string,
|
|
311
365
|
): Promise<PrivateExecutionResult> {
|
|
312
366
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -317,23 +371,20 @@ export class PXE {
|
|
|
317
371
|
await this.contractSyncService.ensureContractSynced(
|
|
318
372
|
contractAddress,
|
|
319
373
|
functionSelector,
|
|
320
|
-
|
|
374
|
+
(privateSyncCall, execScopes) =>
|
|
375
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
321
376
|
anchorBlockHeader,
|
|
322
377
|
jobId,
|
|
378
|
+
scopes,
|
|
323
379
|
);
|
|
324
380
|
|
|
325
|
-
const result = await contractFunctionSimulator.run(
|
|
326
|
-
txRequest,
|
|
381
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
327
382
|
contractAddress,
|
|
328
|
-
functionSelector,
|
|
329
|
-
undefined,
|
|
383
|
+
selector: functionSelector,
|
|
330
384
|
anchorBlockHeader,
|
|
331
|
-
// The sender for tags is set by contracts, typically by an account
|
|
332
|
-
// contract entrypoint
|
|
333
|
-
undefined, // senderForTags
|
|
334
385
|
scopes,
|
|
335
386
|
jobId,
|
|
336
|
-
);
|
|
387
|
+
});
|
|
337
388
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
338
389
|
return result;
|
|
339
390
|
} catch (err) {
|
|
@@ -345,20 +396,20 @@ export class PXE {
|
|
|
345
396
|
}
|
|
346
397
|
|
|
347
398
|
/**
|
|
348
|
-
*
|
|
399
|
+
* Execute a utility function call on the given contract.
|
|
349
400
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
350
401
|
* @param call - The function call to execute.
|
|
351
402
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
352
403
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
353
404
|
* accounts if not specified.
|
|
354
405
|
* @param jobId - The job ID for staged writes.
|
|
355
|
-
* @returns The
|
|
406
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
356
407
|
*/
|
|
357
|
-
async #
|
|
408
|
+
async #executeUtility(
|
|
358
409
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
359
410
|
call: FunctionCall,
|
|
360
411
|
authWitnesses: AuthWitness[] | undefined,
|
|
361
|
-
scopes:
|
|
412
|
+
scopes: AccessScopes,
|
|
362
413
|
jobId: string,
|
|
363
414
|
) {
|
|
364
415
|
try {
|
|
@@ -552,8 +603,7 @@ export class PXE {
|
|
|
552
603
|
* @param artifact - The build artifact for the contract class.
|
|
553
604
|
*/
|
|
554
605
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
555
|
-
const
|
|
556
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
606
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
557
607
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
558
608
|
}
|
|
559
609
|
|
|
@@ -572,17 +622,17 @@ export class PXE {
|
|
|
572
622
|
if (artifact) {
|
|
573
623
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
574
624
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
575
|
-
|
|
576
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
625
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
577
626
|
throw new Error(
|
|
578
|
-
`Artifact does not match expected class id (computed ${
|
|
627
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
579
628
|
);
|
|
580
629
|
}
|
|
581
630
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
582
631
|
if (!computedAddress.equals(instance.address)) {
|
|
583
632
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
584
633
|
}
|
|
585
|
-
|
|
634
|
+
|
|
635
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
586
636
|
|
|
587
637
|
const publicFunctionSignatures = artifact.functions
|
|
588
638
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -631,15 +681,16 @@ export class PXE {
|
|
|
631
681
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
632
682
|
}
|
|
633
683
|
|
|
634
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
635
|
-
|
|
636
684
|
const publicFunctionSignatures = artifact.functions
|
|
637
685
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
638
686
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
639
687
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
640
688
|
|
|
641
689
|
currentInstance.currentContractClassId = contractClass.id;
|
|
642
|
-
await
|
|
690
|
+
await Promise.all([
|
|
691
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
692
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
693
|
+
]);
|
|
643
694
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
644
695
|
});
|
|
645
696
|
}
|
|
@@ -657,11 +708,12 @@ export class PXE {
|
|
|
657
708
|
* (where validators prove the public portion).
|
|
658
709
|
*
|
|
659
710
|
* @param txRequest - An authenticated tx request ready for proving
|
|
711
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
660
712
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
661
713
|
* @throws If contract code not found, or public simulation reverts.
|
|
662
714
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
663
715
|
*/
|
|
664
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
716
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
665
717
|
let privateExecutionResult: PrivateExecutionResult;
|
|
666
718
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
667
719
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -672,7 +724,7 @@ export class PXE {
|
|
|
672
724
|
await this.blockStateSynchronizer.sync();
|
|
673
725
|
const syncTime = syncTimer.ms();
|
|
674
726
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
675
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
727
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
676
728
|
|
|
677
729
|
const {
|
|
678
730
|
publicInputs,
|
|
@@ -736,17 +788,13 @@ export class PXE {
|
|
|
736
788
|
|
|
737
789
|
/**
|
|
738
790
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
739
|
-
*
|
|
740
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
741
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
742
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
791
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
743
792
|
* @returns A trace of the program execution with gate counts.
|
|
744
793
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
745
794
|
*/
|
|
746
795
|
public profileTx(
|
|
747
796
|
txRequest: TxExecutionRequest,
|
|
748
|
-
profileMode
|
|
749
|
-
skipProofGeneration: boolean = true,
|
|
797
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
750
798
|
): Promise<TxProfileResult> {
|
|
751
799
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
752
800
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -769,12 +817,7 @@ export class PXE {
|
|
|
769
817
|
const syncTime = syncTimer.ms();
|
|
770
818
|
|
|
771
819
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
772
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
773
|
-
contractFunctionSimulator,
|
|
774
|
-
txRequest,
|
|
775
|
-
undefined,
|
|
776
|
-
jobId,
|
|
777
|
-
);
|
|
820
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
778
821
|
|
|
779
822
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
780
823
|
txRequest,
|
|
@@ -831,12 +874,7 @@ export class PXE {
|
|
|
831
874
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
832
875
|
*
|
|
833
876
|
*
|
|
834
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
835
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
836
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
837
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
838
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
839
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
877
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
840
878
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
841
879
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
842
880
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -845,11 +883,7 @@ export class PXE {
|
|
|
845
883
|
*/
|
|
846
884
|
public simulateTx(
|
|
847
885
|
txRequest: TxExecutionRequest,
|
|
848
|
-
simulatePublic:
|
|
849
|
-
skipTxValidation: boolean = false,
|
|
850
|
-
skipFeeEnforcement: boolean = false,
|
|
851
|
-
overrides?: SimulationOverrides,
|
|
852
|
-
scopes?: AztecAddress[],
|
|
886
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
853
887
|
): Promise<TxSimulationResult> {
|
|
854
888
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
855
889
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -896,6 +930,7 @@ export class PXE {
|
|
|
896
930
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
897
931
|
privateExecutionResult,
|
|
898
932
|
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
933
|
+
this.node,
|
|
899
934
|
));
|
|
900
935
|
} else {
|
|
901
936
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -914,6 +949,9 @@ export class PXE {
|
|
|
914
949
|
const publicSimulationTimer = new Timer();
|
|
915
950
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
916
951
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
952
|
+
if (publicOutput?.debugLogs?.length) {
|
|
953
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
954
|
+
}
|
|
917
955
|
}
|
|
918
956
|
|
|
919
957
|
let validationTime: number | undefined;
|
|
@@ -922,7 +960,8 @@ export class PXE {
|
|
|
922
960
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
923
961
|
validationTime = validationTimer.ms();
|
|
924
962
|
if (validationResult.result === 'invalid') {
|
|
925
|
-
|
|
963
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
964
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
926
965
|
}
|
|
927
966
|
}
|
|
928
967
|
|
|
@@ -973,29 +1012,23 @@ export class PXE {
|
|
|
973
1012
|
inspect(txRequest),
|
|
974
1013
|
`simulatePublic=${simulatePublic}`,
|
|
975
1014
|
`skipTxValidation=${skipTxValidation}`,
|
|
976
|
-
`scopes=${scopes
|
|
1015
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
977
1016
|
);
|
|
978
1017
|
}
|
|
979
1018
|
});
|
|
980
1019
|
}
|
|
981
1020
|
|
|
982
1021
|
/**
|
|
983
|
-
*
|
|
984
|
-
*
|
|
1022
|
+
* Executes a contract utility function.
|
|
985
1023
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
986
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
987
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
988
|
-
* default to all.
|
|
989
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
990
1024
|
*/
|
|
991
|
-
public
|
|
1025
|
+
public executeUtility(
|
|
992
1026
|
call: FunctionCall,
|
|
993
|
-
authwits
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1027
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
1028
|
+
): Promise<UtilityExecutionResult> {
|
|
1029
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
997
1030
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
998
|
-
// delete the same read value, or reading values that another
|
|
1031
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
999
1032
|
return this.#putInJobQueue(async jobId => {
|
|
1000
1033
|
try {
|
|
1001
1034
|
const totalTimer = new Timer();
|
|
@@ -1009,12 +1042,14 @@ export class PXE {
|
|
|
1009
1042
|
await this.contractSyncService.ensureContractSynced(
|
|
1010
1043
|
call.to,
|
|
1011
1044
|
call.selector,
|
|
1012
|
-
|
|
1045
|
+
(privateSyncCall, execScopes) =>
|
|
1046
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1013
1047
|
anchorBlockHeader,
|
|
1014
1048
|
jobId,
|
|
1049
|
+
scopes,
|
|
1015
1050
|
);
|
|
1016
1051
|
|
|
1017
|
-
const executionResult = await this.#
|
|
1052
|
+
const executionResult = await this.#executeUtility(
|
|
1018
1053
|
contractFunctionSimulator,
|
|
1019
1054
|
call,
|
|
1020
1055
|
authwits ?? [],
|
|
@@ -1041,8 +1076,8 @@ export class PXE {
|
|
|
1041
1076
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1042
1077
|
throw this.#contextualizeError(
|
|
1043
1078
|
err,
|
|
1044
|
-
`
|
|
1045
|
-
`scopes=${scopes
|
|
1079
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1080
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1046
1081
|
);
|
|
1047
1082
|
}
|
|
1048
1083
|
});
|
|
@@ -1078,10 +1113,11 @@ export class PXE {
|
|
|
1078
1113
|
await this.contractSyncService.ensureContractSynced(
|
|
1079
1114
|
filter.contractAddress,
|
|
1080
1115
|
null,
|
|
1081
|
-
async privateSyncCall =>
|
|
1082
|
-
await this.#
|
|
1116
|
+
async (privateSyncCall, execScopes) =>
|
|
1117
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1083
1118
|
anchorBlockHeader,
|
|
1084
1119
|
jobId,
|
|
1120
|
+
filter.scopes,
|
|
1085
1121
|
);
|
|
1086
1122
|
});
|
|
1087
1123
|
|
|
@@ -1096,9 +1132,10 @@ export class PXE {
|
|
|
1096
1132
|
}
|
|
1097
1133
|
|
|
1098
1134
|
/**
|
|
1099
|
-
* Stops the PXE's job queue.
|
|
1135
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1100
1136
|
*/
|
|
1101
|
-
public stop(): Promise<void> {
|
|
1102
|
-
|
|
1137
|
+
public async stop(): Promise<void> {
|
|
1138
|
+
await this.jobQueue.end();
|
|
1139
|
+
await this.db.close();
|
|
1103
1140
|
}
|
|
1104
1141
|
}
|