No CPI into the pool
The Shield Pool program rejects its tree-appending instructions (Transact, TransactSwap and
CloseSwapState) when they are reached through a cross-program invocation. It checks the invocation
depth and fails with CpiNotAllowed (0x10D8).
The reason is consistency: off-chain indexers rebuild the pool’s Merkle tree by reading transaction
instructions. An append made from inside another program would be invisible to them and would
desynchronize every reconstructed tree from the on-chain one.
Two more properties rule out wrapping a shield inside another program’s instruction:
- A shield carries a signed risk assessment that the program reads, by instruction introspection, from index 0 of the transaction.
- The depositor must sign the transaction directly and pay its fee.
Patterns that work
Your program pays out, the user shields
Your program sends tokens to the user’s wallet as usual. The user’s client then shields them withcloak.shield(...). The two transactions are separate, and the shield is signed by the user.
Your backend acts on behalf of your program
When the funds belong to your protocol rather than a user, hold them in an ordinary key controlled by your backend and use business mode. Your program’s logic decides when to pay; the backend executes the Cloak call.Your program pays into a private balance
To pay a user privately, withdraw from your program to a wallet your backend controls, shield, thensend to the user’s cloak_ address. The user receives a private note; the only public record is
your program paying your own wallet.
React to Cloak activity
To trigger program logic after a private payment, have the recipient’s client or your backend observe it (cloak.balance(), cloak.notes(), or scanTransactions with the viewing key) and then call your
program. Cloak activity is private, so no on-chain hook can see who received what.
Reading Cloak state from a program
The pool’s accounts are ordinary program-derived accounts, but their contents (commitments, nullifiers, roots) reveal nothing about balances or owners by design. There is no on-chain way to check that a given user holds a private balance. When a counterparty needs to verify a user’s history, the user discloses it off chain with their viewing key. See Viewing keys and selective disclosure.Related
- Shield Pool program: instructions, accounts and errors.
- Backend integration