@aztec/pxe 0.0.1-commit.6d63667d → 0.0.1-commit.72dcdcda8
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 +173 -69
- 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 +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 +71 -26
- 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 +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 +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.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 +70 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +84 -59
- 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/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 +322 -130
- 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 +1 -1
- package/src/contract_function_simulator/oracle/oracle.ts +3 -3
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +95 -102
- 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 +17 -24
- 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 +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 +153 -102
- package/src/storage/contract_store/contract_store.ts +174 -75
- package/src/storage/note_store/note_store.ts +12 -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
|
@@ -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.
|
|
@@ -92,6 +145,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
92
145
|
export class PXE {
|
|
93
146
|
private constructor(
|
|
94
147
|
private node: AztecNode,
|
|
148
|
+
private db: AztecAsyncKVStore,
|
|
95
149
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
96
150
|
private keyStore: KeyStore,
|
|
97
151
|
private contractStore: ContractStore,
|
|
@@ -121,15 +175,15 @@ export class PXE {
|
|
|
121
175
|
*
|
|
122
176
|
* @returns A promise that resolves PXE is ready to be used.
|
|
123
177
|
*/
|
|
124
|
-
public static async create(
|
|
125
|
-
node
|
|
126
|
-
store
|
|
127
|
-
proofCreator
|
|
128
|
-
simulator
|
|
129
|
-
protocolContractsProvider
|
|
130
|
-
config
|
|
131
|
-
loggerOrSuffix
|
|
132
|
-
) {
|
|
178
|
+
public static async create({
|
|
179
|
+
node,
|
|
180
|
+
store,
|
|
181
|
+
proofCreator,
|
|
182
|
+
simulator,
|
|
183
|
+
protocolContractsProvider,
|
|
184
|
+
config,
|
|
185
|
+
loggerOrSuffix,
|
|
186
|
+
}: PXECreateArgs) {
|
|
133
187
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
134
188
|
const bindings: LoggerBindings | undefined =
|
|
135
189
|
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
@@ -139,7 +193,9 @@ export class PXE {
|
|
|
139
193
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
140
194
|
: loggerOrSuffix;
|
|
141
195
|
|
|
142
|
-
const
|
|
196
|
+
const info = await node.getNodeInfo();
|
|
197
|
+
|
|
198
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
143
199
|
const addressStore = new AddressStore(store);
|
|
144
200
|
const privateEventStore = new PrivateEventStore(store);
|
|
145
201
|
const contractStore = new ContractStore(store);
|
|
@@ -185,6 +241,7 @@ export class PXE {
|
|
|
185
241
|
|
|
186
242
|
const pxe = new PXE(
|
|
187
243
|
node,
|
|
244
|
+
store,
|
|
188
245
|
synchronizer,
|
|
189
246
|
keyStore,
|
|
190
247
|
contractStore,
|
|
@@ -210,13 +267,12 @@ export class PXE {
|
|
|
210
267
|
debugUtils.setPXEHelpers(
|
|
211
268
|
pxe.#putInJobQueue.bind(pxe),
|
|
212
269
|
pxe.#getSimulatorForTx.bind(pxe),
|
|
213
|
-
pxe.#
|
|
270
|
+
pxe.#executeUtility.bind(pxe),
|
|
214
271
|
);
|
|
215
272
|
|
|
216
273
|
pxe.jobQueue.start();
|
|
217
274
|
|
|
218
275
|
await pxe.#registerProtocolContracts();
|
|
219
|
-
const info = await node.getNodeInfo();
|
|
220
276
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
221
277
|
return pxe;
|
|
222
278
|
}
|
|
@@ -226,20 +282,20 @@ export class PXE {
|
|
|
226
282
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
227
283
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
228
284
|
|
|
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
|
-
);
|
|
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
|
+
});
|
|
243
299
|
}
|
|
244
300
|
|
|
245
301
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -291,9 +347,8 @@ export class PXE {
|
|
|
291
347
|
async #registerProtocolContracts() {
|
|
292
348
|
const registered: Record<string, string> = {};
|
|
293
349
|
for (const name of protocolContractNames) {
|
|
294
|
-
const { address,
|
|
295
|
-
|
|
296
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
350
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
351
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
297
352
|
await this.contractStore.addContractInstance(instance);
|
|
298
353
|
registered[name] = address.toString();
|
|
299
354
|
}
|
|
@@ -305,7 +360,7 @@ export class PXE {
|
|
|
305
360
|
async #executePrivate(
|
|
306
361
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
307
362
|
txRequest: TxExecutionRequest,
|
|
308
|
-
scopes:
|
|
363
|
+
scopes: AccessScopes,
|
|
309
364
|
jobId: string,
|
|
310
365
|
): Promise<PrivateExecutionResult> {
|
|
311
366
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -316,23 +371,20 @@ export class PXE {
|
|
|
316
371
|
await this.contractSyncService.ensureContractSynced(
|
|
317
372
|
contractAddress,
|
|
318
373
|
functionSelector,
|
|
319
|
-
|
|
374
|
+
(privateSyncCall, execScopes) =>
|
|
375
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
320
376
|
anchorBlockHeader,
|
|
321
377
|
jobId,
|
|
378
|
+
scopes,
|
|
322
379
|
);
|
|
323
380
|
|
|
324
|
-
const result = await contractFunctionSimulator.run(
|
|
325
|
-
txRequest,
|
|
381
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
326
382
|
contractAddress,
|
|
327
|
-
functionSelector,
|
|
328
|
-
undefined,
|
|
383
|
+
selector: functionSelector,
|
|
329
384
|
anchorBlockHeader,
|
|
330
|
-
// The sender for tags is set by contracts, typically by an account
|
|
331
|
-
// contract entrypoint
|
|
332
|
-
undefined, // senderForTags
|
|
333
385
|
scopes,
|
|
334
386
|
jobId,
|
|
335
|
-
);
|
|
387
|
+
});
|
|
336
388
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
337
389
|
return result;
|
|
338
390
|
} catch (err) {
|
|
@@ -344,20 +396,20 @@ export class PXE {
|
|
|
344
396
|
}
|
|
345
397
|
|
|
346
398
|
/**
|
|
347
|
-
*
|
|
399
|
+
* Execute a utility function call on the given contract.
|
|
348
400
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
349
401
|
* @param call - The function call to execute.
|
|
350
402
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
351
403
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
352
404
|
* accounts if not specified.
|
|
353
405
|
* @param jobId - The job ID for staged writes.
|
|
354
|
-
* @returns The
|
|
406
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
355
407
|
*/
|
|
356
|
-
async #
|
|
408
|
+
async #executeUtility(
|
|
357
409
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
358
410
|
call: FunctionCall,
|
|
359
411
|
authWitnesses: AuthWitness[] | undefined,
|
|
360
|
-
scopes:
|
|
412
|
+
scopes: AccessScopes,
|
|
361
413
|
jobId: string,
|
|
362
414
|
) {
|
|
363
415
|
try {
|
|
@@ -430,6 +482,19 @@ export class PXE {
|
|
|
430
482
|
|
|
431
483
|
// Public API
|
|
432
484
|
|
|
485
|
+
/**
|
|
486
|
+
* Returns the block header up to which the PXE has synced.
|
|
487
|
+
* @returns The synced block header
|
|
488
|
+
*/
|
|
489
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
490
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
495
|
+
* @param address - The contract address.
|
|
496
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
497
|
+
*/
|
|
433
498
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
434
499
|
return this.contractStore.getContractInstance(address);
|
|
435
500
|
}
|
|
@@ -538,8 +603,7 @@ export class PXE {
|
|
|
538
603
|
* @param artifact - The build artifact for the contract class.
|
|
539
604
|
*/
|
|
540
605
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
541
|
-
const
|
|
542
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
606
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
543
607
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
544
608
|
}
|
|
545
609
|
|
|
@@ -558,17 +622,17 @@ export class PXE {
|
|
|
558
622
|
if (artifact) {
|
|
559
623
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
560
624
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
561
|
-
|
|
562
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
625
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
563
626
|
throw new Error(
|
|
564
|
-
`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})`,
|
|
565
628
|
);
|
|
566
629
|
}
|
|
567
630
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
568
631
|
if (!computedAddress.equals(instance.address)) {
|
|
569
632
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
570
633
|
}
|
|
571
|
-
|
|
634
|
+
|
|
635
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
572
636
|
|
|
573
637
|
const publicFunctionSignatures = artifact.functions
|
|
574
638
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -617,15 +681,16 @@ export class PXE {
|
|
|
617
681
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
618
682
|
}
|
|
619
683
|
|
|
620
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
621
|
-
|
|
622
684
|
const publicFunctionSignatures = artifact.functions
|
|
623
685
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
624
686
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
625
687
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
626
688
|
|
|
627
689
|
currentInstance.currentContractClassId = contractClass.id;
|
|
628
|
-
await
|
|
690
|
+
await Promise.all([
|
|
691
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
692
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
693
|
+
]);
|
|
629
694
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
630
695
|
});
|
|
631
696
|
}
|
|
@@ -643,11 +708,12 @@ export class PXE {
|
|
|
643
708
|
* (where validators prove the public portion).
|
|
644
709
|
*
|
|
645
710
|
* @param txRequest - An authenticated tx request ready for proving
|
|
711
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
646
712
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
647
713
|
* @throws If contract code not found, or public simulation reverts.
|
|
648
714
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
649
715
|
*/
|
|
650
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
716
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
651
717
|
let privateExecutionResult: PrivateExecutionResult;
|
|
652
718
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
653
719
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -658,7 +724,7 @@ export class PXE {
|
|
|
658
724
|
await this.blockStateSynchronizer.sync();
|
|
659
725
|
const syncTime = syncTimer.ms();
|
|
660
726
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
661
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
727
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
662
728
|
|
|
663
729
|
const {
|
|
664
730
|
publicInputs,
|
|
@@ -722,17 +788,13 @@ export class PXE {
|
|
|
722
788
|
|
|
723
789
|
/**
|
|
724
790
|
* 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.
|
|
791
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
729
792
|
* @returns A trace of the program execution with gate counts.
|
|
730
793
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
731
794
|
*/
|
|
732
795
|
public profileTx(
|
|
733
796
|
txRequest: TxExecutionRequest,
|
|
734
|
-
profileMode
|
|
735
|
-
skipProofGeneration: boolean = true,
|
|
797
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
736
798
|
): Promise<TxProfileResult> {
|
|
737
799
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
738
800
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -755,12 +817,7 @@ export class PXE {
|
|
|
755
817
|
const syncTime = syncTimer.ms();
|
|
756
818
|
|
|
757
819
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
758
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
759
|
-
contractFunctionSimulator,
|
|
760
|
-
txRequest,
|
|
761
|
-
undefined,
|
|
762
|
-
jobId,
|
|
763
|
-
);
|
|
820
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
764
821
|
|
|
765
822
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
766
823
|
txRequest,
|
|
@@ -817,12 +874,7 @@ export class PXE {
|
|
|
817
874
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
818
875
|
*
|
|
819
876
|
*
|
|
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.
|
|
877
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
826
878
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
827
879
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
828
880
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -831,11 +883,7 @@ export class PXE {
|
|
|
831
883
|
*/
|
|
832
884
|
public simulateTx(
|
|
833
885
|
txRequest: TxExecutionRequest,
|
|
834
|
-
simulatePublic:
|
|
835
|
-
skipTxValidation: boolean = false,
|
|
836
|
-
skipFeeEnforcement: boolean = false,
|
|
837
|
-
overrides?: SimulationOverrides,
|
|
838
|
-
scopes?: AztecAddress[],
|
|
886
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
839
887
|
): Promise<TxSimulationResult> {
|
|
840
888
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
841
889
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -881,7 +929,8 @@ export class PXE {
|
|
|
881
929
|
if (skipKernels) {
|
|
882
930
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
883
931
|
privateExecutionResult,
|
|
884
|
-
this.contractStore,
|
|
932
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
933
|
+
this.node,
|
|
885
934
|
));
|
|
886
935
|
} else {
|
|
887
936
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -900,6 +949,9 @@ export class PXE {
|
|
|
900
949
|
const publicSimulationTimer = new Timer();
|
|
901
950
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
902
951
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
952
|
+
if (publicOutput?.debugLogs?.length) {
|
|
953
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
954
|
+
}
|
|
903
955
|
}
|
|
904
956
|
|
|
905
957
|
let validationTime: number | undefined;
|
|
@@ -908,7 +960,8 @@ export class PXE {
|
|
|
908
960
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
909
961
|
validationTime = validationTimer.ms();
|
|
910
962
|
if (validationResult.result === 'invalid') {
|
|
911
|
-
|
|
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}`);
|
|
912
965
|
}
|
|
913
966
|
}
|
|
914
967
|
|
|
@@ -959,29 +1012,23 @@ export class PXE {
|
|
|
959
1012
|
inspect(txRequest),
|
|
960
1013
|
`simulatePublic=${simulatePublic}`,
|
|
961
1014
|
`skipTxValidation=${skipTxValidation}`,
|
|
962
|
-
`scopes=${scopes
|
|
1015
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
963
1016
|
);
|
|
964
1017
|
}
|
|
965
1018
|
});
|
|
966
1019
|
}
|
|
967
1020
|
|
|
968
1021
|
/**
|
|
969
|
-
*
|
|
970
|
-
*
|
|
1022
|
+
* Executes a contract utility function.
|
|
971
1023
|
* @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
1024
|
*/
|
|
977
|
-
public
|
|
1025
|
+
public executeUtility(
|
|
978
1026
|
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.
|
|
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.
|
|
983
1030
|
// 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
|
|
1031
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
985
1032
|
return this.#putInJobQueue(async jobId => {
|
|
986
1033
|
try {
|
|
987
1034
|
const totalTimer = new Timer();
|
|
@@ -995,12 +1042,14 @@ export class PXE {
|
|
|
995
1042
|
await this.contractSyncService.ensureContractSynced(
|
|
996
1043
|
call.to,
|
|
997
1044
|
call.selector,
|
|
998
|
-
|
|
1045
|
+
(privateSyncCall, execScopes) =>
|
|
1046
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
999
1047
|
anchorBlockHeader,
|
|
1000
1048
|
jobId,
|
|
1049
|
+
scopes,
|
|
1001
1050
|
);
|
|
1002
1051
|
|
|
1003
|
-
const executionResult = await this.#
|
|
1052
|
+
const executionResult = await this.#executeUtility(
|
|
1004
1053
|
contractFunctionSimulator,
|
|
1005
1054
|
call,
|
|
1006
1055
|
authwits ?? [],
|
|
@@ -1027,8 +1076,8 @@ export class PXE {
|
|
|
1027
1076
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1028
1077
|
throw this.#contextualizeError(
|
|
1029
1078
|
err,
|
|
1030
|
-
`
|
|
1031
|
-
`scopes=${scopes
|
|
1079
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1080
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1032
1081
|
);
|
|
1033
1082
|
}
|
|
1034
1083
|
});
|
|
@@ -1064,10 +1113,11 @@ export class PXE {
|
|
|
1064
1113
|
await this.contractSyncService.ensureContractSynced(
|
|
1065
1114
|
filter.contractAddress,
|
|
1066
1115
|
null,
|
|
1067
|
-
async privateSyncCall =>
|
|
1068
|
-
await this.#
|
|
1116
|
+
async (privateSyncCall, execScopes) =>
|
|
1117
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1069
1118
|
anchorBlockHeader,
|
|
1070
1119
|
jobId,
|
|
1120
|
+
filter.scopes,
|
|
1071
1121
|
);
|
|
1072
1122
|
});
|
|
1073
1123
|
|
|
@@ -1082,9 +1132,10 @@ export class PXE {
|
|
|
1082
1132
|
}
|
|
1083
1133
|
|
|
1084
1134
|
/**
|
|
1085
|
-
* Stops the PXE's job queue.
|
|
1135
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1086
1136
|
*/
|
|
1087
|
-
public stop(): Promise<void> {
|
|
1088
|
-
|
|
1137
|
+
public async stop(): Promise<void> {
|
|
1138
|
+
await this.jobQueue.end();
|
|
1139
|
+
await this.db.close();
|
|
1089
1140
|
}
|
|
1090
1141
|
}
|