For the complete documentation index, see llms.txt. This page is also available as Markdown.

Typical Flow

A private swap on Solana takes two v1 transactions: prepare_swap stages the proof and router calldata, then swap executes. The order below is what a relayer-driven flow looks like end-to-end.

1. Off-chain (client)

  • Build CircomData for the chosen dimensions tuple (2×2×1 or 2×6×1 for swap).

  • Generate the Groth16 proof.

  • Encrypt the new UTXO output(s).

  • Build the CPI instruction list for the chosen router (Jupiter, Raydium, …) as a Vec<SolanaInstructionData>.

  • Pick an id: u32 to seed the staging PDA, and a 32-byte swapper_account_additional_seed to derive a unique swapper PDA for this swap.

2. Stage (one transaction)

prepare_swap(id, dimensions, proof, on_chain_encrypted_output, instructions) writes the SwapStagingAccount at (program, deployer, signer, id). The swap instruction finds it by re-deriving the same seeds.

3. Submit (one transaction)

swap is invoked with:

  • id (matches the staging PDA).

  • swapper_account_additional_seed (matches the proof's public signals).

  • in_nullifiers (must equal the public signals).

  • relayer_fee, variable_rate.

  • dimensions = 2×2×1 or 2×6×1.

The nullifier PDAs are passed as the named nullifier accounts and created with init_if_needed in this transaction. remaining_accounts carries every program/account referenced by the staged SolanaInstructionData list.

4. Verify (process_proof_and_state)

  • Groth16 verification (verify_proof).

  • calldata_hash recomputation across recipient, signer, encrypted outputs, fees, instructions, and remaining accounts.

  • Merkle root membership check against the 100-root window.

  • Nullifier validation + insertion.

  • Commitment insertion (skipped for legs flagged on_chain_creation).

  • Whitelisted-relayer check, stealth-address randomness check, mint binding check.

5. Move funds (swap_common + perform_swap)

  • Storage vault → swapper PDA: input liquidity transferred under vault seeds.

  • perform_swap replays the staged CPI batch. Account index 255 is replaced with the swapper PDA and signed via invoke_signed.

  • swapped_amount = balance_after - balance_before on the destination side.

6. Settle

  • calculate_total_fee = relayer_fee + swapped_amount * variable_rate / 10_000. Fee is paid to the signer.

  • The remainder forms the output UTXO. insert_onchain_commitment inserts the commitment and NewCommitment (with non-zero on_chain_data) is emitted via emit_cpi!.

  • The staging account is closed and its rent returned to the signer.

  • validate_token_balance_diff / validate_sol_balance_diff runs on both legs to enforce:


transact and transfer skip the staging step: the proof travels in the instruction data and everything happens in one transaction.

  • transact moves funds between the signer's wallet and the storage vault.

  • transfer moves only the relayer fee out of the vault; the rest is a pure shielded-to-shielded rebalance.

Last updated