-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '197_GMW' of github.com:multiparty/jiff into 197_GMW
- Loading branch information
Showing
189 changed files
with
148,123 additions
and
13,396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#MPC As a Service | ||
|
||
In many circumstances, some parties might want to participate in a secure MPC protocol but not have the computational | ||
resources to conduct the full protocol themselves. In this case, they might choose to outsource some of the computation | ||
to third parties who offer MPC as a service. This demo is a simple example of how JIFF might be used in such a scenario. | ||
|
||
Here, we have two types of parties: *input* parties who provide input to the computation, and *compute* parties, who do | ||
not provide input but participate in the computation process. In this simplistic example, they compute the sum of the | ||
inputs. | ||
|
||
## Running Demo | ||
Unlike many of the other demos provided here, parameters such as party count are not specified as in-line arguments. | ||
Instead, this information as well as the information for which of the parties are input parties and which are compute | ||
parties is set in config.json. | ||
|
||
Another different from the other demos is that here only the compute parties may be run through the terminal, while input | ||
parties must be run through a web browser. | ||
|
||
As currently configured in config.json, there are 3 compute parties and 2 input parties. | ||
|
||
Additionally, config.json specifies whether to use preprocessing or crypto provider. For more on this, please | ||
check the preprocessing tutorial. | ||
|
||
1. Running the server: | ||
```shell | ||
node demos/array-mpc-as-a-service/server.js | ||
``` | ||
|
||
2. Running compute parties: | ||
```shell | ||
# run a single compute party | ||
node demos/array-mpc-as-a-service/compute-party.js | ||
``` | ||
|
||
3. For the input parties, go to *http://localhost:8080/demos/array-mpc-as-a-service/client.html* in a web browser. | ||
|
||
## File structure | ||
The demo consists of the following parts: | ||
1. Server script: *server.js* | ||
2. Web Based input parties: | ||
* *client.html*: UI for the browser. | ||
* *client.js*: Handlers for UI buttons and input validations. | ||
* *client-mpc.js*: MPC protocol for parties that provide input of computation. | ||
3. Compute parties: | ||
* *compute-party.js*: MPC protocol for parties that help compute but do not receive output. | ||
4. Configuration file: | ||
* *config.json* | ||
5. Documentation: | ||
* This *README.md* file. | ||
6. Tests: | ||
* *tests/config-*.json*: configuration files for various tests. | ||
* *tests/test.js*: mocha testing suite. | ||
* *test.sh*: entry point for tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
(function (exports, node) { | ||
if (node) { | ||
// eslint-disable-next-line no-undef | ||
JIFFClient = require('../../lib/jiff-client.js'); | ||
// eslint-disable-next-line no-undef | ||
jiff_restAPI = require('../../lib/ext/jiff-client-restful.js'); | ||
} | ||
|
||
var __jiff_instance, config, all_parties; | ||
exports.connect = function (hostname, computation_id, options, _config) { | ||
config = _config; | ||
|
||
all_parties = config.compute_parties.concat(config.input_parties); | ||
|
||
var opt = Object.assign({}, options); | ||
opt['crypto_provider'] = config.preprocessing === false; | ||
opt['initialization'] = { role: 'input' }; | ||
opt['party_count'] = config.party_count; | ||
opt['autoConnect'] = false; | ||
|
||
// eslint-disable-next-line no-undef | ||
__jiff_instance = new JIFFClient(hostname, computation_id, opt); | ||
// eslint-disable-next-line no-undef | ||
__jiff_instance.apply_extension(jiff_restAPI); | ||
__jiff_instance.connect(); | ||
return __jiff_instance; | ||
}; | ||
exports.compute = function (input, jiff_instance_) { | ||
var jiff_instance = __jiff_instance; | ||
if (jiff_instance_) { | ||
jiff_instance = jiff_instance_; | ||
} | ||
|
||
// Set up array sharing | ||
var skeleton = jiff_instance.skeleton_of(input); | ||
var skeletons = {}; | ||
var i, p_id; | ||
for (i = 0; i < config.input_parties.length; i++) { | ||
p_id = config.input_parties[i]; | ||
skeletons[p_id] = skeleton; // Assume same skeleton for all parties | ||
} | ||
|
||
// Share with compute parties | ||
jiff_instance.share_ND_array(input, skeletons, null, config.compute_parties, config.input_parties); | ||
|
||
// If this party is still connected after the compute parties are done, it will | ||
// receive the result. | ||
|
||
var promise = jiff_instance.receive_open_array(all_parties, config.compute_parties); | ||
|
||
promise.then(function (value) { | ||
jiff_instance.disconnect(true, true); | ||
}); | ||
|
||
return promise; | ||
}; | ||
}((typeof exports === 'undefined' ? this.mpc = {} : exports), typeof exports !== 'undefined')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!-- Basic UI for running the demo in the browser --> | ||
|
||
<html> | ||
<head> | ||
<title>Sum integers under MPC</title> | ||
<style> | ||
.error { | ||
color: #FF0000; | ||
} | ||
</style> | ||
<script src="/config.js"></script> | ||
|
||
<script src="https://code.jquery.com/jquery-1.11.1.js"></script> | ||
<script src="/dist/jiff-client.js"></script> | ||
<script src="/lib/ext/jiff-client-restful.js"></script> | ||
|
||
<!-- Contains UI Handlers and Input Checks --> | ||
<script type="text/javascript" src="./client.js"></script> | ||
|
||
<!-- Contains Client MPC code --> | ||
<script type="text/javascript" src="./client-mpc.js"></script> | ||
</head> | ||
<body> | ||
<h1>Connect JIFF</h1> | ||
<label for="computation_id">Computation ID</label><input id="computation_id" value="test"/><br/><br/> | ||
<button id="connectButton" onclick="connect();">Connect</button> | ||
<br/><br/> | ||
<hr/> | ||
<h1>Sum and Dot Numbers under MPC as a service</h1> | ||
<label for="number">Enter your array: </label> <br/><br/> | ||
<textarea id="inputText" rows="5" cols="35">[1, 3, 2]</textarea> <button onclick="submit();" disabled="disabled" id="processButton">Start</button><br/> | ||
<div id="output"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Do not modify this file unless you have to. | ||
* This file has UI handlers. | ||
*/ | ||
|
||
/* global config */ | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
function connect() { | ||
$('#connectButton').prop('disabled', true); | ||
var computation_id = $('#computation_id').val(); | ||
|
||
var options = { party_count: config.party_count }; | ||
options.onError = function (_, error) { | ||
$('#output').append("<p class='error'>"+error+'</p>'); | ||
}; | ||
|
||
var hostname = window.location.hostname.trim(); | ||
var port = window.location.port; | ||
if (port == null || port === '') { | ||
port = '80'; | ||
} | ||
if (!(hostname.startsWith('http://') || hostname.startsWith('https://'))) { | ||
hostname = 'http://' + hostname; | ||
} | ||
if (hostname.endsWith('/')) { | ||
hostname = hostname.substring(0, hostname.length-1); | ||
} | ||
if (hostname.indexOf(':') > -1 && hostname.lastIndexOf(':') > hostname.indexOf(':')) { | ||
hostname = hostname.substring(0, hostname.lastIndexOf(':')); | ||
} | ||
|
||
hostname = hostname + ':' + port; | ||
// eslint-disable-next-line no-undef | ||
var jiff = mpc.connect(hostname, computation_id, options, config); | ||
jiff.wait_for(config.compute_parties, function () { | ||
$('#processButton').attr('disabled', false); $('#output').append('<p>Connected to the compute parties!</p>'); | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
function submit() { | ||
var arr = JSON.parse(document.getElementById('inputText').value); | ||
|
||
if (arr.length !== config.input_length) { | ||
alert('Please input an array of length ' + config.input_length + '.'); | ||
return; | ||
} | ||
|
||
for (var i = 0; i < arr.length; i++) { | ||
if (typeof(arr[i]) !== 'number') { | ||
alert('Please input an array of integers.'); | ||
return; | ||
} | ||
} | ||
|
||
$('#processButton').attr('disabled', true); | ||
$('#output').append('<p>Starting...</p>'); | ||
|
||
// eslint-disable-next-line no-undef | ||
var promise = mpc.compute(arr); | ||
promise.then(function (opened_array) { | ||
var results = { | ||
sum: opened_array[0], | ||
product: opened_array[1] | ||
}; | ||
handleResult(results); | ||
}); | ||
} | ||
|
||
function handleResult(results) { | ||
$('#output').append('<p>The sum is ' + results.sum + ' and the inner product is ' + results.product + '.</p>'); | ||
$('#button').attr('disabled', false); | ||
} |
Oops, something went wrong.