@aztec/protocol-contracts 0.0.0-test.1 → 0.0.1-commit.0208eb9
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 +2 -2
- package/artifacts/AuthRegistry.json +1627 -1588
- package/artifacts/ContractClassRegistry.json +5984 -0
- package/artifacts/ContractInstanceRegistry.json +2953 -0
- package/artifacts/FeeJuice.json +3017 -2976
- package/artifacts/MultiCallEntrypoint.json +1858 -1094
- package/artifacts/PublicChecks.json +980 -0
- package/dest/auth-registry/index.d.ts +3 -2
- package/dest/auth-registry/index.d.ts.map +1 -1
- package/dest/auth-registry/index.js +1 -1
- package/dest/auth-registry/lazy.d.ts +1 -1
- package/dest/auth-registry/lazy.js +4 -4
- package/dest/class-registry/contract_class_published_event.d.ts +17 -0
- package/dest/class-registry/contract_class_published_event.d.ts.map +1 -0
- package/dest/{class-registerer/contract_class_registered_event.js → class-registry/contract_class_published_event.js} +15 -20
- package/dest/class-registry/index.d.ts +8 -0
- package/dest/class-registry/index.d.ts.map +1 -0
- package/dest/class-registry/index.js +17 -0
- package/dest/class-registry/lazy.d.ts +9 -0
- package/dest/class-registry/lazy.d.ts.map +1 -0
- package/dest/class-registry/lazy.js +26 -0
- package/dest/class-registry/private_function_broadcasted_event.d.ts +44 -0
- package/dest/class-registry/private_function_broadcasted_event.d.ts.map +1 -0
- package/dest/{class-registerer → class-registry}/private_function_broadcasted_event.js +11 -11
- package/dest/class-registry/utility_function_broadcasted_event.d.ts +38 -0
- package/dest/class-registry/utility_function_broadcasted_event.d.ts.map +1 -0
- package/dest/{class-registerer/unconstrained_function_broadcasted_event.js → class-registry/utility_function_broadcasted_event.js} +20 -20
- package/dest/fee-juice/index.d.ts +2 -2
- package/dest/fee-juice/index.d.ts.map +1 -1
- package/dest/fee-juice/index.js +1 -1
- package/dest/fee-juice/lazy.d.ts +1 -1
- package/dest/fee-juice/lazy.js +4 -4
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/instance-registry/contract_instance_published_event.d.ts +21 -0
- package/dest/instance-registry/contract_instance_published_event.d.ts.map +1 -0
- package/dest/{instance-deployer/contract_instance_deployed_event.js → instance-registry/contract_instance_published_event.js} +9 -6
- 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-deployer → instance-registry}/index.js +5 -5
- package/dest/instance-registry/lazy.d.ts +8 -0
- package/dest/{instance-deployer → instance-registry}/lazy.d.ts.map +1 -1
- package/dest/instance-registry/lazy.js +25 -0
- package/dest/make_protocol_contract.d.ts +1 -1
- package/dest/make_protocol_contract.js +2 -2
- package/dest/multi-call-entrypoint/index.d.ts +1 -1
- package/dest/multi-call-entrypoint/index.js +1 -1
- package/dest/multi-call-entrypoint/lazy.d.ts +1 -1
- package/dest/multi-call-entrypoint/lazy.js +4 -4
- package/dest/protocol_contract.d.ts +1 -1
- package/dest/protocol_contract_data.d.ts +14 -16
- package/dest/protocol_contract_data.d.ts.map +1 -1
- package/dest/protocol_contract_data.js +33 -23
- package/dest/provider/bundle.d.ts +1 -1
- package/dest/provider/bundle.d.ts.map +1 -1
- package/dest/provider/bundle.js +6 -6
- package/dest/provider/lazy.d.ts +1 -1
- package/dest/provider/lazy.d.ts.map +1 -1
- package/dest/provider/lazy.js +9 -9
- package/dest/provider/protocol_contracts_provider.d.ts +1 -1
- package/dest/public-checks/index.d.ts +5 -0
- package/dest/public-checks/index.d.ts.map +1 -0
- package/dest/{router → public-checks}/index.js +4 -4
- package/dest/public-checks/lazy.d.ts +6 -0
- package/dest/public-checks/lazy.d.ts.map +1 -0
- package/dest/public-checks/lazy.js +23 -0
- package/dest/scripts/cleanup_artifacts.js +2 -2
- package/dest/scripts/generate_data.js +43 -50
- package/dest/tests/fixtures.d.ts +4 -6
- package/dest/tests/fixtures.d.ts.map +1 -1
- package/dest/tests/fixtures.js +6 -6
- package/package.json +23 -20
- package/src/auth-registry/index.ts +3 -3
- package/src/auth-registry/lazy.ts +4 -4
- package/src/class-registry/__snapshots__/README.md +9 -0
- package/src/{class-registerer/contract_class_registered_event.ts → class-registry/contract_class_published_event.ts} +23 -23
- package/src/{class-registerer → class-registry}/index.ts +7 -9
- package/src/class-registry/lazy.ts +33 -0
- package/src/{class-registerer → class-registry}/private_function_broadcasted_event.ts +13 -9
- package/src/{class-registerer/unconstrained_function_broadcasted_event.ts → class-registry/utility_function_broadcasted_event.ts} +26 -22
- package/src/fee-juice/index.ts +2 -2
- package/src/fee-juice/lazy.ts +4 -4
- package/src/index.ts +0 -1
- package/src/instance-registry/__snapshots__/README.md +9 -0
- package/src/{instance-deployer/contract_instance_deployed_event.ts → instance-registry/contract_instance_published_event.ts} +13 -7
- package/src/{instance-deployer → instance-registry}/contract_instance_updated_event.ts +15 -15
- package/src/{instance-deployer → instance-registry}/index.ts +6 -6
- package/src/{instance-deployer → instance-registry}/lazy.ts +11 -11
- package/src/make_protocol_contract.ts +2 -2
- package/src/multi-call-entrypoint/index.ts +1 -1
- package/src/multi-call-entrypoint/lazy.ts +4 -4
- package/src/protocol_contract_data.ts +34 -23
- package/src/provider/bundle.ts +6 -6
- package/src/provider/lazy.ts +9 -9
- package/src/{router → public-checks}/index.ts +4 -4
- package/src/public-checks/lazy.ts +29 -0
- package/src/tests/fixtures.ts +6 -6
- package/artifacts/ContractClassRegisterer.json +0 -7219
- package/artifacts/ContractInstanceDeployer.json +0 -2984
- package/artifacts/Router.json +0 -3798
- package/dest/build_protocol_contract_tree.d.ts +0 -10
- package/dest/build_protocol_contract_tree.d.ts.map +0 -1
- package/dest/build_protocol_contract_tree.js +0 -20
- package/dest/class-registerer/contract_class_registered_event.d.ts +0 -18
- package/dest/class-registerer/contract_class_registered_event.d.ts.map +0 -1
- package/dest/class-registerer/index.d.ts +0 -8
- package/dest/class-registerer/index.d.ts.map +0 -1
- package/dest/class-registerer/index.js +0 -17
- package/dest/class-registerer/lazy.d.ts +0 -9
- package/dest/class-registerer/lazy.d.ts.map +0 -1
- package/dest/class-registerer/lazy.js +0 -26
- package/dest/class-registerer/private_function_broadcasted_event.d.ts +0 -46
- package/dest/class-registerer/private_function_broadcasted_event.d.ts.map +0 -1
- package/dest/class-registerer/unconstrained_function_broadcasted_event.d.ts +0 -40
- package/dest/class-registerer/unconstrained_function_broadcasted_event.d.ts.map +0 -1
- package/dest/instance-deployer/contract_instance_deployed_event.d.ts +0 -20
- package/dest/instance-deployer/contract_instance_deployed_event.d.ts.map +0 -1
- package/dest/instance-deployer/contract_instance_updated_event.d.ts +0 -16
- package/dest/instance-deployer/contract_instance_updated_event.d.ts.map +0 -1
- package/dest/instance-deployer/contract_instance_updated_event.js +0 -36
- package/dest/instance-deployer/index.d.ts +0 -7
- package/dest/instance-deployer/index.d.ts.map +0 -1
- package/dest/instance-deployer/lazy.d.ts +0 -8
- package/dest/instance-deployer/lazy.js +0 -25
- package/dest/protocol_contract_tree.d.ts +0 -7
- package/dest/protocol_contract_tree.d.ts.map +0 -1
- package/dest/protocol_contract_tree.js +0 -34
- package/dest/router/index.d.ts +0 -5
- package/dest/router/index.d.ts.map +0 -1
- package/dest/router/lazy.d.ts +0 -6
- package/dest/router/lazy.d.ts.map +0 -1
- package/dest/router/lazy.js +0 -23
- package/src/build_protocol_contract_tree.ts +0 -29
- package/src/class-registerer/lazy.ts +0 -33
- package/src/protocol_contract_tree.ts +0 -44
- package/src/router/lazy.ts +0 -29
- /package/artifacts/{ContractClassRegisterer.d.json.ts → ContractClassRegistry.d.json.ts} +0 -0
- /package/artifacts/{ContractInstanceDeployer.d.json.ts → ContractInstanceRegistry.d.json.ts} +0 -0
- /package/artifacts/{Router.d.json.ts → PublicChecks.d.json.ts} +0 -0
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { CANONICAL_AUTH_REGISTRY_ADDRESS,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { CANONICAL_AUTH_REGISTRY_ADDRESS, CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS, CONTRACT_INSTANCE_PUBLISHED_MAGIC_VALUE, CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, FEE_JUICE_ADDRESS, GeneratorIndex, MAX_PROTOCOL_CONTRACTS, MULTI_CALL_ENTRYPOINT_ADDRESS, PUBLIC_CHECKS_ADDRESS } from '@aztec/constants';
|
|
2
|
+
import { makeTuple } from '@aztec/foundation/array';
|
|
3
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { createConsoleLogger } from '@aztec/foundation/log';
|
|
5
6
|
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
6
7
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
-
import {
|
|
8
|
+
import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
|
|
9
|
+
import { ProtocolContracts } from '@aztec/stdlib/tx';
|
|
8
10
|
import { promises as fs } from 'fs';
|
|
9
11
|
import path from 'path';
|
|
10
|
-
import { buildProtocolContractTree } from '../build_protocol_contract_tree.js';
|
|
11
12
|
const log = createConsoleLogger('autogenerate');
|
|
12
13
|
const noirContractsRoot = '../../noir-projects/noir-contracts';
|
|
13
14
|
const srcPath = path.join(noirContractsRoot, './target');
|
|
@@ -16,11 +17,11 @@ const outputFilePath = './src/protocol_contract_data.ts';
|
|
|
16
17
|
const salt = new Fr(1);
|
|
17
18
|
const contractAddressMapping = {
|
|
18
19
|
AuthRegistry: CANONICAL_AUTH_REGISTRY_ADDRESS,
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
ContractInstanceRegistry: CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
|
|
21
|
+
ContractClassRegistry: CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS,
|
|
21
22
|
MultiCallEntrypoint: MULTI_CALL_ENTRYPOINT_ADDRESS,
|
|
22
23
|
FeeJuice: FEE_JUICE_ADDRESS,
|
|
23
|
-
|
|
24
|
+
PublicChecks: PUBLIC_CHECKS_ADDRESS
|
|
24
25
|
};
|
|
25
26
|
async function clearDestDir() {
|
|
26
27
|
try {
|
|
@@ -49,20 +50,12 @@ async function copyArtifact(srcName, destName) {
|
|
|
49
50
|
await fs.copyFile(src, dest);
|
|
50
51
|
return artifact;
|
|
51
52
|
}
|
|
52
|
-
async function
|
|
53
|
-
const instance = await
|
|
53
|
+
async function computeAddress(artifact) {
|
|
54
|
+
const instance = await getContractInstanceFromInstantiationParams(loadContractArtifact(artifact), {
|
|
54
55
|
salt
|
|
55
56
|
});
|
|
56
57
|
return instance.address;
|
|
57
58
|
}
|
|
58
|
-
async function computeRoot(names, leaves) {
|
|
59
|
-
const data = names.map((name, i)=>({
|
|
60
|
-
address: new AztecAddress(new Fr(contractAddressMapping[name])),
|
|
61
|
-
leaf: leaves[i]
|
|
62
|
-
}));
|
|
63
|
-
const tree = await buildProtocolContractTree(data);
|
|
64
|
-
return Fr.fromBuffer(tree.root);
|
|
65
|
-
}
|
|
66
59
|
async function generateDeclarationFile(destName) {
|
|
67
60
|
const content = `
|
|
68
61
|
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
@@ -95,46 +88,47 @@ function generateContractAddresses(names) {
|
|
|
95
88
|
};
|
|
96
89
|
`;
|
|
97
90
|
}
|
|
98
|
-
function
|
|
91
|
+
function generateDerivedAddresses(names, derivedAddresses) {
|
|
99
92
|
return `
|
|
100
|
-
export const
|
|
101
|
-
${
|
|
93
|
+
export const ProtocolContractDerivedAddress = {
|
|
94
|
+
${derivedAddresses.map((address, i)=>`${names[i]}: AztecAddress.fromString('${address.toString()}')`).join(',\n')}
|
|
102
95
|
};
|
|
103
96
|
`;
|
|
104
97
|
}
|
|
105
|
-
async function
|
|
106
|
-
const
|
|
98
|
+
async function generateProtocolContractsList(names, derivedAddresses) {
|
|
99
|
+
const list = makeTuple(MAX_PROTOCOL_CONTRACTS, ()=>AztecAddress.zero());
|
|
100
|
+
for(let i = 0; i < names.length; i++){
|
|
101
|
+
const name = names[i];
|
|
102
|
+
const address = contractAddressMapping[name];
|
|
103
|
+
const derivedAddressIndex = address - 1;
|
|
104
|
+
if (!list[derivedAddressIndex].equals(AztecAddress.zero())) {
|
|
105
|
+
throw new Error(`Duplicate protocol contract address: ${address.toString()}`);
|
|
106
|
+
}
|
|
107
|
+
list[derivedAddressIndex] = derivedAddresses[i];
|
|
108
|
+
}
|
|
107
109
|
return `
|
|
108
|
-
export const
|
|
110
|
+
export const ProtocolContractsList = new ProtocolContracts([
|
|
111
|
+
${list.map((address)=>`AztecAddress.fromString('${address.toString()}')`).join(',\n')}
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
export const protocolContractsHash = Fr.fromString('${(await new ProtocolContracts(list).hash()).toString()}');
|
|
109
115
|
`;
|
|
110
116
|
}
|
|
117
|
+
// Generate the siloed log tags for events emitted via private logs.
|
|
111
118
|
async function generateLogTags() {
|
|
112
|
-
// See silo_contract_class_log for all registerer tags
|
|
113
119
|
return `
|
|
114
|
-
export const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
])}');
|
|
118
|
-
export const REGISTERER_PRIVATE_FUNCTION_BROADCASTED_TAG = Fr.fromHexString('${await poseidon2Hash([
|
|
119
|
-
REGISTERER_CONTRACT_ADDRESS,
|
|
120
|
-
REGISTERER_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE
|
|
121
|
-
])}');
|
|
122
|
-
export const REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_TAG = Fr.fromHexString('${await poseidon2Hash([
|
|
123
|
-
REGISTERER_CONTRACT_ADDRESS,
|
|
124
|
-
REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE
|
|
125
|
-
])}');
|
|
126
|
-
export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_TAG = Fr.fromHexString('${await poseidon2Hash([
|
|
127
|
-
DEPLOYER_CONTRACT_ADDRESS,
|
|
128
|
-
DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE
|
|
129
|
-
])}');
|
|
130
|
-
export const DEPLOYER_CONTRACT_INSTANCE_UPDATED_TAG = new Fr(${DEPLOYER_CONTRACT_INSTANCE_UPDATED_MAGIC_VALUE}n);
|
|
120
|
+
export const CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG = Fr.fromHexString('${await poseidon2HashWithSeparator([
|
|
121
|
+
CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
|
|
122
|
+
CONTRACT_INSTANCE_PUBLISHED_MAGIC_VALUE
|
|
123
|
+
], GeneratorIndex.PRIVATE_LOG_FIRST_FIELD)}');
|
|
131
124
|
`;
|
|
132
125
|
}
|
|
133
|
-
async function generateOutputFile(names,
|
|
126
|
+
async function generateOutputFile(names, derivedAddresses) {
|
|
134
127
|
const content = `
|
|
135
128
|
// GENERATED FILE - DO NOT EDIT. RUN \`yarn generate\` or \`yarn generate:data\`
|
|
136
|
-
import { Fr } from '@aztec/foundation/
|
|
129
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
137
130
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
131
|
+
import { ProtocolContracts } from '@aztec/stdlib/tx';
|
|
138
132
|
|
|
139
133
|
${generateNames(names)}
|
|
140
134
|
|
|
@@ -142,9 +136,9 @@ async function generateOutputFile(names, leaves) {
|
|
|
142
136
|
|
|
143
137
|
${generateContractAddresses(names)}
|
|
144
138
|
|
|
145
|
-
${
|
|
139
|
+
${generateDerivedAddresses(names, derivedAddresses)}
|
|
146
140
|
|
|
147
|
-
${await
|
|
141
|
+
${await generateProtocolContractsList(names, derivedAddresses)}
|
|
148
142
|
|
|
149
143
|
${await generateLogTags()}
|
|
150
144
|
`;
|
|
@@ -153,17 +147,16 @@ async function generateOutputFile(names, leaves) {
|
|
|
153
147
|
async function main() {
|
|
154
148
|
await clearDestDir();
|
|
155
149
|
const srcNames = JSON.parse(await fs.readFile(path.join(noirContractsRoot, 'protocol_contracts.json'), 'utf8'));
|
|
156
|
-
const
|
|
150
|
+
const derivedAddresses = [];
|
|
157
151
|
const destNames = srcNames.map((n)=>n.split('-')[1]);
|
|
158
152
|
for(let i = 0; i < srcNames.length; i++){
|
|
159
153
|
const srcName = srcNames[i];
|
|
160
154
|
const destName = destNames[i];
|
|
161
155
|
const artifact = await copyArtifact(srcName, destName);
|
|
162
156
|
await generateDeclarationFile(destName);
|
|
163
|
-
|
|
164
|
-
leaves.push(contractLeaf.toField());
|
|
157
|
+
derivedAddresses.push(await computeAddress(artifact));
|
|
165
158
|
}
|
|
166
|
-
await generateOutputFile(destNames,
|
|
159
|
+
await generateOutputFile(destNames, derivedAddresses);
|
|
167
160
|
}
|
|
168
161
|
try {
|
|
169
162
|
await main();
|
package/dest/tests/fixtures.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
export declare function getSampleContractClassRegisteredEventPayload(): Buffer;
|
|
1
|
+
export declare function getSampleContractClassPublishedEventPayload(): Buffer;
|
|
4
2
|
export declare function getSamplePrivateFunctionBroadcastedEventPayload(): Buffer;
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
3
|
+
export declare function getSampleUtilityFunctionBroadcastedEventPayload(): Buffer;
|
|
4
|
+
export declare function getSampleContractInstancePublishedEventPayload(): Buffer;
|
|
7
5
|
export declare function getPathToFixture(name: string): string;
|
|
8
|
-
//# sourceMappingURL=
|
|
6
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZml4dHVyZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0cy9maXh0dXJlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFLQSx3QkFBZ0IsMkNBQTJDLElBQUksTUFBTSxDQUdwRTtBQUdELHdCQUFnQiwrQ0FBK0MsSUFBSSxNQUFNLENBR3hFO0FBR0Qsd0JBQWdCLCtDQUErQyxJQUFJLE1BQU0sQ0FHeEU7QUFHRCx3QkFBZ0IsOENBQThDLElBQUksTUFBTSxDQUd2RTtBQUVELHdCQUFnQixnQkFBZ0IsQ0FBQyxJQUFJLEVBQUUsTUFBTSxVQUU1QyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../src/tests/fixtures.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../src/tests/fixtures.ts"],"names":[],"mappings":"AAKA,wBAAgB,2CAA2C,IAAI,MAAM,CAGpE;AAGD,wBAAgB,+CAA+C,IAAI,MAAM,CAGxE;AAGD,wBAAgB,+CAA+C,IAAI,MAAM,CAGxE;AAGD,wBAAgB,8CAA8C,IAAI,MAAM,CAGvE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,UAE5C"}
|
package/dest/tests/fixtures.js
CHANGED
|
@@ -2,8 +2,8 @@ import { readFileSync } from 'fs';
|
|
|
2
2
|
import { dirname, resolve } from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
// Generated from end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts with AZTEC_GENERATE_TEST_DATA=1
|
|
5
|
-
export function
|
|
6
|
-
const path = getPathToFixture('
|
|
5
|
+
export function getSampleContractClassPublishedEventPayload() {
|
|
6
|
+
const path = getPathToFixture('ContractClassPublishedEventData.hex');
|
|
7
7
|
return Buffer.from(readFileSync(path).toString(), 'hex');
|
|
8
8
|
}
|
|
9
9
|
// Generated from end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts with AZTEC_GENERATE_TEST_DATA=1
|
|
@@ -12,13 +12,13 @@ export function getSamplePrivateFunctionBroadcastedEventPayload() {
|
|
|
12
12
|
return Buffer.from(readFileSync(path).toString(), 'hex');
|
|
13
13
|
}
|
|
14
14
|
// Generated from end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts with AZTEC_GENERATE_TEST_DATA=1
|
|
15
|
-
export function
|
|
16
|
-
const path = getPathToFixture('
|
|
15
|
+
export function getSampleUtilityFunctionBroadcastedEventPayload() {
|
|
16
|
+
const path = getPathToFixture('UtilityFunctionBroadcastedEventData.hex');
|
|
17
17
|
return Buffer.from(readFileSync(path).toString(), 'hex');
|
|
18
18
|
}
|
|
19
19
|
// Generated from end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts with AZTEC_GENERATE_TEST_DATA=1
|
|
20
|
-
export function
|
|
21
|
-
const path = getPathToFixture('
|
|
20
|
+
export function getSampleContractInstancePublishedEventPayload() {
|
|
21
|
+
const path = getPathToFixture('ContractInstancePublishedEventData.hex');
|
|
22
22
|
return Buffer.from(readFileSync(path).toString(), 'hex');
|
|
23
23
|
}
|
|
24
24
|
export function getPathToFixture(name) {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@aztec/protocol-contracts",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/protocol-contracts",
|
|
4
4
|
"description": "Canonical Noir contracts for the Aztec Network",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.1-commit.0208eb9",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./dest/index.js",
|
|
@@ -14,23 +14,21 @@
|
|
|
14
14
|
"typedocOptions": {
|
|
15
15
|
"entryPoints": [
|
|
16
16
|
"./src/index.ts",
|
|
17
|
-
"./src/class-
|
|
18
|
-
"./src/instance-
|
|
17
|
+
"./src/class-registry/index.ts",
|
|
18
|
+
"./src/instance-registry/index.ts"
|
|
19
19
|
],
|
|
20
20
|
"name": "Protocol Contracts",
|
|
21
21
|
"tsconfig": "./tsconfig.json"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
|
-
"build": "yarn clean && yarn generate && yarn generate:cleanup-artifacts && tsc
|
|
25
|
-
"build:keep-debug-symbols": "yarn clean && yarn generate && tsc
|
|
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
26
|
"generate": "yarn generate:data",
|
|
27
27
|
"generate:cleanup-artifacts": "node --no-warnings --loader @swc-node/register/esm src/scripts/cleanup_artifacts.ts",
|
|
28
28
|
"generate:data": "node --no-warnings --loader @swc-node/register/esm src/scripts/generate_data.ts",
|
|
29
|
-
"build:dev": "tsc
|
|
30
|
-
"build:ts": "tsc
|
|
29
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
30
|
+
"build:ts": "../scripts/tsc.sh",
|
|
31
31
|
"clean": "rm -rf ./dest .tsbuildinfo ./artifacts",
|
|
32
|
-
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
33
|
-
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
34
32
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
35
33
|
},
|
|
36
34
|
"inherits": [
|
|
@@ -68,27 +66,32 @@
|
|
|
68
66
|
"testTimeout": 120000,
|
|
69
67
|
"setupFiles": [
|
|
70
68
|
"../../foundation/src/jest/setup.mjs"
|
|
69
|
+
],
|
|
70
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
71
|
+
"setupFilesAfterEnv": [
|
|
72
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
71
73
|
]
|
|
72
74
|
},
|
|
73
75
|
"dependencies": {
|
|
74
|
-
"@aztec/constants": "0.0.
|
|
75
|
-
"@aztec/foundation": "0.0.
|
|
76
|
-
"@aztec/stdlib": "0.0.
|
|
76
|
+
"@aztec/constants": "0.0.1-commit.0208eb9",
|
|
77
|
+
"@aztec/foundation": "0.0.1-commit.0208eb9",
|
|
78
|
+
"@aztec/stdlib": "0.0.1-commit.0208eb9",
|
|
77
79
|
"lodash.chunk": "^4.2.0",
|
|
78
80
|
"lodash.omit": "^4.5.0",
|
|
79
81
|
"tslib": "^2.4.0"
|
|
80
82
|
},
|
|
81
83
|
"devDependencies": {
|
|
82
|
-
"@jest/globals": "^
|
|
83
|
-
"@types/jest": "^
|
|
84
|
+
"@jest/globals": "^30.0.0",
|
|
85
|
+
"@types/jest": "^30.0.0",
|
|
84
86
|
"@types/lodash.chunk": "^4.2.9",
|
|
85
87
|
"@types/lodash.omit": "^4.5.9",
|
|
86
|
-
"@types/node": "^
|
|
87
|
-
"
|
|
88
|
-
"jest
|
|
89
|
-
"
|
|
88
|
+
"@types/node": "^22.15.17",
|
|
89
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
90
|
+
"jest": "^30.0.0",
|
|
91
|
+
"jest-mock-extended": "^4.0.0",
|
|
92
|
+
"ts-loader": "^9.5.4",
|
|
90
93
|
"ts-node": "^10.9.1",
|
|
91
|
-
"typescript": "^5.
|
|
94
|
+
"typescript": "^5.3.3"
|
|
92
95
|
},
|
|
93
96
|
"files": [
|
|
94
97
|
"dest",
|
|
@@ -98,6 +101,6 @@
|
|
|
98
101
|
"!src/scripts/*"
|
|
99
102
|
],
|
|
100
103
|
"engines": {
|
|
101
|
-
"node": ">=
|
|
104
|
+
"node": ">=20.10"
|
|
102
105
|
}
|
|
103
106
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
1
|
+
import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
2
|
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
3
3
|
|
|
4
|
-
import AuthRegistryJson from '../../artifacts/AuthRegistry.json'
|
|
4
|
+
import AuthRegistryJson from '../../artifacts/AuthRegistry.json' with { type: 'json' };
|
|
5
5
|
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
6
6
|
import type { ProtocolContract } from '../protocol_contract.js';
|
|
7
7
|
|
|
8
8
|
let protocolContract: ProtocolContract;
|
|
9
9
|
|
|
10
|
-
export const AuthRegistryArtifact = loadContractArtifact(AuthRegistryJson as NoirCompiledContract);
|
|
10
|
+
export const AuthRegistryArtifact: ContractArtifact = loadContractArtifact(AuthRegistryJson as NoirCompiledContract);
|
|
11
11
|
|
|
12
12
|
/** Returns the canonical deployment of the auth registry. */
|
|
13
13
|
export async function getCanonicalAuthRegistry(): Promise<ProtocolContract> {
|
|
@@ -8,10 +8,10 @@ let protocolContractArtifact: ContractArtifact;
|
|
|
8
8
|
|
|
9
9
|
export async function getAuthRegistryArtifact(): Promise<ContractArtifact> {
|
|
10
10
|
if (!protocolContractArtifact) {
|
|
11
|
-
// Cannot assert this import as it's incompatible with
|
|
12
|
-
// https://
|
|
13
|
-
//
|
|
14
|
-
//
|
|
11
|
+
// Cannot assert this import as it's incompatible with bundlers like vite
|
|
12
|
+
// https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352
|
|
13
|
+
// Even if now supported by al major browsers, the MIME type is replaced with
|
|
14
|
+
// "text/javascript"
|
|
15
15
|
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
16
16
|
const { default: authRegistryJson } = await import('../../artifacts/AuthRegistry.json');
|
|
17
17
|
protocolContractArtifact = loadContractArtifact(authRegistryJson);
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { CONTRACT_CLASS_PUBLISHED_MAGIC_VALUE } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { FieldReader } from '@aztec/foundation/serialize';
|
|
4
|
-
import {
|
|
4
|
+
import { bufferFromFields } from '@aztec/stdlib/abi';
|
|
5
5
|
import {
|
|
6
6
|
type ContractClassPublic,
|
|
7
|
-
type PublicFunction,
|
|
8
7
|
computeContractClassId,
|
|
9
8
|
computePublicBytecodeCommitment,
|
|
10
9
|
} from '@aztec/stdlib/contract';
|
|
11
10
|
import type { ContractClassLog } from '@aztec/stdlib/logs';
|
|
12
11
|
|
|
13
|
-
import {
|
|
12
|
+
import { ProtocolContractAddress } from '../protocol_contract_data.js';
|
|
14
13
|
|
|
15
|
-
/** Event emitted from the
|
|
16
|
-
export class
|
|
14
|
+
/** Event emitted from the ContractClassRegistry. */
|
|
15
|
+
export class ContractClassPublishedEvent {
|
|
17
16
|
constructor(
|
|
18
17
|
public readonly contractClassId: Fr,
|
|
19
18
|
public readonly version: number,
|
|
@@ -22,19 +21,24 @@ export class ContractClassRegisteredEvent {
|
|
|
22
21
|
public readonly packedPublicBytecode: Buffer,
|
|
23
22
|
) {}
|
|
24
23
|
|
|
25
|
-
static
|
|
26
|
-
return
|
|
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
|
+
);
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
static fromLog(log: ContractClassLog) {
|
|
30
|
-
|
|
32
|
+
// See how the log is serialized in `noir-projects/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);
|
|
31
35
|
const contractClassId = reader.readField();
|
|
32
36
|
const version = reader.readField().toNumber();
|
|
33
37
|
const artifactHash = reader.readField();
|
|
34
38
|
const privateFunctionsRoot = reader.readField();
|
|
35
|
-
const packedPublicBytecode = bufferFromFields(reader.readFieldArray(
|
|
39
|
+
const packedPublicBytecode = bufferFromFields(reader.readFieldArray(fieldsWithoutTag.length - reader.cursor));
|
|
36
40
|
|
|
37
|
-
return new
|
|
41
|
+
return new ContractClassPublishedEvent(
|
|
38
42
|
contractClassId,
|
|
39
43
|
version,
|
|
40
44
|
artifactHash,
|
|
@@ -60,24 +64,20 @@ export class ContractClassRegisteredEvent {
|
|
|
60
64
|
throw new Error(`Unexpected contract class version ${this.version}`);
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Remove public functions.
|
|
64
|
-
const publicFunctions: PublicFunction[] = [];
|
|
65
|
-
if (this.packedPublicBytecode.length > 0) {
|
|
66
|
-
publicFunctions.push({
|
|
67
|
-
selector: FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
|
|
68
|
-
bytecode: this.packedPublicBytecode,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
67
|
return {
|
|
73
68
|
id: this.contractClassId,
|
|
74
69
|
artifactHash: this.artifactHash,
|
|
75
70
|
packedBytecode: this.packedPublicBytecode,
|
|
76
71
|
privateFunctionsRoot: this.privateFunctionsRoot,
|
|
77
|
-
publicFunctions: publicFunctions,
|
|
78
72
|
version: this.version,
|
|
79
73
|
privateFunctions: [],
|
|
80
|
-
|
|
74
|
+
utilityFunctions: [],
|
|
81
75
|
};
|
|
82
76
|
}
|
|
77
|
+
|
|
78
|
+
public static extractContractClassEvents(logs: ContractClassLog[]): ContractClassPublishedEvent[] {
|
|
79
|
+
return logs
|
|
80
|
+
.filter((log: ContractClassLog) => ContractClassPublishedEvent.isContractClassPublishedEvent(log))
|
|
81
|
+
.map((log: ContractClassLog) => ContractClassPublishedEvent.fromLog(log));
|
|
82
|
+
}
|
|
83
83
|
}
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
2
|
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import ContractClassRegistryJson from '../../artifacts/ContractClassRegistry.json' with { type: 'json' };
|
|
5
5
|
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
6
6
|
import type { ProtocolContract } from '../protocol_contract.js';
|
|
7
7
|
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './contract_class_published_event.js';
|
|
9
9
|
export * from './private_function_broadcasted_event.js';
|
|
10
|
-
export * from './
|
|
10
|
+
export * from './utility_function_broadcasted_event.js';
|
|
11
11
|
|
|
12
|
-
export const
|
|
13
|
-
ContractClassRegistererJson as NoirCompiledContract,
|
|
14
|
-
);
|
|
12
|
+
export const ContractClassRegistryArtifact = loadContractArtifact(ContractClassRegistryJson as NoirCompiledContract);
|
|
15
13
|
|
|
16
14
|
let protocolContract: ProtocolContract;
|
|
17
15
|
|
|
18
16
|
/** Returns the canonical deployment of the contract. */
|
|
19
|
-
export async function
|
|
17
|
+
export async function getCanonicalClassRegistry(): Promise<ProtocolContract> {
|
|
20
18
|
if (!protocolContract) {
|
|
21
|
-
const artifact =
|
|
22
|
-
protocolContract = await makeProtocolContract('
|
|
19
|
+
const artifact = ContractClassRegistryArtifact;
|
|
20
|
+
protocolContract = await makeProtocolContract('ContractClassRegistry', artifact);
|
|
23
21
|
}
|
|
24
22
|
return protocolContract;
|
|
25
23
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
|
|
3
|
+
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
4
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
5
|
+
|
|
6
|
+
export * from './contract_class_published_event.js';
|
|
7
|
+
export * from './private_function_broadcasted_event.js';
|
|
8
|
+
export * from './utility_function_broadcasted_event.js';
|
|
9
|
+
|
|
10
|
+
let protocolContract: ProtocolContract;
|
|
11
|
+
let protocolContractArtifact: ContractArtifact;
|
|
12
|
+
|
|
13
|
+
export async function getContractClassRegistryArtifact(): Promise<ContractArtifact> {
|
|
14
|
+
if (!protocolContractArtifact) {
|
|
15
|
+
// Cannot assert this import as it's incompatible with bundlers like vite
|
|
16
|
+
// https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352
|
|
17
|
+
// Even if now supported by al major browsers, the MIME type is replaced with
|
|
18
|
+
// "text/javascript"
|
|
19
|
+
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
20
|
+
const { default: contractClassRegistryJson } = await import('../../artifacts/ContractClassRegistry.json');
|
|
21
|
+
protocolContractArtifact = loadContractArtifact(contractClassRegistryJson);
|
|
22
|
+
}
|
|
23
|
+
return protocolContractArtifact;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Returns the canonical deployment of the auth registry. */
|
|
27
|
+
export async function getCanonicalClassRegistry(): Promise<ProtocolContract> {
|
|
28
|
+
if (!protocolContract) {
|
|
29
|
+
const contractClassRegistryArtifact = await getContractClassRegistryArtifact();
|
|
30
|
+
protocolContract = await makeProtocolContract('ContractClassRegistry', contractClassRegistryArtifact);
|
|
31
|
+
}
|
|
32
|
+
return protocolContract;
|
|
33
|
+
}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ARTIFACT_FUNCTION_TREE_MAX_HEIGHT,
|
|
3
|
+
CONTRACT_CLASS_REGISTRY_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE,
|
|
3
4
|
FUNCTION_TREE_HEIGHT,
|
|
4
5
|
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
5
6
|
} from '@aztec/constants';
|
|
6
|
-
import { Fr } from '@aztec/foundation/
|
|
7
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
7
8
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
8
9
|
import { FieldReader } from '@aztec/foundation/serialize';
|
|
9
10
|
import { FunctionSelector, bufferFromFields } from '@aztec/stdlib/abi';
|
|
10
11
|
import type { ExecutablePrivateFunctionWithMembershipProof, PrivateFunction } from '@aztec/stdlib/contract';
|
|
11
12
|
import type { ContractClassLog } from '@aztec/stdlib/logs';
|
|
12
13
|
|
|
13
|
-
import {
|
|
14
|
+
import { ProtocolContractAddress } from '../protocol_contract_data.js';
|
|
14
15
|
|
|
15
|
-
/** Event emitted from the
|
|
16
|
+
/** Event emitted from the ContractClassRegistry. */
|
|
16
17
|
export class PrivateFunctionBroadcastedEvent {
|
|
17
18
|
constructor(
|
|
18
19
|
public readonly contractClassId: Fr,
|
|
19
20
|
public readonly artifactMetadataHash: Fr,
|
|
20
|
-
public readonly
|
|
21
|
+
public readonly utilityFunctionsTreeRoot: Fr,
|
|
21
22
|
public readonly privateFunctionTreeSiblingPath: Tuple<Fr, typeof FUNCTION_TREE_HEIGHT>,
|
|
22
23
|
public readonly privateFunctionTreeLeafIndex: number,
|
|
23
24
|
public readonly artifactFunctionTreeSiblingPath: Tuple<Fr, typeof ARTIFACT_FUNCTION_TREE_MAX_HEIGHT>,
|
|
@@ -26,11 +27,14 @@ export class PrivateFunctionBroadcastedEvent {
|
|
|
26
27
|
) {}
|
|
27
28
|
|
|
28
29
|
static isPrivateFunctionBroadcastedEvent(log: ContractClassLog) {
|
|
29
|
-
return
|
|
30
|
+
return (
|
|
31
|
+
log.contractAddress.equals(ProtocolContractAddress.ContractClassRegistry) &&
|
|
32
|
+
log.fields.fields[0].toBigInt() === CONTRACT_CLASS_REGISTRY_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE
|
|
33
|
+
);
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
static fromLog(log: ContractClassLog) {
|
|
33
|
-
const reader = new FieldReader(log.fields.slice(1));
|
|
37
|
+
const reader = new FieldReader(log.fields.fields.slice(1));
|
|
34
38
|
const event = PrivateFunctionBroadcastedEvent.fromFields(reader);
|
|
35
39
|
while (!reader.isFinished()) {
|
|
36
40
|
const field = reader.readField();
|
|
@@ -46,7 +50,7 @@ export class PrivateFunctionBroadcastedEvent {
|
|
|
46
50
|
const reader = FieldReader.asReader(fields);
|
|
47
51
|
const contractClassId = reader.readField();
|
|
48
52
|
const artifactMetadataHash = reader.readField();
|
|
49
|
-
const
|
|
53
|
+
const utilityFunctionsTreeRoot = reader.readField();
|
|
50
54
|
const privateFunctionTreeSiblingPath = reader.readFieldArray(FUNCTION_TREE_HEIGHT);
|
|
51
55
|
const privateFunctionTreeLeafIndex = reader.readField().toNumber();
|
|
52
56
|
const artifactFunctionTreeSiblingPath = reader.readFieldArray(ARTIFACT_FUNCTION_TREE_MAX_HEIGHT);
|
|
@@ -56,7 +60,7 @@ export class PrivateFunctionBroadcastedEvent {
|
|
|
56
60
|
return new PrivateFunctionBroadcastedEvent(
|
|
57
61
|
contractClassId,
|
|
58
62
|
artifactMetadataHash,
|
|
59
|
-
|
|
63
|
+
utilityFunctionsTreeRoot,
|
|
60
64
|
privateFunctionTreeSiblingPath,
|
|
61
65
|
privateFunctionTreeLeafIndex,
|
|
62
66
|
artifactFunctionTreeSiblingPath,
|
|
@@ -71,7 +75,7 @@ export class PrivateFunctionBroadcastedEvent {
|
|
|
71
75
|
bytecode: this.privateFunction.bytecode,
|
|
72
76
|
functionMetadataHash: this.privateFunction.metadataHash,
|
|
73
77
|
artifactMetadataHash: this.artifactMetadataHash,
|
|
74
|
-
|
|
78
|
+
utilityFunctionsTreeRoot: this.utilityFunctionsTreeRoot,
|
|
75
79
|
privateFunctionTreeSiblingPath: this.privateFunctionTreeSiblingPath,
|
|
76
80
|
privateFunctionTreeLeafIndex: this.privateFunctionTreeLeafIndex,
|
|
77
81
|
artifactTreeSiblingPath: this.artifactFunctionTreeSiblingPath.filter(fr => !fr.isZero()),
|