Skip to main content
x0-zk-proofs is a Rust crate compiled to WebAssembly for client-side zero-knowledge proof generation. It wraps Solana’s solana-zk-token-sdk cryptographic primitives and exposes them via wasm-bindgen for use in browsers and Node.js.

Why Off-Chain?

Zero-knowledge proof generation is computationally expensive (elliptic curve operations, multi-exponentiation). Performing this on-chain would exceed Solana’s compute unit limits. Instead:
  1. Client generates proof — Using x0-zk-proofs in WASM (~50ms per proof)
  2. Client submits proof — Proof data included in transaction instruction
  3. On-chain verifier checks — x0-zk-verifier validates the proof (much cheaper than generation)

Installation

npm / yarn

From source

WASM-Exported Functions

version()

Returns the crate version string.

generate_pubkey_validity_proof(elgamal_keypair)

Generates a proof that an ElGamal public key is correctly derived from its secret.
Input: 64-byte ElGamal keypair (32-byte secret + 32-byte public key)
Output: 64-byte PubkeyValidityData proof

generate_withdraw_proof(elgamal_keypair, balance_ciphertext, withdraw_amount)

Generates a proof that a withdrawal is valid against an encrypted balance.
Input:
  • elgamal_keypair — 64-byte keypair
  • balance_ciphertext — 64-byte ElGamal ciphertext of current balance
  • withdraw_amountu64 amount to withdraw
Output: Object with proofData (160 bytes) and newBalance (BigInt)

generate_zero_balance_proof(elgamal_keypair, balance_ciphertext)

Generates a proof that an encrypted balance is zero.

decrypt_elgamal_u64(elgamal_keypair, ciphertext)

Decrypts an ElGamal ciphertext to recover the underlying u64 value.

Internal Architecture

Dependencies

Error Handling

All functions return JavaScript errors via JsValue. The internal error type:

SDK Integration

The TypeScript SDK wraps these WASM functions in a higher-level API:
See the SDK ZK Verifier Client for the full integration guide.

Test Coverage

The crate includes 47 native unit tests and 14 WASM integration tests covering:
  • ElGamal keypair reconstruction and roundtrip encryption/decryption
  • Proof generation for all four proof types
  • Edge cases: zero amounts, maximum amounts, wrong keypairs, invalid inputs
  • Full lifecycle: keypair generation → proof creation → bytemuck serialization
Last modified on February 8, 2026