Skip to content

Instantly share code, notes, and snippets.

@plantvsbirds
Created October 15, 2019 10:18
Show Gist options
  • Save plantvsbirds/75d570d2f85c7f975db044df2871c428 to your computer and use it in GitHub Desktop.
Save plantvsbirds/75d570d2f85c7f975db044df2871c428 to your computer and use it in GitHub Desktop.
check mp2... compare garble result. look up table... etc...
from circuit import BooleanCircuit
from evaluator import GarbledCircuitEvaluator
if __name__ == "__main__":
import sys
import json
if len(sys.argv) < 3:
print("usage: python duipai.py <circuit.json> <garbled.json>")
sys.exit(1)
filename = sys.argv[1]
obj = json.load(open(filename))
# Circuit
c = BooleanCircuit(from_json=obj)
print(('Circuit loaded: %d gates, %d input wires, %d output_wires, %d total' \
% (len(c.gates), len(c.input_wires), len(c.output_wires), len(c.wires))))
cout = None
# inputs
if "inputs" in obj:
print("Inputs found")
inputs = obj["inputs"]
assert len(inputs) == len(c.input_wires)
cout = c.evaluate(inputs)
filename = sys.argv[2]
obj = json.load(open(filename))
c = GarbledCircuitEvaluator(from_json=obj)
print('Garbled circuit loaded: %d gates, %d input wires, %d output_wires, %d total' \
% (len(c.gates), len(c.input_wires), len(c.output_wires), len(c.wires)), file=sys.stderr)
# Evaluate the circuit
inputs = obj["inputs"]
gout = c.garbled_evaluate(inputs)
for wid, wv in cout.items():
assert gout[wid] == obj["wire_labels"][wid][wv]
print("wow")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment