@aztec/pxe 0.0.1-commit.023c3e5 → 0.0.1-commit.08c5969dc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/block_synchronizer/block_synchronizer.d.ts +4 -2
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +7 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +52 -27
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +169 -63
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +3 -3
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +3 -3
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +23 -11
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +35 -35
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +73 -20
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +34 -15
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +64 -44
- package/dest/contract_sync/contract_sync_service.d.ts +42 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +97 -0
- package/dest/contract_sync/helpers.d.ts +28 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/{index.js → helpers.js} +13 -12
- package/dest/debug/pxe_debug_utils.d.ts +12 -9
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +16 -15
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +9 -1
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +9 -1
- package/dest/entrypoints/server/index.d.ts +2 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -1
- package/dest/entrypoints/server/utils.js +9 -1
- package/dest/logs/log_service.d.ts +2 -2
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +6 -13
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/pxe.d.ts +68 -23
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +68 -42
- package/dest/storage/contract_store/contract_store.js +5 -5
- package/dest/storage/note_store/note_store.d.ts +1 -2
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +4 -2
- package/package.json +25 -16
- package/src/block_synchronizer/block_synchronizer.ts +6 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +315 -119
- package/src/contract_function_simulator/oracle/interfaces.ts +2 -2
- package/src/contract_function_simulator/oracle/oracle.ts +14 -7
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +95 -96
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +105 -44
- package/src/contract_sync/contract_sync_service.ts +145 -0
- package/src/contract_sync/{index.ts → helpers.ts} +15 -20
- package/src/debug/pxe_debug_utils.ts +46 -17
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/index.ts +1 -1
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/logs/log_service.ts +6 -15
- package/src/oracle_version.ts +2 -2
- package/src/pxe.ts +146 -83
- package/src/storage/contract_store/contract_store.ts +4 -4
- package/src/storage/note_store/note_store.ts +5 -2
- package/dest/contract_sync/index.d.ts +0 -23
- package/dest/contract_sync/index.d.ts.map +0 -1
package/dest/pxe.js
CHANGED
|
@@ -13,7 +13,8 @@ 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 {
|
|
16
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
17
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
17
18
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
18
19
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
19
20
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
@@ -45,6 +46,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
45
46
|
recipientTaggingStore;
|
|
46
47
|
addressStore;
|
|
47
48
|
privateEventStore;
|
|
49
|
+
contractSyncService;
|
|
48
50
|
simulator;
|
|
49
51
|
proverEnabled;
|
|
50
52
|
proofCreator;
|
|
@@ -53,7 +55,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
53
55
|
jobQueue;
|
|
54
56
|
jobCoordinator;
|
|
55
57
|
debug;
|
|
56
|
-
constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
|
|
58
|
+
constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
|
|
57
59
|
this.node = node;
|
|
58
60
|
this.blockStateSynchronizer = blockStateSynchronizer;
|
|
59
61
|
this.keyStore = keyStore;
|
|
@@ -66,6 +68,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
66
68
|
this.recipientTaggingStore = recipientTaggingStore;
|
|
67
69
|
this.addressStore = addressStore;
|
|
68
70
|
this.privateEventStore = privateEventStore;
|
|
71
|
+
this.contractSyncService = contractSyncService;
|
|
69
72
|
this.simulator = simulator;
|
|
70
73
|
this.proverEnabled = proverEnabled;
|
|
71
74
|
this.proofCreator = proofCreator;
|
|
@@ -81,11 +84,12 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
81
84
|
* can be contacted.
|
|
82
85
|
*
|
|
83
86
|
* @returns A promise that resolves PXE is ready to be used.
|
|
84
|
-
*/ static async create(node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix) {
|
|
87
|
+
*/ static async create({ node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix }) {
|
|
85
88
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
86
89
|
const bindings = loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
87
90
|
const log = !loggerOrSuffix || typeof loggerOrSuffix === 'string' ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`) : loggerOrSuffix;
|
|
88
|
-
const
|
|
91
|
+
const info = await node.getNodeInfo();
|
|
92
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
89
93
|
const addressStore = new AddressStore(store);
|
|
90
94
|
const privateEventStore = new PrivateEventStore(store);
|
|
91
95
|
const contractStore = new ContractStore(store);
|
|
@@ -97,29 +101,43 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
97
101
|
const capsuleStore = new CapsuleStore(store);
|
|
98
102
|
const keyStore = new KeyStore(store);
|
|
99
103
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
100
|
-
const
|
|
104
|
+
const contractSyncService = new ContractSyncService(node, contractStore, noteStore, createLogger('pxe:contract_sync', bindings));
|
|
105
|
+
const synchronizer = new BlockSynchronizer(node, store, anchorBlockStore, noteStore, privateEventStore, tipsStore, contractSyncService, config, bindings);
|
|
101
106
|
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
102
107
|
jobCoordinator.registerStores([
|
|
103
108
|
capsuleStore,
|
|
104
109
|
senderTaggingStore,
|
|
105
110
|
recipientTaggingStore,
|
|
106
111
|
privateEventStore,
|
|
107
|
-
noteStore
|
|
112
|
+
noteStore,
|
|
113
|
+
contractSyncService
|
|
108
114
|
]);
|
|
109
|
-
const debugUtils = new PXEDebugUtils(
|
|
115
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
110
116
|
const jobQueue = new SerialQueue();
|
|
111
|
-
const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils);
|
|
112
|
-
debugUtils.
|
|
117
|
+
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);
|
|
118
|
+
debugUtils.setPXEHelpers(pxe.#putInJobQueue.bind(pxe), pxe.#getSimulatorForTx.bind(pxe), pxe.#simulateUtility.bind(pxe));
|
|
113
119
|
pxe.jobQueue.start();
|
|
114
120
|
await pxe.#registerProtocolContracts();
|
|
115
|
-
const info = await node.getNodeInfo();
|
|
116
121
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
117
122
|
return pxe;
|
|
118
123
|
}
|
|
119
124
|
// Internal methods
|
|
120
125
|
#getSimulatorForTx(overrides) {
|
|
121
126
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
122
|
-
return new ContractFunctionSimulator(
|
|
127
|
+
return new ContractFunctionSimulator({
|
|
128
|
+
contractStore: proxyContractStore,
|
|
129
|
+
noteStore: this.noteStore,
|
|
130
|
+
keyStore: this.keyStore,
|
|
131
|
+
addressStore: this.addressStore,
|
|
132
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
133
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
134
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
135
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
136
|
+
capsuleStore: this.capsuleStore,
|
|
137
|
+
privateEventStore: this.privateEventStore,
|
|
138
|
+
simulator: this.simulator,
|
|
139
|
+
contractSyncService: this.contractSyncService
|
|
140
|
+
});
|
|
123
141
|
}
|
|
124
142
|
#contextualizeError(err, ...context) {
|
|
125
143
|
let contextStr = '';
|
|
@@ -175,10 +193,14 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
175
193
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
176
194
|
try {
|
|
177
195
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
178
|
-
await ensureContractSynced(contractAddress, functionSelector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [],
|
|
179
|
-
const result = await contractFunctionSimulator.run(txRequest,
|
|
180
|
-
|
|
181
|
-
|
|
196
|
+
await this.contractSyncService.ensureContractSynced(contractAddress, functionSelector, (privateSyncCall, execScopes)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
|
|
197
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
198
|
+
contractAddress,
|
|
199
|
+
selector: functionSelector,
|
|
200
|
+
anchorBlockHeader,
|
|
201
|
+
scopes,
|
|
202
|
+
jobId
|
|
203
|
+
});
|
|
182
204
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
183
205
|
return result;
|
|
184
206
|
} catch (err) {
|
|
@@ -252,7 +274,17 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
252
274
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
253
275
|
}
|
|
254
276
|
// Public API
|
|
255
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Returns the block header up to which the PXE has synced.
|
|
279
|
+
* @returns The synced block header
|
|
280
|
+
*/ getSyncedBlockHeader() {
|
|
281
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
285
|
+
* @param address - The contract address.
|
|
286
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
287
|
+
*/ getContractInstance(address) {
|
|
256
288
|
return this.contractStore.getContractInstance(address);
|
|
257
289
|
}
|
|
258
290
|
/**
|
|
@@ -419,10 +451,11 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
419
451
|
* (where validators prove the public portion).
|
|
420
452
|
*
|
|
421
453
|
* @param txRequest - An authenticated tx request ready for proving
|
|
454
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
422
455
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
423
456
|
* @throws If contract code not found, or public simulation reverts.
|
|
424
457
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
425
|
-
*/ proveTx(txRequest) {
|
|
458
|
+
*/ proveTx(txRequest, scopes) {
|
|
426
459
|
let privateExecutionResult;
|
|
427
460
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
428
461
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -433,7 +466,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
433
466
|
await this.blockStateSynchronizer.sync();
|
|
434
467
|
const syncTime = syncTimer.ms();
|
|
435
468
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
436
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
469
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
437
470
|
const { publicInputs, chonkProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
438
471
|
simulate: false,
|
|
439
472
|
skipFeeEnforcement: false,
|
|
@@ -483,13 +516,10 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
483
516
|
}
|
|
484
517
|
/**
|
|
485
518
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
486
|
-
*
|
|
487
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
488
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
489
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
519
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
490
520
|
* @returns A trace of the program execution with gate counts.
|
|
491
521
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
492
|
-
*/ profileTx(txRequest, profileMode, skipProofGeneration = true) {
|
|
522
|
+
*/ profileTx(txRequest, { profileMode, skipProofGeneration = true, scopes }) {
|
|
493
523
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
494
524
|
return this.#putInJobQueue(async (jobId)=>{
|
|
495
525
|
const totalTimer = new Timer();
|
|
@@ -507,7 +537,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
507
537
|
await this.blockStateSynchronizer.sync();
|
|
508
538
|
const syncTime = syncTimer.ms();
|
|
509
539
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
510
|
-
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
540
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
511
541
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
512
542
|
simulate: skipProofGeneration,
|
|
513
543
|
skipFeeEnforcement: false,
|
|
@@ -552,18 +582,13 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
552
582
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
553
583
|
*
|
|
554
584
|
*
|
|
555
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
556
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
557
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
558
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
559
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
560
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
585
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
561
586
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
562
587
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
563
588
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
564
589
|
*
|
|
565
590
|
* TODO(#7456) Prevent msgSender being defined here for the first call
|
|
566
|
-
*/ simulateTx(txRequest, simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes) {
|
|
591
|
+
*/ simulateTx(txRequest, { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }) {
|
|
567
592
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
568
593
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
569
594
|
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
@@ -586,13 +611,19 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
586
611
|
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
587
612
|
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
588
613
|
// or not.
|
|
589
|
-
const
|
|
614
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
615
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
616
|
+
const skipKernels = hasOverriddenContracts;
|
|
617
|
+
// Set overridden contracts on the sync service so it knows to skip syncing them
|
|
618
|
+
if (hasOverriddenContracts) {
|
|
619
|
+
this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
|
|
620
|
+
}
|
|
590
621
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
591
622
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
592
623
|
let publicInputs;
|
|
593
624
|
let executionSteps = [];
|
|
594
625
|
if (skipKernels) {
|
|
595
|
-
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, this.contractStore));
|
|
626
|
+
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), this.node));
|
|
596
627
|
} else {
|
|
597
628
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
598
629
|
({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
@@ -657,14 +688,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
657
688
|
});
|
|
658
689
|
}
|
|
659
690
|
/**
|
|
660
|
-
*
|
|
661
|
-
*
|
|
691
|
+
* Simulates the execution of a contract utility function.
|
|
662
692
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
663
|
-
|
|
664
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
665
|
-
* default to all.
|
|
666
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
667
|
-
*/ simulateUtility(call, authwits, scopes) {
|
|
693
|
+
*/ simulateUtility(call, { authwits, scopes } = {}) {
|
|
668
694
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
669
695
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
670
696
|
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
@@ -677,7 +703,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
677
703
|
const functionTimer = new Timer();
|
|
678
704
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
679
705
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
680
|
-
await ensureContractSynced(call.to, call.selector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [],
|
|
706
|
+
await this.contractSyncService.ensureContractSynced(call.to, call.selector, (privateSyncCall, execScopes)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
|
|
681
707
|
const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
|
|
682
708
|
const functionTime = functionTimer.ms();
|
|
683
709
|
const totalTime = totalTimer.ms();
|
|
@@ -727,7 +753,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
727
753
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
728
754
|
anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
729
755
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
730
|
-
await ensureContractSynced(filter.contractAddress, null, async (privateSyncCall)=>await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [],
|
|
756
|
+
await this.contractSyncService.ensureContractSynced(filter.contractAddress, null, async (privateSyncCall, execScopes)=>await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, filter.scopes);
|
|
731
757
|
});
|
|
732
758
|
// anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
|
|
733
759
|
const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber).validate(filter);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
-
import { FunctionSelector, FunctionType, contractArtifactFromBuffer, contractArtifactToBuffer, encodeArguments, getFunctionDebugMetadata } from '@aztec/stdlib/abi';
|
|
2
|
+
import { FunctionCall, FunctionSelector, FunctionType, contractArtifactFromBuffer, contractArtifactToBuffer, encodeArguments, getFunctionDebugMetadata } from '@aztec/stdlib/abi';
|
|
3
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import { SerializableContractInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
5
5
|
import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
@@ -219,15 +219,15 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
219
219
|
if (!functionDao) {
|
|
220
220
|
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
|
|
221
221
|
}
|
|
222
|
-
return {
|
|
222
|
+
return FunctionCall.from({
|
|
223
223
|
name: functionDao.name,
|
|
224
|
-
|
|
224
|
+
to,
|
|
225
225
|
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
226
226
|
type: functionDao.functionType,
|
|
227
|
-
to,
|
|
228
227
|
hideMsgSender: false,
|
|
229
228
|
isStatic: functionDao.isStatic,
|
|
229
|
+
args: encodeArguments(functionDao, args),
|
|
230
230
|
returnTypes: functionDao.returnTypes
|
|
231
|
-
};
|
|
231
|
+
});
|
|
232
232
|
}
|
|
233
233
|
}
|
|
@@ -35,7 +35,6 @@ export declare class NoteStore implements StagedStore {
|
|
|
35
35
|
* @params jobId - the job context to read from.
|
|
36
36
|
* @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
|
|
37
37
|
* returned once if this is the case)
|
|
38
|
-
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
39
38
|
*/
|
|
40
39
|
getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]>;
|
|
41
40
|
/**
|
|
@@ -80,4 +79,4 @@ export declare class NoteStore implements StagedStore {
|
|
|
80
79
|
commit(jobId: string): Promise<void>;
|
|
81
80
|
discardStaged(jobId: string): Promise<void>;
|
|
82
81
|
}
|
|
83
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
82
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm90ZV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2Uvbm90ZV9zdG9yZS9ub3RlX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLEVBQUUsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFxQyxNQUFNLGlCQUFpQixDQUFDO0FBQzVGLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQ3ZELE9BQU8sRUFBRSxPQUFPLEVBQWMsS0FBSyxXQUFXLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUUzRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSwwQ0FBMEMsQ0FBQztBQUc1RTs7Ozs7SUFLSTtBQUNKLHFCQUFhLFNBQVUsWUFBVyxXQUFXOztJQUMzQ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QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAarF;IAcD;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CA6F/D;IAED;;;;;;;;;;;;;;OAcG;IACH,eAAe,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAyChF;IAED;;;;;;;;;;;OAWG;IACU,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMpF;IA6ED;;;;;;;;;OASG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUzC;IAED,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG1C;CAkCF"}
|
|
@@ -74,10 +74,9 @@ import { StoredNote } from './stored_note.js';
|
|
|
74
74
|
* @params jobId - the job context to read from.
|
|
75
75
|
* @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
|
|
76
76
|
* returned once if this is the case)
|
|
77
|
-
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
78
77
|
*/ getNotes(filter, jobId) {
|
|
79
78
|
if (filter.scopes !== undefined && filter.scopes.length === 0) {
|
|
80
|
-
return Promise.
|
|
79
|
+
return Promise.resolve([]);
|
|
81
80
|
}
|
|
82
81
|
return this.#store.transactionAsync(async ()=>{
|
|
83
82
|
const targetStatus = filter.status ?? NoteStatus.ACTIVE;
|
|
@@ -173,6 +172,9 @@ import { StoredNote } from './stored_note.js';
|
|
|
173
172
|
if (nullifiers.length === 0) {
|
|
174
173
|
return Promise.resolve([]);
|
|
175
174
|
}
|
|
175
|
+
if (nullifiers.some((n)=>n.l2BlockNumber === 0)) {
|
|
176
|
+
return Promise.reject(new Error('applyNullifiers: nullifiers cannot have been emitted at block 0'));
|
|
177
|
+
}
|
|
176
178
|
return this.#withJobLock(jobId, ()=>this.#store.transactionAsync(async ()=>{
|
|
177
179
|
const notesToNullify = await Promise.all(nullifiers.map(async (nullifierInBlock)=>{
|
|
178
180
|
const nullifier = nullifierInBlock.data.toString();
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/pxe",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.08c5969dc",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"typedocOptions": {
|
|
6
|
+
"entryPoints": [
|
|
7
|
+
"./src/entrypoints/server/index.ts",
|
|
8
|
+
"./src/entrypoints/client/lazy/index.ts",
|
|
9
|
+
"./src/config/index.ts"
|
|
10
|
+
],
|
|
11
|
+
"name": "PXE",
|
|
12
|
+
"tsconfig": "./tsconfig.json"
|
|
13
|
+
},
|
|
5
14
|
"exports": {
|
|
6
15
|
"./server": "./dest/entrypoints/server/index.js",
|
|
7
16
|
"./client/lazy": "./dest/entrypoints/client/lazy/index.js",
|
|
@@ -61,19 +70,19 @@
|
|
|
61
70
|
]
|
|
62
71
|
},
|
|
63
72
|
"dependencies": {
|
|
64
|
-
"@aztec/bb-prover": "0.0.1-commit.
|
|
65
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
66
|
-
"@aztec/builder": "0.0.1-commit.
|
|
67
|
-
"@aztec/constants": "0.0.1-commit.
|
|
68
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
69
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
70
|
-
"@aztec/key-store": "0.0.1-commit.
|
|
71
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
72
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
73
|
-
"@aztec/noir-types": "0.0.1-commit.
|
|
74
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
75
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
76
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
73
|
+
"@aztec/bb-prover": "0.0.1-commit.08c5969dc",
|
|
74
|
+
"@aztec/bb.js": "0.0.1-commit.08c5969dc",
|
|
75
|
+
"@aztec/builder": "0.0.1-commit.08c5969dc",
|
|
76
|
+
"@aztec/constants": "0.0.1-commit.08c5969dc",
|
|
77
|
+
"@aztec/ethereum": "0.0.1-commit.08c5969dc",
|
|
78
|
+
"@aztec/foundation": "0.0.1-commit.08c5969dc",
|
|
79
|
+
"@aztec/key-store": "0.0.1-commit.08c5969dc",
|
|
80
|
+
"@aztec/kv-store": "0.0.1-commit.08c5969dc",
|
|
81
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.08c5969dc",
|
|
82
|
+
"@aztec/noir-types": "0.0.1-commit.08c5969dc",
|
|
83
|
+
"@aztec/protocol-contracts": "0.0.1-commit.08c5969dc",
|
|
84
|
+
"@aztec/simulator": "0.0.1-commit.08c5969dc",
|
|
85
|
+
"@aztec/stdlib": "0.0.1-commit.08c5969dc",
|
|
77
86
|
"koa": "^2.16.1",
|
|
78
87
|
"koa-router": "^13.1.1",
|
|
79
88
|
"lodash.omit": "^4.5.0",
|
|
@@ -82,8 +91,8 @@
|
|
|
82
91
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
83
92
|
},
|
|
84
93
|
"devDependencies": {
|
|
85
|
-
"@aztec/merkle-tree": "0.0.1-commit.
|
|
86
|
-
"@aztec/noir-test-contracts.js": "0.0.1-commit.
|
|
94
|
+
"@aztec/merkle-tree": "0.0.1-commit.08c5969dc",
|
|
95
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.08c5969dc",
|
|
87
96
|
"@jest/globals": "^30.0.0",
|
|
88
97
|
"@types/jest": "^30.0.0",
|
|
89
98
|
"@types/lodash.omit": "^4.5.7",
|
|
@@ -7,6 +7,7 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
|
7
7
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
8
8
|
|
|
9
9
|
import type { BlockSynchronizerConfig } from '../config/index.js';
|
|
10
|
+
import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
|
|
10
11
|
import type { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
|
|
11
12
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
12
13
|
import type { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
|
|
@@ -28,6 +29,7 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
28
29
|
private noteStore: NoteStore,
|
|
29
30
|
private privateEventStore: PrivateEventStore,
|
|
30
31
|
private l2TipsStore: L2TipsKVStore,
|
|
32
|
+
private contractSyncService: ContractSyncService,
|
|
31
33
|
private config: Partial<BlockSynchronizerConfig> = {},
|
|
32
34
|
bindings?: LoggerBindings,
|
|
33
35
|
) {
|
|
@@ -125,6 +127,10 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
125
127
|
|
|
126
128
|
/** Updates the anchor block header to the target block */
|
|
127
129
|
private async updateAnchorBlockHeader(blockHeader: BlockHeader) {
|
|
130
|
+
// Whenever the anchor block header is updated, we need to synchronize the private state of contracts again.
|
|
131
|
+
// Therefore, we clear the contract synchronization cache here such that the sync is re-triggered upon new
|
|
132
|
+
// execution.
|
|
133
|
+
this.contractSyncService.wipe();
|
|
128
134
|
this.log.verbose(`Updated pxe last block to ${blockHeader.getBlockNumber()}`, blockHeader.toInspect());
|
|
129
135
|
await this.anchorBlockStore.setHeader(blockHeader);
|
|
130
136
|
}
|