Skip to content

feat(elgamal): ADR-0052 ElGamal on Jubjub + ADR-0053 threshold DKG — accepted designs and implementation - #76

Merged
satran004 merged 18 commits into
mainfrom
design/adr-0052-elgamal-jubjub
Oct 9, 2026
Merged

satran004 merged 18 commits into
mainfrom
design/adr-0052-elgamal-jubjub

Conversation

@satran004

@satran004 satran004 commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR carries two accepted designs and their full implementation, at the maintainer's request.

  • ADR-0052, exponential ElGamal on Jubjub (elgamal-jubjub-v1).
  • ADR-0053, threshold key generation and decryption (elgamal-jubjub-threshold-v1).
    • [GJKR07] New-DKG over Jubjub, admission from authenticated evidence, and t-of-n Lagrange decryption on ADR-0052's safe API.
    • Accepted at cc038a7.
    • Implemented: M0–M3, and M4 docs.

This is now an implementation PR, no longer docs-only: 72 files, about 20.6k insertions against main. Of that, 8,835 lines are the two independent Python references and their output. Experimental status. Secret operations are compatibility/offline class (ADR-0039), with no constant-time claim.

Milestones

Commit Milestone Main types Internal review
0f7d6e7 0052 M0 docs/specs/elgamal-jubjub-v1.md, Python reference approve
5985efb 0052 M1 ElGamal, key/ciphertext/statement types, FastJubjubPoint, JubjubDiscreteLog approve (P2s closed)
67a5ac6 0052 M2 InCircuitElGamal, ZkElGamal* one P1 fixed, then approve
972fc9f rename ElGamalPublicKey.affineU()/affineV() n/a
fb6fdf2 0053 M0 docs/specs/elgamal-jubjub-threshold-v1.md, Python reference (514 checks, 134 case vectors) 5 rounds, approve
644d207 0053 M1 ThresholdMath, ThresholdVss, Blake2bDigest approve
21b20ca 0053 M2 DkgConfig, DkgMessage, DkgRules, DkgParticipant, DkgTranscript, ThresholdKeyContext.admit two P1s fixed; rounds 3–5 hardened admission, then approve
43fb062 0053 M3 threshold decryptionShare, VerifiedDecryptionShare.verify(ct, id, …), combine approve
8a5078a M4 docs support matrix, READMEs, gadget guide, annotation guide, benchmark record n/a

Each milestone note on this PR gives details. The internal reviews were run by independent agents, and are not a substitute for this review.

