Skip to content

Commit c338a5c

Browse files
committed
refactor: drop lib.lock.json and move auth-registry to @aztec/canonical-contracts
Drop `noir-projects/aztec-nr/canonical_addresses/lib.lock.json`. Its unique fields (`artifactHash`, `srcContentHash`) are now embedded in the `DO NOT EDIT` comment header of `lib.nr` instead. Update `renderNoirLib` to include both fields and update the cycle guard to extract the stamped address directly from `lib.nr` via grep/sed rather than jq. Create `yarn-project/canonical-contracts/` as a new package `@aztec/canonical- contracts` and move the entire auth-registry sub-package from `@aztec/protocol-contracts` into it. The auth-registry is not a protocol contract (it is deployed on first-use) so it belongs in a sibling package. Update all consumers of `@aztec/protocol-contracts/auth-registry` to import from `@aztec/canonical-contracts/auth-registry` instead.
1 parent 35f5ebb commit c338a5c

33 files changed

Lines changed: 245 additions & 91 deletions

File tree

noir-projects/aztec-nr/canonical_addresses/lib.lock.json

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
// GENERATED FILE - DO NOT EDIT
22
//
3-
// Written by `yarn-project/protocol-contracts/src/scripts/derive_auth_registry.ts` once
3+
// Written by `yarn-project/canonical-contracts/src/scripts/derive_auth_registry.ts` once
44
// `auth_registry_contract` has been compiled. Regenerate with
5-
// `yarn workspace @aztec/protocol-contracts run regen:auth-registry-address`.
5+
// `yarn workspace @aztec/canonical-contracts run regen:auth-registry-address`.
66
//
77
// Auth registry MUST NOT depend on this crate. The structural and bytecode-level cycle guard in
88
// `noir-projects/scripts/auth_registry_cycle_guard.sh` pins this invariant.
99
//
10-
// stampKey = 0x2f40338537369f28dd399693f5cd35b177935af02ece1f3c9024639ac840d1f0
10+
// artifactHash = 0x2f40338537369f28dd399693f5cd35b177935af02ece1f3c9024639ac840d1f0
11+
// srcContentHash = 0x4ea3348417959a4d18386572ff254539805f0ea5d786f96e7b66f06c947403ec
1112

1213
use protocol_types::{address::AztecAddress, traits::FromField};
1314

1415
pub global AUTH_REGISTRY_ADDRESS: AztecAddress = AztecAddress::from_field(
15-
0x27225abf9a79bc1c9279c82591f5e19d0b861cffcff33ac21d9f89ce14004ff1,
16+
0x1f7f0c3d878160356b2025b056a7a390ab34bd17f2ba4320ffb4a71698d5bf3a,
1617
);

noir-projects/scripts/auth_registry_cycle_guard.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set -euo pipefail
1515
ROOT="$(git rev-parse --show-toplevel)"
1616
NARGO_TOML="$ROOT/noir-projects/noir-contracts/contracts/canonical/auth_registry_contract/Nargo.toml"
1717
ARTIFACT="$ROOT/noir-projects/noir-contracts/target/auth_registry_contract-AuthRegistry.json"
18-
LOCK="$ROOT/noir-projects/aztec-nr/canonical_addresses/lib.lock.json"
18+
LIB_NR="$ROOT/noir-projects/aztec-nr/canonical_addresses/src/lib.nr"
1919

2020
if grep -q '^canonical_addresses[[:space:]]*=' "$NARGO_TOML"; then
2121
echo "auth registry must not depend on its own address; use the private authwit path or move logic to a non-protocol helper." >&2
@@ -27,13 +27,13 @@ if [ ! -f "$ARTIFACT" ]; then
2727
exit 1
2828
fi
2929

30-
if [ ! -f "$LOCK" ]; then
31-
echo "canonical_addresses lib.lock.json not found at $LOCK — run \`yarn workspace @aztec/protocol-contracts run regen:auth-registry-address\` from yarn-project/." >&2
30+
if [ ! -f "$LIB_NR" ]; then
31+
echo "canonical_addresses lib.nr not found at $LIB_NR — run \`yarn workspace @aztec/canonical-contracts run regen:auth-registry-address\` from yarn-project/." >&2
3232
exit 1
3333
fi
3434

35-
stamped_address=$(jq -r '.address' "$LOCK")
36-
if [ -z "$stamped_address" ] || [ "$stamped_address" = "null" ] || [ "$stamped_address" = "0x0" ]; then
35+
stamped_address=$(grep -A1 'from_field' "$LIB_NR" | grep -o '0x[0-9a-fA-F]*')
36+
if [ -z "$stamped_address" ] || [ "$stamped_address" = "0x0" ]; then
3737
exit 0
3838
fi
3939

