Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/usecases/digital-product-passport.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

Prove product compliance without revealing trade secrets. EU-mandated, blockchain-anchored, ZK-verified.

> **Note (2026-10-11): read this with the current demo design.** This study was written before
> the demo was hardened. The first demo hashed each measurement with a secret that every
> manufacturer had to hold (and the demo published), so a 16-bit measurement could be recovered
> by trying every value against the mint datum, and the minting policy let the manufacturer pick
> its own threshold. A hash hides a value only if the attacker can't try every candidate, and a
> secret shared by every prover protects nothing. The demo now has the auditor commit each claim
> with a Pedersen commitment and a fresh 252-bit blinding, and mints an auditor-co-signed,
> locked passport ([zeroj-usecases ADR-0009](https://github.com/bloxbean/zeroj-usecases/blob/main/docs/adr/0009-privacy-and-binding-hardening-of-the-original-demos.md), D1). See the
> [product passport page](https://zeroj.dev/use-cases/digital-product-passport/) for that design.

## Table of Contents

- [Overview](#overview)
Expand Down
8 changes: 8 additions & 0 deletions docs/usecases/private-nft-ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Prove you own an NFT without revealing your wallet address.

> **Note (2026-10-11): two pitfalls fixed in the demo.** (1) A nullifier built only from public
> values, such as `Poseidon(nft_id, context)`, can be recomputed for every token in the
> collection, so it reveals which NFT (and wallet) was used: include a holder secret, as the demo
> now does with `Poseidon(Poseidon(secret, tokenName), contextId)`. (2) The on-chain list must
> admit exactly the nullifier the proof attests, or one proof can be reused. The scenarios below
> that use `Poseidon(nft_id, …)` need the same change. See [zeroj-usecases ADR-0009](https://github.com/bloxbean/zeroj-usecases/blob/main/docs/adr/0009-privacy-and-binding-hardening-of-the-original-demos.md), D2, and the
> [NFT ownership page](https://zeroj.dev/use-cases/nft-ownership/).

## Table of Contents

- [Overview](#overview)
Expand Down
37 changes: 30 additions & 7 deletions docs/usecases/private-voting.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

Trustless anonymous voting using zero-knowledge proofs on Cardano's UTXO model.

> **Correction (2026-10-11): the ballot design in this note does not keep votes secret.**
> It records each ballot as `commitment = Poseidon(vote, nullifier)`. The nullifier is public and a
> vote is only 0 or 1, so anyone can compute `Poseidon(0, nullifier)` and `Poseidon(1, nullifier)`
> and see which one matches. Every vote can be read from chain data: the design hides **who**
> voted, not **how**. A secret salt would stop the guessing, but then nobody could count the votes
> without each voter revealing the salt, and with it the vote.
>
> The zeroj-usecases `private-voting` demo now encrypts each ballot with exponential ElGamal
> (`elgamal-jubjub-v1`) under a key held by trustees, adds the ballots up while encrypted, and
> decrypts only the total
> ([zeroj-usecases ADR-0005](https://github.com/bloxbean/zeroj-usecases/blob/main/docs/adr/0005-private-ballot-homomorphic-tally.md),
> [issue #7](https://github.com/bloxbean/zeroj-usecases/issues/7)). See the
> [private voting page](https://zeroj.dev/use-cases/private-voting/) for that design.
>
> The rest of this note (nullifiers, the on-chain registry approaches, concurrency, cost, and the
> alternatives) still applies, because the encrypted ballot keeps the same voter list, nullifier
> and sorted-list registry. The code samples show the hash-ballot circuit and are illustrative only.

## Table of Contents

- [Overview](#overview)
Expand Down Expand Up @@ -64,14 +82,16 @@ Tx 1: addr_??? → voting_contract
proof: "I'm an eligible voter AND my vote is 0 or 1"
public: nullifier=0xABC, commitment=0x789

Nobody knows: who voted, what they voted, which address they used
Nobody knows: who voted, or which address they used
(with commitment = Poseidon(vote, nullifier), what they voted CAN be recovered:
see the correction at the top)
```

### What Each Party Sees

| Data | Voter | Smart Contract | Public |
|------|-------|---------------|--------|
| Vote (YES/NO) | Yes | No | No |
| Vote (YES/NO) | Yes | Recoverable from the commitment (see the correction) | Recoverable from the commitment |
| Voter identity | Yes | No | No |
| Secret key | Yes | No | No |
| Nullifier | Yes | Yes | Yes |
Expand Down Expand Up @@ -172,7 +192,9 @@ public class PrivateVoteCircuit implements CircuitSpec {
nullifier);

// 3. Commitment = Poseidon(vote, nullifier)
// Binds the vote to the nullifier (for tally verification)
// Binds the vote to the nullifier (for tally verification).
// NOT hiding: the nullifier is public and vote is 0 or 1, so anyone can
// recompute both candidates. The demo replaced this with an ElGamal ballot.
c.assertEqual(SignalPoseidon.hash(c, vote, nullifier), commitment);

// 4. Voter is in the eligible voter Merkle tree
Expand Down Expand Up @@ -570,6 +592,7 @@ var compressed = ProverToCardano.compressProof(proof);
│ │
│ 1. Read all nullifier nodes from chain │
│ 2. Each commitment is public → tally YES/NO from commitments │
│ (by recomputing Poseidon(0|1, nullifier): this reveals each vote)│
│ 3. Result is verifiable by anyone │
│ 4. Cleanup: burn tokens, reclaim ADA to treasury │
│ │
Expand All @@ -582,11 +605,11 @@ var compressed = ProverToCardano.compressProof(proof);
|----------|------------------|
| **One vote per person** | Nullifier is deterministic (same key + election = same hash) |
| **Can't fake identity** | Merkle proof ties secret key to voter list |
| **Vote is private** | Nullifier reveals nothing about YES/NO |
| **Vote is private** | **Not provided by this design.** The nullifier reveals nothing about YES/NO, but the commitment does (see the correction at the top). The encrypted ballot provides it. |
| **Votes unlinkable across elections** | Different electionId → different nullifier |
| **No trusted third party** | Sorted linked list is fully on-chain |
| **Censorship resistant** | Voters submit directly to Cardano |
| **Verifiable tally** | Commitments are public, anyone can count |
| **Verifiable tally** | Commitments are public, anyone can count, because anyone can read every vote |
| **ADA reclaimable** | Cleanup after election returns all locked ADA |

## Alternative Approaches
Expand Down Expand Up @@ -738,8 +761,8 @@ The coordinator (who has the decryption key) processes all votes and produces a
| | Sorted Linked List | MACI |
|---|---|---|
| **Vote buying resistance** | No — voter can prove their vote to briber | **Yes — voter can secretly change** |
| **Trust** | **Trustless** | Coordinator sees votes (can't change them) |
| **Privacy from public** | **Full** | **Full** |
| **Trust** | **Trustless** registry (the encrypted ballot adds trustees, who decrypt only the total) | Coordinator sees votes (can't change them) |
| **Privacy from public** | Identity only with the hash ballot; **full** with the encrypted ballot | **Full** |
| **Privacy from coordinator** | N/A | No (coordinator decrypts) |
| **Complexity** | Medium | High |
| **Best for** | Standard DAO governance | **High-stakes votes where buying is a threat** |
Expand Down
7 changes: 7 additions & 0 deletions docs/usecases/proof-of-reserves.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Prove solvency without revealing individual account balances.

> **Note (2026-10-11): salt the leaves.** A leaf `Poseidon(accountId, balance)` with a guessable id
> lets anyone who sees it (for example as a sibling in their own Merkle path) recover the balance
> by trying values. The demo now uses `Poseidon(Poseidon(idTag, salt), balance)` with a fresh
> 252-bit salt per account and snapshot, and mints the attestation only with a verified solvent
> proof. See [zeroj-usecases ADR-0009](https://github.com/bloxbean/zeroj-usecases/blob/main/docs/adr/0009-privacy-and-binding-hardening-of-the-original-demos.md), D4, and the
> [proof of reserves page](https://zeroj.dev/use-cases/proof-of-reserves/).

## Table of Contents

- [Overview](#overview)
Expand Down
9 changes: 9 additions & 0 deletions www/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export default defineConfig({
items: [{ autogenerate: { directory: 'learn' } }],
},
{ label: 'Tutorials', items: [{ autogenerate: { directory: 'tutorials' } }] },
{
label: 'Selective disclosure',
badge: { text: 'What to use when', variant: 'note' },
items: [{ autogenerate: { directory: 'selective-disclosure' } }],
},
{
label: 'Guides',
items: [
Expand All @@ -50,6 +55,10 @@ export default defineConfig({
label: 'Credentials & state',
items: [{ autogenerate: { directory: 'guides/credentials' } }],
},
{
label: 'Commitments & encryption',
items: [{ autogenerate: { directory: 'guides/confidential' } }],
},
],
},
{ label: 'Use cases', items: [{ autogenerate: { directory: 'use-cases' } }] },
Expand Down
8 changes: 8 additions & 0 deletions www/scripts/ai-artifacts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ZEROJ_DEV_VERSION,
ZEROJ_RELEASED,
ZEROJ_VERSION,
releasedSince,
replaceVersionTokens,
sourceRevision,
} from '../site.config.mjs';
Expand All @@ -37,10 +38,12 @@ export const SECTIONS = [
{ dir: 'start', title: 'Start here' },
{ dir: 'learn', title: 'Learn zero-knowledge (concepts)' },
{ dir: 'tutorials', title: 'Tutorials' },
{ dir: 'selective-disclosure', title: 'Selective disclosure: what to use when' },
{ dir: 'guides/circuits', title: 'Guides: circuits' },
{ dir: 'guides/proving', title: 'Guides: proving' },
{ dir: 'guides/verifying', title: 'Guides: verifying' },
{ dir: 'guides/credentials', title: 'Guides: credentials & state' },
{ dir: 'guides/confidential', title: 'Guides: commitments & encryption' },
{ dir: 'use-cases', title: 'Use cases' },
{ dir: 'reference', title: 'Reference' },
{ dir: 'ai', title: 'Build with AI' },
Expand Down Expand Up @@ -191,6 +194,11 @@ export function toPlainMarkdown(body, { mdx }) {
? ''
: `> **Caution:** ZeroJ ${ZEROJ_VERSION} isn't on Maven Central yet, so these snippets won't resolve until it's published. Build from source with \`./gradlew publishToMavenLocal\` meanwhile (local versions are \`${ZEROJ_VERSION}-<commit>-SNAPSHOT\`).`,
)
.replace(/<SinceNotice\s+since="([^"]+)"\s*\/>/g, (_, since) =>
releasedSince(since)
? ''
: `> **Note:** the APIs on this page are new in ZeroJ ${since} and not in a release on Maven Central yet (the latest is ${ZEROJ_VERSION}). Use a development snapshot (\`${since}-<commit>-SNAPSHOT\`) from https://repo.bloxbean.org/maven/snapshots to try them.`,
)
.replace(/<\/?(Steps|Tabs|CardGrid|FileTree|Card|TabItem|Aside)(\s[^>]*)?>/g, '');
}
text = convertDirectives(text);
Expand Down
3 changes: 3 additions & 0 deletions www/scripts/check-api-refs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ for (const b of blocks) {
}
const entries = byName.get(type);
if (!entries || docTypes.has(type) || EXTERNAL.has(type)) continue;
// The block imports a non-ZeroJ type with this simple name (java.security.Signature, say), so a
// ZeroJ type that shares the name isn't the one in use.
if (imported.has(type) && !imported.get(type).startsWith('org.zeroj.')) continue;
if (member === 'class' || member === 'length') continue;
if (!declares(entries, member)) {
// Enum constants/nested types declared in a nested type with the same simple name are covered by
Expand Down
20 changes: 20 additions & 0 deletions www/site.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ function readRelease() {
return release;
}

// Orders release versions such as 0.1.0-pre12 < 0.1.0-pre13 < 0.1.0. A pre-release sorts before
// the plain release of the same x.y.z.
export function compareVersions(a, b) {
const parse = (v) => {
const [core, pre] = v.split('-');
const pr = pre?.match(/^pre(\d+)$/);
return [...core.split('.').map(Number), pre ? (pr ? Number(pr[1]) : 0) : Infinity];
};
const x = parse(a);
const y = parse(b);
for (let i = 0; i < 4; i++) if (x[i] !== y[i]) return x[i] < y[i] ? -1 : 1;
return 0;
}

// True when the published release (release.json, and only once it is on Maven Central) contains
// features first shipped in `since`. Pages use it through <SinceNotice since="…" />.
export function releasedSince(since) {
return ZEROJ_RELEASED && compareVersions(ZEROJ_VERSION, since) >= 0;
}

export const VERSION_TOKENS = {
'%ZEROJ_VERSION%': ZEROJ_VERSION,
'%JULC_VERSION%': JULC_VERSION,
Expand Down
23 changes: 23 additions & 0 deletions www/src/components/SinceNotice.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
// Shown on pages that document APIs newer than the published release in release.json. Renders
// nothing once a release at or after `since` is on Maven Central. The AI exports get the same text
// (scripts/ai-artifacts.mjs).
import { Aside } from '@astrojs/starlight/components';
import { ZEROJ_VERSION, releasedSince } from '../../site.config.mjs';

interface Props {
since: string;
}
const { since } = Astro.props;
---

{
!releasedSince(since) && (
<Aside type="note" title={`New in ZeroJ ${since}, not released yet`}>
The APIs on this page are on <code>main</code> but aren't in a release on Maven Central yet
(the latest is {ZEROJ_VERSION}). To try them now, use a
<a href="/start/installation/#snapshots">development snapshot</a>, versioned{' '}
<code>{since}-&lt;commit&gt;-SNAPSHOT</code>.
</Aside>
)
}
Loading