Points needing a maintainer decision

  1. ADR-0053 Q1, the private channels. These stay out of scope here. The proposal is ADR-0054 (ADR-0054: encrypted DKG share delivery (HPKE RFC 9180) — resolve ADR-0053 Q1 #77): HPKE (RFC 9180), possibly with encrypted shares posted on the board, in a separate PR.

  2. ADR-0053 Q7, late SHAREs under partial synchrony (spec §5.2). Options:

    • (a) timely private delivery is a transport requirement (current);
    • (b) an honest dealer declines to answer;
    • (c) asynchronous DKG.

    Lean: (a). Board-posted encrypted shares under ADR-0054: encrypted DKG share delivery (HPKE RFC 9180) — resolve ADR-0053 Q1 #77 would largely remove the issue.

  3. Acknowledge the implementation notes. These are refinements of the accepted designs, each stated normatively in the specs:

    • ADR-0052 notes 1–6: local possession; locally computed shares; combinations stay admitted; the statement order; affine import; witness access.
    • ADR-0053 notes 1–9:
      • A8;
      • A7 at t + 1 differing, with an equivocator counting as differing;
      • R5 evaluates every complaint;
      • the §5.2 delivery precondition;
      • abort hygiene and A9;
      • shares only from QUAL;
      • a misplaced SHARE/CONFIRMATION in a transcript is refused;
      • roster keys distinct (as bytes);
      • per-window delivery (early posts dropped).
  4. Release gating. If ADR-0054: encrypted DKG share delivery (HPKE RFC 9180) — resolve ADR-0053 Q1 #77 posts encrypted shares on the board or commits encryption keys into the session, the threshold profile's round-1 messages or session would change. Lean: merge this PR, but don't ship elgamal-jubjub-threshold-v1 in a release until ADR-0054 settles that. elgamal-jubjub-v1 is unaffected.

  5. ADR-0052 M3 entry gate. The usecase migration ran against a local snapshot (0.1.0-pre13-8a5078a-SNAPSHOT), not a release. That deviation was the maintainer's choice.

Review guidance

Please number implementation findings from F9 on. The design reviews used F1–F8. The R* and N* IDs in the ADRs' implementation notes come from the internal reviews and the reference.

Suggested focus:

  • Spec ↔ code. Check elgamal-jubjub-v1 §3–§9 and elgamal-jubjub-threshold-v1 §1–§9 against org.zeroj.circuit.lib.jubjub and org.zeroj.circuit.lib.zk.
  • Trust boundaries.
    • Decode and subgroup checks.
    • Ciphertexts enter the safe layer only through encrypt/admit.
    • Shares are accepted only as VerifiedDecryptionShare.
    • Every DLEQ coordinate is a required public input.
    • Admission is library-computed (ThresholdKeyContext.admit): steps 2–6, round-7 closure, and the t + 1 counting rules.
  • Circuits. InCircuitElGamal: one k decomposition drives both scalar multiplications; keys are bound to their circuit; width ≤ 64; randomness must be 252 bits.
  • Secrets. Every secret multiplication uses the blinded schedule. FastJubjubPoint is public data only. The BSGS timing leak is documented.
  • The DKG against [GJKR07] Fig. 2. Complaints, answers, QUAL, marks and reconstruction, plus the abort table A1–A9.

Test plan

  • ./gradlew build on 8a5078a: BUILD SUCCESSFUL.

  • Each milestone commit was tested in a clean worktree:

    Commit Jubjub tests Failures
    M0 361 0
    M1 369 0
    M2 407 0
    M3 551 0

    M3's integration test (AnnotatedElGamalTest, Groth16 end to end) also passes.

  • Independent references (written from the specs with no Java read; Java must match byte for byte):

    • src/test/resources/elgamal-reference/;
    • src/test/resources/elgamal-threshold-reference/: 514 checks, and all 134 case.* vectors replay in Java.
    • Regenerating each reference reproduces its checked-in output byte for byte.
  • Differential checks: FastJubjubPoint vs JubjubPoint; host vs circuit; Java vs Python; library vs the usecase prototype's vectors.

  • Usecases on DevKit (zeroj-usecases#8 7ad844f): private-voting E2E tallies YES=2, NO=1; the pedersen-commitments E2E (3 tests) passes.

  • Reviewer: the focus points above.

🤖 Generated with Claude Code

Moves the generic part of zeroj-usecases' private-ballot ElGamal into a
ZeroJ profile: elgamal-jubjub-v1 (CGS97 §2.5 lifted ElGamal over the
Jubjub subgroup), a validated host API with plaintext bounds, typed
in-circuit relations (encryption with one shared decomposition of k;
DLEQ for key possession and decryption shares), n-of-n key aggregation
with proof of possession enforced by type, and compatibility/offline
labelling of secret-bearing host operations (ADR-0039). The Chaum-Pedersen
Σ-protocol path is escalated: the CFRG draft has no Jubjub ciphersuite.

Docs only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Verdict: CHANGES REQUESTED

Review of ADR-0052 at 9fe1c11fd444c18884551eb16be746cbe26531a7, following adr-pr-reviewer (round 1).

The lifted-ElGamal equations, shared scalar decomposition, explicit key provenance in the circuit, and decision to defer a new Jubjub sigma ciphersuite are a sound direction. I independently reproduced the reference vectors and the quoted DLEQ/ballot constraint counts. The remaining issues concern the guarantees of the proposed general-purpose API: integer bounds at admission, verification of decryption shares, common-key context, and proof migration. These are design findings; there is no ElGamal implementation in this PR.

F1 [P1] Establish the plaintext bound at every admission boundary

Location: docs/adr/0052-exponential-elgamal-jubjub.md, D1–D3 lines 165–178, 195–202, 214–221; D7 lines 300–303; I6/I7/I10 and M1/M2.

Problem: The message is only width-bounded, with no admitted-width rule ensuring 2^w - 1 < l; the < l bound rejection is specified for homomorphic results only. Separately, the 64-byte decoder establishes point validity, not the claimed plaintext range. The ADR does not say how a decoded ciphertext acquires a trustworthy bound. Carrying a caller-provided number in a record cannot establish I7, and a successful small discrete log does not detect prior modular wraparound. ADR-0051 D3a already requires range evidence for every externally supplied term before interpreting the result as an integer.

Evidence: l < 2^252. A temporary circuit using D3's stated equations, message decomposition, and shared guarded randomness accepted both m=0 and m=l for the same public ciphertext, with k=7, PK=3G. Independently, importing Enc(l-1;7,3G) and Enc(1;11,3G) with claimed bounds 1 each yields a subgroup-valid sum that decrypts to 0 within bound 2, although the integer sum was l. Neither canonical point decoding nor the search detects the false range claim.

Requested revision: Specify nonnegative message and bound admission rules for fresh ciphertexts, imported ciphertexts, and circuits—not just add/scale. Require an initial maximum below l (or an explicit canonical message bound and corresponding circuit constraint). Distinguish raw decoded points from ciphertexts whose bound is established by trusted local encryption or verification of the D3 range/encryption statement for the exact ciphertext; document any delegated verifier obligation explicitly. This does not require inventing an out-of-circuit range proof. Update I6/I7/I10, M1/M2 and the negatives to cover width 252 with m=l, bound relabelling after serialization, and wrapped imported terms. Keep the full 252-bit randomness rule; this finding concerns message bounds.

F2 [P1] Make share verification a prerequisite of distributed decryption

Location: D1 lines 179–183; D2 lines 200–202; D3/D4; I10; M1/M2.

Problem: Claimed shares are explicitly untrusted, but combine(ciphertext, shares) has no specified admission contract requiring verified DLEQ proofs, one share per registered trustee, and binding to the exact aggregate handle and trustee key. D3 provides a relation; that alone does not make the host combiner use it. The statement that the bounded search fails closed is insufficient for malicious shares.

Evidence: For distinct trustee keys 3G and 5G, encrypt m=1, k=7 under their joint key 8G: A=7G, B=57G. The honest share is D1=21G; the second trustee can publish D2=36G instead of 35G. All points are canonical subgroup points, yet B-D1-D2=O, and the bounded search returns 0 in [0,1]. More generally, after seeing the other shares an attacker sets D_bad=B-[t]G-sum(D_honest) for a chosen in-range t. The temporary independent-reference probe reproduced this. CGS97 §2.3 verifies the authorities' proofs before combining their shares.

Requested revision: Specify either a verified-share type/callback boundary analogous to VerifiedKeyShare, or an explicitly low-level unchecked operation with a separately specified safe combiner. The safe path must verify the exact (X=A_aggregate, P=registered PK_j, D=D_j) statement with trusted verification material, require complete and unique coverage of the n-of-n key set, and reject missing, repeated, foreign-key, wrong-handle and invalid-proof shares. State the subgroup-validation boundary for the handle before any secret multiplication. Add these conditions to the invariants and milestone tests, including the forged in-range tally above. Application deadlines and authorization can remain out of scope.

F3 [P2] Bind ciphertext operations to one encryption key

Location: D1 lines 171–175; D2 lines 195–202; D5; D7.

Problem: The homomorphic identities require the same public key, but the ciphertext record contains only (A,B,bound). Neither the arithmetic nor the imported-ciphertext contract states or enforces a common-key association. Validating each key independently does not establish this relationship.

Evidence: The independent probe gives Enc(1;1,3G)=(G,4G) and Enc(1;1,2G)=(G,3G). Addition produces (2G,7G), with bound 2. Decryption under secret 3 returns 1, inside that bound, although the two messages sum to 2. Thus mixing keys need not merely cause a search failure.

Requested revision: Carry validated key context through encryption, verified import, aggregation and decryption, and reject mixed contexts on the safe path. Specify how the context is restored alongside the 64-byte encoding and how it is tied to verified ciphertext admission; an unauthenticated key label alone is insufficient. If raw algebra is also exposed, state its common-key precondition and conditional guarantees explicitly. Add a mixed-key rejection test using the example above.

F4 [P2] Separate ciphertext compatibility from SNARK proof/key compatibility

Location: Compatibility lines 358–360; M3 line 369.

Problem: Unchanged encodings and public-input order are insufficient to preserve old Groth16 proofs under a newly compiled verifier. Proofs and setup keys are tied to the actual compiled constraint system and wire assignment. A typed-adapter migration or added validation rows may change those even while implementing the same mathematical relation. The current compatibility statement conditions proof validity only on D7.

Evidence: The pinned usecase compiles to 6,546 rows for DLEQ and 8,022/9,486 rows for the depth-4/depth-10 ballots; these counts were reproduced against this PR head. D3/M2 introduce new entry points and validation requirements, but M3 has no explicit compiled-artifact/setup compatibility decision. Even equal row counts would not establish equal matrices or verification keys.

Requested revision: Promise ciphertext compatibility separately. Make old-proof acceptance conditional on demonstrated compiled-system and verification-key compatibility, with archived proof fixtures exercised at the actual verifier boundary. Otherwise require new setup artifacts/circuit versions and describe retaining the old verifier for existing proofs/state, including any on-chain script migration. Do not present fresh prove/verify success as evidence that old proofs remain valid.

Things to retain

  • I5's single shared decomposition and the inherited secrecy/width guard rails. Noncanonical k >= l is harmless for the stated subgroup equations; it does not justify noncanonical integer messages.
  • The verifier-fixed-public-key versus subgroup-checked-witness distinction, with nonidentity required in both paths.
  • Proof-of-possession admission, distinct shares and nonidentity aggregate keys; the caller-supplied proof verifier remains a trust boundary.
  • Q3: using one generator for key and message is acceptable for IND-CPA under the stated DDH assumption. My reasoning is that replacing [k]PK by a uniform subgroup point in the DDH hybrid hides [m]G regardless of whether the message base equals the key base. This is not the two-independent-base requirement of a binding Pedersen commitment.
  • D4's explicit escalation. The pinned sigma-protocols-03 §8 lists P-256 and BLS12-381, with no Jubjub suite; fiat-shamir-03 §9 uses SHAKE/TurboSHAKE.
  • Experimental/offline classification, external review gates, production setup requirements, and separation of proof validity from application authorization.

Validation and scope

Reviewed in a detached temporary worktree at the SHA above. The base-to-head diff adds only this 439-line ADR; implementation sources are unchanged.

Executed:

./gradlew :zeroj-circuit-lib:test \
  --tests '*JubjubPointTest' --tests '*JubjubCurveParametersTest' \
  --tests '*InCircuitJubjubTest' --tests '*InCircuitJubjubSubgroupTest' \
  --tests '*JubjubBitDecompositionOwnershipTest' --tests '*WindowedFixedBaseTest' \
  --tests '*PedersenReferenceVectorsTest' --tests '*PedersenHidingSafeApiTest' \
  --tests '*PedersenHomomorphicApiTest' --tests '*ZkJubjubPointSafetyTest'
python3 /tmp/zeroj-pr76-evidence/probe.py
java --class-path 'zeroj-api/build/classes/java/main:zeroj-circuit-dsl/build/classes/java/main:zeroj-circuit-lib/build/classes/java/main:zeroj-circuit-annotation-api/build/classes/java/main' /tmp/zeroj-pr76-evidence/WidthProbe.java
javac -proc:none -d /tmp/zeroj-pr76-evidence/classes -cp 'zeroj-api/build/classes/java/main:zeroj-circuit-dsl/build/classes/java/main:zeroj-circuit-lib/build/classes/java/main:zeroj-circuit-annotation-api/build/classes/java/main' /tmp/zeroj-pr76-evidence/CostProbe.java /tmp/zeroj-pr76-evidence/JubjubElGamalGadget.java /tmp/zeroj-pr76-evidence/PrivateBallotProof.java /tmp/zeroj-pr76-evidence/TrusteeShareProof.java
java -cp '/tmp/zeroj-pr76-evidence/classes:zeroj-api/build/classes/java/main:zeroj-circuit-dsl/build/classes/java/main:zeroj-circuit-lib/build/classes/java/main:zeroj-circuit-annotation-api/build/classes/java/main' com.bloxbean.cardano.zeroj.usecases.voting.circuit.CostProbe

Results: 141 tests, 0 failures, 0 errors, 0 skipped. The temporary probes reproduced the counterexamples above; the Java alias probe calculates satisfying witnesses, not Groth16 proofs. The independent Python reference from zeroj-usecases@20a16a8 reproduced all 35 fixture lines exactly. A temporary harness calling the pinned usecase circuit bodies reproduced 6,546 / 8,022 / 9,486 constraints. These probes are not an implementation of the proposed API.

References re-fetched: CGS97 authors' copy, ePrint 2007/264, both CFRG -03 drafts, ZIP 216, and Zcash protocol build v2026.7.0-236-ga735ca (Jubjub parameters); checked alongside ADR-0037/0038/0039/0051 and the local Pedersen specification. The original ElGamal/Chaum–Pedersen papers remain directly unverified as the ADR says. The Plutus CPU/memory measurement and DevKit runs were not rerun. No implementation files were changed by this review.

Acceptance of this ADR would be design acceptance only. It would not certify the implementation, its tests, or its security. Q1–Q5 remain maintainer decisions, with the technical assessment of Q3 above.

F1: ciphertext admission establishes plaintext bounds (local encryption
or a verified D3 statement for the exact ciphertext/key/width); message
width capped at 64 bits (the m = l alias at width 252); decoding yields
unbounded raw ciphertexts. F2: decryption only with verified shares bound
to the exact handle and a registered trustee, complete and unique.
F3: every safe-layer ciphertext carries its key context; mixed contexts
refused. F4: ciphertext compatibility promised separately from
proof/verification-key compatibility; M3 records a compiled-system gate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Author reply: round r2 · head f1007ff

r2 is pushed as f1007ff. It changes docs/adr/0052-exponential-elgamal-jubjub.md only; no implementation files.

I reproduced every counterexample independently before accepting the findings. The probe is a standalone Python Jubjub implementation written from the curve definition (d = −10240/10241, G = [8](u₀, 11)), not the ZeroJ code:

l < 2^252: True   2^251 < l: True
F1a alias m=0 vs m=l: True
F1b wrapped sum decrypts to: 0 (integer sum was l)
F2 honest decrypts: 1   forged decrypts: 0
F3 mixed-key sum under sk=3: 1 (messages sum to 2)
Finding Change in r2 Where
F1 [P1] Plaintext bound at every admission boundary Accepted. Message width: capped at 1 ≤ w ≤ 64 (MAX_MESSAGE_BITS), so every admitted message is canonical (2^64 − 1 < l). In circuits, a wider declaration is refused when the circuit is defined, which closes the m = 0 / m = l alias at width 252. Admission: new D2a. A bound is established only by local encrypt, or by admit(raw, context, width, verifier) checking the D3 encryption statement for exactly this ciphertext, key and width; that is an explicit delegated verifier obligation, with the on-chain validator case described. Raw ciphertexts: decoding yields a RawElGamalCiphertext with no bound and no key, which cannot be added or decrypted on the safe path. No constructor accepts a claimed bound. Randomness: the 252-bit rule is unchanged. Tests: M1 and M2 negatives cover m = l, relabelling after serialization, and the wrapped terms Enc(l−1) + Enc(1). D1, D2, D2a, D3, D7, I6, I7, I10, I16, M1, M2, Verification, Risks
F2 [P1] Share verification before distributed decryption Accepted. New D2b. VerifiedDecryptionShare.verify(ciphertext, trusteeShare, D, proof, verifier) is the only constructor. It checks DLEQ with X = the admitted ciphertext's handle (never taken from the sender) and P = the registered key share. decrypt(ciphertext, verifiedShares, max) requires complete, unique coverage of the registered trustees, and refuses missing, repeated, foreign or wrong-handle shares. D5's aggregation now returns an ElGamalKeyContext holding the registered share set. Subgroup boundary: I15 makes secret multiplication run only on a validated subgroup handle, so sk_j mod 8 cannot leak. The unchecked unmask lives only on the raw layer, documented as giving no guarantee. Tests: M1 negatives include your forged in-range share (D2 = 36G). D1, D2, D2b, D5, I10, I14, I15, M1, Risks
F3 [P2] One encryption key per operation Accepted. New D2c. Every safe-layer ciphertext carries its ElGamalKeyContext. add, scale and decrypt refuse mixed contexts. The 64-byte encoding carries no key (D7). A decoded ciphertext gets its context only through admission, and the verified D3 statement includes the key as public inputs, so a bare label is never trusted. Raw-layer arithmetic states its one-key precondition. Test: an M1 negative uses your Enc(1;1,3G) + Enc(1;1,2G) example. D1, D2, D2c, D7, I13, M1
F4 [P2] Ciphertext versus proof and key compatibility Accepted. Compatibility is rewritten. Ciphertext compatibility is promised, with a differential test. Proof and verification-key compatibility is not promised. Old proofs are accepted under a new verifier only with evidence of an identical compiled system (an R1CS digest over every row's terms) and archived proofs verifying at the real verifier boundary. Otherwise migration means a new circuit version, setup and scripts, and existing state (an election under way) keeps the old circuit, keys and scripts. M3 records this decision. A fresh prove-and-verify round-trip is explicitly not evidence. Compatibility, M3, Verification

Retained, as you asked:

  • I5's single decomposition and the guard rails;
  • the two ways a key enters a circuit, with non-identity required in both;
  • proof-of-possession admission;
  • D4's escalation;
  • the offline classification and gates.

Q3: your DDH-hybrid assessment is recorded in the ADR. It remains a maintainer decision.

Escalated to the maintainer (unchanged): Q1–Q5. Q2 now applies the type-or-documentation choice to admitted ciphertexts and decryption shares as well as to key shares.

The revision history lists r1–r2. Over to you for round 2.

@satran004

Copy link
Copy Markdown
Member Author

Verdict: CHANGES REQUESTED

Round 2 review of f1007ff8adcf39616b9f14cbacab7a719326fb15, diffed from 9fe1c11fd444c18884551eb16be746cbe26531a7.

The revision closes the two P1 findings and the proof-migration issue. One narrow completion of F3 remains in the newly explicit single-key decryption API.

Finding Status Notes
F1 [P1] Resolved D1/D3 cap fresh message widths at 64 bits; D2a separates canonical raw decoding from verified range/key admission. D7, I6/I7/I16, M1/M2, verification and risks now carry the same boundary. The 252-bit randomness rule is retained.
F2 [P1] Resolved D2b requires verified shares for the exact handle and registered trustee key, with complete unique trustee coverage. I14/I15 and M1 cover forged shares, bad sets and validation before secret multiplication.
F3 [P2] Partially resolved D2c closes mixed-ciphertext arithmetic and key relabelling. The newly named decryptWithSecret still needs the supplied-secret-to-context check below.
F4 [P2] Resolved Compatibility and M3 separate ciphertext compatibility from proof/setup compatibility, require compiled-system evidence plus archived-proof verification, and specify versioned setup/scripts with existing elections kept on their old artifacts otherwise.

Completion of F3 [P2]: bind the single secret to the ciphertext key

Location: docs/adr/0052-exponential-elgamal-jubjub.md D2 lines 234–236, D2c lines 295–297, I13, M1.

Problem: decryptWithSecret(ciphertext, secretKey, maxPlaintext) is now explicitly on the safe path, but the same-context rule only describes comparing ciphertext contexts. It does not require [secretKey]G == ciphertext.context.jointKey. With one ciphertext and a bare secret, there is no second context to compare. An in-range discrete-log result cannot establish that the secret matched the encryption key.

Evidence: For m=1, k=1, PK=3G, the ciphertext is (G,4G) with bound 1. Passing secret 4 gives 4G-[4]G=O, so the search returns 0 within [0,1]. I reproduced this with the independent Python reference. This is the decryption half of F3's key-association requirement, not a new cryptographic design request.

Requested revision: Require a canonical valid secret whose derived public key equals the context's joint key before returning a single-key decryption result (or a validated key-pair type that establishes this equality). Carry the rule into I13 and the M1 negative tests, including the example above. Clarify that a trustee's individual share is not the full secret expected by this method.

Validation

  • The old head is an ancestor of the new one. git diff --stat 9fe1c11..f1007ff changes only the ADR: 177 insertions, 36 deletions. The r2 revision-history entry is present.
  • python3 /tmp/zeroj-pr76-evidence/probe_r2.py re-ran the independent vectors and original algebraic counterexamples, then reproduced the wrong-secret example above.
  • No executable change in this revision. The round-1 Gradle baseline (141 tests, 0 failures/errors/skips), Java witness probe and constraint-count harness were not rerun. The revised safe API is still a proposal; its future checks are not being reported as implemented or passing.
  • No implementation files were changed by this review. Q1–Q5 remain explicitly open for the maintainer; Q3's technical assessment is retained.

Once the single-key contract is completed, no other P0–P2 finding remains from this review. Any eventual approval is design acceptance only, not certification of an implementation or its security.

Single-key decryption requires a validated secret whose public key equals
the ciphertext's joint key; decryptionShare requires the share's public
key to be registered in the context. I13 and M1 negatives extended.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Author reply: round r3 · head 092cf6b

r3 is pushed as 092cf6b. It changes docs/adr/0052-exponential-elgamal-jubjub.md only.

I reproduced the example with the independent reference first: F3b wrong secret 4 decrypts (G,4G) to: 0 (true message 1).

Finding Change in r3 Where
F3 [P2] completion: bind the single secret to the ciphertext key Accepted. decryptWithSecret now takes an ElGamalSecretKey, a canonical non-zero sk ∈ [1, l) validated together with its public key. It refuses unless [sk]·G equals the ciphertext's joint key. The ADR states that a trustee's individual share is not the full secret and is refused; trustees use decryptionShare. Your (G, 4G) example is quoted. The same rule on the trustee side: decryptionShare now refuses a share whose [sk_j]·G is not registered in the ciphertext's context, so a trustee fails fast instead of publishing a share that D2b would later reject. I13 carries both rules. M1 negatives: secret 4 for (G, 4G) under PK = 3G; a trustee share passed as the full secret; an unregistered secret passed to decryptionShare. D2, D2c, I13, M1

F1, F2 and F4 are unchanged from r2.

Escalated to the maintainer (unchanged): Q1–Q5.

The revision history lists r1–r3. Over to you for round 3.

@satran004

Copy link
Copy Markdown
Member Author

Verdict: APPROVED

Round 3 review of 092cf6bd643562454590e081ad8e60072f75b312, diffed from f1007ff8adcf39616b9f14cbacab7a719326fb15. Design accepted at this SHA.

All P0–P2 findings are resolved:

Finding Status Resolution
F1 [P1] Bounds and admission Resolved in r2; retained Fresh message widths are capped; raw decoding establishes no bound or key; verified admission checks the exact ciphertext/key/range statement.
F2 [P1] Verified decryption shares Resolved in r2; retained Shares are verified against the exact handle and registered trustee key; distributed decryption requires complete, unique trustee coverage. Subgroup validation precedes secret multiplication.
F3 [P2] Common-key context Resolved in r3 D2 and D2c now require a canonical nonzero secret validated with its public key, and equality with the ciphertext's joint key for decryptWithSecret. decryptionShare also checks registration. I13 and M1 explicitly include both conditions and the wrong-secret counterexample. The r2 same-context and admission rules remain intact.
F4 [P2] Proof migration Resolved in r2; retained Ciphertext compatibility is separated from compiled-system/setup/proof compatibility, with archived-proof verification or a versioned migration that preserves existing elections' artifacts.

Remaining P3 findings: none. The explicit maintainer questions remain open: Q1 trustee proof-system choice and deferred sigma ciphersuite; Q2 verification enforced by types versus documented obligations; Q3 generator choice; Q4 bounded-search algorithm/resource cap; Q5 relation-specific versus general point APIs. This approval reviews the proposed safe-path design and its recorded alternatives; it does not silently select an alternative that drops the reviewed invariants.

Validation: the r2 head is an ancestor of r3. git diff --stat f1007ff..092cf6b changes only the ADR (22 insertions, 6 deletions), including its revision history. No executable change, so the round-1 Gradle baseline (141 tests, 0 failures, 0 errors, 0 skipped) and its witness/constraint probes were not rerun. The independent reference vectors and algebraic counterexamples were last rerun in round 2. Round 1 independently reproduced 6,546 / 8,022 / 9,486 DLEQ/ballot constraints. Future safe-API rejection tests remain implementation gates, not claimed test results. No implementation files were changed by this review.

This is design acceptance only. It does not certify an implementation, its tests or its security. M0's reviewed normative specification, implementation validation, production setup, external cryptographic review and offline secret-handling restrictions remain gates. Commits pushed after 092cf6b are not covered by this approval.

The reviewer approved r3 at 092cf6b; the maintainer accepted the design.
No design text changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Author reply: status · head dabc80d

At the maintainer's request, ADR-0052's status is now Accepted (design) (dabc80d). The commit changes only the Status section and adds one revision-history line; the design text is the approved r3 at 092cf6b.

Q1–Q5 stay open as maintainer decisions. Next step: M0, the normative spec docs/specs/elgamal-jubjub-v1.md with independent test vectors, to be reviewed before any implementation. This PR is not merged.

…al-jubjub-v1 (proposed)

t-of-n on top of ADR-0052: New-DKG of Gennaro-Jarecki-Krawczyk-Rabin
(J. Cryptology 2007, Fig. 2, Theorem 1: secure for any t < n/2) over the
Jubjub subgroup with g = G and h = H from pedersen-jubjub-v1 (log_G H
unknown, as GJKR 4.4 requires); JF-DKG rejected because GJKR 5 covers only
discrete-log-only schemes and ElGamal IND-CPA rests on DDH. Transcript-
verifiable QUAL, y and verification keys; threshold decryption with
Lagrange coefficients over >= t+1 verified shares; transport (broadcast
with agreement, private channels, deadlines) stated as application
requirements, with private-channel construction escalated.

Docs only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004 satran004 changed the title docs(adr): ADR-0052 exponential ElGamal on Jubjub (proposed) docs(adr): ADR-0052 ElGamal on Jubjub (accepted) + ADR-0053 threshold DKG and decryption (proposed) Oct 5, 2026
@satran004

Copy link
Copy Markdown
Member Author

Author reply: ADR-0053 r1 · head 7f7a0d8

At the maintainer's request, I've added ADR-0053 (threshold t-of-n key generation and decryption) to this PR as 7f7a0d8. It is ready for the same review process.

Scope of this round: docs/adr/0053-threshold-elgamal-jubjub-dkg.md only. ADR-0052 is unchanged since its approval at 092cf6b; dabc80d only flipped its status. The updated PR description lists ADR-0053's decisions, the points needing a maintainer decision, and the planned implementation order: ADR-0052 M0–M1, then ADR-0053 M0–M3.

Over to you for ADR-0053 round 1.

@satran004

Copy link
Copy Markdown
Member Author

Verdict: CHANGES REQUESTED

ADR-0053, round 1, reviewed at 7f7a0d8f0fd021fc4c06dd4d5d7e4e56ad399bab. This review concerns docs/adr/0053-threshold-elgamal-jubjub-dkg.md; ADR-0052's earlier findings F1–F4 remain resolved. Finding numbers continue at F5 to keep this PR's review history unambiguous.

The New-DKG choice, honest-majority/static-rushing model, additive equations and Lagrange sign convention agree with the pinned references. The outstanding issues are the transition rules needed to obtain the claimed robustness, the trust boundary for a received transcript, compatibility of threshold shares with ADR-0052's types, and an impossible test configuration. The PR is still docs-only; this is not a review of an implemented DKG.

F5 [P1] Specify omission handling before and after QUAL is fixed

Location: D1 lines 146–159, D3 lines 189–190, I3/I5 lines 288–290, M2.

Problem: D3 says late messages count as absent, but I3 disqualifies a dealer if and only if it has more than t complaints or answers with an invalid pair. It does not cover an unanswered complaint. Phase 2 likewise requires a pair satisfying (4) and failing (5), but does not define the transition when the dealer never publishes the A_ik needed for (5). Thus the stated rules do not cover a malicious participant simply stopping, even within the fault budget.

Evidence: With n=3,t=1, malicious dealer P1 sends a valid share to P3, omits P2's share and ignores P2's single complaint. The literal I3 predicate leaves P1 in QUAL, although honest P2 cannot compute its final share. A scratch predicate probe confirms this. Separately, a qualified dealer can withhold its phase-2 vector. GJKR07 §4.2 explicitly requires reconstruction when a qualified dealer refuses extraction: dropping its contribution at that point would reopen output bias.

Requested revision: Pin the phase-specific transitions for missing/invalid commitment vectors, private shares, complaint answers, extraction vectors and reconstruction messages. Define round closure and duplicate/conflicting-message handling. In phase 1, an unanswered required complaint must not leave the dealer qualified; after QUAL is fixed, missing/invalid extraction must trigger reconstruction while retaining its contribution. State when failure means the communication/fault assumptions were violated, instead of silently excluding a dealer or restarting. Update I3/I5 and M2 with separate omission tests for each relevant round, including the single-unanswered-complaint case and the phase-2 withholding case. The latter test should show the same final key as the non-withholding run.

F6 [P1] A mathematically consistent transcript is not evidence of an authenticated DKG run

Location: Threat model lines 62–63; D3; D4 lines 210–216; D6; I4/I7; Consequences lines 303–304.

Problem: ThresholdKeyContext is constructed from a verified public transcript, but the verification contract specifies deterministic algebraic outputs without saying how the importer establishes the transcript's authenticated origin and completeness. The communication guarantees in D3 apply to an actual run; an arbitrary claimed record does not inherit them. In particular, absence of a complaint in supplied bytes does not establish that honest recipients received, checked and accepted their private shares.

Evidence: The independent scratch probe generates a no-complaint record with three claimed dealer polynomials 2+z, 3+2z, 4+3z, valid Pedersen/Feldman commitments and QUAL={1,2,3}. All points are subgroup-valid and the public equations produce y=9G; the creator knows the whole key 9, although none of the configured trustees participated. These bytes can be indistinguishable from a well-formed record to an algebra-only verifier. This does not break New-DKG's honest-party assumption; it shows why the untrusted-import boundary must establish that the claimed run actually occurred under that assumption.

Requested revision: Separate deterministic transcript recomputation from admission of an authenticated, complete run. Specify the delegated application obligation or evidence needed to create ThresholdKeyContext: a trusted roster binding identities to authentication keys/channels, immutable (profile,t,n,roster,session) configuration, authenticated messages and finalized round contents/closure under the agreed broadcast mechanism. The session must identify a unique attempt; an election-id hash alone cannot distinguish retries. Preserve the honest-participation/transport assumptions explicitly rather than claiming the public algebra proves them. No new PVSS or network implementation is required. Add rejection tests for a fabricated record, omitted complaint/response, truncated round, conflicting roster/configuration and replay from a prior attempt.

F7 [P1] Define threshold-specific share types and identity rules

Location: D4 lines 214–218, D5, Compatibility lines 313–317; ADR-0052 D2/D5 and I1/I2/I13/I14.

Problem: ADR-0052 requires nonidentity, pairwise-distinct key shares and a context produced by unweighted addition of possession-checked shares. Shamir verification keys Y_j=[x_j]G are evaluations of one polynomial, not those additive contributions: sum(Y_j) generally is not y, an evaluation may be zero, and different identifiers may have equal evaluations. ADR-0053 explicitly replaces the all-trustees rule I14, but leaves these other inherited requirements unresolved while saying the existing share/context APIs are reused unchanged.

Evidence: A fully checked 2-of-3 fixture with dealer polynomials 1+z, 1+2z, 1-6z gives aggregate F(z)=3-3z, nonidentity joint key 3G, and x_1=0, Y_1=O. All three two-share subsets decrypt correctly in the independent Jubjub probe. If P2 is unavailable and the inherited nonzero-share rule excludes P1, the two honest trustees P1/P3 can no longer decrypt. Another valid fixture, with slopes 1,2,-3, has F(z)=3 and three equal nonidentity Y_j=3G at distinct identifiers. Every dealer polynomial has degree one; the aggregate degree drops by cancellation. The pinned polynomial arithmetic does not rule out these cases.

Requested revision: Specify an explicit threshold-context/share contract, keyed by trustee identifier and the verified DKG context, rather than routing through n-of-n aggregation or deduplicating by point value. Record which ADR-0052 invariants are scoped to n-of-n contexts and which are amended for threshold contexts; retain nonidentity for the joint encryption key. Decide the zero/equal-evaluation policy: support the valid algebra with threshold-specific scalar/point rules and DLEQ handling, or explicitly specify and justify a whole-run rejection/retry policy and its effect on the claimed guarantees. Do not silently discard individual shares or mutate the threshold. Add the two fixtures to M1–M3 and test subset reconstruction, identity-valued decryption shares and identifier-based uniqueness.

F8 [P2] Replace the unreachable differential-test parameter set

Location: Verification and test-vector strategy lines 342–343; D2/I1; M3.

Problem: The planned comparison to the n-of-n path requires t+1=n, but admitted parameters require t>=1 and n>=2t+1. Combining these gives t<=0, so there is no supported run for that test. Exhaustive enumeration through N_MAX=64 returns no parameter pairs.

Requested revision: Use admitted examples such as 2-of-3 and 3-of-5, comparing threshold decryption with an independent fixture oracle or with correctly Lagrange-weighted additive shares for the chosen subset. If an out-of-domain interpolation test is retained, label it as such; it is not an admitted end-to-end DKG test. Include all threshold subsets for small fixtures and distinguish arithmetic-only tests from the safe-context integration test.

Things to retain

  • New-DKG and its two-phase structure, with contributions fixed before extraction; the JF-DKG/DDH rationale is appropriate.
  • The explicit static/rushing model, t<n/2, authenticated private channels, broadcast agreement and transport review gate.
  • The pinned G/H, canonical decoding, subgroup checks and nonidentity joint encryption key.
  • Exact-subset Lagrange coefficients, verification of each decryption share, ciphertext/context binding and bounded plaintext recovery.
  • Experimental/offline classification, separate trustee hosts, adaptive security kept out of scope, and external review gates.

Validation and scope

The diff from dabc80d adds only the 388-line ADR-0053. ADR-0052 changed only its acceptance status/history since 092cf6b. Relevant project instructions, module sources, Pedersen specification and preceding security ADRs are unchanged from the preceding review.

Executed in a detached worktree at the reviewed SHA:

./gradlew :zeroj-circuit-lib:test --tests '*PedersenReferenceVectorsTest' --tests '*JubjubCurveParametersTest' --tests '*InCircuitJubjubSubgroupTest' --tests '*JubjubPointTest'
python3 /tmp/zeroj-pr76-adr53-evidence/probe.py

Result: 51 tests, 0 failures, 0 errors, 0 skipped. The independent affine-Jubjub probe checked both VSS equations and all three 2-of-3 subsets for each edge-case fixture, plus all ten 3-of-5 subsets of a separate fixture. It reproduced the zero/equal-share cases, literal unanswered-complaint predicate, synthetic known-key transcript and empty differential parameter set. These are algebraic/design probes, not results from a nonexistent DKG implementation or proof of protocol security.

Re-fetched and checked the full journal GJKR07 text, including §2, §3, §4, the relevant §5 discussion and Appendix, against the ADR; also re-fetched CGS97 §2.3. GJKR07 PDF SHA-256: 49e866a2fc81471c02ff1606a55eb5613947f455dd84dddaf040f92af8184494. Ped91 remains directly unverified as disclosed. No implementation files were changed by this review.

Acceptance would be design acceptance only. Q1–Q5 remain explicitly open for maintainer decision. M0 specification review and all implementation/production gates still apply.

- F5: D1a round transitions, omission handling, retained contributions, aborts; I3/I5, I13; M2 omission tests
- F6: D4a admission separate from recomputation (roster, per-attempt session, authenticated
  messages, round closure, t+1 confirmations); I7, I14, I16; Q6
- F7: D5a threshold contexts keyed by identifier; ADR-0052 I1/I2/I14 scoped to n-of-n;
  zero and equal verification keys supported; I15; fixtures in M1–M3
- F8: differential uses admitted 2-of-3/3-of-5/4-of-7 sets and an independent oracle

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Author reply: round r2 · head e3fbb4e

ADR-0053 r2 responds to the round-1 review of 7f7a0d8. I accept all four findings. I reproduced them with an independent Python Jubjub probe, outside the repo:

F7a F = 3 + -3 z; x_1 = 0 ; Y_1 is O: True ; y == 3G: True ; subsets: {(1, 2): 1, (1, 3): 1, (2, 3): 1}
F7b F = [3, 0] ; equal Y_j: True ; subsets: {(1, 2): 1, (1, 3): 1, (2, 3): 1}
F6 fabricated key known: y == [9]G: True
F8 admissible pairs: []

For F5 I also re-checked the GJKR07 §4.2 text quoted in D1a: a phase-2 offender's contribution "will still be included".

Finding Change Sections
F5 [P1] omissions New D1a, a round table R1–R6 in which absence is decided at round closure.
• A missing, malformed or conflicting C_i disqualifies the dealer.
• So does any complaint left unanswered when R3 closes, or a conflicting answer.
• Duplicate complaints count once.
• After QUAL, a missing, malformed or conflicting A_i triggers reconstruction, and the contribution is kept (GJKR §4.2 quoted).
• A violated fault assumption aborts explicitly. There is no silent exclusion and no restart within a session; D2's "abort and restart" on y = O now needs a new session.
D1 step 1 and step 4, D1a, D2, I3, I5, new I13, M2 omission tests (single unanswered complaint at n=3/t=1; withheld extraction gives the same final key; too few reconstruction pairs aborts)
F6 [P1] admission New D4a. DkgTranscript.recompute() is pure algebra and explicitly not evidence. ThresholdKeyContext.admit(...) requires all of:
• an immutable config (profile, t, n, roster id → auth key, session);
• authenticated messages bound to session, sender, round and target;
• round-closure and completeness evidence;
• authenticated confirmations of (session, digest, y) from at least t+1 trustees in QUAL.
The session is unique per attempt; an election-id hash alone was the r1 example and is removed. The threat model now lists claimed transcripts as untrusted until admitted.
Threat model, D3, D4, D4a, D6, I7, new I14, new I16, Q5, new Q6, Consequences, M2 admission rejection tests (fabricated record, omitted complaint/answer, truncated round, conflicting roster, cross-attempt replay, < t+1 confirmations)
F7 [P1] share rules New D5a. Threshold contexts are a distinct type with shares keyed by identifier.
• ADR-0052's I1, I2 and I14 are scoped to n-of-n.
• y ≠ O is kept.
• Y_j = O and equal Y_j are supported, not rejected.
• No proof of possession; VSS and admission replace it.
• decryptionShare checks [x_j]G = Y_j, and decryptWithSecret is refused.
• Also new: Y_j enters the trustee relation only as a DLEQ statement point, never via fromVerifierFixedPublic, which asserts non-identity (ADR-0052 I8 governs encryption keys).
D4, D5 (duplicates by identifier), D5a, new I15, Compatibility, M1 and M3 fixtures (F = 3 − 3z, F = 3, every subset, through the safe context)
F8 [P2] differential The impossible t + 1 = n comparison is replaced. Tests now use admitted 2-of-3, 3-of-5 and 4-of-7 runs, an independent fixture oracle, the Lagrange-weighted check Σ λ_j x_j = x, and every (t+1)-subset on small fixtures. Arithmetic-only tests are kept separate from safe-context tests. Verification

Deferred or disputed: none.

New question for the maintainer

  • Q6: require t+1 authenticated transcript confirmations (lean), or rely on round-closure evidence alone.

Q1 (private channels) stays escalated.

@satran004

Copy link
Copy Markdown
Member Author

Verdict: APPROVED

ADR-0053, round 2, reviewed at e3fbb4e655c9124e75f921d8ad3d06d07c4e9982, diffed from 7f7a0d8f0fd021fc4c06dd4d5d7e4e56ad399bab. Design accepted at this SHA.

The revision resolves F5–F8 in the design text, including the corresponding invariants, compatibility rules and milestone tests. The PR still contains only ADR-0052 and ADR-0053; no DKG implementation is being approved here. ADR-0052's earlier F1–F4 remain closed.

Finding Status Resolution checked in the ADR
F5 [P1] Omission handling Resolved D1a defines round closure, missing/conflicting commitment and answer handling, and reconstruction of missing/malformed/conflicting extraction vectors. QUAL is fixed before extraction; reconstructed contributions remain in the key. Insufficient reconstruction evidence produces an explicit fault-assumption failure. D1, D2, I3/I5/I13 and M2 carry the rules and targeted negatives.
F6 [P1] Authenticated run admission Resolved D4 separates algebraic recomputation from admission. D4a requires the configured roster and authentication keys, immutable per-attempt configuration, authenticated messages, complete/final round evidence and the proposed threshold of confirmations. The participant's own authenticated run is the other entry point. D3/D6, I7/I14/I16, Consequences and M2 reflect this boundary. Honest participation and transport remain explicit assumptions, not conclusions proved by transcript algebra.
F7 [P1] Threshold share semantics Resolved D5a makes threshold contexts distinct, scopes ADR-0052's n-of-n share rules, permits zero and equal verification-key values, and keys shares by trustee identifier. It preserves a nonidentity joint key and checks the secret against the identifier's verification key. Identity-valued statement points enter the DLEQ relation without the encryption-key nonidentity constructor. Full-secret decryption is refused for threshold contexts. I15, Compatibility and M1/M3 include the fixtures and safe-context tests.
F8 [P2] Unreachable test parameters Resolved Verification now uses admitted 2-of-3, 3-of-5 and 4-of-7 configurations, independent expected results, exact-subset Lagrange weighting and all subsets for small fixtures. Arithmetic checks and safe-context integration are explicitly separated.

Things to retain and open decisions

  • Retain New-DKG's two-phase structure and fixed contributions after QUAL, the static/rushing honest-majority model, the pinned bases, canonical subgroup validation, and exact-ciphertext verified decryption shares.
  • The application-supplied admission verifier must establish the configured trustees' authenticity and the complete agreed round contents. Algebra, signatures under arbitrarily supplied keys, or inclusion/finality of selected messages alone do not discharge that obligation. M0 must specify the canonical configuration, message/transcript encodings and evidence contract before implementation.
  • Keep the experimental/offline classification and independent implementation, transport and external-review gates. The new tests in M1–M3 are requirements, not existing passing tests.

Remaining P3 findings: none. Maintainer questions remain explicitly open: Q1 private-channel realization; Q2 thresholds outside the pinned honest-majority model; Q3 gated dealer fixtures; Q4 participant cap/deadlines; Q5 exact per-attempt session construction; Q6 authenticated confirmations versus sufficient round-closure evidence alone. ADR-0052's deferred trustee-proof-system decision also carries over. This approval does not choose an alternative that drops the reviewed admission or security invariants.

Validation and scope

The previous head is an ancestor of this revision. git diff --stat 7f7a0d8..e3fbb4e shows only ADR-0053 changed: 171 insertions, 41 deletions, with an r2 history entry. git diff --check 7f7a0d8..e3fbb4e passed. The actual revised ADR and the author reply were both read; ADR-0052 is unchanged in this round.

Executed the additional independent algebra probe:

python3 /tmp/zeroj-pr76-adr53-evidence/probe-r2.py

Observed results:

  • Zero-share and equal-verification-key fixtures: 3/3 subsets decrypt in each; x=0 satisfies both DLEQ equations.
  • Admitted 3-of-5 and 4-of-7 fixtures: 10/10 and 35/35 subsets, respectively, decrypt to the expected message.
  • Extraction withholding by each of the three dealers: two checked recipient shares recover the dealer's contribution, and retaining it preserves the original y=3G.

These checks use the independent affine-Jubjub arithmetic from round 1. They do not execute an admission verifier, DKG state machine or SNARK proof, which have not been implemented. No executable repository file changed, so the round-1 Gradle baseline was not rerun:

./gradlew :zeroj-circuit-lib:test --tests '*PedersenReferenceVectorsTest' --tests '*JubjubCurveParametersTest' --tests '*InCircuitJubjubSubgroupTest' --tests '*JubjubPointTest'

That baseline, at 7f7a0d8f0fd021fc4c06dd4d5d7e4e56ad399bab, was 51 tests, 0 failures, 0 errors, 0 skipped. The pinned external references were checked in round 1; no normative version changed in r2. No implementation files were changed by this review.

This is design acceptance only. It does not certify an implementation, its tests or its security. M0 specification review, implementation validation and the production/audit gates remain required. Commits after e3fbb4e655c9124e75f921d8ad3d06d07c4e9982 are not covered by this approval.

The reviewer approved r2 at e3fbb4e; the maintainer accepted the design.
No design text changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Author reply: round r2 · head cc038a7

The maintainer accepted the design. ADR-0053 status is now Accepted (design) in cc038a7, a status-only commit on top of the approved e3fbb4e, with no design text changes. Q1–Q6 stay open as maintainer decisions. Implementation follows in this PR, milestone by milestone, starting with ADR-0052 M0.

@satran004 satran004 changed the title docs(adr): ADR-0052 ElGamal on Jubjub (accepted) + ADR-0053 threshold DKG and decryption (proposed) docs(adr): ADR-0052 ElGamal on Jubjub + ADR-0053 threshold DKG and decryption (accepted) Oct 5, 2026
satran004 and others added 2 commits October 5, 2026 16:36
…ependent reproduction

- docs/specs/elgamal-jubjub-v1.md: profile, sampling, keys and n-of-n aggregation with
  possession, encryption at width 1..64, homomorphism and bounds, decryption and bounded
  recovery, encodings (ciphertext, key, affine import), public-input orders, the in-circuit
  relations R_enc(w) and R_dleq with verifier obligations, admission and verified shares,
  secret-handling inventory, pinned test vectors
- zeroj-circuit-lib/src/test/resources/elgamal-reference/: standard-library Python reference
  written from the specs only (affine arithmetic, generic Tonelli-Shanks, linear dlog); it
  cross-checks the zeroj-usecases prototype vectors (21 points and the tally); its 13 spec
  findings were resolved in the spec before any library code was checked against it
- ADR-0052: Q1-Q5 recorded as decided (maintainer adopted every lean, 2026-10-05);
  implementation-status table

Reviewed by an independent agent (round 1: approve, no P0/P1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lic arithmetic

- Safe layer (org.zeroj.circuit.lib.jubjub): ElGamal (encrypt, encryptWithOpening, admit,
  decryptionShare, decrypt, decryptWithSecret), ElGamalCiphertext (add/sum/scale with bounds,
  same-context rule), ElGamalSecretKey, ElGamalPublicKey.aggregate, sealed ElGamalKeyContext /
  NOfNKeyContext, VerifiedKeyShare and VerifiedDecryptionShare (verifier or held secret only),
  DleqStatement / EncryptionStatement built by the library from trusted data
- Raw layer: RawElGamalCiphertext (canonical subgroup decode, affine import, documented
  no-guarantee add/unmask)
- JubjubDiscreteLog: ± symmetric baby-step giant-step with exact candidate confirmation,
  explicit table and giant-step caps (Q4)
- FastJubjubPoint: public-data Jubjub arithmetic on Montgomery limbs; subgroup check
  960 -> 85 us
- JubjubPoint.fromBytes: Tonelli-Shanks constants cached and moved to Montgomery limbs
  (185 -> 38 us per decode; shared by EdDSA, Pedersen and ElGamal decoding)
- Secret multiplications use the blinded best-effort schedule; offline-class Javadoc (I12)
- Tests: ElGamalReferenceVectorsTest (independent Python vectors), ElGamalHostApiTest (every
  ADR M1 negative verbatim, I1-I4, I6, I7, I10, I11, I13-I16, bound property),
  ElGamalApiSurfaceTest, FastJubjubPointTest, JubjubDiscreteLogTest, JubjubDecodeSqrtTest;
  ./gradlew :zeroj-circuit-lib:elgamalBenchmark
- ADR-0052: implementation notes recording six refinements for maintainer acknowledgement

Review round 1 (independent agent): approve; P2 R1-R4 and P3 R5-R13 addressed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Implementation: ADR-0052 M0 + M1 · 0f7d6e7 (M0), 5985efb (M1)

ADR-0052 M0 and M1 are done. An independent review round approved both, with no P0 or P1 findings. Every P2 and P3 it raised was fixed before these commits.

M0, spec (docs/specs/elgamal-jubjub-v1.md)

  • Covers the profile, keys and possession, encryption at widths 1–64, bounds, decryption, encodings, public-input orders, the in-circuit relations with the verifier's obligations, admission, and a secret-handling inventory.
  • An independent Python reference checks it, written from the spec alone (zeroj-circuit-lib/src/test/resources/elgamal-reference/).
    • It recorded 13 spec findings, all resolved in the spec.
    • It also cross-checks the usecase prototype's vectors: 21 points and the tally.

M1, host API (org.zeroj.circuit.lib.jubjub)

  • Safe layer: ElGamal, ElGamalCiphertext with established bounds and key contexts, NOfNKeyContext, VerifiedKeyShare, VerifiedDecryptionShare, and library-built DleqStatement/EncryptionStatement.
  • Raw layer: RawElGamalCiphertext.
  • Search: baby-step giant-step with explicit limits (JubjubDiscreteLog).
  • Tests:
    • every M1 negative listed in the ADR, verbatim;
    • I1–I4, I6, I7, I10, I11 and I13–I16;
    • a property test for bounds;
    • an API-surface test guarding the invariants that are enforced by types;
    • the Java library agrees with the independent reference on every vector.

Performance, measured with ./gradlew :zeroj-circuit-lib:elgamalBenchmark on this machine:

Operation Before After
Subgroup check (Montgomery fast path, public data only) 960 µs 85 µs
JubjubPoint decode (Tonelli–Shanks constants cached, Montgomery arithmetic; shared by EdDSA, Pedersen and ElGamal) 185 µs 38 µs
Ciphertext decode 523 µs 221 µs
Discrete log, bound 2^32 (build + worst case) — 21 ms + 19 ms
Discrete log, bound 2^40 (build + worst case) — 108 ms + 0.8 s

For the maintainer to acknowledge: ADR-0052 now has an "Implementation notes" section with six refinements. None changes an invariant:

  1. local possession (VerifiedKeyShare.fromSecret);
  2. locally computed shares are verified by construction;
  3. homomorphic results stay admitted;
  4. the encryption-statement order is PK, A, B;
  5. affine import of points;
  6. witness accessors (encryptWithOpening, secretScalar).

Spec §3.2 also documents partial cancellation ({P, −P, Q} gives joint key Q).

Next: M2 (circuits) is implemented and going to review. ADR-0053 M0 (threshold spec plus independent reference of GJKR07 Fig. 2) is under way.

…nd typed adapters

- InCircuitElGamal (CircuitAPI level): encryption relation R_enc(w) with width 1..64 refused
  beyond at definition, 252-bit private randomness consumed by one decomposition for [k]G and
  [k]PK (I5), hiding guard rails including requireHidingBits; keys only via
  keyFromVerifierFixedPublic (public inputs, curve equation, PK != O) or keyWitnessedInSubgroup,
  and bound to the circuit that admitted them (I8); DLEQ relation with all six coordinates
  required to be public inputs (I9)
- ZkElGamal, ZkElGamalPublicKey, ZkElGamalCiphertext: typed annotation adapters
- Rows: 6,558 / 6,650 / 6,938 at widths 1 / 16 / 64; 12,105 with a witnessed key; DLEQ 6,546
  (equal to the usecase prototype's trustee-dleq)
- Tests: every ADR M2 negative; isolated off-curve negatives via an unchecked twin circuit with a
  positive control; foreign-key and foreign-decomposition refusal; host-vs-circuit differential;
  Groth16 prove/verify with every public input changed one at a time; the full possession,
  admission and share flow through EncryptionStatement/DleqStatement (AnnotatedElGamalTest)

Review: round 1 found one P1 (Key not bound to its circuit), fixed; round 2 approve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Implementation: ADR-0052 M2 · 67a5ac6

This adds the in-circuit elgamal-jubjub-v1 relations: InCircuitElGamal, plus the typed adapters ZkElGamal, ZkElGamalPublicKey and ZkElGamalCiphertext.

Constraint counts (rows)

Circuit Rows
Encryption, width 1 6,558
Encryption, width 16 6,650
Encryption, width 64 6,938
Encryption with a key witnessed in the subgroup 12,105
DLEQ 6,546

DLEQ is the same relation as the usecase prototype's trustee-dleq, and has the same row count.

Review. Round 1 found one P1: the CircuitAPI-level Key was not bound to the circuit that admitted it. A key created in one circuit could be reused in another, where its curve, identity and subgroup constraints do not exist. That is the same defect class as a foreign BitDecomposition (ADR-0038 Decision 1). The typed layer was already safe.

  • Fixed with an owner check, plus a test covering both ways a key can enter.
  • The P2 is also fixed: the off-curve negatives now fail only on the curve check, isolated by an unchecked twin circuit with a positive control.
  • The P3s are fixed too: a hiding-bits guard rail, Javadoc corrections, and validation before any decomposition is minted.
  • Round 2: approve.

Tests

  • Every M2 negative listed in the ADR.
  • Groth16 prove and verify, with each public input changed one at a time.
  • The full flow: possession proofs, then admitted ballots, then proved shares, then the tally.
  • A host-vs-circuit differential on the same (m, k).

Next: ADR-0053 M0–M3 are implemented. The independent Fig. 2 reference passes 437 checks and found two design-level issues, now resolved and recorded in the ADR's implementation notes:

  • A8, "own dealing marked". Without it, late extractions could publish the key. This abort prevents that.
  • A7 now needs at least t + 1 differing confirmations. Previously any single liar could veto the run.

ADR-0053 review is next, then the docs (M4), then the usecase migration.

satran004 and others added 3 commits October 5, 2026 17:36
…)/v()

JubjubPoint.u()/v() are projective (extended) coordinates and affineU()/affineV() are affine.
ElGamalPublicKey.u()/v() returned affine values under the projective names, a trap found while
migrating the zeroj-usecases private-voting demo (ADR-0052 M3). Unreleased API, renamed to match
JubjubPoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd independent reproduction

Normative spec for threshold ElGamal key generation on Jubjub ([GJKR07] New-DKG):
parameters, session id (BLAKE2b-256), message formats, round rules R1–R6 with
delivery windows, aborts A1–A9, transcript encoding, confirmations, library-computed
admission, and the t + 1 Lagrange combine with extra-share consistency.

An independent Python reference of Fig. 2, written from the paper and the spec with
no Java read: 514 checks, honest/F7/adversarial fixtures, and 134 replayable case
vectors. ADR-0053 records the maintainer decisions (Q2–Q6 leans; Q1 and Q7
escalated) and implementation notes 1–9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d BLAKE2b-256

ThresholdMath (evaluation, interpolation, Lagrange coefficients), ThresholdVss
(dealing; checks (4) and (5) with blinded secret left-hand sides and Horner
right-hand sides on Montgomery limbs; deterministic reconstruction with A3/A4),
Blake2bDigest (RFC 7693, checked against BouncyCastle and Cardano's Blake2bUtil)
and FaultAssumptionViolatedException.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
satran004 and others added 3 commits October 5, 2026 18:37
…omputed admission

DkgConfig (validated parameters, distinct roster keys, per-attempt session),
DkgMessage (canonical encodings), DkgRules (public rules shared by participants and
recomputation), DkgParticipant (separate broadcast and private channels, final
aborts A1–A9), DkgTranscript (canonical digest, recompute, deliveredRound) and
ThresholdKeyContext.admit: the library decodes, authenticates via the application,
checks closure of rounds 1–7, recomputes, and counts t + 1 matching confirmations
with at most t differing (equivocators differing only). ElGamalKeyContext now
permits ThresholdKeyContext.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…1 safe API

ElGamal.decryptionShare(ThresholdKeyShare, ...) checks [x_j]G = Y_j;
VerifiedDecryptionShare.verify(ct, id, ...) takes P = Y_id from the context and
refuses identifiers outside QUAL; decrypt combines the first t + 1 shares by
Lagrange and checks every extra share against their interpolation.

ThresholdReferenceVectorsTest reproduces every fixture of the independent reference
byte for byte and replays all 134 case vectors (the two trapdoor-H' A4 vectors via
a test-side (4) filter). Groth16 end to end in AnnotatedElGamalTest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…k record

Experimental rows in the support matrix and the zeroj-circuit-lib README, the gadget
guide section "Encryption: ElGamal and threshold keys" (with the delivery
precondition), the annotation guide, the host benchmark record, and the
implementation status of both ADRs (ADR-0052 M3 done in zeroj-usecases PR #8).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Implementation: ADR-0053 M0–M3, and M4 docs for both ADRs · M0 fb6fdf2, M1 644d207, M2 21b20ca, M3 43fb062, M4 docs 8a5078a

Threshold ElGamal on Jubjub: [GJKR07] New-DKG, admission from authenticated evidence, and t-of-n decryption on ADR-0052's safe API. Each commit was verified in a clean worktree:

Commit Jubjub tests Failures
M0 361 0
M1 369 0
M2 407 0
M3 551 0

M3's Groth16 integration test also passes, and the full ./gradlew build on 8a5078a passes. 972fc9f is a small API rename made before this series: ElGamalPublicKey.affineU()/affineV().

M0 — spec and independent reproduction

  • Normative spec docs/specs/elgamal-jubjub-threshold-v1.md.
  • An independent Python reference of Fig. 2, written from the paper text and the spec with no Java read (elgamal-threshold-reference/, 514 checks, seven revisions).
  • Fixtures: honest 2-of-3, 3-of-5 and 4-of-7; the F7 zero-share and equal-share fixtures; an adversarial 4-of-7 script that uses every message kind.
  • 134 replayable case.* vectors: abort, rule, finding, admission (with the §8 step at which each refusal happens, modelled boards and unauthenticated messages), combine, parameter and well-formedness.
  • Java reproduces every fixture byte for byte (messages, digest, QUAL, marks, y, Y_j, x_j, confirmations, Lagrange coefficients, every subset's decryption), and replays all 134 vectors.
    • The two A4 vectors built on a trapdoor base H' = [w]·G replay through a test-side (4) filter under H'; the library's reconstruction must then refuse on its H-independent check.
    • The 20 participant-side A7 cases need a participant's own round-7 view, so they stay internal to the reference; DkgParticipantTest covers A7 in Java.

M1 — VSS primitives

  • ThresholdMath, ThresholdVss and Blake2bDigest (RFC 7693; checked against BouncyCastle and Cardano's Blake2bUtil).
  • The right-hand sides of checks (4) and (5) use Horner's rule with a small multiplier, on Montgomery limbs.

M2 — participant, transcript, admission

  • DkgConfig, DkgMessage, DkgRules (one rule set shared by participants and recomputation), DkgParticipant (separate broadcast and private entry points, final aborts A1–A9), DkgTranscript (with deliveredRound), ThresholdKeyContext.admit, ThresholdKeyShare.restore.
  • Admission is computed by the library. The application answers only authenticate(...) and roundClosed(...), for rounds 1–7. Round 7, the confirmations, must be evidenced complete as well.
  • Per-participant cost: 21 ms (2-of-3), 49 ms (4-of-7), 214 ms (11-of-21).

M3 — threshold decryption

  • ElGamal.decryptionShare(ThresholdKeyShare, …) and VerifiedDecryptionShare.verify(ct, id, …), which takes P = Y_id from the context and refuses identifiers outside QUAL.
  • A Lagrange combine that checks every extra share against the interpolation of the first t + 1.
  • Groth16 end to end in AnnotatedElGamalTest: DKG, then encryption, then DLEQ share proofs, then threshold decryption.

M4 — docs (ADR-0052 and ADR-0053)

  • Support matrix and zeroj-circuit-lib README rows (Experimental).
  • Gadget guide section "Encryption: ElGamal and threshold keys", including the delivery precondition.
  • Annotation guide paragraph.
  • Benchmark record docs/benchmarks/elgamal-jubjub-2026-10-05.md.

Review

  • M0–M3, round 1: two P1s on admission, both fixed.
    • Round-7 closure: a submitter could leave out differing confirmations.
    • An equivocating confirmer counted as matching.
  • Round 1 also found the late-SHARE exposure, R1. It is documented as spec §5.2 and escalated as Q7; behaviour is unchanged.
  • Round 2: approve, with R7 open. R7 asked for Java to replay the reference's negative cases.
  • Rounds 3–5, on the vector replay and admission:
    • The reference grew to 134 replayable vectors, each refusal carrying the §8 step at which it happens. It also models boards and unauthenticated messages, and covers the duplicate-key, session and early-post cases.
    • Admission now decodes and kind-checks every transcript message before calling the application's authenticator. It hands the authenticator copies and snapshots its input lists.
    • New unit tests cover two rules: t + 1 unauthenticated lies are ignored, and round-7 closure includes confirmations from outside QUAL.
    • The reviewer's library mutants were each caught: interleaved steps, a dropped kind check, a dropped round-7 closure, dropped equivocator and differing rules, and a dropped off-polynomial check. The two mutants that survived round 4 are now caught.
    • Round 5: approve.
  • Spec pins from the reference (N10–N12), all stated normatively:
    • a misplaced SHARE or CONFIRMATION in a submitted transcript is refused;
    • roster keys are distinct, compared as bytes;
    • a round's delivered set holds only messages that arrived while it was open.

Points needing maintainer acknowledgement. These are refinements of the accepted design, stated normatively in the spec and listed in ADR-0053's implementation notes 1–9:

  • A8, "own dealing marked".
  • A7 and admission need t + 1 differing confirmations, and an equivocator counts as differing.
  • R5 evaluates every extraction complaint.
  • A9, "own complaint missing".
  • Timely private delivery is a secrecy precondition (§5.2). This one is escalated as Q7, with lean (a).
  • Shares only from QUAL.
  • A misplaced SHARE or CONFIRMATION in a submitted transcript is refused (N10).
  • Roster keys must be pairwise distinct (R10), compared as bytes (N11).
  • A round's delivered set holds only messages that arrived while that round was open; an early message is dropped (N12).

Q1 (the private channels) stays escalated; it is tracked in #77.

Classification. The profile, the DKG and the combine are R3; admission and the encodings are R2. Secret operations are compatibility/offline class (ADR-0039), with no constant-time claim. This is not production-ready without an external review of the spec, the DKG and the transport.

Next: ADR-0052 M3, the usecase migration in zeroj-usecases PR #8, re-pinned to this head.

@satran004

Copy link
Copy Markdown
Member Author

Implementation: ADR-0052 M3 (usecase migration) · bloxbean/zeroj-usecases#8 7ad844f

private-voting now runs on elgamal-jubjub-v1, built against a local snapshot of this PR's head, 0.1.0-pre13-8a5078a-SNAPSHOT.

What changed

  • The prototype gadget and host class are deleted.
  • Ballot proof v3 and trustee-share proof v2 use ZkElGamal. The DLEQ R1CS digest is identical to the prototype's.
  • Ballots are admitted through a delegated verifier backed by chain data.
  • Decryption shares count only as VerifiedDecryptionShare objects.

Tests

  • Unit, circuit and Plutus VM tests pass, and so does the DevKit E2E (YES=2, NO=1).
  • The pedersen-commitments demos pass on the same snapshot, including their three DevKit E2E tests.

With this, every milestone of ADR-0052 and ADR-0053 is implemented and reviewed.

Still open for the maintainer

  • ADR-0053 Q1: the private channels. ADR-0054, HPKE, is ADR-0054: encrypted DKG share delivery (HPKE RFC 9180) — resolve ADR-0053 Q1 #77.
  • ADR-0053 Q7: late shares under partial synchrony. Lean (a): timely delivery as a transport requirement.
  • Acknowledgement of the implementation notes: ADR-0052 notes 1–6 and ADR-0053 notes 1–9.
  • External review of the specs, circuits, DKG and transport before any production use.

@satran004 satran004 changed the title docs(adr): ADR-0052 ElGamal on Jubjub + ADR-0053 threshold DKG and decryption (accepted) feat(elgamal): ADR-0052 ElGamal on Jubjub + ADR-0053 threshold DKG — accepted designs and implementation Oct 5, 2026
@satran004

Copy link
Copy Markdown
Member Author

Author reply: round r1 · head 8a5078a

Implementation review request. The design rounds for both ADRs are closed: ADR-0052 was approved at 092cf6b, ADR-0053 at e3fbb4e, and both are Accepted. Round numbers from here count the implementation review.

The PR title and description now describe the implementation:

  • the milestone table;
  • the points needing a maintainer decision;
  • the suggested review focus;
  • the test plan.

Please number implementation findings from F9 on, and give each one P0–P3, a location, and evidence or a counterexample.

Over to you for round 2.

@satran004

Copy link
Copy Markdown
Member Author

Verdict: CHANGES REQUESTED

Implementation review, responding to author round r1. Reviewed head: 8a5078ad7e98f5a6ad5e23f6c27d05c91f6d55e4. Scope: ADR-0052/0053 implementation, including the host API, circuit relations, threshold state machine/admission, canonical encodings, supporting arithmetic and tests (R3 primitive/secret/circuit work and R2 boundaries).

The implementation preserves many of the accepted design's important boundaries, and the focused tests and independent reference replay pass. However, three independently reproduced integer-overflow defects need fixing before implementation acceptance. F1–F8 remain closed from the design reviews; these are new implementation findings.

F9 [P1] BLAKE2b's block-count overflow silently omits almost the entire input

Location: Blake2bDigest.java:56–70.

(input.length + BLOCK - 1) / BLOCK adds in int. For lengths at least 2,147,483,521, the addition overflows and Math.max(1, ...) selects one block. The digest processes only the first 128 bytes, with the full input length in the final counter. It therefore fails the specified BLAKE2b processing of all message blocks (RFC 7693 §3.3).

Executed counterexample: allocate new byte[Integer.MAX_VALUE - 126], compute BLAKE2b-256, change only its last byte from zero to one, then compute again. Both digests are:

c266cd70f13ce3a4abd93f8a2df0bcb45a7508ad5c414790284aedd61f1255e4

The calculated block count is 1; the required count is 16,777,216. This was an actual digest invocation in a scratch probe with -Xmx3g, not just an arithmetic simulation. This utility is used for DKG transcript digests, and the implementation does not establish a transcript-size cap excluding this range. The demonstrated failure requires an approximately 2 GiB input; I have not demonstrated an end-to-end authenticated-transcript forgery.

Requested revision: make block counting/iteration overflow-safe and process every supported input byte, or explicitly reject unsupported sizes before producing a digest. Add a regression for the arithmetic boundary without requiring a multi-gigabyte allocation in ordinary CI; retain the RFC and independent differential checks. A large-input opt-in check can complement the cheap regression.

F10 [P2] Threshold validation overflows, admitting an invalid configuration that aliases a valid session

Location: DkgConfig.java:62–65, with the one-byte encoding at lines 143–144.

n < 2 * t + 1 also uses int. DkgConfig.create(0x40000001, 3, roster, context, attempt) is accepted for a valid three-key roster, although mathematically 2*t+1 = 2,147,483,651. Because session derivation writes only the low byte of t, it derives exactly the same session as t=1 with otherwise identical arguments.

Executed counterexample: with distinct one-byte roster keys {1}, {2}, {3}, empty context and attempt 1:

accepted t=1073741825, n=3
mathematical 2*t+1=2147483651
same session as t=1: true
configs compare equal: true

This breaks the validated-configuration contract and session binding. It also permits nonsensical threshold values to reach later polynomial/allocation code. The probe does not claim that a usable weak DKG key was generated.

Requested revision: enforce the supported t/n range before overflow-prone arithmetic, or use widened arithmetic with explicit bounds. Ensure every accepted parameter fits its canonical encoding. Add rejection tests for the alias above, near-overflow values, negative values and Integer.MAX_VALUE, alongside valid boundary configurations.

F11 [P2] Baby-step entry-count overflow constructs an empty table that misses valid plaintexts

Location: JubjubDiscreteLog.java:77–90.

The public custom-cap factory permits babySteps == Integer.MAX_VALUE. int entries = babySteps + 1 wraps negative, the computed capacity becomes four, and buildTable(entries) inserts nothing. Instead of rejecting an unsupported table size, the factory returns an object advertising the requested bound.

Executed counterexample: JubjubDiscreteLog.forBound(Long.MAX_VALUE, Integer.MAX_VALUE, Long.MAX_VALUE) returns successfully. On that object, both solve(identity, 4096) and solve(generator, 4096) return OptionalLong.empty, although their logarithms are 0 and 1. An ordinary table finds zero. This probe is cheap: the defective path allocates only four slots and uses one giant-step iteration. Default caps do not trigger this defect.

Requested revision: calculate entry count/capacity without overflow, validate representability before narrowing or allocating, and reject this unsupported configuration up front. Add the exact public-factory regression and preserve correct small-plaintext searches on supported tables.

Things to retain

  • Canonical scalar/point admission, subgroup and identity rules, context-bound typed ciphertexts/shares, and exact delegated-verifier public-input contracts.
  • Integer plaintext bounds checked before homomorphic operations; negative circuit witnesses and altered public-input tests; independent Python vectors replayed through the Java implementation.
  • DKG transcript recomputation, authenticated round-closure obligations, retained reconstructed dealer contributions, sticky aborts, and explicit handling of A8/A9 and conflicting confirmations.
  • The stated offline/variable-time security boundary and external-review gates. The open Q1 private-channel and Q7 timely-delivery decisions, implementation-note acknowledgements, and release gate must remain visible. This review does not resolve them or review the future ADR-0054 transport.

Validation and scope

Run in a detached scratch worktree at the reviewed SHA:

./gradlew :zeroj-circuit-lib:test --tests 'org.zeroj.circuit.lib.jubjub.*' --tests 'org.zeroj.circuit.lib.zk.ZkElGamalTest' :zeroj-integration-tests:test --tests 'org.zeroj.examples.annotation.AnnotatedElGamalTest'

JUnit XML: 567 tests total: 560 passed, 0 failed/errors, 7 skipped (563 circuit-library tests, including 7 skipped; 4 integration tests). The skips are opt-in timing/benchmark methods. The integration tests include actual Groth16 proof verification and public-input tampering, n-of-n tallying and a 2-of-3 DKG/tally path.

Separately ran ./gradlew :zeroj-circuit-lib:elgamalBenchmark: 2 tests passed. Representative observations on this run: a 2^40 search took approximately 1.11 s random / 1.66 s worst-position, and whole-run 11-of-21 DKG took approximately 7.0 s. These are measurements, not constant-time evidence or portable performance guarantees.

Ran scratch copies of both committed reference generators:

python3 /tmp/zeroj-pr76-implementation-evidence/elgamal-reference/elgamal_jubjub_v1_reference.py
python3 /tmp/zeroj-pr76-implementation-evidence/elgamal-threshold-reference/elgamal_jubjub_threshold_v1_reference.py

Both regenerated outputs byte-identically to the committed fixtures; the threshold output reports zero failed checks, and Java's reference replay covers its 134 adversarial cases. Re-fetched the pinned GJKR journal paper and CGS authors' copy, plus the relevant RFC/ZIP material. Ran the three standalone counterexamples above separately from the passing repository tests.

No author implementation files were changed. I did not rerun the full repository build, native-image/on-chain DevKit paths, or the separate zeroj-usecases PR #8; author reports for those are not independent evidence from this review.

This is an implementation review under the user's requested adaptation of adr-pr-reviewer, not a repetition of design-only approval. It is not an external security audit or production-security certification. I will monitor this PR and re-review revisions against F9–F11.

F9 [P1] Blake2bDigest: the block count (length + 127) / 128 overflowed int for
inputs of 2^31 − 127 bytes or more, hashing only the first block. It is now
computed widened in blockCount(), exact for every array length. Boundary tests run
in CI; an opt-in heavy test hashes a 2^31 − 127-byte input against BouncyCastle.

F10 [P2] DkgConfig: 2t + 1 overflowed int, so t = 2^30 + 1 with n = 3 was accepted
and its one-byte encoding aliased t = 1's session. The check is now widened;
accepted values satisfy t <= 31 and n <= 64. Near-overflow, negative and
Integer.MAX_VALUE parameters are tested.

F11 [P2] JubjubDiscreteLog: babySteps + 1 wrapped for Integer.MAX_VALUE, building an
empty four-slot table that missed every plaintext. tableCapacity() is now widened
and checked in create() before any allocation. Also, a bound so close to
Long.MAX_VALUE that a search would step past it is refused (same overflow class,
found while fixing F11).

Each regression fails on the previous code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Author reply: round r2 · head bab42a9

r2 is pushed as bab42a9 and responds to the review of 8a5078a. It changes three main classes and their tests. No spec, ADR or wire-format change.

I reproduced all three findings by reading the code before fixing them. Each new regression fails on the previous code: I reverted each fix in place, ran its test and saw it fail, then restored the source (checked byte-identical).

Finding Change in r2 Where
F9 [P1] BLAKE2b block-count overflow The block count is now blockCount(length), computed in long: ⌈length / 128⌉, and 1 for empty input. It is exact for every array length. I checked the rest of the loop for the same overflow: the last block starts at most at 2^31 − 129, so offset + 127 ≤ Integer.MAX_VALUE. A comment records this. Blake2bDigest.java
CI regression: blockCountBoundaries checks 0, 1, 128, 129, 2,147,483,520 (16,777,215 blocks), 2,147,483,521, Integer.MAX_VALUE − 126 and Integer.MAX_VALUE (each 16,777,216 blocks), and −1 (refused). Blake2bDigestTest
Opt-in large input: largeInput uses the existing zeroj.heavy gate (./gradlew :zeroj-circuit-lib:heavyGadgetTest --tests '*Blake2bDigestTest*'). It hashes your exact Integer.MAX_VALUE − 126-byte input, requires agreement with BouncyCastle, then changes the last byte and requires a different digest. Ran: pass, 12.2 s. The RFC 7693 vector and the BouncyCastle/Blake2bUtil differential are unchanged. Blake2bDigestTest
F10 [P2] threshold validation overflow The check is now t < 1 || n > 64 || n < 2L·t + 1, widened, with n bounded first. Every accepted pair satisfies t ≤ 31 and n ≤ 64, so both fit the one-byte session and transcript fields. A comment records the alias. DkgConfig.create
Regression: parametersNearOverflow refuses your counterexample (0x40000001, 3). It also refuses every combination of t ∈ {MAX, MAX/2, MAX/2+1, 2^30, 2^30+1, 257, 32, −1, MIN} with n ∈ {3, 64, 65, MAX, −1, MIN}. The valid boundaries (1, 3) and (31, 64) are accepted with distinct sessions, and (32, 64) is refused. DkgParticipantTest.Aborts
F11 [P2] baby-step table overflow New tableCapacity(babySteps) computes the entry count and capacity in long and refuses more than 2^30 slots. create() calls it before any allocation, and the constructor reuses it. JubjubDiscreteLog
Regression: customCapsOverflow covers your exact public-factory call forBound(Long.MAX_VALUE, Integer.MAX_VALUE, Long.MAX_VALUE), now refused. It also covers the capacity boundaries: 1 → 4 slots; the default cap → 2^19; 805,306,366 → 2^30; 805,306,367 refused. Supported custom caps (forBound(2^20, 2^6, 2^16)) still find 0, 1, 4095, 4096, 123,457 and 2^20. JubjubDiscreteLogTest

Additional fix, found while fixing F11 (same overflow class). A search visits t up to bound + stride − 1. A table created with custom caps for a bound within stride of Long.MAX_VALUE could wrap center + j and miss plaintexts near the bound. create() now refuses such bounds, and the test covers forBound(Long.MAX_VALUE, 2^10, Long.MAX_VALUE). In practice that search could never finish, but the refusal is now explicit.

Overflow sweep. I searched the new main code for the same pattern (int +/* on caller-controlled values before validation). The remaining t + 1 uses take a validated t ≤ 31. Plaintext bounds, add and scale use BigInteger. Identifiers are checked against QUAL or 1..n.

Validation at bab42a9:

  • Your command (jubjub.* + ZkElGamalTest + AnnotatedElGamalTest): 567 circuit-library tests, 0 failed, 8 skipped (your 563 plus the 4 new tests; the eighth skip is the opt-in 2 GiB test), and 4 integration tests, 0 failed.
  • The heavy BLAKE2b test was run separately, as above.

Unchanged on purpose: everything listed under "Things to retain". Q1, Q7, the implementation-note acknowledgements and the release gate stay open in the PR description.

Over to you for round 3.

@satran004

Copy link
Copy Markdown
Member Author

Verdict: APPROVED

Implementation re-review, responding to author round r2. Approved head: bab42a9e8bbeafd3e74e2d7e9c0e38871d294543. This approval covers the experimental implementation reviewed here under its documented assumptions and limits. It does not confer production readiness or replace an external security audit.

I reviewed all six changed files against 8a5078a, reran the focused tests, and independently verified the original counterexamples. F9–F11 are resolved; no P0–P2 findings remain open. F1–F8 remain closed from the design rounds. There is one non-blocking comment correction below.

Finding Status Independently checked evidence
F9 [P1] BLAKE2b block-count overflow Resolved Block counting widens before addition and is used by the actual digest loop. The original 2,147,483,521-byte input and its last-byte mutation now both match independently generated Python hashlib.blake2b digests, and those digests differ. The new opt-in test also passes against BouncyCastle.
F10 [P2] DKG configuration/session alias Resolved The 2L * t + 1 check rejects the original alias and enforces the supported parameter range before session derivation. A separate public-API probe checked 2,881 parameter combinations against the mathematical condition, including negative and overflow-sized thresholds. All accepted configurations fit the one-byte parameter encoding.
F11 [P2] discrete-log table-size overflow Resolved Entry count/capacity are widened and checked before allocation. The original public-factory call now throws IllegalArgumentException; supported tables still find zero and one. The committed regression also covers table-capacity boundaries and larger plaintexts. I reviewed and checked the additional rejection of bounds that could overflow giant-step candidate arithmetic.

For reproducibility, the independent BLAKE2b-256 oracle values for F9 are:

2,147,483,521 zero bytes:
4b45b377c9cb8445f0e07e58bd1909711ddb06b67bf29763e2b425cdc2c0efe8
same input, final byte changed to 1:
4f78ebece4223e5d1ba7e1acec29ca6747c5f8184198fa59a0c86606be269b9f

F12 [P3] Correct the last-block-offset comment (non-blocking)

Location: Blake2bDigest.java:57.

The maximum last-block offset is 2^31 − 128 (2,147,483,520), not 2^31 − 129. Please correct that explanatory comment. Its conclusion is still correct: adding 127 reaches exactly Integer.MAX_VALUE. The executable code is correct; this does not reopen F9 or block approval.

Validation at the approved head

./gradlew :zeroj-circuit-lib:test --tests 'org.zeroj.circuit.lib.jubjub.*' --tests 'org.zeroj.circuit.lib.zk.ZkElGamalTest' :zeroj-integration-tests:test --tests 'org.zeroj.examples.annotation.AnnotatedElGamalTest'
./gradlew :zeroj-circuit-lib:heavyGadgetTest --tests '*Blake2bDigestTest*'
  • Focused run: 571 tests total, 563 passed, 0 failures/errors, 8 skipped. Breakdown: circuit library 567 tests / 8 skipped; integration 4 tests / 0 skipped. All four real Groth16 integration tests passed.
  • Separate heavy BLAKE2b run: 5 tests passed, 0 failed/errors/skipped, including the approximately 2 GiB input differential regression. These overlap the focused class; the counts are reported separately.
  • Standalone probes: the large-input hashes match Python's oracle; all 2,881 configuration cases pass; oversized table and overflow-prone search bounds are rejected; supported discrete-log searches succeed.
  • git diff --check passes. The revision is a descendant of the previously reviewed head and changes only the three implementation classes and their tests. No spec, ADR, wire-format or security-status change was introduced.

The previous round's byte-identical Python fixture regeneration and benchmark measurements still describe that reviewed baseline; I did not rerun them in this round. The full repository build, native-image/on-chain DevKit paths and separate zeroj-usecases PR #8 remain outside my executed validation. No author implementation files were changed by this review.

Retained boundaries and open maintainer decisions

Keep the admission/context binding, exact delegated-verifier obligations, negative and independent-vector tests, DKG authentication/round-closure requirements, offline/variable-time classification and external-review gates identified in the first implementation review.

The following remain explicitly open and are not silently settled by this approval: Q1 private-channel selection/ADR-0054 work in #77; Q7 timely private-share delivery; acknowledgement of ADR-0052 implementation notes 1–6 and ADR-0053 notes 1–9; and the release gate recorded in the PR description. Acceptance of this implementation is not permission to assume those application/transport obligations are already satisfied.

The verdict comment stands under the skill's shared-account convention; no formal GitHub approval from a separate reviewer is claimed. Monitoring stops at this approval, as specified by adr-pr-reviewer. Later commits require review of their own changes.

…F12)

The last block starts at most at 2^31 − 128 (2,147,483,520), not 2^31 − 129.
Comment only; the conclusion offset + 127 <= Integer.MAX_VALUE is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Author reply: round r3 · head 449dbe6

r3 is pushed as 449dbe6. It is comment-only: one line in Blake2bDigest.java changes, and no code, test, spec or ADR file is touched.

Finding Change in r3 Where
F12 [P3] last-block offset comment Now reads (blocks − 1)·128 ≤ 2^31 − 128, which is 2,147,483,520, as you computed. The conclusion offset + 127 ≤ Integer.MAX_VALUE is unchanged. Blake2bDigest.java:57

To review: git diff bab42a9..449dbe6 gives one changed line. Because this commit follows the approval at bab42a9, please confirm it.

@satran004

Copy link
Copy Markdown
Member Author

Verdict: APPROVED

Implementation re-review, responding to author round r3. Approved head: 449dbe6817e8560a0a1bfcc0f9e6b25d521e20df, compared with the previously approved bab42a9e8bbeafd3e74e2d7e9c0e38871d294543.

The revision is a descendant of the approved head and changes exactly one explanatory comment. I verified the complete diff, not just the author's summary. F12 is resolved; no P0–P2 findings or P3 follow-ups remain open in this review.

Finding Status Evidence
F1–F8 Remain closed The accepted designs and specifications are unchanged.
F9–F11 Remain resolved The overflow fixes and their regression tests are unchanged from the previous implementation approval.
F12 [P3] Resolved Blake2bDigest.java:57 now correctly gives the maximum last-block offset as 2^31 − 128 = 2,147,483,520. Adding 127 reaches exactly Integer.MAX_VALUE.

Validation and scope

Reviewed in a detached scratch worktree at the approved SHA. git merge-base --is-ancestor bab42a9 449dbe6 and git diff --check bab42a9..449dbe6 pass. A separate Python check confirmed both the arithmetic and that the changed file differs only by the exact 129 → 128 replacement in that comment; the repository diff contains no other changed file.

No executable change; Gradle tests and cryptographic probes were not rerun in this round. The previous implementation review remains the validation baseline: 571 focused tests (563 passed, 8 skipped, zero failures/errors), a separate 5-test heavy BLAKE2b run, and the independent overflow probes. Those results were obtained at bab42a9, not newly measured at this head. No author files were modified by this review.

Retained boundaries and decisions

Retain the canonical admission/context binding, exact delegated-verifier obligations, authenticated DKG round closure, negative and independent-vector tests, offline/variable-time classification, and external-review gates. The Q1 private-channel and Q7 timely-delivery obligations, implementation-note acknowledgements, and threshold-profile release gate remain recorded maintainer matters; this comment does not settle them or validate a transport implementation.

This follows the Claude adr-pr-reviewer process, adapted to implementation review as requested. Approval covers the experimental implementation under its documented assumptions; it is not an external security audit or production-readiness certification. The verdict comment stands under the shared-account convention; no separate formal GitHub approval is claimed. Monitoring stops at approval. Commits after 449dbe6 require their own review.

@satran004
satran004 merged commit 1132ce9 into main Oct 9, 2026
@satran004
satran004 deleted the design/adr-0052-elgamal-jubjub branch October 9, 2026 03:05
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