@aztec/pxe 0.0.1-commit.6d63667d → 0.0.1-commit.71324e566
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 +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +8 -15
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +62 -30
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +205 -74
- 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 +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 +4 -6
- 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 +8 -10
- 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 +2 -2
- 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 +2 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
- 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 +6 -11
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +61 -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 +47 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +75 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +282 -97
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +53 -80
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +110 -87
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +118 -64
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +312 -128
- 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 +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 -4
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +69 -35
- 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 +5 -6
- 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 +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 +11 -3
- 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 +11 -3
- 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 +3 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -1
- 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 +11 -3
- 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/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 -7
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +33 -48
- 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 +4 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +20 -10
- 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 +18 -13
- package/dest/private_kernel/private_kernel_oracle.d.ts +10 -6
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +19 -18
- package/dest/pxe.d.ts +73 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +122 -75
- 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 +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +148 -70
- 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 -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/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/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 +8 -22
- 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/bin/check_oracle_version.ts +4 -4
- package/src/block_synchronizer/block_synchronizer.ts +22 -2
- package/src/config/index.ts +3 -9
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +365 -136
- package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
- 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 +9 -9
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
- package/src/contract_function_simulator/oracle/interfaces.ts +82 -54
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
- package/src/contract_function_simulator/oracle/oracle.ts +364 -140
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +138 -178
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +527 -158
- 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 +52 -0
- package/src/contract_sync/contract_sync_service.ts +102 -55
- package/src/contract_sync/helpers.ts +8 -3
- package/src/debug/pxe_debug_utils.ts +11 -14
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +11 -4
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +11 -4
- package/src/entrypoints/pxe_creation_options.ts +7 -0
- package/src/entrypoints/server/index.ts +2 -1
- package/src/entrypoints/server/utils.ts +9 -10
- package/src/events/event_service.ts +17 -4
- package/src/events/private_event_filter_validator.ts +21 -1
- package/src/logs/log_service.ts +63 -91
- 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 +20 -10
- 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 +18 -16
- package/src/private_kernel/private_kernel_oracle.ts +21 -21
- package/src/pxe.ts +214 -119
- 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 +181 -80
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +9 -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/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 +12 -25
- 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/dest/pxe.js
CHANGED
|
@@ -13,12 +13,14 @@ import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
|
13
13
|
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
14
14
|
import { ContractFunctionSimulator, generateSimulatedProvingResult } from './contract_function_simulator/contract_function_simulator.js';
|
|
15
15
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
16
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
16
17
|
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
17
18
|
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
18
19
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
19
20
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
20
21
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
21
22
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
23
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
22
24
|
import { PrivateKernelExecutionProver } from './private_kernel/private_kernel_execution_prover.js';
|
|
23
25
|
import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
|
|
24
26
|
import { AddressStore } from './storage/address_store/address_store.js';
|
|
@@ -35,6 +37,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
35
37
|
* manage private state of users.
|
|
36
38
|
*/ export class PXE {
|
|
37
39
|
node;
|
|
40
|
+
db;
|
|
38
41
|
blockStateSynchronizer;
|
|
39
42
|
keyStore;
|
|
40
43
|
contractStore;
|
|
@@ -47,6 +50,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
47
50
|
addressStore;
|
|
48
51
|
privateEventStore;
|
|
49
52
|
contractSyncService;
|
|
53
|
+
messageContextService;
|
|
54
|
+
l2TipsStore;
|
|
50
55
|
simulator;
|
|
51
56
|
proverEnabled;
|
|
52
57
|
proofCreator;
|
|
@@ -55,8 +60,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
55
60
|
jobQueue;
|
|
56
61
|
jobCoordinator;
|
|
57
62
|
debug;
|
|
58
|
-
constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
|
|
63
|
+
constructor(node, db, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, messageContextService, l2TipsStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
|
|
59
64
|
this.node = node;
|
|
65
|
+
this.db = db;
|
|
60
66
|
this.blockStateSynchronizer = blockStateSynchronizer;
|
|
61
67
|
this.keyStore = keyStore;
|
|
62
68
|
this.contractStore = contractStore;
|
|
@@ -69,6 +75,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
69
75
|
this.addressStore = addressStore;
|
|
70
76
|
this.privateEventStore = privateEventStore;
|
|
71
77
|
this.contractSyncService = contractSyncService;
|
|
78
|
+
this.messageContextService = messageContextService;
|
|
79
|
+
this.l2TipsStore = l2TipsStore;
|
|
72
80
|
this.simulator = simulator;
|
|
73
81
|
this.proverEnabled = proverEnabled;
|
|
74
82
|
this.proofCreator = proofCreator;
|
|
@@ -84,11 +92,12 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
84
92
|
* can be contacted.
|
|
85
93
|
*
|
|
86
94
|
* @returns A promise that resolves PXE is ready to be used.
|
|
87
|
-
*/ static async create(node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix) {
|
|
95
|
+
*/ static async create({ node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix }) {
|
|
88
96
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
89
97
|
const bindings = loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
90
98
|
const log = !loggerOrSuffix || typeof loggerOrSuffix === 'string' ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`) : loggerOrSuffix;
|
|
91
|
-
const
|
|
99
|
+
const info = await node.getNodeInfo();
|
|
100
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
92
101
|
const addressStore = new AddressStore(store);
|
|
93
102
|
const privateEventStore = new PrivateEventStore(store);
|
|
94
103
|
const contractStore = new ContractStore(store);
|
|
@@ -101,6 +110,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
101
110
|
const keyStore = new KeyStore(store);
|
|
102
111
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
103
112
|
const contractSyncService = new ContractSyncService(node, contractStore, noteStore, createLogger('pxe:contract_sync', bindings));
|
|
113
|
+
const messageContextService = new MessageContextService(node);
|
|
104
114
|
const synchronizer = new BlockSynchronizer(node, store, anchorBlockStore, noteStore, privateEventStore, tipsStore, contractSyncService, config, bindings);
|
|
105
115
|
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
106
116
|
jobCoordinator.registerStores([
|
|
@@ -113,18 +123,32 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
113
123
|
]);
|
|
114
124
|
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
115
125
|
const jobQueue = new SerialQueue();
|
|
116
|
-
const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils);
|
|
117
|
-
debugUtils.setPXEHelpers(pxe.#putInJobQueue.bind(pxe), pxe.#getSimulatorForTx.bind(pxe), pxe.#
|
|
126
|
+
const pxe = new PXE(node, store, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, messageContextService, tipsStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils);
|
|
127
|
+
debugUtils.setPXEHelpers(pxe.#putInJobQueue.bind(pxe), pxe.#getSimulatorForTx.bind(pxe), pxe.#executeUtility.bind(pxe));
|
|
118
128
|
pxe.jobQueue.start();
|
|
119
129
|
await pxe.#registerProtocolContracts();
|
|
120
|
-
const info = await node.getNodeInfo();
|
|
121
130
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
122
131
|
return pxe;
|
|
123
132
|
}
|
|
124
133
|
// Internal methods
|
|
125
134
|
#getSimulatorForTx(overrides) {
|
|
126
135
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
127
|
-
return new ContractFunctionSimulator(
|
|
136
|
+
return new ContractFunctionSimulator({
|
|
137
|
+
contractStore: proxyContractStore,
|
|
138
|
+
noteStore: this.noteStore,
|
|
139
|
+
keyStore: this.keyStore,
|
|
140
|
+
addressStore: this.addressStore,
|
|
141
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
142
|
+
l2TipsStore: this.l2TipsStore,
|
|
143
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
144
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
145
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
146
|
+
capsuleStore: this.capsuleStore,
|
|
147
|
+
privateEventStore: this.privateEventStore,
|
|
148
|
+
simulator: this.simulator,
|
|
149
|
+
contractSyncService: this.contractSyncService,
|
|
150
|
+
messageContextService: this.messageContextService
|
|
151
|
+
});
|
|
128
152
|
}
|
|
129
153
|
#contextualizeError(err, ...context) {
|
|
130
154
|
let contextStr = '';
|
|
@@ -167,8 +191,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
167
191
|
async #registerProtocolContracts() {
|
|
168
192
|
const registered = {};
|
|
169
193
|
for (const name of protocolContractNames){
|
|
170
|
-
const { address,
|
|
171
|
-
await this.contractStore.addContractArtifact(
|
|
194
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
195
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
172
196
|
await this.contractStore.addContractInstance(instance);
|
|
173
197
|
registered[name] = address.toString();
|
|
174
198
|
}
|
|
@@ -180,10 +204,14 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
180
204
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
181
205
|
try {
|
|
182
206
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
183
|
-
await this.contractSyncService.ensureContractSynced(contractAddress, functionSelector, (privateSyncCall)=>this.#
|
|
184
|
-
const result = await contractFunctionSimulator.run(txRequest,
|
|
185
|
-
|
|
186
|
-
|
|
207
|
+
await this.contractSyncService.ensureContractSynced(contractAddress, functionSelector, (privateSyncCall, execScopes)=>this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
|
|
208
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
209
|
+
contractAddress,
|
|
210
|
+
selector: functionSelector,
|
|
211
|
+
anchorBlockHeader,
|
|
212
|
+
scopes,
|
|
213
|
+
jobId
|
|
214
|
+
});
|
|
187
215
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
188
216
|
return result;
|
|
189
217
|
} catch (err) {
|
|
@@ -194,18 +222,22 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
194
222
|
}
|
|
195
223
|
}
|
|
196
224
|
/**
|
|
197
|
-
*
|
|
225
|
+
* Execute a utility function call on the given contract.
|
|
198
226
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
199
227
|
* @param call - The function call to execute.
|
|
200
228
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
201
229
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
202
230
|
* accounts if not specified.
|
|
203
231
|
* @param jobId - The job ID for staged writes.
|
|
204
|
-
* @returns The
|
|
205
|
-
*/ async #
|
|
232
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
233
|
+
*/ async #executeUtility(contractFunctionSimulator, call, authWitnesses, scopes, jobId) {
|
|
206
234
|
try {
|
|
207
235
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
208
|
-
|
|
236
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
|
|
237
|
+
return {
|
|
238
|
+
result,
|
|
239
|
+
offchainEffects
|
|
240
|
+
};
|
|
209
241
|
} catch (err) {
|
|
210
242
|
if (err instanceof SimulationError) {
|
|
211
243
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -250,14 +282,25 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
250
282
|
* @returns An object that contains the output of the kernel execution, including the ChonkProof if proving is enabled.
|
|
251
283
|
*/ async #prove(txExecutionRequest, proofCreator, privateExecutionResult, config) {
|
|
252
284
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
253
|
-
const
|
|
254
|
-
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
285
|
+
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
|
|
255
286
|
const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled, this.log.getBindings());
|
|
256
287
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
257
288
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
258
289
|
}
|
|
259
290
|
// Public API
|
|
260
|
-
|
|
291
|
+
/**
|
|
292
|
+
* Returns the block header up to which the PXE has synced.
|
|
293
|
+
* @returns The synced block header
|
|
294
|
+
*/ getSyncedBlockHeader() {
|
|
295
|
+
return this.#putInJobQueue(()=>{
|
|
296
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
301
|
+
* @param address - The contract address.
|
|
302
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
303
|
+
*/ getContractInstance(address) {
|
|
261
304
|
return this.contractStore.getContractInstance(address);
|
|
262
305
|
}
|
|
263
306
|
/**
|
|
@@ -299,6 +342,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
299
342
|
* @returns The address of the sender.
|
|
300
343
|
* TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
|
|
301
344
|
*/ async registerSender(sender) {
|
|
345
|
+
if (!await sender.isValid()) {
|
|
346
|
+
throw new Error(`Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`);
|
|
347
|
+
}
|
|
302
348
|
const accounts = await this.keyStore.getAccounts();
|
|
303
349
|
if (accounts.includes(sender)) {
|
|
304
350
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
@@ -307,6 +353,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
307
353
|
const wasAdded = await this.senderAddressBookStore.addSender(sender);
|
|
308
354
|
if (wasAdded) {
|
|
309
355
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
356
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
357
|
+
// all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
|
|
358
|
+
await this.#putInJobQueue(()=>Promise.resolve(this.contractSyncService.wipe()));
|
|
310
359
|
} else {
|
|
311
360
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
312
361
|
}
|
|
@@ -344,8 +393,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
344
393
|
*
|
|
345
394
|
* @param artifact - The build artifact for the contract class.
|
|
346
395
|
*/ async registerContractClass(artifact) {
|
|
347
|
-
const
|
|
348
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
396
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
349
397
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
350
398
|
}
|
|
351
399
|
/**
|
|
@@ -361,15 +409,14 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
361
409
|
if (artifact) {
|
|
362
410
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
363
411
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
throw new Error(`Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`);
|
|
412
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
413
|
+
throw new Error(`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`);
|
|
367
414
|
}
|
|
368
415
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
369
416
|
if (!computedAddress.equals(instance.address)) {
|
|
370
417
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
371
418
|
}
|
|
372
|
-
await this.contractStore.addContractArtifact(
|
|
419
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
373
420
|
const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
|
|
374
421
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
375
422
|
} else {
|
|
@@ -405,11 +452,13 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
405
452
|
if (!contractClass.id.equals(currentClassId)) {
|
|
406
453
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
407
454
|
}
|
|
408
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
409
455
|
const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
|
|
410
456
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
411
457
|
currentInstance.currentContractClassId = contractClass.id;
|
|
412
|
-
await
|
|
458
|
+
await Promise.all([
|
|
459
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
460
|
+
this.contractStore.addContractInstance(currentInstance)
|
|
461
|
+
]);
|
|
413
462
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
414
463
|
});
|
|
415
464
|
}
|
|
@@ -424,10 +473,11 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
424
473
|
* (where validators prove the public portion).
|
|
425
474
|
*
|
|
426
475
|
* @param txRequest - An authenticated tx request ready for proving
|
|
476
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
427
477
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
428
478
|
* @throws If contract code not found, or public simulation reverts.
|
|
429
479
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
430
|
-
*/ proveTx(txRequest) {
|
|
480
|
+
*/ proveTx(txRequest, scopes) {
|
|
431
481
|
let privateExecutionResult;
|
|
432
482
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
433
483
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -438,7 +488,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
438
488
|
await this.blockStateSynchronizer.sync();
|
|
439
489
|
const syncTime = syncTimer.ms();
|
|
440
490
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
441
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
491
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
442
492
|
const { publicInputs, chonkProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
443
493
|
simulate: false,
|
|
444
494
|
skipFeeEnforcement: false,
|
|
@@ -469,16 +519,16 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
469
519
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
470
520
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
471
521
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
472
|
-
const
|
|
473
|
-
if (
|
|
522
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
523
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
474
524
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
475
525
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
476
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
477
|
-
this.log.debug(`Stored used
|
|
478
|
-
|
|
526
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
527
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
528
|
+
taggingIndexRangesUsedInTheTx
|
|
479
529
|
});
|
|
480
530
|
} else {
|
|
481
|
-
this.log.debug(`No
|
|
531
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
482
532
|
}
|
|
483
533
|
return txProvingResult;
|
|
484
534
|
} catch (err) {
|
|
@@ -488,13 +538,10 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
488
538
|
}
|
|
489
539
|
/**
|
|
490
540
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
491
|
-
*
|
|
492
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
493
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
494
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
541
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
495
542
|
* @returns A trace of the program execution with gate counts.
|
|
496
543
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
497
|
-
*/ profileTx(txRequest, profileMode, skipProofGeneration = true) {
|
|
544
|
+
*/ profileTx(txRequest, { profileMode, skipProofGeneration = true, scopes }) {
|
|
498
545
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
499
546
|
return this.#putInJobQueue(async (jobId)=>{
|
|
500
547
|
const totalTimer = new Timer();
|
|
@@ -512,7 +559,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
512
559
|
await this.blockStateSynchronizer.sync();
|
|
513
560
|
const syncTime = syncTimer.ms();
|
|
514
561
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
515
|
-
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
562
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
516
563
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
517
564
|
simulate: skipProofGeneration,
|
|
518
565
|
skipFeeEnforcement: false,
|
|
@@ -557,18 +604,13 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
557
604
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
558
605
|
*
|
|
559
606
|
*
|
|
560
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
561
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
562
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
563
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
564
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
565
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
607
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
566
608
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
567
609
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
568
610
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
569
611
|
*
|
|
570
612
|
* TODO(#7456) Prevent msgSender being defined here for the first call
|
|
571
|
-
*/ simulateTx(txRequest, simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes) {
|
|
613
|
+
*/ simulateTx(txRequest, { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, skipKernels = true, overrides, scopes }) {
|
|
572
614
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
573
615
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
574
616
|
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
@@ -587,23 +629,23 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
587
629
|
const syncTimer = new Timer();
|
|
588
630
|
await this.blockStateSynchronizer.sync();
|
|
589
631
|
const syncTime = syncTimer.ms();
|
|
590
|
-
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
591
|
-
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
592
|
-
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
593
|
-
// or not.
|
|
594
632
|
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
595
633
|
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
596
|
-
|
|
597
|
-
|
|
634
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
635
|
+
throw new Error('Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.');
|
|
636
|
+
}
|
|
637
|
+
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
598
638
|
if (hasOverriddenContracts) {
|
|
599
|
-
|
|
639
|
+
// Overridden contracts don't have a sync function, so calling sync on them would fail.
|
|
640
|
+
// We exclude them so the sync service skips them entirely.
|
|
641
|
+
this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
|
|
600
642
|
}
|
|
601
643
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
602
644
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
603
645
|
let publicInputs;
|
|
604
646
|
let executionSteps = [];
|
|
605
647
|
if (skipKernels) {
|
|
606
|
-
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, this.contractStore));
|
|
648
|
+
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), this.node));
|
|
607
649
|
} else {
|
|
608
650
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
609
651
|
({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
@@ -620,6 +662,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
620
662
|
const publicSimulationTimer = new Timer();
|
|
621
663
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
622
664
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
665
|
+
if (publicOutput?.debugLogs?.length) {
|
|
666
|
+
await displayDebugLogs(publicOutput.debugLogs, (addr)=>this.contractStore.getDebugContractName(addr));
|
|
667
|
+
}
|
|
623
668
|
}
|
|
624
669
|
let validationTime;
|
|
625
670
|
if (!skipTxValidation) {
|
|
@@ -630,7 +675,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
630
675
|
});
|
|
631
676
|
validationTime = validationTimer.ms();
|
|
632
677
|
if (validationResult.result === 'invalid') {
|
|
633
|
-
|
|
678
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
679
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
634
680
|
}
|
|
635
681
|
}
|
|
636
682
|
const txHash = simulatedTx.getTxHash();
|
|
@@ -663,22 +709,19 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
663
709
|
nodeRPCCalls: simulatorStats.nodeRPCCalls
|
|
664
710
|
});
|
|
665
711
|
} catch (err) {
|
|
666
|
-
throw this.#contextualizeError(err, inspect(txRequest), `simulatePublic=${simulatePublic}`, `skipTxValidation=${skipTxValidation}`, `scopes=${scopes
|
|
712
|
+
throw this.#contextualizeError(err, inspect(txRequest), `simulatePublic=${simulatePublic}`, `skipTxValidation=${skipTxValidation}`, `scopes=${scopes.map((s)=>s.toString()).join(', ')}`);
|
|
667
713
|
}
|
|
668
714
|
});
|
|
669
715
|
}
|
|
670
716
|
/**
|
|
671
|
-
*
|
|
672
|
-
*
|
|
717
|
+
* Executes a contract utility function.
|
|
673
718
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
*/ simulateUtility(call, authwits, scopes) {
|
|
679
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
719
|
+
*/ executeUtility(call, { authwits, scopes } = {
|
|
720
|
+
scopes: []
|
|
721
|
+
}) {
|
|
722
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
680
723
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
681
|
-
// delete the same read value, or reading values that another
|
|
724
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
682
725
|
return this.#putInJobQueue(async (jobId)=>{
|
|
683
726
|
try {
|
|
684
727
|
const totalTimer = new Timer();
|
|
@@ -688,8 +731,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
688
731
|
const functionTimer = new Timer();
|
|
689
732
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
690
733
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
691
|
-
await this.contractSyncService.ensureContractSynced(call.to, call.selector, (privateSyncCall)=>this.#
|
|
692
|
-
const executionResult = await this.#
|
|
734
|
+
await this.contractSyncService.ensureContractSynced(call.to, call.selector, (privateSyncCall, execScopes)=>this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
|
|
735
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
|
|
693
736
|
const functionTime = functionTimer.ms();
|
|
694
737
|
const totalTime = totalTimer.ms();
|
|
695
738
|
const perFunction = [
|
|
@@ -707,6 +750,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
707
750
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
708
751
|
return {
|
|
709
752
|
result: executionResult,
|
|
753
|
+
offchainEffects,
|
|
754
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
710
755
|
stats: {
|
|
711
756
|
timings,
|
|
712
757
|
nodeRPCCalls: simulationStats.nodeRPCCalls
|
|
@@ -715,7 +760,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
715
760
|
} catch (err) {
|
|
716
761
|
const { to, name, args } = call;
|
|
717
762
|
const stringifiedArgs = args.map((arg)=>arg.toString()).join(', ');
|
|
718
|
-
throw this.#contextualizeError(err, `
|
|
763
|
+
throw this.#contextualizeError(err, `executeUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes.map((s)=>s.toString()).join(', ')}`);
|
|
719
764
|
}
|
|
720
765
|
});
|
|
721
766
|
}
|
|
@@ -738,7 +783,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
738
783
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
739
784
|
anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
740
785
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
741
|
-
await this.contractSyncService.ensureContractSynced(filter.contractAddress, null, async (privateSyncCall)=>await this.#
|
|
786
|
+
await this.contractSyncService.ensureContractSynced(filter.contractAddress, null, async (privateSyncCall, execScopes)=>await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, filter.scopes);
|
|
742
787
|
});
|
|
743
788
|
// anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
|
|
744
789
|
const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber).validate(filter);
|
|
@@ -746,8 +791,10 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
746
791
|
return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
|
|
747
792
|
}
|
|
748
793
|
/**
|
|
749
|
-
* Stops the PXE's job queue.
|
|
750
|
-
*/ stop() {
|
|
751
|
-
|
|
794
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
795
|
+
*/ async stop() {
|
|
796
|
+
await this.jobQueue.end();
|
|
797
|
+
await this.blockStateSynchronizer.stop();
|
|
798
|
+
await this.db.close();
|
|
752
799
|
}
|
|
753
800
|
}
|
|
@@ -17,7 +17,7 @@ export class AnchorBlockStore {
|
|
|
17
17
|
await this.#synchronizedHeader.set(header.toBuffer());
|
|
18
18
|
}
|
|
19
19
|
async getBlockHeader() {
|
|
20
|
-
const headerBuffer = await this.#synchronizedHeader.getAsync();
|
|
20
|
+
const headerBuffer = await this.#store.transactionAsync(()=>this.#synchronizedHeader.getAsync());
|
|
21
21
|
if (!headerBuffer) {
|
|
22
22
|
throw new Error(`Trying to get block header with a not-yet-synchronized PXE - this should never happen`);
|
|
23
23
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
import type { CapsuleStore } from './capsule_store.js';
|
|
5
|
+
/**
|
|
6
|
+
* Wraps a CapsuleStore with scope-based access control. Each operation asserts that the requested scope is in the
|
|
7
|
+
* allowed scopes list before delegating to the underlying store.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CapsuleService {
|
|
10
|
+
private readonly capsuleStore;
|
|
11
|
+
private readonly allowedScopes;
|
|
12
|
+
constructor(capsuleStore: CapsuleStore, allowedScopes: AztecAddress[]);
|
|
13
|
+
setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress): void;
|
|
14
|
+
getCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress, transientCapsules?: Capsule[]): Promise<Fr[] | null>;
|
|
15
|
+
deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): void;
|
|
16
|
+
copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number, jobId: string, scope: AztecAddress): Promise<void>;
|
|
17
|
+
appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
|
|
18
|
+
readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[][]>;
|
|
19
|
+
setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2Fwc3VsZV9zZXJ2aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9jYXBzdWxlX3N0b3JlL2NhcHN1bGVfc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFDM0QsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFaEQsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFFdkQ7OztHQUdHO0FBQ0gscUJBQWEsY0FBYztJQUV2QixPQUFPLENBQUMsUUFBUSxDQUFDLFlBQVk7SUFDN0IsT0FBTyxDQUFDLFFBQVEsQ0FBQyxhQUFhO0lBRmhDLFlBQ21CLFlBQVksRUFBRSxZQUFZLEVBQzFCLGFBQWEsRUFBRSxZQUFZLEVBQUUsRUFDNUM7SUFFSixVQUFVLENBQUMsZUFBZSxFQUFFLFlBQVksRUFBRSxJQUFJLEVBQUUsRUFBRSxFQUFFLE9BQU8sRUFBRSxFQUFFLEVBQUUsRUFBRSxLQUFLLEVBQUUsTUFBTSxFQUFFLEtBQUssRUFBRSxZQUFZLFFBR3BHO0lBRUssVUFBVSxDQUNkLGVBQWUsRUFBRSxZQUFZLEVBQzdCLElBQUksRUFBRSxFQUFFLEVBQ1IsS0FBSyxFQUFFLE1BQU0sRUFDYixLQUFLLEVBQUUsWUFBWSxFQUNuQixpQkFBaUIsQ0FBQyxFQUFFLE9BQU8sRUFBRSxHQUM1QixPQUFPLENBQUMsRUFBRSxFQUFFLEdBQUcsSUFBSSxDQUFDLENBWXRCO0lBRUQsYUFBYSxDQUFDLGVBQWUsRUFBRSxZQUFZLEVBQUUsSUFBSSxFQUFFLEVBQUUsRUFBRSxLQUFLLEVBQUUsTUFBTSxFQUFFLEtBQUssRUFBRSxZQUFZLFFBR3hGO0lBRUQsV0FBVyxDQUNULGVBQWUsRUFBRSxZQUFZLEVBQzdCLE9BQU8sRUFBRSxFQUFFLEVBQ1gsT0FBTyxFQUFFLEVBQUUsRUFDWCxVQUFVLEVBQUUsTUFBTSxFQUNsQixLQUFLLEVBQUUsTUFBTSxFQUNiLEtBQUssRUFBRSxZQUFZLEdBQ2xCLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FHZjtJQUVELG9CQUFvQixDQUNsQixlQUFlLEVBQUUsWUFBWSxFQUM3QixRQUFRLEVBQUUsRUFBRSxFQUNaLE9BQU8sRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUNmLEtBQUssRUFBRSxNQUFNLEVBQ2IsS0FBSyxFQUFFLFlBQVksR0FDbEIsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUdmO0lBRUQsZ0JBQWdCLENBQUMsZUFBZSxFQUFFLFlBQVksRUFBRSxRQUFRLEVBQUUsRUFBRSxFQUFFLEtBQUssRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLFlBQVksR0FBRyxPQUFPLENBQUMsRUFBRSxFQUFFLEVBQUUsQ0FBQyxDQUdqSDtJQUVELGVBQWUsQ0FBQyxlQUFlLEVBQUUsWUFBWSxFQUFFLFFBQVEsRUFBRSxFQUFFLEVBQUUsT0FBTyxFQUFFLEVBQUUsRUFBRSxFQUFFLEVBQUUsS0FBSyxFQUFFLE1BQU0sRUFBRSxLQUFLLEVBQUUsWUFBWSxpQkFHL0c7Q0FDRiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capsule_service.d.ts","sourceRoot":"","sources":["../../../src/storage/capsule_store/capsule_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;GAGG;AACH,qBAAa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAFhC,YACmB,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,YAAY,EAAE,EAC5C;IAEJ,UAAU,CAAC,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,QAGpG;IAEK,UAAU,CACd,eAAe,EAAE,YAAY,EAC7B,IAAI,EAAE,EAAE,EACR,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,EACnB,iBAAiB,CAAC,EAAE,OAAO,EAAE,GAC5B,OAAO,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAYtB;IAED,aAAa,CAAC,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,QAGxF;IAED,WAAW,CACT,eAAe,EAAE,YAAY,EAC7B,OAAO,EAAE,EAAE,EACX,OAAO,EAAE,EAAE,EACX,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CAGf;IAED,oBAAoB,CAClB,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,EAAE,EACZ,OAAO,EAAE,EAAE,EAAE,EAAE,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CAGf;IAED,gBAAgB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAGjH;IAED,eAAe,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,iBAG/G;CACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a CapsuleStore with scope-based access control. Each operation asserts that the requested scope is in the
|
|
4
|
+
* allowed scopes list before delegating to the underlying store.
|
|
5
|
+
*/ export class CapsuleService {
|
|
6
|
+
capsuleStore;
|
|
7
|
+
allowedScopes;
|
|
8
|
+
constructor(capsuleStore, allowedScopes){
|
|
9
|
+
this.capsuleStore = capsuleStore;
|
|
10
|
+
this.allowedScopes = allowedScopes;
|
|
11
|
+
}
|
|
12
|
+
setCapsule(contractAddress, slot, capsule, jobId, scope) {
|
|
13
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
14
|
+
this.capsuleStore.setCapsule(contractAddress, slot, capsule, jobId, scope);
|
|
15
|
+
}
|
|
16
|
+
async getCapsule(contractAddress, slot, jobId, scope, transientCapsules) {
|
|
17
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
18
|
+
// TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
|
|
19
|
+
const maybeTransientCapsule = transientCapsules?.find((c)=>c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot) && (c.scope ?? AztecAddress.ZERO).equals(scope))?.data;
|
|
20
|
+
return maybeTransientCapsule ?? await this.capsuleStore.getCapsule(contractAddress, slot, jobId, scope);
|
|
21
|
+
}
|
|
22
|
+
deleteCapsule(contractAddress, slot, jobId, scope) {
|
|
23
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
24
|
+
this.capsuleStore.deleteCapsule(contractAddress, slot, jobId, scope);
|
|
25
|
+
}
|
|
26
|
+
copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope) {
|
|
27
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
28
|
+
return this.capsuleStore.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope);
|
|
29
|
+
}
|
|
30
|
+
appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
|
|
31
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
32
|
+
return this.capsuleStore.appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
|
|
33
|
+
}
|
|
34
|
+
readCapsuleArray(contractAddress, baseSlot, jobId, scope) {
|
|
35
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
36
|
+
return this.capsuleStore.readCapsuleArray(contractAddress, baseSlot, jobId, scope);
|
|
37
|
+
}
|
|
38
|
+
setCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
|
|
39
|
+
assertAllowedScope(scope, this.allowedScopes);
|
|
40
|
+
return this.capsuleStore.setCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function assertAllowedScope(scope, allowedScopes) {
|
|
44
|
+
if (scope.equals(AztecAddress.ZERO)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!allowedScopes.some((allowed)=>allowed.equals(scope))) {
|
|
48
|
+
throw new Error(`Scope ${scope.toString()} is not in the allowed scopes list: [${allowedScopes.map((s)=>s.toString()).join(', ')}]. See https://docs.aztec.network/errors/10`);
|
|
49
|
+
}
|
|
50
|
+
}
|