You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library demonstrates how a functionality can be implemented using a `secure multi-party computation (MPC) protocol <https://eprint.iacr.org/2023/1740>`__ for evaluating arithmetic sum-of-products expressions (as implemented in `tinynmc <https://pypi.org/project/tinynmc>`__). The approach used in this library can serve as a template for any workflow that relies on multiple simultaneous instances of such a protocol.
28
+
25
29
Installation and Usage
26
30
----------------------
27
-
28
31
This library is available as a `package on PyPI <https://pypi.org/project/tinybook>`__:
29
32
30
33
.. code-block:: bash
@@ -38,6 +41,69 @@ The library can be imported in the usual way:
Suppose that a secure decentralized voting workflow is supported by three parties. The |node|_ objects would be instantiated locally by each of
51
+
these three parties:
52
+
53
+
.. code-block:: python
54
+
55
+
>>> nodes = [node(), node(), node()]
56
+
57
+
The preprocessing workflow that the nodes must execute can be simulated. It is assumed that all permitted prices are integers greater than or equal to ``0`` and strictly less than a fixed maximum value. The number of distinct prices can be supplied to the preprocessing simulation:
58
+
59
+
.. code-block:: python
60
+
61
+
>>> preprocess(nodes, prices=16)
62
+
63
+
A request must be submitted for the opportunity to submit an order. Below, two clients each create their request (one for an ask order and the other for a bid order):
64
+
65
+
.. code-block:: python
66
+
67
+
>>> request_ask = request.ask()
68
+
>>> request_bid = request.bid()
69
+
70
+
Each client can deliver their request to each node, and each node can then locally generate masks that can be returned to the requesting client:
71
+
72
+
.. code-block:: python
73
+
74
+
>>> masks_ask = [node.masks(request_ask) for node in nodes]
75
+
>>> masks_bid = [node.masks(request_bid) for node in nodes]
Each client can then generate locally an |order|_ instance (*i.e.*, a masked representation of the order):
81
+
82
+
.. code-block:: python
83
+
84
+
>>> order_ask = order(masks_ask, 4)
85
+
>>> order_bid = order(masks_bid, 9)
86
+
87
+
Each client can broadcast its masked order to all the nodes. Each node can locally assemble these as they arrive. Once a node has received both masked orders, it can determine its shares of the overall outcome:
88
+
89
+
.. code-block:: python
90
+
91
+
>>> shares = [node.outcome(order_ask, order_bid) for node in nodes]
The overall outcome can be reconstructed from the shares by the workflow operator. The outcome is either ``None`` (if the bid price does not equal or exceed the ask price) or a |range|_ instance representing the bid-ask spread (where for a |range|_ instance ``r``, the ask price is ``min(r)`` and the bid price is ``max(r)``):
97
+
98
+
.. code-block:: python
99
+
100
+
>>> reveal(shares)
101
+
range(4, 10)
102
+
>>>min(reveal(shares))
103
+
4
104
+
>>>max(reveal(shares))
105
+
9
106
+
41
107
Development
42
108
-----------
43
109
All installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__:
0 commit comments