@aztec/pxe 0.0.1-commit.993d52e → 0.0.1-commit.9badcec54
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 +13 -5
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +40 -15
- 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 +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 +281 -96
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +25 -50
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +51 -76
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +94 -60
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +276 -110
- 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/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 +125 -64
- 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 +17 -12
- 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 +12 -8
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +55 -29
- 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 +3 -9
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +54 -26
- 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 +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 +363 -139
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +61 -96
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +451 -147
- 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/hints/private_kernel_reset_private_inputs_builder.ts +157 -110
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +17 -15
- package/src/private_kernel/private_kernel_oracle.ts +14 -14
- package/src/pxe.ts +82 -34
- 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/dest/pxe.js
CHANGED
|
@@ -20,6 +20,7 @@ import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
|
20
20
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
21
21
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
22
22
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
23
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
23
24
|
import { PrivateKernelExecutionProver } from './private_kernel/private_kernel_execution_prover.js';
|
|
24
25
|
import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
|
|
25
26
|
import { AddressStore } from './storage/address_store/address_store.js';
|
|
@@ -36,6 +37,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
36
37
|
* manage private state of users.
|
|
37
38
|
*/ export class PXE {
|
|
38
39
|
node;
|
|
40
|
+
db;
|
|
39
41
|
blockStateSynchronizer;
|
|
40
42
|
keyStore;
|
|
41
43
|
contractStore;
|
|
@@ -48,6 +50,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
48
50
|
addressStore;
|
|
49
51
|
privateEventStore;
|
|
50
52
|
contractSyncService;
|
|
53
|
+
messageContextService;
|
|
54
|
+
l2TipsStore;
|
|
51
55
|
simulator;
|
|
52
56
|
proverEnabled;
|
|
53
57
|
proofCreator;
|
|
@@ -56,8 +60,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
56
60
|
jobQueue;
|
|
57
61
|
jobCoordinator;
|
|
58
62
|
debug;
|
|
59
|
-
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){
|
|
60
64
|
this.node = node;
|
|
65
|
+
this.db = db;
|
|
61
66
|
this.blockStateSynchronizer = blockStateSynchronizer;
|
|
62
67
|
this.keyStore = keyStore;
|
|
63
68
|
this.contractStore = contractStore;
|
|
@@ -70,6 +75,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
70
75
|
this.addressStore = addressStore;
|
|
71
76
|
this.privateEventStore = privateEventStore;
|
|
72
77
|
this.contractSyncService = contractSyncService;
|
|
78
|
+
this.messageContextService = messageContextService;
|
|
79
|
+
this.l2TipsStore = l2TipsStore;
|
|
73
80
|
this.simulator = simulator;
|
|
74
81
|
this.proverEnabled = proverEnabled;
|
|
75
82
|
this.proofCreator = proofCreator;
|
|
@@ -103,6 +110,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
103
110
|
const keyStore = new KeyStore(store);
|
|
104
111
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
105
112
|
const contractSyncService = new ContractSyncService(node, contractStore, noteStore, createLogger('pxe:contract_sync', bindings));
|
|
113
|
+
const messageContextService = new MessageContextService(node);
|
|
106
114
|
const synchronizer = new BlockSynchronizer(node, store, anchorBlockStore, noteStore, privateEventStore, tipsStore, contractSyncService, config, bindings);
|
|
107
115
|
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
108
116
|
jobCoordinator.registerStores([
|
|
@@ -115,7 +123,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
115
123
|
]);
|
|
116
124
|
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
117
125
|
const jobQueue = new SerialQueue();
|
|
118
|
-
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);
|
|
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);
|
|
119
127
|
debugUtils.setPXEHelpers(pxe.#putInJobQueue.bind(pxe), pxe.#getSimulatorForTx.bind(pxe), pxe.#executeUtility.bind(pxe));
|
|
120
128
|
pxe.jobQueue.start();
|
|
121
129
|
await pxe.#registerProtocolContracts();
|
|
@@ -131,13 +139,15 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
131
139
|
keyStore: this.keyStore,
|
|
132
140
|
addressStore: this.addressStore,
|
|
133
141
|
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
142
|
+
l2TipsStore: this.l2TipsStore,
|
|
134
143
|
senderTaggingStore: this.senderTaggingStore,
|
|
135
144
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
136
145
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
137
146
|
capsuleStore: this.capsuleStore,
|
|
138
147
|
privateEventStore: this.privateEventStore,
|
|
139
148
|
simulator: this.simulator,
|
|
140
|
-
contractSyncService: this.contractSyncService
|
|
149
|
+
contractSyncService: this.contractSyncService,
|
|
150
|
+
messageContextService: this.messageContextService
|
|
141
151
|
});
|
|
142
152
|
}
|
|
143
153
|
#contextualizeError(err, ...context) {
|
|
@@ -223,7 +233,11 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
223
233
|
*/ async #executeUtility(contractFunctionSimulator, call, authWitnesses, scopes, jobId) {
|
|
224
234
|
try {
|
|
225
235
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
226
|
-
|
|
236
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
|
|
237
|
+
return {
|
|
238
|
+
result,
|
|
239
|
+
offchainEffects
|
|
240
|
+
};
|
|
227
241
|
} catch (err) {
|
|
228
242
|
if (err instanceof SimulationError) {
|
|
229
243
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -268,8 +282,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
268
282
|
* @returns An object that contains the output of the kernel execution, including the ChonkProof if proving is enabled.
|
|
269
283
|
*/ async #prove(txExecutionRequest, proofCreator, privateExecutionResult, config) {
|
|
270
284
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
271
|
-
const
|
|
272
|
-
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
285
|
+
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
|
|
273
286
|
const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled, this.log.getBindings());
|
|
274
287
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
275
288
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
@@ -279,7 +292,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
279
292
|
* Returns the block header up to which the PXE has synced.
|
|
280
293
|
* @returns The synced block header
|
|
281
294
|
*/ getSyncedBlockHeader() {
|
|
282
|
-
return this
|
|
295
|
+
return this.#putInJobQueue(()=>{
|
|
296
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
297
|
+
});
|
|
283
298
|
}
|
|
284
299
|
/**
|
|
285
300
|
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
@@ -327,6 +342,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
327
342
|
* @returns The address of the sender.
|
|
328
343
|
* TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
|
|
329
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
|
+
}
|
|
330
348
|
const accounts = await this.keyStore.getAccounts();
|
|
331
349
|
if (accounts.includes(sender)) {
|
|
332
350
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
@@ -335,6 +353,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
335
353
|
const wasAdded = await this.senderAddressBookStore.addSender(sender);
|
|
336
354
|
if (wasAdded) {
|
|
337
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()));
|
|
338
359
|
} else {
|
|
339
360
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
340
361
|
}
|
|
@@ -498,16 +519,16 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
498
519
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
499
520
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
500
521
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
501
|
-
const
|
|
502
|
-
if (
|
|
522
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
523
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
503
524
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
504
525
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
505
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
506
|
-
this.log.debug(`Stored used
|
|
507
|
-
|
|
526
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
527
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
528
|
+
taggingIndexRangesUsedInTheTx
|
|
508
529
|
});
|
|
509
530
|
} else {
|
|
510
|
-
this.log.debug(`No
|
|
531
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
511
532
|
}
|
|
512
533
|
return txProvingResult;
|
|
513
534
|
} catch (err) {
|
|
@@ -589,7 +610,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
589
610
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
590
611
|
*
|
|
591
612
|
* TODO(#7456) Prevent msgSender being defined here for the first call
|
|
592
|
-
*/ simulateTx(txRequest, { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }) {
|
|
613
|
+
*/ simulateTx(txRequest, { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, skipKernels = true, overrides, scopes }) {
|
|
593
614
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
594
615
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
595
616
|
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
@@ -608,16 +629,16 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
608
629
|
const syncTimer = new Timer();
|
|
609
630
|
await this.blockStateSynchronizer.sync();
|
|
610
631
|
const syncTime = syncTimer.ms();
|
|
611
|
-
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
612
|
-
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
613
|
-
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
614
|
-
// or not.
|
|
615
632
|
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
616
633
|
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
617
|
-
|
|
618
|
-
|
|
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);
|
|
619
638
|
if (hasOverriddenContracts) {
|
|
620
|
-
|
|
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);
|
|
621
642
|
}
|
|
622
643
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
623
644
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -654,7 +675,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
654
675
|
});
|
|
655
676
|
validationTime = validationTimer.ms();
|
|
656
677
|
if (validationResult.result === 'invalid') {
|
|
657
|
-
|
|
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}`);
|
|
658
680
|
}
|
|
659
681
|
}
|
|
660
682
|
const txHash = simulatedTx.getTxHash();
|
|
@@ -687,7 +709,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
687
709
|
nodeRPCCalls: simulatorStats.nodeRPCCalls
|
|
688
710
|
});
|
|
689
711
|
} catch (err) {
|
|
690
|
-
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(', ')}`);
|
|
691
713
|
}
|
|
692
714
|
});
|
|
693
715
|
}
|
|
@@ -695,7 +717,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
695
717
|
* Executes a contract utility function.
|
|
696
718
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
697
719
|
*/ executeUtility(call, { authwits, scopes } = {
|
|
698
|
-
scopes:
|
|
720
|
+
scopes: []
|
|
699
721
|
}) {
|
|
700
722
|
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
701
723
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -710,7 +732,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
710
732
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
711
733
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
712
734
|
await this.contractSyncService.ensureContractSynced(call.to, call.selector, (privateSyncCall, execScopes)=>this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
|
|
713
|
-
const executionResult = await this.#executeUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
|
|
735
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
|
|
714
736
|
const functionTime = functionTimer.ms();
|
|
715
737
|
const totalTime = totalTimer.ms();
|
|
716
738
|
const perFunction = [
|
|
@@ -728,6 +750,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
728
750
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
729
751
|
return {
|
|
730
752
|
result: executionResult,
|
|
753
|
+
offchainEffects,
|
|
754
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
731
755
|
stats: {
|
|
732
756
|
timings,
|
|
733
757
|
nodeRPCCalls: simulationStats.nodeRPCCalls
|
|
@@ -736,7 +760,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
736
760
|
} catch (err) {
|
|
737
761
|
const { to, name, args } = call;
|
|
738
762
|
const stringifiedArgs = args.map((arg)=>arg.toString()).join(', ');
|
|
739
|
-
throw this.#contextualizeError(err, `executeUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes
|
|
763
|
+
throw this.#contextualizeError(err, `executeUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes.map((s)=>s.toString()).join(', ')}`);
|
|
740
764
|
}
|
|
741
765
|
});
|
|
742
766
|
}
|
|
@@ -767,8 +791,10 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
767
791
|
return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
|
|
768
792
|
}
|
|
769
793
|
/**
|
|
770
|
-
* Stops the PXE's job queue.
|
|
771
|
-
*/ stop() {
|
|
772
|
-
|
|
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();
|
|
773
799
|
}
|
|
774
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2Fwc3VsZV9zZXJ2aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9jYXBzdWxlX3N0b3JlL2NhcHN1bGVfc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFDM0QsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFaEQsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFFdkQ7OztHQUdHO0FBQ0gscUJBQWEsY0FBYztJQUV2QixPQUFPLENBQUMsUUFBUSxDQUFDLFlBQVk7SUFDN0IsT0FBTyxDQUFDLFFBQVEsQ0FBQyxhQUFhO0lBRmhDLFlBQ21CLFlBQVksRUFBRSxZQUFZLEVBQzFCLGFBQWEsRUFBRSxZQUFZLEVBQUUsRUFDNUM7SUFFSixVQUF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AK,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
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { type Logger } from '@aztec/foundation/log';
|
|
3
3
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
4
|
-
import
|
|
4
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
|
|
6
6
|
export declare class CapsuleStore implements StagedStore {
|
|
7
7
|
#private;
|
|
@@ -31,20 +31,20 @@ export declare class CapsuleStore implements StagedStore {
|
|
|
31
31
|
* to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
|
|
32
32
|
* network state it's backed by local PXE db.
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress): void;
|
|
35
35
|
/**
|
|
36
36
|
* Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
|
|
37
37
|
* @param contractAddress - The contract address under which the data is scoped.
|
|
38
38
|
* @param slot - The slot in the database to read.
|
|
39
39
|
* @returns The stored data or `null` if no data is stored under the slot.
|
|
40
40
|
*/
|
|
41
|
-
|
|
41
|
+
getCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[] | null>;
|
|
42
42
|
/**
|
|
43
43
|
* Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
|
|
44
44
|
* @param contractAddress - The contract address under which the data is scoped.
|
|
45
45
|
* @param slot - The slot in the database to delete.
|
|
46
46
|
*/
|
|
47
|
-
deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string): void;
|
|
47
|
+
deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): void;
|
|
48
48
|
/**
|
|
49
49
|
* Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
|
|
50
50
|
* structures by avoiding repeated calls to `loadCapsule` and `storeCapsule`.
|
|
@@ -56,7 +56,7 @@ export declare class CapsuleStore implements StagedStore {
|
|
|
56
56
|
* @param dstSlot - The first slot to copy to.
|
|
57
57
|
* @param numEntries - The number of entries to copy.
|
|
58
58
|
*/
|
|
59
|
-
copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number, jobId: string): Promise<void>;
|
|
59
|
+
copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number, jobId: string, scope: AztecAddress): Promise<void>;
|
|
60
60
|
/**
|
|
61
61
|
* Appends multiple capsules to a capsule array stored at the base slot.
|
|
62
62
|
* The array length is stored at the base slot, and elements are stored in consecutive slots after it.
|
|
@@ -65,8 +65,8 @@ export declare class CapsuleStore implements StagedStore {
|
|
|
65
65
|
* @param baseSlot - The slot where the array length is stored
|
|
66
66
|
* @param content - Array of capsule data to append
|
|
67
67
|
*/
|
|
68
|
-
appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string): Promise<void>;
|
|
69
|
-
readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string): Promise<Fr[][]>;
|
|
70
|
-
setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string): Promise<void>;
|
|
68
|
+
appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
|
|
69
|
+
readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[][]>;
|
|
70
|
+
setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
|
|
71
71
|
}
|
|
72
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
72
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2Fwc3VsZV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvY2Fwc3VsZV9zdG9yZS9jYXBzdWxlX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFDbEUsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFDeEUsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBRTNELE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLDBDQUEwQyxDQUFDO0FBRTVFLHFCQUFhLFlBQWEsWUFBVyxXQUFXOztJQUM5QyxRQUFRLENBQUMsU0FBUyxhQUFhO0lBYS9CLE1BQU0sRUFBRSxNQUFNLENBQUM7SUFFZixZQUFZLEtBQUssRUFBRSxpQkFBaUIsRUFRbkM7SUErREQ7Ozs7OztPQU1HO0lBQ0csTUFBTSxDQUFDLEtBQUssRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQWV6QztJQUVEOztPQUVHO0lBQ0gsYUFBYSxDQUFDLEtBQUssRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUcxQztJQUVEOzs7Ozs7Ozs7O09BVUc7SUF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UUsRUFBRSxFQUFFLEtBQUssRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLFlBQVksR0FBRyxPQUFPLENBQUMsRUFBRSxFQUFFLEVBQUUsQ0FBQyxDQTJCakg7SUFFRCxlQUFlLENBQUMsZUFBZSxFQUFFLFlBQVksRUFBRSxRQUFRLEVBQUUsRUFBRSxFQUFFLE9BQU8sRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUFFLEtBQUssRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLFlBQVksaUJBMkIvRztDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capsule_store.d.ts","sourceRoot":"","sources":["../../../src/storage/capsule_store/capsule_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,
|
|
1
|
+
{"version":3,"file":"capsule_store.d.ts","sourceRoot":"","sources":["../../../src/storage/capsule_store/capsule_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAE5E,qBAAa,YAAa,YAAW,WAAW;;IAC9C,QAAQ,CAAC,SAAS,aAAa;IAa/B,MAAM,EAAE,MAAM,CAAC;IAEf,YAAY,KAAK,EAAE,iBAAiB,EAQnC;IA+DD;;;;;;OAMG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,I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E,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,iBA2B/G;CACF"}
|
|
@@ -3,10 +3,11 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
3
3
|
export class CapsuleStore {
|
|
4
4
|
storeName = 'capsule';
|
|
5
5
|
#store;
|
|
6
|
-
// Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${key}
|
|
6
|
+
// Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${scope}:${key}`, using the zero
|
|
7
|
+
// address for the global scope.
|
|
7
8
|
#capsules;
|
|
8
|
-
// jobId => `${contractAddress}:${key}` => capsule data
|
|
9
|
-
// when `#stagedCapsules.get('some-job-id').get('${some-contract-address
|
|
9
|
+
// jobId => `${contractAddress}:${scope}:${key}` => capsule data
|
|
10
|
+
// when `#stagedCapsules.get('some-job-id').get('${some-contract-address}:${some-scope}:${some-key}') === null`,
|
|
10
11
|
// it signals that the capsule was deleted during the job, so it needs to be deleted on commit
|
|
11
12
|
#stagedCapsules;
|
|
12
13
|
logger;
|
|
@@ -101,8 +102,8 @@ export class CapsuleStore {
|
|
|
101
102
|
* @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
|
|
102
103
|
* to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
|
|
103
104
|
* network state it's backed by local PXE db.
|
|
104
|
-
*/
|
|
105
|
-
const dbSlotKey = dbSlotToKey(contractAddress, slot);
|
|
105
|
+
*/ setCapsule(contractAddress, slot, capsule, jobId, scope) {
|
|
106
|
+
const dbSlotKey = dbSlotToKey(contractAddress, slot, scope);
|
|
106
107
|
// A store overrides any pre-existing data on the slot
|
|
107
108
|
this.#setOnStage(jobId, dbSlotKey, Buffer.concat(capsule.map((value)=>value.toBuffer())));
|
|
108
109
|
}
|
|
@@ -111,8 +112,11 @@ export class CapsuleStore {
|
|
|
111
112
|
* @param contractAddress - The contract address under which the data is scoped.
|
|
112
113
|
* @param slot - The slot in the database to read.
|
|
113
114
|
* @returns The stored data or `null` if no data is stored under the slot.
|
|
114
|
-
*/
|
|
115
|
-
|
|
115
|
+
*/ getCapsule(contractAddress, slot, jobId, scope) {
|
|
116
|
+
return this.#store.transactionAsync(()=>this.#getCapsuleInternal(contractAddress, slot, jobId, scope));
|
|
117
|
+
}
|
|
118
|
+
/** Same as getCapsule but without its own transaction, for use inside an existing transactionAsync. */ async #getCapsuleInternal(contractAddress, slot, jobId, scope) {
|
|
119
|
+
const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot, scope));
|
|
116
120
|
if (!dataBuffer) {
|
|
117
121
|
this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
|
|
118
122
|
return null;
|
|
@@ -127,9 +131,9 @@ export class CapsuleStore {
|
|
|
127
131
|
* Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
|
|
128
132
|
* @param contractAddress - The contract address under which the data is scoped.
|
|
129
133
|
* @param slot - The slot in the database to delete.
|
|
130
|
-
*/ deleteCapsule(contractAddress, slot, jobId) {
|
|
134
|
+
*/ deleteCapsule(contractAddress, slot, jobId, scope) {
|
|
131
135
|
// When we commit this, we will interpret null as a deletion, so we'll propagate the delete to the KV store
|
|
132
|
-
this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot));
|
|
136
|
+
this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot, scope));
|
|
133
137
|
}
|
|
134
138
|
/**
|
|
135
139
|
* Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
|
|
@@ -141,7 +145,7 @@ export class CapsuleStore {
|
|
|
141
145
|
* @param srcSlot - The first slot to copy from.
|
|
142
146
|
* @param dstSlot - The first slot to copy to.
|
|
143
147
|
* @param numEntries - The number of entries to copy.
|
|
144
|
-
*/ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId) {
|
|
148
|
+
*/ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope) {
|
|
145
149
|
// This transactional context gives us "copy atomicity":
|
|
146
150
|
// there shouldn't be concurrent writes to what's being copied here.
|
|
147
151
|
// Equally important: this in practice is expected to perform thousands of DB operations
|
|
@@ -156,8 +160,8 @@ export class CapsuleStore {
|
|
|
156
160
|
indexes.reverse();
|
|
157
161
|
}
|
|
158
162
|
for (const i of indexes){
|
|
159
|
-
const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)));
|
|
160
|
-
const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)));
|
|
163
|
+
const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)), scope);
|
|
164
|
+
const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)), scope);
|
|
161
165
|
const toCopy = await this.#getFromStage(jobId, currentSrcSlot);
|
|
162
166
|
if (!toCopy) {
|
|
163
167
|
throw new Error(`Attempted to copy empty slot ${currentSrcSlot} for contract ${contractAddress.toString()}`);
|
|
@@ -173,7 +177,7 @@ export class CapsuleStore {
|
|
|
173
177
|
* @param contractAddress - The contract address that owns the capsule array
|
|
174
178
|
* @param baseSlot - The slot where the array length is stored
|
|
175
179
|
* @param content - Array of capsule data to append
|
|
176
|
-
*/ appendToCapsuleArray(contractAddress, baseSlot, content, jobId) {
|
|
180
|
+
*/ appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
|
|
177
181
|
// We wrap this in a transaction to serialize concurrent calls from Promise.all.
|
|
178
182
|
// Without this, concurrent appends to the same array could race: both read length=0,
|
|
179
183
|
// both write at the same slots, one overwrites the other.
|
|
@@ -181,21 +185,21 @@ export class CapsuleStore {
|
|
|
181
185
|
// and not using a transaction here would heavily impact performance.
|
|
182
186
|
return this.#store.transactionAsync(async ()=>{
|
|
183
187
|
// Load current length, defaulting to 0 if not found
|
|
184
|
-
const lengthData = await this
|
|
188
|
+
const lengthData = await this.#getCapsuleInternal(contractAddress, baseSlot, jobId, scope);
|
|
185
189
|
const currentLength = lengthData ? lengthData[0].toNumber() : 0;
|
|
186
190
|
// Store each capsule at consecutive slots after baseSlot + 1 + currentLength
|
|
187
191
|
for(let i = 0; i < content.length; i++){
|
|
188
192
|
const nextSlot = arraySlot(baseSlot, currentLength + i);
|
|
189
|
-
this.
|
|
193
|
+
this.setCapsule(contractAddress, nextSlot, content[i], jobId, scope);
|
|
190
194
|
}
|
|
191
195
|
// Update length to include all new capsules
|
|
192
196
|
const newLength = currentLength + content.length;
|
|
193
|
-
this.
|
|
197
|
+
this.setCapsule(contractAddress, baseSlot, [
|
|
194
198
|
new Fr(newLength)
|
|
195
|
-
], jobId);
|
|
199
|
+
], jobId, scope);
|
|
196
200
|
});
|
|
197
201
|
}
|
|
198
|
-
readCapsuleArray(contractAddress, baseSlot, jobId) {
|
|
202
|
+
readCapsuleArray(contractAddress, baseSlot, jobId, scope) {
|
|
199
203
|
// I'm leaving this transactional context here though because I'm assuming this
|
|
200
204
|
// gives us "read array atomicity": there shouldn't be concurrent writes to what's being copied
|
|
201
205
|
// here.
|
|
@@ -203,12 +207,12 @@ export class CapsuleStore {
|
|
|
203
207
|
// of jobs: different calls running concurrently on the same contract may cause trouble.
|
|
204
208
|
return this.#store.transactionAsync(async ()=>{
|
|
205
209
|
// Load length, defaulting to 0 if not found
|
|
206
|
-
const maybeLength = await this
|
|
210
|
+
const maybeLength = await this.#getCapsuleInternal(contractAddress, baseSlot, jobId, scope);
|
|
207
211
|
const length = maybeLength ? maybeLength[0].toBigInt() : 0n;
|
|
208
212
|
const values = [];
|
|
209
213
|
// Read each capsule at consecutive slots after baseSlot
|
|
210
214
|
for(let i = 0; i < length; i++){
|
|
211
|
-
const currentValue = await this
|
|
215
|
+
const currentValue = await this.#getCapsuleInternal(contractAddress, arraySlot(baseSlot, i), jobId, scope);
|
|
212
216
|
if (currentValue == undefined) {
|
|
213
217
|
throw new Error(`Expected non-empty value at capsule array in base slot ${baseSlot} at index ${i} for contract ${contractAddress}`);
|
|
214
218
|
}
|
|
@@ -217,7 +221,7 @@ export class CapsuleStore {
|
|
|
217
221
|
return values;
|
|
218
222
|
});
|
|
219
223
|
}
|
|
220
|
-
setCapsuleArray(contractAddress, baseSlot, content, jobId) {
|
|
224
|
+
setCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
|
|
221
225
|
// This transactional context in theory isn't so critical now because we aren't
|
|
222
226
|
// writing to DB so if there's exceptions midway and it blows up, no visible impact
|
|
223
227
|
// to persistent storage will happen.
|
|
@@ -228,25 +232,29 @@ export class CapsuleStore {
|
|
|
228
232
|
// of jobs: different calls running concurrently on the same contract may cause trouble.
|
|
229
233
|
return this.#store.transactionAsync(async ()=>{
|
|
230
234
|
// Load current length, defaulting to 0 if not found
|
|
231
|
-
const maybeLength = await this
|
|
235
|
+
const maybeLength = await this.#getCapsuleInternal(contractAddress, baseSlot, jobId, scope);
|
|
232
236
|
const originalLength = maybeLength ? maybeLength[0].toNumber() : 0;
|
|
233
237
|
// Set the new length
|
|
234
|
-
this.
|
|
238
|
+
this.setCapsule(contractAddress, baseSlot, [
|
|
235
239
|
new Fr(content.length)
|
|
236
|
-
], jobId);
|
|
240
|
+
], jobId, scope);
|
|
237
241
|
// Store the new content, possibly overwriting existing values
|
|
238
242
|
for(let i = 0; i < content.length; i++){
|
|
239
|
-
this.
|
|
243
|
+
this.setCapsule(contractAddress, arraySlot(baseSlot, i), content[i], jobId, scope);
|
|
240
244
|
}
|
|
241
245
|
// Clear any stragglers
|
|
242
246
|
for(let i = content.length; i < originalLength; i++){
|
|
243
|
-
this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
|
|
247
|
+
this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId, scope);
|
|
244
248
|
}
|
|
245
249
|
});
|
|
246
250
|
}
|
|
247
251
|
}
|
|
248
|
-
function dbSlotToKey(contractAddress, slot) {
|
|
249
|
-
return
|
|
252
|
+
function dbSlotToKey(contractAddress, slot, scope) {
|
|
253
|
+
return [
|
|
254
|
+
contractAddress.toString(),
|
|
255
|
+
scope.toString(),
|
|
256
|
+
slot.toString()
|
|
257
|
+
].join(':');
|
|
250
258
|
}
|
|
251
259
|
function arraySlot(baseSlot, index) {
|
|
252
260
|
return baseSlot.add(new Fr(1)).add(new Fr(index));
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
export { CapsuleService } from './capsule_service.js';
|
|
1
2
|
export { CapsuleStore } from './capsule_store.js';
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL2NhcHN1bGVfc3RvcmUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGNBQWMsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ3RELE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/capsule_store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/capsule_store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|