@aztec/pxe 0.72.1 → 0.74.0
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 +1 -3
- package/dest/contract_data_oracle/index.js +4 -4
- package/dest/contract_data_oracle/private_functions_tree.d.ts +7 -6
- package/dest/contract_data_oracle/private_functions_tree.d.ts.map +1 -1
- package/dest/contract_data_oracle/private_functions_tree.js +25 -14
- package/dest/database/kv_pxe_database.d.ts.map +1 -1
- package/dest/database/kv_pxe_database.js +6 -7
- package/dest/database/note_dao.d.ts +3 -3
- package/dest/database/note_dao.d.ts.map +1 -1
- package/dest/database/note_dao.js +3 -3
- package/dest/kernel_oracle/index.d.ts.map +1 -1
- package/dest/kernel_oracle/index.js +5 -5
- package/dest/kernel_prover/kernel_prover.js +5 -5
- package/dest/pxe_http/pxe_http_server.d.ts.map +1 -1
- package/dest/pxe_http/pxe_http_server.js +2 -1
- package/dest/pxe_service/error_enriching.js +4 -4
- package/dest/pxe_service/pxe_service.d.ts +12 -6
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +38 -29
- package/dest/pxe_service/test/pxe_test_suite.js +5 -5
- package/dest/simulator_oracle/index.d.ts.map +1 -1
- package/dest/simulator_oracle/index.js +8 -7
- package/dest/synchronizer/synchronizer.d.ts +2 -1
- package/dest/synchronizer/synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/synchronizer.js +6 -3
- package/package.json +14 -14
- package/src/bin/index.ts +0 -3
- package/src/contract_data_oracle/index.ts +3 -3
- package/src/contract_data_oracle/private_functions_tree.ts +28 -20
- package/src/database/kv_pxe_database.ts +13 -10
- package/src/database/note_dao.ts +2 -2
- package/src/kernel_oracle/index.ts +4 -4
- package/src/kernel_prover/kernel_prover.ts +4 -4
- package/src/pxe_http/pxe_http_server.ts +1 -0
- package/src/pxe_service/error_enriching.ts +3 -3
- package/src/pxe_service/pxe_service.ts +45 -21
- package/src/pxe_service/test/pxe_test_suite.ts +4 -4
- package/src/simulator_oracle/index.ts +8 -7
- package/src/synchronizer/synchronizer.ts +5 -2
|
@@ -100,10 +100,13 @@ export class PXEService implements PXE {
|
|
|
100
100
|
private proofCreator: PrivateKernelProver,
|
|
101
101
|
private simulationProvider: SimulationProvider,
|
|
102
102
|
config: PXEServiceConfig,
|
|
103
|
-
|
|
103
|
+
loggerOrSuffix?: string | Logger,
|
|
104
104
|
) {
|
|
105
|
-
this.log =
|
|
106
|
-
|
|
105
|
+
this.log =
|
|
106
|
+
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
107
|
+
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
108
|
+
: loggerOrSuffix;
|
|
109
|
+
this.synchronizer = new Synchronizer(node, db, tipsStore, config, loggerOrSuffix);
|
|
107
110
|
this.contractDataOracle = new ContractDataOracle(db);
|
|
108
111
|
this.simulator = getAcirSimulator(db, node, keyStore, this.simulationProvider, this.contractDataOracle);
|
|
109
112
|
this.packageVersion = getPackageInfo().version;
|
|
@@ -146,13 +149,33 @@ export class PXEService implements PXE {
|
|
|
146
149
|
return this.db.getContractInstance(address);
|
|
147
150
|
}
|
|
148
151
|
|
|
149
|
-
public async
|
|
152
|
+
public async getContractClassMetadata(
|
|
153
|
+
id: Fr,
|
|
154
|
+
includeArtifact: boolean = false,
|
|
155
|
+
): Promise<{
|
|
156
|
+
contractClass: ContractClassWithId | undefined;
|
|
157
|
+
isContractClassPubliclyRegistered: boolean;
|
|
158
|
+
artifact: ContractArtifact | undefined;
|
|
159
|
+
}> {
|
|
150
160
|
const artifact = await this.db.getContractArtifact(id);
|
|
151
|
-
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
contractClass: artifact && (await getContractClassFromArtifact(artifact)),
|
|
164
|
+
isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
|
|
165
|
+
artifact: includeArtifact ? artifact : undefined,
|
|
166
|
+
};
|
|
152
167
|
}
|
|
153
168
|
|
|
154
|
-
public
|
|
155
|
-
|
|
169
|
+
public async getContractMetadata(address: AztecAddress): Promise<{
|
|
170
|
+
contractInstance: ContractInstanceWithAddress | undefined;
|
|
171
|
+
isContractInitialized: boolean;
|
|
172
|
+
isContractPubliclyDeployed: boolean;
|
|
173
|
+
}> {
|
|
174
|
+
return {
|
|
175
|
+
contractInstance: await this.db.getContractInstance(address),
|
|
176
|
+
isContractInitialized: await this.#isContractInitialized(address),
|
|
177
|
+
isContractPubliclyDeployed: await this.#isContractPubliclyDeployed(address),
|
|
178
|
+
};
|
|
156
179
|
}
|
|
157
180
|
|
|
158
181
|
public async registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
|
|
@@ -217,7 +240,7 @@ export class PXEService implements PXE {
|
|
|
217
240
|
}
|
|
218
241
|
|
|
219
242
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
220
|
-
const contractClassId = computeContractClassId(getContractClassFromArtifact(artifact));
|
|
243
|
+
const contractClassId = await computeContractClassId(await getContractClassFromArtifact(artifact));
|
|
221
244
|
await this.db.addContractArtifact(contractClassId, artifact);
|
|
222
245
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
223
246
|
}
|
|
@@ -228,8 +251,8 @@ export class PXEService implements PXE {
|
|
|
228
251
|
|
|
229
252
|
if (artifact) {
|
|
230
253
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
231
|
-
const contractClass = getContractClassFromArtifact(artifact);
|
|
232
|
-
const contractClassId = computeContractClassId(contractClass);
|
|
254
|
+
const contractClass = await getContractClassFromArtifact(artifact);
|
|
255
|
+
const contractClassId = await computeContractClassId(contractClass);
|
|
233
256
|
if (!contractClassId.equals(instance.contractClassId)) {
|
|
234
257
|
throw new Error(
|
|
235
258
|
`Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.contractClassId})`,
|
|
@@ -341,7 +364,7 @@ export class PXEService implements PXE {
|
|
|
341
364
|
throw new Error('Note does not exist.');
|
|
342
365
|
}
|
|
343
366
|
|
|
344
|
-
const siloedNullifier = siloNullifier(note.contractAddress, innerNullifier!);
|
|
367
|
+
const siloedNullifier = await siloNullifier(note.contractAddress, innerNullifier!);
|
|
345
368
|
const [nullifierIndex] = await this.node.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [
|
|
346
369
|
siloedNullifier,
|
|
347
370
|
]);
|
|
@@ -434,7 +457,7 @@ export class PXEService implements PXE {
|
|
|
434
457
|
break;
|
|
435
458
|
}
|
|
436
459
|
|
|
437
|
-
const nonce = computeNoteHashNonce(firstNullifier, i);
|
|
460
|
+
const nonce = await computeNoteHashNonce(firstNullifier, i);
|
|
438
461
|
const { uniqueNoteHash } = await this.simulator.computeNoteHashAndOptionallyANullifier(
|
|
439
462
|
note.contractAddress,
|
|
440
463
|
nonce,
|
|
@@ -526,8 +549,9 @@ export class PXEService implements PXE {
|
|
|
526
549
|
}
|
|
527
550
|
}
|
|
528
551
|
|
|
529
|
-
|
|
530
|
-
|
|
552
|
+
const txHash = await simulatedTx.getTxHash();
|
|
553
|
+
this.log.info(`Simulation completed for ${txHash.toString()} in ${timer.ms()}ms`, {
|
|
554
|
+
txHash,
|
|
531
555
|
...txInfo,
|
|
532
556
|
...(profileResult ? { gateCounts: profileResult.gateCounts } : {}),
|
|
533
557
|
...(publicOutput
|
|
@@ -558,7 +582,7 @@ export class PXEService implements PXE {
|
|
|
558
582
|
}
|
|
559
583
|
|
|
560
584
|
public async sendTx(tx: Tx): Promise<TxHash> {
|
|
561
|
-
const txHash = tx.getTxHash();
|
|
585
|
+
const txHash = await tx.getTxHash();
|
|
562
586
|
if (await this.node.getTxEffect(txHash)) {
|
|
563
587
|
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
564
588
|
}
|
|
@@ -645,7 +669,7 @@ export class PXEService implements PXE {
|
|
|
645
669
|
return {
|
|
646
670
|
name: functionDao.name,
|
|
647
671
|
args: encodeArguments(functionDao, args),
|
|
648
|
-
selector: FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
672
|
+
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
649
673
|
type: functionDao.functionType,
|
|
650
674
|
to,
|
|
651
675
|
isStatic: functionDao.isStatic,
|
|
@@ -824,16 +848,16 @@ export class PXEService implements PXE {
|
|
|
824
848
|
});
|
|
825
849
|
}
|
|
826
850
|
|
|
827
|
-
|
|
851
|
+
async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
|
|
828
852
|
return !!(await this.node.getContractClass(id));
|
|
829
853
|
}
|
|
830
854
|
|
|
831
|
-
|
|
855
|
+
async #isContractPubliclyDeployed(address: AztecAddress): Promise<boolean> {
|
|
832
856
|
return !!(await this.node.getContract(address));
|
|
833
857
|
}
|
|
834
858
|
|
|
835
|
-
|
|
836
|
-
const initNullifier = siloNullifier(address, address.toField());
|
|
859
|
+
async #isContractInitialized(address: AztecAddress): Promise<boolean> {
|
|
860
|
+
const initNullifier = await siloNullifier(address, address.toField());
|
|
837
861
|
return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
|
|
838
862
|
}
|
|
839
863
|
|
|
@@ -866,7 +890,7 @@ export class PXEService implements PXE {
|
|
|
866
890
|
throw new Error('No registered account');
|
|
867
891
|
}
|
|
868
892
|
|
|
869
|
-
const preaddress = registeredAccount.getPreaddress();
|
|
893
|
+
const preaddress = await registeredAccount.getPreaddress();
|
|
870
894
|
|
|
871
895
|
secretKey = await computeAddressSecret(preaddress, secretKey);
|
|
872
896
|
}
|
|
@@ -47,22 +47,22 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
|
|
|
47
47
|
|
|
48
48
|
it('registers a class and adds a contract for it', async () => {
|
|
49
49
|
const artifact = randomContractArtifact();
|
|
50
|
-
const contractClass = getContractClassFromArtifact(artifact);
|
|
50
|
+
const contractClass = await getContractClassFromArtifact(artifact);
|
|
51
51
|
const contractClassId = contractClass.id;
|
|
52
52
|
const instance = await randomContractInstanceWithAddress({ contractClassId });
|
|
53
53
|
|
|
54
54
|
await pxe.registerContractClass(artifact);
|
|
55
|
-
expect(await pxe.
|
|
55
|
+
expect((await pxe.getContractClassMetadata(contractClassId)).contractClass).toMatchObject(
|
|
56
56
|
omit(contractClass, 'privateFunctionsRoot', 'publicBytecodeCommitment'),
|
|
57
57
|
);
|
|
58
58
|
|
|
59
59
|
await pxe.registerContract({ instance });
|
|
60
|
-
expect(await pxe.
|
|
60
|
+
expect((await pxe.getContractMetadata(instance.address)).contractInstance).toEqual(instance);
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
it('refuses to register a class with a mismatched address', async () => {
|
|
64
64
|
const artifact = randomContractArtifact();
|
|
65
|
-
const contractClass = getContractClassFromArtifact(artifact);
|
|
65
|
+
const contractClass = await getContractClassFromArtifact(artifact);
|
|
66
66
|
const contractClassId = contractClass.id;
|
|
67
67
|
const instance = await randomContractInstanceWithAddress({ contractClassId });
|
|
68
68
|
await expect(
|
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
encodeArguments,
|
|
40
40
|
getFunctionArtifact,
|
|
41
41
|
} from '@aztec/foundation/abi';
|
|
42
|
+
import { timesParallel } from '@aztec/foundation/collection';
|
|
42
43
|
import { poseidon2Hash } from '@aztec/foundation/crypto';
|
|
43
44
|
import { createLogger } from '@aztec/foundation/log';
|
|
44
45
|
import { type KeyStore } from '@aztec/key-store';
|
|
@@ -393,7 +394,7 @@ export class SimulatorOracle implements DBOracle {
|
|
|
393
394
|
let [numConsecutiveEmptyLogs, currentIndex] = [0, oldIndex];
|
|
394
395
|
do {
|
|
395
396
|
// We compute the tags for the current window of indexes
|
|
396
|
-
const currentTags =
|
|
397
|
+
const currentTags = await timesParallel(WINDOW_SIZE, i => {
|
|
397
398
|
const indexedAppTaggingSecret = new IndexedTaggingSecret(appTaggingSecret, currentIndex + i);
|
|
398
399
|
return indexedAppTaggingSecret.computeSiloedTag(recipient, contractAddress);
|
|
399
400
|
});
|
|
@@ -489,8 +490,8 @@ export class SimulatorOracle implements DBOracle {
|
|
|
489
490
|
|
|
490
491
|
while (secretsAndWindows.length > 0) {
|
|
491
492
|
const secretsForTheWholeWindow = getIndexedTaggingSecretsForTheWindow(secretsAndWindows);
|
|
492
|
-
const tagsForTheWholeWindow =
|
|
493
|
-
secret.computeSiloedTag(recipient, contractAddress),
|
|
493
|
+
const tagsForTheWholeWindow = await Promise.all(
|
|
494
|
+
secretsForTheWholeWindow.map(secret => secret.computeSiloedTag(recipient, contractAddress)),
|
|
494
495
|
);
|
|
495
496
|
|
|
496
497
|
// We store the new largest indexes we find in the iteration in the following map to later on construct
|
|
@@ -607,7 +608,7 @@ export class SimulatorOracle implements DBOracle {
|
|
|
607
608
|
const ivskM = await this.keyStore.getMasterSecretKey(
|
|
608
609
|
recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey,
|
|
609
610
|
);
|
|
610
|
-
const addressSecret = await computeAddressSecret(recipientCompleteAddress.getPreaddress(), ivskM);
|
|
611
|
+
const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
|
|
611
612
|
|
|
612
613
|
// Since we could have notes with the same index for different txs, we need
|
|
613
614
|
// to keep track of them scoping by txHash
|
|
@@ -753,8 +754,8 @@ export class SimulatorOracle implements DBOracle {
|
|
|
753
754
|
|
|
754
755
|
// Siloed and unique hashes are computed by us instead of relying on values sent by the contract to make sure
|
|
755
756
|
// we're not e.g. storing notes that belong to some other contract, which would constitute a security breach.
|
|
756
|
-
const uniqueNoteHash = computeUniqueNoteHash(nonce, siloNoteHash(contractAddress, noteHash));
|
|
757
|
-
const siloedNullifier = siloNullifier(contractAddress, nullifier);
|
|
757
|
+
const uniqueNoteHash = await computeUniqueNoteHash(nonce, await siloNoteHash(contractAddress, noteHash));
|
|
758
|
+
const siloedNullifier = await siloNullifier(contractAddress, nullifier);
|
|
758
759
|
|
|
759
760
|
// We store notes by their index in the global note hash tree, which has the convenient side effect of validating
|
|
760
761
|
// note existence in said tree. Note that while this is technically a historical query, we perform it at the latest
|
|
@@ -808,7 +809,7 @@ export class SimulatorOracle implements DBOracle {
|
|
|
808
809
|
const execRequest: FunctionCall = {
|
|
809
810
|
name: artifact.name,
|
|
810
811
|
to: contractAddress,
|
|
811
|
-
selector: FunctionSelector.fromNameAndParameters(artifact),
|
|
812
|
+
selector: await FunctionSelector.fromNameAndParameters(artifact),
|
|
812
813
|
type: FunctionType.UNCONSTRAINED,
|
|
813
814
|
isStatic: artifact.isStatic,
|
|
814
815
|
args: encodeArguments(artifact, [
|
|
@@ -27,9 +27,12 @@ export class Synchronizer implements L2BlockStreamEventHandler {
|
|
|
27
27
|
private db: PxeDatabase,
|
|
28
28
|
private l2TipsStore: L2TipsStore,
|
|
29
29
|
config: Partial<Pick<PXEConfig, 'l2StartingBlock'>> = {},
|
|
30
|
-
|
|
30
|
+
loggerOrSuffix?: string | Logger,
|
|
31
31
|
) {
|
|
32
|
-
this.log =
|
|
32
|
+
this.log =
|
|
33
|
+
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
34
|
+
? createLogger(loggerOrSuffix ? `pxe:synchronizer:${loggerOrSuffix}` : `pxe:synchronizer`)
|
|
35
|
+
: loggerOrSuffix;
|
|
33
36
|
this.blockStream = this.createBlockStream(config);
|
|
34
37
|
}
|
|
35
38
|
|