ZeraLabs logo
WALLET

Testing & Security

Test suite, invariants, circuit integrity, OFAC compliance, and post-quantum analysis

The SDK ships with 144 tests covering crypto primitives, Merkle operations, proof generation, transaction building, and note management.

Test Coverage

# Run the full test suite
pnpm test
# Test categories:
├── crypto/poseidon — hash consistency, field boundaries, circomlibjs compat
├── crypto/keccak — commitment generation, recipient hashing
├── note — creation, commitment, nullifier derivation
├── merkle-tree — insert, proof, root, capacity bounds
├── prover — deposit/withdraw/transfer proof generation
├── tx/deposit — transaction builder output validation
├── tx/withdraw — nullifier PDA derivation, proof embedding
├── tx/transfer — 1-input 2-output value conservation
├── pda — deterministic address derivation
├── tree-state — on-chain sync, incremental leaf fetching
├── note-store — memory and file backend persistence
├── voucher — parse, validate, legacy format detection
└── utils — field conversion, byte formatting

Critical Invariants

These properties must hold for the system to be secure. Every PR is tested against them:

// 1. Commitment uniqueness
// Two different notes MUST produce different commitments
assert(computeCommitment(noteA) !== computeCommitment(noteB))
// 2. Nullifier determinism
// Same secret + commitment ALWAYS produces the same nullifier
assert(computeNullifier(s, c) === computeNullifier(s, c))
// 3. Nullifier unlinkability
// Different secrets produce different nullifiers for same commitment
assert(computeNullifier(s1, c) !== computeNullifier(s2, c))
// 4. Value conservation (transfer circuit)
// input.amount === output1.amount + output2.amount
// Enforced inside the Groth16 circuit — prover cannot cheat
// 5. Merkle inclusion
// A valid proof must reference a root in the 100-entry history buffer
// Stale roots are rejected on-chain
// 6. Field boundary
// All values must be < BN254_PRIME
// Overflow would break proof soundness

Circuit Integrity Verification

Before generating any proof, verify the circuit files haven't been tampered with:

// The wallet SHA-256 hashes WASM and zkey files before proving
// This prevents supply-chain attacks where a malicious circuit
// could generate valid-looking proofs that leak secrets
// Expected hashes are pinned in the application
// Any mismatch aborts proof generation immediately
// Verification happens client-side before every proof:
// 1. Fetch circuit file (WASM or zkey)
// 2. Compute SHA-256 digest
// 3. Compare against pinned expected hash
// 4. Abort if mismatch — do NOT generate proof

On-Chain Verification

// The Solana program performs these checks:
// 1. Groth16 proof verification via alt_bn128 precompile
// 2. Nullifier PDA existence check (double-spend prevention)
// 3. Merkle root membership in 100-entry history buffer
// 4. Token balance sufficiency for deposits
// 5. Fee calculation and vault transfer
// If ANY check fails, the entire transaction reverts
// No partial execution — atomic by Solana's runtime guarantee

OFAC Compliance

The desktop wallet integrates TRM Labs for address screening:

// Desktop wallet (Tauri) performs OFAC screening before transactions
// Integration via TRM Labs API — address-only, no KYC, no identity
// Risk categories: LOW | MEDIUM | HIGH | UNKNOWN
// Block categories: sanctions, OFAC, terrorist financing,
// darknet, ransomware, stolen funds, child exploitation, mixers
// CRITICAL: Fails closed on ANY API error
// If TRM is unreachable, the transaction is blocked by default
// This is a deliberate safety choice — never transact blind

Comprehensive security analysis of Zera's deployed privacy system — Poseidon X5 commitments, Groth16 zk-SNARKs over BN254, incremental Merkle tree accumulation, and on-chain verification via Solana's alt_bn128 precompile.

Deployed Cryptographic Primitives

Zera's security rests on a concrete stack of cryptographic primitives, each with well-characterized security assumptions and quantum-resistance properties.

Cryptographic PrimitiveMathematical DefinitionSecurity PropertiesQuantum Resistance
Poseidon X5 HashPoseidon: F_p^n → F_pCollision resistance, preimage resistanceAlgebraic; not broken by Shor
Commitment SchemePoseidon(amt, sec, blind, ...)Computational hiding + bindingHash-based; quantum-resistant
Groth16 zk-SNARKBN254 pairing: e(A,B) checkKnowledge soundness, zero-knowledgeBN254 pairings vulnerable to Shor
Merkle Accumulator24-level Poseidon treeBinding, append-only, tamper-evidentHash-based; quantum-resistant
Nullifier SystemN = Poseidon(secret, C)Deterministic, unlinkable, non-replayableHash-based; quantum-resistant
Binding & Hiding
Poseidon commitments are computationally binding (collision resistance) and computationally hiding (preimage resistance with high-entropy secret/blinding inputs). Both properties hold under the algebraic hardness assumptions of the Poseidon X5 permutation over F_p.
Groth16 Soundness
Knowledge soundness relies on the Knowledge-of-Exponent Assumption (KEA) on BN254. The trusted setup produces a structured reference string (SRS); security requires at least one honest ceremony participant. Zero-knowledge is achieved via simulation with the SRS trapdoor.

Post-Quantum Threat Surface

Most privacy protocols are built entirely on elliptic curves — keys, commitments, proofs, everything. A cryptographically relevant quantum computer running Shor's algorithm would break all of it in one shot. ZERA's architecture is different: the privacy layer is predominantly hash-based. Here's the exact breakdown.

