@aztec/stdlib 0.79.0 → 0.80.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/abi/abi.d.ts +7 -5
- package/dest/abi/abi.d.ts.map +1 -1
- package/dest/abi/abi.js +8 -3
- package/dest/abi/contract_artifact.d.ts +16 -1
- package/dest/abi/contract_artifact.d.ts.map +1 -1
- package/dest/abi/contract_artifact.js +61 -11
- package/dest/contract/contract_class.d.ts.map +1 -1
- package/dest/contract/contract_class.js +2 -0
- package/dest/contract/contract_instance.d.ts +2 -2
- package/dest/contract/contract_instance.d.ts.map +1 -1
- package/dest/contract/contract_instance.js +3 -2
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +1 -0
- package/package.json +6 -6
- package/src/abi/abi.ts +16 -9
- package/src/abi/contract_artifact.ts +76 -10
- package/src/contract/contract_class.ts +2 -0
- package/src/contract/contract_instance.ts +13 -5
- package/src/tests/mocks.ts +1 -0
package/dest/abi/abi.d.ts
CHANGED
|
@@ -808,10 +808,10 @@ export type FieldLayout = {
|
|
|
808
808
|
export interface ContractArtifact {
|
|
809
809
|
/** The name of the contract. */
|
|
810
810
|
name: string;
|
|
811
|
-
/** The
|
|
812
|
-
aztecNrVersion?: string;
|
|
813
|
-
/** The functions of the contract. */
|
|
811
|
+
/** The functions of the contract. Includes private and unconstrained functions, plus the public dispatch function. */
|
|
814
812
|
functions: FunctionArtifact[];
|
|
813
|
+
/** The public functions of the contract, excluding dispatch. */
|
|
814
|
+
nonDispatchPublicFunctions: FunctionAbi[];
|
|
815
815
|
/** The outputs of the contract. */
|
|
816
816
|
outputs: {
|
|
817
817
|
structs: Record<string, AbiType[]>;
|
|
@@ -828,6 +828,8 @@ export declare const ContractArtifactSchema: ZodFor<ContractArtifact>;
|
|
|
828
828
|
export declare function getFunctionArtifactByName(artifact: ContractArtifact, functionName: string): FunctionArtifact;
|
|
829
829
|
/** Gets a function artifact including debug metadata given its name or selector. */
|
|
830
830
|
export declare function getFunctionArtifact(artifact: ContractArtifact, functionNameOrSelector: string | FunctionSelector): Promise<FunctionArtifact>;
|
|
831
|
+
/** Gets all function abis */
|
|
832
|
+
export declare function getAllFunctionAbis(artifact: ContractArtifact): FunctionAbi[];
|
|
831
833
|
export declare function parseDebugSymbols(debugSymbols: string): DebugInfo[];
|
|
832
834
|
/**
|
|
833
835
|
* Gets the debug metadata of a given function from the contract artifact
|
|
@@ -843,12 +845,12 @@ export declare function getFunctionDebugMetadata(contractArtifact: ContractArtif
|
|
|
843
845
|
* @param contractArtifact - The contract artifact.
|
|
844
846
|
* @returns An initializer function, or none if there are no functions flagged as initializers in the contract.
|
|
845
847
|
*/
|
|
846
|
-
export declare function getDefaultInitializer(contractArtifact: ContractArtifact):
|
|
848
|
+
export declare function getDefaultInitializer(contractArtifact: ContractArtifact): FunctionAbi | undefined;
|
|
847
849
|
/**
|
|
848
850
|
* Returns an initializer from the contract.
|
|
849
851
|
* @param initializerNameOrArtifact - The name of the constructor, or the artifact of the constructor, or undefined
|
|
850
852
|
* to pick the default initializer.
|
|
851
853
|
*/
|
|
852
|
-
export declare function getInitializer(contract: ContractArtifact, initializerNameOrArtifact: string | undefined | FunctionArtifact):
|
|
854
|
+
export declare function getInitializer(contract: ContractArtifact, initializerNameOrArtifact: string | undefined | FunctionArtifact): FunctionAbi | undefined;
|
|
853
855
|
export {};
|
|
854
856
|
//# sourceMappingURL=abi.d.ts.map
|
package/dest/abi/abi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi.d.ts","sourceRoot":"","sources":["../../src/abi/abi.ts"],"names":[],"mappings":";;AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,KAAK,MAAM,EAAW,MAAM,2BAA2B,CAAC;AAGjE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE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,CAAC,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,GAAG,gBAAgB,CAS5G;AAED,oFAAoF;AACpF,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,gBAAgB,EAC1B,sBAAsB,EAAE,MAAM,GAAG,gBAAgB,GAChD,OAAO,CAAC,gBAAgB,CAAC,CAsB3B;AAED,6BAA6B;AAC7B,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,WAAW,EAAE,CAE5E;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,CAEnE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,gBAAgB,EAAE,gBAAgB,EAClC,gBAAgB,EAAE,gBAAgB,GACjC,qBAAqB,GAAG,SAAS,CA0BnC;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,WAAW,GAAG,SAAS,CAUjG;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,gBAAgB,EAC1B,yBAAyB,EAAE,MAAM,GAAG,SAAS,GAAG,gBAAgB,GAC/D,WAAW,GAAG,SAAS,CAkBzB"}
|
package/dest/abi/abi.js
CHANGED
|
@@ -156,8 +156,8 @@ export const ContractNoteSchema = z.object({
|
|
|
156
156
|
});
|
|
157
157
|
export const ContractArtifactSchema = z.object({
|
|
158
158
|
name: z.string(),
|
|
159
|
-
aztecNrVersion: z.string().optional(),
|
|
160
159
|
functions: z.array(FunctionArtifactSchema),
|
|
160
|
+
nonDispatchPublicFunctions: z.array(FunctionAbiSchema),
|
|
161
161
|
outputs: z.object({
|
|
162
162
|
structs: z.record(z.array(AbiTypeSchema)).transform((structs)=>{
|
|
163
163
|
for (const [key, value] of Object.entries(structs)){
|
|
@@ -213,6 +213,9 @@ export function getFunctionArtifactByName(artifact, functionName) {
|
|
|
213
213
|
debug: debugMetadata
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
|
+
/** Gets all function abis */ export function getAllFunctionAbis(artifact) {
|
|
217
|
+
return artifact.functions.map((f)=>f).concat(artifact.nonDispatchPublicFunctions || []);
|
|
218
|
+
}
|
|
216
219
|
export function parseDebugSymbols(debugSymbols) {
|
|
217
220
|
return JSON.parse(inflate(Buffer.from(debugSymbols, 'base64'), {
|
|
218
221
|
to: 'string',
|
|
@@ -255,7 +258,8 @@ export function parseDebugSymbols(debugSymbols) {
|
|
|
255
258
|
* @param contractArtifact - The contract artifact.
|
|
256
259
|
* @returns An initializer function, or none if there are no functions flagged as initializers in the contract.
|
|
257
260
|
*/ export function getDefaultInitializer(contractArtifact) {
|
|
258
|
-
const
|
|
261
|
+
const functionAbis = getAllFunctionAbis(contractArtifact);
|
|
262
|
+
const initializers = functionAbis.filter((f)=>f.isInitializer);
|
|
259
263
|
return initializers.length > 1 ? initializers.find((f)=>f.name === 'constructor') ?? initializers.find((f)=>f.name === 'initializer') ?? initializers.find((f)=>f.parameters?.length === 0) ?? initializers.find((f)=>f.functionType === "private") ?? initializers[0] : initializers[0];
|
|
260
264
|
}
|
|
261
265
|
/**
|
|
@@ -264,7 +268,8 @@ export function parseDebugSymbols(debugSymbols) {
|
|
|
264
268
|
* to pick the default initializer.
|
|
265
269
|
*/ export function getInitializer(contract, initializerNameOrArtifact) {
|
|
266
270
|
if (typeof initializerNameOrArtifact === 'string') {
|
|
267
|
-
const
|
|
271
|
+
const functionAbis = getAllFunctionAbis(contract);
|
|
272
|
+
const found = functionAbis.find((f)=>f.name === initializerNameOrArtifact);
|
|
268
273
|
if (!found) {
|
|
269
274
|
throw new Error(`Constructor method ${initializerNameOrArtifact} not found in contract artifact`);
|
|
270
275
|
} else if (!found.isInitializer) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import { type ContractArtifact } from '../abi/index.js';
|
|
3
|
+
import { type ContractArtifact, type FunctionArtifact } from '../abi/index.js';
|
|
4
4
|
import { type NoirCompiledContract } from '../noir/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* Serializes a contract artifact to a buffer for storage.
|
|
@@ -16,8 +16,23 @@ export declare function contractArtifactToBuffer(artifact: ContractArtifact): Bu
|
|
|
16
16
|
export declare function contractArtifactFromBuffer(buffer: Buffer): Promise<ContractArtifact>;
|
|
17
17
|
/**
|
|
18
18
|
* Gets nargo build output and returns a valid contract artifact instance.
|
|
19
|
+
* Does not include public bytecode, apart from the public_dispatch function.
|
|
19
20
|
* @param input - Input object as generated by nargo compile.
|
|
20
21
|
* @returns A valid contract artifact instance.
|
|
21
22
|
*/
|
|
22
23
|
export declare function loadContractArtifact(input: NoirCompiledContract): ContractArtifact;
|
|
24
|
+
/**
|
|
25
|
+
* Gets nargo build output and returns a valid contract artifact instance.
|
|
26
|
+
* Differs from loadContractArtifact() by retaining all bytecode.
|
|
27
|
+
* @param input - Input object as generated by nargo compile.
|
|
28
|
+
* @returns A valid contract artifact instance.
|
|
29
|
+
*/
|
|
30
|
+
export declare function loadContractArtifactForPublic(input: NoirCompiledContract): ContractArtifact;
|
|
31
|
+
/** Function from a noir contract compilation artifact */
|
|
32
|
+
type NoirCompiledContractFunction = NoirCompiledContract['functions'][number];
|
|
33
|
+
/**
|
|
34
|
+
* Returns true if we should retain bytecode
|
|
35
|
+
*/
|
|
36
|
+
export declare function retainBytecode(input: NoirCompiledContractFunction | FunctionArtifact): boolean;
|
|
37
|
+
export {};
|
|
23
38
|
//# sourceMappingURL=contract_artifact.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract_artifact.d.ts","sourceRoot":"","sources":["../../src/abi/contract_artifact.ts"],"names":[],"mappings":";;AAEA,OAAO,EAKL,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"contract_artifact.d.ts","sourceRoot":"","sources":["../../src/abi/contract_artifact.ts"],"names":[],"mappings":";;AAEA,OAAO,EAKL,KAAK,gBAAgB,EAKrB,KAAK,gBAAgB,EAKtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAML,KAAK,oBAAoB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CAE3E;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAEpF;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,oBAAoB,GAAG,gBAAgB,CAKlF;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,oBAAoB,GAAG,gBAAgB,CAE3F;AAoDD,yDAAyD;AACzD,KAAK,4BAA4B,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9E;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,4BAA4B,GAAG,gBAAgB,GAAG,OAAO,CAI9F"}
|
|
@@ -17,6 +17,7 @@ import { AZTEC_INITIALIZER_ATTRIBUTE, AZTEC_INTERNAL_ATTRIBUTE, AZTEC_PRIVATE_AT
|
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Gets nargo build output and returns a valid contract artifact instance.
|
|
20
|
+
* Does not include public bytecode, apart from the public_dispatch function.
|
|
20
21
|
* @param input - Input object as generated by nargo compile.
|
|
21
22
|
* @returns A valid contract artifact instance.
|
|
22
23
|
*/ export function loadContractArtifact(input) {
|
|
@@ -25,6 +26,14 @@ import { AZTEC_INITIALIZER_ATTRIBUTE, AZTEC_INTERNAL_ATTRIBUTE, AZTEC_PRIVATE_AT
|
|
|
25
26
|
}
|
|
26
27
|
return generateContractArtifact(input);
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Gets nargo build output and returns a valid contract artifact instance.
|
|
31
|
+
* Differs from loadContractArtifact() by retaining all bytecode.
|
|
32
|
+
* @param input - Input object as generated by nargo compile.
|
|
33
|
+
* @returns A valid contract artifact instance.
|
|
34
|
+
*/ export function loadContractArtifactForPublic(input) {
|
|
35
|
+
return generateContractArtifactForPublic(input);
|
|
36
|
+
}
|
|
28
37
|
/**
|
|
29
38
|
* Checks if the given input looks like a valid ContractArtifact. The check is not exhaustive,
|
|
30
39
|
* and it's just meant to differentiate between nargo raw build artifacts and the ones
|
|
@@ -49,6 +58,11 @@ import { AZTEC_INITIALIZER_ATTRIBUTE, AZTEC_INTERNAL_ATTRIBUTE, AZTEC_PRIVATE_AT
|
|
|
49
58
|
if (typeof fn.functionType !== 'string') {
|
|
50
59
|
return false;
|
|
51
60
|
}
|
|
61
|
+
if (!retainBytecode(fn) && fn.bytecode.length) {
|
|
62
|
+
// We want to remove the bytecode of public fns (apart from the dispatch fn) to save space
|
|
63
|
+
// If the input is private-only, we don't need to use generateContractArtifact() below
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
52
66
|
}
|
|
53
67
|
return true;
|
|
54
68
|
}
|
|
@@ -67,11 +81,17 @@ import { AZTEC_INITIALIZER_ATTRIBUTE, AZTEC_INTERNAL_ATTRIBUTE, AZTEC_PRIVATE_AT
|
|
|
67
81
|
};
|
|
68
82
|
}
|
|
69
83
|
/**
|
|
70
|
-
*
|
|
84
|
+
* Returns true if we should retain bytecode
|
|
85
|
+
*/ export function retainBytecode(input) {
|
|
86
|
+
const functionType = input.functionType ?? getFunctionType(input);
|
|
87
|
+
return functionType !== FunctionType.PUBLIC || input.name == 'public_dispatch';
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Generates a function abi.
|
|
71
91
|
* @param fn - Noir function entry.
|
|
72
92
|
* @param contract - Parent contract.
|
|
73
|
-
* @returns Function
|
|
74
|
-
*/ function
|
|
93
|
+
* @returns Function abi.
|
|
94
|
+
*/ function generateFunctionAbi(fn, contract) {
|
|
75
95
|
if (fn.custom_attributes === undefined) {
|
|
76
96
|
throw new Error(`No custom attributes found for contract function ${fn.name}. Try rebuilding the contract with the latest nargo version.`);
|
|
77
97
|
}
|
|
@@ -112,12 +132,23 @@ import { AZTEC_INITIALIZER_ATTRIBUTE, AZTEC_INTERNAL_ATTRIBUTE, AZTEC_PRIVATE_AT
|
|
|
112
132
|
isInitializer: fn.custom_attributes.includes(AZTEC_INITIALIZER_ATTRIBUTE),
|
|
113
133
|
parameters,
|
|
114
134
|
returnTypes,
|
|
115
|
-
bytecode: fn.bytecode,
|
|
116
|
-
debugSymbols: fn.debug_symbols,
|
|
117
135
|
errorTypes: fn.abi.error_types,
|
|
118
136
|
...fn.assert_messages ? {
|
|
119
137
|
assertMessages: fn.assert_messages
|
|
120
|
-
} : undefined
|
|
138
|
+
} : undefined
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Generates a function build artifact.
|
|
143
|
+
* @param fn - Noir function entry.
|
|
144
|
+
* @param contract - Parent contract.
|
|
145
|
+
* @returns Function artifact.
|
|
146
|
+
*/ function generateFunctionArtifact(fn, contract) {
|
|
147
|
+
const abi = generateFunctionAbi(fn, contract);
|
|
148
|
+
return {
|
|
149
|
+
...abi,
|
|
150
|
+
bytecode: fn.bytecode,
|
|
151
|
+
debugSymbols: fn.debug_symbols,
|
|
121
152
|
...fn.verification_key ? {
|
|
122
153
|
verificationKey: fn.verification_key
|
|
123
154
|
} : undefined
|
|
@@ -212,20 +243,39 @@ function getFunctionType(fn) {
|
|
|
212
243
|
}
|
|
213
244
|
/**
|
|
214
245
|
* Given a Nargo output generates an Aztec-compatible contract artifact.
|
|
246
|
+
* Does not include public bytecode, apart from the public_dispatch function.
|
|
247
|
+
* @param compiled - Noir build output.
|
|
248
|
+
* @returns Aztec contract build artifact.
|
|
249
|
+
*/ function generateContractArtifact(contract) {
|
|
250
|
+
try {
|
|
251
|
+
return ContractArtifactSchema.parse({
|
|
252
|
+
name: contract.name,
|
|
253
|
+
functions: contract.functions.filter((f)=>retainBytecode(f)).map((f)=>generateFunctionArtifact(f, contract)),
|
|
254
|
+
nonDispatchPublicFunctions: contract.functions.filter((f)=>!retainBytecode(f)).map((f)=>generateFunctionAbi(f, contract)),
|
|
255
|
+
outputs: contract.outputs,
|
|
256
|
+
storageLayout: getStorageLayout(contract),
|
|
257
|
+
notes: getNoteTypes(contract),
|
|
258
|
+
fileMap: contract.file_map
|
|
259
|
+
});
|
|
260
|
+
} catch (err) {
|
|
261
|
+
throw new Error(`Could not generate contract artifact for ${contract.name}: ${err}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Given a Nargo output generates an Aztec-compatible contract artifact.
|
|
266
|
+
* Retains all public bytecode.
|
|
215
267
|
* @param compiled - Noir build output.
|
|
216
268
|
* @returns Aztec contract build artifact.
|
|
217
|
-
*/ function
|
|
269
|
+
*/ function generateContractArtifactForPublic(contract) {
|
|
218
270
|
try {
|
|
219
271
|
return ContractArtifactSchema.parse({
|
|
220
272
|
name: contract.name,
|
|
221
273
|
functions: contract.functions.map((f)=>generateFunctionArtifact(f, contract)),
|
|
274
|
+
nonDispatchPublicFunctions: contract.functions.filter((f)=>!retainBytecode(f)).map((f)=>generateFunctionAbi(f, contract)),
|
|
222
275
|
outputs: contract.outputs,
|
|
223
276
|
storageLayout: getStorageLayout(contract),
|
|
224
277
|
notes: getNoteTypes(contract),
|
|
225
|
-
fileMap: contract.file_map
|
|
226
|
-
...aztecNrVersion ? {
|
|
227
|
-
aztecNrVersion
|
|
228
|
-
} : {}
|
|
278
|
+
fileMap: contract.file_map
|
|
229
279
|
});
|
|
230
280
|
} catch (err) {
|
|
231
281
|
throw new Error(`Could not generate contract artifact for ${contract.name}: ${err}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract_class.d.ts","sourceRoot":"","sources":["../../src/contract/contract_class.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE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,6 +9,8 @@ const cmpFunctionArtifacts = (a, b)=>a.selector.toField().cmp(b.selector.toField
|
|
|
9
9
|
/** Creates a ContractClass from a contract compilation artifact. */ export async function getContractClassFromArtifact(artifact) {
|
|
10
10
|
const artifactHash = 'artifactHash' in artifact ? artifact.artifactHash : await computeArtifactHash(artifact);
|
|
11
11
|
const publicFunctions = artifact.functions.filter((f)=>f.functionType === FunctionType.PUBLIC);
|
|
12
|
+
// TODO(#8985): ContractArtifact.functions should ensure that the below only contains the public dispatch function
|
|
13
|
+
// So we can likely remove this and just use the below to assign the dispatch.
|
|
12
14
|
const artifactPublicFunctions = await Promise.all(publicFunctions.map(async (f)=>({
|
|
13
15
|
selector: await FunctionSelector.fromNameAndParameters(f.name, f.parameters),
|
|
14
16
|
bytecode: f.bytecode
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
import { BufferReader } from '@aztec/foundation/serialize';
|
|
5
5
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
6
|
-
import { type ContractArtifact, type
|
|
6
|
+
import { type ContractArtifact, type FunctionAbi } from '../abi/index.js';
|
|
7
7
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
8
8
|
import { PublicKeys } from '../keys/public_keys.js';
|
|
9
9
|
import type { ContractInstance, ContractInstanceWithAddress } from './interfaces/contract_instance.js';
|
|
@@ -30,7 +30,7 @@ export declare class SerializableContractInstance {
|
|
|
30
30
|
* @returns - The contract instance
|
|
31
31
|
*/
|
|
32
32
|
export declare function getContractInstanceFromDeployParams(artifact: ContractArtifact, opts: {
|
|
33
|
-
constructorArtifact?:
|
|
33
|
+
constructorArtifact?: FunctionAbi | string;
|
|
34
34
|
constructorArgs?: any[];
|
|
35
35
|
skipArgsDecoding?: boolean;
|
|
36
36
|
salt?: Fr;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract_instance.d.ts","sourceRoot":"","sources":["../../src/contract/contract_instance.ts"],"names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AM,CAAC,OAAO;CAWf;AAED;;;;;GAKG;AACH,wBAAsB,mCAAmC,CACvD,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE;IACJ,mBAAmB,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IAC3C,eAAe,CAAC,EAAE,GAAG,EAAE,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,IAAI,CAAC,EAAE,EAAE,CAAC;IACV,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB,GACA,OAAO,CAAC,2BAA2B,CAAC,CA0BtC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
-
import { FunctionSelector, getDefaultInitializer } from '../abi/index.js';
|
|
3
|
+
import { FunctionSelector, getAllFunctionAbis, getDefaultInitializer } from '../abi/index.js';
|
|
4
4
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
5
5
|
import { getContractClassFromArtifact } from '../contract/contract_class.js';
|
|
6
6
|
import { PublicKeys } from '../keys/public_keys.js';
|
|
@@ -99,11 +99,12 @@ export class SerializableContractInstance {
|
|
|
99
99
|
}
|
|
100
100
|
function getConstructorArtifact(artifact, requestedConstructorArtifact) {
|
|
101
101
|
if (typeof requestedConstructorArtifact === 'string') {
|
|
102
|
-
const found = artifact.
|
|
102
|
+
const found = getAllFunctionAbis(artifact).find((fn)=>fn.name === requestedConstructorArtifact);
|
|
103
103
|
if (!found) {
|
|
104
104
|
throw new Error(`No constructor found with name ${requestedConstructorArtifact}`);
|
|
105
105
|
}
|
|
106
106
|
return found;
|
|
107
107
|
}
|
|
108
|
+
// TODO: shouldn't we check that requestedConstructorArtifact exists on artifact before returning?
|
|
108
109
|
return requestedConstructorArtifact ?? getDefaultInitializer(artifact);
|
|
109
110
|
}
|
|
@@ -1 +1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Qd;IACD,uCAAuC,CAAC,EAAE,MAAM,CAAC;IACjD,oCAAoC,CAAC,EAAE,MAAM,CAAC;IAC9C,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,gBAsDF,CAAC;AAEF,eAAO,MAAM,eAAe,gCAC2E,CAAC;AAExG,eAAO,MAAM,eAAe,gDAgB3B,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAAO,gBAWxC,CAAC;AAEH,eAAO,MAAM,iCAAiC,UACtC;IAAE,eAAe,CAAC,EAAE,EAAE,CAAA;CAAE,YACpB,YAAY,KACrB,QAAQ,2BAA2B,CAUrC,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;EAIlC,CAAC;AAEF,MAAM,WAAW,2BAA2B;IAC1C,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,EAAE,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAyBD,eAAO,MAAM,iBAAiB,aAAoB,2BAA2B,KAAG,QAAQ,aAAa,CAGpG,CAAC;AAGF,eAAO,MAAM,oBAAoB,aAAoB,2BAA2B,KAAG,QAAQ,gBAAgB,CAG1G,CAAC"}
|
package/dest/tests/mocks.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/stdlib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.80.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"inherits": [
|
|
6
6
|
"../package.common.json",
|
|
@@ -66,11 +66,11 @@
|
|
|
66
66
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@aztec/bb.js": "0.
|
|
70
|
-
"@aztec/blob-lib": "0.
|
|
71
|
-
"@aztec/constants": "0.
|
|
72
|
-
"@aztec/ethereum": "0.
|
|
73
|
-
"@aztec/foundation": "0.
|
|
69
|
+
"@aztec/bb.js": "0.80.0",
|
|
70
|
+
"@aztec/blob-lib": "0.80.0",
|
|
71
|
+
"@aztec/constants": "0.80.0",
|
|
72
|
+
"@aztec/ethereum": "0.80.0",
|
|
73
|
+
"@aztec/foundation": "0.80.0",
|
|
74
74
|
"lodash.chunk": "^4.2.0",
|
|
75
75
|
"lodash.isequal": "^4.5.0",
|
|
76
76
|
"lodash.omit": "^4.5.0",
|
package/src/abi/abi.ts
CHANGED
|
@@ -334,12 +334,12 @@ export interface ContractArtifact {
|
|
|
334
334
|
/** The name of the contract. */
|
|
335
335
|
name: string;
|
|
336
336
|
|
|
337
|
-
/** The
|
|
338
|
-
aztecNrVersion?: string;
|
|
339
|
-
|
|
340
|
-
/** The functions of the contract. */
|
|
337
|
+
/** The functions of the contract. Includes private and unconstrained functions, plus the public dispatch function. */
|
|
341
338
|
functions: FunctionArtifact[];
|
|
342
339
|
|
|
340
|
+
/** The public functions of the contract, excluding dispatch. */
|
|
341
|
+
nonDispatchPublicFunctions: FunctionAbi[];
|
|
342
|
+
|
|
343
343
|
/** The outputs of the contract. */
|
|
344
344
|
outputs: {
|
|
345
345
|
structs: Record<string, AbiType[]>;
|
|
@@ -358,8 +358,8 @@ export interface ContractArtifact {
|
|
|
358
358
|
|
|
359
359
|
export const ContractArtifactSchema: ZodFor<ContractArtifact> = z.object({
|
|
360
360
|
name: z.string(),
|
|
361
|
-
aztecNrVersion: z.string().optional(),
|
|
362
361
|
functions: z.array(FunctionArtifactSchema),
|
|
362
|
+
nonDispatchPublicFunctions: z.array(FunctionAbiSchema),
|
|
363
363
|
outputs: z.object({
|
|
364
364
|
structs: z.record(z.array(AbiTypeSchema)).transform(structs => {
|
|
365
365
|
for (const [key, value] of Object.entries(structs)) {
|
|
@@ -419,6 +419,11 @@ export async function getFunctionArtifact(
|
|
|
419
419
|
return { ...functionArtifact, debug: debugMetadata };
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
+
/** Gets all function abis */
|
|
423
|
+
export function getAllFunctionAbis(artifact: ContractArtifact): FunctionAbi[] {
|
|
424
|
+
return artifact.functions.map(f => f as FunctionAbi).concat(artifact.nonDispatchPublicFunctions || []);
|
|
425
|
+
}
|
|
426
|
+
|
|
422
427
|
export function parseDebugSymbols(debugSymbols: string): DebugInfo[] {
|
|
423
428
|
return JSON.parse(inflate(Buffer.from(debugSymbols, 'base64'), { to: 'string', raw: true })).debug_infos;
|
|
424
429
|
}
|
|
@@ -467,8 +472,9 @@ export function getFunctionDebugMetadata(
|
|
|
467
472
|
* @param contractArtifact - The contract artifact.
|
|
468
473
|
* @returns An initializer function, or none if there are no functions flagged as initializers in the contract.
|
|
469
474
|
*/
|
|
470
|
-
export function getDefaultInitializer(contractArtifact: ContractArtifact):
|
|
471
|
-
const
|
|
475
|
+
export function getDefaultInitializer(contractArtifact: ContractArtifact): FunctionAbi | undefined {
|
|
476
|
+
const functionAbis = getAllFunctionAbis(contractArtifact);
|
|
477
|
+
const initializers = functionAbis.filter(f => f.isInitializer);
|
|
472
478
|
return initializers.length > 1
|
|
473
479
|
? initializers.find(f => f.name === 'constructor') ??
|
|
474
480
|
initializers.find(f => f.name === 'initializer') ??
|
|
@@ -486,9 +492,10 @@ export function getDefaultInitializer(contractArtifact: ContractArtifact): Funct
|
|
|
486
492
|
export function getInitializer(
|
|
487
493
|
contract: ContractArtifact,
|
|
488
494
|
initializerNameOrArtifact: string | undefined | FunctionArtifact,
|
|
489
|
-
):
|
|
495
|
+
): FunctionAbi | undefined {
|
|
490
496
|
if (typeof initializerNameOrArtifact === 'string') {
|
|
491
|
-
const
|
|
497
|
+
const functionAbis = getAllFunctionAbis(contract);
|
|
498
|
+
const found = functionAbis.find(f => f.name === initializerNameOrArtifact);
|
|
492
499
|
if (!found) {
|
|
493
500
|
throw new Error(`Constructor method ${initializerNameOrArtifact} not found in contract artifact`);
|
|
494
501
|
} else if (!found.isInitializer) {
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ContractArtifactSchema,
|
|
10
10
|
type ContractNote,
|
|
11
11
|
type FieldLayout,
|
|
12
|
+
type FunctionAbi,
|
|
12
13
|
type FunctionArtifact,
|
|
13
14
|
FunctionType,
|
|
14
15
|
type IntegerValue,
|
|
@@ -44,6 +45,7 @@ export function contractArtifactFromBuffer(buffer: Buffer): Promise<ContractArti
|
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
47
|
* Gets nargo build output and returns a valid contract artifact instance.
|
|
48
|
+
* Does not include public bytecode, apart from the public_dispatch function.
|
|
47
49
|
* @param input - Input object as generated by nargo compile.
|
|
48
50
|
* @returns A valid contract artifact instance.
|
|
49
51
|
*/
|
|
@@ -54,6 +56,16 @@ export function loadContractArtifact(input: NoirCompiledContract): ContractArtif
|
|
|
54
56
|
return generateContractArtifact(input);
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Gets nargo build output and returns a valid contract artifact instance.
|
|
61
|
+
* Differs from loadContractArtifact() by retaining all bytecode.
|
|
62
|
+
* @param input - Input object as generated by nargo compile.
|
|
63
|
+
* @returns A valid contract artifact instance.
|
|
64
|
+
*/
|
|
65
|
+
export function loadContractArtifactForPublic(input: NoirCompiledContract): ContractArtifact {
|
|
66
|
+
return generateContractArtifactForPublic(input);
|
|
67
|
+
}
|
|
68
|
+
|
|
57
69
|
/**
|
|
58
70
|
* Checks if the given input looks like a valid ContractArtifact. The check is not exhaustive,
|
|
59
71
|
* and it's just meant to differentiate between nargo raw build artifacts and the ones
|
|
@@ -79,6 +91,11 @@ function isContractArtifact(input: any): input is ContractArtifact {
|
|
|
79
91
|
if (typeof fn.functionType !== 'string') {
|
|
80
92
|
return false;
|
|
81
93
|
}
|
|
94
|
+
if (!retainBytecode(fn) && fn.bytecode.length) {
|
|
95
|
+
// We want to remove the bytecode of public fns (apart from the dispatch fn) to save space
|
|
96
|
+
// If the input is private-only, we don't need to use generateContractArtifact() below
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
82
99
|
}
|
|
83
100
|
return true;
|
|
84
101
|
}
|
|
@@ -103,15 +120,21 @@ function generateFunctionParameter(param: NoirCompiledContractFunctionParameter)
|
|
|
103
120
|
type NoirCompiledContractFunction = NoirCompiledContract['functions'][number];
|
|
104
121
|
|
|
105
122
|
/**
|
|
106
|
-
*
|
|
123
|
+
* Returns true if we should retain bytecode
|
|
124
|
+
*/
|
|
125
|
+
export function retainBytecode(input: NoirCompiledContractFunction | FunctionArtifact): boolean {
|
|
126
|
+
const functionType =
|
|
127
|
+
(input as FunctionArtifact).functionType ?? getFunctionType(input as NoirCompiledContractFunction);
|
|
128
|
+
return functionType !== FunctionType.PUBLIC || input.name == 'public_dispatch';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Generates a function abi.
|
|
107
133
|
* @param fn - Noir function entry.
|
|
108
134
|
* @param contract - Parent contract.
|
|
109
|
-
* @returns Function
|
|
135
|
+
* @returns Function abi.
|
|
110
136
|
*/
|
|
111
|
-
function
|
|
112
|
-
fn: NoirCompiledContractFunction,
|
|
113
|
-
contract: NoirCompiledContract,
|
|
114
|
-
): Omit<FunctionArtifact, 'bytecode'> & { bytecode: string } {
|
|
137
|
+
function generateFunctionAbi(fn: NoirCompiledContractFunction, contract: NoirCompiledContract): FunctionAbi {
|
|
115
138
|
if (fn.custom_attributes === undefined) {
|
|
116
139
|
throw new Error(
|
|
117
140
|
`No custom attributes found for contract function ${fn.name}. Try rebuilding the contract with the latest nargo version.`,
|
|
@@ -156,10 +179,26 @@ function generateFunctionArtifact(
|
|
|
156
179
|
isInitializer: fn.custom_attributes.includes(AZTEC_INITIALIZER_ATTRIBUTE),
|
|
157
180
|
parameters,
|
|
158
181
|
returnTypes,
|
|
159
|
-
bytecode: fn.bytecode,
|
|
160
|
-
debugSymbols: fn.debug_symbols,
|
|
161
182
|
errorTypes: fn.abi.error_types,
|
|
162
183
|
...(fn.assert_messages ? { assertMessages: fn.assert_messages } : undefined),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Generates a function build artifact.
|
|
189
|
+
* @param fn - Noir function entry.
|
|
190
|
+
* @param contract - Parent contract.
|
|
191
|
+
* @returns Function artifact.
|
|
192
|
+
*/
|
|
193
|
+
function generateFunctionArtifact(
|
|
194
|
+
fn: NoirCompiledContractFunction,
|
|
195
|
+
contract: NoirCompiledContract,
|
|
196
|
+
): Omit<FunctionArtifact, 'bytecode'> & { bytecode: string } {
|
|
197
|
+
const abi = generateFunctionAbi(fn, contract);
|
|
198
|
+
return {
|
|
199
|
+
...abi,
|
|
200
|
+
bytecode: fn.bytecode,
|
|
201
|
+
debugSymbols: fn.debug_symbols,
|
|
163
202
|
...(fn.verification_key ? { verificationKey: fn.verification_key } : undefined),
|
|
164
203
|
};
|
|
165
204
|
}
|
|
@@ -274,19 +313,46 @@ function getNoteTypes(input: NoirCompiledContract) {
|
|
|
274
313
|
|
|
275
314
|
/**
|
|
276
315
|
* Given a Nargo output generates an Aztec-compatible contract artifact.
|
|
316
|
+
* Does not include public bytecode, apart from the public_dispatch function.
|
|
317
|
+
* @param compiled - Noir build output.
|
|
318
|
+
* @returns Aztec contract build artifact.
|
|
319
|
+
*/
|
|
320
|
+
function generateContractArtifact(contract: NoirCompiledContract): ContractArtifact {
|
|
321
|
+
try {
|
|
322
|
+
return ContractArtifactSchema.parse({
|
|
323
|
+
name: contract.name,
|
|
324
|
+
functions: contract.functions.filter(f => retainBytecode(f)).map(f => generateFunctionArtifact(f, contract)),
|
|
325
|
+
nonDispatchPublicFunctions: contract.functions
|
|
326
|
+
.filter(f => !retainBytecode(f))
|
|
327
|
+
.map(f => generateFunctionAbi(f, contract)),
|
|
328
|
+
outputs: contract.outputs,
|
|
329
|
+
storageLayout: getStorageLayout(contract),
|
|
330
|
+
notes: getNoteTypes(contract),
|
|
331
|
+
fileMap: contract.file_map,
|
|
332
|
+
});
|
|
333
|
+
} catch (err) {
|
|
334
|
+
throw new Error(`Could not generate contract artifact for ${contract.name}: ${err}`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Given a Nargo output generates an Aztec-compatible contract artifact.
|
|
340
|
+
* Retains all public bytecode.
|
|
277
341
|
* @param compiled - Noir build output.
|
|
278
342
|
* @returns Aztec contract build artifact.
|
|
279
343
|
*/
|
|
280
|
-
function
|
|
344
|
+
function generateContractArtifactForPublic(contract: NoirCompiledContract): ContractArtifact {
|
|
281
345
|
try {
|
|
282
346
|
return ContractArtifactSchema.parse({
|
|
283
347
|
name: contract.name,
|
|
284
348
|
functions: contract.functions.map(f => generateFunctionArtifact(f, contract)),
|
|
349
|
+
nonDispatchPublicFunctions: contract.functions
|
|
350
|
+
.filter(f => !retainBytecode(f))
|
|
351
|
+
.map(f => generateFunctionAbi(f, contract)),
|
|
285
352
|
outputs: contract.outputs,
|
|
286
353
|
storageLayout: getStorageLayout(contract),
|
|
287
354
|
notes: getNoteTypes(contract),
|
|
288
355
|
fileMap: contract.file_map,
|
|
289
|
-
...(aztecNrVersion ? { aztecNrVersion } : {}),
|
|
290
356
|
});
|
|
291
357
|
} catch (err) {
|
|
292
358
|
throw new Error(`Could not generate contract artifact for ${contract.name}: ${err}`);
|
|
@@ -20,6 +20,8 @@ export async function getContractClassFromArtifact(
|
|
|
20
20
|
): Promise<ContractClassWithId & ContractClassIdPreimage> {
|
|
21
21
|
const artifactHash = 'artifactHash' in artifact ? artifact.artifactHash : await computeArtifactHash(artifact);
|
|
22
22
|
const publicFunctions = artifact.functions.filter(f => f.functionType === FunctionType.PUBLIC);
|
|
23
|
+
// TODO(#8985): ContractArtifact.functions should ensure that the below only contains the public dispatch function
|
|
24
|
+
// So we can likely remove this and just use the below to assign the dispatch.
|
|
23
25
|
const artifactPublicFunctions: ContractClass['publicFunctions'] = await Promise.all(
|
|
24
26
|
publicFunctions.map(async f => ({
|
|
25
27
|
selector: await FunctionSelector.fromNameAndParameters(f.name, f.parameters),
|
|
@@ -2,7 +2,14 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
2
2
|
import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
3
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
type ContractArtifact,
|
|
7
|
+
type FunctionAbi,
|
|
8
|
+
type FunctionArtifact,
|
|
9
|
+
FunctionSelector,
|
|
10
|
+
getAllFunctionAbis,
|
|
11
|
+
getDefaultInitializer,
|
|
12
|
+
} from '../abi/index.js';
|
|
6
13
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
7
14
|
import { getContractClassFromArtifact } from '../contract/contract_class.js';
|
|
8
15
|
import { PublicKeys } from '../keys/public_keys.js';
|
|
@@ -101,7 +108,7 @@ export class SerializableContractInstance {
|
|
|
101
108
|
export async function getContractInstanceFromDeployParams(
|
|
102
109
|
artifact: ContractArtifact,
|
|
103
110
|
opts: {
|
|
104
|
-
constructorArtifact?:
|
|
111
|
+
constructorArtifact?: FunctionAbi | string;
|
|
105
112
|
constructorArgs?: any[];
|
|
106
113
|
skipArgsDecoding?: boolean;
|
|
107
114
|
salt?: Fr;
|
|
@@ -138,14 +145,15 @@ export async function getContractInstanceFromDeployParams(
|
|
|
138
145
|
|
|
139
146
|
function getConstructorArtifact(
|
|
140
147
|
artifact: ContractArtifact,
|
|
141
|
-
requestedConstructorArtifact: FunctionArtifact | string | undefined,
|
|
142
|
-
):
|
|
148
|
+
requestedConstructorArtifact: FunctionArtifact | FunctionAbi | string | undefined,
|
|
149
|
+
): FunctionAbi | undefined {
|
|
143
150
|
if (typeof requestedConstructorArtifact === 'string') {
|
|
144
|
-
const found = artifact.
|
|
151
|
+
const found = getAllFunctionAbis(artifact).find(fn => fn.name === requestedConstructorArtifact);
|
|
145
152
|
if (!found) {
|
|
146
153
|
throw new Error(`No constructor found with name ${requestedConstructorArtifact}`);
|
|
147
154
|
}
|
|
148
155
|
return found;
|
|
149
156
|
}
|
|
157
|
+
// TODO: shouldn't we check that requestedConstructorArtifact exists on artifact before returning?
|
|
150
158
|
return requestedConstructorArtifact ?? getDefaultInitializer(artifact);
|
|
151
159
|
}
|
package/src/tests/mocks.ts
CHANGED
|
@@ -228,6 +228,7 @@ export const mockSimulatedTx = async (seed = 1) => {
|
|
|
228
228
|
export const randomContractArtifact = (): ContractArtifact => ({
|
|
229
229
|
name: randomBytes(4).toString('hex'),
|
|
230
230
|
functions: [],
|
|
231
|
+
nonDispatchPublicFunctions: [],
|
|
231
232
|
outputs: {
|
|
232
233
|
structs: {},
|
|
233
234
|
globals: {},
|