Giter Club home page Giter Club logo

jigg's Introduction

JIGG

JavaScript implementation of garbled gates and 2PC boolean circuit protocols.

Requirements and Installation

This library is implemented entirely in JavaScript. Running the server requires Node.js, npm (both installed via yum install nodejs npm or brew install npm on macOS), Socket.IO, and libsodium.

Run npm to install all JIGG dependencies:

npm install

Project Layout

├─ circuits/        Circuit files
│  ├─ macros/       Macro files to assemble circuits using [CASM](https://github.com/wyatt-howe/macro-circuit-assembler)
│  └─ bristol/      Bristol format files
├─ demo/            Demo for client-server deployment scenario
├─ src/             Library modules implementing protocol steps for participants
│  ├─ comm/         Communications modules (such as for OT)
│  ├─ modules/         Data structure modules (such as circuits)
│  └─ utils/        Other utility modules (such as cryptographic primitives)
├─ test/            End-to-end tests
└─ tutorial/        Interactive tutorial on using JIGG

Running The tutorial

You can run the tutorial interactively on your local machine, after cloning JIGG, by using

cd path/to/JIGG
npm run tutorial

Running Demo Circuit Applications

Start the communications server from server.js with the command below:

node demo/server.js <port number>

As a Browser Party

Parties can go to http://localhost:<port>/ in a web browser supporting JavaScript to begin communications.

As a Node.js Party

Connect a new party in Node.js by running:

node demo/party.js <port> <role> <input> <encoding> <circuitName>
# <role>: Garbler or Evaluator
# <input>: string with no whitespaces
# <encoding>: bits, number, or hex
# <circuitName>: must include file extension
#                demo will run bristol circuit found at
#                'circuits/bristol/<circuitName>'

For example to join an AES-128 computation as the garbler, run:

node demo/party.js 3000 Evaluator 00000000000000000000000000000000 hex aes-128-reverse.txt

Server + Garbler/Evaluator

The server may also run as a garbler or evaluator. You can acheive this by running the server with the same arguments as a party:

node demo/server.js <port> <role> <input> <encoding> <circuitName>

Demo Circuits

We have a variety of circuits available under circuits/bristol mostly from this page.

Circuit Format

JIGG can parse a circuit in the standardized 'Bristol Format' which is supported by several compiled MPC libraries such as SCALE-MAMBA.

4 8
2 2 2
1 3
2 1 0 1 4 AND
2 1 2 3 5 XOR
1 1 5 6 INV
2 1 4 6 7 AND

Circuit Assembler

To create a new circuit, write a macro with existing circuits as its gates and run the macro-circuit-assembler with:

npm run casm -- <path_to_macro> <output_path>

For example, this macro assembles an AND circuit over 8 bits using existing 4 bit AND circuits:

npm run casm -- circuits/macros/and-8.casm circuits/and-8.txt

Running Tests

All of the built-in test vectors can be verified in npm test. The tests will run a server automatically. These are end-to-end tests.

Capabilities

JIGG is designed for semi-honest parties (in either node or in the browser). We support point-and-permute, free-XOR, free single-input gates, and encryption from a random oracle (fixed-key XChaCha20). The half-AND optimization is compatible but not yet supported. The default label size is 128 bits and relies on JavaScript's Uint8Array class. The simple-labels branch demonstrates dynamically-sized labels (that are 53 bits in length or less) without using arrays. Some potential improvements are listed in the to-do section.

Contributing

JIGG is fully functional as it is now, but there's still more to do (see the list below) before version 1. Pull requests are welcome for any improvement. The JIGG source is maintained with the help of ESLint for style and the included test suite for stability.

To Do

  • Half-AND gate optimization
  • Standardize JSON/serialized/compressed formats for inter-party messages compatible with SIGG

Information and Collaborators

More information about this project, including collaborators and publications, can be found at multiparty.org.

jigg's People

Contributors

kinanbab avatar lapets avatar wyatt-howe avatar

Stargazers

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

jigg's Issues

Potential security issue with incorrect doubling

Doubling is implemented here

Label.prototype.double = function () {
const bytes = this.bytes.slice();
const leastbyte = bytes[0];
bytes.copyWithin(0,1,15); // Logical left shift by 1 byte
bytes[14] = leastbyte; // Restore old least byte as new greatest (non-pointer) byte
return new Label(bytes);
};

This is supposed to be based on the D4 method in Fig6 of the BHKR13 paper https://eprint.iacr.org/2013/426.pdf

But the paper says that this must be "Circular left shift" of BITS, but your code performs a shift of BYTES.
Maybe this does not introduce an exploitable attack vector but definitely the implementation is not in line with the paper.
Is this a bug or was this done on purpose to avoid bit shifting?

Error while running `npm test`

Hello, first of all thank you for providing such a good tool so that I don't have to know too much about the principles of MPC and can try to use it。

but when I run it, I find that there is an error, after searching no problem, hope to get your help, thanks

➜  jigg npm test

> [email protected] test ~/workspace/jigg
> mocha test/test.js --timeout 120000



  Exhaustive regular server: logic-and-4-bit.txt
    ✓ Inputs 00 00 (1337ms)
    ✓ Inputs 00 01 (327ms)
    ✓ Inputs 00 10 (326ms)
    ✓ Inputs 00 11 (333ms)
    ✓ Inputs 01 00 (335ms)
    ✓ Inputs 01 01 (325ms)
    ✓ Inputs 01 10 (326ms)
    ✓ Inputs 01 11 (324ms)
    ✓ Inputs 10 00 (332ms)
    ✓ Inputs 10 01 (333ms)
    ✓ Inputs 10 10 (359ms)
    ✓ Inputs 10 11 (340ms)
    ✓ Inputs 11 00 (341ms)
    ✓ Inputs 11 01 (342ms)
    ✓ Inputs 11 10 (343ms)
    ✓ Inputs 11 11 (342ms)

  SHA256 Garbling Server
    1) Input 0
