.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/privacy/analysis/plot_03_monero_traceability.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_analysis_plot_03_monero_traceability.py: Traceability in Monero: when decoys fail (2018) =============================================== Möser, Soska, Heilman, Lee, Heffan, Srivastava, Hogan, Hennessey, Miller, Narayanan and Christin, and independently Kumar, Fischer, Tople and Saxena, showed that most early Monero inputs could be traced. - **Zero-mixin chain reaction.** A ring with no decoys reveals its output. Struck from every other ring, it can leave some of them with one member, which reveals theirs, and so on. - **Guess-newest.** Coins are usually spent soon after they arrive, but decoys were drawn uniformly from all history, so the newest member was usually the real one. If a ring of size :math:`n` mixes the real output with decoys of the same age distribution, guessing the newest is right with probability about :math:`1/n`; with uniform decoys, it approaches 1 as the chain grows. .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: Python import matplotlib.pyplot as plt import blockchainkit as bk from blockchainkit.privacy.visualizers import plot_ring_positions .. GENERATED FROM PYTHON SOURCE LINES 28-31 The chain reaction ------------------ Early Monero: rings of two, most without decoys. .. GENERATED FROM PYTHON SOURCE LINES 31-42 .. code-block:: Python early = bk.privacy.simulate_rings(2_000, 900, ring_size=2, zero_mixin=0.6, seed=5) report = bk.privacy.trace_rings(early) cascade = report.deduced - report.zero_mixin print(f"{report.zero_mixin} zero-mixin inputs; the chain reaction traces {cascade} more") assert cascade > 0 larger = bk.privacy.trace_rings( bk.privacy.simulate_rings(2_000, 900, ring_size=5, zero_mixin=0.6, seed=5) ) print(f"with rings of five it traces {larger.deduced - larger.zero_mixin} more") .. rst-class:: sphx-glr-script-out .. code-block:: none 545 zero-mixin inputs; the chain reaction traces 118 more with rings of five it traces 2 more .. GENERATED FROM PYTHON SOURCE LINES 43-45 Guess-newest, and the fix ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 45-64 .. code-block:: Python uniform = bk.privacy.simulate_rings(5_000, 1_000, ring_size=5, sampling="uniform", seed=7) recent = bk.privacy.simulate_rings(5_000, 1_000, ring_size=5, sampling="recent", seed=7) for name, rings in (("uniform decoys", uniform), ("age-matched decoys", recent)): print(f"{name}: newest is real in {bk.privacy.trace_rings(rings).newest_correct / 10:.0f}%") assert ( bk.privacy.trace_rings(uniform).newest_correct > 2 * bk.privacy.trace_rings(recent).newest_correct ) fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11, 4)) plot_ring_positions(uniform, ax=ax1) ax1.set_title("Uniform decoys: " + ax1.get_title()) plot_ring_positions(recent, ax=ax2) ax2.set_title("Age-matched decoys: " + ax2.get_title()) fig.tight_layout() plt.show() .. image-sg:: /api/gallery/privacy/analysis/images/sphx_glr_plot_03_monero_traceability_001.png :alt: Uniform decoys: Newest member is the real one in 89% of rings, Age-matched decoys: Newest member is the real one in 21% of rings :srcset: /api/gallery/privacy/analysis/images/sphx_glr_plot_03_monero_traceability_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none uniform decoys: newest is real in 89% age-matched decoys: newest is real in 21% .. GENERATED FROM PYTHON SOURCE LINES 65-72 Exercise -------- Monero made rings of size 11 mandatory in 2018. Using :func:`~blockchainkit.privacy.systems.traceability.simulate_rings`, how much of a ledger with 60% zero-mixin rings of size 2 does the chain reaction trace, and how much once the other 40% have size 11? A worked solution is in :doc:`/exercises/privacy`. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.120 seconds) .. _sphx_glr_download_api_gallery_privacy_analysis_plot_03_monero_traceability.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/analysis/plot_03_monero_traceability.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_monero_traceability.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_monero_traceability.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_monero_traceability.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_