Skip to content

feat(auth_registry): demote to non-protocol contract via two-pass build#23106

Open
dbanks12 wants to merge 2 commits intonextfrom
cb/e468a77822a0
Open

feat(auth_registry): demote to non-protocol contract via two-pass build#23106
dbanks12 wants to merge 2 commits intonextfrom
cb/e468a77822a0

Conversation

@dbanks12
Copy link
Copy Markdown
Contributor

@dbanks12 dbanks12 commented May 8, 2026

Summary

  • Introduces noir-projects/aztec-nr/auth_registry_address/ as the dependency-cut crate every consumer of the auth_registry address imports from. Today it aliases the magic slot-1 protocol-contract address; the follow-up demotion PR overwrites it with the artifact-derived address via yarn-project/protocol-contracts/src/scripts/derive_auth_registry.ts.
  • Migrates the 4 Noir consumers (aztec-nr/aztec/src/authwit/auth.nr, aztec-nr/aztec/src/test/helpers/authwit.nr, aztec_sublib/src/authwit/auth.nr, avm_test_contract/src/main.nr) and their Nargo.toml deps to use the new crate. auth_registry_contract itself MUST NOT depend on the new crate; the structural + bytecode-level cycle guard at noir-projects/scripts/auth_registry_cycle_guard.sh pins that invariant.
  • Carries derive_auth_registry.ts (Noir + TS twin renderer + lib.lock.json writer with srcContentHash for the freshness gate) and a unit test for its determinism. Not yet wired into bootstrap — calling it from noir-projects/ requires @aztec/foundation/@aztec/stdlib to already be built, which violates the existing barretenberg → noir → l1-contracts → yarn-project build order. That wiring is the follow-up.

Why scoped down from the original design

Final design lives at https://gist.github.com/dbanks12/149a8f296e8c141a8d19ff20c5ea9f45 (Category C: tree-shaken-leaf two-pass build). The first attempt (commit d983ec7, reverted in 91c7205) implemented the full design: split bootstrap.sh into phase1 → stamp → phase2, dropped auth_registry_contract from protocol_contracts.json + the CANONICAL_AUTH_REGISTRY_ADDRESS constant, and migrated every TS-side consumer.

CI failed (https://github.com/AztecProtocol/aztec-packages/actions/runs/25572154854/job/75070294420) because bootstrap.sh's new stamp step shells out to yarn generate:auth-registry-address from inside noir-projects/ — but yarn-project hasn't been built yet at that point. The clean fix is to either (a) move stamp logic into a dependency-free Noir-projects-side script or (b) restructure the build pipeline so a minimal @aztec/foundation+@aztec/stdlib slice builds before noir-projects/. Both are bigger changes than what fits in this PR; this PR sets up the dependency-cut crate so the follow-up can land cleanly.

Test plan

  • Stamp determinism unit test (yarn-project/protocol-contracts/src/auth-registry/derive_auth_registry.test.ts).
  • Cycle-guard CI script (noir-projects/scripts/auth_registry_cycle_guard.sh) — structural + bytecode invariant.
  • Functional regression: AUTH_REGISTRY_ADDRESS still resolves to slot 1, so e2e_authwit* and every consumer is bytecode-identical to base modulo the import path.

Risks

  • None for runtime behaviour — AUTH_REGISTRY_ADDRESS is unchanged at slot 1 and the protocol-contracts roster is unchanged.
  • auth_registry_address participates in every consumer's cache_content_hash (via aztec-nr/), so a comment-only edit to that crate's lib.nr triggers a wider rebuild than before. Expected once stamping is wired up; flagging now.
  • Cycle-guard depends on tree-shaking. If a future Noir compiler emits bytecode for unused public functions, the guard would fire on every CI run; the fallback is a private/public split of aztec-nr/authwit.

Cuts the apparent build cycle ("every consumer needs the address; the
address depends on the artifact") with a new
`noir-projects/aztec-nr/auth_registry_address/` crate sitting downstream
of `auth_registry_contract` but upstream of every consumer. The cut
works because auth_registry only calls the private-path authwit helpers
and the public-path wrappers (which inline the address) get tree-shaken
out of its bytecode. The cycle-guard CI script enforces both halves of
that invariant.

Splits `noir-projects/noir-contracts/bootstrap.sh build` into
phase 1 (compile auth_registry) -> stamp (TS script writes lib.nr +
lib.lock.json + TS twin from the artifact) -> phase 2 (compile
everything else); a source-content-hash freshness gate fronts every
partial build and exits with the regen instruction on drift.

Drops `auth_registry_contract` from `protocol_contracts.json`,
`CANONICAL_AUTH_REGISTRY_ADDRESS` from `constants.nr`, the matching
CPP/PIL whitelist entries, and the `AuthRegistry` slot in
`generate_data.ts`. Slot 1 in the protocol-contracts roster stays
vacant (`AztecAddress::zero()`); `MAX_PROTOCOL_CONTRACTS` stays at 11.
@dbanks12 dbanks12 changed the title feat(auth_registry): demote to non-protocol contract via two-pass build [messing around...] feat(auth_registry): demote to non-protocol contract via two-pass build May 8, 2026
@dbanks12 dbanks12 marked this pull request as ready for review May 8, 2026 18:21
@dbanks12 dbanks12 removed request for LeilaWang and nventuro May 8, 2026 18:21
@dbanks12 dbanks12 changed the title [messing around...] feat(auth_registry): demote to non-protocol contract via two-pass build [messing around... for ci] feat(auth_registry): demote to non-protocol contract via two-pass build May 8, 2026
@dbanks12 dbanks12 changed the title [messing around... for ci] feat(auth_registry): demote to non-protocol contract via two-pass build feat(auth_registry): demote to non-protocol contract via two-pass build May 8, 2026
Reverts the protocol-contracts roster removal, the bootstrap.sh phase
split, and the cascade of TS-side rewrites that depended on them. The
build-pipeline ordering (noir-projects builds before yarn-project)
means a stamp script that depends on @aztec/foundation/@aztec/stdlib
cannot run during noir-projects bootstrap; that's a structural change
to make in a follow-up alongside the actual demotion.

Keeps the structural Noir-side cut: the new
`noir-projects/aztec-nr/auth_registry_address/` crate (alias for the
slot-1 magic address while auth_registry remains a protocol contract),
4 Noir consumer migrations to import from it, the cycle-guard CI
script, and the stamp-script + tests as utilities for the follow-up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant