/mpyc

MPyC: Multiparty Computation in Python

Primary LanguagePythonMIT LicenseMIT

Binder Travis CI codecov Read the Docs PyPI

MPyC MPyC logo Multiparty Computation in Python

MPyC supports secure m-party computation tolerating a dishonest minority of up to t passively corrupt parties, where m ≥ 1 and 0 ≤ t < m/2. The underlying cryptographic protocols are based on threshold secret sharing over finite fields (using Shamir's threshold scheme as well as pseudorandom secret sharing).

The details of the secure computation protocols are mostly transparent due to the use of sophisticated operator overloading combined with asynchronous evaluation of the associated protocols.

Documentation

Read the Docs for Sphinx-based documentation, including an overview of the demos.
GitHub Pages for pydoc-based documentation.

See demos for Python programs and Jupyter notebooks with lots of example code. Click the "launch binder" badge above to view the entire repository and try out the Jupyter notebooks from the demos directory in the cloud, without any install.

The MPyC homepage has some more info and background.

Installation

Pure Python, no dependencies. Python 3.9+ (following NumPy's deprecation policy).

Run pip install . in the root directory (containing file setup.py).
Or, run pip install -e ., if you want to edit the MPyC source files.

Use pip install numpy to enable support for secure NumPy arrays in MPyC, along with vectorized implementations.

Use pip install gmpy2 to run MPyC with the package gmpy2 for considerably better performance.

Some Tips

  • Try run-all.sh or run-all.bat in the demos directory to have a quick look at all pure Python demos. Demos bnnmnist.py and cnnmnist.py require NumPy, demo kmsurvival.py requires pandas, Matplotlib, and lifelines, and demo ridgeregression.py (and therefore demo multilateration.py) even require Scikit-learn.
    Try np-run-all.sh or np-run-all.bat in the demos directory to run all Python demos employing MPyC's secure arrays. Major speedups are achieved due to the reduced overhead of secure arrays and vectorized processing throughout the protocols.

  • To use the Jupyter notebooks demos\*.ipynb, you need to have Jupyter installed, e.g., using pip install jupyter. An interesting feature of Jupyter is the support of top-level await. For example, instead of mpc.run(mpc.start()) you can simply use await mpc.start() anywhere in a notebook cell, even outside a coroutine.
    For Python, you also get top-level await by running python -m asyncio to launch a natively async REPL. By running python -m mpyc instead you even get this REPL with the MPyC runtime preloaded!

  • Directory demos\.config contains configuration info used to run MPyC with multiple parties. The file gen.bat shows how to generate fresh key material for SSL. To generate SSL key material of your own, first run pip install cryptography (alternatively, run pip install pyOpenSSL).

Copyright © 2018-2023 Berry Schoenmakers