Thanks to visit codestin.com
Credit goes to lib.rs

14 unstable releases (6 breaking)

0.7.0-alpha.1 Sep 28, 2025
0.6.1 Mar 19, 2025
0.5.0 Aug 28, 2024
0.4.0 Jul 29, 2024
0.1.2 Jul 27, 2022

#97 in Programming languages

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

246 downloads per month
Used in 4 crates (2 directly)

MIT license

510KB
11K SLoC

A purely functional programming language with a Rust-like syntax that compiles to logic gates for secure multi-party computation.

Garble programs always terminate and are compiled into a combination of Boolean AND / XOR / NOT gates. These Boolean circuits can either be executed directly (mostly for testing purposes) or passed to a multi-party computation engine.

use garble_lang::{compile, literal::Literal, token::UnsignedNumType::U32};

// Compile and type-check a simple program to add the inputs of 3 parties:
let code = "pub fn main(x: u32, y: u32, z: u32) -> u32 { x + y + z }";
let prg = compile(code).map_err(|e| e.prettify(&code)).unwrap();

// We can evaluate the circuit directly, useful for testing purposes:
let mut eval = prg.evaluator();
eval.set_u32(2);
eval.set_u32(10);
eval.set_u32(100);
let output = eval.run().map_err(|e| e.prettify(&code)).unwrap();
assert_eq!(u32::try_from(output).map_err(|e| e.prettify(&code)).unwrap(), 2 + 10 + 100);

// Or we can run the compiled circuit in an MPC engine, simulated using `prg.circuit.eval()`:
let x = prg.parse_arg(0, "2").unwrap().as_bits();
let y = prg.parse_arg(1, "10").unwrap().as_bits();
let z = prg.parse_arg(2, "100").unwrap().as_bits();
let output = prg.circuit.eval(&[x, y, z]); // use your own MPC engine here instead
let result = prg.parse_output(&output).unwrap();
assert_eq!("112", result.to_string());

// Input arguments can also be constructed directly as literals:
let x = prg.literal_arg(0, Literal::NumUnsigned(2, U32)).unwrap().as_bits();
let y = prg.literal_arg(1, Literal::NumUnsigned(10, U32)).unwrap().as_bits();
let z = prg.literal_arg(2, Literal::NumUnsigned(100, U32)).unwrap().as_bits();
let output = prg.circuit.eval(&[x, y, z]); // use your own MPC engine here instead
let result = prg.parse_output(&output).unwrap();
assert_eq!(Literal::NumUnsigned(112, U32), result);

The Garble Programming Language

Garble is a simple programming language for Multi-Party Computation. Garble programs are compiled to Boolean circuits and always terminate, making them ideal for Garbled Circuits. Garble is statically typed, low-level, purely functional and uses a Rust-like syntax. Garble is much simpler than Rust though, making it easy to learn and simple to integrate into MPC engines.

// A program for solving Yao's Millionaires' problem in Garble:

enum Richest {
    IsA,
    IsB,
    Tie,
}

pub fn main(a: u64, b: u64) -> Richest {
    if a > b {
        Richest::IsA
    } else if b > a {
        Richest::IsB
    } else {
        Richest::Tie
    }
}

To learn more about Garble, check out the website.

Dependencies

~0–2.7MB
~48K SLoC