Giter Club home page Giter Club logo

garble-lang's Introduction

Garble Language

Garble is a simple programming language for Secure Multi-Party Computation with Garbled Circuits. The circuits generated by Garble specify a function, with each input coming from a different party and the output computed collaboratively by all parties in a way that no party learns another party's input. Garble is statically typed, low-level, purely functional and uses a syntax heavily inspired by Rust.

All programs written in Garble are deliberately Turing-incomplete (only supporting bounded recursion), guaranteeing that they can be compiled to circuits using only AND, XOR and NOT gates (without any kind of stateful latches or registers). Here's an example of solving the Millionaire's Problem in Garble:

// A function for solving Yao's Millionaires' problem:

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
    }
}

For more examples, see the Language Tour.

How to Use Garble

The circuits generated by Garble are meant to be executed using a cryptographically secure MPC engine, which is not provided by this crate. Garble is agnostic about the details of the MPC engine and assumes only that the engine executes Garbled Circuits with support for AND, XOR and NOT gates. For local development and testing, Garble supports a direct and unencrypted evaluation of a generated circuit, with all inputs supplied by the local user.

To execute the Millionaire's problem example, first install the garble utility, checkout the repository to get the example programs, then run the function inside the repository directory:

$ cargo install garble_lang
$ git clone [email protected]:sine-fdn/garble-lang.git
$ cd garble-lang
$ garble run garble_examples/millionaires.garble.rs --function=main 10000000u64 10000u64
Richest::IsA
$ garble run garble_examples/millionaires.garble.rs --function=main 100u64 5000000u64
Richest::IsB
$ garble run garble_examples/millionaires.garble.rs --function=main 1000u64 1000u64
Richest::Tie

You can also type-check a program without running it by using garble check followed by the file name.

You might need to wrap input or metadata in single quotes if they contain whitespace.

Architecture of this Repository

The Garble compiler is relatively straightforward and turns a program &str into a circuit::Circuit (or aborts with a scan/parse/type error). The different steps and their modules are as follows (with steps 1-4 happening during compile time, step 5 during run time):

  1. scan.rs splits a program &str into a token::Token sequence.
  2. parse.rs parses a token::Token sequence into an untyped ast::Program.
  3. check.rs type-checks an untyped ast::Program, returning a typed ast::Program.
  4. compile.rs converts a well-typed ast::Program into a circuit::Circuit.
  5. eval.rs executes a circuit::Circuit with locally supplied inputs.

garble-lang's People

Contributors

dependabot[bot] avatar fkettelhoit avatar raimundo-henriques avatar zeitgeist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

eknoes namnc

garble-lang's Issues

Separating the garbler from the evaluator & question about specific protocol

That's a really cool library!

I started playing around with it and I was wondering if it's possible to separate the garbler from the evaluator. In my understanding, the garble run garble_examples/millionaires.garble.rs --function=main 10000000u64 10000u64 command would run the whole protocol by simulating both parties. What would be the steps required to separate the two parties (and have them run with RPC for example)?

On a side note, what is the exact GC protocol that is currently implemented? What optimizations are used or do you think that could be supported in the future?

Thanks,
Dimitris

Replace public tuple structs by structs with named fields

Context

There are several places in the code where we can find public tuple structs.

E.g. at lib/ast.rs:

pub struct ParamDef(pub Mutability, pub String, pub Type);

Problem

As the fields of tuple structs are identified by index rather than .name (which they lack), this creates further difficulties when reading the code. This is more relevant concerning public parts of the code.

Solution

Go through the code and replace all tuple structs by structs with appropriately named fields.

Unexpected type error in `else if`

Description

While working on the credit scoring demo, I was experimenting with a sequence of if ; else if statements and got the following error: The operands have incompatible types; () vs Score:. In a debugging efort, I kept only the main if else statement, erasing all else ifs from it. No error that time.

Code

pub fn main(user: User) -> Score {
  let mut points = 0u16;

  if user.income >= 10000u32 {
      points = points + 200u16
    } else if user.income >= 5000u32 {
      points = points + 100u16
    } else if user.income >= 20000u32 {
      points = points + 50u16
  } else {
      points = points + 0u16
  }


  if points > 150u16 {
    Score::Good(points)
  } else {
    Score::Bad(points)
  }
}

struct User {
  age: u8,
  income: u32,
}


enum Score {
  Good(u16),
  Bad(u16),
}

Error

I ran garble credit_scoring.garble.rs main 'User {age: 37u8, income: 5000u32}' and got the following error message:

Type error on line 6:12.
The operands have incompatible types; () vs Score:
       |   if user.income >= 10000u32 {
       |       points = points + 200u16
   6 > |     } else if user.income >= 5000u32 {
     > |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   7 > |       points = points + 100u16
     > | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   8 > |     } else if user.income >= 20000u32 {
     > | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   9 > |       points = points + 50u16
     > | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10 > |   } else {
     > | ^^^^^^^^^^
  11 > |       points = points + 0u16
     > | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12 > |   }
     > | ^^^
  13 > | 
     > | 
  14 > | 
     > | 
  15 > |   if points > 150u16 {
     > | ^^^^^^^^^^^^^^^^^^^^^^
  16 > |     Score::Good(points)
     > | ^^^^^^^^^^^^^^^^^^^^^^^
  17 > |   } else {
     > | ^^^^^^^^^^
  18 > |     Score::Bad(points)
     > | ^^^^^^^^^^^^^^^^^^^^^^
  19 > |   }
     > | ^^^
       | }

Generate circuit into a file

First of all, thank you for this amazing work!

Is there a simple command I can run to generate a circuit directly to a file? I am missing a cli tool for that.

Or is there any other way to do it?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.