Core Types
EncryptedRef<T>
A 32-byte hash reference to encrypted data stored in the content-addressable store.- Size: Always 32 bytes (SHA256 hash)
- Borsh serializable for account storage
- Type parameter
Tindicates the encrypted integer type - Does not contain actual ciphertext data
Encrypted<T>
A loaded encrypted value ready for FHE computation.- Contains actual ciphertext data (10KB-100KB)
- Supports arithmetic and comparison operations
- Created by loading from
EncryptedRefor as result of operations - Must be stored back to get a reference for account storage
EncryptedBool
The result of comparison operations on encrypted values.- Result of comparison operations (
ge,gt,le,lt,eq_enc) - Used with
select()for conditional logic - Can be stored and loaded like other encrypted values
Type Flow
Complete Example
Type Safety Benefits
The type system prevents several classes of errors:1. Mixing Integer Sizes
2. Confusing References and Values
3. Incorrect Storage
Working with Hashes
EncryptedRef<T> provides several methods for working with the underlying hash:
Serialization
All reference types implement Borsh serialization for on-chain storage:Best Practices
Use Smallest Type
Choose u8 when values fit in 0-255. Smaller types have faster operations.
Store References
Always store EncryptedRef in accounts, not Encrypted values.
Load Once
Load encrypted values once and reuse them to minimize syscalls.
Batch Stores
Store results at the end of computation, not after each operation.