.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/economics/mev/plot_03_mev_boost_pbs.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_economics_mev_plot_03_mev_boost_pbs.py: Proposer-builder separation and MEV-Boost (2022) ================================================ Extracting the value of transaction ordering takes searchers, private order flow and fast infrastructure. A validator that has them earns more per unit of stake than one that does not, and so attracts more stake: MEV pushes proof of stake toward a few large operators. Proposer-builder separation splits the roles. Specialized *builders* assemble blocks and bid for the slot; the proposer, any validator, signs the best bid. If builders bid their values :math:`v_b = f + \sigma_b M` for fees :math:`f`, MEV :math:`M` and skill :math:`\sigma_b`, the proposer receives at least the second-highest value, .. math:: \text{revenue} \ge v_{(2)} = f + \sigma_{(2)} M, so with competitive builders a solo validator earns nearly as much per slot as a sophisticated one. Flashbots' MEV-Boost, launched with Ethereum's move to proof of stake in September 2022, runs this auction outside the protocol, through relays the proposer must trust. .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import blockchainkit as bk .. GENERATED FROM PYTHON SOURCE LINES 33-35 A sophisticated operator and two solo stakers --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-69 .. code-block:: Python stakes = {"operator": 64, "solo A": 32, "solo B": 32} options = {"sophisticated": {"operator"}, "slots": 20_000, "fees": 0.05, "mev": 0.05} runs = {} for label, separated, builders in ( ("no PBS", False, {}), ("PBS, two strong builders", True, {"b1": 1.0, "b2": 0.95}), ("PBS, one strong builder", True, {"b1": 1.0, "b2": 0.3}), ): runs[label] = bk.economics.simulate_pbs( stakes, separated=separated, builders=builders, seed=9, **options ) per_stake = {v: runs[label].revenue_per_stake(v) * 32 for v in stakes} print(label, {v: round(r, 1) for v, r in per_stake.items()}) alone = runs["no PBS"] assert alone.revenue_per_stake("operator") > 1.7 * alone.revenue_per_stake("solo A") boosted = runs["PBS, two strong builders"] assert boosted.revenue_per_stake("operator") < 1.1 * boosted.revenue_per_stake("solo A") fig, (left, right) = plt.subplots(1, 2, figsize=(12, 4.5)) xs = np.arange(len(stakes)) for i, (label, run) in enumerate(runs.items()): left.bar( xs + (i - 1) * 0.27, [run.revenue_per_stake(v) * 32 for v in stakes], 0.27, label=label, ) left.set_xticks(xs, list(stakes)) left.set(ylabel="revenue per 32 staked") left.set_title("Builder competition equalizes validators") left.legend(fontsize=8) .. image-sg:: /api/gallery/economics/mev/images/sphx_glr_plot_03_mev_boost_pbs_001.png :alt: Builder competition equalizes validators :srcset: /api/gallery/economics/mev/images/sphx_glr_plot_03_mev_boost_pbs_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none no PBS {'operator': 503.8, 'solo A': 247.5, 'solo B': 248.1} PBS, two strong builders {'operator': 503.8, 'solo A': 480.0, 'solo B': 483.5} PBS, one strong builder {'operator': 503.8, 'solo A': 320.9, 'solo B': 322.4} .. GENERATED FROM PYTHON SOURCE LINES 70-72 How much competition is enough? ------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 72-89 .. code-block:: Python skills = np.linspace(0, 1, 11) ratio = [] for skill in skills: run = bk.economics.simulate_pbs( stakes, builders={"b1": 1.0, "b2": float(skill)}, seed=9, **options ) ratio.append(run.revenue_per_stake("solo A") / run.revenue_per_stake("operator")) right.plot(skills, ratio, "o-", color="#2563eb") right.axhline(1, color="black", linestyle=":") right.set(xlabel="second builder's skill", ylabel="solo revenue / operator revenue") right.set_title("Solo stakers get what the runner-up builder would pay") fig.tight_layout() assert ratio[0] < ratio[-1] and ratio[-1] > 0.95 plt.show() .. GENERATED FROM PYTHON SOURCE LINES 90-96 Exercise -------- The proposer receives the second-highest value, but the winning builder keeps the gap between its value and that price. With one builder of skill 1 and one of skill 0.5, what fraction of the MEV does the winning builder keep, and why might it pay to integrate a builder with a large validator? .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.436 seconds) .. _sphx_glr_download_api_gallery_economics_mev_plot_03_mev_boost_pbs.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/economics/mev/plot_03_mev_boost_pbs.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_mev_boost_pbs.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_mev_boost_pbs.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_mev_boost_pbs.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_