Examples
This page contains practical examples of using Gateway’s garbled circuits for privacy-preserving computations. For more examples and the complete source code, visit our GitHub repository.
Core Examples
1. Discount Eligibility Check
A simple example demonstrating threshold-based decision making:
This example shows:
- Basic comparison operations
- Constant value handling
- Boolean return types
2. Loan Eligibility Assessment
A complex example showcasing multi-criteria decision making:
This example demonstrates:
- Complex conditional logic
- Range-based pattern matching
- Multiple input parameters
- Categorical output encoding
3. Access Control System
An example showing role-based access control:
This example illustrates:
- Match expressions
- Role-based authorization
- Bitwise operations for permission flags
Key Patterns
Pattern 1: Range-Based Logic
Pattern 2: Multi-Level Decision Trees
Pattern 3: Composite Conditions
Testing Examples
Each example can be tested using the provided main function:
Remember that these examples are running in a secure, encrypted environment where all computations maintain data privacy throughout the execution.
Best Practices Demonstrated
1. Clear Constants
- Define constants at the beginning of functions
- Use descriptive names for better readability
2. Range Validation
- Use if-let with ranges for input validation
- Handle out-of-range cases explicitly
3. Error Handling
- Always provide default/error cases
- Use clear error codes or flags
4. Code Organization
- Structured decision trees
- Clear separation of logic levels
Additional Resources
You can find more examples in our GitHub repository. Each example includes detailed comments and test cases. The repository also contains additional utilities and helper functions.