@aztec/pxe 0.72.1 → 0.73.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 +10 -5
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +32 -26
- 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/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 +39 -18
- package/src/pxe_service/test/pxe_test_suite.ts +4 -4
- package/src/simulator_oracle/index.ts +8 -7
|
@@ -146,13 +146,33 @@ export class PXEService implements PXE {
|
|
|
146
146
|
return this.db.getContractInstance(address);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
public async
|
|
149
|
+
public async getContractClassMetadata(
|
|
150
|
+
id: Fr,
|
|
151
|
+
includeArtifact: boolean = false,
|
|
152
|
+
): Promise<{
|
|
153
|
+
contractClass: ContractClassWithId | undefined;
|
|
154
|
+
isContractClassPubliclyRegistered: boolean;
|
|
155
|
+
artifact: ContractArtifact | undefined;
|
|
156
|
+
}> {
|
|
150
157
|
const artifact = await this.db.getContractArtifact(id);
|
|
151
|
-
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
contractClass: artifact && (await getContractClassFromArtifact(artifact)),
|
|
161
|
+
isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
|
|
162
|
+
artifact: includeArtifact ? artifact : undefined,
|
|
163
|
+
};
|
|
152
164
|
}
|
|
153
165
|
|
|
154
|
-
public
|
|
155
|
-
|
|
166
|
+
public async getContractMetadata(address: AztecAddress): Promise<{
|
|
167
|
+
contractInstance: ContractInstanceWithAddress | undefined;
|
|
168
|
+
isContractInitialized: boolean;
|
|
169
|
+
isContractPubliclyDeployed: boolean;
|
|
170
|
+
}> {
|
|
171
|
+
return {
|
|
172
|
+
contractInstance: await this.db.getContractInstance(address),
|
|
173
|
+
isContractInitialized: await this.#isContractInitialized(address),
|
|
174
|
+
isContractPubliclyDeployed: await this.#isContractPubliclyDeployed(address),
|
|
175
|
+
};
|
|
156
176
|
}
|
|
157
177
|
|
|
158
178
|
public async registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
|
|
@@ -217,7 +237,7 @@ export class PXEService implements PXE {
|
|
|
217
237
|
}
|
|
218
238
|
|
|
219
239
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
220
|
-
const contractClassId = computeContractClassId(getContractClassFromArtifact(artifact));
|
|
240
|
+
const contractClassId = await computeContractClassId(await getContractClassFromArtifact(artifact));
|
|
221
241
|
await this.db.addContractArtifact(contractClassId, artifact);
|
|
222
242
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
223
243
|
}
|
|
@@ -228,8 +248,8 @@ export class PXEService implements PXE {
|
|
|
228
248
|
|
|
229
249
|
if (artifact) {
|
|
230
250
|
// 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);
|
|
251
|
+
const contractClass = await getContractClassFromArtifact(artifact);
|
|
252
|
+
const contractClassId = await computeContractClassId(contractClass);
|
|
233
253
|
if (!contractClassId.equals(instance.contractClassId)) {
|
|
234
254
|
throw new Error(
|
|
235
255
|
`Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.contractClassId})`,
|
|
@@ -341,7 +361,7 @@ export class PXEService implements PXE {
|
|
|
341
361
|
throw new Error('Note does not exist.');
|
|
342
362
|
}
|
|
343
363
|
|
|
344
|
-
const siloedNullifier = siloNullifier(note.contractAddress, innerNullifier!);
|
|
364
|
+
const siloedNullifier = await siloNullifier(note.contractAddress, innerNullifier!);
|
|
345
365
|
const [nullifierIndex] = await this.node.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [
|
|
346
366
|
siloedNullifier,
|
|
347
367
|
]);
|
|
@@ -434,7 +454,7 @@ export class PXEService implements PXE {
|
|
|
434
454
|
break;
|
|
435
455
|
}
|
|
436
456
|
|
|
437
|
-
const nonce = computeNoteHashNonce(firstNullifier, i);
|
|
457
|
+
const nonce = await computeNoteHashNonce(firstNullifier, i);
|
|
438
458
|
const { uniqueNoteHash } = await this.simulator.computeNoteHashAndOptionallyANullifier(
|
|
439
459
|
note.contractAddress,
|
|
440
460
|
nonce,
|
|
@@ -526,8 +546,9 @@ export class PXEService implements PXE {
|
|
|
526
546
|
}
|
|
527
547
|
}
|
|
528
548
|
|
|
529
|
-
|
|
530
|
-
|
|
549
|
+
const txHash = await simulatedTx.getTxHash();
|
|
550
|
+
this.log.info(`Simulation completed for ${txHash.toString()} in ${timer.ms()}ms`, {
|
|
551
|
+
txHash,
|
|
531
552
|
...txInfo,
|
|
532
553
|
...(profileResult ? { gateCounts: profileResult.gateCounts } : {}),
|
|
533
554
|
...(publicOutput
|
|
@@ -558,7 +579,7 @@ export class PXEService implements PXE {
|
|
|
558
579
|
}
|
|
559
580
|
|
|
560
581
|
public async sendTx(tx: Tx): Promise<TxHash> {
|
|
561
|
-
const txHash = tx.getTxHash();
|
|
582
|
+
const txHash = await tx.getTxHash();
|
|
562
583
|
if (await this.node.getTxEffect(txHash)) {
|
|
563
584
|
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
564
585
|
}
|
|
@@ -645,7 +666,7 @@ export class PXEService implements PXE {
|
|
|
645
666
|
return {
|
|
646
667
|
name: functionDao.name,
|
|
647
668
|
args: encodeArguments(functionDao, args),
|
|
648
|
-
selector: FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
669
|
+
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
649
670
|
type: functionDao.functionType,
|
|
650
671
|
to,
|
|
651
672
|
isStatic: functionDao.isStatic,
|
|
@@ -824,16 +845,16 @@ export class PXEService implements PXE {
|
|
|
824
845
|
});
|
|
825
846
|
}
|
|
826
847
|
|
|
827
|
-
|
|
848
|
+
async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
|
|
828
849
|
return !!(await this.node.getContractClass(id));
|
|
829
850
|
}
|
|
830
851
|
|
|
831
|
-
|
|
852
|
+
async #isContractPubliclyDeployed(address: AztecAddress): Promise<boolean> {
|
|
832
853
|
return !!(await this.node.getContract(address));
|
|
833
854
|
}
|
|
834
855
|
|
|
835
|
-
|
|
836
|
-
const initNullifier = siloNullifier(address, address.toField());
|
|
856
|
+
async #isContractInitialized(address: AztecAddress): Promise<boolean> {
|
|
857
|
+
const initNullifier = await siloNullifier(address, address.toField());
|
|
837
858
|
return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
|
|
838
859
|
}
|
|
839
860
|
|
|
@@ -866,7 +887,7 @@ export class PXEService implements PXE {
|
|
|
866
887
|
throw new Error('No registered account');
|
|
867
888
|
}
|
|
868
889
|
|
|
869
|
-
const preaddress = registeredAccount.getPreaddress();
|
|
890
|
+
const preaddress = await registeredAccount.getPreaddress();
|
|
870
891
|
|
|
871
892
|
secretKey = await computeAddressSecret(preaddress, secretKey);
|
|
872
893
|
}
|
|
@@ -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, [
|