Encryption
How a balance and an amount are stored on chain, and what reads them.
The Confidential Transfer extension of Token-2022 defines how a balance is stored and encrypted. Hush's two mints turn it on, and the app and the SDK do the encrypting and decrypting with your keys.
Two keys
Unlocking derives two keys in your browser:
| Key | Kind | What it does |
|---|---|---|
| Encryption keypair | twisted ElGamal | The public half sits on your Hush account and anyone can encrypt an amount to it. The secret half decrypts those amounts. |
| Owner key | AES | Encrypts and decrypts your own copy of the available balance. |
Together they are your key. Your key covers where they come from.
Ciphertexts you can add
Two twisted ElGamal ciphertexts made for the same key can be added, and the result decrypts to the sum of the two amounts. The token program uses this on every credit and debit. It adds the ciphertext of an incoming amount to your pending balance, and subtracts the ciphertext of an outgoing amount from your available balance, and at no point does it learn either number.
The owner copy
Decrypting a twisted ElGamal ciphertext means searching for the number it holds, which is quick for a small number and slow for a large one, and a balance can be large. So each time you change your available balance, your app also stores the new figure encrypted with your AES key, and reads that copy back with a single decryption. The chain keeps both. The proofs are checked against the twisted ElGamal ciphertext, and nothing on chain reads the owner copy.
Amounts in two parts
A transfer amount is a number of base units up to 48 bits long. It travels as two ciphertexts, a low part of 16 bits and a high part of 32 bits, each small enough for the recipient to decrypt quickly. 48 bits is 281,474,976.71 USDC or 281,474.98 SOL in one transfer.
A send encrypts the amount twice: once to the sender's key and once to the recipient's. The sender's copy is subtracted from their available balance, and the recipient's copy is added to their pending balance. Each of the two can decrypt the amount from their own copy, which is how a receipt opens for both.
No third key
A Confidential Transfer mint can name an auditor key that every transfer amount is also encrypted to. hSOL and hUSDC name none. An amount is encrypted to the sender and the recipient, and a balance to its owner.