The "Gateway Circuit SDK", is an encrypted runtime environment that enables developers to use regular rust functions as secure circuits, whereby an evaluator executes a secure function on a user's ciphertext inputs, without ever seeing the encrypted values. The protocol allows end users to process on encrypted data while ensuring both privacy and verifiability without the need for additional zero-knowledge proofs (such as SNARKs) for inputs and outputs.
- Developer creates a new secure function decorated with the
encrypted
macro - Upon regular execution:
- the rust function is transpiled into a secure MPC circuit
- an embedded 2 party testnet is instantiated
- the maliciously secure WRK17a protocol is executed to safely calculate the output
- the output is normalized back into idiomatic rust
Building an encrypted function is as easy as creating a regular rust function with primitive types, decorating it with the encrypted
macro and running it from main, or another function. This example automatically starts up an embedded evaluator, compiles the access_content
function into an encrypted circuit and submits the circuits with inputs via regular calls to the function.
Run this example with:
cargo run --release example age_content_control
use compute::prelude::*;
#[encrypted(execute)]
fn access_content(age: u8) -> u8 {
// Access level codes
let RESTRICTED = 1; // Restricted access for underage users
let FULL = 2; // Full access for adult users
let LIMITED = 3; // Limited access for senior users
let INVALID = 0; // Invalid age code
// Determine access level based on age ranges
match age {
1..=17 => RESTRICTED, // Users aged 1-17
18..=65 => FULL, // Users aged 18-65
66..=120 => LIMITED, // Users aged 66-120
_ => INVALID, // Age outside expected bounds
}
}
fn main() {
// Test cases to check access level functionality
let age = 25_u8;
let access_level = access_content(age);
println!("Access Level: {}", access_level); // Expected output: 2 (Full)
let age = 15_u8;
let access_level = access_content(age);
println!("Access Level: {}", access_level); // Expected output: 1 (Restricted)
let age = 70_u8;
let access_level = access_content(age);
println!("Access Level: {}", access_level); // Expected output: 3 (Limited)
let age = 125_u8;
let access_level = access_content(age);
println!("Access Level: {}", access_level); // Expected output: 0 (Invalid)
}
(For an example of running two parties p2p, see the server crate.)
- Fully Encrypted Computation: The entire computation is hidden from external observers, including inputs, outputs, and intermediate states.
- Input Privacy: data is fully encrypted going into the function.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
See CONTRIBUTING.md.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
The incredible tandem project and the team over at Sine Foundation for providing the underlying 2PC garbling scheme