@aztec/pxe 0.0.1-commit.b1c78909e → 0.0.1-commit.b2a5d0dd1
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/bin/check_oracle_version.js +4 -4
- package/dest/block_synchronizer/block_synchronizer.d.ts +6 -2
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +19 -1
- package/dest/config/index.d.ts +1 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +7 -14
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +13 -5
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +35 -10
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
- package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
- 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 +17 -9
- 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 -4
- 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 +3 -6
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +3 -6
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +32 -19
- 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 +47 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +50 -18
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +186 -39
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +12 -23
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +30 -28
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +74 -42
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +252 -87
- 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 +20 -3
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
- package/dest/contract_logging.d.ts +9 -4
- package/dest/contract_logging.d.ts.map +1 -1
- package/dest/contract_logging.js +21 -6
- package/dest/contract_sync/contract_sync_service.d.ts +6 -5
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +62 -43
- package/dest/contract_sync/helpers.d.ts +2 -3
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +7 -2
- package/dest/debug/pxe_debug_utils.d.ts +3 -3
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.d.ts +1 -2
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +0 -1
- 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 +1 -2
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +0 -1
- 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 -3
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -2
- 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 +26 -5
- package/dest/events/private_event_filter_validator.d.ts +3 -2
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +15 -0
- package/dest/logs/log_service.d.ts +7 -8
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +27 -37
- 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 -5
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +14 -5
- package/dest/notes_filter.d.ts +2 -3
- package/dest/notes_filter.d.ts.map +1 -1
- package/dest/oracle_version.d.ts +4 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +20 -10
- 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 +4 -7
- package/dest/private_kernel/private_kernel_oracle.d.ts +5 -5
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +12 -15
- package/dest/pxe.d.ts +10 -7
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +58 -35
- package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
- 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 +36 -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 +1 -1
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +4 -2
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +1 -1
- 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/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +3 -0
- package/dest/storage/private_event_store/stored_private_event.js +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +26 -25
- 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/index.d.ts +2 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -2
- 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 +2 -16
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +10 -1
- 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 +2 -1
- 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 +24 -11
- package/package.json +16 -16
- package/src/bin/check_oracle_version.ts +4 -4
- package/src/block_synchronizer/block_synchronizer.ts +22 -2
- package/src/config/index.ts +2 -8
- package/src/contract_function_simulator/contract_function_simulator.ts +49 -14
- package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +16 -11
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -4
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -4
- package/src/contract_function_simulator/oracle/interfaces.ts +51 -17
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
- package/src/contract_function_simulator/oracle/oracle.ts +258 -34
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +40 -34
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +423 -114
- package/src/contract_function_simulator/pick_notes.ts +22 -3
- package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
- package/src/contract_logging.ts +18 -5
- package/src/contract_sync/contract_sync_service.ts +99 -75
- package/src/contract_sync/helpers.ts +4 -4
- package/src/debug/pxe_debug_utils.ts +3 -3
- package/src/entrypoints/client/bundle/index.ts +0 -1
- package/src/entrypoints/client/bundle/utils.ts +2 -3
- package/src/entrypoints/client/lazy/index.ts +0 -1
- 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 -2
- package/src/entrypoints/server/utils.ts +2 -3
- package/src/events/event_service.ts +30 -5
- package/src/events/private_event_filter_validator.ts +21 -1
- package/src/logs/log_service.ts +57 -78
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +18 -8
- package/src/notes_filter.ts +1 -3
- package/src/oracle_version.ts +20 -10
- package/src/private_kernel/private_kernel_execution_prover.ts +4 -9
- package/src/private_kernel/private_kernel_oracle.ts +14 -14
- package/src/pxe.ts +113 -42
- package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +44 -26
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +8 -6
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +2 -5
- package/src/storage/private_event_store/private_event_store.ts +4 -0
- package/src/storage/private_event_store/stored_private_event.ts +1 -1
- package/src/storage/tagging_store/sender_tagging_store.ts +182 -135
- package/src/tagging/index.ts +1 -1
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +5 -15
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +19 -1
- 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 +19 -9
- package/dest/access_scopes.d.ts +0 -9
- package/dest/access_scopes.d.ts.map +0 -1
- package/dest/access_scopes.js +0 -6
- package/src/access_scopes.ts +0 -9
package/src/pxe.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from '@aztec/stdlib/abi';
|
|
19
19
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
20
20
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
|
+
import type { L2TipsProvider } from '@aztec/stdlib/block';
|
|
21
22
|
import {
|
|
22
23
|
CompleteAddress,
|
|
23
24
|
type ContractInstanceWithAddress,
|
|
@@ -52,7 +53,6 @@ import {
|
|
|
52
53
|
|
|
53
54
|
import { inspect } from 'util';
|
|
54
55
|
|
|
55
|
-
import type { AccessScopes } from './access_scopes.js';
|
|
56
56
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
57
57
|
import type { PXEConfig } from './config/index.js';
|
|
58
58
|
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
@@ -68,6 +68,7 @@ import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
|
68
68
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
69
69
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
70
70
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
71
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
71
72
|
import {
|
|
72
73
|
PrivateKernelExecutionProver,
|
|
73
74
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -95,7 +96,7 @@ export type ProfileTxOpts = {
|
|
|
95
96
|
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
96
97
|
skipProofGeneration?: boolean;
|
|
97
98
|
/** Addresses whose private state and keys are accessible during private execution. */
|
|
98
|
-
scopes:
|
|
99
|
+
scopes: AztecAddress[];
|
|
99
100
|
};
|
|
100
101
|
|
|
101
102
|
/** Options for PXE.simulateTx. */
|
|
@@ -106,10 +107,12 @@ export type SimulateTxOpts = {
|
|
|
106
107
|
skipTxValidation?: boolean;
|
|
107
108
|
/** If false, fees are enforced. */
|
|
108
109
|
skipFeeEnforcement?: boolean;
|
|
109
|
-
/**
|
|
110
|
+
/** If true, kernel logic is emulated in TS for simulation */
|
|
111
|
+
skipKernels?: boolean;
|
|
112
|
+
/** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
|
|
110
113
|
overrides?: SimulationOverrides;
|
|
111
114
|
/** Addresses whose private state and keys are accessible during private execution */
|
|
112
|
-
scopes:
|
|
115
|
+
scopes: AztecAddress[];
|
|
113
116
|
};
|
|
114
117
|
|
|
115
118
|
/** Options for PXE.executeUtility. */
|
|
@@ -117,7 +120,7 @@ export type ExecuteUtilityOpts = {
|
|
|
117
120
|
/** The authentication witnesses required for the function call. */
|
|
118
121
|
authwits?: AuthWitness[];
|
|
119
122
|
/** The accounts whose notes we can access in this call */
|
|
120
|
-
scopes:
|
|
123
|
+
scopes: AztecAddress[];
|
|
121
124
|
};
|
|
122
125
|
|
|
123
126
|
/** Args for PXE.create. */
|
|
@@ -158,6 +161,8 @@ export class PXE {
|
|
|
158
161
|
private addressStore: AddressStore,
|
|
159
162
|
private privateEventStore: PrivateEventStore,
|
|
160
163
|
private contractSyncService: ContractSyncService,
|
|
164
|
+
private messageContextService: MessageContextService,
|
|
165
|
+
private l2TipsStore: L2TipsProvider,
|
|
161
166
|
private simulator: CircuitSimulator,
|
|
162
167
|
private proverEnabled: boolean,
|
|
163
168
|
private proofCreator: PrivateKernelProver,
|
|
@@ -213,6 +218,8 @@ export class PXE {
|
|
|
213
218
|
noteStore,
|
|
214
219
|
createLogger('pxe:contract_sync', bindings),
|
|
215
220
|
);
|
|
221
|
+
const messageContextService = new MessageContextService(node);
|
|
222
|
+
|
|
216
223
|
const synchronizer = new BlockSynchronizer(
|
|
217
224
|
node,
|
|
218
225
|
store,
|
|
@@ -254,6 +261,8 @@ export class PXE {
|
|
|
254
261
|
addressStore,
|
|
255
262
|
privateEventStore,
|
|
256
263
|
contractSyncService,
|
|
264
|
+
messageContextService,
|
|
265
|
+
tipsStore,
|
|
257
266
|
simulator,
|
|
258
267
|
proverEnabled,
|
|
259
268
|
proofCreator,
|
|
@@ -288,6 +297,7 @@ export class PXE {
|
|
|
288
297
|
keyStore: this.keyStore,
|
|
289
298
|
addressStore: this.addressStore,
|
|
290
299
|
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
300
|
+
l2TipsStore: this.l2TipsStore,
|
|
291
301
|
senderTaggingStore: this.senderTaggingStore,
|
|
292
302
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
293
303
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
@@ -295,6 +305,7 @@ export class PXE {
|
|
|
295
305
|
privateEventStore: this.privateEventStore,
|
|
296
306
|
simulator: this.simulator,
|
|
297
307
|
contractSyncService: this.contractSyncService,
|
|
308
|
+
messageContextService: this.messageContextService,
|
|
298
309
|
});
|
|
299
310
|
}
|
|
300
311
|
|
|
@@ -360,14 +371,13 @@ export class PXE {
|
|
|
360
371
|
async #executePrivate(
|
|
361
372
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
362
373
|
txRequest: TxExecutionRequest,
|
|
363
|
-
|
|
374
|
+
anchorBlockHeader: BlockHeader,
|
|
375
|
+
scopes: AztecAddress[],
|
|
364
376
|
jobId: string,
|
|
365
377
|
): Promise<PrivateExecutionResult> {
|
|
366
378
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
367
379
|
|
|
368
380
|
try {
|
|
369
|
-
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
370
|
-
|
|
371
381
|
await this.contractSyncService.ensureContractSynced(
|
|
372
382
|
contractAddress,
|
|
373
383
|
functionSelector,
|
|
@@ -409,12 +419,19 @@ export class PXE {
|
|
|
409
419
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
410
420
|
call: FunctionCall,
|
|
411
421
|
authWitnesses: AuthWitness[] | undefined,
|
|
412
|
-
scopes:
|
|
422
|
+
scopes: AztecAddress[],
|
|
413
423
|
jobId: string,
|
|
414
424
|
) {
|
|
415
425
|
try {
|
|
416
426
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
417
|
-
|
|
427
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
428
|
+
call,
|
|
429
|
+
authWitnesses ?? [],
|
|
430
|
+
anchorBlockHeader,
|
|
431
|
+
scopes,
|
|
432
|
+
jobId,
|
|
433
|
+
);
|
|
434
|
+
return { result, offchainEffects };
|
|
418
435
|
} catch (err) {
|
|
419
436
|
if (err instanceof SimulationError) {
|
|
420
437
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -465,11 +482,10 @@ export class PXE {
|
|
|
465
482
|
txExecutionRequest: TxExecutionRequest,
|
|
466
483
|
proofCreator: PrivateKernelProver,
|
|
467
484
|
privateExecutionResult: PrivateExecutionResult,
|
|
485
|
+
anchorBlockHeader: BlockHeader,
|
|
468
486
|
config: PrivateKernelExecutionProverConfig,
|
|
469
487
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
470
|
-
const
|
|
471
|
-
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
472
|
-
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
488
|
+
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
|
|
473
489
|
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
474
490
|
kernelOracle,
|
|
475
491
|
proofCreator,
|
|
@@ -487,7 +503,9 @@ export class PXE {
|
|
|
487
503
|
* @returns The synced block header
|
|
488
504
|
*/
|
|
489
505
|
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
490
|
-
return this
|
|
506
|
+
return this.#putInJobQueue(() => {
|
|
507
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
508
|
+
});
|
|
491
509
|
}
|
|
492
510
|
|
|
493
511
|
/**
|
|
@@ -544,6 +562,12 @@ export class PXE {
|
|
|
544
562
|
* TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
|
|
545
563
|
*/
|
|
546
564
|
public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
|
|
565
|
+
if (!(await sender.isValid())) {
|
|
566
|
+
throw new Error(
|
|
567
|
+
`Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
|
|
547
571
|
const accounts = await this.keyStore.getAccounts();
|
|
548
572
|
if (accounts.includes(sender)) {
|
|
549
573
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
@@ -554,6 +578,9 @@ export class PXE {
|
|
|
554
578
|
|
|
555
579
|
if (wasAdded) {
|
|
556
580
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
581
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
582
|
+
// all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
|
|
583
|
+
await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
|
|
557
584
|
} else {
|
|
558
585
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
559
586
|
}
|
|
@@ -722,16 +749,23 @@ export class PXE {
|
|
|
722
749
|
try {
|
|
723
750
|
const syncTimer = new Timer();
|
|
724
751
|
await this.blockStateSynchronizer.sync();
|
|
752
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
725
753
|
const syncTime = syncTimer.ms();
|
|
726
754
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
727
|
-
privateExecutionResult = await this.#executePrivate(
|
|
755
|
+
privateExecutionResult = await this.#executePrivate(
|
|
756
|
+
contractFunctionSimulator,
|
|
757
|
+
txRequest,
|
|
758
|
+
anchorBlockHeader,
|
|
759
|
+
scopes,
|
|
760
|
+
jobId,
|
|
761
|
+
);
|
|
728
762
|
|
|
729
763
|
const {
|
|
730
764
|
publicInputs,
|
|
731
765
|
chonkProof,
|
|
732
766
|
executionSteps,
|
|
733
767
|
timings: { proving } = {},
|
|
734
|
-
} = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
768
|
+
} = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
|
|
735
769
|
simulate: false,
|
|
736
770
|
skipFeeEnforcement: false,
|
|
737
771
|
profileMode: 'none',
|
|
@@ -766,17 +800,17 @@ export class PXE {
|
|
|
766
800
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
767
801
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
768
802
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
769
|
-
const
|
|
770
|
-
if (
|
|
803
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
804
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
771
805
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
772
806
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
773
807
|
|
|
774
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
775
|
-
this.log.debug(`Stored used
|
|
776
|
-
|
|
808
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
809
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
810
|
+
taggingIndexRangesUsedInTheTx,
|
|
777
811
|
});
|
|
778
812
|
} else {
|
|
779
|
-
this.log.debug(`No
|
|
813
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
780
814
|
}
|
|
781
815
|
|
|
782
816
|
return txProvingResult;
|
|
@@ -814,15 +848,23 @@ export class PXE {
|
|
|
814
848
|
);
|
|
815
849
|
const syncTimer = new Timer();
|
|
816
850
|
await this.blockStateSynchronizer.sync();
|
|
851
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
817
852
|
const syncTime = syncTimer.ms();
|
|
818
853
|
|
|
819
854
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
820
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
855
|
+
const privateExecutionResult = await this.#executePrivate(
|
|
856
|
+
contractFunctionSimulator,
|
|
857
|
+
txRequest,
|
|
858
|
+
anchorBlockHeader,
|
|
859
|
+
scopes,
|
|
860
|
+
jobId,
|
|
861
|
+
);
|
|
821
862
|
|
|
822
863
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
823
864
|
txRequest,
|
|
824
865
|
this.proofCreator,
|
|
825
866
|
privateExecutionResult,
|
|
867
|
+
anchorBlockHeader,
|
|
826
868
|
{
|
|
827
869
|
simulate: skipProofGeneration,
|
|
828
870
|
skipFeeEnforcement: false,
|
|
@@ -883,7 +925,14 @@ export class PXE {
|
|
|
883
925
|
*/
|
|
884
926
|
public simulateTx(
|
|
885
927
|
txRequest: TxExecutionRequest,
|
|
886
|
-
{
|
|
928
|
+
{
|
|
929
|
+
simulatePublic,
|
|
930
|
+
skipTxValidation = false,
|
|
931
|
+
skipFeeEnforcement = false,
|
|
932
|
+
skipKernels = true,
|
|
933
|
+
overrides,
|
|
934
|
+
scopes,
|
|
935
|
+
}: SimulateTxOpts,
|
|
887
936
|
): Promise<TxSimulationResult> {
|
|
888
937
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
889
938
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -905,23 +954,33 @@ export class PXE {
|
|
|
905
954
|
);
|
|
906
955
|
const syncTimer = new Timer();
|
|
907
956
|
await this.blockStateSynchronizer.sync();
|
|
957
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
908
958
|
const syncTime = syncTimer.ms();
|
|
909
959
|
|
|
910
|
-
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
911
|
-
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
912
|
-
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
913
|
-
// or not.
|
|
914
960
|
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
915
961
|
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
916
|
-
const skipKernels = hasOverriddenContracts;
|
|
917
962
|
|
|
918
|
-
|
|
963
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
964
|
+
throw new Error(
|
|
965
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
969
|
+
|
|
919
970
|
if (hasOverriddenContracts) {
|
|
920
|
-
|
|
971
|
+
// Overridden contracts don't have a sync function, so calling sync on them would fail.
|
|
972
|
+
// We exclude them so the sync service skips them entirely.
|
|
973
|
+
this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
|
|
921
974
|
}
|
|
922
975
|
|
|
923
976
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
924
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
977
|
+
const privateExecutionResult = await this.#executePrivate(
|
|
978
|
+
contractFunctionSimulator,
|
|
979
|
+
txRequest,
|
|
980
|
+
anchorBlockHeader,
|
|
981
|
+
scopes,
|
|
982
|
+
jobId,
|
|
983
|
+
);
|
|
925
984
|
|
|
926
985
|
let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
|
|
927
986
|
let executionSteps: PrivateExecutionStep[] = [];
|
|
@@ -934,11 +993,17 @@ export class PXE {
|
|
|
934
993
|
));
|
|
935
994
|
} else {
|
|
936
995
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
937
|
-
({ publicInputs, executionSteps } = await this.#prove(
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
996
|
+
({ publicInputs, executionSteps } = await this.#prove(
|
|
997
|
+
txRequest,
|
|
998
|
+
this.proofCreator,
|
|
999
|
+
privateExecutionResult,
|
|
1000
|
+
anchorBlockHeader,
|
|
1001
|
+
{
|
|
1002
|
+
simulate: true,
|
|
1003
|
+
skipFeeEnforcement,
|
|
1004
|
+
profileMode: 'none',
|
|
1005
|
+
},
|
|
1006
|
+
));
|
|
942
1007
|
}
|
|
943
1008
|
|
|
944
1009
|
const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
|
|
@@ -1012,7 +1077,7 @@ export class PXE {
|
|
|
1012
1077
|
inspect(txRequest),
|
|
1013
1078
|
`simulatePublic=${simulatePublic}`,
|
|
1014
1079
|
`skipTxValidation=${skipTxValidation}`,
|
|
1015
|
-
`scopes=${scopes
|
|
1080
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
1016
1081
|
);
|
|
1017
1082
|
}
|
|
1018
1083
|
});
|
|
@@ -1024,7 +1089,7 @@ export class PXE {
|
|
|
1024
1089
|
*/
|
|
1025
1090
|
public executeUtility(
|
|
1026
1091
|
call: FunctionCall,
|
|
1027
|
-
{ authwits, scopes }: ExecuteUtilityOpts = { scopes:
|
|
1092
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
|
|
1028
1093
|
): Promise<UtilityExecutionResult> {
|
|
1029
1094
|
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1030
1095
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -1049,7 +1114,7 @@ export class PXE {
|
|
|
1049
1114
|
scopes,
|
|
1050
1115
|
);
|
|
1051
1116
|
|
|
1052
|
-
const executionResult = await this.#executeUtility(
|
|
1117
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
1053
1118
|
contractFunctionSimulator,
|
|
1054
1119
|
call,
|
|
1055
1120
|
authwits ?? [],
|
|
@@ -1070,14 +1135,19 @@ export class PXE {
|
|
|
1070
1135
|
};
|
|
1071
1136
|
|
|
1072
1137
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
1073
|
-
return {
|
|
1138
|
+
return {
|
|
1139
|
+
result: executionResult,
|
|
1140
|
+
offchainEffects,
|
|
1141
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1142
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1143
|
+
};
|
|
1074
1144
|
} catch (err: any) {
|
|
1075
1145
|
const { to, name, args } = call;
|
|
1076
1146
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1077
1147
|
throw this.#contextualizeError(
|
|
1078
1148
|
err,
|
|
1079
1149
|
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1080
|
-
`scopes=${scopes
|
|
1150
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
1081
1151
|
);
|
|
1082
1152
|
}
|
|
1083
1153
|
});
|
|
@@ -1136,6 +1206,7 @@ export class PXE {
|
|
|
1136
1206
|
*/
|
|
1137
1207
|
public async stop(): Promise<void> {
|
|
1138
1208
|
await this.jobQueue.end();
|
|
1209
|
+
await this.blockStateSynchronizer.stop();
|
|
1139
1210
|
await this.db.close();
|
|
1140
1211
|
}
|
|
1141
1212
|
}
|
|
@@ -23,7 +23,7 @@ export class AnchorBlockStore {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async getBlockHeader(): Promise<BlockHeader> {
|
|
26
|
-
const headerBuffer = await this.#synchronizedHeader.getAsync();
|
|
26
|
+
const headerBuffer = await this.#store.transactionAsync(() => this.#synchronizedHeader.getAsync());
|
|
27
27
|
if (!headerBuffer) {
|
|
28
28
|
throw new Error(`Trying to get block header with a not-yet-synchronized PXE - this should never happen`);
|
|
29
29
|
}
|
|
@@ -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
|
+
}
|