A faithful port of Semaphore v4 to Soroban / Stellar: anonymous group membership + an epoch-scoped nullifier + an arbitrary signal, verified on-chain.
Semaphore v4 uses BN254 (Ethereum's alt_bn128) with Groth16. Soroban's BN254 host
functions are byte-for-byte EVM-compatible, so a proof and verification key produced by
Ethereum's Semaphore trusted-setup ceremony verify unchanged on Stellar — no new
ceremony required.
This repository is the core library. Confidential applications built on it live in their own repositories:
- semaphore-stellar-multisig — confidential custom accounts: single-signer, k-of-n threshold, and a proposal-based DAO.
- semaphore-stellar-relay — the payer-privacy relay: a relayer pays the fee for an anonymous member and is tipped from a pool.
- semaphore-stellar-groups — a trustless on-chain group tree: the Merkle root is computed on-chain (LeanIMT + circomlib Poseidon), so no admin can forge it.
contracts/verifier— a Groth16/BN254 verifier for Semaphore's 4 public inputs ([merkleTreeRoot, nullifier, hash(message), hash(scope)], IC has 5 points). Exposes a reusableverify_encodedplus averifycontract entry. Verified against a real ceremony proof on-chain (cargo test -p semaphore-verifier; also live on testnet).contracts/semaphore— the genericISemaphore-aligned library: groups (off-chain tree- on-chain root), a per-depth verification-key registry,
verify_proof(stateless) andvalidate_proof(consumes a group-scoped nullifier), with canonical-input (< r) checks.
- on-chain root), a per-depth verification-key registry,
groth16_verify checks the pairing identity in product form:
e(-A, B) · e(alpha, beta) · e(vk_x, gamma) · e(C, delta) == 1
vk_x = IC[0] + Σ pub_signals[i] · IC[i + 1]
via env.crypto().bn254().pairing_check. Point encoding is Soroban's uncompressed BN254
format: G1 = X‖Y (64 bytes), G2 = Xc1‖Xc0‖Yc1‖Yc0 (128 bytes, Fp2 imaginary first),
scalars are 32-byte big-endian field elements. Budget: a single verification is ~29M
instructions, well under the 100M mainnet per-tx limit.
cargo test # 8 tests (verifier 3, semaphore 5)
stellar contract buildThe full library flow runs live on testnet (deploy → register_vkey → create_group →
update_root → validate a real proof → replay rejected); see DEPLOYMENT.md and scripts/.
The fixture is generated, not hand-written — a real proof re-verified with snarkjs.groth16.verify
against the depth-2 ceremony vkey, then encoded for Soroban:
cd tools && npm install && node gen-fixture.mjs- Done: Groth16/BN254 verifier (real ceremony proof, on-chain) + the generic library, live
on testnet; root-validity window + admin transfer +
ISemaphoregetters; confidential multisig and payer-privacy relay (incl. a real on-chain__check_authand an explicit fee-bump) in their own repos. - On-chain trustless tree — done (in semaphore-stellar-groups, on sdk 28): LeanIMT + circomlib Poseidon computed on-chain, verified live on testnet; see docs/ONCHAIN-TREE-POSEIDON.md.
- Next: fold the on-chain tree into the sdk-29 library once the SDK exposes a public Poseidon; SEP drafts (membership interface + relay protocol).
⚠️ Prototype — unaudited, testnet only. This code has not been audited and runs only on Stellar testnet with small fixtures. Do not use it with real value or on mainnet.
verify_proofis a raw verification primitive (the caller suppliesmerkle_rootanddepth); it is not a membership check on its own.verify_with_onchain_rootreads the trustedgroupscontract from config — callset_trusted_groups(admin) first; it never accepts the groups address from the caller.- v1 uses an off-chain tree: a group admin's
update_group_rootcan set any root, so soundness reduces to trusting the group admin. The trustless alternative is the on-chaingroupscontract. - A superseded root stays valid for a ~24h window, so a just-removed member can still prove membership briefly.
- Storage TTL is managed: every state-changing call extends the instance storage and the relevant persistent entries (vkeys, groups, historical roots, nullifiers) by ~30 days (bumping when under ~15 days remain), so an actively-used contract never archives. A contract left completely idle past the bump window still needs a one-time Soroban
restore(state archival applies to every contract).
Proofs reuse Ethereum's Semaphore trusted-setup ceremony (no new ceremony is performed).
MIT — see LICENSE. Compatible with Semaphore (MIT, Ethereum Foundation / PSE).