Repository navigation
[interface] Add docs on confidential supply reconciliation and balance counters - #1495
Conversation
| /// # 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`. |
There was a problem hiding this comment.
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.
joncinque
left a comment
There was a problem hiding this comment.
Looks great to me! Just a couple of questions to make sure I understand
| /// 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| /// 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. |
There was a problem hiding this comment.
What kind of snapshot is this referring to? The one stored on the account?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
that would probably be better, since "snapshot" can be a loaded term in validator operation
a309a9f to
153ca8d
Compare
|
Okay, I re-worked the wordings a bit. Let me know what you think! |
Problem
The confidential mint-burn docs do not explain how clients reconcile
decryptable_supplyafter pending burns are applied, or why a separateUpdateDecryptableSupplyis not needed after everyApplyPendingBurn. 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
ConfidentialMintBurnandConfidentialTransferAccountto explain:I also updated the related instruction docs, keeping the detailed explanations on the state structs.