yarn-project/aztec.js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
]
9595
},
9696
"dependencies": {
97+
"@aztec/canonical-contracts": "workspace:^",
9798
"@aztec/constants": "workspace:^",
9899
"@aztec/entrypoints": "workspace:^",
99100
"@aztec/ethereum": "workspace:^",

yarn-project/aztec.js/src/utils/authwit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { AUTH_REGISTRY_ADDRESS } from '@aztec/canonical-contracts/auth-registry';
12
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
23
import { Fr } from '@aztec/foundation/curves/bn254';
3-
import { AUTH_REGISTRY_ADDRESS } from '@aztec/protocol-contracts/auth-registry';
44
import { type ABIParameterVisibility, type FunctionAbi, type FunctionCall, FunctionType } from '@aztec/stdlib/abi';
55
import { AuthWitness, computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
66
import type { AztecAddress } from '@aztec/stdlib/aztec-address';

yarn-project/aztec.js/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"tsBuildInfoFile": ".tsbuildinfo"
77
},
88
"references": [
9+
{
10+
"path": "../canonical-contracts"
11+
},
912
{
1013
"path": "../constants"
1114
},
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"name": "@aztec/canonical-contracts",
3+
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/canonical-contracts",
4+
"description": "Canonical non-protocol contracts for the Aztec Network",
5+
"version": "0.1.0",
6+
"type": "module",
7+
"exports": {
8+
".": "./dest/index.js",
9+
"./*": "./dest/*/index.js",
10+
"./*/lazy": "./dest/*/lazy.js"
11+
},
12+
"scripts": {
13+
"build": "yarn clean && yarn generate && ../scripts/tsc.sh",
14+
"generate": "yarn generate:data",
15+
"generate:data": "node --no-warnings --loader @swc-node/register/esm src/scripts/generate_data.ts",
16+
"regen:auth-registry-address": "node --experimental-vm-modules dest/scripts/derive_auth_registry.js",
17+
"build:dev": "../scripts/tsc.sh --watch",
18+
"build:ts": "../scripts/tsc.sh",
19+
"clean": "rm -rf ./dest .tsbuildinfo ./artifacts",
20+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
21+
},
22+
"inherits": [
23+
"../package.common.json",
24+
"./package.local.json"
25+
],
26+
"jest": {
27+
"moduleNameMapper": {
28+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
29+
},
30+
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
31+
"rootDir": "./src",
32+
"transform": {
33+
"^.+\\.tsx?$": [
34+
"@swc/jest",
35+
{
36+
"jsc": {
37+
"parser": {
38+
"syntax": "typescript",
39+
"decorators": true
40+
},
41+
"transform": {
42+
"decoratorVersion": "2022-03"
43+
}
44+
}
45+
}
46+
]
47+
},
48+
"extensionsToTreatAsEsm": [
49+
".ts"
50+
],
51+
"reporters": [
52+
"default"
53+
],
54+
"testTimeout": 120000,
55+
"setupFiles": [
56+
"../../foundation/src/jest/setup.mjs"
57+
],
58+
"testEnvironment": "../../foundation/src/jest/env.mjs",
59+
"setupFilesAfterEnv": [
60+
"../../foundation/src/jest/setupAfterEnv.mjs"
61+
]
62+
},
63+
"dependencies": {
64+
"@aztec/foundation": "workspace:^",
65+
"@aztec/protocol-contracts": "workspace:^",
66+
"@aztec/stdlib": "workspace:^",
67+
"tslib": "^2.4.0"
68+
},
69+
"devDependencies": {
70+
"@jest/globals": "^30.0.0",
71+
"@types/jest": "^30.0.0",
72+
"@types/node": "^22.15.17",
73+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
74+
"jest": "^30.0.0",
75+
"jest-mock-extended": "^4.0.0",
76+
"ts-loader": "^9.5.4",
77+
"ts-node": "^10.9.1",
78+
"typescript": "^5.3.3"
79+
},
80+
"files": [
81+
"dest",
82+
"src",
83+
"!*.test.*",
84+
"artifacts",
85+
"!src/scripts/*"
86+
],
87+
"engines": {
88+
"node": ">=20.10"
89+
}
90+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"scripts": {
3+
"build": "yarn clean && yarn generate && ../scripts/tsc.sh",
4+
"build:dev": "../scripts/tsc.sh --watch",
5+
"clean": "rm -rf ./dest .tsbuildinfo ./artifacts"
6+
},
7+
"files": ["dest", "src", "artifacts", "!*.test.*"]
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// GENERATED FILE - DO NOT EDIT.
2+
// Written by `yarn-project/canonical-contracts/src/scripts/derive_auth_registry.ts`.
3+
import { Fr } from '@aztec/foundation/curves/bn254';
4+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
5+
6+
export const AUTH_REGISTRY_ADDRESS: AztecAddress = AztecAddress.fromString(
7+
'0x1f7f0c3d878160356b2025b056a7a390ab34bd17f2ba4320ffb4a71698d5bf3a',
8+
);
9+
export const AUTH_REGISTRY_CLASS_ID: Fr = Fr.fromString(
10+
'0x22586102100c4e25fea653d1edc4f3ef903e431ebc7725f70dafaea28a74e8a7',
11+
);

yarn-project/protocol-contracts/src/auth-registry/derive_auth_registry.test.ts renamed to yarn-project/canonical-contracts/src/auth-registry/derive_auth_registry.test.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ import {
88
ARTIFACT_PATH,
99
type AuthRegistryStamp,
1010
NR_LIB_PATH,
11-
NR_LOCK_PATH,
1211
TS_TWIN_PATH,
1312
deriveAuthRegistryStamp,
1413
hashAuthRegistrySources,
15-
renderLockJson,
1614
renderNoirLib,
1715
renderTsTwin,
1816
} from './derive_auth_registry.js';
1917

2018
const REGEN_HINT =
21-
'auth_registry stamp is stale; run `yarn workspace @aztec/protocol-contracts run regen:auth-registry-address` and commit the result.';
19+
'auth_registry stamp is stale; run `yarn workspace @aztec/canonical-contracts run regen:auth-registry-address` and commit the result.';
2220

2321
describe('derive_auth_registry renderers', () => {
2422
const stamp: AuthRegistryStamp = {
@@ -32,10 +30,6 @@ describe('derive_auth_registry renderers', () => {
3230
expect(renderNoirLib(stamp)).toEqual(renderNoirLib(stamp));
3331
});
3432

35-
it('renders byte-identical lock JSON for the same stamp (determinism)', () => {
36-
expect(renderLockJson(stamp)).toEqual(renderLockJson(stamp));
37-
});
38-
3933
it('renders byte-identical TS twin for the same stamp (determinism)', () => {
4034
expect(renderTsTwin(stamp)).toEqual(renderTsTwin(stamp));
4135
});
@@ -47,11 +41,10 @@ describe('derive_auth_registry renderers', () => {
4741
expect(lib).not.toContain('AUTH_REGISTRY_CLASS_ID');
4842
});
4943

50-
it('embeds srcContentHash in the lock JSON for the freshness gate', () => {
51-
const lock = JSON.parse(renderLockJson(stamp));
52-
expect(lock.srcContentHash).toEqual(stamp.srcContentHash);
53-
expect(lock.address).toEqual(stamp.address.toString());
54-
expect(lock.classId).toEqual(stamp.classId.toString());
44+
it('embeds artifactHash and srcContentHash in the Noir lib header', () => {
45+
const lib = renderNoirLib(stamp);
46+
expect(lib).toContain(stamp.artifactHash.toString());
47+
expect(lib).toContain(stamp.srcContentHash);
5548
});
5649

5750
it('TS twin parses as expected exports', () => {
@@ -72,7 +65,7 @@ describe('auth_registry stamp freshness', () => {
7265
.catch(() => false);
7366
});
7467

75-
it('on-disk lib.nr / lib.lock.json / address.gen.ts match the freshly-derived stamp', async () => {
68+
it('on-disk lib.nr / address.gen.ts match the freshly-derived stamp', async () => {
7669
if (!artifactExists) {
7770
// Artifact is produced by `./bootstrap.sh build` (or `nargo compile` +
7871
// `bb aztec_process` for the noir-contracts package). Skip with a clear
@@ -87,16 +80,14 @@ describe('auth_registry stamp freshness', () => {
8780
const stamp = await deriveAuthRegistryStamp(artifact, srcContentHash);
8881

8982
const expectedLib = renderNoirLib(stamp);
90-
const expectedLock = renderLockJson(stamp);
9183
const expectedTs = renderTsTwin(stamp);
9284

93-
const [actualLib, actualLock, actualTs] = await Promise.all([
85+
const [actualLib, actualTs] = await Promise.all([
9486
fs.readFile(NR_LIB_PATH, 'utf8'),
95-
fs.readFile(NR_LOCK_PATH, 'utf8'),
9687
fs.readFile(TS_TWIN_PATH, 'utf8'),
9788
]);
9889

99-
if (actualLib !== expectedLib || actualLock !== expectedLock || actualTs !== expectedTs) {
90+
if (actualLib !== expectedLib || actualTs !== expectedTs) {
10091
throw new Error(REGEN_HINT);
10192
}
10293
});

0 commit comments

Comments
 (0)