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

Instructions

The user-facing instructions exposed by lib.rs. They fall into four groups: transact / transfer (proof-bearing, one instruction), swap (proof staged by prepare_swap, then swap), proofless deposit, and admin / lifecycle.

All proof-bearing transactions are sent as Solana v1 transactions (4096 bytes, no address lookup tables).

Nullifier accounts

transact, transfer and swap declare their nullifier PDAs as named optional accounts (first_nullifier … sixth_nullifier for transact/transfer, up to twelfth_nullifier for swap) with init_if_needed, seeded by in_nullifiers[i]. A nullifier account is created and marked used in the same instruction, so a failed transaction never leaves an unused nullifier account behind. Unused slots are passed as the program id (Anchor's None); 2-input calls fill only the first slots.

Transact (deposit / withdraw)

transact(forbid_deposit, in_nullifiers, relayer_fee, dimensions, root_hash_index, proof: ProofData)

dimensions is 1×2×1 or 1×6×1. The proof, public signals and encrypted outputs travel in the instruction data (ProofData); nothing is staged.

Bridges a wallet's public balance to or from the shielded vault.

  • If mint is None → SOL flow (perform_transact_funds); otherwise → SPL flow (perform_transact_tokens).

  • forbid_deposit = true rejects flows whose net amount_change is non-negative.

  • Net positive amount_change → deposit_funds from signer to vault.

  • Net negative → vault transfers |amount_change| - relayer_fee to recipient and relayer_fee to signer (signer is the relayer).

  • The 1×6×1 shape supports up to 6 input nullifiers, used when consolidating fragmented UTXOs.

  • After movement, validate_*_balance_diff enforces the closing balance equation.

Transfer (shielded → shielded)

transfer(in_nullifiers, relayer_fee, dimensions, root_hash_index, proof: ProofData)

dimensions is 1×2×2 or 1×6×2. Moves value between two shielded UTXOs without exiting the vault, via transfer_common. The only fund movement is paying relayer_fee from the vault to the signer.

Swap (shielded → DEX → shielded)

A swap's proof, outputs and router calldata do not fit in one transaction together with the route accounts, so it takes two:

prepare_swap(id, dimensions, proof: ProofData, on_chain_encrypted_output, instructions: Vec<SolanaInstructionData>)

Writes one SwapStagingAccount at ["hinkal_swap_staging", deployer, signer, id] holding the proof, public signals, encrypted outputs, the on-chain encrypted output and the CPI batch. It creates the account (or resizes it if it already exists) and checks the encrypted-output count and sizes. It does not touch nullifiers.

swap(id, swapper_account_additional_seed, in_nullifiers, relayer_fee, variable_rate, dimensions, root_hash_index)

dimensions is 2×2×1 or 2×6×1. Reads the staging account (version-checked), runs the swap, and closes the staging account back to the signer. Steps in swap_common:

  1. validate_swap_atas - the supplied mint_from / mint_to and their ATAs must be consistent (no SOL pretending to be a token, etc.).

  2. process_proof_and_state with on_chain_creation = [false, true] - the input leg uses proof-derived nullifiers/commitments; the output leg's commitment is built on-chain from the actual swap result.

  3. swapper_account_additional_seed from the proof must match the seed used to derive the swapper PDA (SwapperAccountAdditionalSeedMismatch).

  4. determine_swap_mode → TokenToToken | TokenToSol | SolToToken.

  5. Vault → swapper PDA: input liquidity is moved to the swapper (which is the CPI authority).

  6. perform_swap invokes the staged CPI batch against remaining_accounts. Account index 255 is replaced with the swapper PDA at execution time and the call is signed via invoke_signed with the swapper seeds. Self-CPI back into Hinkal is rejected (SelfCPIForbidden).

  7. swapped_amount = balance delta on the destination ATA / SOL account.

  8. calculate_total_fee = relayer_fee + swapped_amount * variable_rate / 10000. variable_rate is in basis points × 10 (i.e. denominator 10_000).

  9. Fee is paid to the signer; the remainder is the UTXO amount. A new commitment is built on-chain from (amount, mint_to, stealth_address_structure, timestamp) and inserted into the Merkle tree.

  10. validate_token_balance_diff / validate_sol_balance_diff is run on both legs to enforce the closing equation.

The swap transaction holds at most 64 accounts. With 21 fixed Hinkal accounts (including the event-CPI authority) plus one per real input note, 37–42 accounts remain for the router.

Proofless deposits

proofless_deposit(amounts[], stealth_address_structure[], encrypted_blobs[], create_blocked_utxos, timestamp: Option<i64>)

1..N outputs in a single instruction. SOL or SPL, selected by whether mint is supplied. timestamp overrides the block clock for the resulting UTXO(s) when supplied (None falls back to the on-chain clock). When create_blocked_utxos = true, also emits BlockedUtxosCreated { sender, mint, amounts } so a downstream service can build "blocked" UTXOs (e.g. for cooldowns).

Calls proofless_deposit_common:

  • amount > 0 for every output.

  • If access_token_owner is supplied as a signer, validate it against AccessTokenStorageAccount.access_token_owner_key. Otherwise, fall back to is_access_token_required(total_amount, token_limit) — if total_amount exceeds the per-mint limit, revert with AccessTokenRequired.

  • Run the deposit (SOL via deposit_funds, SPL via deposit_tokens) and assert balance_diff == total_amount.

  • For each output, build an on-chain UTXO via build_onchain_utxo and insert it into the Merkle tree (process_onchain_commitments).

Admin & lifecycle

Instruction
Authority
Effect

initialize

original_deployer

Allocates and seeds storage, both Merkle trees, ownership, and access-token storage. Funds the vault PDA with rent-minimum.

transfer_ownership(new_owner)

current owner

Sets pending_owner. Emits OwnershipTransferred.

accept_ownership

pending_owner

Promotes pending → current. Emits OwnershipAccepted.

update_relayer_status(status)

owner

Adds or removes a relayer from the whitelist. Emits RelayerStatusUpdated.

init_token_limit

anyone (rent payer)

Allocates a per-(deployer, mint) TokenLimitStorageAccount with amount_limit = 0.

update_token_limit(amount)

owner

Sets the per-mint deposit/withdraw threshold. Emits TokenLimitUpdated.

add_access_token(access_key)

access_token_owner

Creates the AccesskeyAccount lock and inserts access_key into the access-token Merkle tree. Emits NewAccessKeyAdded.

change_access_token_owner_key(new_owner)

owner

Rotates access_token_owner_key. Emits AccessTokenOwnerChanged.

Last updated