def test(): sid = ('one', (1, 2)) f2p, p2f = GenChannel(), GenChannel() f2a, a2f = GenChannel(), GenChannel() f2z, z2f = GenChannel(), GenChannel() p2a, a2p = GenChannel(), GenChannel() p2z, z2p = GenChannel(), GenChannel() z2a, a2z = GenChannel(), GenChannel() p = PartyWrapper(sid, z2p, p2z, f2p, p2f, a2p, p2a) gevent.spawn(p.run) f = FunctionalityWrapper(p2f, f2p, a2f, f2a, z2f, f2z) gevent.spawn(f.run) f.newFID(sid, 'F_clock', Clock_Functionality) advitm = DummyAdversary('adv', -1, z2a, a2z, p2a, a2p, a2f, f2a) setAdversary(advitm) gevent.spawn(advitm.run) z2p.write((1, ((sid, 'F_clock'), ('RequestRound', )))) fro, (to, msg) = wait_for(p2z) print('\033[1m\tRound from F_clock from 1\033[0m', msg) z2p.write((2, ((sid, 'F_clock'), ('RoundOK', )))) fro, msg = wait_for(p2z) print('\033[1mOK from f_clock after OK from 2\033[0m', msg) z2a.write(('A2F', ((sid, 'F_clock'), ('get-leaks', )))) fro, msg = wait_for(a2z) print('\033[1m\tAdversary leak on OK from 2\033[0m', msg) z2p.write((2, ((sid, 'F_clock'), ('RequestRound', )))) fro, (to, msg) = wait_for(p2z) print('\033[1m\tRound from F_clock for 2\033[0m', msg) z2p.write((1, ((sid, 'F_clock'), ('RoundOK', )))) fro, msg = wait_for(p2z) print('\033[1mOK from f_clock after OK from 1\033[0m', msg) z2a.write(('A2F', ((sid, 'F_clock'), ('get-leaks', )))) fro, msg = wait_for(a2z) print('\033[1m\tAdversary leak on OK from 1\033[0m', msg) z2p.write((2, ((sid, 'F_clock'), ('RequestRound', )))) fro, (to, msg) = wait_for(p2z) print('\033[1m\tRound from F_clock for 2\033[0m', msg)
def test(): sid = ('one', 1, 2) f2p, p2f = GenChannel(), GenChannel() f2a, a2f = GenChannel(), GenChannel() f2z, z2f = GenChannel(), GenChannel() p2a, a2p = GenChannel(), GenChannel() p2z, z2p = GenChannel(), GenChannel() z2a, a2z = GenChannel(), GenChannel() p = PartyWrapper(sid, z2p, p2z, f2p, p2f, a2p, p2a) gevent.spawn(p.run) f = FunctionalityWrapper(p2f, f2p, a2f, f2a, z2f, f2z) gevent.spawn(f.run) f.newFID(sid, 'F_bd', BD_SEC_Functionality) advitm = KatzDummyAdversary('adv', -1, z2a, a2z, p2a, a2p, a2f, f2a) setAdversary(advitm) gevent.spawn(advitm.run) z2p.write((1, ((sid, 'F_bd'), ('send', 'hello')))) msg = wait_for(p2z) print('Party back from f_bd', msg) z2a.write(('A2F', ((sid, 'F_bd'), ('get-leaks', )))) msg = wait_for(a2z) print('Leaks the right way', msg) z2a.write(('A2F', ((sid, 'F_bd'), ('delay', 0)))) msg = wait_for(a2z) print('adv message', msg) z2p.write((2, ((sid, 'F_bd'), ('fetch', )))) fro, (receiver, msg) = wait_for(p2z) print('p2z message', msg)
def test_one_crupt_party(): sid = ('one', 4, (1, 2, 3, 4)) f2p, p2f = GenChannel('f2p'), GenChannel('p2f') f2a, a2f = GenChannel('f2a'), GenChannel('a2f') f2z, z2f = GenChannel('f2z'), GenChannel('z2f') p2a, a2p = GenChannel('p2a'), GenChannel('a2p') p2z, z2p = GenChannel('p2z'), GenChannel('z2p') z2a, a2z = GenChannel('z2a'), GenChannel('a2z') z_crupt(sid, 4) f = FunctionalityWrapper(p2f, f2p, a2f, f2a, z2f, f2z) gevent.spawn(f.run) f.newcls('F_clock', Clock_Functionality) f.newcls('F_bd', BD_SEC_Functionality) advitm = KatzDummyAdversary(sid, -1, z2a, a2z, p2a, a2p, a2f, f2a) setAdversary(advitm) gevent.spawn(advitm.run) p = ProtocolWrapper(z2p, p2z, f2p, p2f, a2p, p2a, Bracha_Protocol) gevent.spawn(p.run) #z2a.write( ('A2F', ('corrupt',4)) ) #z2a.write( ('corrupt',(sid,4)) ) z2a.write(('corrupt', 4)) wait_for(a2z) # Start synchronization requires roundOK first to determine honest parties # giving input to a party before all have done this will result in Exception p.spawn(sid, 1) wait_for(a2z) p.spawn(sid, 2) wait_for(a2z) p.spawn(sid, 3) wait_for(a2z) p.spawn(sid, 4) wait_for(a2z) ## DEALER INPUT z2p.write(((sid, 1), ('input', 10))) wait_for(a2z) # N=3 ACTIVATIONS FOR ROUND=1 (Dealer sends VAL) for i in range(4): z2p.write(((sid, 1), ('output', ))) wait_for(a2z) z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) # # z2a.write( ('A2P', ((sid,4), ( ((sid, 'F_clock'), ('RoundOK',))))) ) # wait_for(a2z) # # # N=3 ACTIVATIONS FOR ROUND=2 (get VAL, send ECHO) for i in range(4): z2p.write(((sid, 1), ('output', ))) wait_for(a2z) z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) # N=3 ACTIVATIONS FOR ROUND=3 (get ECHO, send READY) for _ in range(3): z2p.write(((sid, 1), ('output', ))) wait_for(a2z) z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) z2p.write(((sid, 1), ('output', ))) wait_for(a2z) z2p.write(((sid, 1), ('output', ))) fro, msg = wait_for(p2z) assert msg[0] == 'early' z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) # First activation should get READY and ACCEPT (get READY, wait n activations to output) for i in range(4): z2p.write(((sid, 3), ('output', ))) wait_for(a2z) z2p.write(((sid, 1), ('output', ))) wait_for(a2z) z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 1), ('output', ))) fro, msg = wait_for(p2z) print("P1 output", msg) z2p.write(((sid, 2), ('output', ))) fro, msg = wait_for(p2z) print("P2 output", msg) z2p.write(((sid, 3), ('output', ))) fro, msg = wait_for(p2z) print("P3 output", msg)
def test_crupt_dealer_1_accept_1_not(): sid = ('one', 4, (1, 2, 3)) f2p, p2f = GenChannel('f2p'), GenChannel('p2f') f2a, a2f = GenChannel('f2a'), GenChannel('a2f') f2z, z2f = GenChannel('f2z'), GenChannel('z2f') p2a, a2p = GenChannel('p2a'), GenChannel('a2p') p2z, z2p = GenChannel('p2z'), GenChannel('z2p') z2a, a2z = GenChannel('z2a'), GenChannel('a2z') z_crupt(sid, 1) f = FunctionalityWrapper(p2f, f2p, a2f, f2a, z2f, f2z) gevent.spawn(f.run) f.newcls('F_clock', Clock_Functionality) f.newcls('F_bd', BD_SEC_Functionality) advitm = KatzDummyAdversary('adv', -1, z2a, a2z, p2a, a2p, a2f, f2a) setAdversary(advitm) gevent.spawn(advitm.run) p = ProtocolWrapper(sid, z2p, p2z, f2p, p2f, a2p, p2a, Bracha_Protocol) gevent.spawn(p.run) # Start synchronization requires roundOK first to determine honest parties # giving input to a party before all have done this will result in Exception p.spawn(1) wait_for(a2z) p.spawn(2) wait_for(a2z) p.spawn(3) wait_for(a2z) # corrupt the dealer # change protocol itm to a passthrough itm # register corruption with F_clock z2a.write(('A2P', (1, ((('one', 1, 2, 1), 'F_bd'), ('send', ('VAL', 3)))))) wait_for(a2z) z2a.write(('A2P', (1, ((('one', 1, 3, 1), 'F_bd'), ('send', ('VAL', 3)))))) wait_for(a2z) z2a.write(('A2P', (1, (((sid, 'F_clock'), ('RoundOK', )))))) wait_for(a2z) for _ in range(3): z2p.write((2, ('output', ))) wait_for(a2z) z2p.write((3, ('output', ))) wait_for(a2z) for _ in range(3): z2p.write((2, ('output', ))) wait_for(a2z) z2p.write((3, ('output', ))) wait_for(a2z) z2a.write(('A2P', (1, (((sid, 'F_clock'), ('RoundOK', )))))) wait_for(a2z) for _ in range(3): z2p.write((2, ('output', ))) wait_for(a2z) z2a.write( ('A2P', (1, ((('one', 1, 2, 3), 'F_bd'), ('send', ('READY', 3)))))) wait_for(a2z) z2a.write( ('A2P', (1, ((('one', 1, 3, 3), 'F_bd'), ('send', ('READY', 3)))))) wait_for(a2z) z2a.write(('A2P', (1, (((sid, 'F_clock'), ('RoundOK', )))))) wait_for(a2z) for _ in range(3): z2p.write((3, ('output', ))) wait_for(a2z) z2p.write((2, ('output', ))) wait_for(a2z) z2p.write((3, ('output', ))) wait_for(a2z)
def test_sim(): sid = ('one', 4, (1, 2, 3)) f2p, p2f = GenChannel('f2p'), GenChannel('p2f') f2a, a2f = GenChannel('f2a'), GenChannel('a2f') f2z, z2f = GenChannel('f2z'), GenChannel('z2f') p2a, a2p = GenChannel('p2a'), GenChannel('a2p') p2z, z2p = GenChannel('p2z'), GenChannel('z2p') z2a, a2z = GenChannel('z2a'), GenChannel('a2z') f = FunctionalityWrapper(p2f, f2p, a2f, f2a, z2f, f2z) gevent.spawn(f.run) f.newcls('F_sfe', SFE_Bracha_Functionality) #advitm = DummyAdversary('adv',-1, z2a,a2z, p2a,a2p, a2f,f2a) advitm = BrachaSimulator(('one', (1, 2, 3)), -1, z2a, a2z, p2a, a2p, a2f, f2a) setAdversary(advitm) gevent.spawn(advitm.run) p = PartyWrapper(sid, z2p, p2z, f2p, p2f, a2p, p2a, 'F_sfe') gevent.spawn(p.run) p.spawn(1) wait_for(a2z) p.spawn(2) wait_for(a2z) p.spawn(3) wait_for(a2z) z2p.write((1, ('input', 3))) wait_for(a2z) print('\n\n\n\n\n\n\n\n\n\n ***') f2a.write(((sid, 'F_sfe'), ('input', 1, 3))) wait_for(a2z) for _ in range(2): f2a.write(((sid, 'F_sfe'), ('activated', 1))) fro, msg = wait_for(a2z) assert msg == (1, ('sent', ('VAL', 3))), msg f2a.write(((sid, 'F_sfe'), ('activated', 1))) fro, msg = wait_for(a2z) for _ in range(3): f2a.write(((sid, 'F_sfe'), ('activated', 2))) wait_for(a2z) f2a.write(((sid, 'F_sfe'), ('activated', 3))) wait_for(a2z) for _ in range(2): f2a.write(((sid, 'F_sfe'), ('activated', 1))) fro, msg = wait_for(a2z) assert msg == (1, ('sent', ('ECHO', 3))), msg f2a.write(((sid, 'F_sfe'), ('activated', 2))) fro, msg = wait_for(a2z) assert msg == (2, ('sent', ('ECHO', 3))), msg f2a.write(((sid, 'F_sfe'), ('activated', 3))) fro, msg = wait_for(a2z) assert msg == (3, ('sent', ('ECHO', 3))) f2a.write(((sid, 'F_sfe'), ('activated', 3))) fro, msg = wait_for(a2z) assert msg == ('switch', 3), msg f2a.write(((sid, 'F_sfe'), ('activated', 2))) fro, msg = wait_for(a2z) assert msg == ('switch', 2), msg f2a.write(((sid, 'F_sfe'), ('activated', 1))) fro, msg = wait_for(a2z) assert msg == ('switch', 1), msg for _ in range(2): f2a.write(((sid, 'F_sfe'), ('activated', 1))) fro, msg = wait_for(a2z) assert msg == (1, ('sent', ('READY', 3))), msg f2a.write(((sid, 'F_sfe'), ('activated', 2))) fro, msg = wait_for(a2z) assert msg == (2, ('sent', ('READY', 3))), msg f2a.write(((sid, 'F_sfe'), ('activated', 3))) fro, msg = wait_for(a2z) assert msg == (3, ('sent', ('READY', 3))) f2a.write(((sid, 'F_sfe'), ('activated', 3))) fro, msg = wait_for(a2z) assert msg == ('switch', 3), msg f2a.write(((sid, 'F_sfe'), ('activated', 2))) fro, msg = wait_for(a2z) assert msg == ('switch', 2), msg f2a.write(((sid, 'F_sfe'), ('activated', 1))) fro, msg = wait_for(a2z) assert msg == ('switch', 1), msg # TODO prot_bracha should only return after |P| activations # in the last, Rnd=4, round (output takes the place of 'early') for _ in range(1): f2a.write(((sid, 'F_sfe'), ('activated', 1))) wait_for(a2z) f2a.write(((sid, 'F_sfe'), ('activated', 2))) wait_for(a2z) f2a.write(((sid, 'F_sfe'), ('activated', 3))) wait_for(a2z)
def test_one_crupt_party(): sid = ('one', 4, (1, 2, 3, 4)) f2p, p2f = GenChannel('f2p'), GenChannel('p2f') f2a, a2f = GenChannel('f2a'), GenChannel('a2f') f2z, z2f = GenChannel('f2z'), GenChannel('z2f') p2a, a2p = GenChannel('p2a'), GenChannel('a2p') p2z, z2p = GenChannel('p2z'), GenChannel('z2p') z2a, a2z = GenChannel('z2a'), GenChannel('a2z') z_crupt(sid, 4) f = FunctionalityWrapper(p2f, f2p, a2f, f2a, z2f, f2z) gevent.spawn(f.run) f.newcls('F_sfe', SFE_Bracha_Functionality) advitm = BrachaSimulator(sid, -1, z2a, a2z, p2a, a2p, a2f, f2a) setAdversary(advitm) gevent.spawn(advitm.run) p = PartyWrapper(z2p, p2z, f2p, p2f, a2p, p2a, 'F_sfe') gevent.spawn(p.run) z2a.write(('corrupt', 4)) wait_for(a2z) p.spawn(sid, 1) wait_for(a2z) p.spawn(sid, 2) wait_for(a2z) p.spawn(sid, 3) wait_for(a2z) p.spawn(sid, 4) wait_for(a2z) z2p.write(((sid, 1), ('input', 3))) m = wait_for(a2z) #z2a.write( ('A2P', (4, ( ((sid, 'F_clock'), ('RoundOK',))))) ) #wait_for(a2z) for _ in range(4): z2p.write(((sid, 1), ('output', ))) wait_for(a2z) z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) for _ in range(4): z2p.write(((sid, 1), ('output', ))) fro, msg = wait_for(a2z) z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) for _ in range(4): z2p.write(((sid, 1), ('output', ))) fro, msg = wait_for(a2z) z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) for _ in range(4): z2p.write(((sid, 1), ('output', ))) wait_for(a2z) z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) z2p.write(((sid, 1), ('output', ))) fro, m = wait_for(p2z) print('P1 output:', m) z2p.write(((sid, 2), ('output', ))) fro, m = wait_for(p2z) print('P2 output;', m) z2p.write(((sid, 3), ('output', ))) fro, m = wait_for(p2z) print('P3 output:', m)
def test_all_honest(): sid = ('one', 4, (1, 2, 3)) f2p, p2f = GenChannel('f2p'), GenChannel('p2f') f2a, a2f = GenChannel('f2a'), GenChannel('a2f') f2z, z2f = GenChannel('f2z'), GenChannel('z2f') p2a, a2p = GenChannel('p2a'), GenChannel('a2p') p2z, z2p = GenChannel('p2z'), GenChannel('z2p') z2a, a2z = GenChannel('z2a'), GenChannel('a2z') f = FunctionalityWrapper(p2f, f2p, a2f, f2a, z2f, f2z) gevent.spawn(f.run) f.newcls('F_sfe', SFE_Bracha_Functionality) #advitm = DummyAdversary('adv',-1, z2a,a2z, p2a,a2p, a2f,f2a) advitm = BrachaSimulator(sid, -1, z2a, a2z, p2a, a2p, a2f, f2a) setAdversary(advitm) gevent.spawn(advitm.run) p = PartyWrapper(z2p, p2z, f2p, p2f, a2p, p2a, 'F_sfe') gevent.spawn(p.run) p.spawn(sid, 1) wait_for(a2z) p.spawn(sid, 2) wait_for(a2z) p.spawn(sid, 3) wait_for(a2z) z2p.write(((sid, 1), ('input', 3))) wait_for(a2z) for _ in range(3): z2p.write(((sid, 1), ('output', ))) wait_for(a2z) z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) for _ in range(3): z2p.write(((sid, 1), ('output', ))) fro, msg = wait_for(a2z) z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) for _ in range(2): z2p.write(((sid, 1), ('output', ))) wait_for(a2z) z2p.write(((sid, 2), ('output', ))) fro, msg = wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) z2p.write(((sid, 1), ('output', ))) wait_for(a2z) z2p.write(((sid, 1), ('output', ))) fro, msg = wait_for(p2z) assert msg[0] == 'early' z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 3), ('output', ))) wait_for(a2z) for _ in range(3): z2p.write(((sid, 3), ('output', ))) wait_for(a2z) z2p.write(((sid, 1), ('output', ))) wait_for(a2z) z2p.write(((sid, 2), ('output', ))) wait_for(a2z) z2p.write(((sid, 1), ('output', ))) fro, msg = wait_for(p2z) print('P1 output', msg) z2p.write(((sid, 2), ('output', ))) fro, msg = wait_for(p2z) print('P2 output', msg) z2p.write(((sid, 3), ('output', ))) fro, msg = wait_for(p2z) print('P3 output', msg)