stderr in node [ 'demo/server.js',
  '3001',
  'Garbler',
  '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F',
  'hex',
  'sha-256-reverse.txt',
  'false' ]
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::3001
    at Server.setupListenHandle [as _listen2] (net.js:1286:14)
    at listenInCluster (net.js:1334:12)
    at Server.listen (net.js:1421:7)
    at Object.<anonymous> (/Users/linfang/workspace/prove/jigg-master/demo/server.js:21:12)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
Emitted 'error' event at:
    at emitErrorNT (net.js:1313:8)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:744:11)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)

stderr in node [ 'demo/server.js',
  '3001',
  'Garbler',
  '0000000000000000000000000000000000000000000000000000000000000000',
  'hex',
  'sha-256-reverse.txt',
  'false' ]
events.js:173
    throw err; // Unhandled 'error' event
    ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. (Role already taken!)
    at Socket.emit (events.js:171:17)
    at Socket.emit (~/workspace/jigg/node_modules/socket.io/lib/socket.js:142:10)
    at Server.join (~/workspace/jigg/src/jiggServer.js:52:12)
    at Socket.emit (events.js:182:13)
    at~/workspace/jigg/node_modules/socket.io/lib/socket.js:528:12
    at process._tickCallback (internal/process/next_tick.js:61:11)

socket.io v 4 does not work

Hi, I just wanted to give you a heads-up that the recent socket.io version 4.0.1 wil result in not being able to connect to the server.
Installing an earlier version with e.g. npm install [email protected] resolves the issue.

What does the AES algorithm do?

hi,

We have a variety of circuits available under circuits/bristol , What does AES-128.txt do? there are two inputs here, are they key and message for AES encryption? there is 1 output,it's length is 128bit, what is the content of this output?

look forward for your reply ,thanks

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.