@aztec/pxe 0.0.1-commit.e2b2873ed → 0.0.1-commit.e304674f1
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/block_synchronizer/block_synchronizer.d.ts +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +6 -0
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +14 -7
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +138 -45
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
- package/dest/contract_function_simulator/index.d.ts +2 -1
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -5
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -9
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -6
- 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 +5 -10
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -45
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +38 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +64 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +187 -97
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +23 -48
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +50 -81
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +66 -46
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +190 -99
- package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +9 -2
- package/dest/contract_logging.d.ts +27 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +38 -0
- package/dest/contract_sync/contract_sync_service.d.ts +7 -5
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +45 -38
- package/dest/contract_sync/helpers.d.ts +2 -2
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +9 -4
- package/dest/debug/pxe_debug_utils.d.ts +4 -3
- 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 +3 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +2 -2
- package/dest/entrypoints/client/lazy/index.d.ts +3 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +2 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +2 -2
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/pxe_creation_options.js +3 -1
- package/dest/entrypoints/server/index.d.ts +2 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -0
- package/dest/entrypoints/server/utils.d.ts +2 -2
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +2 -2
- package/dest/events/event_service.d.ts +3 -2
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +16 -4
- package/dest/logs/log_service.d.ts +6 -6
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +34 -32
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/notes/note_service.d.ts +4 -4
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +17 -7
- package/dest/notes_filter.d.ts +24 -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 +18 -14
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +74 -48
- package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +33 -28
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +140 -64
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +3 -2
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +2 -2
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
- package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/index.d.ts +3 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
- package/package.json +16 -16
- package/src/block_synchronizer/block_synchronizer.ts +6 -0
- package/src/config/index.ts +1 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +254 -65
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -8
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -9
- package/src/contract_function_simulator/oracle/interfaces.ts +63 -54
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
- package/src/contract_function_simulator/oracle/oracle.ts +223 -139
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +58 -102
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +320 -122
- package/src/contract_function_simulator/pick_notes.ts +9 -2
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +79 -54
- package/src/contract_sync/helpers.ts +8 -3
- package/src/debug/pxe_debug_utils.ts +8 -7
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +2 -3
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +2 -3
- package/src/entrypoints/pxe_creation_options.ts +7 -0
- package/src/entrypoints/server/index.ts +1 -0
- package/src/entrypoints/server/utils.ts +2 -3
- package/src/events/event_service.ts +17 -4
- package/src/logs/log_service.ts +68 -51
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +19 -8
- package/src/notes_filter.ts +24 -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 +104 -61
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +34 -26
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +170 -71
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +4 -3
- package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
- package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts
CHANGED
|
@@ -47,7 +47,7 @@ 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';
|
|
@@ -60,12 +60,14 @@ import {
|
|
|
60
60
|
generateSimulatedProvingResult,
|
|
61
61
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
62
62
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
63
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
63
64
|
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
64
65
|
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
65
66
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
66
67
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
67
68
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
68
69
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
70
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
69
71
|
import {
|
|
70
72
|
PrivateKernelExecutionProver,
|
|
71
73
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -93,7 +95,7 @@ export type ProfileTxOpts = {
|
|
|
93
95
|
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
94
96
|
skipProofGeneration?: boolean;
|
|
95
97
|
/** Addresses whose private state and keys are accessible during private execution. */
|
|
96
|
-
scopes
|
|
98
|
+
scopes: AztecAddress[];
|
|
97
99
|
};
|
|
98
100
|
|
|
99
101
|
/** Options for PXE.simulateTx. */
|
|
@@ -104,18 +106,20 @@ export type SimulateTxOpts = {
|
|
|
104
106
|
skipTxValidation?: boolean;
|
|
105
107
|
/** If false, fees are enforced. */
|
|
106
108
|
skipFeeEnforcement?: boolean;
|
|
107
|
-
/**
|
|
109
|
+
/** If true, kernel logic is emulated in TS for simulation */
|
|
110
|
+
skipKernels?: boolean;
|
|
111
|
+
/** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
|
|
108
112
|
overrides?: SimulationOverrides;
|
|
109
|
-
/** Addresses whose private state and keys are accessible during private execution
|
|
110
|
-
scopes
|
|
113
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
114
|
+
scopes: AztecAddress[];
|
|
111
115
|
};
|
|
112
116
|
|
|
113
|
-
/** Options for PXE.
|
|
114
|
-
export type
|
|
117
|
+
/** Options for PXE.executeUtility. */
|
|
118
|
+
export type ExecuteUtilityOpts = {
|
|
115
119
|
/** The authentication witnesses required for the function call. */
|
|
116
120
|
authwits?: AuthWitness[];
|
|
117
|
-
/** The accounts whose notes we can access in this call
|
|
118
|
-
scopes
|
|
121
|
+
/** The accounts whose notes we can access in this call */
|
|
122
|
+
scopes: AztecAddress[];
|
|
119
123
|
};
|
|
120
124
|
|
|
121
125
|
/** Args for PXE.create. */
|
|
@@ -143,6 +147,7 @@ export type PXECreateArgs = {
|
|
|
143
147
|
export class PXE {
|
|
144
148
|
private constructor(
|
|
145
149
|
private node: AztecNode,
|
|
150
|
+
private db: AztecAsyncKVStore,
|
|
146
151
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
147
152
|
private keyStore: KeyStore,
|
|
148
153
|
private contractStore: ContractStore,
|
|
@@ -155,6 +160,7 @@ export class PXE {
|
|
|
155
160
|
private addressStore: AddressStore,
|
|
156
161
|
private privateEventStore: PrivateEventStore,
|
|
157
162
|
private contractSyncService: ContractSyncService,
|
|
163
|
+
private messageContextService: MessageContextService,
|
|
158
164
|
private simulator: CircuitSimulator,
|
|
159
165
|
private proverEnabled: boolean,
|
|
160
166
|
private proofCreator: PrivateKernelProver,
|
|
@@ -210,6 +216,8 @@ export class PXE {
|
|
|
210
216
|
noteStore,
|
|
211
217
|
createLogger('pxe:contract_sync', bindings),
|
|
212
218
|
);
|
|
219
|
+
const messageContextService = new MessageContextService(node);
|
|
220
|
+
|
|
213
221
|
const synchronizer = new BlockSynchronizer(
|
|
214
222
|
node,
|
|
215
223
|
store,
|
|
@@ -238,6 +246,7 @@ export class PXE {
|
|
|
238
246
|
|
|
239
247
|
const pxe = new PXE(
|
|
240
248
|
node,
|
|
249
|
+
store,
|
|
241
250
|
synchronizer,
|
|
242
251
|
keyStore,
|
|
243
252
|
contractStore,
|
|
@@ -250,6 +259,7 @@ export class PXE {
|
|
|
250
259
|
addressStore,
|
|
251
260
|
privateEventStore,
|
|
252
261
|
contractSyncService,
|
|
262
|
+
messageContextService,
|
|
253
263
|
simulator,
|
|
254
264
|
proverEnabled,
|
|
255
265
|
proofCreator,
|
|
@@ -263,7 +273,7 @@ export class PXE {
|
|
|
263
273
|
debugUtils.setPXEHelpers(
|
|
264
274
|
pxe.#putInJobQueue.bind(pxe),
|
|
265
275
|
pxe.#getSimulatorForTx.bind(pxe),
|
|
266
|
-
pxe.#
|
|
276
|
+
pxe.#executeUtility.bind(pxe),
|
|
267
277
|
);
|
|
268
278
|
|
|
269
279
|
pxe.jobQueue.start();
|
|
@@ -291,6 +301,7 @@ export class PXE {
|
|
|
291
301
|
privateEventStore: this.privateEventStore,
|
|
292
302
|
simulator: this.simulator,
|
|
293
303
|
contractSyncService: this.contractSyncService,
|
|
304
|
+
messageContextService: this.messageContextService,
|
|
294
305
|
});
|
|
295
306
|
}
|
|
296
307
|
|
|
@@ -343,9 +354,8 @@ export class PXE {
|
|
|
343
354
|
async #registerProtocolContracts() {
|
|
344
355
|
const registered: Record<string, string> = {};
|
|
345
356
|
for (const name of protocolContractNames) {
|
|
346
|
-
const { address,
|
|
347
|
-
|
|
348
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
357
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
358
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
349
359
|
await this.contractStore.addContractInstance(instance);
|
|
350
360
|
registered[name] = address.toString();
|
|
351
361
|
}
|
|
@@ -357,7 +367,7 @@ export class PXE {
|
|
|
357
367
|
async #executePrivate(
|
|
358
368
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
359
369
|
txRequest: TxExecutionRequest,
|
|
360
|
-
scopes: AztecAddress[]
|
|
370
|
+
scopes: AztecAddress[],
|
|
361
371
|
jobId: string,
|
|
362
372
|
): Promise<PrivateExecutionResult> {
|
|
363
373
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -369,7 +379,7 @@ export class PXE {
|
|
|
369
379
|
contractAddress,
|
|
370
380
|
functionSelector,
|
|
371
381
|
(privateSyncCall, execScopes) =>
|
|
372
|
-
this.#
|
|
382
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
373
383
|
anchorBlockHeader,
|
|
374
384
|
jobId,
|
|
375
385
|
scopes,
|
|
@@ -393,25 +403,32 @@ export class PXE {
|
|
|
393
403
|
}
|
|
394
404
|
|
|
395
405
|
/**
|
|
396
|
-
*
|
|
406
|
+
* Execute a utility function call on the given contract.
|
|
397
407
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
398
408
|
* @param call - The function call to execute.
|
|
399
409
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
400
410
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
401
411
|
* accounts if not specified.
|
|
402
412
|
* @param jobId - The job ID for staged writes.
|
|
403
|
-
* @returns The
|
|
413
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
404
414
|
*/
|
|
405
|
-
async #
|
|
415
|
+
async #executeUtility(
|
|
406
416
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
407
417
|
call: FunctionCall,
|
|
408
418
|
authWitnesses: AuthWitness[] | undefined,
|
|
409
|
-
scopes: AztecAddress[]
|
|
419
|
+
scopes: AztecAddress[],
|
|
410
420
|
jobId: string,
|
|
411
421
|
) {
|
|
412
422
|
try {
|
|
413
423
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
414
|
-
|
|
424
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
425
|
+
call,
|
|
426
|
+
authWitnesses ?? [],
|
|
427
|
+
anchorBlockHeader,
|
|
428
|
+
scopes,
|
|
429
|
+
jobId,
|
|
430
|
+
);
|
|
431
|
+
return { result, offchainEffects };
|
|
415
432
|
} catch (err) {
|
|
416
433
|
if (err instanceof SimulationError) {
|
|
417
434
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -484,7 +501,9 @@ export class PXE {
|
|
|
484
501
|
* @returns The synced block header
|
|
485
502
|
*/
|
|
486
503
|
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
487
|
-
return this
|
|
504
|
+
return this.#putInJobQueue(() => {
|
|
505
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
506
|
+
});
|
|
488
507
|
}
|
|
489
508
|
|
|
490
509
|
/**
|
|
@@ -551,6 +570,9 @@ export class PXE {
|
|
|
551
570
|
|
|
552
571
|
if (wasAdded) {
|
|
553
572
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
573
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
574
|
+
// all contracts must re-sync to discover them.
|
|
575
|
+
this.contractSyncService.wipe();
|
|
554
576
|
} else {
|
|
555
577
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
556
578
|
}
|
|
@@ -600,8 +622,7 @@ export class PXE {
|
|
|
600
622
|
* @param artifact - The build artifact for the contract class.
|
|
601
623
|
*/
|
|
602
624
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
603
|
-
const
|
|
604
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
625
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
605
626
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
606
627
|
}
|
|
607
628
|
|
|
@@ -620,17 +641,17 @@ export class PXE {
|
|
|
620
641
|
if (artifact) {
|
|
621
642
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
622
643
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
623
|
-
|
|
624
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
644
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
625
645
|
throw new Error(
|
|
626
|
-
`Artifact does not match expected class id (computed ${
|
|
646
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
627
647
|
);
|
|
628
648
|
}
|
|
629
649
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
630
650
|
if (!computedAddress.equals(instance.address)) {
|
|
631
651
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
632
652
|
}
|
|
633
|
-
|
|
653
|
+
|
|
654
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
634
655
|
|
|
635
656
|
const publicFunctionSignatures = artifact.functions
|
|
636
657
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -679,15 +700,16 @@ export class PXE {
|
|
|
679
700
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
680
701
|
}
|
|
681
702
|
|
|
682
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
683
|
-
|
|
684
703
|
const publicFunctionSignatures = artifact.functions
|
|
685
704
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
686
705
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
687
706
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
688
707
|
|
|
689
708
|
currentInstance.currentContractClassId = contractClass.id;
|
|
690
|
-
await
|
|
709
|
+
await Promise.all([
|
|
710
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
711
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
712
|
+
]);
|
|
691
713
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
692
714
|
});
|
|
693
715
|
}
|
|
@@ -763,17 +785,17 @@ export class PXE {
|
|
|
763
785
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
764
786
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
765
787
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
766
|
-
const
|
|
767
|
-
if (
|
|
788
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
789
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
768
790
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
769
791
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
770
792
|
|
|
771
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
772
|
-
this.log.debug(`Stored used
|
|
773
|
-
|
|
793
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
794
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
795
|
+
taggingIndexRangesUsedInTheTx,
|
|
774
796
|
});
|
|
775
797
|
} else {
|
|
776
|
-
this.log.debug(`No
|
|
798
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
777
799
|
}
|
|
778
800
|
|
|
779
801
|
return txProvingResult;
|
|
@@ -880,7 +902,14 @@ export class PXE {
|
|
|
880
902
|
*/
|
|
881
903
|
public simulateTx(
|
|
882
904
|
txRequest: TxExecutionRequest,
|
|
883
|
-
{
|
|
905
|
+
{
|
|
906
|
+
simulatePublic,
|
|
907
|
+
skipTxValidation = false,
|
|
908
|
+
skipFeeEnforcement = false,
|
|
909
|
+
skipKernels = true,
|
|
910
|
+
overrides,
|
|
911
|
+
scopes,
|
|
912
|
+
}: SimulateTxOpts,
|
|
884
913
|
): Promise<TxSimulationResult> {
|
|
885
914
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
886
915
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -904,17 +933,20 @@ export class PXE {
|
|
|
904
933
|
await this.blockStateSynchronizer.sync();
|
|
905
934
|
const syncTime = syncTimer.ms();
|
|
906
935
|
|
|
907
|
-
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
908
|
-
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
909
|
-
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
910
|
-
// or not.
|
|
911
936
|
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
912
937
|
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
913
|
-
const skipKernels = hasOverriddenContracts;
|
|
914
938
|
|
|
915
|
-
|
|
939
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
940
|
+
throw new Error(
|
|
941
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
945
|
+
|
|
916
946
|
if (hasOverriddenContracts) {
|
|
917
|
-
|
|
947
|
+
// Overridden contracts don't have a sync function, so calling sync on them would fail.
|
|
948
|
+
// We exclude them so the sync service skips them entirely.
|
|
949
|
+
this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
|
|
918
950
|
}
|
|
919
951
|
|
|
920
952
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
@@ -927,6 +959,7 @@ export class PXE {
|
|
|
927
959
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
928
960
|
privateExecutionResult,
|
|
929
961
|
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
962
|
+
this.node,
|
|
930
963
|
));
|
|
931
964
|
} else {
|
|
932
965
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -945,6 +978,9 @@ export class PXE {
|
|
|
945
978
|
const publicSimulationTimer = new Timer();
|
|
946
979
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
947
980
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
981
|
+
if (publicOutput?.debugLogs?.length) {
|
|
982
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
983
|
+
}
|
|
948
984
|
}
|
|
949
985
|
|
|
950
986
|
let validationTime: number | undefined;
|
|
@@ -953,7 +989,8 @@ export class PXE {
|
|
|
953
989
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
954
990
|
validationTime = validationTimer.ms();
|
|
955
991
|
if (validationResult.result === 'invalid') {
|
|
956
|
-
|
|
992
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
993
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
957
994
|
}
|
|
958
995
|
}
|
|
959
996
|
|
|
@@ -1004,23 +1041,23 @@ export class PXE {
|
|
|
1004
1041
|
inspect(txRequest),
|
|
1005
1042
|
`simulatePublic=${simulatePublic}`,
|
|
1006
1043
|
`skipTxValidation=${skipTxValidation}`,
|
|
1007
|
-
`scopes=${scopes
|
|
1044
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
1008
1045
|
);
|
|
1009
1046
|
}
|
|
1010
1047
|
});
|
|
1011
1048
|
}
|
|
1012
1049
|
|
|
1013
1050
|
/**
|
|
1014
|
-
*
|
|
1051
|
+
* Executes a contract utility function.
|
|
1015
1052
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
1016
1053
|
*/
|
|
1017
|
-
public
|
|
1054
|
+
public executeUtility(
|
|
1018
1055
|
call: FunctionCall,
|
|
1019
|
-
{ authwits, scopes }:
|
|
1020
|
-
): Promise<
|
|
1021
|
-
// We disable concurrent
|
|
1056
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
|
|
1057
|
+
): Promise<UtilityExecutionResult> {
|
|
1058
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1022
1059
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
1023
|
-
// delete the same read value, or reading values that another
|
|
1060
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
1024
1061
|
return this.#putInJobQueue(async jobId => {
|
|
1025
1062
|
try {
|
|
1026
1063
|
const totalTimer = new Timer();
|
|
@@ -1035,13 +1072,13 @@ export class PXE {
|
|
|
1035
1072
|
call.to,
|
|
1036
1073
|
call.selector,
|
|
1037
1074
|
(privateSyncCall, execScopes) =>
|
|
1038
|
-
this.#
|
|
1075
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1039
1076
|
anchorBlockHeader,
|
|
1040
1077
|
jobId,
|
|
1041
1078
|
scopes,
|
|
1042
1079
|
);
|
|
1043
1080
|
|
|
1044
|
-
const executionResult = await this.#
|
|
1081
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
1045
1082
|
contractFunctionSimulator,
|
|
1046
1083
|
call,
|
|
1047
1084
|
authwits ?? [],
|
|
@@ -1062,14 +1099,19 @@ export class PXE {
|
|
|
1062
1099
|
};
|
|
1063
1100
|
|
|
1064
1101
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
1065
|
-
return {
|
|
1102
|
+
return {
|
|
1103
|
+
result: executionResult,
|
|
1104
|
+
offchainEffects,
|
|
1105
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1106
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1107
|
+
};
|
|
1066
1108
|
} catch (err: any) {
|
|
1067
1109
|
const { to, name, args } = call;
|
|
1068
1110
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1069
1111
|
throw this.#contextualizeError(
|
|
1070
1112
|
err,
|
|
1071
|
-
`
|
|
1072
|
-
`scopes=${scopes
|
|
1113
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1114
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
1073
1115
|
);
|
|
1074
1116
|
}
|
|
1075
1117
|
});
|
|
@@ -1106,7 +1148,7 @@ export class PXE {
|
|
|
1106
1148
|
filter.contractAddress,
|
|
1107
1149
|
null,
|
|
1108
1150
|
async (privateSyncCall, execScopes) =>
|
|
1109
|
-
await this.#
|
|
1151
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1110
1152
|
anchorBlockHeader,
|
|
1111
1153
|
jobId,
|
|
1112
1154
|
filter.scopes,
|
|
@@ -1124,9 +1166,10 @@ export class PXE {
|
|
|
1124
1166
|
}
|
|
1125
1167
|
|
|
1126
1168
|
/**
|
|
1127
|
-
* Stops the PXE's job queue.
|
|
1169
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1128
1170
|
*/
|
|
1129
|
-
public stop(): Promise<void> {
|
|
1130
|
-
|
|
1171
|
+
public async stop(): Promise<void> {
|
|
1172
|
+
await this.jobQueue.end();
|
|
1173
|
+
await this.db.close();
|
|
1131
1174
|
}
|
|
1132
1175
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { Capsule } from '@aztec/stdlib/tx';
|
|
4
|
+
|
|
5
|
+
import type { CapsuleStore } from './capsule_store.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a CapsuleStore with scope-based access control. Each operation asserts that the requested scope is in the
|
|
9
|
+
* allowed scopes list before delegating to the underlying store.
|
|
10
|
+
*/
|
|
11
|
+
export class CapsuleService {
|
|
12
|
+
constructor(
|
|
13
|
+
private readonly capsuleStore: CapsuleStore,
|
|
14
|
+
private readonly allowedScopes: AztecAddress[],
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress) {
|
|
18
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
19
|
+
this.capsuleStore.setCapsule(contractAddress, slot, capsule, jobId, scope);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async getCapsule(
|
|
23
|
+
contractAddress: AztecAddress,
|
|
24
|
+
slot: Fr,
|
|
25
|
+
jobId: string,
|
|
26
|
+
scope: AztecAddress,
|
|
27
|
+
transientCapsules?: Capsule[],
|
|
28
|
+
): Promise<Fr[] | null> {
|
|
29
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
30
|
+
|
|
31
|
+
// TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
|
|
32
|
+
const maybeTransientCapsule = transientCapsules?.find(
|
|
33
|
+
c =>
|
|
34
|
+
c.contractAddress.equals(contractAddress) &&
|
|
35
|
+
c.storageSlot.equals(slot) &&
|
|
36
|
+
(c.scope ?? AztecAddress.ZERO).equals(scope),
|
|
37
|
+
)?.data;
|
|
38
|
+
|
|
39
|
+
return maybeTransientCapsule ?? (await this.capsuleStore.getCapsule(contractAddress, slot, jobId, scope));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress) {
|
|
43
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
44
|
+
this.capsuleStore.deleteCapsule(contractAddress, slot, jobId, scope);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
copyCapsule(
|
|
48
|
+
contractAddress: AztecAddress,
|
|
49
|
+
srcSlot: Fr,
|
|
50
|
+
dstSlot: Fr,
|
|
51
|
+
numEntries: number,
|
|
52
|
+
jobId: string,
|
|
53
|
+
scope: AztecAddress,
|
|
54
|
+
): Promise<void> {
|
|
55
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
56
|
+
return this.capsuleStore.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
appendToCapsuleArray(
|
|
60
|
+
contractAddress: AztecAddress,
|
|
61
|
+
baseSlot: Fr,
|
|
62
|
+
content: Fr[][],
|
|
63
|
+
jobId: string,
|
|
64
|
+
scope: AztecAddress,
|
|
65
|
+
): Promise<void> {
|
|
66
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
67
|
+
return this.capsuleStore.appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[][]> {
|
|
71
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
72
|
+
return this.capsuleStore.readCapsuleArray(contractAddress, baseSlot, jobId, scope);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress) {
|
|
76
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
77
|
+
return this.capsuleStore.setCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function assertAllowedScope(scope: AztecAddress, allowedScopes: AztecAddress[]) {
|
|
82
|
+
if (scope.equals(AztecAddress.ZERO)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!allowedScopes.some((allowed: AztecAddress) => allowed.equals(scope))) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`Scope ${scope.toString()} is not in the allowed scopes list: [${allowedScopes.map((s: AztecAddress) => s.toString()).join(', ')}]. See https://docs.aztec.network/errors/10`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|