@aztec-labs/protocol-contracts 6.0.0-nightly.20260829
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/README.md +7 -0
- package/artifacts/ContractClassRegistry.d.json.ts +5 -0
- package/artifacts/ContractClassRegistry.json +4206 -0
- package/artifacts/ContractInstanceRegistry.d.json.ts +5 -0
- package/artifacts/ContractInstanceRegistry.json +5544 -0
- package/artifacts/FeeJuice.d.json.ts +5 -0
- package/artifacts/FeeJuice.json +7356 -0
- package/dest/class-registry/contract_class_published_event.d.ts +20 -0
- package/dest/class-registry/contract_class_published_event.d.ts.map +1 -0
- package/dest/class-registry/contract_class_published_event.js +58 -0
- package/dest/class-registry/index.d.ts +6 -0
- package/dest/class-registry/index.d.ts.map +1 -0
- package/dest/class-registry/index.js +15 -0
- package/dest/class-registry/lazy.d.ts +7 -0
- package/dest/class-registry/lazy.d.ts.map +1 -0
- package/dest/class-registry/lazy.js +24 -0
- package/dest/fee-juice/index.d.ts +15 -0
- package/dest/fee-juice/index.d.ts.map +1 -0
- package/dest/fee-juice/index.js +26 -0
- package/dest/fee-juice/lazy.d.ts +6 -0
- package/dest/fee-juice/lazy.d.ts.map +1 -0
- package/dest/fee-juice/lazy.js +23 -0
- package/dest/index.d.ts +3 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +2 -0
- package/dest/instance-registry/contract_instance_published_event.d.ts +22 -0
- package/dest/instance-registry/contract_instance_published_event.d.ts.map +1 -0
- package/dest/instance-registry/contract_instance_published_event.js +60 -0
- package/dest/instance-registry/contract_instance_updated_event.d.ts +17 -0
- package/dest/instance-registry/contract_instance_updated_event.d.ts.map +1 -0
- package/dest/instance-registry/contract_instance_updated_event.js +35 -0
- package/dest/instance-registry/index.d.ts +7 -0
- package/dest/instance-registry/index.d.ts.map +1 -0
- package/dest/instance-registry/index.js +15 -0
- package/dest/instance-registry/lazy.d.ts +8 -0
- package/dest/instance-registry/lazy.d.ts.map +1 -0
- package/dest/instance-registry/lazy.js +25 -0
- package/dest/make_protocol_contract.d.ts +9 -0
- package/dest/make_protocol_contract.d.ts.map +1 -0
- package/dest/make_protocol_contract.js +39 -0
- package/dest/protocol_contract.d.ts +20 -0
- package/dest/protocol_contract.d.ts.map +1 -0
- package/dest/protocol_contract.js +8 -0
- package/dest/protocol_contract_data.d.ts +28 -0
- package/dest/protocol_contract_data.d.ts.map +1 -0
- package/dest/protocol_contract_data.js +91 -0
- package/dest/provider/bundle.d.ts +9 -0
- package/dest/provider/bundle.d.ts.map +1 -0
- package/dest/provider/bundle.js +14 -0
- package/dest/provider/lazy.d.ts +7 -0
- package/dest/provider/lazy.d.ts.map +1 -0
- package/dest/provider/lazy.js +17 -0
- package/dest/provider/protocol_contracts_provider.d.ts +7 -0
- package/dest/provider/protocol_contracts_provider.d.ts.map +1 -0
- package/dest/provider/protocol_contracts_provider.js +1 -0
- package/dest/scripts/cleanup_artifacts.js +16 -0
- package/dest/scripts/generate_data.js +214 -0
- package/dest/tests/fixtures.d.ts +4 -0
- package/dest/tests/fixtures.d.ts.map +1 -0
- package/dest/tests/fixtures.js +16 -0
- package/package.json +107 -0
- package/src/class-registry/__snapshots__/README.md +9 -0
- package/src/class-registry/contract_class_published_event.ts +77 -0
- package/src/class-registry/index.ts +21 -0
- package/src/class-registry/lazy.ts +31 -0
- package/src/fee-juice/index.ts +37 -0
- package/src/fee-juice/lazy.ts +29 -0
- package/src/index.ts +2 -0
- package/src/instance-registry/__snapshots__/README.md +9 -0
- package/src/instance-registry/contract_instance_published_event.ts +74 -0
- package/src/instance-registry/contract_instance_updated_event.ts +44 -0
- package/src/instance-registry/index.ts +23 -0
- package/src/instance-registry/lazy.ts +32 -0
- package/src/make_protocol_contract.ts +50 -0
- package/src/protocol_contract.ts +35 -0
- package/src/protocol_contract_data.ts +101 -0
- package/src/provider/bundle.ts +21 -0
- package/src/provider/lazy.ts +21 -0
- package/src/provider/protocol_contracts_provider.ts +7 -0
- package/src/tests/fixtures.ts +19 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// GENERATED FILE - DO NOT EDIT. RUN `yarn generate` or `yarn generate:data`
|
|
2
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
3
|
+
import { FunctionSelector } from '@aztec-labs/stdlib/abi';
|
|
4
|
+
import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
5
|
+
import { ProtocolContracts } from '@aztec-labs/stdlib/tx';
|
|
6
|
+
export const protocolContractNames = [
|
|
7
|
+
'ContractInstanceRegistry',
|
|
8
|
+
'ContractClassRegistry',
|
|
9
|
+
'FeeJuice'
|
|
10
|
+
];
|
|
11
|
+
export const ProtocolContractSalt = {
|
|
12
|
+
ContractInstanceRegistry: new Fr(1),
|
|
13
|
+
ContractClassRegistry: new Fr(1),
|
|
14
|
+
FeeJuice: new Fr(1)
|
|
15
|
+
};
|
|
16
|
+
export const ProtocolContractAddress = {
|
|
17
|
+
ContractInstanceRegistry: AztecAddress.fromBigIntUnsafe(2n),
|
|
18
|
+
ContractClassRegistry: AztecAddress.fromBigIntUnsafe(1n),
|
|
19
|
+
FeeJuice: AztecAddress.fromBigIntUnsafe(3n)
|
|
20
|
+
};
|
|
21
|
+
export const ProtocolContractDerivedAddress = {
|
|
22
|
+
ContractInstanceRegistry: AztecAddress.fromStringUnsafe('0x2d822c19c286cf1b249431a6c5ffb1864f627b469a6386574da83f44800d6c17'),
|
|
23
|
+
ContractClassRegistry: AztecAddress.fromStringUnsafe('0x1bbb52d2b4ac8c634f4b5026f2228580627c918895c369495f71caae13d996fe'),
|
|
24
|
+
FeeJuice: AztecAddress.fromStringUnsafe('0x1df1b0934b368c073f61d3cdb2de064766cd44ea4429f7920959f4a7758ef208')
|
|
25
|
+
};
|
|
26
|
+
export const ProtocolContractClassId = {
|
|
27
|
+
ContractInstanceRegistry: Fr.fromString('0x28d8b9fff43315ce084cbd127532c8a1bb562fe1f147aee518c2c8ca822dcd4a'),
|
|
28
|
+
ContractClassRegistry: Fr.fromString('0x0026d0944a8b8204b840c37cf238b145bdd6b1af9daf59eeb5e689022a708e5e'),
|
|
29
|
+
FeeJuice: Fr.fromString('0x013e4ae6015db998dabfe78684c8b9e2fe413d316b36395091f53b9ea40f15ed')
|
|
30
|
+
};
|
|
31
|
+
export const ProtocolContractClassIdPreimage = {
|
|
32
|
+
ContractInstanceRegistry: {
|
|
33
|
+
artifactHash: Fr.fromString('0x19835337f0aee2e9042f3a0ae0d334bdb39ecb22794b40d2670d26b2ca72b98f'),
|
|
34
|
+
privateFunctionsRoot: Fr.fromString('0x05bb912d9d2871492d76c610472544d8219df70aa874768f9667e99861d7971f'),
|
|
35
|
+
publicBytecodeCommitment: Fr.fromString('0x1fd8380bb220e7d13db681da7e62c93b03add6754895a84c51d13fcde03e8d25')
|
|
36
|
+
},
|
|
37
|
+
ContractClassRegistry: {
|
|
38
|
+
artifactHash: Fr.fromString('0x0d0ef0a61d9c829c306eee702aa7914299d58e7d3fc9f11d5aebd38c838fa1d0'),
|
|
39
|
+
privateFunctionsRoot: Fr.fromString('0x119c77be6d76c221642b63a337d94bf7b6ed8f872927ef3645c7e6b5002baa34'),
|
|
40
|
+
publicBytecodeCommitment: Fr.fromString('0x0ce4c618c3ed7f3a20410e618c06bb701e150af7fe28a3e92f68e7733809f33e')
|
|
41
|
+
},
|
|
42
|
+
FeeJuice: {
|
|
43
|
+
artifactHash: Fr.fromString('0x100f61126a468cb2c4b5bad99a769256f7944830ea7b396225975a8628bd37a6'),
|
|
44
|
+
privateFunctionsRoot: Fr.fromString('0x1c4bf54a4a33e3b9eae6f816dfc81e128d76d2646807a5443598c8adbd47f81f'),
|
|
45
|
+
publicBytecodeCommitment: Fr.fromString('0x2968eb109f722c701d59d171c32d32b79199841f0044d6bbd77dc43bd513a770')
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
export const ProtocolContractInitializationHash = {
|
|
49
|
+
ContractInstanceRegistry: Fr.fromString('0x0000000000000000000000000000000000000000000000000000000000000000'),
|
|
50
|
+
ContractClassRegistry: Fr.fromString('0x0000000000000000000000000000000000000000000000000000000000000000'),
|
|
51
|
+
FeeJuice: Fr.fromString('0x0000000000000000000000000000000000000000000000000000000000000000')
|
|
52
|
+
};
|
|
53
|
+
export const ProtocolContractPrivateFunctions = {
|
|
54
|
+
ContractInstanceRegistry: [
|
|
55
|
+
{
|
|
56
|
+
selector: FunctionSelector.fromField(Fr.fromString('0x0000000000000000000000000000000000000000000000000000000077cff62f')),
|
|
57
|
+
vkHash: Fr.fromString('0x19172c0acecd517dd8995c2e36178ca2aa16cbe001c3606d8cd848776ab80d23')
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
ContractClassRegistry: [
|
|
61
|
+
{
|
|
62
|
+
selector: FunctionSelector.fromField(Fr.fromString('0x000000000000000000000000000000000000000000000000000000006934ed0d')),
|
|
63
|
+
vkHash: Fr.fromString('0x1241fdbf61631c59b977bb6a520cafe3169604036705b8680dea59f05fb71251')
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
FeeJuice: [
|
|
67
|
+
{
|
|
68
|
+
selector: FunctionSelector.fromField(Fr.fromString('0x00000000000000000000000000000000000000000000000000000000cbe67243')),
|
|
69
|
+
vkHash: Fr.fromString('0x0bdf2e5c4467f295f8defb436546a7f2e642e7fe75786d0d54aef497b76527a1')
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
selector: FunctionSelector.fromField(Fr.fromString('0x00000000000000000000000000000000000000000000000000000000e8d374b6')),
|
|
73
|
+
vkHash: Fr.fromString('0x2616a94d2d2981737c31ed7d74b9fd32ddc8376bf436dd60fb2507662b47c6dd')
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
};
|
|
77
|
+
export const ProtocolContractsList = new ProtocolContracts([
|
|
78
|
+
AztecAddress.fromStringUnsafe('0x1bbb52d2b4ac8c634f4b5026f2228580627c918895c369495f71caae13d996fe'),
|
|
79
|
+
AztecAddress.fromStringUnsafe('0x2d822c19c286cf1b249431a6c5ffb1864f627b469a6386574da83f44800d6c17'),
|
|
80
|
+
AztecAddress.fromStringUnsafe('0x1df1b0934b368c073f61d3cdb2de064766cd44ea4429f7920959f4a7758ef208'),
|
|
81
|
+
AztecAddress.fromStringUnsafe('0x0000000000000000000000000000000000000000000000000000000000000000'),
|
|
82
|
+
AztecAddress.fromStringUnsafe('0x0000000000000000000000000000000000000000000000000000000000000000'),
|
|
83
|
+
AztecAddress.fromStringUnsafe('0x0000000000000000000000000000000000000000000000000000000000000000'),
|
|
84
|
+
AztecAddress.fromStringUnsafe('0x0000000000000000000000000000000000000000000000000000000000000000'),
|
|
85
|
+
AztecAddress.fromStringUnsafe('0x0000000000000000000000000000000000000000000000000000000000000000'),
|
|
86
|
+
AztecAddress.fromStringUnsafe('0x0000000000000000000000000000000000000000000000000000000000000000'),
|
|
87
|
+
AztecAddress.fromStringUnsafe('0x0000000000000000000000000000000000000000000000000000000000000000'),
|
|
88
|
+
AztecAddress.fromStringUnsafe('0x0000000000000000000000000000000000000000000000000000000000000000')
|
|
89
|
+
]);
|
|
90
|
+
export const protocolContractsHash = Fr.fromString('0x14cec0ae6f31e913c3be04691c6d49c3ec07b3f2d024c9558693ea62fc530bbf');
|
|
91
|
+
export const CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG = Fr.fromHexString('0x1a7e1badb79abdd38c684b3c8306ffe7ecb33c69e3380d9855730aaaa83a21a8');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
|
|
2
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
3
|
+
import type { ProtocolContractName } from '../protocol_contract_data.js';
|
|
4
|
+
import type { ProtocolContractsProvider } from './protocol_contracts_provider.js';
|
|
5
|
+
export declare const ProtocolContractArtifact: Record<ProtocolContractName, ContractArtifact>;
|
|
6
|
+
export declare class BundledProtocolContractsProvider implements ProtocolContractsProvider {
|
|
7
|
+
getProtocolContractArtifact(name: ProtocolContractName): Promise<ProtocolContract>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVuZGxlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHJvdmlkZXIvYnVuZGxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFNL0QsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBRSxNQUFNLDhCQUE4QixDQUFDO0FBQ3pFLE9BQU8sS0FBSyxFQUFFLHlCQUF5QixFQUFFLE1BQU0sa0NBQWtDLENBQUM7QUFFbEYsZUFBTyxNQUFNLHdCQUF3QixFQUFFLE1BQU0sQ0FBQyxvQkFBb0IsRUFBRSxnQkFBZ0IsQ0FJbkYsQ0FBQztBQUVGLHFCQUFhLGdDQUFpQyxZQUFXLHlCQUF5QjtJQUNoRiwyQkFBMkIsQ0FBQyxJQUFJLEVBQUUsb0JBQW9CLEdBQUcsT0FBTyxDQUFDLGdCQUFnQixDQUFDLENBRWpGO0NBQ0YifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/provider/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAElF,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,oBAAoB,EAAE,gBAAgB,CAInF,CAAC;AAEF,qBAAa,gCAAiC,YAAW,yBAAyB;IAChF,2BAA2B,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAEjF;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ContractClassRegistryArtifact } from '../class-registry/index.js';
|
|
2
|
+
import { FeeJuiceArtifact } from '../fee-juice/index.js';
|
|
3
|
+
import { ContractInstanceRegistryArtifact } from '../instance-registry/index.js';
|
|
4
|
+
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
5
|
+
export const ProtocolContractArtifact = {
|
|
6
|
+
ContractInstanceRegistry: ContractInstanceRegistryArtifact,
|
|
7
|
+
ContractClassRegistry: ContractClassRegistryArtifact,
|
|
8
|
+
FeeJuice: FeeJuiceArtifact
|
|
9
|
+
};
|
|
10
|
+
export class BundledProtocolContractsProvider {
|
|
11
|
+
getProtocolContractArtifact(name) {
|
|
12
|
+
return Promise.resolve(makeProtocolContract(name, ProtocolContractArtifact[name]));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
2
|
+
import type { ProtocolContractName } from '../protocol_contract_data.js';
|
|
3
|
+
import type { ProtocolContractsProvider } from './protocol_contracts_provider.js';
|
|
4
|
+
export declare class LazyProtocolContractsProvider implements ProtocolContractsProvider {
|
|
5
|
+
getProtocolContractArtifact(name: ProtocolContractName): Promise<ProtocolContract>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGF6eS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3Byb3ZpZGVyL2xhenkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0EsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBRSxNQUFNLDhCQUE4QixDQUFDO0FBQ3pFLE9BQU8sS0FBSyxFQUFFLHlCQUF5QixFQUFFLE1BQU0sa0NBQWtDLENBQUM7QUFFbEYscUJBQWEsNkJBQThCLFlBQVcseUJBQXlCO0lBQzdFLDJCQUEyQixDQUFDLElBQUksRUFBRSxvQkFBb0IsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FXakY7Q0FDRiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../src/provider/lazy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAElF,qBAAa,6BAA8B,YAAW,yBAAyB;IAC7E,2BAA2B,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAWjF;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getCanonicalClassRegistry } from '../class-registry/lazy.js';
|
|
2
|
+
import { getCanonicalFeeJuice } from '../fee-juice/lazy.js';
|
|
3
|
+
import { getCanonicalInstanceRegistry } from '../instance-registry/lazy.js';
|
|
4
|
+
export class LazyProtocolContractsProvider {
|
|
5
|
+
getProtocolContractArtifact(name) {
|
|
6
|
+
switch(name){
|
|
7
|
+
case 'ContractInstanceRegistry':
|
|
8
|
+
return getCanonicalInstanceRegistry();
|
|
9
|
+
case 'ContractClassRegistry':
|
|
10
|
+
return getCanonicalClassRegistry();
|
|
11
|
+
case 'FeeJuice':
|
|
12
|
+
return getCanonicalFeeJuice();
|
|
13
|
+
default:
|
|
14
|
+
throw new Error(`Unknown protocol contract name: ${name}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
2
|
+
import type { ProtocolContractName } from '../protocol_contract_data.js';
|
|
3
|
+
/** Returns the canonical deployment of a given artifact. */
|
|
4
|
+
export interface ProtocolContractsProvider {
|
|
5
|
+
getProtocolContractArtifact(name: ProtocolContractName): Promise<ProtocolContract>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvdG9jb2xfY29udHJhY3RzX3Byb3ZpZGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHJvdmlkZXIvcHJvdG9jb2xfY29udHJhY3RzX3Byb3ZpZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDaEUsT0FBTyxLQUFLLEVBQUUsb0JBQW9CLEVBQUUsTUFBTSw4QkFBOEIsQ0FBQztBQUV6RSw0REFBNEQ7QUFDNUQsTUFBTSxXQUFXLHlCQUF5QjtJQUN4QywyQkFBMkIsQ0FBQyxJQUFJLEVBQUUsb0JBQW9CLEdBQUcsT0FBTyxDQUFDLGdCQUFnQixDQUFDLENBQUM7Q0FDcEYifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol_contracts_provider.d.ts","sourceRoot":"","sources":["../../src/provider/protocol_contracts_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,4DAA4D;AAC5D,MAAM,WAAW,yBAAyB;IACxC,2BAA2B,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACpF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/** Returns the canonical deployment of a given artifact. */ export { };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { fileURLToPath } from '@aztec-labs/foundation/url';
|
|
2
|
+
import { readFile, readdir, writeFile } from 'fs/promises';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
async function cleanupArtifacts(target) {
|
|
5
|
+
const files = await readdir(target);
|
|
6
|
+
for (const file of files){
|
|
7
|
+
if (!file.endsWith('.json')) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
const fileData = JSON.parse((await readFile(join(target, file), 'utf8')).toString());
|
|
11
|
+
/* eslint-disable camelcase */ fileData.file_map = {};
|
|
12
|
+
fileData.debug_symbols = {};
|
|
13
|
+
/* eslint-enable camelcase */ await writeFile(join(target, file), JSON.stringify(fileData));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
await cleanupArtifacts(fileURLToPath(new URL('../../artifacts', import.meta.url).href));
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// Reads compiled Noir artifacts for each protocol contract and derives their addresses, class IDs,
|
|
2
|
+
// bytecode commitments, and other deployment data, emitting everything as precomputed constants into
|
|
3
|
+
// `protocol_contract_data.ts`. This avoids clients repeating the expensive hashing at runtime and
|
|
4
|
+
// ensures a single source of truth for the protocol contracts hash enforced by circuits, P2P, and L1.
|
|
5
|
+
import { CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS, CONTRACT_INSTANCE_PUBLISHED_MAGIC_VALUE, CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, FEE_JUICE_ADDRESS, MAX_PROTOCOL_CONTRACTS } from '@aztec-labs/constants';
|
|
6
|
+
import { makeTuple } from '@aztec-labs/foundation/array';
|
|
7
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
8
|
+
import { createConsoleLogger } from '@aztec-labs/foundation/log';
|
|
9
|
+
import { fileURLToPath } from '@aztec-labs/foundation/url';
|
|
10
|
+
import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
|
|
11
|
+
import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
12
|
+
import { computeContractAddressFromInstance, computeInitializationHash, getContractClassFromArtifact } from '@aztec-labs/stdlib/contract';
|
|
13
|
+
import { computeSiloedPrivateLogFirstField } from '@aztec-labs/stdlib/hash';
|
|
14
|
+
import { PublicKeys } from '@aztec-labs/stdlib/keys';
|
|
15
|
+
import { ProtocolContracts } from '@aztec-labs/stdlib/tx';
|
|
16
|
+
import { promises as fs } from 'fs';
|
|
17
|
+
import path from 'path';
|
|
18
|
+
const log = createConsoleLogger('autogenerate');
|
|
19
|
+
const artifactsPkgRoot = path.dirname(fileURLToPath(import.meta.resolve('@aztec/protocol-contracts-artifacts/package.json')));
|
|
20
|
+
const srcPath = path.join(artifactsPkgRoot, 'artifacts');
|
|
21
|
+
const destArtifactsDir = './artifacts';
|
|
22
|
+
const outputFilePath = './src/protocol_contract_data.ts';
|
|
23
|
+
const salt = new Fr(1);
|
|
24
|
+
const contractAddressMapping = {
|
|
25
|
+
ContractInstanceRegistry: CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
|
|
26
|
+
ContractClassRegistry: CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS,
|
|
27
|
+
FeeJuice: FEE_JUICE_ADDRESS
|
|
28
|
+
};
|
|
29
|
+
async function clearDestDir() {
|
|
30
|
+
try {
|
|
31
|
+
await fs.access(destArtifactsDir);
|
|
32
|
+
// If the directory exists, remove it recursively.
|
|
33
|
+
await fs.rm(destArtifactsDir, {
|
|
34
|
+
recursive: true,
|
|
35
|
+
force: true,
|
|
36
|
+
maxRetries: 3
|
|
37
|
+
});
|
|
38
|
+
} catch (err) {
|
|
39
|
+
if (err.code === 'ENOENT') {
|
|
40
|
+
// If the directory does not exist, do nothing.
|
|
41
|
+
} else {
|
|
42
|
+
log(`Error removing dest directory: ${err}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
await fs.mkdir(destArtifactsDir, {
|
|
46
|
+
recursive: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async function copyArtifact(srcName, destName) {
|
|
50
|
+
const src = path.join(srcPath, `${srcName}.json`);
|
|
51
|
+
const artifact = JSON.parse(await fs.readFile(src, 'utf8'));
|
|
52
|
+
const dest = path.join(destArtifactsDir, `${destName}.json`);
|
|
53
|
+
await fs.copyFile(src, dest);
|
|
54
|
+
return artifact;
|
|
55
|
+
}
|
|
56
|
+
// Precompute all the expensive contract data that can be obtained from the artifact, to avoid redundant computations in clients.
|
|
57
|
+
// Protocol contracts come from a trusted source, so no class verifications are needed.
|
|
58
|
+
async function computeContractData(artifact, deployer) {
|
|
59
|
+
const loaded = loadContractArtifact(artifact);
|
|
60
|
+
const contractClass = await getContractClassFromArtifact(loaded);
|
|
61
|
+
const constructorArtifact = loaded.functions.find((f)=>f.name === 'constructor');
|
|
62
|
+
const initializationHash = await computeInitializationHash(constructorArtifact, []);
|
|
63
|
+
const instance = {
|
|
64
|
+
version: 2,
|
|
65
|
+
currentContractClassId: contractClass.id,
|
|
66
|
+
originalContractClassId: contractClass.id,
|
|
67
|
+
initializationHash,
|
|
68
|
+
immutablesHash: Fr.ZERO,
|
|
69
|
+
publicKeys: PublicKeys.default(),
|
|
70
|
+
salt,
|
|
71
|
+
deployer
|
|
72
|
+
};
|
|
73
|
+
const address = await computeContractAddressFromInstance(instance);
|
|
74
|
+
return {
|
|
75
|
+
address,
|
|
76
|
+
classId: contractClass.id,
|
|
77
|
+
artifactHash: contractClass.artifactHash,
|
|
78
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
79
|
+
publicBytecodeCommitment: contractClass.publicBytecodeCommitment,
|
|
80
|
+
initializationHash,
|
|
81
|
+
privateFunctions: contractClass.privateFunctions
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async function generateDeclarationFile(destName) {
|
|
85
|
+
const content = `
|
|
86
|
+
import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
|
|
87
|
+
const circuit: NoirCompiledContract;
|
|
88
|
+
export = circuit;
|
|
89
|
+
`;
|
|
90
|
+
await fs.writeFile(path.join(destArtifactsDir, `${destName}.d.json.ts`), content);
|
|
91
|
+
}
|
|
92
|
+
function generateNames(names) {
|
|
93
|
+
return `
|
|
94
|
+
export const protocolContractNames = [
|
|
95
|
+
${names.map((name)=>`'${name}'`).join(',\n')}
|
|
96
|
+
] as const;
|
|
97
|
+
|
|
98
|
+
export type ProtocolContractName = typeof protocolContractNames[number];
|
|
99
|
+
`;
|
|
100
|
+
}
|
|
101
|
+
function generateSalts(names) {
|
|
102
|
+
return `
|
|
103
|
+
export const ProtocolContractSalt: Record<ProtocolContractName, Fr> = {
|
|
104
|
+
${names.map((name)=>`${name}: new Fr(${salt.toNumber()})`).join(',\n')}
|
|
105
|
+
};
|
|
106
|
+
`;
|
|
107
|
+
}
|
|
108
|
+
function generateContractAddresses(names) {
|
|
109
|
+
const addresses = names.map((name)=>`${name}: AztecAddress.fromBigIntUnsafe(${contractAddressMapping[name]}n)`).join(',\n');
|
|
110
|
+
return `
|
|
111
|
+
export const ProtocolContractAddress: Record<ProtocolContractName, AztecAddress> = {
|
|
112
|
+
${addresses}
|
|
113
|
+
};
|
|
114
|
+
`;
|
|
115
|
+
}
|
|
116
|
+
function generateDerivedAddresses(names, contractData) {
|
|
117
|
+
return `
|
|
118
|
+
export const ProtocolContractDerivedAddress = {
|
|
119
|
+
${contractData.map((d, i)=>`${names[i]}: AztecAddress.fromStringUnsafe('${d.address.toString()}')`).join(',\n')}
|
|
120
|
+
};
|
|
121
|
+
`;
|
|
122
|
+
}
|
|
123
|
+
function generateClassIdPreimages(names, contractData) {
|
|
124
|
+
return `
|
|
125
|
+
export const ProtocolContractClassId: Record<ProtocolContractName, Fr> = {
|
|
126
|
+
${contractData.map((d, i)=>`${names[i]}: Fr.fromString('${d.classId.toString()}')`).join(',\n')}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export const ProtocolContractClassIdPreimage: Record<ProtocolContractName, { artifactHash: Fr; privateFunctionsRoot: Fr; publicBytecodeCommitment: Fr }> = {
|
|
130
|
+
${contractData.map((d, i)=>`${names[i]}: {
|
|
131
|
+
artifactHash: Fr.fromString('${d.artifactHash.toString()}'),
|
|
132
|
+
privateFunctionsRoot: Fr.fromString('${d.privateFunctionsRoot.toString()}'),
|
|
133
|
+
publicBytecodeCommitment: Fr.fromString('${d.publicBytecodeCommitment.toString()}'),
|
|
134
|
+
}`).join(',\n')}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export const ProtocolContractInitializationHash: Record<ProtocolContractName, Fr> = {
|
|
138
|
+
${contractData.map((d, i)=>`${names[i]}: Fr.fromString('${d.initializationHash.toString()}')`).join(',\n')}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const ProtocolContractPrivateFunctions: Record<ProtocolContractName, { selector: FunctionSelector; vkHash: Fr }[]> = {
|
|
142
|
+
${contractData.map((d, i)=>`${names[i]}: [${d.privateFunctions.map((fn)=>`{ selector: FunctionSelector.fromField(Fr.fromString('${fn.selector.toField().toString()}')), vkHash: Fr.fromString('${fn.vkHash.toString()}') }`).join(', ')}]`).join(',\n')}
|
|
143
|
+
};
|
|
144
|
+
`;
|
|
145
|
+
}
|
|
146
|
+
async function generateProtocolContractsList(names, contractData) {
|
|
147
|
+
const list = makeTuple(MAX_PROTOCOL_CONTRACTS, ()=>AztecAddress.zero());
|
|
148
|
+
for(let i = 0; i < names.length; i++){
|
|
149
|
+
const name = names[i];
|
|
150
|
+
const address = contractAddressMapping[name];
|
|
151
|
+
const derivedAddressIndex = address - 1;
|
|
152
|
+
if (!list[derivedAddressIndex].equals(AztecAddress.zero())) {
|
|
153
|
+
throw new Error(`Duplicate protocol contract address: ${address.toString()}`);
|
|
154
|
+
}
|
|
155
|
+
list[derivedAddressIndex] = contractData[i].address;
|
|
156
|
+
}
|
|
157
|
+
return `
|
|
158
|
+
export const ProtocolContractsList = new ProtocolContracts([
|
|
159
|
+
${list.map((address)=>`AztecAddress.fromStringUnsafe('${address.toString()}')`).join(',\n')}
|
|
160
|
+
]);
|
|
161
|
+
|
|
162
|
+
export const protocolContractsHash = Fr.fromString('${(await new ProtocolContracts(list).hash()).toString()}');
|
|
163
|
+
`;
|
|
164
|
+
}
|
|
165
|
+
// Generate the siloed log tags for events emitted via private logs.
|
|
166
|
+
async function generateLogTags() {
|
|
167
|
+
return `
|
|
168
|
+
export const CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG = Fr.fromHexString('${await computeSiloedPrivateLogFirstField(new AztecAddress(new Fr(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS)), new Fr(CONTRACT_INSTANCE_PUBLISHED_MAGIC_VALUE))}');
|
|
169
|
+
`;
|
|
170
|
+
}
|
|
171
|
+
async function generateOutputFile(names, contractData) {
|
|
172
|
+
const content = `
|
|
173
|
+
// GENERATED FILE - DO NOT EDIT. RUN \`yarn generate\` or \`yarn generate:data\`
|
|
174
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
175
|
+
import { FunctionSelector } from '@aztec-labs/stdlib/abi';
|
|
176
|
+
import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
177
|
+
import { ProtocolContracts } from '@aztec-labs/stdlib/tx';
|
|
178
|
+
|
|
179
|
+
${generateNames(names)}
|
|
180
|
+
|
|
181
|
+
${generateSalts(names)}
|
|
182
|
+
|
|
183
|
+
${generateContractAddresses(names)}
|
|
184
|
+
|
|
185
|
+
${generateDerivedAddresses(names, contractData)}
|
|
186
|
+
|
|
187
|
+
${generateClassIdPreimages(names, contractData)}
|
|
188
|
+
|
|
189
|
+
${await generateProtocolContractsList(names, contractData)}
|
|
190
|
+
|
|
191
|
+
${await generateLogTags()}
|
|
192
|
+
`;
|
|
193
|
+
await fs.writeFile(outputFilePath, content);
|
|
194
|
+
}
|
|
195
|
+
async function main() {
|
|
196
|
+
await clearDestDir();
|
|
197
|
+
const srcNames = JSON.parse(await fs.readFile(path.join(artifactsPkgRoot, 'protocol_contracts.json'), 'utf8'));
|
|
198
|
+
const contractDataList = [];
|
|
199
|
+
const destNames = srcNames.map((n)=>n.split('-')[1]);
|
|
200
|
+
for(let i = 0; i < srcNames.length; i++){
|
|
201
|
+
const srcName = srcNames[i];
|
|
202
|
+
const destName = destNames[i];
|
|
203
|
+
const artifact = await copyArtifact(srcName, destName);
|
|
204
|
+
await generateDeclarationFile(destName);
|
|
205
|
+
contractDataList.push(await computeContractData(artifact, AztecAddress.fromBigIntUnsafe(BigInt(contractAddressMapping[destName]))));
|
|
206
|
+
}
|
|
207
|
+
await generateOutputFile(destNames, contractDataList);
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
await main();
|
|
211
|
+
} catch (err) {
|
|
212
|
+
log(`Error copying protocol contract artifacts: ${err}`);
|
|
213
|
+
process.exit(1);
|
|
214
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function getSampleContractClassPublishedEventPayload(): Buffer;
|
|
2
|
+
export declare function getSampleContractInstancePublishedEventPayload(): Buffer;
|
|
3
|
+
export declare function getPathToFixture(name: string): string;
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZml4dHVyZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0cy9maXh0dXJlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFLQSx3QkFBZ0IsMkNBQTJDLElBQUksTUFBTSxDQUdwRTtBQUdELHdCQUFnQiw4Q0FBOEMsSUFBSSxNQUFNLENBR3ZFO0FBRUQsd0JBQWdCLGdCQUFnQixDQUFDLElBQUksRUFBRSxNQUFNLFVBRTVDIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../src/tests/fixtures.ts"],"names":[],"mappings":"AAKA,wBAAgB,2CAA2C,IAAI,MAAM,CAGpE;AAGD,wBAAgB,8CAA8C,IAAI,MAAM,CAGvE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,UAE5C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { dirname, resolve } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
// Generated from end-to-end/src/automine/contracts/deploy/contract_class_registration.test.ts with AZTEC_GENERATE_TEST_DATA=1
|
|
5
|
+
export function getSampleContractClassPublishedEventPayload() {
|
|
6
|
+
const path = getPathToFixture('ContractClassPublishedEventData.hex');
|
|
7
|
+
return Buffer.from(readFileSync(path).toString(), 'hex');
|
|
8
|
+
}
|
|
9
|
+
// Generated from end-to-end/src/automine/contracts/deploy/contract_class_registration.test.ts with AZTEC_GENERATE_TEST_DATA=1
|
|
10
|
+
export function getSampleContractInstancePublishedEventPayload() {
|
|
11
|
+
const path = getPathToFixture('ContractInstancePublishedEventData.hex');
|
|
12
|
+
return Buffer.from(readFileSync(path).toString(), 'hex');
|
|
13
|
+
}
|
|
14
|
+
export function getPathToFixture(name) {
|
|
15
|
+
return resolve(dirname(fileURLToPath(import.meta.url)), `../../fixtures/${name}`);
|
|
16
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aztec-labs/protocol-contracts",
|
|
3
|
+
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/protocol-contracts",
|
|
4
|
+
"description": "Canonical Noir contracts for the Aztec Network",
|
|
5
|
+
"version": "6.0.0-nightly.20260829",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dest/index.js",
|
|
9
|
+
"./providers/bundle": "./dest/provider/bundle.js",
|
|
10
|
+
"./providers/lazy": "./dest/provider/lazy.js",
|
|
11
|
+
"./*": "./dest/*/index.js",
|
|
12
|
+
"./*/lazy": "./dest/*/lazy.js"
|
|
13
|
+
},
|
|
14
|
+
"typedocOptions": {
|
|
15
|
+
"entryPoints": [
|
|
16
|
+
"./src/index.ts",
|
|
17
|
+
"./src/class-registry/index.ts",
|
|
18
|
+
"./src/instance-registry/index.ts"
|
|
19
|
+
],
|
|
20
|
+
"name": "Protocol Contracts",
|
|
21
|
+
"tsconfig": "./tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "yarn clean && yarn generate && yarn generate:cleanup-artifacts && ../scripts/tsc.sh",
|
|
25
|
+
"build:keep-debug-symbols": "yarn clean && yarn generate && ../scripts/tsc.sh",
|
|
26
|
+
"generate": "yarn generate:data",
|
|
27
|
+
"generate:cleanup-artifacts": "node --no-warnings --loader @swc-node/register/esm src/scripts/cleanup_artifacts.ts",
|
|
28
|
+
"generate:data": "node --no-warnings --loader @swc-node/register/esm src/scripts/generate_data.ts",
|
|
29
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
30
|
+
"build:ts": "../scripts/tsc.sh",
|
|
31
|
+
"clean": "rm -rf ./dest .tsbuildinfo ./artifacts",
|
|
32
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
33
|
+
},
|
|
34
|
+
"inherits": [
|
|
35
|
+
"../package.common.json",
|
|
36
|
+
"./package.local.json"
|
|
37
|
+
],
|
|
38
|
+
"jest": {
|
|
39
|
+
"moduleNameMapper": {
|
|
40
|
+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
41
|
+
},
|
|
42
|
+
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
|
|
43
|
+
"rootDir": "./src",
|
|
44
|
+
"transform": {
|
|
45
|
+
"^.+\\.tsx?$": [
|
|
46
|
+
"@swc/jest",
|
|
47
|
+
{
|
|
48
|
+
"jsc": {
|
|
49
|
+
"parser": {
|
|
50
|
+
"syntax": "typescript",
|
|
51
|
+
"decorators": true
|
|
52
|
+
},
|
|
53
|
+
"transform": {
|
|
54
|
+
"decoratorVersion": "2022-03"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"extensionsToTreatAsEsm": [
|
|
61
|
+
".ts"
|
|
62
|
+
],
|
|
63
|
+
"reporters": [
|
|
64
|
+
"default"
|
|
65
|
+
],
|
|
66
|
+
"testTimeout": 120000,
|
|
67
|
+
"setupFiles": [
|
|
68
|
+
"../../foundation/src/jest/setup.mjs"
|
|
69
|
+
],
|
|
70
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
71
|
+
"setupFilesAfterEnv": [
|
|
72
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"@aztec-labs/constants": "6.0.0-nightly.20260829",
|
|
77
|
+
"@aztec-labs/foundation": "6.0.0-nightly.20260829",
|
|
78
|
+
"@aztec-labs/stdlib": "6.0.0-nightly.20260829",
|
|
79
|
+
"lodash.chunk": "^4.2.0",
|
|
80
|
+
"lodash.omit": "^4.5.0",
|
|
81
|
+
"tslib": "^2.4.0"
|
|
82
|
+
},
|
|
83
|
+
"devDependencies": {
|
|
84
|
+
"@aztec/protocol-contracts-artifacts": "6.0.0-nightly.20260826",
|
|
85
|
+
"@jest/globals": "^30.0.0",
|
|
86
|
+
"@types/jest": "^30.0.0",
|
|
87
|
+
"@types/lodash.chunk": "^4.2.9",
|
|
88
|
+
"@types/lodash.omit": "^4.5.9",
|
|
89
|
+
"@types/node": "^22.15.17",
|
|
90
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
91
|
+
"jest": "^30.0.0",
|
|
92
|
+
"jest-mock-extended": "^4.0.0",
|
|
93
|
+
"ts-loader": "^9.5.4",
|
|
94
|
+
"ts-node": "^10.9.1",
|
|
95
|
+
"typescript": "^5.3.3"
|
|
96
|
+
},
|
|
97
|
+
"files": [
|
|
98
|
+
"dest",
|
|
99
|
+
"src",
|
|
100
|
+
"!*.test.*",
|
|
101
|
+
"artifacts",
|
|
102
|
+
"!src/scripts/*"
|
|
103
|
+
],
|
|
104
|
+
"engines": {
|
|
105
|
+
"node": ">=20.10"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { CONTRACT_CLASS_PUBLISHED_MAGIC_VALUE } from '@aztec-labs/constants';
|
|
2
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
3
|
+
import { FieldReader } from '@aztec-labs/foundation/serialize';
|
|
4
|
+
import { bufferFromFields } from '@aztec-labs/stdlib/abi';
|
|
5
|
+
import {
|
|
6
|
+
type ContractClassPublic,
|
|
7
|
+
type ContractClassPublicWithCommitment,
|
|
8
|
+
computePublicBytecodeCommitment,
|
|
9
|
+
} from '@aztec-labs/stdlib/contract';
|
|
10
|
+
import type { ContractClassLog } from '@aztec-labs/stdlib/logs';
|
|
11
|
+
|
|
12
|
+
import { ProtocolContractAddress } from '../protocol_contract_data.js';
|
|
13
|
+
|
|
14
|
+
/** Event emitted from the ContractClassRegistry. */
|
|
15
|
+
export class ContractClassPublishedEvent {
|
|
16
|
+
constructor(
|
|
17
|
+
public readonly contractClassId: Fr,
|
|
18
|
+
public readonly version: number,
|
|
19
|
+
public readonly artifactHash: Fr,
|
|
20
|
+
public readonly privateFunctionsRoot: Fr,
|
|
21
|
+
public readonly packedPublicBytecode: Buffer,
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
static isContractClassPublishedEvent(log: ContractClassLog) {
|
|
25
|
+
return (
|
|
26
|
+
log.contractAddress.equals(ProtocolContractAddress.ContractClassRegistry) &&
|
|
27
|
+
log.fields.fields[0].toBigInt() === CONTRACT_CLASS_PUBLISHED_MAGIC_VALUE
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static fromLog(log: ContractClassLog) {
|
|
32
|
+
// See how the log is serialized in `noir-projects/fnd/noir-contracts/contracts/protocol/contract_class_registry_contract/src/events/class_published.nr`.
|
|
33
|
+
const fieldsWithoutTag = log.fields.fields.slice(1);
|
|
34
|
+
const reader = new FieldReader(fieldsWithoutTag);
|
|
35
|
+
const contractClassId = reader.readField();
|
|
36
|
+
const version = reader.readField().toNumber();
|
|
37
|
+
const artifactHash = reader.readField();
|
|
38
|
+
const privateFunctionsRoot = reader.readField();
|
|
39
|
+
const bytecodeFields = reader.readFieldArray(fieldsWithoutTag.length - reader.cursor);
|
|
40
|
+
// The fixed-size class log can hold at most this many packed-bytecode bytes (every payload field
|
|
41
|
+
// carries 31 bytes). Bound the declared length to it so a malformed log can't declare a multi-MiB
|
|
42
|
+
// length backed by a tiny payload and force a large allocation during early (pre-proof) validation.
|
|
43
|
+
const maxByteLength = (bytecodeFields.length - 1) * (Fr.SIZE_IN_BYTES - 1);
|
|
44
|
+
const packedPublicBytecode = bufferFromFields(bytecodeFields, maxByteLength);
|
|
45
|
+
|
|
46
|
+
return new ContractClassPublishedEvent(
|
|
47
|
+
contractClassId,
|
|
48
|
+
version,
|
|
49
|
+
artifactHash,
|
|
50
|
+
privateFunctionsRoot,
|
|
51
|
+
packedPublicBytecode,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Converts the event to a contract class, without computing or validating the bytecode commitment. */
|
|
56
|
+
toContractClassPublic(): ContractClassPublic {
|
|
57
|
+
return {
|
|
58
|
+
id: this.contractClassId,
|
|
59
|
+
artifactHash: this.artifactHash,
|
|
60
|
+
packedBytecode: this.packedPublicBytecode,
|
|
61
|
+
privateFunctionsRoot: this.privateFunctionsRoot,
|
|
62
|
+
version: this.version as 1,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Converts the event to a contract class with its bytecode commitment (expensive). */
|
|
67
|
+
async toContractClassPublicWithBytecodeCommitment(): Promise<ContractClassPublicWithCommitment> {
|
|
68
|
+
const publicBytecodeCommitment = await computePublicBytecodeCommitment(this.packedPublicBytecode);
|
|
69
|
+
return { ...this.toContractClassPublic(), publicBytecodeCommitment };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public static extractContractClassEvents(logs: ContractClassLog[]): ContractClassPublishedEvent[] {
|
|
73
|
+
return logs
|
|
74
|
+
.filter((log: ContractClassLog) => ContractClassPublishedEvent.isContractClassPublishedEvent(log))
|
|
75
|
+
.map((log: ContractClassLog) => ContractClassPublishedEvent.fromLog(log));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
|
|
2
|
+
import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
|
|
3
|
+
|
|
4
|
+
import ContractClassRegistryJson from '../../artifacts/ContractClassRegistry.json' with { type: 'json' };
|
|
5
|
+
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
6
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
7
|
+
|
|
8
|
+
export * from './contract_class_published_event.js';
|
|
9
|
+
|
|
10
|
+
export const ContractClassRegistryArtifact = loadContractArtifact(ContractClassRegistryJson as NoirCompiledContract);
|
|
11
|
+
|
|
12
|
+
let protocolContract: ProtocolContract;
|
|
13
|
+
|
|
14
|
+
/** Returns the canonical deployment of the contract. */
|
|
15
|
+
export function getCanonicalClassRegistry(): Promise<ProtocolContract> {
|
|
16
|
+
if (!protocolContract) {
|
|
17
|
+
const artifact = ContractClassRegistryArtifact;
|
|
18
|
+
protocolContract = makeProtocolContract('ContractClassRegistry', artifact);
|
|
19
|
+
}
|
|
20
|
+
return Promise.resolve(protocolContract);
|
|
21
|
+
}
|