@aztec/protocol-contracts 0.0.0-test.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.
Files changed (124) hide show
  1. package/README.md +7 -0
  2. package/artifacts/AuthRegistry.d.json.ts +5 -0
  3. package/artifacts/AuthRegistry.json +2725 -0
  4. package/artifacts/ContractClassRegisterer.d.json.ts +5 -0
  5. package/artifacts/ContractClassRegisterer.json +7219 -0
  6. package/artifacts/ContractInstanceDeployer.d.json.ts +5 -0
  7. package/artifacts/ContractInstanceDeployer.json +2984 -0
  8. package/artifacts/FeeJuice.d.json.ts +5 -0
  9. package/artifacts/FeeJuice.json +4281 -0
  10. package/artifacts/MultiCallEntrypoint.d.json.ts +5 -0
  11. package/artifacts/MultiCallEntrypoint.json +2005 -0
  12. package/artifacts/Router.d.json.ts +5 -0
  13. package/artifacts/Router.json +3798 -0
  14. package/dest/auth-registry/index.d.ts +5 -0
  15. package/dest/auth-registry/index.d.ts.map +1 -0
  16. package/dest/auth-registry/index.js +13 -0
  17. package/dest/auth-registry/lazy.d.ts +6 -0
  18. package/dest/auth-registry/lazy.d.ts.map +1 -0
  19. package/dest/auth-registry/lazy.js +23 -0
  20. package/dest/build_protocol_contract_tree.d.ts +10 -0
  21. package/dest/build_protocol_contract_tree.d.ts.map +1 -0
  22. package/dest/build_protocol_contract_tree.js +20 -0
  23. package/dest/class-registerer/contract_class_registered_event.d.ts +18 -0
  24. package/dest/class-registerer/contract_class_registered_event.d.ts.map +1 -0
  25. package/dest/class-registerer/contract_class_registered_event.js +63 -0
  26. package/dest/class-registerer/index.d.ts +8 -0
  27. package/dest/class-registerer/index.d.ts.map +1 -0
  28. package/dest/class-registerer/index.js +17 -0
  29. package/dest/class-registerer/lazy.d.ts +9 -0
  30. package/dest/class-registerer/lazy.d.ts.map +1 -0
  31. package/dest/class-registerer/lazy.js +26 -0
  32. package/dest/class-registerer/private_function_broadcasted_event.d.ts +46 -0
  33. package/dest/class-registerer/private_function_broadcasted_event.d.ts.map +1 -0
  34. package/dest/class-registerer/private_function_broadcasted_event.js +85 -0
  35. package/dest/class-registerer/unconstrained_function_broadcasted_event.d.ts +40 -0
  36. package/dest/class-registerer/unconstrained_function_broadcasted_event.d.ts.map +1 -0
  37. package/dest/class-registerer/unconstrained_function_broadcasted_event.js +81 -0
  38. package/dest/fee-juice/index.d.ts +15 -0
  39. package/dest/fee-juice/index.d.ts.map +1 -0
  40. package/dest/fee-juice/index.js +26 -0
  41. package/dest/fee-juice/lazy.d.ts +6 -0
  42. package/dest/fee-juice/lazy.d.ts.map +1 -0
  43. package/dest/fee-juice/lazy.js +23 -0
  44. package/dest/index.d.ts +4 -0
  45. package/dest/index.d.ts.map +1 -0
  46. package/dest/index.js +3 -0
  47. package/dest/instance-deployer/contract_instance_deployed_event.d.ts +20 -0
  48. package/dest/instance-deployer/contract_instance_deployed_event.d.ts.map +1 -0
  49. package/dest/instance-deployer/contract_instance_deployed_event.js +53 -0
  50. package/dest/instance-deployer/contract_instance_updated_event.d.ts +16 -0
  51. package/dest/instance-deployer/contract_instance_updated_event.d.ts.map +1 -0
  52. package/dest/instance-deployer/contract_instance_updated_event.js +36 -0
  53. package/dest/instance-deployer/index.d.ts +7 -0
  54. package/dest/instance-deployer/index.d.ts.map +1 -0
  55. package/dest/instance-deployer/index.js +15 -0
  56. package/dest/instance-deployer/lazy.d.ts +8 -0
  57. package/dest/instance-deployer/lazy.d.ts.map +1 -0
  58. package/dest/instance-deployer/lazy.js +25 -0
  59. package/dest/make_protocol_contract.d.ts +9 -0
  60. package/dest/make_protocol_contract.d.ts.map +1 -0
  61. package/dest/make_protocol_contract.js +23 -0
  62. package/dest/multi-call-entrypoint/index.d.ts +5 -0
  63. package/dest/multi-call-entrypoint/index.d.ts.map +1 -0
  64. package/dest/multi-call-entrypoint/index.js +13 -0
  65. package/dest/multi-call-entrypoint/lazy.d.ts +6 -0
  66. package/dest/multi-call-entrypoint/lazy.d.ts.map +1 -0
  67. package/dest/multi-call-entrypoint/lazy.js +23 -0
  68. package/dest/protocol_contract.d.ts +17 -0
  69. package/dest/protocol_contract.d.ts.map +1 -0
  70. package/dest/protocol_contract.js +4 -0
  71. package/dest/protocol_contract_data.d.ts +21 -0
  72. package/dest/protocol_contract_data.d.ts.map +1 -0
  73. package/dest/protocol_contract_data.js +41 -0
  74. package/dest/protocol_contract_tree.d.ts +7 -0
  75. package/dest/protocol_contract_tree.d.ts.map +1 -0
  76. package/dest/protocol_contract_tree.js +34 -0
  77. package/dest/provider/bundle.d.ts +9 -0
  78. package/dest/provider/bundle.d.ts.map +1 -0
  79. package/dest/provider/bundle.js +20 -0
  80. package/dest/provider/lazy.d.ts +7 -0
  81. package/dest/provider/lazy.d.ts.map +1 -0
  82. package/dest/provider/lazy.js +26 -0
  83. package/dest/provider/protocol_contracts_provider.d.ts +7 -0
  84. package/dest/provider/protocol_contracts_provider.d.ts.map +1 -0
  85. package/dest/provider/protocol_contracts_provider.js +1 -0
  86. package/dest/router/index.d.ts +5 -0
  87. package/dest/router/index.d.ts.map +1 -0
  88. package/dest/router/index.js +13 -0
  89. package/dest/router/lazy.d.ts +6 -0
  90. package/dest/router/lazy.d.ts.map +1 -0
  91. package/dest/router/lazy.js +23 -0
  92. package/dest/scripts/cleanup_artifacts.js +16 -0
  93. package/dest/scripts/generate_data.js +173 -0
  94. package/dest/tests/fixtures.d.ts +8 -0
  95. package/dest/tests/fixtures.d.ts.map +1 -0
  96. package/dest/tests/fixtures.js +26 -0
  97. package/package.json +103 -0
  98. package/src/auth-registry/index.ts +18 -0
  99. package/src/auth-registry/lazy.ts +29 -0
  100. package/src/build_protocol_contract_tree.ts +29 -0
  101. package/src/class-registerer/contract_class_registered_event.ts +83 -0
  102. package/src/class-registerer/index.ts +25 -0
  103. package/src/class-registerer/lazy.ts +33 -0
  104. package/src/class-registerer/private_function_broadcasted_event.ts +105 -0
  105. package/src/class-registerer/unconstrained_function_broadcasted_event.ts +99 -0
  106. package/src/fee-juice/index.ts +37 -0
  107. package/src/fee-juice/lazy.ts +29 -0
  108. package/src/index.ts +3 -0
  109. package/src/instance-deployer/contract_instance_deployed_event.ts +64 -0
  110. package/src/instance-deployer/contract_instance_updated_event.ts +44 -0
  111. package/src/instance-deployer/index.ts +23 -0
  112. package/src/instance-deployer/lazy.ts +32 -0
  113. package/src/make_protocol_contract.ts +26 -0
  114. package/src/multi-call-entrypoint/index.ts +18 -0
  115. package/src/multi-call-entrypoint/lazy.ts +29 -0
  116. package/src/protocol_contract.ts +23 -0
  117. package/src/protocol_contract_data.ts +63 -0
  118. package/src/protocol_contract_tree.ts +44 -0
  119. package/src/provider/bundle.ts +27 -0
  120. package/src/provider/lazy.ts +30 -0
  121. package/src/provider/protocol_contracts_provider.ts +7 -0
  122. package/src/router/index.ts +18 -0
  123. package/src/router/lazy.ts +29 -0
  124. package/src/tests/fixtures.ts +31 -0
