Discussion:
[PATCH 0 of 6] equality support in the runtime
Sigurd Meldgaard
2008-09-16 18:15:37 UTC
Permalink
I have written a new mixin for doing secret equality testing!
Sigurd Meldgaard
2008-09-16 18:15:43 UTC
Permalink
# HG changeset patch
# User Sigurd Meldgaard <***@daimi.au.dk>
# Date 1219613205 -7200
# Node ID 643a1d2541ec0639a3f1bed8bb0ff9762dd3dd68
# Parent 87cc366a4c27167b8548214d023d8967271e3d38
Removed doubling of word in comment

diff -r 87cc366a4c27 -r 643a1d2541ec viff/runtime.py
--- a/viff/runtime.py Mon Sep 08 18:31:14 2008 +0200
+++ b/viff/runtime.py Sun Aug 24 23:26:45 2008 +0200
@@ -1034,7 +1034,7 @@

The number is shared using polynomial of degree *threshold*
(defaults to :attr:`threshold`). Returns a list of shares
- unless unless there is only one inputter in which case the
+ unless there is only one inputter in which case the
share is returned directly.

Communication cost: n elements transmitted.
Martin Geisler
2008-09-16 20:33:09 UTC
Permalink
Post by Sigurd Meldgaard
# HG changeset patch
# Date 1219613205 -7200
# Node ID 643a1d2541ec0639a3f1bed8bb0ff9762dd3dd68
# Parent 87cc366a4c27167b8548214d023d8967271e3d38
Removed doubling of word in comment
diff -r 87cc366a4c27 -r 643a1d2541ec viff/runtime.py
--- a/viff/runtime.py Mon Sep 08 18:31:14 2008 +0200
+++ b/viff/runtime.py Sun Aug 24 23:26:45 2008 +0200
@@ -1034,7 +1034,7 @@
The number is shared using polynomial of degree *threshold*
(defaults to :attr:`threshold`). Returns a list of shares
- unless unless there is only one inputter in which case the
+ unless there is only one inputter in which case the
share is returned directly.
Thanks, applied as 635a8d6ac335!
--
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.
Sigurd Meldgaard
2008-09-16 18:15:40 UTC
Permalink
# HG changeset patch
# User Sigurd Meldgaard <***@daimi.au.dk>
# Date 1221574270 -7200
# Node ID 5aa168c8778a1e2909cda7c1ea08da8501b66a95
# Parent a0b713380c029ca32f42e5fa1b4d8752f74e578b
Test of robabilistic equality mix-in
* * *

diff -r a0b713380c02 -r 5aa168c8778a viff/test/test_runtime_equal.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/viff/test/test_runtime_equal.py Tue Sep 16 16:11:10 2008 +0200
@@ -0,0 +1,67 @@
+# Copyright 2008 VIFF Development Team.
+#
+# This file is part of VIFF, the Virtual Ideal Functionality Framework.
+#
+# VIFF is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License (LGPL) as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIFF is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
+
+
+"""Tests of the equality protocol(s)."""
+
+import operator
+
+from viff.equality import ProbabilisticEqualityMixin
+from viff.test.util import RuntimeTestCase, BinaryOperatorTestCase
+from viff.runtime import Runtime
+
+
+class EqualRuntime(Runtime, ProbabilisticEqualityMixin):
+ """A runtime with the equality mixin."""
+ pass
+
+
+class ProbabilisticEqualityTestDifferent(BinaryOperatorTestCase,
+ RuntimeTestCase):
+ """Testin the equality with a and b different."""
+ # Arbitrarily chosen
+ a = 12442
+ b = 91243
+ runtime_class = EqualRuntime
+ operator = operator.eq
+
+
+class ProbabilisticEqualityTestEqual(BinaryOperatorTestCase, RuntimeTestCase):
+ """Testin the equality with a and b equal."""
+ a = 4023
+ b = 4023
+ runtime_class = EqualRuntime
+ operator = operator.eq
+
+
+class ProbabilisticEqualityTestDiff1_1(BinaryOperatorTestCase,
+ RuntimeTestCase):
+ """Testin the equality with a and b different by only one."""
+ a = 0
+ b = 1
+ runtime_class = EqualRuntime
+ operator = operator.eq
+
+
+class ProbabilisticEqualityTestDiff1_2(BinaryOperatorTestCase,
+ RuntimeTestCase):
+ """Testin the equality with a and b different by only in the other
+ direction."""
+ a = 1
+ b = 0
+ runtime_class = EqualRuntime
+ operator = operator.eq
Martin Geisler
2008-09-16 20:12:35 UTC
Permalink
Sigurd Meldgaard <***@daimi.au.dk> writes:

