Why a Custom Allocator?
The Problem
| Allocator | Heap Size | FHE Support |
|---|---|---|
| Default Solana | ~32KB | No |
| Privora FHE | ~1MB | Yes |
The Solution
TheFheBumpAllocator provides:
- ~1MB heap space (configurable)
- Bump allocation (fast, no deallocation)
- Compatible with Solana BPF environment
Setup
Basic Setup
Add at the top of yourlib.rs:
Custom Heap Size
For programs needing more memory:How It Works
Macro Expansion
The macro expands to:- Only active when compiling for Solana (
target_os = "solana") - Uses
#[global_allocator]to replace the default allocator - Static lifetime - exists for program duration
Bump Allocation
The allocator uses bump allocation:- Fast: O(1) allocation (just bump a pointer)
- No deallocation: Memory is never freed during execution
- Reset on completion: All memory reclaimed when program exits
FheBumpAllocator API
Construction
Constants
Memory Usage Patterns
Typical Memory Usage
| Operation | Memory Used |
|---|---|
| Load u8 ciphertext | ~10KB |
| Load u64 ciphertext | ~80KB |
| FHE addition result | ~10-80KB |
| Comparison result | ~1KB |
Example Program
Troubleshooting
Out of Memory Error
setup_fhe_allocator!()not called- Called in wrong location (not crate root)
- Exceeded heap size
Allocator Not Active
If FHE operations fail in tests:Heap Size Too Small
For complex programs with many operations:Best Practices
1. Load Only What You Need
2. Process in Batches
For large workloads:3. Use Appropriate Types
Memory Layout
The Solana BPF memory layout:0x300000000.
Comparison with Default Allocator
| Feature | Default | FheBumpAllocator |
|---|---|---|
| Heap Size | ~32KB | ~1MB |
| Allocation | Bump | Bump |
| Deallocation | None | None |
| FHE Support | No | Yes |
| Performance | Fast | Fast |