The Challenge
In normal programming:The Solution: Encrypted Selection
FHE uses oblivious selection: compute both branches and select the result based on an encrypted condition.high_value and low_value are computed; the select operation picks one based on the encrypted condition without revealing which.
Comparison Operations
Available Comparisons
| Method | Comparison | Returns |
|---|---|---|
.ge(&other) | >= | EncryptedBool |
.gt(&other) | > | EncryptedBool |
.le(&other) | <= | EncryptedBool |
.lt(&other) | < | EncryptedBool |
.eq_enc(&other) | == | EncryptedBool |
Examples
The select() Method
EncryptedBool::select() implements encrypted if-then-else:
| Condition (encrypted) | Result |
|---|---|
| true | true_value |
| false | false_value |
Type Safety
Both values must have the same type:Common Patterns
Pattern 1: Price Matching
Pattern 2: Clamping Values
Pattern 3: Conditional Fees
Pattern 4: Safe Subtraction
Min/Max Operations
Privora provides built-in min/max that are more efficient than manual comparison + select:Storing Boolean Results
If you need to persist comparison results:Performance Considerations
Comparison Cost
Comparisons are expensive (5-10x more than addition):Optimization Strategies
- Minimize comparisons
- Use min/max instead of compare + select
- Batch arithmetic before comparisons