Skip to content

[interface] Add docs on confidential supply reconciliation and balance counters - #1495

Merged
samkim-crypto merged 3 commits into
solana-program:mainfrom
samkim-crypto:docs/confidential-supply-reconciliation
Sep 28, 2026
Merged

samkim-crypto merged 3 commits into
solana-program:mainfrom
samkim-crypto:docs/confidential-supply-reconciliation

Conversation

@samkim-crypto

@samkim-crypto samkim-crypto commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The confidential mint-burn docs do not explain how clients reconcile decryptable_supply after pending burns are applied, or why a separate UpdateDecryptableSupply is not needed after every ApplyPendingBurn. This is only described in solana-labs/solana-program-library#6881 (comment), which is obviously hard to find.

The pending balance counter docs also reference an outdated field name and incorrectly suggest that a counter mismatch means there is more pending balance to apply.

Summary of Changes

I added docs to ConfidentialMintBurn and ConfidentialTransferAccount to explain:

  • How clients recover the current supply using the AES cache and the ElGamal ciphertext, including the 32-bit limit on the burn difference and how minting refreshes the cache.
  • What the expected and actual pending balance credit counters record, and how a mismatch can indicate a stale decryptable available balance even though all pending credits were applied.

I also updated the related instruction docs, keeping the detailed explanations on the state structs.

Comment on lines +65 to +97
/// # Pending balance credit counters
///
/// Incoming credits accumulate in `pending_balance_lo` and `pending_balance_hi`,
/// and `pending_balance_credit_counter` counts the credits since the last
/// `ApplyPendingBalance`.
///
/// To prepare `ApplyPendingBalance`, the client computes a new AES-encrypted
/// available balance from an account snapshot and supplies that snapshot's
/// pending credit count as `expected_pending_balance_credit_counter`. More
/// credits may arrive before the instruction executes.
///
/// At execution, the program records the client's expected count and the current
/// `pending_balance_credit_counter` as `actual_pending_balance_credit_counter`.
/// It applies the entire pending balance to `available_balance` and resets the
/// pending balance and its counter to zero, even if the expected and actual
/// counts differ. The supplied AES-encrypted balance is stored unchanged in
/// `decryptable_available_balance`.
///
/// The expected and actual counts persist until the next `ApplyPendingBalance`;
/// later credits only increment `pending_balance_credit_counter`. Clients can
/// compare the recorded counts after the instruction succeeds to detect credits
/// that arrived after their account snapshot. For example, if the client
/// observed two credits and a third arrived before execution, all three are
/// applied, but the recorded expected and actual counts are two and three.
///
/// In that case, `decryptable_available_balance` may be missing the third credit,
/// so the client must recover the correct available balance before relying on
/// that cache. Applying the pending balance again using the stale cache does not
/// recover credits that were already applied.
///
/// These counters help detect changes to the pending balance; matching counts
/// do not verify the supplied decryptable balance, which the program does not
/// check against the ElGamal-encrypted `available_balance`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally planning on putting this above the field names, but it became a bit long, so I put it here. If you prefer otherwise, then let me know.

@samkim-crypto
samkim-crypto marked this pull request as ready for review September 24, 2026 03:13
joncinque
joncinque previously approved these changes Sep 25, 2026

@joncinque joncinque left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me! Just a couple of questions to make sure I understand

Comment on lines +40 to +43
/// When the cache was last set to the correct supply, this difference is the
/// total burns applied since that update. The difference must be non-negative
/// and fit in a `u32` for `decrypt_u32` to succeed; the full supply can still
/// be a `u64`. A larger difference cannot be recovered with this method.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's greater than u32, which is probably expected to happen since that's only 4.2 SOL, they need to actually go through burn transactions, correct? Or do they separate the middle 32 bits from the rest?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, with the current helper, larger differences require recovering the supply separately (i.e. from burn history). Individual burns have separate low/high ciphertexts, but these are combined in the mint state. We can extend the client's decoding range to handle larger differences directly, but I'll think more about this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I clarified the wording here a bit. Decrypting differences of around 40 bits is practical with a suitable discrete-log search. When direct recovery becomes impractical, clients cana recover the applied burns from transaction history.

The current client helper still only handles 32-bit differences, but improvements are in progress. For example, solana-program/zk-elgamal-proof#571 adds support for shifting the 32-bit search window using a caller-provided lower bound.

Comment on lines +71 to +74
/// To prepare `ApplyPendingBalance`, the client computes a new AES-encrypted
/// available balance from an account snapshot and supplies that snapshot's
/// pending credit count as `expected_pending_balance_credit_counter`. More
/// credits may arrive before the instruction executes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of snapshot is this referring to? The one stored on the account?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I meant the account data fetched by the client before constructing ApplyPendingBalance. The client uses that local copy to compute the new decryptable available balance and set the expected counter. More credits may arrive before execution, so the program records the actual counter at execution time.

I can replace "from an account snapshot" with "from the account data fetched by the client" to make that clearer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would probably be better, since "snapshot" can be a loaded term in validator operation

@samkim-crypto

Copy link
Copy Markdown
Contributor Author

Okay, I re-worked the wordings a bit. Let me know what you think!

@joncinque joncinque left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok great, thanks!

@samkim-crypto
samkim-crypto merged commit 28a131d into solana-program:main Sep 28, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants