Newbie question
Francois Koeune <francois.koeune <at> uclouvain.be>
2011-03-16 18:15:26 GMT
Hello,
A real beginner question, I am afraid : I just started playing with VIFF.
After installing the tools and running some of the apps example, I tried
writing my own code, starting by modifying some of the examples.
Taking shamir-share-open.py as a starting point, I started by doing some
extra computations with the 3 shared values, e.g. computing a*c+b.
Everything went fine.
Then I wanted to compare some values. So I began by mixing Toft07Runtime
with the default class, and adding a line like
d = greater_than_equal(a,b) # (BTW, I know I could do the same with
the operator >=)
Now the code stalls. Checking the file sort.py, the comparison result
appears to be a deferred, so I tried adding a callback to d, but with no
success. I also compared my code with compare.py, but I do not see where
I deviate from what they do.
Can anybody help me ? Sorry again if the question is stupid, I am a bit
lost here, and searching mostly by mimicing other programs and trying
whether it works isn't very efficient.
I am also open to any comment regarding « bad practices » in my 10 lines
of code, and to any pointer to things I should read to begin with (I
must confess I am also a beginner to Twisted, but Twisted is a huge
tool, and it seems difficult to become a Twisted expert before being
able to play with VIFF).
Last question so far : it seems quite logical to me that the result of
a comparison is a deferred, and also that the result of an addition is
immediate. On the other hand, I am a bit surprised that the result of a
multiplication (cf. my a*b+c above) seems to be immediate, as
multiplying requires all participants to be involved ... Or perhaps I
was just extremely lucky to get the result ?
Here is my code :
=====================================================================
import sys
import viff.reactor
viff.reactor.install()
from twisted.internet import reactor
from optparse import OptionParser
from viff.field import GF
from viff.runtime import Runtime, create_runtime, gather_shares
from viff.config import load_config
from viff.util import dprint
from viff.comparison import Toft07Runtime
id, players = load_config(sys.argv[1])
Zp = GF(int(sys.argv[2]))
input = int(sys.argv[3])
print "I am player %d and will input %s" % (id, input)
def protocol(rt):
def dready(d):
print "OK"*32
dd = rt.open(d)
dprint("### opened d: %s ###", dd)
def problem(d):
print "!"*64
print "-" * 64
print "Program started"
print
a, b, c = rt.shamir_share([1, 2, 3], Zp, input)
aa = rt.open(a)
bb = rt.open(b)
cc = rt.open(c)
dprint("### opened a: %s ###", aa)
dprint("### opened b: %s ###", bb)
dprint("### opened c: %s ###", cc)
res = a*c+b
rres = rt.open(res)
dprint("### opened res: %s ###", rres)
d = greater_than_equal(a,b)
d.addCallback(dready)
d.addErrback(problem)
rt.wait_for(aa, bb, cc, rres)
pre_runtime = create_runtime(id, players, 1, runtime_class=Toft07Runtime)
pre_runtime.addCallback(protocol)
reactor.callLater(10, reactor.stop)
reactor.run()