Repository navigation
feat(confidential): register circuit - #715
Conversation
`sort` is locale-sensitive: macOS (en_US) sorts case-insensitively, so `gadget_*` sorts before `Package`; Ubuntu CI (C locale) sorts by byte, so `P` (0x50) sorts before `g` (0x67). Same content, different order between local regen and CI -> spurious diff failure. Fix by pinning `LC_ALL=C` in both the CI step and the documented regen command, and regenerate `constraints.baseline` under the same setting so the file matches what CI computes.
The `typos` linter (default ruleset) flags `ba` as a likely misspelling of `by` / `be`. The identifier `s_ba` in the ECDH symmetry test triggers this, even though it's notation for "shared secret computed from b's side". Rename `s_ab` / `s_ba` to `s_a_b` / `s_b_a` -- underscore-split tokens dodge the substring match without losing the math symmetry.
- noir.yml: drop persisted GITHUB_TOKEN on the checkout step. The Noir job only reads source -- no push, no API calls -- so a compromised dependency in any later step can't exfiltrate the token. - Architecture.md: add `text` language to the directory-tree fence so markdownlint and renderers treat it as plain text. - gadgets/ecdh: document why the on-curve check is intentionally absent. Per design doc Section 7.1, point validation is the wrapper contract's responsibility, not the circuit's; adding the check in-gadget would inflate the constraint count and misrepresent production circuits' real cost.
Adds `assert_on_curve` (lenient, allows identity -- for commitments) and `assert_on_curve_non_identity` (strict -- for keys, per design doc Section 7.1 point 4) to the lib. The verifier itself doesn't check curve membership, so a missed validation at the contract layer would let the prover slip an off-curve point past every commitment / ECDH constraint -- proof still verifies, resulting state is malformed. In-circuit validation makes that soundness-bound. Cost is ~2 ACIR opcodes per point check (less than 1% overhead on the heaviest circuit), so there's no real tradeoff vs. the safety gain. - `lib/src/lib.nr`: two new helpers + 5 unit tests (positive G/H, identity-lenient, off-curve rejection, identity rejection in the strict variant). - `gadgets/ecdh`: now calls `assert_on_curve_non_identity` before `ecdh`, so the measured constraint count reflects what production circuits will pay (+2 ACIR opcodes vs. previous gadget). - `gadgets/assert_on_curve`: new gadget measuring the check in isolation. - `constraints.baseline`: regenerated. Contract-side validation (per Section 7.1) stays as a defense-in-depth layer and early-rejection ergonomic; this PR doesn't change that.
The lenient `assert_on_curve` accepted any (x, y, is_infinite=true) because the curve-equation constraint gated off (x, y) when is_infinite was set. A caller doing field-wise coordinate comparisons later could be tricked into accepting attacker-chosen values that present as "identity" but carry arbitrary x and y. Close the gap by also constraining x == 0 and y == 0 when is_infinite, matching the design doc's canonical identity encoding (Section 7.1 point 2). Cost: 2 mul gates; no gadget calls the lenient variant so the baseline is unaffected. Adds `on_curve_rejects_non_canonical_identity` test that exercises the attack vector directly. `assert_on_curve_non_identity` doesn't need this fix -- it already rejects is_infinite=true upfront.
`nargo` writes empty `Prover.toml` templates per-package on first run and a `target/` for compiled ACIR. Neither needs to be in the repo; add a `.gitignore` at the circuits workspace root and remove the seven templates that slipped in via the previous commit.
Implements design doc §7.2 constraints R1-R3 (spending key well-formedness, wrapper-bound viewing key derivation, public viewing key consistency) plus on-curve / non-identity validation on Y and PVK per §7.1 point 4. All crypto delegates to the primitives lib; the circuit body is three lib calls and five assertions. Six tests cover the happy path and the anti-poisoning negatives (tampered PVK, wrong wrap, off-curve Y, identity Y) per #703's soundness-critical regression coverage. 33 ACIR opcodes. Closes #704.
Adds scripts/extract_vks.sh (compiles each per-operation circuit and writes its UltraHonk VK to vks/<name>.vk via pinned bb 0.87.0), commits the register VK as the first artifact, and extends noir.yml to re-extract under the pinned toolchain and diff against the committed copies. Mirrors the constraints-baseline drift check: byte-identical or CI fails. Cross-cutting deliverable per #703; remaining circuits append to the CIRCUITS array as they land.
WalkthroughThis PR implements the Register Noir circuit and its supporting infrastructure. It adds the circuit package with configuration and constraint logic enforcing key derivation rules, documents the v0.8 public-input specification, defines comprehensive tests covering happy and rejection paths, extracts verification key artifacts, and integrates VK drift detection into CI to prevent artifact divergence. ChangesRegister Circuit and VK Infrastructure
Sequence DiagramsequenceDiagram
participant main as main()
participant scalar_mul as scalar_mul
participant vk_from_sk as vk_from_sk
participant pvk_from_vk as pvk_from_vk
main->>main: receive sk (private), Y.x/y, PVK.x/y, wrap (public)
main->>main: construct EmbeddedCurvePoint for Y and PVK
main->>main: assert_on_curve_non_identity(Y, PVK)
main->>scalar_mul: compute Y_derived = scalar_mul(sk, H)
scalar_mul-->>main: Y_derived
main->>main: assert Y.x == Y_derived.x AND Y.y == Y_derived.y
main->>vk_from_sk: compute vk = vk_from_sk(sk, wrap)
vk_from_sk-->>main: vk
main->>pvk_from_vk: compute pvk = pvk_from_vk(vk)
pvk_from_vk-->>main: pvk
main->>main: assert PVK.x == pvk.x AND PVK.y == pvk.y
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #715 +/- ##
=======================================
Coverage 96.31% 96.31%
=======================================
Files 60 60
Lines 6376 6376
=======================================
Hits 6141 6141
Misses 235 235 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bb's `bytes` output prefixes the field elements with header information that differs between macOS and Linux, so committing the binary VK and diffing in CI failed reproducibility. Switch to `--output_format fields` (JSON array of hex-encoded Fr elements) -- byte-identical across platforms and parseable by the verifier without round-tripping through bb's deserializer. Renames the artifact to `register.vk.json`.
Resolves conflicts with #712 (the lib PR that landed first). Takes main's reviewed version of the lib, gadgets, Architecture.md, testdata README, noir.yml, and Nargo.toml; re-applies register/, vks/, scripts/, BB pin + VK diff CI step on top. Moves register's tests to register/src/tests.nr to mirror the lib's new `mod tests;` convention. constraints.baseline regenerated; register's VK is byte-identical (lib changes were docs + constant renames, no computational behavior change).
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/noir.yml:
- Around line 54-59: Replace the live "install | bash" fetches with immutable
references: update the "Install bbup" step that currently curls
https://raw.githubusercontent.com/AztecProtocol/aztec-packages/master/.../install
to pin that URL to a specific commit SHA (or an immutable release asset) instead
of "master", and likewise update the noirup fetch (the curl to
https://raw.githubusercontent.com/noir-lang/noirup/main/.../install) to a
specific commit SHA or signed release; ensure both steps still pipe to bash (or
preferably download-verify-then-execute) but use the exact commit SHAs/releases
so the "Install bbup" and "noirup" installs are reproducible and supply-chain
safe.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8a92addd-3151-4b12-8ff3-0ce1ef8fdfaf
📒 Files selected for processing (10)
.github/workflows/noir.ymlpackages/tokens/src/confidential/circuits/Nargo.tomlpackages/tokens/src/confidential/circuits/PUBLIC_INPUTS.mdpackages/tokens/src/confidential/circuits/constraints.baselinepackages/tokens/src/confidential/circuits/register/Nargo.tomlpackages/tokens/src/confidential/circuits/register/src/main.nrpackages/tokens/src/confidential/circuits/register/src/tests.nrpackages/tokens/src/confidential/circuits/scripts/extract_vks.shpackages/tokens/src/confidential/circuits/vks/README.mdpackages/tokens/src/confidential/circuits/vks/register.vk.json
The design doc adds two explicit non-zero scalar constraints to Register and retires in-circuit `assert_on_curve_non_identity` on Y and PVK: both points are bound to in-circuit `scalar_mul` outputs and are therefore on-curve by construction. The only remaining gap is the identity, which R4 and R5 close exactly. Drops the separate PUBLIC_INPUTS.md doc in favor of an inline doc block at the top of `main.nr` -- inline docs stay in lockstep with the code by construction; a separate doc just creates drift risk. VK regenerated; constraints baseline picks up a `directive_invert` Brillig opcode from the inverse-based `!= 0` checks.
Both install scripts were fetched from moving branches (noirup/main, aztec-packages/master) and piped to bash, so a silent upstream rewrite would have been executed by every CI run. Pin each URL to a specific commit and verify the script's SHA256 before exec; mismatch aborts. Bump the URL and the hash together when intentionally tracking new upstream.
Summary
Implements the Register circuit (
circuit_register) — the first of six per-operation circuits tracked by #703 — and seeds two cross-cutting deliverables that the remaining five sub-issues will reuse.Closes #704. Stacked on top of #703's primitives lib (base:
ct-noir-lib).Register circuit (design doc §7.2)
Y = sk · Hvk = Poseidon2(δ_vk, sk, wrap)PVK = vk · HPlus
assert_on_curve_non_identity(Y)andassert_on_curve_non_identity(PVK)per design doc §7.1 point 4 — the verifier doesn't check curve membership, so skipping it accepts a key for which ECDH collapses.Public inputs (frozen in
circuits/PUBLIC_INPUTS.md):Y.x, Y.y, PVK.x, PVK.y, wrap. Private witness:sk.Body is three lib calls and five assertions; all crypto delegates to
stellar_confidential_lib.Anti-poisoning tests (per #703)
Inline in
register/src/main.nr:matches_fixture— happy path against the canonicaltestdata/*.jsonvectors.rejects_tampered_pvk— PVK.x perturbed by +1.rejects_wrong_wrap— Y/PVK derived againstwrap=0xbeefbut proof supplies0xcafe.rejects_off_curve_y— Y = (1, 2).rejects_identity_y— Y = (0, 0).vk_intermediate_matches_lib— sanity check the fixture against the lib.Cross-cutting (per #703)
circuits/PUBLIC_INPUTS.md— frozen public-input ordering doc, seeded with Register's entry; sub-issues append theirs as they land. This is the integration contract with the verifier (Multi-VK UltraHonk verifier contract for confidential token wrapper #701), wrapper, and SDK.scripts/extract_vks.shcompiles each per-operation circuit and writes its UltraHonk VK tovks/<name>.vkusing pinnedbb 0.87.0. The committedvks/register.vk(1764 bytes) is byte-reproducible.noir.ymlre-runs the extraction and diffs against the committed copies; drift fails CI, mirroring the existingconstraints.baselinecheck.Caveat to flag
The verifier (#701) hasn't pinned the VK ingestion format yet.
bb write_vkemits raw bytes here; if #701 ends up wanting a different serialization (hex/JSON-wrapped), onlyextract_vks.shand the committed artifact need updating — the script is the source of truth, not the artifact format.Benchmarks (reference hardware: M-series laptop)
nargo executebb proveWell under the "single-digit seconds" target the overview UX section calls out.
Test plan
nargo checkclean on the workspacenargo test— all 6 Register tests pass + existing lib/gadget suites stay greennargo infoshowscircuit_register | main | 33 ACIR | 63 Brillig; matchesconstraints.baseline./scripts/extract_vks.shreproducesvks/register.vkbyte-identicallybb prove+bb verifyround-trip succeeds against the committed VKSummary by CodeRabbit
New Features
Documentation