Skip to content

Commit 7be6e16

Browse files
committed
Add purpose and example to README; update Sphinx version; adjust docstrings.
1 parent 9c2fdf1 commit 7be6e16

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

README.rst

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ Minimal pure-Python library that demonstrates a basic workflow for an encrypted
2222
:target: https://coveralls.io/github/choosek/tinybook?branch=main
2323
:alt: Coveralls test coverage summary.
2424

25+
Purpose
26+
-------
27+
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+
2529
Installation and Usage
2630
----------------------
27-
2831
This library is available as a `package on PyPI <https://pypi.org/project/tinybook>`__:
2932

3033
.. code-block:: bash
@@ -38,6 +41,69 @@ The library can be imported in the usual way:
3841
import tinybook
3942
from tinybook import *
4043
44+
Basic Example
45+
^^^^^^^^^^^^^
46+
47+
.. |node| replace:: ``node``
48+
.. _node: https://tinybook.readthedocs.io/en/0.1.0/_source/tinybook.html#tinybook.tinybook.node
49+
50+
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]
76+
77+
.. |order| replace:: ``order``
78+
.. _order: https://tinybook.readthedocs.io/en/0.1.0/_source/tinybook.html#tinybook.tinybook.order
79+
80+
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]
92+
93+
.. |range| replace:: ``range``
94+
.. _range: https://docs.python.org/3/library/functions.html#func-range
95+
96+
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+
41107
Development
42108
-----------
43109
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>`__:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Documentation = "https://tinybook.readthedocs.io"
2525
[project.optional-dependencies]
2626
docs = [
2727
"toml~=0.10.2",
28-
"sphinx~=4.2.0",
28+
"sphinx~=5.3.0",
2929
"sphinx-rtd-theme~=1.0.0",
3030
"sphinx-autodoc-typehints~=1.12.0"
3131
]

src/tinybook/tinybook.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class node:
1515
and performing node operations.
1616
1717
Suppose that a workflow is supported by three parties. The :obj:`node`
18-
objects would be instantiated locally by each of the three parties.
18+
objects would be instantiated locally by each of these three parties.
1919
2020
>>> nodes = [node(), node(), node()]
2121
@@ -27,7 +27,7 @@ class node:
2727
2828
>>> preprocess(nodes, prices=16)
2929
30-
A requests must be submitted for the opportunity to submit an order. The
30+
A request must be submitted for the opportunity to submit an order. The
3131
clients can create :obj:`request` instances for this purpose. Below, two
3232
clients each create their request.
3333

0 commit comments

Comments
 (0)