Tord Ingolf Reistad <to...@stud.ntnu.no> writes: > Hello, > > Continuing on my previous email about how to code things in VIFF. I > hereby present the complete test code. > > It seems my calculations are done at the same time that the reactor > is closing down so sometimes my code does not return any printed > values. This is a mistake, either in my understanding of VIFF or in > the framework itself.
Yeah, I know what you mean... it takes a bit of time to wrap your head around how to structure things in VIFF. The solution is often very simple when someone else points it out, though :-) But don't worry, after the initial head-ache, you'll be fine... > See the two runs below. > > > class Protocol: > > def __init__(self, runtime): > # Save the Runtime for later use > self.runtime = runtime > own_id = self.runtime.id > > Zp = GF(43) > test_vector = [0, 1, 6, 0] > self.value = test_vector[own_id - 1] > m1, m2, m3 = runtime.shamir_share([1, 2, 3], Zp, self.value) > shares = [m1, m2, m3] > r_as_bits = [m1, m2, m1] > r = m3 > mask = m3 > x = m3 > result = self.protocol_part_1(r_as_bits, r, mask, x) > callback_result = result.addCallback(self.print_answer) > #results.addCallback(lambda _: runtime.synchronize()) > m1.addCallback(lambda _: runtime.shutdown()) This is a problem -- just as soon as m1 arrives from the Shamir sharing above, runtime.shutdown will be called. You will want to call runtime.shutdown at a later point when you know that the protocol is done. > #Create_random_bits > #Convert_to_test_values > #Test_values if useable use random bits otherwise find new bits > #c = r + x > #Compare (c,r) > > def protocol_part_1(self, r_as_bits, r, mask, x): > test = self.test_not_all_zero(r_as_bits, mask) > self.r = r > self.x = x > return test.addCallback(self.protocol_part_2) > > def protocol_part_2(self, test): > if test: > c = self.r + self.x > c_open = self.runtime.open(c) > result = gather_shares([c_open]) > callback_result = result.addCallback(self.print_answer) > return callback_result > else: > print "No value, False" > return False > > def print_answer(self, value): > print "Result ", value I think you want to call self.runtime.shutdown() here since this is when your result is there. -- Martin Geisler VIFF (Virtual Ideal Functionality Framework) brings easy and efficient SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/. _______________________________________________ viff-devel mailing list (http://viff.dk/) viff-devel@viff.dk http://lists.viff.dk/listinfo.cgi/viff-devel-viff.dk