@@ -0,0 +1,16 @@
1
+ import { fileURLToPath } from '@aztec/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
+ fileData.file_map = {};
12
+ fileData.debug_symbols = {};
13
+ await writeFile(join(target, file), JSON.stringify(fileData));
14
+ }
15
+ }
16
+ await cleanupArtifacts(fileURLToPath(new URL('../../artifacts', import.meta.url).href));
@@ -0,0 +1,173 @@
1
+ import { CANONICAL_AUTH_REGISTRY_ADDRESS, DEPLOYER_CONTRACT_ADDRESS, DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE, DEPLOYER_CONTRACT_INSTANCE_UPDATED_MAGIC_VALUE, FEE_JUICE_ADDRESS, MULTI_CALL_ENTRYPOINT_ADDRESS, REGISTERER_CONTRACT_ADDRESS, REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE, REGISTERER_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE, REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE, ROUTER_ADDRESS } from '@aztec/constants';
2
+ import { poseidon2Hash } from '@aztec/foundation/crypto';
3
+ import { Fr } from '@aztec/foundation/fields';
4
+ import { createConsoleLogger } from '@aztec/foundation/log';
5
+ import { loadContractArtifact } from '@aztec/stdlib/abi';
6
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
7
+ import { getContractInstanceFromDeployParams } from '@aztec/stdlib/contract';
8
+ import { promises as fs } from 'fs';
9
+ import path from 'path';
10
+ import { buildProtocolContractTree } from '../build_protocol_contract_tree.js';
11
+ const log = createConsoleLogger('autogenerate');
12
+ const noirContractsRoot = '../../noir-projects/noir-contracts';
13
+ const srcPath = path.join(noirContractsRoot, './target');
14
+ const destArtifactsDir = './artifacts';
15
+ const outputFilePath = './src/protocol_contract_data.ts';
16
+ const salt = new Fr(1);
17
+ const contractAddressMapping = {
18
+ AuthRegistry: CANONICAL_AUTH_REGISTRY_ADDRESS,
19
+ ContractInstanceDeployer: DEPLOYER_CONTRACT_ADDRESS,
20
+ ContractClassRegisterer: REGISTERER_CONTRACT_ADDRESS,
21
+ MultiCallEntrypoint: MULTI_CALL_ENTRYPOINT_ADDRESS,
22
+ FeeJuice: FEE_JUICE_ADDRESS,
23
+ Router: ROUTER_ADDRESS
24
+ };
25
+ async function clearDestDir() {
26
+ try {
27
+ await fs.access(destArtifactsDir);
28
+ // If the directory exists, remove it recursively.
29
+ await fs.rm(destArtifactsDir, {
30
+ recursive: true,
31
+ force: true,
32
+ maxRetries: 3
33
+ });
34
+ } catch (err) {
35
+ if (err.code === 'ENOENT') {
36
+ // If the directory does not exist, do nothing.
37
+ } else {
38
+ log(`Error removing dest directory: ${err}`);
39
+ }
40
+ }
41
+ await fs.mkdir(destArtifactsDir, {
42
+ recursive: true
43
+ });
44
+ }
45
+ async function copyArtifact(srcName, destName) {
46
+ const src = path.join(srcPath, `${srcName}.json`);
47
+ const artifact = JSON.parse(await fs.readFile(src, 'utf8'));
48
+ const dest = path.join(destArtifactsDir, `${destName}.json`);
49
+ await fs.copyFile(src, dest);
50
+ return artifact;
51
+ }
52
+ async function computeContractLeaf(artifact) {
53
+ const instance = await getContractInstanceFromDeployParams(loadContractArtifact(artifact), {
54
+ salt
55
+ });
56
+ return instance.address;
57
+ }
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
+ async function generateDeclarationFile(destName) {
67
+ const content = `
68
+ import type { NoirCompiledContract } from '@aztec/stdlib/noir';
69
+ const circuit: NoirCompiledContract;
70
+ export = circuit;
71
+ `;
72
+ await fs.writeFile(path.join(destArtifactsDir, `${destName}.d.json.ts`), content);
73
+ }
74
+ function generateNames(names) {
75
+ return `
76
+ export const protocolContractNames = [
77
+ ${names.map((name)=>`'${name}'`).join(',\n')}
78
+ ] as const;
79
+
80
+ export type ProtocolContractName = typeof protocolContractNames[number];
81
+ `;
82
+ }
83
+ function generateSalts(names) {
84
+ return `
85
+ export const ProtocolContractSalt: Record<ProtocolContractName, Fr> = {
86
+ ${names.map((name)=>`${name}: new Fr(${salt.toNumber()})`).join(',\n')}
87
+ };
88
+ `;
89
+ }
90
+ function generateContractAddresses(names) {
91
+ const addresses = names.map((name)=>`${name}: AztecAddress.fromBigInt(${contractAddressMapping[name]}n)`).join(',\n');
92
+ return `
93
+ export const ProtocolContractAddress: Record<ProtocolContractName, AztecAddress> = {
94
+ ${addresses}
95
+ };
96
+ `;
97
+ }
98
+ function generateContractLeaves(names, leaves) {
99
+ return `
100
+ export const ProtocolContractLeaves = {
101
+ ${leaves.map((leaf, i)=>`${names[i]}: Fr.fromHexString('${leaf.toString()}')`).join(',\n')}
102
+ };
103
+ `;
104
+ }
105
+ async function generateRoot(names, leaves) {
106
+ const root = await computeRoot(names, leaves);
107
+ return `
108
+ export const protocolContractTreeRoot = Fr.fromHexString('${root.toString()}');
109
+ `;
110
+ }
111
+ async function generateLogTags() {
112
+ // See silo_contract_class_log for all registerer tags
113
+ return `
114
+ export const REGISTERER_CONTRACT_CLASS_REGISTERED_TAG = Fr.fromHexString('${await poseidon2Hash([
115
+ REGISTERER_CONTRACT_ADDRESS,
116
+ REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE
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);
131
+ `;
132
+ }
133
+ async function generateOutputFile(names, leaves) {
134
+ const content = `
135
+ // GENERATED FILE - DO NOT EDIT. RUN \`yarn generate\` or \`yarn generate:data\`
136
+ import { Fr } from '@aztec/foundation/fields';
137
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
138
+
139
+ ${generateNames(names)}
140
+
141
+ ${generateSalts(names)}
142
+
143
+ ${generateContractAddresses(names)}
144
+
145
+ ${generateContractLeaves(names, leaves)}
146
+
147
+ ${await generateRoot(names, leaves)}
148
+
149
+ ${await generateLogTags()}
150
+ `;
151
+ await fs.writeFile(outputFilePath, content);
152
+ }
153
+ async function main() {
154
+ await clearDestDir();
155
+ const srcNames = JSON.parse(await fs.readFile(path.join(noirContractsRoot, 'protocol_contracts.json'), 'utf8'));
156
+ const leaves = [];
157
+ const destNames = srcNames.map((n)=>n.split('-')[1]);
158
+ for(let i = 0; i < srcNames.length; i++){
159
+ const srcName = srcNames[i];
160
+ const destName = destNames[i];
161
+ const artifact = await copyArtifact(srcName, destName);
162
+ await generateDeclarationFile(destName);
163
+ const contractLeaf = await computeContractLeaf(artifact);
164
+ leaves.push(contractLeaf.toField());
165
+ }
166
+ await generateOutputFile(destNames, leaves);
167
+ }
168
+ try {
169
+ await main();
170
+ } catch (err) {
171
+ log(`Error copying protocol contract artifacts: ${err}`);
172
+ process.exit(1);
173
+ }
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ export declare function getSampleContractClassRegisteredEventPayload(): Buffer;
4
+ export declare function getSamplePrivateFunctionBroadcastedEventPayload(): Buffer;
5
+ export declare function getSampleUnconstrainedFunctionBroadcastedEventPayload(): Buffer;
6
+ export declare function getSampleContractInstanceDeployedEventPayload(): Buffer;
7
+ export declare function getPathToFixture(name: string): string;
8
+ //# sourceMappingURL=fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../src/tests/fixtures.ts"],"names":[],"mappings":";;AAKA,wBAAgB,4CAA4C,IAAI,MAAM,CAGrE;AAGD,wBAAgB,+CAA+C,IAAI,MAAM,CAGxE;AAGD,wBAAgB,qDAAqD,IAAI,MAAM,CAG9E;AAGD,wBAAgB,6CAA6C,IAAI,MAAM,CAGtE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,UAE5C"}
@@ -0,0 +1,26 @@
1
+ import { readFileSync } from 'fs';
2
+ import { dirname, resolve } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ // Generated from end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts with AZTEC_GENERATE_TEST_DATA=1
5
+ export function getSampleContractClassRegisteredEventPayload() {
6
+ const path = getPathToFixture('ContractClassRegisteredEventData.hex');
7
+ return Buffer.from(readFileSync(path).toString(), 'hex');
8
+ }
9
+ // Generated from end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts with AZTEC_GENERATE_TEST_DATA=1
10
+ export function getSamplePrivateFunctionBroadcastedEventPayload() {
11
+ const path = getPathToFixture('PrivateFunctionBroadcastedEventData.hex');
12
+ return Buffer.from(readFileSync(path).toString(), 'hex');
13
+ }
14
+ // Generated from end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts with AZTEC_GENERATE_TEST_DATA=1
15
+ export function getSampleUnconstrainedFunctionBroadcastedEventPayload() {
16
+ const path = getPathToFixture('UnconstrainedFunctionBroadcastedEventData.hex');
17
+ return Buffer.from(readFileSync(path).toString(), 'hex');
18
+ }
19
+ // Generated from end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts with AZTEC_GENERATE_TEST_DATA=1
20
+ export function getSampleContractInstanceDeployedEventPayload() {
21
+ const path = getPathToFixture('ContractInstanceDeployedEventData.hex');
22
+ return Buffer.from(readFileSync(path).toString(), 'hex');
23
+ }
24
+ export function getPathToFixture(name) {
25
+ return resolve(dirname(fileURLToPath(import.meta.url)), `../../fixtures/${name}`);
26
+ }
package/package.json ADDED
@@ -0,0 +1,103 @@
1
+ {
2
+ "name": "@aztec/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": "0.0.0-test.0",
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-registerer/index.ts",
18
+ "./src/instance-deployer/index.ts"
19
+ ],
20
+ "name": "Protocol Contracts",
21
+ "tsconfig": "./tsconfig.json"
22
+ },
23
+ "scripts": {
24
+ "build": "yarn clean && yarn generate && yarn generate:cleanup-artifacts && tsc -b",
25
+ "build:keep-debug-symbols": "yarn clean && yarn generate && tsc -b",
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": "tsc -b --watch",
30
+ "build:ts": "tsc -b",
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
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
35
+ },
36
+ "inherits": [
37
+ "../package.common.json",
38
+ "./package.local.json"
39
+ ],
40
+ "jest": {
41
+ "moduleNameMapper": {
42
+ "^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
43
+ },
44
+ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
45
+ "rootDir": "./src",
46
+ "transform": {
47
+ "^.+\\.tsx?$": [
48
+ "@swc/jest",
49
+ {
50
+ "jsc": {
51
+ "parser": {
52
+ "syntax": "typescript",
53
+ "decorators": true
54
+ },
55
+ "transform": {
56
+ "decoratorVersion": "2022-03"
57
+ }
58
+ }
59
+ }
60
+ ]
61
+ },
62
+ "extensionsToTreatAsEsm": [
63
+ ".ts"
64
+ ],
65
+ "reporters": [
66
+ "default"
67
+ ],
68
+ "testTimeout": 120000,
69
+ "setupFiles": [
70
+ "../../foundation/src/jest/setup.mjs"
71
+ ]
72
+ },
73
+ "dependencies": {
74
+ "@aztec/constants": "0.0.0-test.0",
75
+ "@aztec/foundation": "0.0.0-test.0",
76
+ "@aztec/stdlib": "0.0.0-test.0",
77
+ "lodash.chunk": "^4.2.0",
78
+ "lodash.omit": "^4.5.0",
79
+ "tslib": "^2.4.0"
80
+ },
81
+ "devDependencies": {
82
+ "@jest/globals": "^29.5.0",
83
+ "@types/jest": "^29.5.0",
84
+ "@types/lodash.chunk": "^4.2.9",
85
+ "@types/lodash.omit": "^4.5.9",
86
+ "@types/node": "^18.7.23",
87
+ "jest": "^29.5.0",
88
+ "jest-mock-extended": "^3.0.3",
89
+ "ts-loader": "^9.4.4",
90
+ "ts-node": "^10.9.1",
91
+ "typescript": "^5.0.4"
92
+ },
93
+ "files": [
94
+ "dest",
95
+ "src",
96
+ "!*.test.*",
97
+ "artifacts",
98
+ "!src/scripts/*"
99
+ ],
100
+ "engines": {
101
+ "node": ">=18"
102
+ }
103
+ }
@@ -0,0 +1,18 @@
1
+ import { loadContractArtifact } from '@aztec/stdlib/abi';
2
+ import type { NoirCompiledContract } from '@aztec/stdlib/noir';
3
+
4
+ import AuthRegistryJson from '../../artifacts/AuthRegistry.json' assert { type: 'json' };
5
+ import { makeProtocolContract } from '../make_protocol_contract.js';
6
+ import type { ProtocolContract } from '../protocol_contract.js';
7
+
8
+ let protocolContract: ProtocolContract;
9
+
10
+ export const AuthRegistryArtifact = loadContractArtifact(AuthRegistryJson as NoirCompiledContract);
11
+
12
+ /** Returns the canonical deployment of the auth registry. */
13
+ export async function getCanonicalAuthRegistry(): Promise<ProtocolContract> {
14
+ if (!protocolContract) {
15
+ protocolContract = await makeProtocolContract('AuthRegistry', AuthRegistryArtifact);
16
+ }
17
+ return protocolContract;
18
+ }
@@ -0,0 +1,29 @@
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
+ let protocolContract: ProtocolContract;
7
+ let protocolContractArtifact: ContractArtifact;
8
+
9
+ export async function getAuthRegistryArtifact(): Promise<ContractArtifact> {
10
+ if (!protocolContractArtifact) {
11
+ // Cannot assert this import as it's incompatible with browsers
12
+ // https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
13
+ // Use the new "with" syntax once supported by firefox
14
+ // https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
15
+ // In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
16
+ const { default: authRegistryJson } = await import('../../artifacts/AuthRegistry.json');
17
+ protocolContractArtifact = loadContractArtifact(authRegistryJson);
18
+ }
19
+ return protocolContractArtifact;
20
+ }
21
+
22
+ /** Returns the canonical deployment of the auth registry. */
23
+ export async function getCanonicalAuthRegistry(): Promise<ProtocolContract> {
24
+ if (!protocolContract) {
25
+ const authRegistryArtifact = await getAuthRegistryArtifact();
26
+ protocolContract = await makeProtocolContract('AuthRegistry', authRegistryArtifact);
27
+ }
28
+ return protocolContract;
29
+ }
@@ -0,0 +1,29 @@
1
+ import { MAX_PROTOCOL_CONTRACTS, PROTOCOL_CONTRACT_TREE_HEIGHT } from '@aztec/constants';
2
+ import { poseidon2Hash } from '@aztec/foundation/crypto';
3
+ import type { Fr } from '@aztec/foundation/fields';
4
+ import { type IndexedMerkleTree, IndexedMerkleTreeCalculator } from '@aztec/foundation/trees';
5
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
+ import { ProtocolContractLeafPreimage } from '@aztec/stdlib/trees';
7
+
8
+ export async function buildProtocolContractTree(
9
+ contracts: { address: AztecAddress; leaf: Fr }[],
10
+ ): Promise<IndexedMerkleTree<ProtocolContractLeafPreimage, typeof PROTOCOL_CONTRACT_TREE_HEIGHT>> {
11
+ const hasher = {
12
+ hash: async (l: Buffer, r: Buffer) => (await poseidon2Hash([l, r])).toBuffer(),
13
+ hashInputs: async (i: Buffer[]) => (await poseidon2Hash(i)).toBuffer(),
14
+ };
15
+ const calculator = await IndexedMerkleTreeCalculator.create(
16
+ PROTOCOL_CONTRACT_TREE_HEIGHT,
17
+ hasher,
18
+ ProtocolContractLeafPreimage,
19
+ );
20
+
21
+ const leaves = new Array(MAX_PROTOCOL_CONTRACTS).fill(Buffer.alloc(32));
22
+
23
+ for (const contract of contracts) {
24
+ const index = contract.address.toField().toNumber();
25
+ leaves[index] = contract.leaf.toBuffer();
26
+ }
27
+
28
+ return calculator.computeTree(leaves);
29
+ }
@@ -0,0 +1,83 @@
1
+ import { PUBLIC_DISPATCH_SELECTOR } from '@aztec/constants';
2
+ import { Fr } from '@aztec/foundation/fields';
3
+ import { FieldReader } from '@aztec/foundation/serialize';
4
+ import { FunctionSelector, bufferFromFields } from '@aztec/stdlib/abi';
5
+ import {
6
+ type ContractClassPublic,
7
+ type PublicFunction,
8
+ computeContractClassId,
9
+ computePublicBytecodeCommitment,
10
+ } from '@aztec/stdlib/contract';
11
+ import type { ContractClassLog } from '@aztec/stdlib/logs';
12
+
13
+ import { REGISTERER_CONTRACT_CLASS_REGISTERED_TAG } from '../protocol_contract_data.js';
14
+
15
+ /** Event emitted from the ContractClassRegisterer. */
16
+ export class ContractClassRegisteredEvent {
17
+ constructor(
18
+ public readonly contractClassId: Fr,
19
+ public readonly version: number,
20
+ public readonly artifactHash: Fr,
21
+ public readonly privateFunctionsRoot: Fr,
22
+ public readonly packedPublicBytecode: Buffer,
23
+ ) {}
24
+
25
+ static isContractClassRegisteredEvent(log: ContractClassLog) {
26
+ return log.fields[0].equals(REGISTERER_CONTRACT_CLASS_REGISTERED_TAG);
27
+ }
28
+
29
+ static fromLog(log: ContractClassLog) {
30
+ const reader = new FieldReader(log.fields.slice(1));
31
+ const contractClassId = reader.readField();
32
+ const version = reader.readField().toNumber();
33
+ const artifactHash = reader.readField();
34
+ const privateFunctionsRoot = reader.readField();
35
+ const packedPublicBytecode = bufferFromFields(reader.readFieldArray(log.fields.slice(1).length - reader.cursor));
36
+
37
+ return new ContractClassRegisteredEvent(
38
+ contractClassId,
39
+ version,
40
+ artifactHash,
41
+ privateFunctionsRoot,
42
+ packedPublicBytecode,
43
+ );
44
+ }
45
+
46
+ async toContractClassPublic(): Promise<ContractClassPublic> {
47
+ const computedClassId = await computeContractClassId({
48
+ artifactHash: this.artifactHash,
49
+ privateFunctionsRoot: this.privateFunctionsRoot,
50
+ publicBytecodeCommitment: await computePublicBytecodeCommitment(this.packedPublicBytecode),
51
+ });
52
+
53
+ if (!computedClassId.equals(this.contractClassId)) {
54
+ throw new Error(
55
+ `Invalid contract class id: computed ${computedClassId.toString()} but event broadcasted ${this.contractClassId.toString()}`,
56
+ );
57
+ }
58
+
59
+ if (this.version !== 1) {
60
+ throw new Error(`Unexpected contract class version ${this.version}`);
61
+ }
62
+
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
+ return {
73
+ id: this.contractClassId,
74
+ artifactHash: this.artifactHash,
75
+ packedBytecode: this.packedPublicBytecode,
76
+ privateFunctionsRoot: this.privateFunctionsRoot,
77
+ publicFunctions: publicFunctions,
78
+ version: this.version,
79
+ privateFunctions: [],
80
+ unconstrainedFunctions: [],
81
+ };
82
+ }
83
+ }
@@ -0,0 +1,25 @@
1
+ import { loadContractArtifact } from '@aztec/stdlib/abi';
2
+ import type { NoirCompiledContract } from '@aztec/stdlib/noir';
3
+
4
+ import ContractClassRegistererJson from '../../artifacts/ContractClassRegisterer.json' assert { type: 'json' };
5
+ import { makeProtocolContract } from '../make_protocol_contract.js';
6
+ import type { ProtocolContract } from '../protocol_contract.js';
7
+
8
+ export * from './contract_class_registered_event.js';
9
+ export * from './private_function_broadcasted_event.js';
10
+ export * from './unconstrained_function_broadcasted_event.js';
11
+
12
+ export const ContractClassRegistererArtifact = loadContractArtifact(
13
+ ContractClassRegistererJson as NoirCompiledContract,
14
+ );
15
+
16
+ let protocolContract: ProtocolContract;
17
+
18
+ /** Returns the canonical deployment of the contract. */
19
+ export async function getCanonicalClassRegisterer(): Promise<ProtocolContract> {
20
+ if (!protocolContract) {
21
+ const artifact = ContractClassRegistererArtifact;
22
+ protocolContract = await makeProtocolContract('ContractClassRegisterer', artifact);
23
+ }
24
+ return protocolContract;
25
+ }
@@ -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_registered_event.js';
7
+ export * from './private_function_broadcasted_event.js';
8
+ export * from './unconstrained_function_broadcasted_event.js';
9
+
10
+ let protocolContract: ProtocolContract;
11
+ let protocolContractArtifact: ContractArtifact;
12
+
13
+ export async function getContractClassRegistererArtifact(): Promise<ContractArtifact> {
14
+ if (!protocolContractArtifact) {
15
+ // Cannot assert this import as it's incompatible with browsers
16
+ // https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
17
+ // Use the new "with" syntax once supported by firefox
18
+ // https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
19
+ // In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
20
+ const { default: contractClassRegistererJson } = await import('../../artifacts/ContractClassRegisterer.json');
21
+ protocolContractArtifact = loadContractArtifact(contractClassRegistererJson);
22
+ }
23
+ return protocolContractArtifact;
24
+ }
25
+
26
+ /** Returns the canonical deployment of the auth registry. */
27
+ export async function getCanonicalClassRegisterer(): Promise<ProtocolContract> {
28
+ if (!protocolContract) {
29
+ const contractClassRegistererArtifact = await getContractClassRegistererArtifact();
30
+ protocolContract = await makeProtocolContract('ContractClassRegisterer', contractClassRegistererArtifact);
31
+ }
32
+ return protocolContract;
33
+ }
@@ -0,0 +1,105 @@
1
+ import {
2
+ ARTIFACT_FUNCTION_TREE_MAX_HEIGHT,
3
+ FUNCTION_TREE_HEIGHT,
4
+ MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
5
+ } from '@aztec/constants';
6
+ import { Fr } from '@aztec/foundation/fields';
7
+ import type { Tuple } from '@aztec/foundation/serialize';
8
+ import { FieldReader } from '@aztec/foundation/serialize';
9
+ import { FunctionSelector, bufferFromFields } from '@aztec/stdlib/abi';
10
+ import type { ExecutablePrivateFunctionWithMembershipProof, PrivateFunction } from '@aztec/stdlib/contract';
11
+ import type { ContractClassLog } from '@aztec/stdlib/logs';
12
+
13
+ import { REGISTERER_PRIVATE_FUNCTION_BROADCASTED_TAG } from '../protocol_contract_data.js';
14
+
15
+ /** Event emitted from the ContractClassRegisterer. */
16
+ export class PrivateFunctionBroadcastedEvent {
17
+ constructor(
18
+ public readonly contractClassId: Fr,
19
+ public readonly artifactMetadataHash: Fr,
20
+ public readonly unconstrainedFunctionsArtifactTreeRoot: Fr,
21
+ public readonly privateFunctionTreeSiblingPath: Tuple<Fr, typeof FUNCTION_TREE_HEIGHT>,
22
+ public readonly privateFunctionTreeLeafIndex: number,
23
+ public readonly artifactFunctionTreeSiblingPath: Tuple<Fr, typeof ARTIFACT_FUNCTION_TREE_MAX_HEIGHT>,
24
+ public readonly artifactFunctionTreeLeafIndex: number,
25
+ public readonly privateFunction: BroadcastedPrivateFunction,
26
+ ) {}
27
+
28
+ static isPrivateFunctionBroadcastedEvent(log: ContractClassLog) {
29
+ return log.fields[0].equals(REGISTERER_PRIVATE_FUNCTION_BROADCASTED_TAG);
30
+ }
31
+
32
+ static fromLog(log: ContractClassLog) {
33
+ const reader = new FieldReader(log.fields.slice(1));
34
+ const event = PrivateFunctionBroadcastedEvent.fromFields(reader);
35
+ while (!reader.isFinished()) {
36
+ const field = reader.readField();
37
+ if (!field.isZero()) {
38
+ throw new Error(`Unexpected data after parsing PrivateFunctionBroadcastedEvent: ${field.toString()}`);
39
+ }
40
+ }
41
+
42
+ return event;
43
+ }
44
+
45
+ static fromFields(fields: Fr[] | FieldReader) {
46
+ const reader = FieldReader.asReader(fields);
47
+ const contractClassId = reader.readField();
48
+ const artifactMetadataHash = reader.readField();
49
+ const unconstrainedFunctionsArtifactTreeRoot = reader.readField();
50
+ const privateFunctionTreeSiblingPath = reader.readFieldArray(FUNCTION_TREE_HEIGHT);
51
+ const privateFunctionTreeLeafIndex = reader.readField().toNumber();
52
+ const artifactFunctionTreeSiblingPath = reader.readFieldArray(ARTIFACT_FUNCTION_TREE_MAX_HEIGHT);
53
+ const artifactFunctionTreeLeafIndex = reader.readField().toNumber();
54
+ const privateFunction = BroadcastedPrivateFunction.fromFields(reader);
55
+
56
+ return new PrivateFunctionBroadcastedEvent(
57
+ contractClassId,
58
+ artifactMetadataHash,
59
+ unconstrainedFunctionsArtifactTreeRoot,
60
+ privateFunctionTreeSiblingPath,
61
+ privateFunctionTreeLeafIndex,
62
+ artifactFunctionTreeSiblingPath,
63
+ artifactFunctionTreeLeafIndex,
64
+ privateFunction,
65
+ );
66
+ }
67
+
68
+ toFunctionWithMembershipProof(): ExecutablePrivateFunctionWithMembershipProof {
69
+ return {
70
+ ...this.privateFunction,
71
+ bytecode: this.privateFunction.bytecode,
72
+ functionMetadataHash: this.privateFunction.metadataHash,
73
+ artifactMetadataHash: this.artifactMetadataHash,
74
+ unconstrainedFunctionsArtifactTreeRoot: this.unconstrainedFunctionsArtifactTreeRoot,
75
+ privateFunctionTreeSiblingPath: this.privateFunctionTreeSiblingPath,
76
+ privateFunctionTreeLeafIndex: this.privateFunctionTreeLeafIndex,
77
+ artifactTreeSiblingPath: this.artifactFunctionTreeSiblingPath.filter(fr => !fr.isZero()),
78
+ artifactTreeLeafIndex: this.artifactFunctionTreeLeafIndex,
79
+ };
80
+ }
81
+ }
82
+
83
+ export class BroadcastedPrivateFunction implements PrivateFunction {
84
+ constructor(
85
+ /** Selector of the function. Calculated as the hash of the method name and parameters. The specification of this is not enforced by the protocol. */
86
+ public readonly selector: FunctionSelector,
87
+ /** Artifact metadata hash */
88
+ public readonly metadataHash: Fr,
89
+ /** Hash of the verification key associated to this private function. */
90
+ public readonly vkHash: Fr,
91
+ /** ACIR and Brillig bytecode */
92
+ public readonly bytecode: Buffer,
93
+ ) {}
94
+
95
+ static fromFields(fields: Fr[] | FieldReader) {
96
+ const reader = FieldReader.asReader(fields);
97
+ const selector = FunctionSelector.fromField(reader.readField());
98
+ const metadataHash = reader.readField();
99
+ const vkHash = reader.readField();
100
+ // The '* 1' removes the 'Type instantiation is excessively deep and possibly infinite. ts(2589)' err
101
+ const encodedBytecode = reader.readFieldArray(MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS * 1);
102
+ const bytecode = bufferFromFields(encodedBytecode);
103
+ return new BroadcastedPrivateFunction(selector, metadataHash, vkHash, bytecode);
104
+ }
105
+ }