Contract d69a7783fea7e1110f7393c491794d08b9ce56af6d1c56c0fc0829a29bab6bb6

← Back to Index 📥 Download WASM

Meta

rssdkver 22.0.8#f46e9e0610213bbb72285566f9dd960ff96d03d8
rsver 1.88.0

Instances

  • CCYZD2LAMVE65QLNOVJKRK5K522GJUIMVECR3F4PYWJGZTWE6PBCGH3W

Interface

Initialize the privacy contract

fn initialize(env: soroban_sdk::Env) -> Result<(), ContractError>

Deposit assets into the privacy pool Creates a commitment that hides the amount and recipient

In production, commitment = Poseidon(amount, secret, nullifier, recipient) For this demo, we use SHA-256 as Poseidon host functions require the actual X-Ray upgrade

fn deposit(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    token: soroban_sdk::Address,
    amount: i128,
    commitment: soroban_sdk::BytesN<32>,
) -> Result

Withdraw assets from the privacy pool Uses ZK proof to prove ownership without revealing which deposit is being spent

Parameters:

  • proof: ZK-SNARK proof (would use BN254 pairing check in production)
  • nullifier: Prevents double-spending (hash of secret)
  • recipient: Who receives the funds (hidden in transaction, visible in contract)
  • amount: Amount to withdraw (hidden from ledger observers)
  • token: Which token to withdraw
fn withdraw(
    env: soroban_sdk::Env,
    proof: soroban_sdk::Bytes,
    nullifier: soroban_sdk::BytesN<32>,
    recipient: soroban_sdk::Address,
    amount: i128,
    token: soroban_sdk::Address,
) -> Result<(), ContractError>

Make a shielded transfer - deposit and withdraw in one transaction This provides maximum privacy by hiding both sender and amount in contract parameters

fn shielded_transfer(
    env: soroban_sdk::Env,
    sender: soroban_sdk::Address,
    token: soroban_sdk::Address,
    commitment: soroban_sdk::BytesN<32>,
    proof: soroban_sdk::Bytes,
    nullifier: soroban_sdk::BytesN<32>,
    recipient: soroban_sdk::Address,
    deposit_amount: i128,
    withdraw_amount: i128,
) -> Result<(), ContractError>

Query if a nullifier has been used (public, for transparency)

fn is_nullifier_used_public(
    env: soroban_sdk::Env,
    nullifier: soroban_sdk::BytesN<32>,
) -> bool

Get current commitment count (public, for tree building)

fn get_commitment_count(env: soroban_sdk::Env) -> u32

Get commitment by index (public, for merkle tree verification)

fn get_commitment(env: soroban_sdk::Env, index: u32) -> Option>

Create a commitment using Poseidon hash (ZK-friendly) commitment = Poseidon(amount, secret, nullifier, recipient_hash)

fn create_commitment_hash(
    env: soroban_sdk::Env,
    amount: i128,
    secret: soroban_sdk::BytesN<32>,
    nullifier: soroban_sdk::BytesN<32>,
    recipient: soroban_sdk::Address,
) -> soroban_sdk::BytesN<32>

Create a nullifier using Poseidon hash nullifier = Poseidon(secret, index)

fn create_nullifier_hash(
    env: soroban_sdk::Env,
    secret: soroban_sdk::BytesN<32>,
    commitment_index: u32,
) -> soroban_sdk::BytesN<32>

Imports

WebAssembly Text (WAT) ▶