Skip to content

Noir circuit: Withdraw #705

Closed
Closed

Description

@brozorec

Context

The Withdraw circuit proves that an owner has sufficient confidential balance to withdraw a public amount a, computes the new spendable commitment with deterministic randomness, emits an encrypted balance scalar for owner recovery, and produces a sender-auditor ECDH ciphertext for the new balance checkpoint. See internal design doc §7.5.

Scope

Implement circuits/withdraw/ covering the constraints in design doc §7.5:

  • W1–W8: owner key ownership, wrapper binding via vk, opening knowledge, range validity v, a, v − a ∈ [0, 2^127), deterministic new-balance randomness, new commitment construction, encrypted balance scalar, nonzero ephemeral scalar (r_e ≠ 0).
  • W_a1–W_a4: ephemeral key for auditor ECDH, sender-auditor shared secret, sender-auditor channel sponge (single squeeze), encrypted balance checkpoint under the sender-auditor key.

Public inputs (15 fields): C_spend, C_spend', Y, wrap, K_aud_s, a, σ, b̃, R_e, b̃_aud_s.

Private witnesses: sk, vk, v, r, r_e.

Tests:

  • Happy path with various a values.
  • Negative: v < a (should fail W4), wrong vk derivation, mutated b̃, r_e = 0 (should fail W8).

Proposed Approach

  1. Wire in the primitives library (Noir primitives library for confidential token wrapper circuits #699) for Pedersen commit, Poseidon2-with-domain, range check, encrypted-balance helper, ECDH, key derivation.
  2. Write the circuit body following §7.5 constraint-by-constraint; each circuit line links to its constraint ID in a doc-comment.
  3. Generate fixture witness, prove, verify.
  4. Negative tests for each soundness-critical constraint (range, key derivation, encrypted balance consistency, nonzero r_e).

Known References

  • Internal design doc — §5.5 (encrypted balance scalar), §7.5 (Withdraw), §8 (Auditing). Link available in the tracking workspace.

Acceptance Criteria

  • Implementation matches parent epic's frozen public-input ordering
  • Constraints W1–W8 and W_a1–W_a4 covered by unit tests
  • Negative tests reject under-funded withdrawals and tampered ciphertexts
  • VK extracted and published per parent's VK pipeline
  • PR links back to this issue

Activity

  1. added this to the Release v0.8.0 milestone on May 19, 2026
  2. moved this from Todo to In Progress in Stellar Contractson May 22, 2026
  3. moved this from In Progress to Done in Stellar Contractson May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Small

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions