@aztec/pxe 4.0.0-rc.2 → 4.0.0-rc.4
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/private_kernel/private_kernel_oracle.d.ts +6 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +7 -3
- package/dest/pxe.d.ts +1 -1
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +10 -10
- package/dest/storage/contract_store/contract_store.d.ts +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +140 -64
- package/package.json +16 -16
- package/src/private_kernel/private_kernel_oracle.ts +7 -7
- package/src/pxe.ts +11 -12
- package/src/storage/contract_store/contract_store.ts +170 -71
|
@@ -26,7 +26,11 @@ export declare class PrivateKernelOracle {
|
|
|
26
26
|
saltedInitializationHash: Fr;
|
|
27
27
|
}>;
|
|
28
28
|
/** Retrieves the preimage of a contract class id from the contract classes db. */
|
|
29
|
-
getContractClassIdPreimage(contractClassId: Fr): Promise<
|
|
29
|
+
getContractClassIdPreimage(contractClassId: Fr): Promise<{
|
|
30
|
+
artifactHash: Fr;
|
|
31
|
+
privateFunctionsRoot: Fr;
|
|
32
|
+
publicBytecodeCommitment: Fr;
|
|
33
|
+
}>;
|
|
30
34
|
/** Returns a membership witness with the sibling path and leaf index in our private functions tree. */
|
|
31
35
|
getFunctionMembershipWitness(contractClassId: Fr, selector: FunctionSelector): Promise<MembershipWitness<typeof FUNCTION_TREE_HEIGHT>>;
|
|
32
36
|
/**
|
|
@@ -56,4 +60,4 @@ export declare class PrivateKernelOracle {
|
|
|
56
60
|
*/
|
|
57
61
|
getUpdatedClassIdHints(contractAddress: AztecAddress): Promise<UpdatedClassIdHints>;
|
|
58
62
|
}
|
|
59
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
63
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJza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} from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
4
4
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
5
|
-
import {
|
|
5
|
+
import { computeSaltedInitializationHash } from '@aztec/stdlib/contract';
|
|
6
6
|
import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
|
|
7
7
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
8
8
|
import { UpdatedClassIdHints } from '@aztec/stdlib/kernel';
|
|
@@ -30,11 +30,15 @@ import { UpdatedClassIdHints } from '@aztec/stdlib/kernel';
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
/** Retrieves the preimage of a contract class id from the contract classes db. */ async getContractClassIdPreimage(contractClassId) {
|
|
33
|
-
const contractClass = await this.contractStore.
|
|
33
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(contractClassId);
|
|
34
34
|
if (!contractClass) {
|
|
35
35
|
throw new Error(`Contract class not found when getting class id preimage. Class id: ${contractClassId}.`);
|
|
36
36
|
}
|
|
37
|
-
return
|
|
37
|
+
return {
|
|
38
|
+
artifactHash: contractClass.artifactHash,
|
|
39
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
40
|
+
publicBytecodeCommitment: contractClass.publicBytecodeCommitment
|
|
41
|
+
};
|
|
38
42
|
}
|
|
39
43
|
/** Returns a membership witness with the sibling path and leaf index in our private functions tree. */ async getFunctionMembershipWitness(contractClassId, selector) {
|
|
40
44
|
const membershipWitness = await this.contractStore.getFunctionMembershipWitness(contractClassId, selector);
|
package/dest/pxe.d.ts
CHANGED
|
@@ -247,4 +247,4 @@ export declare class PXE {
|
|
|
247
247
|
*/
|
|
248
248
|
stop(): Promise<void>;
|
|
249
249
|
}
|
|
250
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
250
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHhlLmQudHMiLC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AAkB,GACzB,OAAO,CAAC,kBAAkB,EAAE,CAAC,CA8B/B;IAED;;OAEG;IACI,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;CACF"}
|
package/dest/pxe.js
CHANGED
|
@@ -180,8 +180,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
180
180
|
async #registerProtocolContracts() {
|
|
181
181
|
const registered = {};
|
|
182
182
|
for (const name of protocolContractNames){
|
|
183
|
-
const { address,
|
|
184
|
-
await this.contractStore.addContractArtifact(
|
|
183
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
184
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
185
185
|
await this.contractStore.addContractInstance(instance);
|
|
186
186
|
registered[name] = address.toString();
|
|
187
187
|
}
|
|
@@ -371,8 +371,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
371
371
|
*
|
|
372
372
|
* @param artifact - The build artifact for the contract class.
|
|
373
373
|
*/ async registerContractClass(artifact) {
|
|
374
|
-
const
|
|
375
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
374
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
376
375
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
377
376
|
}
|
|
378
377
|
/**
|
|
@@ -388,15 +387,14 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
388
387
|
if (artifact) {
|
|
389
388
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
390
389
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
throw new Error(`Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`);
|
|
390
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
391
|
+
throw new Error(`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`);
|
|
394
392
|
}
|
|
395
393
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
396
394
|
if (!computedAddress.equals(instance.address)) {
|
|
397
395
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
398
396
|
}
|
|
399
|
-
await this.contractStore.addContractArtifact(
|
|
397
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
400
398
|
const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
|
|
401
399
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
402
400
|
} else {
|
|
@@ -432,11 +430,13 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
|
|
|
432
430
|
if (!contractClass.id.equals(currentClassId)) {
|
|
433
431
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
434
432
|
}
|
|
435
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
436
433
|
const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
|
|
437
434
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
438
435
|
currentInstance.currentContractClassId = contractClass.id;
|
|
439
|
-
await
|
|
436
|
+
await Promise.all([
|
|
437
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
438
|
+
this.contractStore.addContractInstance(currentInstance)
|
|
439
|
+
]);
|
|
440
440
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
441
441
|
});
|
|
442
442
|
}
|
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
import type { FUNCTION_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
4
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
4
5
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
5
6
|
import { type ContractArtifact, type FunctionAbi, type FunctionArtifactWithContractName, FunctionCall, type FunctionDebugMetadata, FunctionSelector } from '@aztec/stdlib/abi';
|
|
6
7
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
-
import { type
|
|
8
|
+
import { type ContractClassIdPreimage, type ContractClassWithId, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
9
|
+
/**
|
|
10
|
+
* All contract class data except the large packedBytecode.
|
|
11
|
+
* The expensive data from the ContractClass is precomputed and stored in this format to avoid redundant hashing.
|
|
12
|
+
* Since we have to store the artifacts anyway, the final ContractClass is reconstructed by combining this data
|
|
13
|
+
* with the packedBytecode obtained from the former. That way we can have quick class lookups without wasted storage.
|
|
14
|
+
*/
|
|
15
|
+
export declare class SerializableContractClassData {
|
|
16
|
+
readonly version: 1;
|
|
17
|
+
readonly id: Fr;
|
|
18
|
+
readonly artifactHash: Fr;
|
|
19
|
+
readonly privateFunctionsRoot: Fr;
|
|
20
|
+
readonly publicBytecodeCommitment: Fr;
|
|
21
|
+
readonly privateFunctions: {
|
|
22
|
+
selector: FunctionSelector;
|
|
23
|
+
vkHash: Fr;
|
|
24
|
+
}[];
|
|
25
|
+
constructor(data: ContractClassIdPreimage & {
|
|
26
|
+
id: Fr;
|
|
27
|
+
privateFunctions: {
|
|
28
|
+
selector: FunctionSelector;
|
|
29
|
+
vkHash: Fr;
|
|
30
|
+
}[];
|
|
31
|
+
});
|
|
32
|
+
toBuffer(): Buffer;
|
|
33
|
+
static fromBuffer(bufferOrReader: Buffer | BufferReader): SerializableContractClassData;
|
|
34
|
+
}
|
|
8
35
|
/**
|
|
9
36
|
* ContractStore serves as a data manager and retriever for Aztec.nr contracts.
|
|
10
37
|
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
|
|
@@ -15,19 +42,24 @@ import { type ContractClass, type ContractInstanceWithAddress } from '@aztec/std
|
|
|
15
42
|
export declare class ContractStore {
|
|
16
43
|
#private;
|
|
17
44
|
constructor(store: AztecAsyncKVStore);
|
|
18
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Registers a new contract artifact and its corresponding class data.
|
|
47
|
+
* IMPORTANT: This method does not verify that the provided artifact matches the class data or that the class id matches the artifact.
|
|
48
|
+
* It is the caller's responsibility to ensure the consistency and correctness of the provided data.
|
|
49
|
+
* This is done to avoid redundant, expensive contract class computations
|
|
50
|
+
*/
|
|
51
|
+
addContractArtifact(contract: ContractArtifact, contractClassWithIdAndPreimage?: ContractClassWithId & ContractClassIdPreimage): Promise<Fr>;
|
|
19
52
|
addContractInstance(contract: ContractInstanceWithAddress): Promise<void>;
|
|
20
53
|
getContractsAddresses(): Promise<AztecAddress[]>;
|
|
21
|
-
/** Returns a contract instance for a given address.
|
|
54
|
+
/** Returns a contract instance for a given address. */
|
|
22
55
|
getContractInstance(contractAddress: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
|
|
56
|
+
/** Returns the raw contract artifact for a given class id. */
|
|
23
57
|
getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | undefined>;
|
|
24
|
-
/** Returns a contract class for a given class id.
|
|
25
|
-
|
|
58
|
+
/** Returns a contract class for a given class id. */
|
|
59
|
+
getContractClassWithPreimage(contractClassId: Fr): Promise<(ContractClassWithId & ContractClassIdPreimage) | undefined>;
|
|
26
60
|
getContract(address: AztecAddress): Promise<(ContractInstanceWithAddress & ContractArtifact) | undefined>;
|
|
27
61
|
/**
|
|
28
62
|
* Retrieves the artifact of a specified function within a given contract.
|
|
29
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
30
|
-
* Throws an error if the contract address or function selector are invalid or not found.
|
|
31
63
|
*
|
|
32
64
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
33
65
|
* @param selector - The function selector.
|
|
@@ -39,20 +71,15 @@ export declare class ContractStore {
|
|
|
39
71
|
getFunctionAbi(contractAddress: AztecAddress, selector: FunctionSelector): Promise<FunctionAbi | undefined>;
|
|
40
72
|
/**
|
|
41
73
|
* Retrieves the debug metadata of a specified function within a given contract.
|
|
42
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
43
|
-
* Returns undefined if the debug metadata for the given function is not found.
|
|
44
|
-
* Throws if the contract has not been added to the database.
|
|
45
74
|
*
|
|
46
75
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
47
76
|
* @param selector - The function selector.
|
|
48
|
-
* @returns The corresponding function's
|
|
77
|
+
* @returns The corresponding function's debug metadata, or undefined.
|
|
49
78
|
*/
|
|
50
79
|
getFunctionDebugMetadata(contractAddress: AztecAddress, selector: FunctionSelector): Promise<FunctionDebugMetadata | undefined>;
|
|
51
80
|
getPublicFunctionDebugMetadata(contractAddress: AztecAddress): Promise<FunctionDebugMetadata | undefined>;
|
|
52
81
|
/**
|
|
53
82
|
* Retrieve the function membership witness for the given contract class and function selector.
|
|
54
|
-
* The function membership witness represents a proof that the function belongs to the specified contract.
|
|
55
|
-
* Throws an error if the contract address or function selector is unknown.
|
|
56
83
|
*
|
|
57
84
|
* @param contractClassId - The id of the class.
|
|
58
85
|
* @param selector - The function selector.
|
|
@@ -63,4 +90,4 @@ export declare class ContractStore {
|
|
|
63
90
|
getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string>;
|
|
64
91
|
getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall>;
|
|
65
92
|
}
|
|
66
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
93
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3Rfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL2NvbnRyYWN0X3N0b3JlL2NvbnRyYWN0X3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJB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sRUFDbkIsUUFBUSxFQUFFLGdCQUFnQixHQUN6QixPQUFPLENBQUMsaUJBQWlCLENBQUMsT0FBTyxvQkFBb0IsQ0FBQyxHQUFHLFNBQVMsQ0FBQyxDQUdyRTtJQUVZLG9CQUFvQixDQUFDLGVBQWUsRUFBRSxZQUFZLCtCQUc5RDtJQUVZLG9CQUFvQixDQUFDLGVBQWUsRUFBRSxZQUFZLEVBQUUsUUFBUSxFQUFFLGdCQUFnQixtQkFJMUY7SUEwQlksZUFBZSxDQUFDLFlBQVksRUFBRSxNQUFNLEVBQUUsSUFBSSxFQUFFLEdBQUcsRUFBRSxFQUFFLEVBQUUsRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQXlCdkc7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract_store.d.ts","sourceRoot":"","sources":["../../../src/storage/contract_store/contract_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,
|
|
1
|
+
{"version":3,"file":"contract_store.d.ts","sourceRoot":"","sources":["../../../src/storage/contract_store/contract_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAiC,MAAM,6BAA6B,CAAC;AAC1F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAEhB,KAAK,gCAAgC,EACrC,YAAY,EACZ,KAAK,qBAAqB,EAC1B,gBAAgB,EAMjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,6BA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e,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,mBAI1F;IA0BY,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAyBvG;CACF"}
|
|
@@ -1,8 +1,53 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
1
2
|
import { toArray } from '@aztec/foundation/iterable';
|
|
3
|
+
import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
4
|
import { FunctionCall, FunctionSelector, FunctionType, contractArtifactFromBuffer, contractArtifactToBuffer, encodeArguments, getFunctionDebugMetadata } from '@aztec/stdlib/abi';
|
|
3
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
6
|
import { SerializableContractInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
5
7
|
import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
8
|
+
const VERSION = 1;
|
|
9
|
+
/**
|
|
10
|
+
* All contract class data except the large packedBytecode.
|
|
11
|
+
* The expensive data from the ContractClass is precomputed and stored in this format to avoid redundant hashing.
|
|
12
|
+
* Since we have to store the artifacts anyway, the final ContractClass is reconstructed by combining this data
|
|
13
|
+
* with the packedBytecode obtained from the former. That way we can have quick class lookups without wasted storage.
|
|
14
|
+
*/ export class SerializableContractClassData {
|
|
15
|
+
version = VERSION;
|
|
16
|
+
id;
|
|
17
|
+
artifactHash;
|
|
18
|
+
privateFunctionsRoot;
|
|
19
|
+
publicBytecodeCommitment;
|
|
20
|
+
privateFunctions;
|
|
21
|
+
constructor(data){
|
|
22
|
+
this.id = data.id;
|
|
23
|
+
this.artifactHash = data.artifactHash;
|
|
24
|
+
this.privateFunctionsRoot = data.privateFunctionsRoot;
|
|
25
|
+
this.publicBytecodeCommitment = data.publicBytecodeCommitment;
|
|
26
|
+
this.privateFunctions = data.privateFunctions;
|
|
27
|
+
}
|
|
28
|
+
toBuffer() {
|
|
29
|
+
return serializeToBuffer(numToUInt8(this.version), this.id, this.artifactHash, this.privateFunctionsRoot, this.publicBytecodeCommitment, this.privateFunctions.length, ...this.privateFunctions.map((fn)=>serializeToBuffer(fn.selector, fn.vkHash)));
|
|
30
|
+
}
|
|
31
|
+
static fromBuffer(bufferOrReader) {
|
|
32
|
+
const reader = BufferReader.asReader(bufferOrReader);
|
|
33
|
+
const version = reader.readUInt8();
|
|
34
|
+
if (version !== VERSION) {
|
|
35
|
+
throw new Error(`Unexpected contract class data version ${version}`);
|
|
36
|
+
}
|
|
37
|
+
return new SerializableContractClassData({
|
|
38
|
+
id: reader.readObject(Fr),
|
|
39
|
+
artifactHash: reader.readObject(Fr),
|
|
40
|
+
privateFunctionsRoot: reader.readObject(Fr),
|
|
41
|
+
publicBytecodeCommitment: reader.readObject(Fr),
|
|
42
|
+
privateFunctions: reader.readVector({
|
|
43
|
+
fromBuffer: (r)=>({
|
|
44
|
+
selector: r.readObject(FunctionSelector),
|
|
45
|
+
vkHash: r.readObject(Fr)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
6
51
|
/**
|
|
7
52
|
* ContractStore serves as a data manager and retriever for Aztec.nr contracts.
|
|
8
53
|
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
|
|
@@ -12,24 +57,46 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
12
57
|
*/ export class ContractStore {
|
|
13
58
|
/** Map from contract class id to private function tree. */ // TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
14
59
|
#privateFunctionTrees = new Map();
|
|
15
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* In-memory cache of deserialized ContractArtifact objects, keyed by class id string.
|
|
62
|
+
* Avoids repeated LMDB reads + JSON.parse + Zod validation on every oracle call.
|
|
63
|
+
* Artifacts are large but immutable after registration — safe to cache for the lifetime of the store.
|
|
64
|
+
*/ // TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
65
|
+
#contractArtifactCache = new Map();
|
|
66
|
+
/** Map from contract address to contract class id (avoids KV round-trip on hot path). */ #contractClassIdMap = new Map();
|
|
16
67
|
#store;
|
|
17
68
|
#contractArtifacts;
|
|
69
|
+
#contractClassData;
|
|
18
70
|
#contractInstances;
|
|
19
71
|
constructor(store){
|
|
20
72
|
this.#store = store;
|
|
21
73
|
this.#contractArtifacts = store.openMap('contract_artifacts');
|
|
74
|
+
this.#contractClassData = store.openMap('contract_classes');
|
|
22
75
|
this.#contractInstances = store.openMap('contracts_instances');
|
|
23
76
|
}
|
|
24
77
|
// Setters
|
|
25
|
-
|
|
26
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Registers a new contract artifact and its corresponding class data.
|
|
80
|
+
* IMPORTANT: This method does not verify that the provided artifact matches the class data or that the class id matches the artifact.
|
|
81
|
+
* It is the caller's responsibility to ensure the consistency and correctness of the provided data.
|
|
82
|
+
* This is done to avoid redundant, expensive contract class computations
|
|
83
|
+
*/ async addContractArtifact(contract, contractClassWithIdAndPreimage) {
|
|
84
|
+
const contractClass = contractClassWithIdAndPreimage ?? await getContractClassFromArtifact(contract);
|
|
85
|
+
const key = contractClass.id.toString();
|
|
86
|
+
if (this.#contractArtifactCache.has(key)) {
|
|
87
|
+
return contractClass.id;
|
|
88
|
+
}
|
|
27
89
|
const privateFunctions = contract.functions.filter((functionArtifact)=>functionArtifact.functionType === FunctionType.PRIVATE);
|
|
28
|
-
const privateSelectors = await Promise.all(privateFunctions.map(async (
|
|
90
|
+
const privateSelectors = await Promise.all(privateFunctions.map(async (fn)=>(await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)).toString()));
|
|
29
91
|
if (privateSelectors.length !== new Set(privateSelectors).size) {
|
|
30
92
|
throw new Error('Repeated function selectors of private functions');
|
|
31
93
|
}
|
|
32
|
-
|
|
94
|
+
this.#contractArtifactCache.set(key, contract);
|
|
95
|
+
await this.#store.transactionAsync(async ()=>{
|
|
96
|
+
await this.#contractArtifacts.set(key, contractArtifactToBuffer(contract));
|
|
97
|
+
await this.#contractClassData.set(key, new SerializableContractClassData(contractClass).toBuffer());
|
|
98
|
+
});
|
|
99
|
+
return contractClass.id;
|
|
33
100
|
}
|
|
34
101
|
async addContractInstance(contract) {
|
|
35
102
|
this.#contractClassIdMap.set(contract.address.toString(), contract.currentContractClassId);
|
|
@@ -37,25 +104,17 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
37
104
|
}
|
|
38
105
|
// Private getters
|
|
39
106
|
async #getContractClassId(contractAddress) {
|
|
40
|
-
|
|
107
|
+
const key = contractAddress.toString();
|
|
108
|
+
if (!this.#contractClassIdMap.has(key)) {
|
|
41
109
|
const instance = await this.getContractInstance(contractAddress);
|
|
42
110
|
if (!instance) {
|
|
43
111
|
return;
|
|
44
112
|
}
|
|
45
|
-
this.#contractClassIdMap.set(
|
|
113
|
+
this.#contractClassIdMap.set(key, instance.currentContractClassId);
|
|
46
114
|
}
|
|
47
|
-
return this.#contractClassIdMap.get(
|
|
115
|
+
return this.#contractClassIdMap.get(key);
|
|
48
116
|
}
|
|
49
|
-
|
|
50
|
-
* Retrieve or create a ContractTree instance based on the provided class id.
|
|
51
|
-
* If an existing tree with the same class id is found in the cache, it will be returned.
|
|
52
|
-
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
53
|
-
* and added to the cache before returning.
|
|
54
|
-
*
|
|
55
|
-
* @param classId - The class id of the contract for which the ContractTree is required.
|
|
56
|
-
* @returns A ContractTree instance associated with the specified contract address.
|
|
57
|
-
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
58
|
-
*/ async #getPrivateFunctionTreeForClassId(classId) {
|
|
117
|
+
async #getPrivateFunctionTreeForClassId(classId) {
|
|
59
118
|
if (!this.#privateFunctionTrees.has(classId.toString())) {
|
|
60
119
|
const artifact = await this.getContractArtifact(classId);
|
|
61
120
|
if (!artifact) {
|
|
@@ -66,9 +125,9 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
66
125
|
}
|
|
67
126
|
return this.#privateFunctionTrees.get(classId.toString());
|
|
68
127
|
}
|
|
69
|
-
async #
|
|
70
|
-
const
|
|
71
|
-
return
|
|
128
|
+
async #getArtifactByAddress(contractAddress) {
|
|
129
|
+
const classId = await this.#getContractClassId(contractAddress);
|
|
130
|
+
return classId && this.getContractArtifact(classId);
|
|
72
131
|
}
|
|
73
132
|
// Public getters
|
|
74
133
|
getContractsAddresses() {
|
|
@@ -77,22 +136,43 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
77
136
|
return keys.map(AztecAddress.fromString);
|
|
78
137
|
});
|
|
79
138
|
}
|
|
80
|
-
/** Returns a contract instance for a given address.
|
|
139
|
+
/** Returns a contract instance for a given address. */ getContractInstance(contractAddress) {
|
|
81
140
|
return this.#store.transactionAsync(async ()=>{
|
|
82
141
|
const contract = await this.#contractInstances.getAsync(contractAddress.toString());
|
|
83
142
|
return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
|
|
84
143
|
});
|
|
85
144
|
}
|
|
86
|
-
getContractArtifact(contractClassId) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
145
|
+
/** Returns the raw contract artifact for a given class id. */ async getContractArtifact(contractClassId) {
|
|
146
|
+
const key = contractClassId.toString();
|
|
147
|
+
const cached = this.#contractArtifactCache.get(key);
|
|
148
|
+
if (cached) {
|
|
149
|
+
return cached;
|
|
150
|
+
}
|
|
151
|
+
const artifact = await this.#store.transactionAsync(async ()=>{
|
|
152
|
+
const buf = await this.#contractArtifacts.getAsync(key);
|
|
153
|
+
return buf && contractArtifactFromBuffer(buf);
|
|
91
154
|
});
|
|
155
|
+
if (artifact) {
|
|
156
|
+
this.#contractArtifactCache.set(key, artifact);
|
|
157
|
+
}
|
|
158
|
+
return artifact;
|
|
92
159
|
}
|
|
93
|
-
/** Returns a contract class for a given class id.
|
|
160
|
+
/** Returns a contract class for a given class id. */ async getContractClassWithPreimage(contractClassId) {
|
|
161
|
+
const key = contractClassId.toString();
|
|
162
|
+
const buf = await this.#contractClassData.getAsync(key);
|
|
163
|
+
if (!buf) {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
const classData = SerializableContractClassData.fromBuffer(buf);
|
|
94
167
|
const artifact = await this.getContractArtifact(contractClassId);
|
|
95
|
-
|
|
168
|
+
if (!artifact) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
const packedBytecode = artifact.functions.find((f)=>f.name === 'public_dispatch')?.bytecode ?? Buffer.alloc(0);
|
|
172
|
+
return {
|
|
173
|
+
...classData,
|
|
174
|
+
packedBytecode
|
|
175
|
+
};
|
|
96
176
|
}
|
|
97
177
|
async getContract(address) {
|
|
98
178
|
const instance = await this.getContractInstance(address);
|
|
@@ -110,17 +190,18 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
110
190
|
}
|
|
111
191
|
/**
|
|
112
192
|
* Retrieves the artifact of a specified function within a given contract.
|
|
113
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
114
|
-
* Throws an error if the contract address or function selector are invalid or not found.
|
|
115
193
|
*
|
|
116
194
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
117
195
|
* @param selector - The function selector.
|
|
118
196
|
* @returns The corresponding function's artifact as an object.
|
|
119
197
|
*/ async getFunctionArtifact(contractAddress, selector) {
|
|
120
|
-
const artifact = await this.#
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
198
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
199
|
+
if (!artifact) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
const fn = await this.#findFunctionArtifactBySelector(artifact, selector);
|
|
203
|
+
return fn && {
|
|
204
|
+
...fn,
|
|
124
205
|
contractName: artifact.name
|
|
125
206
|
};
|
|
126
207
|
}
|
|
@@ -136,40 +217,38 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
136
217
|
};
|
|
137
218
|
}
|
|
138
219
|
async getPublicFunctionArtifact(contractAddress) {
|
|
139
|
-
const artifact = await this.#
|
|
140
|
-
const
|
|
141
|
-
return
|
|
142
|
-
...
|
|
220
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
221
|
+
const fn = artifact && artifact.functions.find((f)=>f.functionType === FunctionType.PUBLIC);
|
|
222
|
+
return fn && {
|
|
223
|
+
...fn,
|
|
143
224
|
contractName: artifact.name
|
|
144
225
|
};
|
|
145
226
|
}
|
|
146
227
|
async getFunctionAbi(contractAddress, selector) {
|
|
147
|
-
const artifact = await this.#
|
|
228
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
148
229
|
return artifact && await this.#findFunctionAbiBySelector(artifact, selector);
|
|
149
230
|
}
|
|
150
231
|
/**
|
|
151
232
|
* Retrieves the debug metadata of a specified function within a given contract.
|
|
152
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
153
|
-
* Returns undefined if the debug metadata for the given function is not found.
|
|
154
|
-
* Throws if the contract has not been added to the database.
|
|
155
233
|
*
|
|
156
234
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
157
235
|
* @param selector - The function selector.
|
|
158
|
-
* @returns The corresponding function's
|
|
236
|
+
* @returns The corresponding function's debug metadata, or undefined.
|
|
159
237
|
*/ async getFunctionDebugMetadata(contractAddress, selector) {
|
|
160
|
-
const artifact = await this.#
|
|
161
|
-
|
|
162
|
-
|
|
238
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
239
|
+
if (!artifact) {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
const fn = await this.#findFunctionArtifactBySelector(artifact, selector);
|
|
243
|
+
return fn && getFunctionDebugMetadata(artifact, fn);
|
|
163
244
|
}
|
|
164
245
|
async getPublicFunctionDebugMetadata(contractAddress) {
|
|
165
|
-
const artifact = await this.#
|
|
166
|
-
const
|
|
167
|
-
return
|
|
246
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
247
|
+
const fn = artifact && artifact.functions.find((f)=>f.functionType === FunctionType.PUBLIC);
|
|
248
|
+
return fn && getFunctionDebugMetadata(artifact, fn);
|
|
168
249
|
}
|
|
169
250
|
/**
|
|
170
251
|
* Retrieve the function membership witness for the given contract class and function selector.
|
|
171
|
-
* The function membership witness represents a proof that the function belongs to the specified contract.
|
|
172
|
-
* Throws an error if the contract address or function selector is unknown.
|
|
173
252
|
*
|
|
174
253
|
* @param contractClassId - The id of the class.
|
|
175
254
|
* @param selector - The function selector.
|
|
@@ -179,18 +258,16 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
179
258
|
return tree?.getFunctionMembershipWitness(selector);
|
|
180
259
|
}
|
|
181
260
|
async getDebugContractName(contractAddress) {
|
|
182
|
-
const artifact = await this.#
|
|
261
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
183
262
|
return artifact?.name;
|
|
184
263
|
}
|
|
185
264
|
async getDebugFunctionName(contractAddress, selector) {
|
|
186
|
-
const artifact = await this.#
|
|
187
|
-
const
|
|
188
|
-
return `${artifact?.name ?? contractAddress}:${
|
|
265
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
266
|
+
const fn = artifact && await this.#findFunctionAbiBySelector(artifact, selector);
|
|
267
|
+
return `${artifact?.name ?? contractAddress}:${fn?.name ?? selector}`;
|
|
189
268
|
}
|
|
190
269
|
async #findFunctionArtifactBySelector(artifact, selector) {
|
|
191
|
-
const
|
|
192
|
-
for(let i = 0; i < functions.length; i++){
|
|
193
|
-
const fn = functions[i];
|
|
270
|
+
for (const fn of artifact.functions){
|
|
194
271
|
const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
195
272
|
if (fnSelector.equals(selector)) {
|
|
196
273
|
return fn;
|
|
@@ -198,12 +275,10 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
198
275
|
}
|
|
199
276
|
}
|
|
200
277
|
async #findFunctionAbiBySelector(artifact, selector) {
|
|
201
|
-
const
|
|
278
|
+
for (const fn of [
|
|
202
279
|
...artifact.functions,
|
|
203
280
|
...artifact.nonDispatchPublicFunctions ?? []
|
|
204
|
-
]
|
|
205
|
-
for(let i = 0; i < functions.length; i++){
|
|
206
|
-
const fn = functions[i];
|
|
281
|
+
]){
|
|
207
282
|
const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
208
283
|
if (fnSelector.equals(selector)) {
|
|
209
284
|
return fn;
|
|
@@ -219,10 +294,11 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
219
294
|
if (!functionDao) {
|
|
220
295
|
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
|
|
221
296
|
}
|
|
297
|
+
const selector = await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters);
|
|
222
298
|
return FunctionCall.from({
|
|
223
299
|
name: functionDao.name,
|
|
224
300
|
to,
|
|
225
|
-
selector
|
|
301
|
+
selector,
|
|
226
302
|
type: functionDao.functionType,
|
|
227
303
|
hideMsgSender: false,
|
|
228
304
|
isStatic: functionDao.isStatic,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/pxe",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"typedocOptions": {
|
|
6
6
|
"entryPoints": [
|
|
@@ -70,19 +70,19 @@
|
|
|
70
70
|
]
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@aztec/bb-prover": "4.0.0-rc.
|
|
74
|
-
"@aztec/bb.js": "4.0.0-rc.
|
|
75
|
-
"@aztec/builder": "4.0.0-rc.
|
|
76
|
-
"@aztec/constants": "4.0.0-rc.
|
|
77
|
-
"@aztec/ethereum": "4.0.0-rc.
|
|
78
|
-
"@aztec/foundation": "4.0.0-rc.
|
|
79
|
-
"@aztec/key-store": "4.0.0-rc.
|
|
80
|
-
"@aztec/kv-store": "4.0.0-rc.
|
|
81
|
-
"@aztec/noir-protocol-circuits-types": "4.0.0-rc.
|
|
82
|
-
"@aztec/noir-types": "4.0.0-rc.
|
|
83
|
-
"@aztec/protocol-contracts": "4.0.0-rc.
|
|
84
|
-
"@aztec/simulator": "4.0.0-rc.
|
|
85
|
-
"@aztec/stdlib": "4.0.0-rc.
|
|
73
|
+
"@aztec/bb-prover": "4.0.0-rc.4",
|
|
74
|
+
"@aztec/bb.js": "4.0.0-rc.4",
|
|
75
|
+
"@aztec/builder": "4.0.0-rc.4",
|
|
76
|
+
"@aztec/constants": "4.0.0-rc.4",
|
|
77
|
+
"@aztec/ethereum": "4.0.0-rc.4",
|
|
78
|
+
"@aztec/foundation": "4.0.0-rc.4",
|
|
79
|
+
"@aztec/key-store": "4.0.0-rc.4",
|
|
80
|
+
"@aztec/kv-store": "4.0.0-rc.4",
|
|
81
|
+
"@aztec/noir-protocol-circuits-types": "4.0.0-rc.4",
|
|
82
|
+
"@aztec/noir-types": "4.0.0-rc.4",
|
|
83
|
+
"@aztec/protocol-contracts": "4.0.0-rc.4",
|
|
84
|
+
"@aztec/simulator": "4.0.0-rc.4",
|
|
85
|
+
"@aztec/stdlib": "4.0.0-rc.4",
|
|
86
86
|
"koa": "^2.16.1",
|
|
87
87
|
"koa-router": "^13.1.1",
|
|
88
88
|
"lodash.omit": "^4.5.0",
|
|
@@ -91,8 +91,8 @@
|
|
|
91
91
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@aztec/merkle-tree": "4.0.0-rc.
|
|
95
|
-
"@aztec/noir-test-contracts.js": "4.0.0-rc.
|
|
94
|
+
"@aztec/merkle-tree": "4.0.0-rc.4",
|
|
95
|
+
"@aztec/noir-test-contracts.js": "4.0.0-rc.4",
|
|
96
96
|
"@jest/globals": "^30.0.0",
|
|
97
97
|
"@types/jest": "^30.0.0",
|
|
98
98
|
"@types/lodash.omit": "^4.5.7",
|
|
@@ -8,11 +8,7 @@ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
|
8
8
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
9
9
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
10
|
import { BlockHash } from '@aztec/stdlib/block';
|
|
11
|
-
import {
|
|
12
|
-
type ContractInstanceWithAddress,
|
|
13
|
-
computeContractClassIdPreimage,
|
|
14
|
-
computeSaltedInitializationHash,
|
|
15
|
-
} from '@aztec/stdlib/contract';
|
|
11
|
+
import { type ContractInstanceWithAddress, computeSaltedInitializationHash } from '@aztec/stdlib/contract';
|
|
16
12
|
import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
|
|
17
13
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
18
14
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
@@ -49,11 +45,15 @@ export class PrivateKernelOracle {
|
|
|
49
45
|
|
|
50
46
|
/** Retrieves the preimage of a contract class id from the contract classes db. */
|
|
51
47
|
public async getContractClassIdPreimage(contractClassId: Fr) {
|
|
52
|
-
const contractClass = await this.contractStore.
|
|
48
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(contractClassId);
|
|
53
49
|
if (!contractClass) {
|
|
54
50
|
throw new Error(`Contract class not found when getting class id preimage. Class id: ${contractClassId}.`);
|
|
55
51
|
}
|
|
56
|
-
return
|
|
52
|
+
return {
|
|
53
|
+
artifactHash: contractClass.artifactHash,
|
|
54
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
55
|
+
publicBytecodeCommitment: contractClass.publicBytecodeCommitment,
|
|
56
|
+
};
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/** Returns a membership witness with the sibling path and leaf index in our private functions tree. */
|
package/src/pxe.ts
CHANGED
|
@@ -344,9 +344,8 @@ export class PXE {
|
|
|
344
344
|
async #registerProtocolContracts() {
|
|
345
345
|
const registered: Record<string, string> = {};
|
|
346
346
|
for (const name of protocolContractNames) {
|
|
347
|
-
const { address,
|
|
348
|
-
|
|
349
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
347
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
348
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
350
349
|
await this.contractStore.addContractInstance(instance);
|
|
351
350
|
registered[name] = address.toString();
|
|
352
351
|
}
|
|
@@ -601,8 +600,7 @@ export class PXE {
|
|
|
601
600
|
* @param artifact - The build artifact for the contract class.
|
|
602
601
|
*/
|
|
603
602
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
604
|
-
const
|
|
605
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
603
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
606
604
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
607
605
|
}
|
|
608
606
|
|
|
@@ -621,17 +619,17 @@ export class PXE {
|
|
|
621
619
|
if (artifact) {
|
|
622
620
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
623
621
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
624
|
-
|
|
625
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
622
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
626
623
|
throw new Error(
|
|
627
|
-
`Artifact does not match expected class id (computed ${
|
|
624
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
628
625
|
);
|
|
629
626
|
}
|
|
630
627
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
631
628
|
if (!computedAddress.equals(instance.address)) {
|
|
632
629
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
633
630
|
}
|
|
634
|
-
|
|
631
|
+
|
|
632
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
635
633
|
|
|
636
634
|
const publicFunctionSignatures = artifact.functions
|
|
637
635
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -680,15 +678,16 @@ export class PXE {
|
|
|
680
678
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
681
679
|
}
|
|
682
680
|
|
|
683
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
684
|
-
|
|
685
681
|
const publicFunctionSignatures = artifact.functions
|
|
686
682
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
687
683
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
688
684
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
689
685
|
|
|
690
686
|
currentInstance.currentContractClassId = contractClass.id;
|
|
691
|
-
await
|
|
687
|
+
await Promise.all([
|
|
688
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
689
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
690
|
+
]);
|
|
692
691
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
693
692
|
});
|
|
694
693
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { FUNCTION_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
4
|
+
import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
5
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
5
6
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
6
7
|
import {
|
|
@@ -19,7 +20,8 @@ import {
|
|
|
19
20
|
} from '@aztec/stdlib/abi';
|
|
20
21
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
22
|
import {
|
|
22
|
-
type
|
|
23
|
+
type ContractClassIdPreimage,
|
|
24
|
+
type ContractClassWithId,
|
|
23
25
|
type ContractInstanceWithAddress,
|
|
24
26
|
SerializableContractInstance,
|
|
25
27
|
getContractClassFromArtifact,
|
|
@@ -27,6 +29,68 @@ import {
|
|
|
27
29
|
|
|
28
30
|
import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
29
31
|
|
|
32
|
+
const VERSION = 1 as const;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* All contract class data except the large packedBytecode.
|
|
36
|
+
* The expensive data from the ContractClass is precomputed and stored in this format to avoid redundant hashing.
|
|
37
|
+
* Since we have to store the artifacts anyway, the final ContractClass is reconstructed by combining this data
|
|
38
|
+
* with the packedBytecode obtained from the former. That way we can have quick class lookups without wasted storage.
|
|
39
|
+
*/
|
|
40
|
+
export class SerializableContractClassData {
|
|
41
|
+
public readonly version = VERSION;
|
|
42
|
+
public readonly id: Fr;
|
|
43
|
+
public readonly artifactHash: Fr;
|
|
44
|
+
public readonly privateFunctionsRoot: Fr;
|
|
45
|
+
public readonly publicBytecodeCommitment: Fr;
|
|
46
|
+
public readonly privateFunctions: { selector: FunctionSelector; vkHash: Fr }[];
|
|
47
|
+
|
|
48
|
+
constructor(
|
|
49
|
+
data: ContractClassIdPreimage & {
|
|
50
|
+
id: Fr;
|
|
51
|
+
privateFunctions: { selector: FunctionSelector; vkHash: Fr }[];
|
|
52
|
+
},
|
|
53
|
+
) {
|
|
54
|
+
this.id = data.id;
|
|
55
|
+
this.artifactHash = data.artifactHash;
|
|
56
|
+
this.privateFunctionsRoot = data.privateFunctionsRoot;
|
|
57
|
+
this.publicBytecodeCommitment = data.publicBytecodeCommitment;
|
|
58
|
+
this.privateFunctions = data.privateFunctions;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
toBuffer(): Buffer {
|
|
62
|
+
return serializeToBuffer(
|
|
63
|
+
numToUInt8(this.version),
|
|
64
|
+
this.id,
|
|
65
|
+
this.artifactHash,
|
|
66
|
+
this.privateFunctionsRoot,
|
|
67
|
+
this.publicBytecodeCommitment,
|
|
68
|
+
this.privateFunctions.length,
|
|
69
|
+
...this.privateFunctions.map(fn => serializeToBuffer(fn.selector, fn.vkHash)),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static fromBuffer(bufferOrReader: Buffer | BufferReader): SerializableContractClassData {
|
|
74
|
+
const reader = BufferReader.asReader(bufferOrReader);
|
|
75
|
+
const version = reader.readUInt8();
|
|
76
|
+
if (version !== VERSION) {
|
|
77
|
+
throw new Error(`Unexpected contract class data version ${version}`);
|
|
78
|
+
}
|
|
79
|
+
return new SerializableContractClassData({
|
|
80
|
+
id: reader.readObject(Fr),
|
|
81
|
+
artifactHash: reader.readObject(Fr),
|
|
82
|
+
privateFunctionsRoot: reader.readObject(Fr),
|
|
83
|
+
publicBytecodeCommitment: reader.readObject(Fr),
|
|
84
|
+
privateFunctions: reader.readVector({
|
|
85
|
+
fromBuffer: (r: BufferReader) => ({
|
|
86
|
+
selector: r.readObject(FunctionSelector),
|
|
87
|
+
vkHash: r.readObject(Fr),
|
|
88
|
+
}),
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
30
94
|
/**
|
|
31
95
|
* ContractStore serves as a data manager and retriever for Aztec.nr contracts.
|
|
32
96
|
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
|
|
@@ -39,42 +103,68 @@ export class ContractStore {
|
|
|
39
103
|
// TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
40
104
|
#privateFunctionTrees: Map<string, PrivateFunctionsTree> = new Map();
|
|
41
105
|
|
|
42
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* In-memory cache of deserialized ContractArtifact objects, keyed by class id string.
|
|
108
|
+
* Avoids repeated LMDB reads + JSON.parse + Zod validation on every oracle call.
|
|
109
|
+
* Artifacts are large but immutable after registration — safe to cache for the lifetime of the store.
|
|
110
|
+
*/
|
|
111
|
+
// TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
112
|
+
#contractArtifactCache: Map<string, ContractArtifact> = new Map();
|
|
113
|
+
|
|
114
|
+
/** Map from contract address to contract class id (avoids KV round-trip on hot path). */
|
|
43
115
|
#contractClassIdMap: Map<string, Fr> = new Map();
|
|
44
116
|
|
|
45
117
|
#store: AztecAsyncKVStore;
|
|
46
118
|
#contractArtifacts: AztecAsyncMap<string, Buffer>;
|
|
119
|
+
#contractClassData: AztecAsyncMap<string, Buffer>;
|
|
47
120
|
#contractInstances: AztecAsyncMap<string, Buffer>;
|
|
48
121
|
|
|
49
122
|
constructor(store: AztecAsyncKVStore) {
|
|
50
123
|
this.#store = store;
|
|
51
124
|
this.#contractArtifacts = store.openMap('contract_artifacts');
|
|
125
|
+
this.#contractClassData = store.openMap('contract_classes');
|
|
52
126
|
this.#contractInstances = store.openMap('contracts_instances');
|
|
53
127
|
}
|
|
54
128
|
|
|
55
129
|
// Setters
|
|
56
130
|
|
|
57
|
-
|
|
58
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Registers a new contract artifact and its corresponding class data.
|
|
133
|
+
* IMPORTANT: This method does not verify that the provided artifact matches the class data or that the class id matches the artifact.
|
|
134
|
+
* It is the caller's responsibility to ensure the consistency and correctness of the provided data.
|
|
135
|
+
* This is done to avoid redundant, expensive contract class computations
|
|
136
|
+
*/
|
|
137
|
+
public async addContractArtifact(
|
|
138
|
+
contract: ContractArtifact,
|
|
139
|
+
contractClassWithIdAndPreimage?: ContractClassWithId & ContractClassIdPreimage,
|
|
140
|
+
): Promise<Fr> {
|
|
141
|
+
const contractClass = contractClassWithIdAndPreimage ?? (await getContractClassFromArtifact(contract));
|
|
142
|
+
const key = contractClass.id.toString();
|
|
143
|
+
|
|
144
|
+
if (this.#contractArtifactCache.has(key)) {
|
|
145
|
+
return contractClass.id;
|
|
146
|
+
}
|
|
147
|
+
|
|
59
148
|
const privateFunctions = contract.functions.filter(
|
|
60
149
|
functionArtifact => functionArtifact.functionType === FunctionType.PRIVATE,
|
|
61
150
|
);
|
|
62
|
-
|
|
63
151
|
const privateSelectors = await Promise.all(
|
|
64
|
-
privateFunctions.map(async
|
|
65
|
-
(
|
|
66
|
-
await FunctionSelector.fromNameAndParameters(privateFunctionArtifact.name, privateFunctionArtifact.parameters)
|
|
67
|
-
).toString(),
|
|
152
|
+
privateFunctions.map(async fn =>
|
|
153
|
+
(await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)).toString(),
|
|
68
154
|
),
|
|
69
155
|
);
|
|
70
|
-
|
|
71
156
|
if (privateSelectors.length !== new Set(privateSelectors).size) {
|
|
72
157
|
throw new Error('Repeated function selectors of private functions');
|
|
73
158
|
}
|
|
74
159
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
)
|
|
160
|
+
this.#contractArtifactCache.set(key, contract);
|
|
161
|
+
|
|
162
|
+
await this.#store.transactionAsync(async () => {
|
|
163
|
+
await this.#contractArtifacts.set(key, contractArtifactToBuffer(contract));
|
|
164
|
+
await this.#contractClassData.set(key, new SerializableContractClassData(contractClass).toBuffer());
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return contractClass.id;
|
|
78
168
|
}
|
|
79
169
|
|
|
80
170
|
async addContractInstance(contract: ContractInstanceWithAddress): Promise<void> {
|
|
@@ -89,26 +179,17 @@ export class ContractStore {
|
|
|
89
179
|
// Private getters
|
|
90
180
|
|
|
91
181
|
async #getContractClassId(contractAddress: AztecAddress): Promise<Fr | undefined> {
|
|
92
|
-
|
|
182
|
+
const key = contractAddress.toString();
|
|
183
|
+
if (!this.#contractClassIdMap.has(key)) {
|
|
93
184
|
const instance = await this.getContractInstance(contractAddress);
|
|
94
185
|
if (!instance) {
|
|
95
186
|
return;
|
|
96
187
|
}
|
|
97
|
-
this.#contractClassIdMap.set(
|
|
188
|
+
this.#contractClassIdMap.set(key, instance.currentContractClassId);
|
|
98
189
|
}
|
|
99
|
-
return this.#contractClassIdMap.get(
|
|
190
|
+
return this.#contractClassIdMap.get(key);
|
|
100
191
|
}
|
|
101
192
|
|
|
102
|
-
/**
|
|
103
|
-
* Retrieve or create a ContractTree instance based on the provided class id.
|
|
104
|
-
* If an existing tree with the same class id is found in the cache, it will be returned.
|
|
105
|
-
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
106
|
-
* and added to the cache before returning.
|
|
107
|
-
*
|
|
108
|
-
* @param classId - The class id of the contract for which the ContractTree is required.
|
|
109
|
-
* @returns A ContractTree instance associated with the specified contract address.
|
|
110
|
-
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
111
|
-
*/
|
|
112
193
|
async #getPrivateFunctionTreeForClassId(classId: Fr): Promise<PrivateFunctionsTree | undefined> {
|
|
113
194
|
if (!this.#privateFunctionTrees.has(classId.toString())) {
|
|
114
195
|
const artifact = await this.getContractArtifact(classId);
|
|
@@ -121,9 +202,9 @@ export class ContractStore {
|
|
|
121
202
|
return this.#privateFunctionTrees.get(classId.toString())!;
|
|
122
203
|
}
|
|
123
204
|
|
|
124
|
-
async #
|
|
125
|
-
const
|
|
126
|
-
return
|
|
205
|
+
async #getArtifactByAddress(contractAddress: AztecAddress): Promise<ContractArtifact | undefined> {
|
|
206
|
+
const classId = await this.#getContractClassId(contractAddress);
|
|
207
|
+
return classId && this.getContractArtifact(classId);
|
|
127
208
|
}
|
|
128
209
|
|
|
129
210
|
// Public getters
|
|
@@ -135,7 +216,7 @@ export class ContractStore {
|
|
|
135
216
|
});
|
|
136
217
|
}
|
|
137
218
|
|
|
138
|
-
/** Returns a contract instance for a given address.
|
|
219
|
+
/** Returns a contract instance for a given address. */
|
|
139
220
|
public getContractInstance(contractAddress: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
140
221
|
return this.#store.transactionAsync(async () => {
|
|
141
222
|
const contract = await this.#contractInstances.getAsync(contractAddress.toString());
|
|
@@ -143,18 +224,39 @@ export class ContractStore {
|
|
|
143
224
|
});
|
|
144
225
|
}
|
|
145
226
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
227
|
+
/** Returns the raw contract artifact for a given class id. */
|
|
228
|
+
public async getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | undefined> {
|
|
229
|
+
const key = contractClassId.toString();
|
|
230
|
+
const cached = this.#contractArtifactCache.get(key);
|
|
231
|
+
if (cached) {
|
|
232
|
+
return cached;
|
|
233
|
+
}
|
|
234
|
+
const artifact = await this.#store.transactionAsync(async () => {
|
|
235
|
+
const buf = await this.#contractArtifacts.getAsync(key);
|
|
236
|
+
return buf && contractArtifactFromBuffer(buf);
|
|
151
237
|
});
|
|
238
|
+
if (artifact) {
|
|
239
|
+
this.#contractArtifactCache.set(key, artifact);
|
|
240
|
+
}
|
|
241
|
+
return artifact;
|
|
152
242
|
}
|
|
153
243
|
|
|
154
|
-
/** Returns a contract class for a given class id.
|
|
155
|
-
public async
|
|
244
|
+
/** Returns a contract class for a given class id. */
|
|
245
|
+
public async getContractClassWithPreimage(
|
|
246
|
+
contractClassId: Fr,
|
|
247
|
+
): Promise<(ContractClassWithId & ContractClassIdPreimage) | undefined> {
|
|
248
|
+
const key = contractClassId.toString();
|
|
249
|
+
const buf = await this.#contractClassData.getAsync(key);
|
|
250
|
+
if (!buf) {
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
const classData = SerializableContractClassData.fromBuffer(buf);
|
|
156
254
|
const artifact = await this.getContractArtifact(contractClassId);
|
|
157
|
-
|
|
255
|
+
if (!artifact) {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
const packedBytecode = artifact.functions.find(f => f.name === 'public_dispatch')?.bytecode ?? Buffer.alloc(0);
|
|
259
|
+
return { ...classData, packedBytecode };
|
|
158
260
|
}
|
|
159
261
|
|
|
160
262
|
public async getContract(
|
|
@@ -173,8 +275,6 @@ export class ContractStore {
|
|
|
173
275
|
|
|
174
276
|
/**
|
|
175
277
|
* Retrieves the artifact of a specified function within a given contract.
|
|
176
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
177
|
-
* Throws an error if the contract address or function selector are invalid or not found.
|
|
178
278
|
*
|
|
179
279
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
180
280
|
* @param selector - The function selector.
|
|
@@ -184,9 +284,12 @@ export class ContractStore {
|
|
|
184
284
|
contractAddress: AztecAddress,
|
|
185
285
|
selector: FunctionSelector,
|
|
186
286
|
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
187
|
-
const artifact = await this.#
|
|
188
|
-
|
|
189
|
-
|
|
287
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
288
|
+
if (!artifact) {
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
const fn = await this.#findFunctionArtifactBySelector(artifact, selector);
|
|
292
|
+
return fn && { ...fn, contractName: artifact.name };
|
|
190
293
|
}
|
|
191
294
|
|
|
192
295
|
public async getFunctionArtifactWithDebugMetadata(
|
|
@@ -207,50 +310,48 @@ export class ContractStore {
|
|
|
207
310
|
public async getPublicFunctionArtifact(
|
|
208
311
|
contractAddress: AztecAddress,
|
|
209
312
|
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
210
|
-
const artifact = await this.#
|
|
211
|
-
const
|
|
212
|
-
return
|
|
313
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
314
|
+
const fn = artifact && artifact.functions.find(f => f.functionType === FunctionType.PUBLIC);
|
|
315
|
+
return fn && { ...fn, contractName: artifact.name };
|
|
213
316
|
}
|
|
214
317
|
|
|
215
318
|
public async getFunctionAbi(
|
|
216
319
|
contractAddress: AztecAddress,
|
|
217
320
|
selector: FunctionSelector,
|
|
218
321
|
): Promise<FunctionAbi | undefined> {
|
|
219
|
-
const artifact = await this.#
|
|
322
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
220
323
|
return artifact && (await this.#findFunctionAbiBySelector(artifact, selector));
|
|
221
324
|
}
|
|
222
325
|
|
|
223
326
|
/**
|
|
224
327
|
* Retrieves the debug metadata of a specified function within a given contract.
|
|
225
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
226
|
-
* Returns undefined if the debug metadata for the given function is not found.
|
|
227
|
-
* Throws if the contract has not been added to the database.
|
|
228
328
|
*
|
|
229
329
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
230
330
|
* @param selector - The function selector.
|
|
231
|
-
* @returns The corresponding function's
|
|
331
|
+
* @returns The corresponding function's debug metadata, or undefined.
|
|
232
332
|
*/
|
|
233
333
|
public async getFunctionDebugMetadata(
|
|
234
334
|
contractAddress: AztecAddress,
|
|
235
335
|
selector: FunctionSelector,
|
|
236
336
|
): Promise<FunctionDebugMetadata | undefined> {
|
|
237
|
-
const artifact = await this.#
|
|
238
|
-
|
|
239
|
-
|
|
337
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
338
|
+
if (!artifact) {
|
|
339
|
+
return undefined;
|
|
340
|
+
}
|
|
341
|
+
const fn = await this.#findFunctionArtifactBySelector(artifact, selector);
|
|
342
|
+
return fn && getFunctionDebugMetadata(artifact, fn);
|
|
240
343
|
}
|
|
241
344
|
|
|
242
345
|
public async getPublicFunctionDebugMetadata(
|
|
243
346
|
contractAddress: AztecAddress,
|
|
244
347
|
): Promise<FunctionDebugMetadata | undefined> {
|
|
245
|
-
const artifact = await this.#
|
|
246
|
-
const
|
|
247
|
-
return
|
|
348
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
349
|
+
const fn = artifact && artifact.functions.find(f => f.functionType === FunctionType.PUBLIC);
|
|
350
|
+
return fn && getFunctionDebugMetadata(artifact, fn);
|
|
248
351
|
}
|
|
249
352
|
|
|
250
353
|
/**
|
|
251
354
|
* Retrieve the function membership witness for the given contract class and function selector.
|
|
252
|
-
* The function membership witness represents a proof that the function belongs to the specified contract.
|
|
253
|
-
* Throws an error if the contract address or function selector is unknown.
|
|
254
355
|
*
|
|
255
356
|
* @param contractClassId - The id of the class.
|
|
256
357
|
* @param selector - The function selector.
|
|
@@ -265,23 +366,21 @@ export class ContractStore {
|
|
|
265
366
|
}
|
|
266
367
|
|
|
267
368
|
public async getDebugContractName(contractAddress: AztecAddress) {
|
|
268
|
-
const artifact = await this.#
|
|
369
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
269
370
|
return artifact?.name;
|
|
270
371
|
}
|
|
271
372
|
|
|
272
373
|
public async getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector) {
|
|
273
|
-
const artifact = await this.#
|
|
274
|
-
const
|
|
275
|
-
return `${artifact?.name ?? contractAddress}:${
|
|
374
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
375
|
+
const fn = artifact && (await this.#findFunctionAbiBySelector(artifact, selector));
|
|
376
|
+
return `${artifact?.name ?? contractAddress}:${fn?.name ?? selector}`;
|
|
276
377
|
}
|
|
277
378
|
|
|
278
379
|
async #findFunctionArtifactBySelector(
|
|
279
380
|
artifact: ContractArtifact,
|
|
280
381
|
selector: FunctionSelector,
|
|
281
382
|
): Promise<FunctionArtifact | undefined> {
|
|
282
|
-
const
|
|
283
|
-
for (let i = 0; i < functions.length; i++) {
|
|
284
|
-
const fn = functions[i];
|
|
383
|
+
for (const fn of artifact.functions) {
|
|
285
384
|
const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
286
385
|
if (fnSelector.equals(selector)) {
|
|
287
386
|
return fn;
|
|
@@ -293,9 +392,7 @@ export class ContractStore {
|
|
|
293
392
|
artifact: ContractArtifact,
|
|
294
393
|
selector: FunctionSelector,
|
|
295
394
|
): Promise<FunctionAbi | undefined> {
|
|
296
|
-
const
|
|
297
|
-
for (let i = 0; i < functions.length; i++) {
|
|
298
|
-
const fn = functions[i];
|
|
395
|
+
for (const fn of [...artifact.functions, ...(artifact.nonDispatchPublicFunctions ?? [])]) {
|
|
299
396
|
const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
300
397
|
if (fnSelector.equals(selector)) {
|
|
301
398
|
return fn;
|
|
@@ -316,10 +413,12 @@ export class ContractStore {
|
|
|
316
413
|
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
|
|
317
414
|
}
|
|
318
415
|
|
|
416
|
+
const selector = await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters);
|
|
417
|
+
|
|
319
418
|
return FunctionCall.from({
|
|
320
419
|
name: functionDao.name,
|
|
321
420
|
to,
|
|
322
|
-
selector
|
|
421
|
+
selector,
|
|
323
422
|
type: functionDao.functionType,
|
|
324
423
|
hideMsgSender: false,
|
|
325
424
|
isStatic: functionDao.isStatic,
|