Package: tinybook
Minimal pure-Python library that demonstrates a basic workflow for an encrypted order book by leveraging a secure multi-party computation (MPC)protocol.PurposeThis library demonstrates how a functionality can be implemented using asecure multi-party computation (MPC) protocolfor evaluating arithmetic sum-of-products expressions (as implemented intinynmc). The approach used in this library can serve as a template for any workflow that relies on multiple simultaneous instances of such a protocol.Installation and UsageThis library is available as apackage on PyPI:python-mpipinstalltinybookThe library can be imported in the usual way:importtinybookfromtinybookimport*Basic ExampleSuppose that a secure decentralized voting workflow is supported by three parties. Thenodeobjects would be instantiated locally by each of
these three parties:>>>nodes=[node(),node(),node()]The preprocessing workflow that the nodes must execute can be simulated. It is assumed that all permitted prices are integers greater than or equal to0and strictly less than a fixed maximum value. The number of distinct prices can be supplied to the preprocessing simulation:>>>preprocess(nodes,prices=16)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):>>>request_ask=request.ask()>>>request_bid=request.bid()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:>>>masks_ask=[node.masks(request_ask)fornodeinnodes]>>>masks_bid=[node.masks(request_bid)fornodeinnodes]Each client can then generate locally anorderinstance (i.e., a masked representation of the order):>>>order_ask=order(masks_ask,4)>>>order_bid=order(masks_bid,9)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:>>>shares=[node.outcome(order_ask,order_bid)fornodeinnodes]The overall outcome can be reconstructed from the shares by the workflow operator. The outcome is eitherNone(if the bid price does not equal or exceed the ask price) or arangeinstance representing the bid-ask spread (where for arangeinstancer, the ask price ismin(r)and the bid price ismax(r)):>>>reveal(shares)range(4,10)>>>min(reveal(shares))4>>>max(reveal(shares))9DevelopmentAll installation and development dependencies are fully specified inpyproject.toml. Theproject.optional-dependenciesobject is used tospecify optional requirementsfor various development tasks. This makes it possible to specify additional options (such asdocs,lint, and so on) when performing installation usingpip:python-mpipinstall.[docs,lint]DocumentationThe documentation can be generated automatically from the source files usingSphinx:python-mpipinstall.[docs]cddocssphinx-apidoc-f-E--templatedir=_templates-o_source..&&makehtmlTesting and ConventionsAll unit tests are executed and their coverage is measured when usingpytest(see thepyproject.tomlfile for configuration details):python-mpipinstall.[test]python-mpytestAlternatively, all unit tests are included in the module itself and can be executed usingdoctest:pythonsrc/tinybook/tinybook.py-vStyle conventions are enforced usingPylint:python-mpipinstall.[lint]python-mpylintsrc/tinybookContributionsIn order to contribute to the source code, open an issue or submit a pull request on theGitHub pagefor this library.VersioningThe version number format for this library and the changes to the library associated with version number increments conform withSemantic Versioning 2.0.0.PublishingThis library can be published as apackage on PyPIby a package maintainer. First, install the dependencies required for packaging and publishing:python-mpipinstall.[publish]Ensure that the correct version number appears inpyproject.toml, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has anautomation rulethat activates and sets as the default all tagged versions. Create and push a tag for this version (replacing?.?.?with the version number):gittag?.?.?gitpushorigin?.?.?Remove any old build/distribution files. Then, package the source into a distribution archive:rm-rfbuilddistsrc/*.egg-infopython-mbuild--sdist--wheel.Finally, upload the package distribution archive toPyPI:python-mtwineuploaddist/*