#secure-computation #garbled-circuits #smpc #garbled-circuit

bin+lib garble_lang

Turing-Incomplete Programming Language for Multi-Party Computation with Garbled Circuits

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

#91 in Programming languages

Download history 6/week @ 2025-10-16 16/week @ 2025-11-06 10/week @ 2025-11-13 17/week @ 2025-11-27 84/week @ 2025-12-04 99/week @ 2025-12-11 16/week @ 2025-12-18 16/week @ 2025-12-25 84/week @ 2026-01-01 119/week @ 2026-01-08 18/week @ 2026-01-22 71/week @ 2026-01-29

223 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
~47K SLoC