@aztec/pxe 0.66.0 → 0.67.1-devnet
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/index.js +5 -6
- package/dest/config/index.d.ts +0 -9
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -17
- package/dest/config/package_info.d.ts +5 -0
- package/dest/config/package_info.d.ts.map +1 -0
- package/dest/config/package_info.js +4 -0
- package/dest/contract_data_oracle/index.js +2 -2
- package/dest/database/incoming_note_dao.d.ts +1 -1
- package/dest/database/incoming_note_dao.d.ts.map +1 -1
- package/dest/database/incoming_note_dao.js +2 -2
- package/dest/database/kv_pxe_database.d.ts +10 -13
- package/dest/database/kv_pxe_database.d.ts.map +1 -1
- package/dest/database/kv_pxe_database.js +153 -230
- package/dest/database/outgoing_note_dao.js +2 -2
- package/dest/database/pxe_database.d.ts +7 -25
- package/dest/database/pxe_database.d.ts.map +1 -1
- package/dest/database/pxe_database_test_suite.d.ts.map +1 -1
- package/dest/database/pxe_database_test_suite.js +18 -59
- package/dest/index.d.ts +2 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -1
- package/dest/kernel_oracle/index.d.ts.map +1 -1
- package/dest/kernel_oracle/index.js +4 -4
- package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +2 -2
- package/dest/kernel_prover/index.d.ts +1 -0
- package/dest/kernel_prover/index.d.ts.map +1 -1
- package/dest/kernel_prover/index.js +2 -1
- package/dest/kernel_prover/kernel_prover.d.ts +1 -0
- package/dest/kernel_prover/kernel_prover.d.ts.map +1 -1
- package/dest/kernel_prover/kernel_prover.js +42 -5
- package/dest/kernel_prover/test/test_circuit_prover.d.ts +1 -2
- package/dest/kernel_prover/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/kernel_prover/test/test_circuit_prover.js +7 -13
- package/dest/note_decryption_utils/add_public_values_to_payload.js +2 -2
- package/dest/note_decryption_utils/brute_force_note_info.d.ts +3 -3
- package/dest/note_decryption_utils/brute_force_note_info.d.ts.map +1 -1
- package/dest/note_decryption_utils/brute_force_note_info.js +8 -8
- package/dest/note_decryption_utils/produce_note_daos.d.ts +3 -6
- package/dest/note_decryption_utils/produce_note_daos.d.ts.map +1 -1
- package/dest/note_decryption_utils/produce_note_daos.js +5 -19
- package/dest/note_decryption_utils/produce_note_daos_for_key.d.ts +1 -1
- package/dest/note_decryption_utils/produce_note_daos_for_key.d.ts.map +1 -1
- package/dest/pxe_service/error_enriching.d.ts +3 -3
- package/dest/pxe_service/error_enriching.d.ts.map +1 -1
- package/dest/pxe_service/error_enriching.js +10 -10
- package/dest/pxe_service/index.d.ts +0 -1
- package/dest/pxe_service/index.d.ts.map +1 -1
- package/dest/pxe_service/index.js +1 -2
- package/dest/pxe_service/pxe_service.d.ts +2 -16
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +74 -96
- package/dest/pxe_service/test/pxe_test_suite.d.ts.map +1 -1
- package/dest/pxe_service/test/pxe_test_suite.js +1 -3
- package/dest/simulator/index.d.ts +1 -1
- package/dest/simulator/index.d.ts.map +1 -1
- package/dest/simulator/index.js +2 -2
- package/dest/simulator_oracle/index.d.ts +14 -11
- package/dest/simulator_oracle/index.d.ts.map +1 -1
- package/dest/simulator_oracle/index.js +170 -140
- package/dest/simulator_oracle/tagging_utils.d.ts +15 -0
- package/dest/simulator_oracle/tagging_utils.d.ts.map +1 -0
- package/dest/simulator_oracle/tagging_utils.js +23 -0
- package/dest/synchronizer/synchronizer.d.ts +10 -40
- package/dest/synchronizer/synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/synchronizer.js +35 -69
- package/dest/{pxe_service → utils}/create_pxe_service.d.ts +1 -1
- package/dest/utils/create_pxe_service.d.ts.map +1 -0
- package/dest/utils/create_pxe_service.js +52 -0
- package/package.json +31 -19
- package/src/bin/index.ts +4 -5
- package/src/config/index.ts +0 -21
- package/src/config/package_info.ts +3 -0
- package/src/contract_data_oracle/index.ts +1 -1
- package/src/database/incoming_note_dao.ts +2 -2
- package/src/database/kv_pxe_database.ts +214 -309
- package/src/database/outgoing_note_dao.ts +1 -1
- package/src/database/pxe_database.ts +7 -28
- package/src/database/pxe_database_test_suite.ts +20 -75
- package/src/index.ts +2 -0
- package/src/kernel_oracle/index.ts +3 -3
- package/src/kernel_prover/hints/build_private_kernel_reset_private_inputs.ts +1 -1
- package/src/kernel_prover/index.ts +2 -0
- package/src/kernel_prover/kernel_prover.ts +72 -3
- package/src/kernel_prover/test/test_circuit_prover.ts +11 -25
- package/src/note_decryption_utils/add_public_values_to_payload.ts +1 -1
- package/src/note_decryption_utils/brute_force_note_info.ts +9 -9
- package/src/note_decryption_utils/produce_note_daos.ts +5 -48
- package/src/note_decryption_utils/produce_note_daos_for_key.ts +1 -1
- package/src/pxe_service/error_enriching.ts +14 -12
- package/src/pxe_service/index.ts +0 -1
- package/src/pxe_service/pxe_service.ts +127 -174
- package/src/pxe_service/test/pxe_test_suite.ts +0 -3
- package/src/simulator/index.ts +1 -1
- package/src/simulator_oracle/index.ts +201 -188
- package/src/simulator_oracle/tagging_utils.ts +28 -0
- package/src/synchronizer/synchronizer.ts +37 -77
- package/src/{pxe_service → utils}/create_pxe_service.ts +16 -13
- package/dest/pxe_service/create_pxe_service.d.ts.map +0 -1
- package/dest/pxe_service/create_pxe_service.js +0 -49
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
type L2Block,
|
|
13
13
|
type LogFilter,
|
|
14
14
|
MerkleTreeId,
|
|
15
|
-
type OutgoingNotesFilter,
|
|
16
15
|
type PXE,
|
|
17
16
|
type PXEInfo,
|
|
18
17
|
type PrivateExecutionResult,
|
|
@@ -56,20 +55,18 @@ import {
|
|
|
56
55
|
encodeArguments,
|
|
57
56
|
} from '@aztec/foundation/abi';
|
|
58
57
|
import { Fr, type Point } from '@aztec/foundation/fields';
|
|
59
|
-
import { type
|
|
60
|
-
import {
|
|
58
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
59
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
61
60
|
import { type KeyStore } from '@aztec/key-store';
|
|
62
61
|
import { type L2TipsStore } from '@aztec/kv-store/stores';
|
|
63
|
-
import {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
protocolContractNames,
|
|
67
|
-
} from '@aztec/protocol-contracts';
|
|
68
|
-
import { type AcirSimulator } from '@aztec/simulator';
|
|
62
|
+
import { ProtocolContractAddress, protocolContractNames } from '@aztec/protocol-contracts';
|
|
63
|
+
import { getCanonicalProtocolContract } from '@aztec/protocol-contracts/bundle';
|
|
64
|
+
import { type AcirSimulator } from '@aztec/simulator/client';
|
|
69
65
|
|
|
70
66
|
import { inspect } from 'util';
|
|
71
67
|
|
|
72
|
-
import { type PXEServiceConfig
|
|
68
|
+
import { type PXEServiceConfig } from '../config/index.js';
|
|
69
|
+
import { getPackageInfo } from '../config/package_info.js';
|
|
73
70
|
import { ContractDataOracle } from '../contract_data_oracle/index.js';
|
|
74
71
|
import { IncomingNoteDao } from '../database/incoming_note_dao.js';
|
|
75
72
|
import { type PxeDatabase } from '../database/index.js';
|
|
@@ -87,11 +84,8 @@ export class PXEService implements PXE {
|
|
|
87
84
|
private synchronizer: Synchronizer;
|
|
88
85
|
private contractDataOracle: ContractDataOracle;
|
|
89
86
|
private simulator: AcirSimulator;
|
|
90
|
-
private log:
|
|
87
|
+
private log: Logger;
|
|
91
88
|
private packageVersion: string;
|
|
92
|
-
// serialize synchronizer and calls to proveTx.
|
|
93
|
-
// ensures that state is not changed while simulating
|
|
94
|
-
private jobQueue = new SerialQueue();
|
|
95
89
|
|
|
96
90
|
constructor(
|
|
97
91
|
private keyStore: KeyStore,
|
|
@@ -102,13 +96,11 @@ export class PXEService implements PXE {
|
|
|
102
96
|
config: PXEServiceConfig,
|
|
103
97
|
logSuffix?: string,
|
|
104
98
|
) {
|
|
105
|
-
this.log =
|
|
99
|
+
this.log = createLogger(logSuffix ? `pxe:service:${logSuffix}` : `pxe:service`);
|
|
106
100
|
this.synchronizer = new Synchronizer(node, db, tipsStore, config, logSuffix);
|
|
107
101
|
this.contractDataOracle = new ContractDataOracle(db);
|
|
108
102
|
this.simulator = getAcirSimulator(db, node, keyStore, this.contractDataOracle);
|
|
109
103
|
this.packageVersion = getPackageInfo().version;
|
|
110
|
-
|
|
111
|
-
this.jobQueue.start();
|
|
112
104
|
}
|
|
113
105
|
|
|
114
106
|
/**
|
|
@@ -116,27 +108,12 @@ export class PXEService implements PXE {
|
|
|
116
108
|
*
|
|
117
109
|
* @returns A promise that resolves when the server has started successfully.
|
|
118
110
|
*/
|
|
119
|
-
public async
|
|
120
|
-
await this.synchronizer.start();
|
|
111
|
+
public async init() {
|
|
121
112
|
await this.#registerProtocolContracts();
|
|
122
113
|
const info = await this.getNodeInfo();
|
|
123
114
|
this.log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.protocolVersion}`);
|
|
124
115
|
}
|
|
125
116
|
|
|
126
|
-
/**
|
|
127
|
-
* Stops the PXE Service, halting processing of new transactions and shutting down the synchronizer.
|
|
128
|
-
* This function ensures that all ongoing tasks are completed before stopping the server.
|
|
129
|
-
* It is useful for gracefully shutting down the server during maintenance or restarts.
|
|
130
|
-
*
|
|
131
|
-
* @returns A Promise resolving once the server has been stopped successfully.
|
|
132
|
-
*/
|
|
133
|
-
public async stop() {
|
|
134
|
-
await this.jobQueue.cancel();
|
|
135
|
-
this.log.info('Cancelled Job Queue');
|
|
136
|
-
await this.synchronizer.stop();
|
|
137
|
-
this.log.info('Stopped Synchronizer');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
117
|
isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
|
|
141
118
|
return this.node.isL1ToL2MessageSynced(l1ToL2Message);
|
|
142
119
|
}
|
|
@@ -320,33 +297,6 @@ export class PXEService implements PXE {
|
|
|
320
297
|
return Promise.all(extendedNotes);
|
|
321
298
|
}
|
|
322
299
|
|
|
323
|
-
public async getOutgoingNotes(filter: OutgoingNotesFilter): Promise<UniqueNote[]> {
|
|
324
|
-
const noteDaos = await this.db.getOutgoingNotes(filter);
|
|
325
|
-
|
|
326
|
-
const extendedNotes = noteDaos.map(async dao => {
|
|
327
|
-
let owner = filter.owner;
|
|
328
|
-
if (owner === undefined) {
|
|
329
|
-
const completeAddresses = (await this.db.getCompleteAddresses()).find(address =>
|
|
330
|
-
address.publicKeys.masterOutgoingViewingPublicKey.equals(dao.ovpkM),
|
|
331
|
-
);
|
|
332
|
-
if (completeAddresses === undefined) {
|
|
333
|
-
throw new Error(`Cannot find complete address for OvpkM ${dao.ovpkM.toString()}`);
|
|
334
|
-
}
|
|
335
|
-
owner = completeAddresses.address;
|
|
336
|
-
}
|
|
337
|
-
return new UniqueNote(
|
|
338
|
-
dao.note,
|
|
339
|
-
owner,
|
|
340
|
-
dao.contractAddress,
|
|
341
|
-
dao.storageSlot,
|
|
342
|
-
dao.noteTypeId,
|
|
343
|
-
dao.txHash,
|
|
344
|
-
dao.nonce,
|
|
345
|
-
);
|
|
346
|
-
});
|
|
347
|
-
return Promise.all(extendedNotes);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
300
|
public async getL1ToL2MembershipWitness(
|
|
351
301
|
contractAddress: AztecAddress,
|
|
352
302
|
messageHash: Fr,
|
|
@@ -367,7 +317,7 @@ export class PXEService implements PXE {
|
|
|
367
317
|
}
|
|
368
318
|
|
|
369
319
|
for (const nonce of nonces) {
|
|
370
|
-
const { noteHash,
|
|
320
|
+
const { noteHash, uniqueNoteHash, innerNullifier } = await this.simulator.computeNoteHashAndOptionallyANullifier(
|
|
371
321
|
note.contractAddress,
|
|
372
322
|
nonce,
|
|
373
323
|
note.storageSlot,
|
|
@@ -376,7 +326,7 @@ export class PXEService implements PXE {
|
|
|
376
326
|
note.note,
|
|
377
327
|
);
|
|
378
328
|
|
|
379
|
-
const [index] = await this.node.findLeavesIndexes('latest', MerkleTreeId.NOTE_HASH_TREE, [
|
|
329
|
+
const [index] = await this.node.findLeavesIndexes('latest', MerkleTreeId.NOTE_HASH_TREE, [uniqueNoteHash]);
|
|
380
330
|
if (index === undefined) {
|
|
381
331
|
throw new Error('Note does not exist.');
|
|
382
332
|
}
|
|
@@ -416,7 +366,7 @@ export class PXEService implements PXE {
|
|
|
416
366
|
}
|
|
417
367
|
|
|
418
368
|
for (const nonce of nonces) {
|
|
419
|
-
const { noteHash,
|
|
369
|
+
const { noteHash, uniqueNoteHash, innerNullifier } = await this.simulator.computeNoteHashAndOptionallyANullifier(
|
|
420
370
|
note.contractAddress,
|
|
421
371
|
nonce,
|
|
422
372
|
note.storageSlot,
|
|
@@ -429,7 +379,7 @@ export class PXEService implements PXE {
|
|
|
429
379
|
throw new Error('Unexpectedly received non-zero nullifier.');
|
|
430
380
|
}
|
|
431
381
|
|
|
432
|
-
const [index] = await this.node.findLeavesIndexes('latest', MerkleTreeId.NOTE_HASH_TREE, [
|
|
382
|
+
const [index] = await this.node.findLeavesIndexes('latest', MerkleTreeId.NOTE_HASH_TREE, [uniqueNoteHash]);
|
|
433
383
|
if (index === undefined) {
|
|
434
384
|
throw new Error('Note does not exist.');
|
|
435
385
|
}
|
|
@@ -475,7 +425,7 @@ export class PXEService implements PXE {
|
|
|
475
425
|
}
|
|
476
426
|
|
|
477
427
|
const nonce = computeNoteHashNonce(firstNullifier, i);
|
|
478
|
-
const {
|
|
428
|
+
const { uniqueNoteHash } = await this.simulator.computeNoteHashAndOptionallyANullifier(
|
|
479
429
|
note.contractAddress,
|
|
480
430
|
nonce,
|
|
481
431
|
note.storageSlot,
|
|
@@ -483,7 +433,7 @@ export class PXEService implements PXE {
|
|
|
483
433
|
false,
|
|
484
434
|
note.note,
|
|
485
435
|
);
|
|
486
|
-
if (hash.equals(
|
|
436
|
+
if (hash.equals(uniqueNoteHash)) {
|
|
487
437
|
nonces.push(nonce);
|
|
488
438
|
}
|
|
489
439
|
}
|
|
@@ -511,22 +461,16 @@ export class PXEService implements PXE {
|
|
|
511
461
|
return result.publicInputs;
|
|
512
462
|
}
|
|
513
463
|
|
|
514
|
-
public proveTx(
|
|
464
|
+
public async proveTx(
|
|
515
465
|
txRequest: TxExecutionRequest,
|
|
516
466
|
privateExecutionResult: PrivateExecutionResult,
|
|
517
467
|
): Promise<TxProvingResult> {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
);
|
|
525
|
-
return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof!);
|
|
526
|
-
})
|
|
527
|
-
.catch(err => {
|
|
528
|
-
throw this.contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
|
|
529
|
-
});
|
|
468
|
+
try {
|
|
469
|
+
const { publicInputs, clientIvcProof } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult);
|
|
470
|
+
return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof!);
|
|
471
|
+
} catch (err: any) {
|
|
472
|
+
throw this.contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
|
|
473
|
+
}
|
|
530
474
|
}
|
|
531
475
|
|
|
532
476
|
// TODO(#7456) Prevent msgSender being defined here for the first call
|
|
@@ -538,59 +482,78 @@ export class PXEService implements PXE {
|
|
|
538
482
|
profile: boolean = false,
|
|
539
483
|
scopes?: AztecAddress[],
|
|
540
484
|
): Promise<TxSimulationResult> {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
485
|
+
try {
|
|
486
|
+
const txInfo = {
|
|
487
|
+
origin: txRequest.origin,
|
|
488
|
+
functionSelector: txRequest.functionSelector,
|
|
489
|
+
simulatePublic,
|
|
490
|
+
msgSender,
|
|
491
|
+
chainId: txRequest.txContext.chainId,
|
|
492
|
+
version: txRequest.txContext.version,
|
|
493
|
+
authWitnesses: txRequest.authWitnesses.map(w => w.requestHash),
|
|
494
|
+
};
|
|
495
|
+
this.log.info(
|
|
496
|
+
`Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`,
|
|
497
|
+
txInfo,
|
|
498
|
+
);
|
|
499
|
+
const timer = new Timer();
|
|
500
|
+
await this.synchronizer.sync();
|
|
501
|
+
const privateExecutionResult = await this.#executePrivate(txRequest, msgSender, scopes);
|
|
502
|
+
|
|
503
|
+
let publicInputs: PrivateKernelTailCircuitPublicInputs;
|
|
504
|
+
let profileResult;
|
|
505
|
+
if (profile) {
|
|
506
|
+
({ publicInputs, profileResult } = await this.#profileKernelProver(
|
|
507
|
+
txRequest,
|
|
508
|
+
this.proofCreator,
|
|
509
|
+
privateExecutionResult,
|
|
510
|
+
));
|
|
511
|
+
} else {
|
|
512
|
+
publicInputs = await this.#simulateKernels(txRequest, privateExecutionResult);
|
|
513
|
+
}
|
|
556
514
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
515
|
+
const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
|
|
516
|
+
const simulatedTx = privateSimulationResult.toSimulatedTx();
|
|
517
|
+
let publicOutput: PublicSimulationOutput | undefined;
|
|
518
|
+
if (simulatePublic) {
|
|
519
|
+
publicOutput = await this.#simulatePublicCalls(simulatedTx);
|
|
520
|
+
}
|
|
563
521
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
522
|
+
if (!skipTxValidation) {
|
|
523
|
+
if (!(await this.node.isValidTx(simulatedTx, true))) {
|
|
524
|
+
throw new Error('The simulated transaction is unable to be added to state and is invalid.');
|
|
568
525
|
}
|
|
526
|
+
}
|
|
569
527
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
);
|
|
582
|
-
})
|
|
583
|
-
.catch(err => {
|
|
584
|
-
throw this.contextualizeError(
|
|
585
|
-
err,
|
|
586
|
-
inspect(txRequest),
|
|
587
|
-
`simulatePublic=${simulatePublic}`,
|
|
588
|
-
`msgSender=${msgSender?.toString() ?? 'undefined'}`,
|
|
589
|
-
`skipTxValidation=${skipTxValidation}`,
|
|
590
|
-
`profile=${profile}`,
|
|
591
|
-
`scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
|
|
592
|
-
);
|
|
528
|
+
this.log.info(`Simulation completed for ${simulatedTx.tryGetTxHash()} in ${timer.ms()}ms`, {
|
|
529
|
+
txHash: simulatedTx.tryGetTxHash(),
|
|
530
|
+
...txInfo,
|
|
531
|
+
...(profileResult ? { gateCounts: profileResult.gateCounts } : {}),
|
|
532
|
+
...(publicOutput
|
|
533
|
+
? {
|
|
534
|
+
gasUsed: publicOutput.gasUsed,
|
|
535
|
+
revertCode: publicOutput.txEffect.revertCode.getCode(),
|
|
536
|
+
revertReason: publicOutput.revertReason,
|
|
537
|
+
}
|
|
538
|
+
: {}),
|
|
593
539
|
});
|
|
540
|
+
|
|
541
|
+
return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput(
|
|
542
|
+
privateSimulationResult,
|
|
543
|
+
publicOutput,
|
|
544
|
+
profileResult,
|
|
545
|
+
);
|
|
546
|
+
} catch (err: any) {
|
|
547
|
+
throw this.contextualizeError(
|
|
548
|
+
err,
|
|
549
|
+
inspect(txRequest),
|
|
550
|
+
`simulatePublic=${simulatePublic}`,
|
|
551
|
+
`msgSender=${msgSender?.toString() ?? 'undefined'}`,
|
|
552
|
+
`skipTxValidation=${skipTxValidation}`,
|
|
553
|
+
`profile=${profile}`,
|
|
554
|
+
`scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
|
|
555
|
+
);
|
|
556
|
+
}
|
|
594
557
|
}
|
|
595
558
|
|
|
596
559
|
public async sendTx(tx: Tx): Promise<TxHash> {
|
|
@@ -598,7 +561,7 @@ export class PXEService implements PXE {
|
|
|
598
561
|
if (await this.node.getTxEffect(txHash)) {
|
|
599
562
|
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
600
563
|
}
|
|
601
|
-
this.log.
|
|
564
|
+
this.log.debug(`Sending transaction ${txHash}`);
|
|
602
565
|
await this.node.sendTx(tx).catch(err => {
|
|
603
566
|
throw this.contextualizeError(err, inspect(tx));
|
|
604
567
|
});
|
|
@@ -613,24 +576,22 @@ export class PXEService implements PXE {
|
|
|
613
576
|
_from?: AztecAddress,
|
|
614
577
|
scopes?: AztecAddress[],
|
|
615
578
|
): Promise<AbiDecoded> {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
.
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
);
|
|
633
|
-
});
|
|
579
|
+
try {
|
|
580
|
+
await this.synchronizer.sync();
|
|
581
|
+
// TODO - Should check if `from` has the permission to call the view function.
|
|
582
|
+
const functionCall = await this.#getFunctionCall(functionName, args, to);
|
|
583
|
+
const executionResult = await this.#simulateUnconstrained(functionCall, scopes);
|
|
584
|
+
|
|
585
|
+
// TODO - Return typed result based on the function artifact.
|
|
586
|
+
return executionResult;
|
|
587
|
+
} catch (err: any) {
|
|
588
|
+
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
589
|
+
throw this.contextualizeError(
|
|
590
|
+
err,
|
|
591
|
+
`simulateUnconstrained ${to}:${functionName}(${stringifiedArgs})`,
|
|
592
|
+
`scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
|
|
593
|
+
);
|
|
594
|
+
}
|
|
634
595
|
}
|
|
635
596
|
|
|
636
597
|
public getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
@@ -727,12 +688,14 @@ export class PXEService implements PXE {
|
|
|
727
688
|
}
|
|
728
689
|
|
|
729
690
|
async #registerProtocolContracts() {
|
|
691
|
+
const registered: Record<string, string> = {};
|
|
730
692
|
for (const name of protocolContractNames) {
|
|
731
693
|
const { address, contractClass, instance, artifact } = getCanonicalProtocolContract(name);
|
|
732
694
|
await this.db.addContractArtifact(contractClass.id, artifact);
|
|
733
695
|
await this.db.addContractInstance(instance);
|
|
734
|
-
|
|
696
|
+
registered[name] = address.toString();
|
|
735
697
|
}
|
|
698
|
+
this.log.verbose(`Registered protocol contracts in pxe`, registered);
|
|
736
699
|
}
|
|
737
700
|
|
|
738
701
|
/**
|
|
@@ -764,13 +727,11 @@ export class PXEService implements PXE {
|
|
|
764
727
|
scopes?: AztecAddress[],
|
|
765
728
|
): Promise<PrivateExecutionResult> {
|
|
766
729
|
// TODO - Pause syncing while simulating.
|
|
767
|
-
|
|
768
730
|
const { contractAddress, functionArtifact } = await this.#getSimulationParameters(txRequest);
|
|
769
731
|
|
|
770
|
-
this.log.debug('Executing simulator...');
|
|
771
732
|
try {
|
|
772
733
|
const result = await this.simulator.run(txRequest, functionArtifact, contractAddress, msgSender, scopes);
|
|
773
|
-
this.log.
|
|
734
|
+
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionArtifact.name}`);
|
|
774
735
|
return result;
|
|
775
736
|
} catch (err) {
|
|
776
737
|
if (err instanceof SimulationError) {
|
|
@@ -848,19 +809,14 @@ export class PXEService implements PXE {
|
|
|
848
809
|
}
|
|
849
810
|
|
|
850
811
|
/**
|
|
851
|
-
*
|
|
852
|
-
* The function takes in a transaction request,
|
|
853
|
-
*
|
|
854
|
-
* transaction object with the generated proof and public inputs. If a new contract address is provided,
|
|
855
|
-
* the function will also include the new contract's public functions in the transaction object.
|
|
812
|
+
* Generate a kernel proof, and create a private kernel output.
|
|
813
|
+
* The function takes in a transaction execution request, and the result of private execution
|
|
814
|
+
* and then generates a kernel proof.
|
|
856
815
|
*
|
|
857
816
|
* @param txExecutionRequest - The transaction request to be simulated and proved.
|
|
858
817
|
* @param proofCreator - The proof creator to use for proving the execution.
|
|
859
|
-
* @param
|
|
860
|
-
* @
|
|
861
|
-
* @returns An object that contains:
|
|
862
|
-
* A private transaction object containing the proof, public inputs, and encrypted logs.
|
|
863
|
-
* The return values of the private execution
|
|
818
|
+
* @param privateExecutionResult - The result of the private execution
|
|
819
|
+
* @returns An object that contains the output of the kernel execution, including the ClientIvcProof if proving is enabled.
|
|
864
820
|
*/
|
|
865
821
|
async #prove(
|
|
866
822
|
txExecutionRequest: TxExecutionRequest,
|
|
@@ -875,14 +831,6 @@ export class PXEService implements PXE {
|
|
|
875
831
|
return await kernelProver.prove(txExecutionRequest.toTxRequest(), privateExecutionResult);
|
|
876
832
|
}
|
|
877
833
|
|
|
878
|
-
public async isGlobalStateSynchronized() {
|
|
879
|
-
return await this.synchronizer.isGlobalStateSynchronized();
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
public getSyncStatus() {
|
|
883
|
-
return Promise.resolve(this.synchronizer.getSyncStatus());
|
|
884
|
-
}
|
|
885
|
-
|
|
886
834
|
public async isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
|
|
887
835
|
return !!(await this.node.getContractClass(id));
|
|
888
836
|
}
|
|
@@ -915,7 +863,7 @@ export class PXEService implements PXE {
|
|
|
915
863
|
|
|
916
864
|
const vsks = await Promise.all(
|
|
917
865
|
vpks.map(async vpk => {
|
|
918
|
-
const [keyPrefix, account] = this.keyStore.getKeyPrefixAndAccount(vpk);
|
|
866
|
+
const [keyPrefix, account] = await this.keyStore.getKeyPrefixAndAccount(vpk);
|
|
919
867
|
let secretKey = await this.keyStore.getMasterSecretKey(vpk);
|
|
920
868
|
if (keyPrefix === 'iv') {
|
|
921
869
|
const registeredAccount = await this.getRegisteredAccount(account);
|
|
@@ -936,7 +884,7 @@ export class PXEService implements PXE {
|
|
|
936
884
|
for (const sk of vsks) {
|
|
937
885
|
// TODO: Verify that the first field of the log is the tag siloed with contract address.
|
|
938
886
|
// Or use tags to query logs, like we do with notes.
|
|
939
|
-
const decryptedEvent = L1EventPayload.decryptAsIncoming(log, sk)
|
|
887
|
+
const decryptedEvent = L1EventPayload.decryptAsIncoming(log, sk);
|
|
940
888
|
if (decryptedEvent !== undefined) {
|
|
941
889
|
return [decryptedEvent];
|
|
942
890
|
}
|
|
@@ -1003,10 +951,15 @@ export class PXEService implements PXE {
|
|
|
1003
951
|
}
|
|
1004
952
|
|
|
1005
953
|
private contextualizeError(err: Error, ...context: string[]): Error {
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
954
|
+
let contextStr = '';
|
|
955
|
+
if (context.length > 0) {
|
|
956
|
+
contextStr = `\nContext:\n${context.join('\n')}`;
|
|
957
|
+
}
|
|
958
|
+
if (err instanceof SimulationError) {
|
|
959
|
+
err.setAztecContext(contextStr);
|
|
960
|
+
} else {
|
|
961
|
+
this.log.error(err.name, err);
|
|
962
|
+
this.log.debug(contextStr);
|
|
1010
963
|
}
|
|
1011
964
|
return err;
|
|
1012
965
|
}
|
|
@@ -115,8 +115,5 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
|
|
|
115
115
|
expect(typeof nodeInfo.l1ChainId).toEqual('number');
|
|
116
116
|
expect(nodeInfo.l1ContractAddresses.rollupAddress.toString()).toMatch(/0x[a-fA-F0-9]+/);
|
|
117
117
|
});
|
|
118
|
-
|
|
119
|
-
// Note: Not testing `isGlobalStateSynchronized`, `isAccountStateSynchronized` and `getSyncStatus` as these methods
|
|
120
|
-
// only call synchronizer.
|
|
121
118
|
});
|
|
122
119
|
};
|
package/src/simulator/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AztecNode } from '@aztec/circuit-types';
|
|
2
2
|
import { type KeyStore } from '@aztec/key-store';
|
|
3
|
-
import { AcirSimulator } from '@aztec/simulator';
|
|
3
|
+
import { AcirSimulator } from '@aztec/simulator/client';
|
|
4
4
|
|
|
5
5
|
import { ContractDataOracle } from '../contract_data_oracle/index.js';
|
|
6
6
|
import { type PxeDatabase } from '../database/pxe_database.js';
|