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
CircomDatafor the chosen dimensions tuple (2×2×1or2×6×1forswap).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: u32to seed the staging PDA, and a 32-byteswapper_account_additional_seedto 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×1or2×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_hashrecomputation 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_swapreplays the staged CPI batch. Account index255is replaced with the swapper PDA and signed viainvoke_signed.swapped_amount = balance_after - balance_beforeon 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_commitmentinserts the commitment andNewCommitment(with non-zeroon_chain_data) is emitted viaemit_cpi!.The staging account is closed and its rent returned to the signer.
validate_token_balance_diff/validate_sol_balance_diffruns 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.
transactmoves funds between the signer's wallet and the storage vault.transfermoves only the relayer fee out of the vault; the rest is a pure shielded-to-shielded rebalance.
Last updated

