Skip to content

Private ballots with a homomorphic tally (fixes #7) + Pedersen commitment demos - #8

Closed
satran004 wants to merge 12 commits into
mainfrom
feat/pedersen-private-ballot-and-demos
Closed

satran004 wants to merge 12 commits into
mainfrom
feat/pedersen-private-ballot-and-demos

Conversation

@satran004

@satran004 satran004 commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #7, and adds three new Pedersen commitment use cases. Built against ZeroJ's Pedersen commitment profiles (bloxbean/zeroj#73, ADR-0051) and its elgamal-jubjub-v1 profile (bloxbean/zeroj#76, ADR-0052; this PR is that ADR's milestone M3).

ZeroJ version. version.properties pins the released zerojVersion=0.1.0-pre13 from Maven Central (935bf93).

1. private-voting: votes are now actually private (#7)

Before, the ballot was Poseidon(vote, nullifier) with a public nullifier, so anyone could decode every vote, and the tally did exactly that.

Now each ballot is an exponential ElGamal encryption on Jubjub, A = [k]G, B = [v]G + [k]PK. The key is shared n-of-n by three trustees, each of whom proves possession of their share.

  • Ballot proof (Groth16, verified on-chain). It shows that the voter is eligible, that the nullifier is theirs, and that the ballot encrypts a 0 or a 1. One scalar decomposition drives both [k]G and [k]PK.
  • Tally. The ballots are added while still encrypted. After an on-chain deadline, each trustee decrypts its share of the sum only, once, and proves its share with a Groth16 DLEQ proof. ΣB − ΣD = [YES]·G.
  • Verification from public data. The tally re-checks:
    • the election manifest (keys, key proofs, verification keys, scripts);
    • the script hashes, and the seed binding (the root was minted once, by the seed's spender);
    • a ballot-set digest;
    • every share proof, and the total.
  • The UI shows only encrypted ballots until voting closes, then the total, the trustee shares and the verification checks.

The redesign also closes on-chain binding gaps (ADR-0005 G1–G5):

  • G1: the election id, voter root and election key were taken from the redeemer, so a proof against an attacker's own voter tree was accepted. They are now script parameters.
  • G2: the list key is now the nullifier, the stored ballot is the proved one, and exactly one unit of the nullifier token may exist in the outputs. Before, a voter could re-mint the nullifier token and vote twice.
  • G3: an insert may spend only its anchor, and node values and datums are exact. Before, an insert could spend and rewrite other voters' nodes.
  • G4: ballots must be valid no later than the deadline.
  • G5: the list root is one-shot, via a seed output. Before, a second root started a parallel list.

2. New: pedersen-commitments/, three demos (ADR-0006)

Demo Shows On-chain
A. Confidential points Hidden amounts that still add up (in = out1 + out2; in = change + public price) PointsLedger multi-validator: issuer-only supply, owner-signed spends, unforgeable one-time receipts
B. Committed credential gate One vector commitment to four attributes; prove income ≥ X ∧ score ≥ Y and nothing else CreditGatePolicy: an issuance record (bound to commitment, schema and holder) is required; the badge goes to the holder
C. Hidden-liability solvency Per-customer commitments: customers check their own entry, an auditor opens the total by homomorphism, Σ ≤ R is proved SolvencyVault, one script per public attestation period: attest only before the period, release only after it, so all of a period's attestations are locked at the same time and reserves cannot be reused one after another

There is a CLI walkthrough, ./gradlew run, plus tests. It has no web UI.

Build fixes (2026-10-12)

  • 935bf93: pin ZeroJ 0.1.0-pre13, and the Docker demos use it.
    • Before this, the demo images passed -PzerojVersion=${ZEROJ_VERSION}, which defaulted to 0.1.0-pre12 in compose.demo.yml, compose.yml and both Dockerfiles. So ./demo.sh ignored version.properties and built against an older ZeroJ.
    • The images now copy version.properties and pass -PzerojVersion only when ZEROJ_VERSION is set.
  • a809d1d: add the Gradle wrapper jar to the nine modules that lacked it.
    • .gitignore's *.jar rule also excluded gradle-wrapper.jar. So on a fresh clone, ./gradlew failed in those modules, and ./demo.sh failed with Could not find or load main class org.gradle.wrapper.GradleWrapperMain.
    • The added jar is the official Gradle 9.2.0 wrapper. Its SHA-256 matches Gradle's published 423cb469….
    • .gitignore now re-includes gradle-wrapper.jar.
  • Verified from a fresh clone of the stack head (Privacy and binding hardening of the original demos (ADR-0009) #10):
    • ./demo.sh proof-of-reserves --clean-cache --run built the image against the 0.1.0-pre13 jars and minted a solvent attestation on Yaci DevKit.
    • ZEROJ_YACI_E2E=true ./gradlew test in proof-of-reserves passed 61 tests with 0 failures.

Testing (local, Yaci DevKit)

  • Independent reference. A Python reimplementation of Jubjub ElGamal and the tally, from the curve definition, produces vectors that the Java code matches exactly.
  • Circuits. Honest cases prove and verify; every public input is bound. These have no witness:
    • v = 2, or A and B from different k;
    • another key, or an identity key;
    • unbalanced or wrapped amounts;
    • values below a threshold, or another schema;
    • an insolvent book.
  • Plutus VM mutation tests for every invariant (ADR-0005 V1–V12; ADR-0006 P1–P8, C1–C5, S1–S7). I removed each of these rules and confirmed a test then fails: the one-unit nullifier rule, the exact anchor datum, Split's one-input rule, and the vault's period-start bound.
  • DevKit end-to-end. Each run includes rejections by the scripts themselves, not just the client. A rejection here is the script failing in local Julc evaluation of the real transaction, as the node would run it; rejected transactions are not submitted, because that would cost collateral.
    • Election: three encrypted ballots; rejected: a swapped ballot, a double vote forced past the client, and a post-deadline ballot; the tally decrypts to 2 YES, 1 NO and every check passes.
    • Points: issue, transfer and redeem; rejected: a proof for other commitments, and a spend not signed by the owner.
    • Credential: badge minted; rejected: a claim with no issuance record, and an impostor.
    • Solvency: attest before the period; during it, customers and the auditor check every attestation of the period from chain data; rejected: a second attestation and a release inside the period; after it, the release succeeds.
  • Smoke test. The Spring app ran on DevKit: vote, double-vote refusal, the results page before and after the deadline, and the manifest.
cd private-voting && ./gradlew test && ZEROJ_YACI_E2E=true ./gradlew test
cd pedersen-commitments && ./gradlew test && ZEROJ_YACI_E2E=true ./gradlew test && ./gradlew run

Reviews

Both ADRs and both implementations went through independent adversarial reviews, and the findings are fixed. The fixes include:

  • the pre-minted nullifier-copy attack;
  • an anchor-datum extra-field DoS on the tally;
  • a movable solvency attestation, and reserves reused across sequential attestations (now fixed by attestation periods);
  • forgeable redemption receipts;
  • an unconstrained badge destination.

Not production-ready (documented)

  • Single-party dev trusted setups.
  • Trustees: n-of-n with no DKG, and in this demo all of them run in the backend, which therefore knows every vote.
  • Missing protections: no receipt-freeness, no relayer, unauthenticated demo endpoints.
  • See the "Not provided" sections in ADR-0005, ADR-0006 and the READMEs.

🤖 Generated with Claude Code

satran004 and others added 9 commits October 5, 2026 00:04
Ballots were Poseidon(vote, nullifier) with a public nullifier, so every
vote could be decoded from chain data. Replace them with exponential
ElGamal on Jubjub under an election key shared n-of-n by three trustees
(ADR-0005). The ballot proof shows eligibility, the nullifier, and that
(A, B) encrypts 0 or 1; the sum of all ballots is decrypted once, after an
on-chain deadline, with a Groth16 DLEQ proof per trustee share.

Also closes binding gaps found while redesigning:
- G1: election id, voter root and election key are script parameters
- G2: the list key is the nullifier; the stored ballot is the proved one;
  exactly one unit of the nullifier token may exist in the outputs
- G3: an insert spends exactly one list node; node values are exact
- G4: ballots must be valid no later than the voting deadline
- G5: the list root is one-shot (seed output)

The tally walks the list from its root and fails closed, publishes a
ballot-set digest, and re-verifies the manifest, script hashes, key
proofs, share proofs and the total from public data.

Tests: host ElGamal vs an independent Python reference, circuit
negatives, Plutus VM mutations for every gap, DevKit E2E election.
Builds against a local ZeroJ 0.1.0-pre13 snapshot (bloxbean/zeroj#73).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- P1: the continuing anchor's datum and the list root are now exact
  on-chain. A field-by-field read accepted ListElement with an extra
  field, which the off-chain walk rejects, so anyone copying a mempool
  ballot could make the election untallyable. Off-chain parsing mirrors
  on-chain acceptance (constructor 0, exactly two fields).
- Tests: the pre-minted copy placed after the node (the order a
  "last holder wins" read would accept), N + p nullifier names, foreign
  election id / key, staked outputs, non-root anchors (order violation,
  duplicate key, dropped nullifier), exact root. Removing the one-unit
  rule or the exact anchor datum now fails a VM test (checked).
- DevKit: the double vote and the post-deadline ballot are forced past
  the client and rejected by the scripts on the ledger path.
- Manifest: full verification keys and parameter-applied scripts; the
  seed is bound to chain data (root token minted once, by the seed's
  spender).
- Tally reads chain time before ballots; the ballot-set digest is
  domain-separated and bound to the election id and list policy;
  status no longer deploys scripts; creating an election is refused
  once one is finalized; key caches are keyed by an R1CS digest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New usecase project (ADR-0006) with Pedersen commitment demos on Yaci DevKit.

A. Confidential points: notes whose amounts are pedersen-jubjub-v1
   commitments. PointsLedger (one multi-validator: policy + note address)
   issues notes (issuer-signed), splits a note with a proof of
   in = out1 + out2 over hidden 64-bit amounts, and redeems a public price
   with a proof of in = change + price; a redemption mints a receipt token
   named after the redeemed note, so receipts cannot be forged or replayed.

B. Committed credential gate: a bureau commits to a credit profile
   (income, credit_score, birth_year, country) as one vector commitment
   and records the issuance on-chain (token name binds u, v, σ, holder).
   CreditGatePolicy mints a badge, paid to the holder, for a proof of
   income >= min and credit_score >= min against the record, revealing
   nothing else.

Tests: circuit honest/negative cases, Plutus VM mutation tests for every
invariant (P1-P8, C1-C5), and DevKit end-to-end runs with on-ledger
script rejections.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
C. Solvency with hidden liabilities (Provisions-style): one commitment per
   customer balance, a proof that the hidden total is at most the reserve
   locked in SolvencyVault, a per-customer inclusion check by opening, and
   an auditor opening of the total by homomorphism. The vault keeps the
   reserve and the attestation fixed until unlockAfter (release burns the
   token), so reserves cannot back two attestations or be swapped out.

Also: the ./gradlew run walkthrough of all three demos on DevKit, the
project README, and registration in build.gradle, build-all.sh and the
repository README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- P0 (solvency): the same reserves could back attestations one after
  another (attest, let customers check, release, re-attest for others).
  Attestations are now bound to a public period: each period has its own
  vault script; attest only with a validity range ending by periodStart,
  release only from periodEnd, vault output at the exact enterprise
  address. Every attestation of a period is locked for the whole period
  at once (ADR-0006 r3, S7).
- Customer check: derive the period's vault script, read every live
  attestation at its address, require the entry exactly once across all
  of them. ADR states the id-uniqueness and trusted-setup requirements.
- Points: the receipt names the spender, not the change owner (wallet
  bug); the price binding is now isolated in the VM test (redeemer and
  receipt agree, only the proof rejects); new mint-side negatives (Split
  with no note spent, Receipt with zero or two notes or a short name);
  the two-token note mutation is isolated.
- Credential: the non-canonical u mutation is isolated (record built for
  the same u + p).
- Removing Split's one-input rule or the vault's period-start bound now
  fails a VM test (checked). Circuit allows N <= 16 (on-chain budget).
- Wording: test rejections are scripts failing in local Julc evaluation,
  as the node would run them; rejected transactions are not submitted.

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

The guarantee is per period: each period's attestations must cover the
whole book, customers check every period they rely on, the schedule
publishes every vault parameter set for a period, and periodStart <
periodEnd is enforced where customers derive the vault.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Turn the module into a Spring Boot app (port 8093) like the other
usecases. Thin services drive the existing engine (ConfidentialPoints,
CreditGate, SolvencyAttestation) on Yaci DevKit: they create and fund
the demo wallets, hold the openings on the users' behalf, and expose the
private and the on-chain view of each demo plus its actions, including
the "try to cheat" ones. A false statement maps to "no proof possible"
(422); a validator rejection maps to an onChainValidation body (403).
Circuits and wallets warm up in the background; /api/status reports
readiness. The CLI walkthrough moves to `./gradlew walkthrough`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Svelte 5 + Vite (native fetch, no axios), built into
src/main/resources/static with -PwithFrontend. Each tab shows the
private side (openings held by the demo server) next to the on-chain
side, with actions and "try to cheat" cases:
- points: issue, transfer, redeem; overspend (no proof), spend
  someone else's note (rejected);
- credential: issue and record, claim a badge; threshold above the
  profile (no proof), impostor claim (rejected);
- solvency: book, attest for a period with a countdown, customer
  checks, auditor opening, release; insolvent (no proof), a second
  attestation or a release inside the period (rejected).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`./demo.sh pedersen` (alias of pedersen-commitments, port 8093) with a
--run happy path, a compose.demo.yml service and volume, and a
demo-cache manifest (no setup files committed; setups are generated on
first start). The README documents the UI, its tabs and configuration;
the root README lists the demo.

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

Copy link
Copy Markdown
Member Author

Web UI for pedersen-commitments (c61283d, b300947, 4677d28)

The Pedersen demos now have a Spring Boot + Svelte UI like the other usecases, on port 8093, with one tab per demo. Each tab shows the private side (the openings the demo server holds on the users' behalf) next to the on-chain side (what anyone can read). The UI says plainly that the server holds the keys and openings.

Tab Actions Try to cheat
A. Confidential points Issue, transfer (amounts hidden), redeem at a public price (the retailer gets a receipt token) Overspend: no proof possible. Spend someone else's note: validator rejects
B. Committed credential Bureau issues and records a profile; Alice claims a badge against the lender's thresholds Threshold above her profile: no proof possible. Mallory presents Alice's credential: gate rejects
C. Solvency Editable book; attest with locked reserves for a period, with a countdown; customer checks; auditor opening; release after the period Insolvent: no proof possible. Second attestation or release inside the period: vault rejects

Run

  • Jar: cd pedersen-commitments && ./gradlew clean bootJar -PwithFrontend && java --enable-native-access=ALL-UNNAMED -Dzeroj.allowInsecureTrustedSetup=true -jar build/libs/pedersen-commitments-*.jar, then open http://localhost:8093.
  • Docker: ./demo.sh pedersen [--run]. The image needs a ZeroJ release with ADR-0051, so until then use the jar.
  • The CLI walkthrough is now ./gradlew walkthrough.

Verified on Yaci DevKit

  • Every tab, driven in a browser:
    • points: issue, transfer, redeem, overspend (no proof), theft (rejected);
    • credential: issue, claim, a threshold above the profile (no proof), Mallory (rejected);
    • solvency: insolvent (no proof), attest, checks, audit, second attestation (rejected), release inside the period (rejected), release after the period.
  • API: the demo.sh --run sequence, every call against a fresh jar.
  • Tests: ./gradlew test and ZEROJ_YACI_E2E=true ./gradlew test (three DevKit E2E tests) pass.
  • Build: ./build-all.sh build -x test passes for all usecases.

Rejections are the scripts failing in local Julc evaluation of the real transaction, as the node would run them; rejected transactions are not submitted.

🤖 Generated with Claude Code

The demo's prototype ElGamal (JubjubElGamal, JubjubElGamalGadget) is replaced by
ZeroJ's elgamal-jubjub-v1 profile from zeroj PR #76:

- PrivateBallotProof v3 encrypts with ZkElGamal under a verifier-fixed key
  (vote @uint(bits=1)); TrusteeShareProof v2 is ZkElGamal's DLEQ relation.
  New circuit versions, so new setups and scripts; the DLEQ R1CS digest equals
  the prototype's.
- Services use the safe host API: ballots are admitted with a delegated
  EncryptionStatementVerifier backed by the chain (width, ballot policy, key,
  ciphertext match), and decryption shares are accepted only as
  VerifiedDecryptionShare built from verified DLEQ proofs.
- ElGamalCompatibilityTest shows the prototype's vectors decrypt identically.
- ADR-0005 r4 records the move; zerojVersion pinned to the local snapshot
  0.1.0-pre13-8a5078a-SNAPSHOT (zeroj #76 head) until a release.

Unit, circuit and Plutus VM tests pass, and the DevKit E2E tallies YES=2, NO=1.

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

Copy link
Copy Markdown
Member Author

private-voting now uses ZeroJ's elgamal-jubjub-v1 (7ad844f)

This is ZeroJ ADR-0052's milestone M3, the usecase migration (bloxbean/zeroj#76). ZeroJ is pinned to a local snapshot of #76's head, 0.1.0-pre13-8a5078a-SNAPSHOT. That deviates from the ADR's M3 entry gate, "a ZeroJ release containing it", by maintainer decision. zerojVersion must move to the public release before merge.

Changes

  • Prototype removed. JubjubElGamal, JubjubElGamalGadget and their test are deleted. The circuits use ZkElGamal.
  • Ballot proof v3. It encrypts under a verifier-fixed election key, with the vote declared @UInt(bits=1).
  • Trustee share proof v2. It is ZeroJ's DLEQ relation, and its R1CS digest is identical to the prototype's. The new circuit versions mean new setups and new script hashes.
  • Safe host API.
    • Ballots are admitted with a delegated EncryptionStatementVerifier backed by chain data: the ballot policy accepted the proof for this width, key and ciphertext.
    • Decryption shares count only as VerifiedDecryptionShare objects built from verified DLEQ proofs.
  • ElGamalCompatibilityTest. The prototype's vectors decrypt identically under the library.
  • Docs. ADR-0005 r4 and the README record the move.

Tests (against 8a5078a)

Suite Tests Failures Skipped
private-voting 16 0 1 (DevKit E2E, gated by an environment variable)
private-voting DevKit E2E 1 0 0
pedersen-commitments, with its 3 DevKit E2E tests 19 0 0

The private-voting election on DevKit tallies YES=2, NO=1.

satran004 and others added 2 commits October 12, 2026 18:43
…ion.properties

The Docker demo images passed -PzerojVersion=${ZEROJ_VERSION}, defaulting to 0.1.0-pre12 in
compose.demo.yml and both Dockerfiles, so ./demo.sh ignored version.properties and built
against an older ZeroJ. The images now copy version.properties and pass -PzerojVersion only
when ZEROJ_VERSION is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`*.jar` in .gitignore also excluded gradle/wrapper/gradle-wrapper.jar, so on a fresh clone
./gradlew failed in nine modules and ./demo.sh failed inside the Docker build with "Could not
find or load main class org.gradle.wrapper.GradleWrapperMain". .gitignore now re-includes
gradle-wrapper.jar.

The added jar is the official Gradle 9.2.0 wrapper, generated with the 9.2.0 distribution these
modules use; its SHA-256 matches services.gradle.org/distributions/gradle-9.2.0-wrapper.jar.sha256:
423cb469ccc0ecc31f0e4e1c309976198ccb734cdcbb7029d4bda0f18f57e8d9
The five modules that already tracked a jar keep the official Gradle 7.5 wrapper (91a23940…),
which runs 9.2.0 as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
satran004 added a commit that referenced this pull request Oct 12, 2026
…onfidential-notes-m3

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

# Conflicts:
#	version.properties
satran004 added a commit that referenced this pull request Oct 12, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004 satran004 closed this Nov 22, 2026
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.

private-voting: individual votes are publicly decodable (Poseidon(vote, nullifier) with public nullifier)

1 participant