@aztec/pxe 0.0.1-commit.43597cc1 → 0.0.1-commit.4ad48494d
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/contract_function_simulator/contract_function_simulator.d.ts +51 -28
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +167 -63
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +2 -2
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +34 -36
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +71 -18
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +29 -12
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +31 -28
- package/dest/contract_sync/contract_sync_service.d.ts +3 -2
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +32 -17
- package/dest/debug/pxe_debug_utils.d.ts +1 -1
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +1 -1
- 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/utils.js +9 -1
- package/dest/logs/log_service.d.ts +1 -1
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +4 -9
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/pxe.d.ts +56 -22
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +38 -33
- 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 +1 -2
- package/package.json +16 -16
- package/src/contract_function_simulator/contract_function_simulator.ts +312 -119
- package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
- package/src/contract_function_simulator/oracle/oracle.ts +2 -2
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +91 -93
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +67 -25
- package/src/contract_sync/contract_sync_service.ts +41 -25
- package/src/debug/pxe_debug_utils.ts +3 -2
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/logs/log_service.ts +4 -13
- package/src/oracle_version.ts +2 -2
- package/src/pxe.ts +99 -70
- package/src/storage/note_store/note_store.ts +1 -2
package/src/pxe.ts
CHANGED
|
@@ -86,6 +86,56 @@ export type PackedPrivateEvent = InTx & {
|
|
|
86
86
|
eventSelector: EventSelector;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
+
/** Options for PXE.profileTx. */
|
|
90
|
+
export type ProfileTxOpts = {
|
|
91
|
+
/** The profiling mode to use. */
|
|
92
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
93
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
94
|
+
skipProofGeneration?: boolean;
|
|
95
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
96
|
+
scopes?: AztecAddress[];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** Options for PXE.simulateTx. */
|
|
100
|
+
export type SimulateTxOpts = {
|
|
101
|
+
/** Whether to simulate the public part of the transaction. */
|
|
102
|
+
simulatePublic: boolean;
|
|
103
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
104
|
+
skipTxValidation?: boolean;
|
|
105
|
+
/** If false, fees are enforced. */
|
|
106
|
+
skipFeeEnforcement?: boolean;
|
|
107
|
+
/** State overrides for the simulation, such as contract instances and artifacts. */
|
|
108
|
+
overrides?: SimulationOverrides;
|
|
109
|
+
/** Addresses whose private state and keys are accessible during private execution. Defaults to all. */
|
|
110
|
+
scopes?: AztecAddress[];
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** Options for PXE.simulateUtility. */
|
|
114
|
+
export type SimulateUtilityOpts = {
|
|
115
|
+
/** The authentication witnesses required for the function call. */
|
|
116
|
+
authwits?: AuthWitness[];
|
|
117
|
+
/** The accounts whose notes we can access in this call. Defaults to all. */
|
|
118
|
+
scopes?: AztecAddress[];
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** Args for PXE.create. */
|
|
122
|
+
export type PXECreateArgs = {
|
|
123
|
+
/** The Aztec node to connect to. */
|
|
124
|
+
node: AztecNode;
|
|
125
|
+
/** The key-value store for persisting PXE state. */
|
|
126
|
+
store: AztecAsyncKVStore;
|
|
127
|
+
/** The prover for generating private kernel proofs. */
|
|
128
|
+
proofCreator: PrivateKernelProver;
|
|
129
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
130
|
+
simulator: CircuitSimulator;
|
|
131
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
132
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
133
|
+
/** PXE configuration options. */
|
|
134
|
+
config: PXEConfig;
|
|
135
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
136
|
+
loggerOrSuffix?: string | Logger;
|
|
137
|
+
};
|
|
138
|
+
|
|
89
139
|
/**
|
|
90
140
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
91
141
|
* manage private state of users.
|
|
@@ -122,15 +172,15 @@ export class PXE {
|
|
|
122
172
|
*
|
|
123
173
|
* @returns A promise that resolves PXE is ready to be used.
|
|
124
174
|
*/
|
|
125
|
-
public static async create(
|
|
126
|
-
node
|
|
127
|
-
store
|
|
128
|
-
proofCreator
|
|
129
|
-
simulator
|
|
130
|
-
protocolContractsProvider
|
|
131
|
-
config
|
|
132
|
-
loggerOrSuffix
|
|
133
|
-
) {
|
|
175
|
+
public static async create({
|
|
176
|
+
node,
|
|
177
|
+
store,
|
|
178
|
+
proofCreator,
|
|
179
|
+
simulator,
|
|
180
|
+
protocolContractsProvider,
|
|
181
|
+
config,
|
|
182
|
+
loggerOrSuffix,
|
|
183
|
+
}: PXECreateArgs) {
|
|
134
184
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
135
185
|
const bindings: LoggerBindings | undefined =
|
|
136
186
|
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
@@ -140,7 +190,9 @@ export class PXE {
|
|
|
140
190
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
141
191
|
: loggerOrSuffix;
|
|
142
192
|
|
|
143
|
-
const
|
|
193
|
+
const info = await node.getNodeInfo();
|
|
194
|
+
|
|
195
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
144
196
|
const addressStore = new AddressStore(store);
|
|
145
197
|
const privateEventStore = new PrivateEventStore(store);
|
|
146
198
|
const contractStore = new ContractStore(store);
|
|
@@ -217,7 +269,6 @@ export class PXE {
|
|
|
217
269
|
pxe.jobQueue.start();
|
|
218
270
|
|
|
219
271
|
await pxe.#registerProtocolContracts();
|
|
220
|
-
const info = await node.getNodeInfo();
|
|
221
272
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
222
273
|
return pxe;
|
|
223
274
|
}
|
|
@@ -227,20 +278,20 @@ export class PXE {
|
|
|
227
278
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
228
279
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
229
280
|
|
|
230
|
-
return new ContractFunctionSimulator(
|
|
231
|
-
proxyContractStore,
|
|
232
|
-
this.noteStore,
|
|
233
|
-
this.keyStore,
|
|
234
|
-
this.addressStore,
|
|
235
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
236
|
-
this.senderTaggingStore,
|
|
237
|
-
this.recipientTaggingStore,
|
|
238
|
-
this.senderAddressBookStore,
|
|
239
|
-
this.capsuleStore,
|
|
240
|
-
this.privateEventStore,
|
|
241
|
-
this.simulator,
|
|
242
|
-
this.contractSyncService,
|
|
243
|
-
);
|
|
281
|
+
return new ContractFunctionSimulator({
|
|
282
|
+
contractStore: proxyContractStore,
|
|
283
|
+
noteStore: this.noteStore,
|
|
284
|
+
keyStore: this.keyStore,
|
|
285
|
+
addressStore: this.addressStore,
|
|
286
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
287
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
288
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
289
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
290
|
+
capsuleStore: this.capsuleStore,
|
|
291
|
+
privateEventStore: this.privateEventStore,
|
|
292
|
+
simulator: this.simulator,
|
|
293
|
+
contractSyncService: this.contractSyncService,
|
|
294
|
+
});
|
|
244
295
|
}
|
|
245
296
|
|
|
246
297
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -317,23 +368,20 @@ export class PXE {
|
|
|
317
368
|
await this.contractSyncService.ensureContractSynced(
|
|
318
369
|
contractAddress,
|
|
319
370
|
functionSelector,
|
|
320
|
-
|
|
371
|
+
(privateSyncCall, execScopes) =>
|
|
372
|
+
this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
321
373
|
anchorBlockHeader,
|
|
322
374
|
jobId,
|
|
375
|
+
scopes,
|
|
323
376
|
);
|
|
324
377
|
|
|
325
|
-
const result = await contractFunctionSimulator.run(
|
|
326
|
-
txRequest,
|
|
378
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
327
379
|
contractAddress,
|
|
328
|
-
functionSelector,
|
|
329
|
-
undefined,
|
|
380
|
+
selector: functionSelector,
|
|
330
381
|
anchorBlockHeader,
|
|
331
|
-
// The sender for tags is set by contracts, typically by an account
|
|
332
|
-
// contract entrypoint
|
|
333
|
-
undefined, // senderForTags
|
|
334
382
|
scopes,
|
|
335
383
|
jobId,
|
|
336
|
-
);
|
|
384
|
+
});
|
|
337
385
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
338
386
|
return result;
|
|
339
387
|
} catch (err) {
|
|
@@ -657,11 +705,12 @@ export class PXE {
|
|
|
657
705
|
* (where validators prove the public portion).
|
|
658
706
|
*
|
|
659
707
|
* @param txRequest - An authenticated tx request ready for proving
|
|
708
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
660
709
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
661
710
|
* @throws If contract code not found, or public simulation reverts.
|
|
662
711
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
663
712
|
*/
|
|
664
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
713
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
665
714
|
let privateExecutionResult: PrivateExecutionResult;
|
|
666
715
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
667
716
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -672,7 +721,7 @@ export class PXE {
|
|
|
672
721
|
await this.blockStateSynchronizer.sync();
|
|
673
722
|
const syncTime = syncTimer.ms();
|
|
674
723
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
675
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
724
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
676
725
|
|
|
677
726
|
const {
|
|
678
727
|
publicInputs,
|
|
@@ -736,17 +785,13 @@ export class PXE {
|
|
|
736
785
|
|
|
737
786
|
/**
|
|
738
787
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
739
|
-
*
|
|
740
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
741
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
742
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
788
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
743
789
|
* @returns A trace of the program execution with gate counts.
|
|
744
790
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
745
791
|
*/
|
|
746
792
|
public profileTx(
|
|
747
793
|
txRequest: TxExecutionRequest,
|
|
748
|
-
profileMode
|
|
749
|
-
skipProofGeneration: boolean = true,
|
|
794
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
750
795
|
): Promise<TxProfileResult> {
|
|
751
796
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
752
797
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -769,12 +814,7 @@ export class PXE {
|
|
|
769
814
|
const syncTime = syncTimer.ms();
|
|
770
815
|
|
|
771
816
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
772
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
773
|
-
contractFunctionSimulator,
|
|
774
|
-
txRequest,
|
|
775
|
-
undefined,
|
|
776
|
-
jobId,
|
|
777
|
-
);
|
|
817
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
778
818
|
|
|
779
819
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
780
820
|
txRequest,
|
|
@@ -831,12 +871,7 @@ export class PXE {
|
|
|
831
871
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
832
872
|
*
|
|
833
873
|
*
|
|
834
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
835
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
836
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
837
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
838
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
839
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
874
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
840
875
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
841
876
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
842
877
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -845,11 +880,7 @@ export class PXE {
|
|
|
845
880
|
*/
|
|
846
881
|
public simulateTx(
|
|
847
882
|
txRequest: TxExecutionRequest,
|
|
848
|
-
simulatePublic:
|
|
849
|
-
skipTxValidation: boolean = false,
|
|
850
|
-
skipFeeEnforcement: boolean = false,
|
|
851
|
-
overrides?: SimulationOverrides,
|
|
852
|
-
scopes?: AztecAddress[],
|
|
883
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
853
884
|
): Promise<TxSimulationResult> {
|
|
854
885
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
855
886
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -896,6 +927,7 @@ export class PXE {
|
|
|
896
927
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
897
928
|
privateExecutionResult,
|
|
898
929
|
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
930
|
+
this.node,
|
|
899
931
|
));
|
|
900
932
|
} else {
|
|
901
933
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -980,18 +1012,12 @@ export class PXE {
|
|
|
980
1012
|
}
|
|
981
1013
|
|
|
982
1014
|
/**
|
|
983
|
-
*
|
|
984
|
-
*
|
|
1015
|
+
* Simulates the execution of a contract utility function.
|
|
985
1016
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
986
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
987
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
988
|
-
* default to all.
|
|
989
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
990
1017
|
*/
|
|
991
1018
|
public simulateUtility(
|
|
992
1019
|
call: FunctionCall,
|
|
993
|
-
authwits
|
|
994
|
-
scopes?: AztecAddress[],
|
|
1020
|
+
{ authwits, scopes }: SimulateUtilityOpts = {},
|
|
995
1021
|
): Promise<UtilitySimulationResult> {
|
|
996
1022
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
997
1023
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -1009,9 +1035,11 @@ export class PXE {
|
|
|
1009
1035
|
await this.contractSyncService.ensureContractSynced(
|
|
1010
1036
|
call.to,
|
|
1011
1037
|
call.selector,
|
|
1012
|
-
|
|
1038
|
+
(privateSyncCall, execScopes) =>
|
|
1039
|
+
this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1013
1040
|
anchorBlockHeader,
|
|
1014
1041
|
jobId,
|
|
1042
|
+
scopes,
|
|
1015
1043
|
);
|
|
1016
1044
|
|
|
1017
1045
|
const executionResult = await this.#simulateUtility(
|
|
@@ -1078,10 +1106,11 @@ export class PXE {
|
|
|
1078
1106
|
await this.contractSyncService.ensureContractSynced(
|
|
1079
1107
|
filter.contractAddress,
|
|
1080
1108
|
null,
|
|
1081
|
-
async privateSyncCall =>
|
|
1082
|
-
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [],
|
|
1109
|
+
async (privateSyncCall, execScopes) =>
|
|
1110
|
+
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1083
1111
|
anchorBlockHeader,
|
|
1084
1112
|
jobId,
|
|
1113
|
+
filter.scopes,
|
|
1085
1114
|
);
|
|
1086
1115
|
});
|
|
1087
1116
|
|
|
@@ -103,11 +103,10 @@ export class NoteStore implements StagedStore {
|
|
|
103
103
|
* @params jobId - the job context to read from.
|
|
104
104
|
* @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
|
|
105
105
|
* returned once if this is the case)
|
|
106
|
-
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
107
106
|
*/
|
|
108
107
|
getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]> {
|
|
109
108
|
if (filter.scopes !== undefined && filter.scopes.length === 0) {
|
|
110
|
-
return Promise.
|
|
109
|
+
return Promise.resolve([]);
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
return this.#store.transactionAsync(async () => {
|