Start here

Confidential balances

A confidential account holds value in two places at once: a public balance anyone can read, and an encrypted one only the owner can open. This page is about how the encrypted side is stored and the rules that govern moving value across the line between them.

Two sides of one account

A token account with the Token-2022 confidential transfer extension is still a single SPL account, under a single mint, owned by a single wallet. The extension does not replace the balance you already have. It adds a second place inside the same account to hold value.

The public side is the ordinary amount field, a plain integer any explorer reads without asking. The confidential side is a small set of ElGamal ciphertexts under the encryption key of the owner. Value is never created or destroyed crossing between them: a deposit subtracts from the public side and credits the confidential side, a withdrawal does the reverse, and the two together are what the account holds. There is no wrapper token and no second mint.

Public balancePlain integer, readable by anyone, spendable with ordinary SPL transfers
Available balanceElGamal ciphertext, the confidential funds you can spend right now
Pending balanceElGamal ciphertexts, credits that have arrived but are not yet spendable
Decryptable balanceThe available balance under a symmetric key, for cheap local reads
Encryption keyThe ElGamal public key of the owner, stored in the clear on the account
Credit counterHow many credits have landed in pending since the last apply

The encryption key sitting in the clear is deliberate and is not a leak. A sender needs it to encrypt an amount to you, much as they need your address to send at all. It identifies the account, not the balance.

Available and pending

The confidential side is two balances, not one, and the difference is the detail most people skip. The available_balance is what you can spend. The pending_balance is where everything sent to you lands first. A confidential transfer into your account does not touch your available balance. It adds to pending, homomorphically, without anyone decrypting anything.

The reason is adversarial. Spending means building proofs about one exact ciphertext: this encrypted value, minus this encrypted amount, leaves this encrypted remainder. If inbound transfers rewrote your available balance, a proof you had just built would refer to a ciphertext that no longer exists on the account, and your transaction would fail on arrival. That would hand anyone who knows your address a cheap way to grief you, since a stream of tiny credits would keep your outgoing transfers failing and cost you a fresh round of proof generation each time.

The rule in one line
Nobody but the owner can alter the available balance. Senders can only add to pending, and pending is not spendable until the owner folds it in.

Applying pending

Moving pending into available is its own instruction, ApplyPendingBalance, signed by the owner. It carries no zero-knowledge proof, because nothing about it needs proving: the program adds the pending ciphertexts into the available ciphertext using the additive homomorphism of ElGamal, zeroes pending and resets the counter, without learning any of the three numbers. The owner must supply a fresh decryptable balance, because the program cannot compute a value under a key it has never seen.

The credit counter and its ceiling

Each credit into pending increments a counter. The owner sets a maximum for it when the account is configured, and once pending holds that many credits, further confidential transfers in are rejected until the owner applies and the counter resets. The ceiling is not arbitrary: every credit makes the aggregated pending ciphertext encrypt a larger value, and recovering a value from an ElGamal ciphertext is a bounded search, so unlimited credits would eventually produce a pending balance the owner could not open. A low ceiling means applying more often, a high one a slower decryption when you do.

Applying also has a race worth handling in client code. Credits can arrive between reading the account and landing the instruction. The instruction carries the counter you expected, and the program records both what you expected and what was actually there. If they disagree, the decryptable balance you just wrote is short by whatever arrived in the gap, and the fix is to decrypt the authoritative ElGamal balance and write a corrected value. The funds are never at risk; only the cached number is stale.

The decryptable balance

ElGamal over curve25519 is additively homomorphic, which is what the extension needs, but decryption recovers a curve point rather than an integer. Turning that point back into a number means solving a discrete logarithm by searching a bounded range: fine for small values, slow for large ones, and not something a wallet should do on every render.

So the account stores a second copy of the available balance under a symmetric key, derived on the same device from the same wallet signature as the ElGamal key. Opening it is one symmetric decryption, and this is the number a wallet shows you.

It is a cache, not the source of truth. Proofs are built against the ElGamal ciphertext, and if the two disagree the ciphertext is right. That is also why every instruction changing the available balance must be owner-signed and must carry a new decryptable value. The same bounded search is why the pending balance is kept as a low and a high ciphertext rather than one, so applying stays tractable.

Deposit, apply, withdraw

Four operations touch a confidential balance and they are genuinely distinct. Treating deposit and apply as one step is the most common integration mistake, because a deposit is not spendable the moment it confirms.

  • Deposit. Public side to pending. The amount is a plaintext argument and needs no proof. It lands in pending like any other credit, so it needs an apply first.
  • Apply. Pending into available. Owner only, no proof, no amount.
  • Transfer. An encrypted amount from your available balance to the pending balance of another confidential account. This is the operation that carries proofs, and it has its own page.
  • Withdraw. Available back to the public side. The amount is plaintext, but it still carries proofs, because the chain has to be convinced the encrypted remainder is a real non-negative balance and not an underflow.
public 100   available 0    pending 0

Deposit(25)           public 75   available 0    pending 25
ApplyPendingBalance   public 75   available 25   pending 0
Transfer(?)           public 75   available ?    pending 0
Withdraw(10)          public 85   available ?    pending 0

Read the question marks literally. After the transfer the chain holds a ciphertext and nobody but the owner and the counterparty can say what it stands for. The arguments to deposit and withdraw stay readable forever.

What each step reveals

Confidentiality here is about amounts, and only amounts. The boundary between the two sides is exactly where amounts become visible, so it is worth being blunt about which operations sit on it.

DepositThe amount is a plaintext argument and is public
ApplyNo amount. An observer sees that you applied and how many credits were folded in
TransferNo amount. Sender, receiver, mint and slot are public as usual
WithdrawThe amount is a plaintext argument and is public
Balance readsAnyone can read the ciphertexts. Nobody without the key can read the values
Crossing the line publishes a number
Depositing exactly what you later withdraw, in one go each way, is a correlation any observer can make without decrypting anything. The amounts inside stay encrypted, but two matching public numbers at the edges can still tell a story.

None of this touches what was already public. Your address, your counterparty, the mint and the timing of every instruction are on chain exactly as before. Confidential balances change one column of the ledger.

Setting up an account

There are two levels of configuration and the first one is permanent.

At the mint

The extension is configured on the mint before the mint is initialized. It cannot be bolted onto a mint that already exists, which is why a given token either supports confidential balances or does not. The configuration holds the authority allowed to change these settings, a flag deciding whether new accounts are auto-approved for confidential credits, and an optional auditor key.

At the account

An account needs room for the extension, allocated at creation or by reallocating an existing account, and then configured. Configuration registers the ElGamal public key, an initial decryptable balance of zero, and the maximum pending credit counter, and carries a proof that the registered key is well formed. If the mint does not auto-approve, the mint authority must approve the account before it can receive confidential credits.

// once per account
CreateAccount        with space for ConfidentialTransferAccount
VerifyPubkeyValidity on ZkElGamalProof
ConfigureAccount     elgamal_pubkey
                     decryptable_zero_balance
                     maximum_pending_balance_credit_counter

// then, whenever credits have landed
ApplyPendingBalance  expected_pending_balance_credit_counter
                     new_decryptable_available_balance

Closing works in the same spirit. An account can only be emptied once its available balance provably encrypts zero, so pending has to be applied and spent or withdrawn first. An owner can also refuse incoming confidential credits outright, which is the usual way to make a balance quiescent before winding the account down.