Hello,
I have a problem with how to structure codes with much callback in VIFF.
I want to do some stuff with shares, reveal some values, do more
calculations with shares, reveal more values, and so on.
For illustration purposes, lets say I have a bitwise secret shared value
r (r and r_as_bits), and I want to compute c = x + r. Then reveal c and
print it and reveal c. But this is only done if bits of r are not all zero.
Below is the psudocode and the real code. The real code does not work,
because it will return the last result only if the reactor is not shut
down prematurely. So my question is how do I get a working program that
looks more like my psaudocode?
psaudocode:
--------------------------------------
def protocol(r_as_bits, mask, r, x):
test = test_not_all_zero(r_as_bits, mask)
if test == True
c = r + x
c = open(c)
print c
else
print "False"
def test_not_all_zero(r_as_bits, mask)
#reveal (sum(bits) - number_of_bits)*mask
temp = sum(r_as_bits[:]) - len(r_as_bits)) * mask
temp = open(temp)
if temp == 0
return False
return True
-------------------------------------
real code: 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
return True
def test_not_all_zero(self, r_as_bits, mask):
#reveal (sum(bits))*mask
temp = sum(r_as_bits[:]) * mask
temp_open = self.runtime.open(temp)
def check_result(check):
print "Comparing ", check, " to 0"
if check[0].value == 0:
return False
return True
_______________________________________________
viff-devel mailing list (http://viff.dk/)
viff-devel@viff.dk
http://lists.viff.dk/listinfo.cgi/viff-devel-viff.dk