ComponentPrimitiveQuantum StatusWhy
CommitmentsPoseidon X5 hashSAFEHash-based. Grover gives sqrt speedup (254-bit to ~127-bit effective). No EC dependency.
NullifiersPoseidon(secret, C)SAFEPure hash derivation. Determinism + unlinkability preserved under quantum.
Merkle Tree24-level PoseidonSAFEHash-based accumulator. Membership proofs rely only on collision resistance.
Wallet EncryptionChaCha20-Poly1305SAFESymmetric cipher. 256-bit key to ~128-bit effective under Grover. Still strong.
Proof SystemGroth16 / BN254VULNERABLEBN254 pairing relies on ECDLP. Shor's algorithm solves this in polynomial time.
Wallet SignaturesEd25519 (Solana)VULNERABLESolana protocol-level. Shor breaks Ed25519. This is an ecosystem-wide problem, not ZERA-specific.
Viewing KeysX25519 ECDHVULNERABLECurve25519 key exchange in desktop wallet. Shor breaks this.

The Core Privacy Layer Is Already Post-Quantum

This is the critical distinction: the data that protects your privacy — what you deposited, how much, who you sent it to — is bound by Poseidon hashes, not elliptic curves. A quantum computer could forge Groth16 proofs, but it cannot reverse Poseidon commitments, derive nullifier preimages, or break Merkle inclusion proofs. Your shielded balances remain private even in a post-quantum world.

What a Quantum Attacker Could Do

Forge Groth16 proofs — meaning they could fabricate deposits or withdrawals that the on-chain verifier would accept. This is a soundness break, not a privacy break. The mitigation is replacing Groth16 with a hash-based proof system (STARKs) or a lattice-based SNARK. The Poseidon commitment layer stays untouched during that migration.

Migration Path: Groth16 to STARKs

STARKs (Scalable Transparent ARguments of Knowledge) are hash-based and quantum-resistant. The tradeoff: proof size grows from ~200 bytes (Groth16) to ~50-100 KB, and on-chain verification cost increases. But the commitment layer, nullifier system, and Merkle tree are already STARK-compatible — they're designed around Poseidon, which is the standard hash for both Groth16 circuits and STARK AIR constraints. This is not a coincidence.

Winternitz One-Time Signatures (WOTS) & Hash-Based Hardening

Winternitz One-Time Signatures are a hash-based signature scheme used in XMSS and SPHINCS+. They rely only on hash function security — no elliptic curves, no pairings, fully quantum-resistant. The question is whether WOTS can harden ZERA's protocol.

Where WOTS Fits

  • Note ownership authorization: A WOTS signature chain over the Poseidon commitment hash could provide a hash-based one-time authorization layer for spending notes — independent of Ed25519 or any EC primitive.
  • NFC bearer instruments: An NFC tag could carry a WOTS key pair alongside the note secret. The one-time nature of WOTS is a natural fit for bearer instruments where each tag is spent exactly once.
  • Viewing key replacement: Replace X25519 ECDH with a WOTS-based key exchange for encrypted note sharing between parties.

Where WOTS Does Not Fit

  • Solana wallet signatures: Ed25519 is baked into the Solana runtime. ZERA cannot unilaterally replace it. This is an ecosystem-wide migration (Solana, Ethereum, etc.) that must happen at the protocol level.
  • Proof system: WOTS is a signature scheme, not a proof system. Replacing Groth16 requires STARKs or lattice-based SNARKs, not signatures.

WOTS + Poseidon: A Natural Pairing

Both WOTS and Poseidon operate in the hash-based security model. A WOTS chain using Poseidon as its hash function would be fully consistent with the existing commitment and nullifier infrastructure — same field, same assumptions, same quantum resistance. This is an active area of research for ZERA's post-quantum hardening roadmap.

Quantum Migration Surface Area

Most crypto protocols — Bitcoin, Ethereum, Solana, Zcash, Monero — would require full-stack quantum migration: keys, signatures, commitments, proofs, everything. ZERA's migration surface is comparatively small.

Migration StepScopeComplexity
Groth16 to STARKsReplace proof system; retain Poseidon circuitsMedium — circuit logic stays, prover/verifier changes
X25519 to WOTS/SPHINCS+Desktop wallet viewing keys onlyLow — isolated to note encryption layer
Ed25519 to PQ sigsSolana ecosystem-wide migrationNot ours to solve — blocked on Solana Labs

Bottom line: ZERA needs to migrate one component (Groth16 to STARKs) to achieve full post-quantum privacy. Most protocols need to migrate everything.

Implementation Stack

  • Rust on-chain: light-poseidon 0.4, ark-bn254 0.5.0, ark-ff 0.5.0, groth16-solana 0.2.0
  • TypeScript client: circomlibjs (Poseidon), snarkjs (Groth16), @noble/hashes (Keccak-256)
  • Desktop wallet: X25519-Dalek v2 (viewing keys), ChaCha20-Poly1305 (note encryption), Argon2id (KDF)
  • Field arithmetic: BN254 scalar field, p approx 2^254 (21888...95617)
  • Circuit integrity: SHA-256 verification of WASM/zkey files before proof generation
  • OFAC screening: TRM Labs API (address-only, fails closed on error)

More Developer Resources

Quick Start

Deposit in 15 lines with @zera-labs/sdk

SDK Reference

Complete function signatures, types, constants

Architecture & Performance

Stack diagram, proof gen times, deployment