.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/privacy/mixing/plot_02_tumblebit.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_privacy_mixing_plot_02_tumblebit.py: TumbleBit: an untrusted tumbler that cannot link payments (2017) ================================================================ A mixing service, a *tumbler*, takes coins from payers and pays payees. Heilman, Alshenibr, Baldimtsi, Scafuro and Goldberg made one that can neither steal nor tell who paid whom. The tumbler promises each payee a token locked under an RSA *puzzle* :math:`z = \epsilon^e \bmod N`, which only it can solve. The payee blinds the puzzle with a random :math:`\rho`, .. math:: z' = z \rho^{e} \bmod N, \qquad (z')^{d} = \epsilon \rho , and a payer pays the tumbler to solve :math:`z'`. Dividing the solution by :math:`\rho` gives :math:`\epsilon`, which opens the token. The tumbler saw :math:`z` with the payee and :math:`z'` with the payer: unrelated numbers, as in Chaum's blind signatures. .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python import matplotlib.pyplot as plt import blockchainkit as bk .. GENERATED FROM PYTHON SOURCE LINES 27-29 Twenty payments through one tumbler ----------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 29-38 .. code-block:: Python pairs = [(f"payer{i}", f"payee{i}") for i in range(20)] blinded = bk.privacy.run_tumbler(pairs, seed=1) plain = bk.privacy.run_tumbler(pairs, blind=False, seed=1) assert all(blinded.paid) and all(plain.paid) print("links without blinding:", len(bk.privacy.tumbler_links(plain))) print("links with blinding: ", len(bk.privacy.tumbler_links(blinded))) assert bk.privacy.tumbler_links(blinded) == () .. rst-class:: sphx-glr-script-out .. code-block:: none links without blinding: 20 links with blinding: 0 .. GENERATED FROM PYTHON SOURCE LINES 39-42 The tumbler's two logs ---------------------- Without blinding the same puzzle appears in both; with blinding, never. .. GENERATED FROM PYTHON SOURCE LINES 42-58 .. code-block:: Python n = bk.privacy.TUMBLER_KEY.n fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4), sharey=True) for ax, run, title in ((ax1, plain, "unblinded"), (ax2, blinded, "blinded")): ax.scatter( [z / n for _, z in run.promised], [z / n for _, z in run.solved], color="#2563eb", ) ax.plot([0, 1], [0, 1], color="#64748b", linestyle=":") ax.set(xlabel="puzzle promised to payee i / N", title=f"{title} puzzles") ax1.set_ylabel("puzzle solved for payer i / N") fig.tight_layout() plt.show() .. image-sg:: /api/gallery/privacy/mixing/images/sphx_glr_plot_02_tumblebit_001.png :alt: unblinded puzzles, blinded puzzles :srcset: /api/gallery/privacy/mixing/images/sphx_glr_plot_02_tumblebit_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 59-65 Exercise -------- Every payment in a TumbleBit epoch has the same size, and all are made in the same window. Why do both matter for unlinkability, even though the puzzles are blinded? A worked solution is in :doc:`/exercises/privacy`. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.085 seconds) .. _sphx_glr_download_api_gallery_privacy_mixing_plot_02_tumblebit.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/privacy/mixing/plot_02_tumblebit.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_tumblebit.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_tumblebit.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_tumblebit.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_