Excellent tests -- I like the idea of testing both equal and unequal
numbers, this is actually something which we ought to test with the
other binary operators too.
Post by Sigurd Meldgaard
# HG changeset patch
# Date 1221574270 -7200
# Node ID 5aa168c8778a1e2909cda7c1ea08da8501b66a95
# Parent a0b713380c029ca32f42e5fa1b4d8752f74e578b
Test of robabilistic equality mix-in
Typo ^^^
Post by Sigurd Meldgaard
* * *
I bet those stars are the result of a qfold command... it has this funny
default of merging the commit messages with "* * *" inbetween. Could you
qrefresh and delete it?
Post by Sigurd Meldgaard
+ """A runtime with the equality mixin."""
+ pass
+
+
+class ProbabilisticEqualityTestDifferent(BinaryOperatorTestCase,
+ """Testin the equality with a and b different."""
Missing "g" ^^^ I think I saw this two times more.
Post by Sigurd Meldgaard
+class ProbabilisticEqualityTestDiff1_2(BinaryOperatorTestCase,
+ """Testin the equality with a and b different by only in the other
Here too :-) And I think there is a "one" missing here ^
Post by Sigurd Meldgaard
+ direction."""
+ a = 1
+ b = 0
+ runtime_class = EqualRuntime
+ operator = operator.eq
--
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.
Sigurd Meldgaard
2008-09-16 18:15:39 UTC
Permalink
# HG changeset patch
# User Sigurd Meldgaard <***@daimi.au.dk>
# Date 1221574165 -7200
# Node ID a0b713380c029ca32f42e5fa1b4d8752f74e578b
# Parent 3d1bfa3cb9e2b58a0e47a8fa11c36049762d5a1b
Probabilistic equality mix-in

diff -r 3d1bfa3cb9e2 -r a0b713380c02 viff/equality.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/viff/equality.py Tue Sep 16 16:09:25 2008 +0200
@@ -0,0 +1,111 @@
+# Copyright 2008 VIFF Development Team.
+#
+# This file is part of VIFF, the Virtual Ideal Functionality Framework.
+#
+# VIFF is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License (LGPL) as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIFF is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
+
+"""Equality protocol. The mixin class defined here provide an
+:meth:`equal` method to the :class:`Runtime
+<viff.runtime.Runtime>` they are mixed with.
+"""
+
+from viff.runtime import increment_pc
+
+class ProbabilisticEqualityMixin:
+ """This class implements probabilistic constant-round secure
+ equality-testing of two numbers."""
+
+ @increment_pc
+ def equal(self, share_x, share_y):
+ """
+ Assumes p = 3 mod 4, returns a secret sharing of 1 if
+ share_x == share_y and 0 otherwise.
+
+ This is the probabilistic method based on quadratic reciprocity
+ described in: "Constant-Round Multiparty Computation for
+ Interval Test, Equality Test, and Comparison" by Takashi
+ Nishide and Kazuo Ohta, and fails with probability 1/(2**k)
+ where k is set to the security parameter of the runtime.
+
+ TODO: Make it work for any prime-modulo, the b's should be in
+ {y,1} where y is a non-square modulo p.
+
+ TODO: Make the final "and"ing of the x's more efficient as
+ described in the paper.
+ """
+
+ Zp = share_x.field
+
+ a = share_x - share_y # We will check if a == 0
+ k = self.options.security_parameter
+
+ # The b's are random numbers in {-1, 1}
+ b = [self.prss_share_random(Zp, binary=True) * 2 - 1
+ for _ in range(k)]
+ r = [self.prss_share_random(Zp) for _ in range(k)]
+ rp = [self.prss_share_random(Zp) for _ in range(k)]
+
+ # If b_i == 1 c_i will always be a square modulo p if a is zero
+ # and with probability 1/2 otherwise (except if rp == 0)
+ # If b_i == -1 it will be non-square
+ c = [self.open(a * r[j] + b[j] * rp[j] * rp[j]) for j in range(k)]
+
+ def finish(cj, bj):
+ l = legendre_mod_p(cj)
+ assert l != 0 # This will only happen with negligible probability
+ if l == 1:
+ xj = (1/Zp(2)) * (bj + 1)
+ else: # l == -1
+ assert(l == -1)
+ xj = (-1) * (1/Zp(2)) * (bj - 1)
+ return xj
+
+ x = [cj.addCallback(finish, bj) for cj, bj in zip(c, b)]
+
+ # Take the product (this is here the same as the "and") of all
+ # the x'es
+ while len(x) > 1:
+ x.append(x.pop() * x.pop())
+
+ return x[0]
+
+def legendre_mod_p(a):
+ """
+ Returns the legendre symbol legendre(a, p) where p is
+ the order of the field of a.
+
+ Precondition: p must be odd.
+
+ Input:
+ a -- a field element
+ Output:
+ int: -1 if a is not a square mod p,
+ 0 if gcd(a,p) is not 1
+ 1 if a is a square mod p.
+
+ Examples:
+ >>> legendre(GF(5)(2))
+ -1
+ >>> legendre(GF(3)(3))
+ 0
+ >>> legendre(GF(2003)(7))
+ -1
+ """
+ assert a.modulus % 2 == 1
+ b = (a ** ((a.modulus - 1)/2))
+ if b == 1:
+ return 1
+ elif b == a.modulus-1:
+ return -1
+ return 0
Martin Geisler
2008-09-17 08:14:07 UTC
Permalink
Post by Sigurd Meldgaard
+ """
+ Returns the legendre symbol legendre(a, p) where p is
+ the order of the field of a.
+
+ Precondition: p must be odd.
+
+ a -- a field element
+ int: -1 if a is not a square mod p,
+ 0 if gcd(a,p) is not 1
+ 1 if a is a square mod p.
+
+ >>> legendre(GF(5)(2))
+ -1
+ >>> legendre(GF(3)(3))
+ 0
+ >>> legendre(GF(2003)(7))
+ -1
You should make a file like test_shamir.py which makes Trial run the
doctests as part of the normal test suite.

It only has to contain:

#: Declare doctests for Trial.
__doctests__ = ['viff.equal']
--
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.
Sigurd Meldgaard
2008-09-16 18:15:41 UTC
Permalink
# HG changeset patch
# User Sigurd Meldgaard <***@daimi.au.dk>
# Date 1221574030 -7200
# Node ID f879ad687faab381f1208885a5c1330265e3e119
# Parent 5aa168c8778a1e2909cda7c1ea08da8501b66a95
Added a function viff.runtime.make_runtime_class, that creates a new runtime class with mixins

diff -r 5aa168c8778a -r f879ad687faa viff/runtime.py
--- a/viff/runtime.py Tue Sep 16 16:11:10 2008 +0200
+++ b/viff/runtime.py Tue Sep 16 16:07:10 2008 +0200
@@ -1079,6 +1079,19 @@
result.addCallback(shamir.recombine)
return result

+def make_runtime_class(runtime_class = Runtime, mixins = ()):
+ """Creates a new runtime class with runtime_class as a base class
+ mixing in the mixins.
+
+ mixins must be a list or tuple of mixin-classes.
+ """
+
+ # We must include at least one new-style class in bases. We
+ # include it last to avoid overriding __init__ from the other base
+ # classes.
+ bases = (runtime_class,) + tuple(mixins) + (object,)
+
+ return type("ExtendedRuntime", bases, {})

def create_runtime(id, players, threshold, options=None, runtime_class=Runtime):
"""Create a :class:`Runtime` and connect to the other players.
Martin Geisler
2008-09-16 20:24:14 UTC
Permalink
Post by Sigurd Meldgaard
# HG changeset patch
# Date 1221574030 -7200
# Node ID f879ad687faab381f1208885a5c1330265e3e119
# Parent 5aa168c8778a1e2909cda7c1ea08da8501b66a95
Added a function viff.runtime.make_runtime_class, that creates a new runtime class with mixins
Please try to make the first line in the commit message fit in 80 chars,
otherwise it looks weird in my terminals :-) Then put the bigger
description in a paragraph after the first line.
Post by Sigurd Meldgaard
diff -r 5aa168c8778a -r f879ad687faa viff/runtime.py
--- a/viff/runtime.py Tue Sep 16 16:11:10 2008 +0200
+++ b/viff/runtime.py Tue Sep 16 16:07:10 2008 +0200
@@ -1079,6 +1079,19 @@
result.addCallback(shamir.recombine)
return result
No space around default arguments in functions. Also, I don't think it
makes sense to give mixins as default argument -- people should only use
this function if they actually have something to mix.
Post by Sigurd Meldgaard
+ """Creates a new runtime class with runtime_class as a base class
+ mixing in the mixins.
Please mark parameters a *runtime_class* in the docstrings, that makes
the Sphinx generated output nicer.
Post by Sigurd Meldgaard
+ mixins must be a list or tuple of mixin-classes.
+ """
+
+ # We must include at least one new-style class in bases. We
+ # include it last to avoid overriding __init__ from the other base
+ # classes.
+ bases = (runtime_class,) + tuple(mixins) + (object,)
+
+ return type("ExtendedRuntime", bases, {})
Great idea with such a function so that people wont have to do the scary
dynamic class stuff themselves -- could you please make another patch
which updates apps/benchmark.py to use this function?
--
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.
Sigurd Meldgaard
2008-09-16 18:15:38 UTC
Permalink
# HG changeset patch
# User Sigurd Meldgaard <***@daimi.au.dk>
# Date 1221574088 -7200
# Node ID 3d1bfa3cb9e2b58a0e47a8fa11c36049762d5a1b
# Parent 6ef6574f9c963a635fd3a1e054c0bb849a272783
Added support for equality to the runtime

diff -r 6ef6574f9c96 -r 3d1bfa3cb9e2 viff/runtime.py
--- a/viff/runtime.py Mon Sep 15 22:32:39 2008 +0200
+++ b/viff/runtime.py Tue Sep 16 16:08:08 2008 +0200
@@ -131,6 +131,21 @@
"""Greater-than or equal comparison."""
# self >= other
return self.runtime.greater_than_equal(self, other)
+
+ def __eq__(self, other):
+ """
+ Equality testing
+ returns a share of 1 if self == other mod p
+ 0 otherwise
+ """
+ return self.runtime.equal(self,other)
+
+ def __neq__(self, other):
+ """
+ Negated equality testing
+ """
+ return 1 - self.runtime.equal(self,other)
+

def clone(self):
"""Clone a share.
Sigurd Meldgaard
2008-09-16 18:15:42 UTC
Permalink
# HG changeset patch
# User Sigurd Meldgaard <***@daimi.au.dk>
# Date 1220891474 -7200
# Node ID 87cc366a4c27167b8548214d023d8967271e3d38
# Parent f879ad687faab381f1208885a5c1330265e3e119
Added a new application showing how to use the equality library

diff -r f879ad687faa -r 87cc366a4c27 apps/equality.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/equality.py Mon Sep 08 18:31:14 2008 +0200
@@ -0,0 +1,121 @@
+#!/usr/bin/python
+
+# Copyright 2008 VIFF Development Team.
+#
+# This file is part of VIFF, the Virtual Ideal Functionality Framework.
+#
+# VIFF is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License (LGPL) as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIFF is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
+#
+
+"""
+This program is a very simple example of a viff program.
+It shows the secret equality testing of two numbers
+
+The program can be run as follows for each player (min 3) where 24 is
+the number we would like to compare:
+
+$ python equality.py player-X.ini -n 24
+
+Only the numbers of player 1 and player 2 are actually compared, but
+more players are necessary for the security.
+"""
+
+from optparse import OptionParser
+from twisted.internet import reactor
+
+from viff.field import GF
+from viff.runtime import Runtime, create_runtime, make_runtime_class
+from viff.config import load_config
+from viff.util import find_prime
+from viff.equality import ProbabilisticEqualityMixin
+
+
+class Protocol:
+
+ def __init__(self, runtime):
+ print "connected"
+ self.rt = runtime
+
+ # Is our player id among the two first?
+ if(runtime.id <= 2):
+ print "My number: %d." % options.number
+ # Players 1 and two are doing a sharing over the field ZP
+ # our input is options number
+ (x, y) = runtime.shamir_share([1, 2], Zp, options.number)
+ else:
+ print "I do not have a number."
+ (x, y) = runtime.shamir_share([1, 2], Zp, None)
+
+ # Do the secret computation
+ result = (x == y)
+
+ # Now open the result so that we can see it
+ result = runtime.open(result)
+
+ def finish(e):
+ print
+ if e == 1:
+ print "The two numbers where equal!"
+ else:
+ print "The two numbers where different!"\
+ " (With high probability)"
+ print
+
+
+ # When the values for the opening arrive, we can call the
+ # finish method.
+ result.addCallback(finish)
+ result.addCallback(lambda _: runtime.shutdown())
+
+
+# Parse command line arguments.
+parser = OptionParser(usage=__doc__)
+
+parser.add_option("--modulus",
+ help="lower limit for modulus (can be an expression)")
+parser.add_option("-n", "--number", type="int",
+ help="number to compare")
+parser.add_option("-t", "--test", default=False, action="store_true",
+ help="run doctests on this file")
+
+parser.set_defaults(modulus=2**65)
+
+Runtime.add_options(parser)
+
+options, args = parser.parse_args()
+
+if len(args) == 0:
+ parser.error("you must specify a config file")
+
+Zp = GF(find_prime(options.modulus, blum=True))
+
+# Run doctests
+if options.test:
+ import doctest #pragma NO COVER
+ doctest.testmod(verbose=True) #pragma NO COVER
+
+# Load configuration file.
+id, players = load_config(args[0])
+
+runtime_class = make_runtime_class(mixins = [ProbabilisticEqualityMixin])
+
+pre_runtime = create_runtime(id, players, 1, options,
+ runtime_class = runtime_class)
+pre_runtime.addCallback(Protocol)
+
+# Uncomment the following line to set the numbers for each player
+# options.number = [None, 12, 18, None][id]
+
+# Start the Twisted event loop.
+reactor.run()
Martin Geisler
2008-09-16 20:28:09 UTC
Permalink
Sigurd Meldgaard <***@daimi.au.dk> writes:

Thank you for the application, I have a few small comments below :-)
Post by Sigurd Meldgaard
# HG changeset patch
# Date 1220891474 -7200
# Node ID 87cc366a4c27167b8548214d023d8967271e3d38
# Parent f879ad687faab381f1208885a5c1330265e3e119
Added a new application showing how to use the equality library
Please put a full-stop at the end of sentences.
Post by Sigurd Meldgaard
diff -r f879ad687faa -r 87cc366a4c27 apps/equality.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/equality.py Mon Sep 08 18:31:14 2008 +0200
@@ -0,0 +1,121 @@
+#!/usr/bin/python
+
+# Copyright 2008 VIFF Development Team.
+#
+# This file is part of VIFF, the Virtual Ideal Functionality Framework.
+#
+# VIFF is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License (LGPL) as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIFF is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
+#
+
+"""
+This program is a very simple example of a viff program.
Capitalize viff?
Post by Sigurd Meldgaard
+It shows the secret equality testing of two numbers
+
+The program can be run as follows for each player (min 3) where 24 is
+
+$ python equality.py player-X.ini -n 24
+
+Only the numbers of player 1 and player 2 are actually compared, but
+more players are necessary for the security.
+"""
+
+from optparse import OptionParser
+from twisted.internet import reactor
+
+from viff.field import GF
+from viff.runtime import Runtime, create_runtime, make_runtime_class
+from viff.config import load_config
+from viff.util import find_prime
+from viff.equality import ProbabilisticEqualityMixin
+
+
+
+ print "connected"
+ self.rt = runtime
+
+ # Is our player id among the two first?
+ print "My number: %d." % options.number
+ # Players 1 and two are doing a sharing over the field ZP
+ # our input is options number
+ (x, y) = runtime.shamir_share([1, 2], Zp, options.number)
+ print "I do not have a number."
+ (x, y) = runtime.shamir_share([1, 2], Zp, None)
+
+ # Do the secret computation
+ result = (x == y)
+
+ # Now open the result so that we can see it
+ result = runtime.open(result)
+
+ print
+ print "The two numbers where equal!"
+ print "The two numbers where different!"\
+ " (With high probability)"
+ print
+
+
+ # When the values for the opening arrive, we can call the
+ # finish method.
+ result.addCallback(finish)
+ result.addCallback(lambda _: runtime.shutdown())
+
+
+# Parse command line arguments.
+parser = OptionParser(usage=__doc__)
+
+parser.add_option("--modulus",
+ help="lower limit for modulus (can be an expression)")
+parser.add_option("-n", "--number", type="int",
+ help="number to compare")
+parser.add_option("-t", "--test", default=False, action="store_true",
+ help="run doctests on this file")
+
+parser.set_defaults(modulus=2**65)
+
+Runtime.add_options(parser)
+
+options, args = parser.parse_args()
+
+ parser.error("you must specify a config file")
+
+Zp = GF(find_prime(options.modulus, blum=True))
+
+# Run doctests
+ import doctest #pragma NO COVER
+ doctest.testmod(verbose=True) #pragma NO COVER
I don't think there are any doctests here (any longer).
Post by Sigurd Meldgaard
+# Load configuration file.
+id, players = load_config(args[0])
+
+runtime_class = make_runtime_class(mixins = [ProbabilisticEqualityMixin])
+
+pre_runtime = create_runtime(id, players, 1, options,
+ runtime_class = runtime_class)
There should be no spaces around keyword arguments.
Post by Sigurd Meldgaard
+pre_runtime.addCallback(Protocol)
+
+# Uncomment the following line to set the numbers for each player
+# options.number = [None, 12, 18, None][id]
+
+# Start the Twisted event loop.
+reactor.run()
--
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.
Sigurd Torkel Meldgaard
2008-09-17 10:58:32 UTC
Permalink
Post by Sigurd Meldgaard
Post by Sigurd Meldgaard
# HG changeset patch
# Date 1221574030 -7200
# Node ID f879ad687faab381f1208885a5c1330265e3e119
# Parent 5aa168c8778a1e2909cda7c1ea08da8501b66a95
Added a function viff.runtime.make_runtime_class, that creates a new
runtime class with mixins
Please try to make the first line in the commit message fit in 80 chars,
otherwise it looks weird in my terminals :-) Then put the bigger
description in a paragraph after the first line.
Ok, will try that!
Post by Sigurd Meldgaard
Post by Sigurd Meldgaard
diff -r 5aa168c8778a -r f879ad687faa viff/runtime.py
--- a/viff/runtime.py Tue Sep 16 16:11:10 2008 +0200
+++ b/viff/runtime.py Tue Sep 16 16:07:10 2008 +0200
@@ -1079,6 +1079,19 @@
result.addCallback(shamir.recombine)
return result
No space around default arguments in functions. Also, I don't think it
makes sense to give mixins as default argument -- people should only use
this function if they actually have something to mix.
The default arguments are more for being able to call the function with
keyword-parameters - often you want the runtime_class to be the default value,
but you do not want it to go after the mixins ... good ideas? One possibility
is to special case like:

def make_runtime_class(runtime_class=Runtime, mixins=None):
"""Creates a new runtime class with *runtime_class* as a base
class mixing in the *mixins*.

*mixins* must be a list or tuple of mixin-classes.
"""

if mixins=None:
return runtime_class
else:
# We must include at least one new-style class in bases. We
# include it last to avoid overriding __init__ from the other base
# classes.
bases = (runtime_class,) + tuple(mixins) + (object,)

return type("ExtendedRuntime", bases, {})
Post by Sigurd Meldgaard
Post by Sigurd Meldgaard
+ """Creates a new runtime class with runtime_class as a base class
+ mixing in the mixins.
Please mark parameters a *runtime_class* in the docstrings, that makes
the Sphinx generated output nicer.
Post by Sigurd Meldgaard
+ mixins must be a list or tuple of mixin-classes.
+ """
+
+ # We must include at least one new-style class in bases. We
+ # include it last to avoid overriding __init__ from the other base
+ # classes.
+ bases = (runtime_class,) + tuple(mixins) + (object,)
+
+ return type("ExtendedRuntime", bases, {})
Great idea with such a function so that people wont have to do the scary
dynamic class stuff themselves -- could you please make another patch
which updates apps/benchmark.py to use this function?
Sure
Post by Sigurd Meldgaard
--
Martin Geisler
VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.
Martin Geisler
2008-09-17 11:59:18 UTC
Permalink
Post by Sigurd Torkel Meldgaard
Post by Martin Geisler
Post by Sigurd Meldgaard
diff -r 5aa168c8778a -r f879ad687faa viff/runtime.py
--- a/viff/runtime.py Tue Sep 16 16:11:10 2008 +0200
+++ b/viff/runtime.py Tue Sep 16 16:07:10 2008 +0200
@@ -1079,6 +1079,19 @@
result.addCallback(shamir.recombine)
return result
No space around default arguments in functions. Also, I don't think
it makes sense to give mixins as default argument -- people should
only use this function if they actually have something to mix.
The default arguments are more for being able to call the function
with keyword-parameters - often you want the runtime_class to be
the default value, but you do not want it to go after the mixins
Remove the default from both arguments? Or make runtime_class the last
argument?
Post by Sigurd Torkel Meldgaard
Post by Martin Geisler
Great idea with such a function so that people wont have to do the
scary dynamic class stuff themselves -- could you please make
another patch which updates apps/benchmark.py to use this function?
Sure
Great, thanks! Another idea: it would be fun to have support for
testing equality in benchmark.py... you could do a patch for that if
you have the time :-)
--
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.
Continue reading on narkive:
Loading...