|
1 | 1 | # shielded-circuits |
2 | 2 |
|
3 | | -> ZK circuits for the Shielded Protocol, built with Circom. |
| 3 | +> Circom ZK circuits for Shielded Protocol. |
4 | 4 |
|
5 | | -Part of [shielded-protocol](https://github.com/Shielded-Protocol) — |
| 5 | +Part of [Shielded Protocol](https://github.com/Shielded-Protocol) — |
6 | 6 | private, compliant DeFi on Stellar. |
7 | 7 |
|
8 | | -[](https://github.com/Shielded-Protocol/shielded-circuits/actions) |
| 8 | +[](https://github.com/Shielded-Protocol/shielded-circuits/actions/workflows/ci.yml) |
9 | 9 | [](https://drips.network/wave/stellar) |
| 10 | +[](https://github.com/Shielded-Protocol/shielded-circuits/issues) |
10 | 11 |
|
11 | | -## What this does |
| 12 | +--- |
12 | 13 |
|
13 | | -These circuits implement the zero-knowledge proof system (Groth16 over BN254) that powers private transactions on Stellar Soroban. Users generate proofs off-chain using these circuits, which are then verified on-chain by the `groth16-verifier` contract. |
| 14 | +## Circuits |
14 | 15 |
|
15 | | -The repository includes circuits for deposits, withdrawals, Merkle inclusion proofs, and nullifier derivation. |
| 16 | +| Circuit | Inputs (private) | Inputs (public) | Purpose | |
| 17 | +|---|---|---|---| |
| 18 | +| `withdraw.circom` | secret, amount, tokenId, pathElements, pathIndices | root, nullifierHash, recipient, relayer, fee | Main withdrawal proof | |
| 19 | +| `deposit.circom` | secret, amount, tokenId | — | Commitment generation | |
| 20 | +| `merkle_proof.circom` | leaf, pathElements, pathIndices | root | Merkle inclusion proof | |
| 21 | +| `nullifier_hash.circom` | secret | — | Nullifier derivation | |
16 | 22 |
|
17 | | -## Quickstart |
| 23 | +**Proving system:** Groth16 · **Curve:** BN254 · **Hash:** Poseidon · **Depth:** 20 |
18 | 24 |
|
19 | | -```bash |
| 25 | +--- |
| 26 | + |
| 27 | +## How the withdraw proof works |
| 28 | + |
| 29 | +``` |
| 30 | +Private: secret, amount, tokenId, Merkle path |
| 31 | + │ |
| 32 | + ▼ |
| 33 | + commitment = Poseidon(secret, amount, tokenId) |
| 34 | + │ |
| 35 | + ▼ |
| 36 | + Merkle proof: commitment ∈ tree with known root ──► Public: root |
| 37 | + │ |
| 38 | + nullifier = Poseidon(secret, 1) ──────────────► Public: nullifierHash |
| 39 | + │ |
| 40 | + recipient bound into proof ────────────────────────► Public: recipient |
| 41 | +``` |
| 42 | + |
| 43 | +The proof reveals nothing about the secret, amount, or which commitment is spent. |
| 44 | + |
| 45 | +Quickstart |
| 46 | +# Prerequisites: Node 20+, circom 2.x, snarkjs |
| 47 | + |
| 48 | +npm install -g circom snarkjs |
20 | 49 | npm install |
| 50 | + |
| 51 | +# Compile circuits (generates R1CS + WASM) |
21 | 52 | npm run compile |
| 53 | + |
| 54 | +# Run tests |
22 | 55 | npm test |
23 | | -``` |
24 | 56 |
|
25 | | -## Architecture |
| 57 | +--- |
| 58 | + |
| 59 | +## Constraint counts (approximate) |
| 60 | + |
| 61 | +| Circuit | Constraints | Notes | |
| 62 | +|---|---|---| |
| 63 | +| `withdraw` (depth 20) | ~26,000 | Dominated by Merkle path hashing | |
| 64 | +| `deposit` | ~200 | Simple Poseidon hash | |
| 65 | +| `merkle_proof` (depth 20) | ~24,000 | 20 × Poseidon2 | |
| 66 | +| `nullifier_hash` | ~100 | Single Poseidon2 | |
26 | 67 |
|
27 | | -[Link to shielded-docs](https://github.com/Shielded-Protocol/shielded-docs) |
| 68 | +See issue [#constraint-reduction](https://github.com/Shielded-Protocol/shielded-circuits/issues) |
| 69 | +for optimization work. |
| 70 | + |
| 71 | +--- |
28 | 72 |
|
29 | 73 | ## Contributing |
30 | 74 |
|
31 | | -See [CONTRIBUTING.md](./CONTRIBUTING.md). |
32 | | -Browse [Wave-ready issues](../../issues?q=label%3Astatus%3Awave-ready). |
| 75 | +See [CONTRIBUTING.md](./CONTRIBUTING.md). |
| 76 | + |
| 77 | +Browse [Wave-ready issues](https://github.com/Shielded-Protocol/shielded-circuits/issues?q=label%3Astatus%3Awave-ready+state%3Aopen). |
| 78 | + |
| 79 | +--- |
33 | 80 |
|
34 | 81 | ## License |
35 | 82 |
|
|
0 commit comments