Installation
Add the SDK to your Rust project:The #[encrypted] macro
The #[encrypted] macro transforms regular Rust code into garbled circuit operations. It supports:
1. Arithmetic Operations
2. Comparison Operations
3. Bitwise Operations
4. Control Flow
5. Constants and Literals
Type System
The SDK provides encrypted versions of standard integer types:Circuit Building
While the#[encrypted] macro is recommended, you can also build circuits manually:
Network Protocol
The SDK implements a two-party computation protocol with distinct roles:Garbler
Evaluator
Supported Operations
The SDK supports a wide range of operations on encrypted types:Arithmetic Operations
-
Addition (
+) -
Subtraction (
-) -
Multiplication (
*) -
Division (
/) -
Remainder (
%)
Bitwise Operations
-
AND (
&) -
OR (
|) -
XOR (
^) -
NOT (
!) - NAND
- NOR
- XNOR
Comparison Operations
-
Equal (
==) -
Not Equal (
!=) -
Greater Than (
>) -
Less Than (
<) -
Greater Than or Equal (
>=) -
Less Than or Equal (
<=)
Control Flow
- Conditional execution (if/else)
Error Handling
The SDK usesanyhow::Result for error handling:
Best Practices
-
Use the
#[encrypted]Macro- Prefer the macro over manual circuit building
- Enables natural Rust syntax
- Provides compile-time checks
- Automatically handles constant injection
-
Type Selection
- Use the smallest bit width that satisfies your needs
- Consider unsigned types when possible
-
Control Flow
- Always provide else branches in if expressions
- Use match expressions for complex conditionals
- Leverage range patterns for value categorization
-
Performance Optimization
- Minimize circuit depth when possible
- Reuse intermediate results
- Consider batching operations
-
Error Handling
- Use Result types for fallible operations
- Handle potential circuit compilation errors
- Validate inputs before encryption