<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>lukewasm.eth</title>
        <link>https://paragraph.com/@lukewasm</link>
        <description>undefined</description>
        <lastBuildDate>Sun, 24 May 2026 16:10:45 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[Unveiling Intelligent DeFi: The Coprocessor Revolution]]></title>
            <link>https://paragraph.com/@lukewasm/unveiling-intelligent-defi-the-coprocessor-revolution</link>
            <guid>djKPFa33cDpHS6BSH1x3</guid>
            <pubDate>Fri, 23 Feb 2024 10:26:58 GMT</pubDate>
            <description><![CDATA[Special thanks to @0xkrane, @atiselsts_eth, Avi from @nil_foundation, @ChundaMcCain, @IsdrsP, @Li_Steven1, Maki and @Phil_Kelly_NYC from @o1_labs and @yilongl_megaeth for their invaluable discussions, insights, and feedback on this article!IntroductionToday’s decentralized apps face limitations in performing complex on-chain computations due to blockchain’s restricted processing capabilities. However, with the rapid development of technologies such as blockchain coprocessors, in conjunction w...]]></description>
            <content:encoded><![CDATA[<p><em>Special thanks to </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/0xkrane"><em>@0xkrane</em></a><em>, </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/atiselsts_eth"><em>@atiselsts_eth</em></a><em>, Avi from </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/nil_foundation"><em>@nil_foundation</em></a><em>, </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/ChundaMcCain"><em>@ChundaMcCain</em></a><em>, </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/IsdrsP"><em>@IsdrsP</em></a><em>, </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/Li_Steven1"><em>@Li_Steven1</em></a><em>, Maki and </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/Phil_Kelly_NYC"><em>@Phil_Kelly_NYC</em></a><em> from </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/o1_labs"><em>@o1_labs</em></a><em> and </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/yilongl_megaeth"><em>@yilongl_megaeth</em></a><em> for their invaluable discussions, insights, and feedback on this article!</em></p><h2 id="h-introduction" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Introduction</h2><p>Today’s decentralized apps face limitations in performing complex on-chain computations due to blockchain’s restricted processing capabilities. However, with the rapid development of technologies such as blockchain coprocessors, in conjunction with game theory and mechanism design, a new wave of use cases emerge to greatly improve user experience.</p><p>This article explores the design space of coprocessors, with a focus on potential use cases they empower.</p><p><strong>Key takeaways:</strong></p><ul><li><p>Blockchain computation is expensive and limited; one solution is to move computation off-chain and verify the results on-chain through coprocessors, enabling more complex dapp logics.</p></li><li><p>Coprocessors can be categorized into trustless (ZK), trust-minimized (MPC/TEE), optimistic, and cryptoeconomic based on their security assumptions. These solutions could also be combined to achieve desired security vs efficiency tradeoff.</p></li><li><p>Different types of coprocessors are suited for different tasks in DeFi. Potential use cases cover DEX (AMM &amp; orderbook), money markets, staking, restaking, etc.</p></li><li><p>With the rise of decentralized AI, together with coprocessors, we are entering a new era of “<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/sreeramkannan/status/1730310412904599714?s=46&amp;t=BEj6zzjLWPVaGWy0nmKnCw">Intelligent DeFi</a>”.</p></li></ul><h2 id="h-the-role-of-coprocessors" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">The Role of Coprocessors</h2><p>Blockchain is commonly viewed as a general-purpose CPU virtual machine (VM) that may not be ideal for heavy computations. Tasks involving data-driven analysis and intensive computations often necessitate off-chain solutions. For instance, orderbook exchanges like dydx v3 utilize off-chain matching and risk engines running on centralized servers, with only fund settlements taking place on-chain.</p><p>In computing, coprocessors are introduced to assist processors in performing specific tasks, as indicated by the prefix &apos;co-&apos;. For instance, GPUs serve as coprocessors for CPUs. They excel at handling parallel computations required for tasks like 3D rendering and deep learning. This arrangement allows the primary CPU to concentrate on general-purpose processing. The coprocessor model has empowered computers to handle more complex workloads that would not have been feasible with a single, all-purpose CPU.</p><p>By leveraging coprocessors and accessing on-chain data, blockchain applications can potentially provide advanced features and make informed decisions. This creates opportunities for conducting additional computations, enabling the performance of more complex tasks and allowing applications to become more &quot;intelligent&quot;.</p><h2 id="h-different-types-of-coprocessors" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Different Types of Coprocessors</h2><p>Based on trust assumptions, coprocessors could be classified into mainly three different types- Zero-Knowledge (ZK), Optimistic, and Cryptoeconomic.</p><p><strong><em>ZK coprocessors</em></strong>, if implemented correctly, are theoretically trustless. They perform off-chain computations and submit on-chain proofs for verification. While they provide speed, there is a trade-off in terms of proving cost. As custom hardware advances and cryptography develops, the final cost passed on to end-consumers could potentially be reduced to a more acceptable level.</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/axiom_xyz">Axiom</a> and <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/RiscZero">RISC Zero</a> Bonsai are examples of ZK coprocessors. They allow arbitrary computation with access to the on-chain state to be run off-chain and provide proofs that the computation was performed.</p><p>To provide a clearer understanding of how a typical ZK coprocessor operates, let&apos;s examine the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://dev.risczero.com/api/bonsai/bonsai-on-eth">workflow of RISC Zero Bonsai</a>.</p><p>Applications send coprocessing requests to Bonsai Relay, which then forwards the proof request to the Bonsai proving service. The RISC Zero zkVM executes the program and generates a proof to validate the correct execution of the code, which can be verified by anyone. Subsequently, Bonsai Relay publishes the proof on-chain, and the applications receive the results through a callback function.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b673a4db7bfc899af6be481784263f1dba8f0345a967479a455540ab6f7d0ea5.png" alt="Bonsai on Ethereum" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Bonsai on Ethereum</figcaption></figure><p>While ZK coprocessor is one method for achieving verifiable off-chain computations, alternatives such as MPC and TEEs offer different approaches. MPC enables collaborative computing on sensitive data, while TEEs provide secure hardware-based enclaves. Each option comes with its own set of trade-offs between security and efficiency. In this article, we will focus on ZK coprocessors.</p><p><strong><em>Optimistic coprocessors</em></strong> offer cost-effective solutions, but they suffer from significant latency issues (typically weeks). They require honest parties to effectively challenge them with fraud proofs within the challenging window. Therefore, the time to security guarantees are delayed.</p><p><strong><em>Cryptoeconomic coprocessors</em></strong> are optimistic coprocessors with a large enough economic bond on execution and an on-chain insurance system which allows others to secure compensation for erroneous computation. This economic bond and insurance can be purchased through shared security providers like Eigenlayer. The advantage is instant settlement, but the downside is the cost of acquiring insurance.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/67ec83fecf63f2348dc5a80e95f4cb1dd75674b53055df35852f37509449b69a.png" alt="Characteristics of Various Coprocessor Types" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Characteristics of Various Coprocessor Types</figcaption></figure><p><em>*There are proof generation times of less than a second out there (admittedly for small, optimized, proofs) and they&apos;re improving rapidly.</em></p><p>Different types of coprocessors exhibit distinct cost, latency, and security characteristics. Combining different types of coprocessors can lead to an optimized user experience. A standout example is <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/brevis_zk">Brevis</a>. Initially launched with a zk-coprocessor, Brevis has now unveiled the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.brevis.network/2024/01/18/introducing-brevis-cochain-the-fusion-of-crypto-economics-and-zk-proof-in-a-zk-coprocessor/">Brevis coChain</a>. This innovation combines crypto-economics and ZKP within a ZK coprocessor, resulting in reduced costs, minimized latency, and enhanced user experience.</p><p>Pure ZK coprocessors, in their current state, still present challenges such as high proof generation costs and scalability issues. This is because ZK proofs for data access and computation results are always generated upfront. Leveraging Eigenlayer’s restaking infrastructure, Brevis coChain enables dapps to tailor the level of crypto-economic security they desire, granting them greater flexibility to enhance the user experience. Here&apos;s a simplified explanation of how it operates.</p><p>Brevis coChain would first &apos;optimistically&apos; generate a result to the coprocessing request based on PoS consensus. Then, two challenge windows initiate, one is application-specific and configurable by developers, and the other one is the longer global coChain slashing window.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/402c80b5bb895a5ca66670095eca8a50ceb7cffc7828725845004efc8c76527c.png" alt="Brevis coChain Workflow" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Brevis coChain Workflow</figcaption></figure><p>During the application challenge window, observers can submit a ZKP contradicting the coprocessing results. Successful challenges slash the proposer and reward the challenger. Failed proposals lead to the challenger’s bond being forfeited.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/4e41cb176bb0aa195dcffe089c27742dc917ba422c75abe7eaa7da41dfd8649f.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>If there are no challenges, the app will deem the results valid. The global coChain slashing window is there for enhanced security. Even if an app accepts a faulty result, as long as the coChain slashing window is open, malicious validators can be slashed and incorrect results can be rectified.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/8fe31fbc7e7c358c12e06197a5c461cae7c1fc4335299be29ddab0daf303ec2b.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>As different types of coprocessors exhibit distinct cost, latency, and security characteristics, applications must assess their requirements to determine the type of coprocessors they need. If the computation involves high-security tasks, such as calculating balances of validators on the Beacon chain in liquid staking where billions of dollars are at stake, ZK coprocessors are the most appropriate choice. They provide maximum security since the results can be verified trustlessly. Additionally, latency is not a concern in such scenarios, allowing for the generation of proofs within acceptable timeframes.</p><p>For tasks that are less latency-sensitive and don&apos;t involve significant financial value, such as showcasing on-chain achievement metrics on your social profiles, an optimistic coprocessor that offers the lowest off-chain computation could be preferable.</p><p>For other tasks, cryptoeconomic coprocessors prove more cost-effective when the purchased insurance covers the at-risk value. The analysis of insurance costs should be done on a case-by-case basis, heavily influenced by the value facilitated by the application. These tasks often entail diverse analytics and risk modeling.</p><p>Another way to categorize coprocessors is by computation type, with examples such as:</p><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/RiscZero">RiscZero</a>, <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/SuccinctLabs">Succinct</a> and <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/nil_foundation">=nil;</a> for general computation,</p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/ritualnet">Ritual</a> and <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/ModulusLabs">Modulus</a> for AI,</p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/SpaceandTimeDB">SpaceandTime</a> for database operations,</p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/megaeth_labs">MegaETH</a> for EVM computations, and more.</p></li></ul><p>The use of coprocessors in DeFi is an emerging area that holds great potential. In the following, I will outline existing ideas and implementations on how coprocessors could be utilized in various sectors within DeFi including DEX, money markets, staking, restaking, etc.</p><h2 id="h-dex" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0"><strong>DEX</strong></h2><p>There are multiple stakeholders involved in a DEX. These include traders, liquidity providers, market makers, liquidity managers, solvers/fillers, and more. Coprocessors have the potential to efficiently streamline complex tasks with different levels of trust assumptions, ultimately enhancing the experience for these stakeholders.</p><h3 id="h-cost-reduction" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Cost Reduction</strong></h3><p>In a basic AMM, one important function is to compute the necessary parameters when users initiate a swap. These parameters include the amount to be swapped in and out, the fee, and the price after swapping. One straightforward use case to harness the computational power of zk-coprocessors while maintaining trust guarantees is to perform a portion of the swap function off-chain, and then complete the remaining steps on-chain. zkAMMs are a variant of Automated Market Makers (AMMs) that integrate zero-knowledge proofs <em>in-protocol</em>. Diego (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/0xfuturistic">@0xfuturistic</a>) introduces an implementation of zkAMM (zkUniswap) based on Uniswap v3 where a portion of the AMM swap computation is offloaded to the Risc Zero zkVM. A user starts a swap by making a request on-chain, the swap inputs are picked up by the relayer, and the computation is carried out off-chain. The relayer then posts the output and the proof. The AMM verifies the proof and settles the swap.</p><p>While the computation cost is still comparable to that of EVM at the current stage, it is possible to achieve higher efficiency by parallelizing the computation of swaps with independent paths thanks to RiscZero’s <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.risczero.com/news/continuations">continuation </a>feature. Essentially, the execution of swaps can be done sequentially on-chain, but the actual swap steps can be computed in parallel off-chain using this approach. This enables the parallelization of the heaviest part for batches, which is not natively possible in the EVM. The cost of verification could also be amortized by batching multiple transactions together.</p><p>Users also have the option to use an alternative data availability layer to send swap requests. Another approach is to utilize EIP712 signature for off-chain propagation, which can further reduce swap costs.</p><h3 id="h-dynamic-parameters" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Dynamic Parameters</h3><p>Coprocessors could also be utilized to dynamically control the swap fee for an AMM pool. The concept of a dynamic fee is to increase the fee rate during periods of market volatility and decrease it during calmer market conditions. This serves as a benefit for passive liquidity providers, as they consistently take the unfavorable side of trades and experience value leakage through Loss-versus-rebalance (LVR). The implementation of dynamic fees aims to address this issue by adequately compensating LPs.</p><p>Some AMMs already have this feature. For example, <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/ambient_finance">Ambient</a> utilizes an external oracle that monitors and takes snapshots of different fee tier Uniswap v3 pools every 60 minutes to choose the best performing one.</p><p>To provide further insights into adjusting the fee rate, additional data can be utilized, both on-chain and off-chain. This includes historical trades conducted on-chain for this particular AMM pool or for the same pair across various liquidity pools (such as the Ambient solution) or even pools on different networks. If certain trust assumptions are allowed, off-chain data (e.g. CEX trade data) from reputable oracles like Chainlink or Pyth, could also be introduced.</p><p>The decision on which types of coprocessors to use is influenced by how frequently the fee is adjusted. In cases where a pool requires very frequent dynamic fee changes, cryptoeconomic coprocessors may be more suitable. This is because the costs of proving are likely to outweigh the insurance costs, which can be estimated as the difference in fee rate multiplied by the average volume. In the event of any erroneous calculations, LPs can easily claim their insurance facilitated by Eigenlayer to compensate for their loss in fees.</p><p>On the other hand, there are pools that prefer less frequent fee rate changes. However, these pools handle very large volumes, which can drive up the cost of insurance buying. In such cases, ZK coprocessors are more suitable as they provide the strongest guarantee.</p><h3 id="h-active-liquidity-manager-alm" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Active Liquidity Manager (ALM)</strong></h3><p>Passive liquidity provision can be an attractive option for less experienced users who want to earn fees from their idle liquidity without being overly concerned about price deviations. However, some liquidity providers (LPs) are more susceptible to losses caused by price deviations and statistical arbitrages. We previously discussed how adjusting fees dynamically could mitigate this issue. But why not go a step further and completely change the shape of the liquidity curve? This is a more sophisticated approach to liquidity management known as Active Liquidity Managers (ALMs).</p><p>Regrettably, the majority of existing ALMs only provide basic strategies like rebalancing, which have a limited impact on fee collection. On the other hand, slightly more advanced techniques such as hedging using money markets or derivatives are available. However, they either incur high costs when executed frequently on-chain or rely on centralized off-chain blackbox computation.</p><p>Coprocessors have the potential to tackle cost and trust issues, enabling the adoption of advanced strategies. By integrating with cutting-edge zero-knowledge machine learning (ZKML) solutions such as <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/ModulusLabs">Modulus Labs</a> and decentralized AI platforms like <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/ritualnet">Ritual</a>, liquidity managers can leverage complex strategies based on historical trade data, price correlations, volatility, momentum, and more while enjoying the advantages of privacy and trustlessness.</p><p>High-frequency trading strategies require precise timing and rapid execution. While ZK solutions may not always meet the necessary speed, cryptoeconomic coprocessors excel in this area. These coprocessors allow AI algorithms to be executed swiftly, with parameters updated as frequently as the block time allows. However, utilizing this approach comes with insurance costs. Accurately estimating these costs can be challenging due to potential risks like managers mishandling funds or engaging in counter-trades. The decision-making process involves balancing the additional returns against the insurance expenses, which ultimately depends on the total volume occurring within the coprocessor&apos;s measured timeframe. Scaling this process may also prove difficult based on the capital available for access in a single AVS and the ability to predict the value at risk at any given moment.</p><h3 id="h-metrics-based-reward-distribution" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Metrics-Based Reward Distribution</strong></h3><p>While each transaction is recorded on the blockchain, smart contracts face challenges in determining the metrics these transactions represent, such as transaction volume, number of interactions, TVL per unit of time, etc. One might suggest using indexing solutions like Dune Analytics, which provide valuable information. However, relying on off-chain indexing introduces an additional layer of trust. This is where coprocessors emerge as a promising solution.</p><p>One particularly valuable on-chain metric is volume. For example, the accumulated volume within a specific AMM pool associated with a particular address within certain blocks. This metric is very beneficial for DEX. One use case is to allow for setting different fee tiers for users based on their trading volume. This approach is similar to dynamic fees, but instead of relying on general data, it looks at address-specific data.</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/brevis_zk">Brevis</a> provides an interesting example where volume proof could be combined with a customized fee rebate Uniswap hooks to offer volume-based fee rebates similar to VIP traders on CEXes.</p><p>Specifically, Uniswap v4 can read a user’s historical transactions in the past 30 days, parse each trade event with customized logic, and compute the trading volume with Brevis. The trading volume and a ZK Proof generated by Brevis are then trustlessly verified in a Uniswap v4 Hook smart contract, which determines and records the user’s VIP fee tier asynchronously. After the proof verification, any future trades of an eligible user will trigger the <em>getFee()</em> function to simply look up the VIP record and reduce trading fees for them accordingly.</p><p>The cost of getting certified as a &quot;VIP&quot; is also inexpensive (around $2.5 based on its performance benchmark results). Costs can be further reduced by aggregating multiple users using solutions like <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/nebrazkp">NEBRA</a>. The only trade-off is the latency, as it took approximately 400 seconds to access and compute 2600 on-chain Uniswap transactions. However, this is less concerning for features that are not time-sensitive.</p><p>To address latency concerns, dapps could leverage Brevis’s coChain. Results are computed and delivered swiftly through a PoS consensus mechanism to minimize delays. In case of malicious activities, a ZKP can be used during the challenge window to penalize the rogue validators.</p><p>For instance, in the VIP fee scenario mentioned earlier, if over ⅔ of coChain validators deceitfully assign a higher VIP tier to certain users in a &quot;VIP tier lookup table&quot; linked to the dynamic fee hook, some users might initially receive larger fee discounts. However, when a ZK proof is presented during the slashing window, demonstrating that the VIP tiers are incorrect, the malicious validators will face penalties. The erroneous VIP tiers can then be rectified by enabling the challenge callback to update the VIP tier lookup table. For more cautious scenarios, developers can opt to implement extended application-level challenge windows, providing an additional layer of security and adaptability.</p><h3 id="h-liquidity-mining" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Liquidity Mining</strong></h3><p>Liquidity mining is a form of reward distribution intended to bootstrap liquidity. DEX could gain a deeper understanding of their Liquidity Providers&apos; behavior through coprocessors and appropriately distribute liquidity mining rewards or incentives. It&apos;s important to recognize that not all LPs are alike; some act as mercenaries while others remain loyal long-term believers.</p><p>The optimal liquidity incentive should retrospectively evaluate the dedication of LPs, particularly during significant market fluctuations. Those who consistently provide support to the pool during such periods should receive the highest rewards.</p><h3 id="h-solverfiller-reputation-system" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Solver/Filler Reputation System</strong></h3><p>In a future focused on user intent, solvers/fillers play a crucial role by simplifying complex transactions and achieving faster, cheaper, or better results. However, there is ongoing criticism regarding the selection process for solvers. Current solutions include:</p><ol><li><p>A permissionless system that utilizes Dutch auctions or fee escalators. However, this approach faces challenges in ensuring a competitive and permissionless auction environment, potentially resulting in latency issues or even non-execution for users.</p></li><li><p>A permissionless system requires staking tokens for participation, which creates a financial barrier to entry and may lack clear slashing/penalty conditions, or transparent and trustless enforcements.</p></li><li><p>Alternatively, a whitelist of solvers can be established based on reputation and relationship.</p></li></ol><p>The path ahead should be both permissionless and trustless. However, in order to achieve this, it is necessary to establish guidelines for distinguishing between great solvers and those that are not so great. By utilizing ZK coprocessors, verifiable proofs can be generated to determine whether certain solvers meet or fail to meet these guidelines. Based on this information, solvers can be subjected to priority order flows, slashing, suspension, or even blacklisting. Ideally, better solvers would receive more order flows while worse solvers would receive fewer. It is important to periodically review and update these ratings to prevent entrenchment and promote competition, giving newcomers an equal chance to participate.</p><h3 id="h-manipulation-resistant-price-oracle" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Manipulation-Resistant Price Oracle</strong></h3><p>Uniswap has already introduced embedded oracles in its v2 and v3 versions. With the release of v4, Uniswap has expanded the possibilities for developers by introducing more advanced oracle options. However, there are still limitations and constraints when it comes to on-chain price oracles.</p><p>Firstly, there is the consideration of cost. If a coprocessor computed price oracle can offer cost improvements, it could serve as a more affordable alternative. The more complex the designs of the price oracle, the greater the potential for cost savings.</p><p>Secondly, the on-chain price oracle pool is still susceptible to manipulation. To address this, it is common practice to aggregate prices from different sources and perform calculations to create a more manipulation-resistant price oracle. Coprocessors have the ability to retrieve historical trades from various pools, even across different protocols, enabling the generation of a manipulation-resistant price oracle with competitive costs for integration with other DeFi protocols.</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/DIAdata_org">DIA Data</a> is working on ZK-based oracles with <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/o1_labs">O(1) Labs</a> from the Mina Ecosystem. The approach is similar - taking market data and performing more sophisticated calculations off-chain, free of gas costs and other execution constraints, but with the ability to verify integrity of the calculation as the result is served on-chain. This can make it feasible to supplement simple price feeds with other market data such as depth, to help assess liquidation impact, as well as metadata to enable protocols to customize their feed.</p><h3 id="h-margin-systems" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Margin Systems</strong></h3><p>To overcome the computational limitations of blockchain technology, many derivatives platforms frequently move certain components, such as risk management systems, off-chain.</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/0x_emperor">@0x_emperor</a> and <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/0xkrane">@0xkrane</a> propose an interesting use case of coprocessors where the margining logic is transparent and verifiable. In many exchanges, risk management systems are in place to prevent excessive leverage. One such example is the Auto Deleveraging System (ADL), which strategically allocates losses to profitable traders in order to offset the losses experienced by liquidated traders. Essentially, it redistributes the losses among profitable traders to cover the unpaid debts resulting from these liquidations.</p><p>Users may have questions regarding the forceful closure of their positions. To address this, the exchange could utilize coprocessors to execute margin engine logic using on-chain data and generate proofs to verify correct computation. Since ADL occurrences are infrequent, concerns about latency and proving costs are minimal. However, the use of trustless and verifiable Zk coprocessors enhances transparency and integrity, which is beneficial for the exchange and its users.</p><h2 id="h-money-market" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0"><strong>Money Market</strong></h2><p>By leveraging insights from historic on-chain data, coprocessors have the potential to enhance risk management for LPs and lending protocols. Additionally, protocols can offer improved user experience based on data-driven analytics.</p><p>When Curve experienced an exploit some months ago, attention turned to money markets with millions of CRV tokens at risk of liquidation. Frax lenders found some solace in the protocol&apos;s aggressive interest rate increases when the loan-to-value (LTV) ratio became unhealthy. This incentivized Curve founder to repay the debt more quickly. However, AAVE stakeholders expressed concerns and initiated discussions about reducing collateral capacity and potentially halting the market. Their fear was rooted in the possibility of insufficient liquidity for successful liquidations, which could result in bad debt and vulnerability to market conditions.</p><p>Fortunately, the crisis has been resolved. It is important to regularly review assets listed on money markets, with a particular focus on their liquidity in the market, especially during liquidation events. Illiquid assets should be assigned a lower loan-to-value (LTV) ratio and collateral capacity.</p><p>However, the decision-making process for risk parameter changes in money markets is often reactive, as we observed in the CRV situation. We need more prompt and proactive measures, including trustless solutions. There have been discussions regarding the use of <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://medium.com/gauntlet-networks/feedback-control-as-a-new-primitive-for-defi-27b493f25b1">Feedback Controls</a> to dynamically adjust parameters based on on-chain metrics, such as liquidity utilization, instead of relying on a pre-determined curve. One intriguing concept involves a lending pool that verifies proof of on-chain liquidity for a specific market. The controller receives proof calculated from on-chain metrics by ZK coprocessors, indicating when an asset is no longer sufficiently liquid beyond a certain threshold. Based on this information, the controller can take various measures, such as adjusting interest rates, setting LTV caps, suspending the market, or even discontinuing it altogether.</p><p>More advanced strategies could include periodically adjusting the collateral borrow capacity or interest rate curve based on the previous week&apos;s on-chain liquidity. The exact threshold would be determined through discussions within the DAO. It could be determined by considering factors such as historic on-chain volume, token reserves, minimum slippage for a lump-sum swap, and so on.</p><p>For lenders and borrowers, money markets can provide enhanced services and experiences, similar to fee rebate programs for VIP traders in DEXs. There are existing credit score solutions that aim to create a comprehensive profile of on-chain users. The goal is to incentivize good behaviors, such as effective risk management demonstrated by avoiding liquidation events, maintaining healthy average LTV ratios, making stable large deposits, and more. Trustless rewards can be given for these positive behaviors, including better and smoother interest rates compared to average users, higher maximum LTV and liquidation ratios, a buffer time for liquidation, lower liquidation fees, and more.</p><h2 id="h-staking-and-restaking" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Staking &amp; Restaking</h2><h3 id="h-trust-minimized-oracle" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Trust-minimized Oracle</strong></h3><p>Since the Merge and the Shanghai/Shapella upgrade, the liquid staking market has become the largest market in DeFi. Notably, Lido has amassed over $29 billion TVL, while Rocketpool has over $3.6 billion TVL.</p><p>Given the substantial amount of money involved, it is important to note that the oracles used to report information, such as accurate balances of associated validators on the beacon chain, are still <strong>trusted</strong>. These oracles play a crucial role in distributing rewards to stakers on the execution layer.</p><p>Currently, Lido employs a 5-of-9 quorum mechanism and maintains a list of trusted members to safeguard against malicious actors. Similarly, Rocketpool operates with an invite-only Oracle DAO comprised of node operators who are trusted with updating reward information in the smart contracts on the execution layer.</p><p>However, it is essential to recognize that if a majority of trusted third parties were compromised, it could significantly harm liquid staking token (LST) holders and the entire DeFi ecosystem built on top of LSTs. To mitigate the risk of erroneous/malicious oracle reports, Lido has in place <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.lido.fi/contracts/accounting-oracle/#submitreportdata-1">a series of sanity checks</a> that are implemented in the execution layer code of the protocol.</p><p>With the introduction of EIP-4788 &quot;beacon block root in the EVM&quot;, it becomes easier for coprocessors to gain access to and compute over data on the consensus layer. <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/nil_foundation/status/1691528522764832769">=nill; Foundation</a>, <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/LidoFinance/status/1727708749928730707">Succint </a>and DendrETH are all developing their own ZK-proof TVL oracle for Lido. To ensure maximum security, Lido could utilize a multi-proof architecture.</p><p>Taking =nil;’s design for example, at a high level, the oracle obtains essential information from the Consensus and Execution layers, such as the Beacon Block Header, Beacon State, Lido contract addresses, etc. It then computes a report on the total locked value and validator counts for all Lido validators. These data, along with additional necessary information are passed to the proof producer and run on specialized circuits to generate a ZK proof. The oracle retrieves the proof and submits both the proof and its report to the smart contract for verification. <strong><em>Note that these oracle designs are still in the testing stage and are subject to changes.</em></strong></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/bc9a3d5e8b628b8365112f1b4e36f55b710909ef4bccb08dec9b6180af1e3eaf.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>However, it is worth noting that there will always be some sort of data that may not be provable on the EL side due to the limited nature of what is sent over via 4788 and that oracles may still be required for this subset of data.</p><p>Additionally, trust-minimized ZK-proof oracles are still in their infancy. The proposed approach by Lido contributors is to use the info provided by ZK oracles as a “sanity check” against the work done by the trusted oracles until these ZK implementations can be battle tested. It would be too risky to move all of the trust that’s currently in the oracle system to ZK systems at this stage.</p><p>Furthermore, the proofs for data of this size are very computationally heavy (e.g. can take even 30-45 minutes) and very expensive, so they are not a suitable replacement at the current maturation of the technology for things like daily or even intra-day reporting.</p><h3 id="h-validator-risk-and-performance-analytics" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Validator Risk and Performance Analytics</strong></h3><p>Validators play a crucial role in the staking ecosystem. They lock up 32 ETH on the beacon chain and provide validating services. If they behave properly, they receive rewards. However, if they misbehave, they face slashing. Validators are run by Node Operators who have different risk profiles. They can be curated (e.g. Lido’s Curated Validator Set), bonded (e.g. Rocket pool, Lido’s <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://research.lido.fi/t/community-staking-module/5917">CSM</a>) or solo stakers. They may choose to run their services on cloud data centers or at home, in regions that are either crypto regulation-friendly or unfriendly. Additionally, validators can utilize DVT technology to split internal nodes or join into clusters for enhanced fault-tolerance. As Eigenlayer and various AVS (Actively Validated Services) emerge, validators could potentially offer additional services beyond validating for Ethereum. Undoubtedly, the risk profile of validators will be complex, making it essential to accurately assess their risk profiles. With good validator risk and performance analytics, it opens the door to endless possibilities, including:</p><p>First and foremost, risk assessment plays a crucial role in establishing a <strong>permissionless validator set</strong>. In the context of Lido, the introduction of the Staking Router and the future EIP-7002 &quot;Execution layer triggerable exits&quot; could pave the way for enabling permissionless joining and exiting of validators. The criteria for joining or exiting can be determined based on the risk profile and performance analytics derived from a validator&apos;s past validating activities.</p><p>Second, <strong>node selection in DVT</strong>. For a solo staker, it may be beneficial to choose other nodes to create a DVT cluster. This can help achieve fault tolerance and increase yields. The selection of nodes can be based on various analytics. Additionally, the formation of the cluster can be permissionless, allowing nodes with a strong historical performance to join while underperforming nodes may be removed.</p><p>Third, <strong>restaking</strong>. Liquid Restaking Protocols enable restakers to participate in the Eigenlayer restaking marketplace. These protocols not only produce liquid receipts called Liquid Restaking Tokens (LRT) but also aim to secure the best risk-adjusted returns for restakers. For instance, one of <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/RenzoProtocol">Renzo&apos;s</a> strategies involves building the AVS portfolio with the highest Sharpe Ratio while adhering to a specified target maximum loss, adjusting risk tolerance and weights through DAO. As more AVS projects are launched, the importance of optimizing support for specific AVS and selecting the most suitable AVS operators becomes increasingly crucial.</p><p>So far, we emphasized the significance of validator risk and performance analytics, as well as the wide range of use cases it enables. However, the question remains: How do we accurately assess the risk profile of validators? One potential solution is being developed by <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/ionprotocol">Ion Protocol</a>.</p><p>Ion Protocol is a lending platform that utilizes provable validator-backed data. It enables users to borrow ETH against their staked and restaked positions. Loan parameters, including interest rates, LTVs, and position health, are determined by consensus layer data and safeguarded with ZK data systems.</p><p>Ion is collaborating with the Succinct team on <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/ionprotocol/status/1733272739946058017">Precision</a>—a trustless framework to verify the economic state of validators on Ethereum’s consensus layer. This aims to create a verifiable system that accurately assesses the value of collateral assets, mitigating any potential manipulation or slashing risks. Once established, this system could facilitate loan origination and liquidation processes.</p><p>Ion is also partnering with Modulus Labs, leveraging ZKML for trustless analysis and parametrization of lending markets, including interest rates, LTVs, and other market details to minimize risk exposure in the event of aberrant slashing incidents.</p><h2 id="h-conclusion" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Conclusion</h2><p>DeFi is truly remarkable as it revolutionizes the way financial activities are conducted, eliminating the need for intermediaries and reducing counterparty risks. However, DeFi currently falls short in providing a great user experience. The exciting news is that this is on the brink of change with the introduction of coprocessors that will empower DeFi protocols to offer data-driven features, enhance UX and refine risk management. Moreover, as decentralized AI infrastructure advances, we progress towards a future of Intelligent DeFi.</p><h2 id="h-references" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">References</h2><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://crypto.mirror.xyz/BFqUfBNVZrqYau3Vz9WJ-BACw5FT3W30iUX3mPlKxtA">https://crypto.mirror.xyz/BFqUfBNVZrqYau3Vz9WJ-BACw5FT3W30iUX3mPlKxtA</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://crypto.mirror.xyz/8TXa9EqNkwjnQNenXscPwyHC6V99dmyhcO7uPYbeaIo">https://crypto.mirror.xyz/8TXa9EqNkwjnQNenXscPwyHC6V99dmyhcO7uPYbeaIo</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.brevis.network/2023/11/01/uniswap-v4-hook-brevis-zk-coprocessor-data-driven-dex-experiences/">https://blog.brevis.network/2023/11/01/uniswap-v4-hook-brevis-zk-coprocessor-data-driven-dex-experiences/</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.brevis.network/2024/01/18/introducing-brevis-cochain-the-fusion-of-crypto-economics-and-zk-proof-in-a-zk-coprocessor/">https://blog.brevis.network/2024/01/18/introducing-brevis-cochain-the-fusion-of-crypto-economics-and-zk-proof-in-a-zk-coprocessor/</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://dev.risczero.com/api/">https://dev.risczero.com/api/</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://research.lido.fi/t/trustless-zk-proof-based-total-value-locked-oracle/3405">https://research.lido.fi/t/trustless-zk-proof-based-total-value-locked-oracle/3405</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://research.lido.fi/t/zkllvm-trustless-zk-proof-tvl-oracle/5028">https://research.lido.fi/t/zkllvm-trustless-zk-proof-tvl-oracle/5028</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.ambient.finance/users/dynamic-fees">https://docs.ambient.finance/users/dynamic-fees</a></p>]]></content:encoded>
            <author>lukewasm@newsletter.paragraph.com (lukewasm.eth)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/78b80b5c6b97e52352891376ff44a3eb77c0f96479bc6b1d2720bc7d085db48d.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[Uniswap: Zero to Infinity]]></title>
            <link>https://paragraph.com/@lukewasm/uniswap-zero-to-infinity</link>
            <guid>7Fs8GSBHUCfvJWoi9Rt7</guid>
            <pubDate>Tue, 17 Oct 2023 07:14:35 GMT</pubDate>
            <description><![CDATA[Special thanks to Alex from Maru Network, Brad from Uniswap Labs, Dong Mo from CelerNetwork, Shumo from Manta Network, and Suning from Hyperoracle for their invaluable discussions, insights, and feedback on this article.IntroductionUndoubtedly, Uniswap stands as one of the most widely used decentralized applications. It relentlessly pioneers innovative solutions that redefine the game. In this article, I will delve into Uniswap&apos;s awe-inspiring journey from the past to a limitless future....]]></description>
            <content:encoded><![CDATA[<p><em>Special thanks to Alex from Maru Network, Brad from Uniswap Labs, Dong Mo from CelerNetwork, Shumo from Manta Network, and Suning from Hyperoracle for their invaluable discussions, insights, and feedback on this article.</em></p><h2 id="h-introduction" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Introduction</h2><p>Undoubtedly, Uniswap stands as one of the most widely used decentralized applications. It relentlessly pioneers innovative solutions that redefine the game. In this article, I will delve into Uniswap&apos;s awe-inspiring journey from the past to a limitless future. By examining the features of each version of Uniswap, I uncover how it effectively tackles new challenges and adapts to ever-changing demands. Additionally, I explore how the latest advancements in crypto are shaping the future of decentralized exchanges (DEX). Prepare for a journey from zero to infinity.</p><h2 id="h-v0-proof-of-concept" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">v0: Proof of Concept</h2><p>Prior to Uniswap, EtherDelta was the only decentralized exchange (DEX) that gained traction. However, the user experience was poor.</p><p>The concept of an Automated Market Maker (AMM), proposed by many industry leaders (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.gnosis.pm/building-a-decentralized-exchange-in-ethereum-eea4e7452d6e">Alan Lu of Gnosis</a> and <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.reddit.com/r/ethereum/comments/55m04x/lets_run_onchain_decentralized_exchanges_the_way/">Vitalik</a>), offers an alternative approach to on-chain trading compared to traditional order-book models.</p><h2 id="h-features" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Features</h2><p><strong>Constant Product AMM</strong></p><p>Uniswap utilizes a constant product formula (x * y = k) to calculate the price of an asset. In this formula, x represents the reserve of the base asset, while y represents the reserve of the quote asset. When a token is withdrawn (bought) from a pool, a proportional amount must be deposited (sold) to ensure that the constant k is maintained. The ratio of tokens in the pool determines the price of a token.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/fe5d22460bdc4b39f0bde612d5f1101de91eb5d8d7ce1bfce327ca83b56b2bab.png" alt="Source: Uniswap" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Source: Uniswap</figcaption></figure><p>It&apos;s worth noting that other AMMs utilize different mathematical formulas to represent liquidity curves. Some examples include Curve&apos;s <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://classic.curve.fi/files/stableswap-paper.pdf">Stableswap</a> and <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.balancer.fi/concepts/pools/weighted.html">Balancer&apos;s weighted pools</a>.</p><h2 id="h-problems" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Problems</h2><p>Uniswap v0 is essentially a Proof-of-Concept, meaning there are still many unresolved issues. The two major problems are as follows:</p><ul><li><p>It only worked for a single ETH/ERC20 pair.</p></li><li><p>It only worked for a single liquidity provider (LP).</p></li></ul><h1 id="h-v1-functional-dex" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">v1: Functional DEX</h1><h2 id="h-features" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0"><strong>Features</strong></h2><p>Uniswap v1 launched on Ethereum mainnet on November 2, 2018. It supports multiple liquidity providers using an internal token to track fees and collateral. It utilizes a factory contract that enables anyone to add any token for trading against native ETH. This version provides a functional DEX. However, there are certain issues that need to be addressed.</p><h2 id="h-problems" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0"><strong>Problems</strong></h2><p>Since all tokens are paired with ETH, users can easily swap any ERC20 token for another ERC20 token by using ETH as an intermediary in a single transaction. However, there is a drawback: when it comes to frequent stablecoin swaps like DAI/USDT, relying on ETH as an intermediary for every swap becomes inefficient. In this case, a direct token pair is preferred.</p><h1 id="h-v2-money-lego" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">v2: Money Lego</h1><p>In May 2020, Uniswap v2 was launched, introducing numerous upgrades to the Uniswap Protocol. These enhancements increased its flexibility and expanded the range of trades possible.</p><h2 id="h-features" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Features</h2><h3 id="h-erc20erc20-pairs" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>ERC20/ERC20 Pairs</strong></h3><p>In Uniswap V2, there is a notable difference: instead of only pairing ERC20 tokens with ETH, now any ERC20 token can be directly pooled with any other ERC20 token. This feature offers great utility for liquidity providers as they can now maintain more diverse ERC20 token-denominated positions, including Stablecoin pairs.</p><h3 id="h-price-oracle" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Price Oracle</strong></h3><p>Uniswap v2 offers on-chain price feeds that can be utilized by numerous DeFi applications. These price feeds are resistant to manipulation, making them highly valuable. The mechanism involves adding the end-of-block price to a cumulative-price variable in the core contract, which is weighted by the duration of time that particular price existed. This variable essentially represents the sum of Uniswap prices for every second throughout the contract&apos;s entire history.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/38e0485eabe891147e1e62a4d03b1c6b5acad2f370173a78b5fea5cd93faa8a6.png" alt="Source: Uniswap" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Source: Uniswap</figcaption></figure><p>This variable can be utilized by external contracts to accurately track time-weighted average prices (TWAPs) over any given time interval. The process involves reading the cumulative price from an ERC20 token pair at the start and end of the interval. By calculating the difference in this cumulative price and dividing it by the length of the interval, a TWAP for that specific period can be generated.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/089a1eefbf7d65b28eab5683d49d6bd64209cf115f17155f8add911e7daf933c.png" alt="Source: Uniswap" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Source: Uniswap</figcaption></figure><h3 id="h-flash-swaps" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Flash Swaps</strong></h3><p>Uniswap v2 also introduces Flash Swaps, which is a type of <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://chain.link/education-hub/flash-loans">flash loan</a> pioneered by the lending market <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.aave.com/faq/flash-loans">AAVE</a>. This feature allows any user to withdraw as much as ERC20 token in a pool with no upfront cost and do arbitrary actions, provided that by the end of the transaction execution equivalent values (plus fees) are returned.</p><p>Flash loan features get its bad reputation as it comes often in headline with various kinds of attacks on DeFi protocols. But flash loans are not the problem. The real issues are existing vulnerabilities in a protocol. The atomic nature of flash loans eliminates the need for upfront capital requirements typically associated with operations such as arbitraging between pools and obtaining margin leverage.</p><h2 id="h-problems" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0"><strong>Problems</strong></h2><p>Although the AMM is innovative and beneficial for bootstrapping trading and liquidity in new markets, it still has some inefficiencies. For instance, when dealing with low volatility tokens, liquidity is only necessary within a narrow price range. However, the current design distributes liquidity uniformly across all price ranges.</p><h1 id="h-v3-capital-efficiency" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">v3: Capital Efficiency</h1><p>Uniswap v3 aims to be the most flexible and efficient AMM due to its groundbreaking concentrated liquidity design.</p><h2 id="h-features" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Features</h2><h3 id="h-concentrated-liquidity-cl" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Concentrated Liquidity (CL)</strong></h3><p>In Uniswap v2, liquidity is evenly distributed across an x*y=k price curve, encompassing all prices from 0 to infinity. However, in most pools, a significant portion of this liquidity remains unused.</p><p>In Uniswap v3, liquidity providers (LPs) have the ability to concentrate their capital within specific price ranges, allowing for increased liquidity at desired prices. This customization enables LPs to construct personalized price curves that align with their preferences. These individual positions are then aggregated into a single pool, creating a unified curve against which users can trade. The outcome is mutually beneficial for both traders and liquidity providers: Traders experience reduced slippage and LPs earn greater fees, thanks to the higher concentration of liquidity within a customized range.</p><p>CL is incredibly valuable for stable pairs, such as stablecoins and liquid staking derivative tokens. These assets tend to be traded within a narrow price range. However, for more volatile token pairs, CL requires more advanced liquidity management techniques. It may be challenging for average retail liquidity providers to consistently manage their positions effectively.</p><h3 id="h-range-orders" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Range Orders</h3><p>With CL, a novel order type called <em>range orders</em> are introduced to complement market orders. LPs have the ability to deposit a single token within a custom price range, either above or below the current price. If the market price falls within their specified range, they can sell one asset for another along a smooth curve, all while earning swap fees.</p><p>A range order functions similarly to a &apos;limit order,&apos; but with the drawback of reversibility- when the price reverses, the order is also reversed. However, fees are still earned in the process. Barry Fried (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/BarryFried1">@BarryFried1</a>) offers a detailed example of how to use range orders in this <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/BarryFried1/status/1569758739736969217">thread</a>.</p><h3 id="h-multiple-fee-tiers" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Multiple Fee Tiers</strong></h3><p>Instead of having one fee tier, Uniswap v3 introduces three separate fee tiers per pair — 0.05%, 0.30%, and 1.00%, allowing LPs to be appropriately compensated for taking on varying degrees of risk</p><h3 id="h-advanced-oracles" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Advanced Oracles</strong></h3><p>Uniswap v3 offers significant improvements to the price oracle. Instead of storing only one price cumulative variable, v3 stores an array of variables, making it far easier and cheaper to create more advanced oracles that include simple-moving averages (SMA), exponential moving averages (EMA), outlier filtering, and more.</p><h2 id="h-problems" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Problems</h2><h3 id="h-lack-of-flexibility" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Lack of Flexibility</h3><p>Although concentrated liquidity and fee tiers provided more flexibility for liquidity providers and enabled the implementation of new strategies, Uniswap v3 fell short in accommodating the evolving functionalities and innovations in AMMs and markets. To incorporate additional features such as TWAP orders, limit orders, advanced oracles, and dynamic fees, it would have been necessary to re-implement the core protocol.</p><p>Certain features, such as the price oracle initially introduced in Uniswap v2, enabled integrators to utilize decentralized on-chain pricing data. However, this came at the expense of increased gas costs for swappers and lacked customization options for integrators.</p><h3 id="h-complicated-liquidity-management" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Complicated Liquidity Management</h3><p>As mentioned earlier, concentrated liquidity is challenging to manage for unsophisticated liquidity providers, particularly for volatile pairs. While several automatic liquidity management protocols have emerged, they mostly consist of simple rebalancing strategies designed for pegged assets. Unfortunately, these strategies are ineffective when it comes to volatile pairs because of the limitations imposed by long block times, gas costs, hedging costs, etc.</p><p>Moreover, since the concentrated liquidity position varies for each liquidity provider, the LP token is inherently non-fungible. It can only be represented by a non-fungible token (NFT), which presents a challenge for other DeFi protocols looking to integrate with it.</p><p>Numerous outstanding projects are actively addressing this issue using a range of strategies, including rebalancing, dynamic hedging with money markets, perpetuals, and options. Atis Elsts (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/atiselsts_eth">@atiselsts_eth</a>) has written <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://atise.medium.com/liquidity-provider-strategies-for-uniswap-v3-table-of-contents-64725c6c0b10">a series of excellent articles</a> on LP strategies that are highly recommended.</p><h3 id="h-value-leakage" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Value Leakage</h3><p>The issue of value leakage is the most significant problem of all. While this is not unique to Uniswap v3, it has gained attention due to the increased volumes and wider adoption of AMMs since the launch of v3. This value leaks out of the DEX system in forms of</p><ul><li><p>Traders end up paying higher slippage than necessary due to front running and sandwich attacks.</p></li><li><p>Liquidity providers lose value through CEX-DEX arbitrages (a.k.a. Loss-versus-Rebalancing)</p></li></ul><p>To address these problems, we need more customized and sophisticated designs that go beyond what Uniswap v3 currently offers. We require a DEX platform that is more expressive and powerful.</p><h1 id="h-v4-ultimate-platform" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">v4: Ultimate Platform</h1><p>Uniswap v4 builds on top of AMM models introduced in previous generations and through the introduction of &apos;hooks&apos;, it aims to be the ultimate DEX platform with high efficiency and customization.</p><h2 id="h-efficiency" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Efficiency</h2><h3 id="h-singleton" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Singleton</strong></h3><p>In Uniswap v3, every pool is created as an individual contract through a factory contract. On the other hand, in v4, all pools coexist within a single smart contract (known as a singleton). This singleton model significantly decreases the expenses associated with creating pools and executing multi-hop trades.</p><h3 id="h-flash-accounting" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Flash Accounting</strong></h3><p>In v4, the singleton utilizes flash accounting to optimize asset transfers. Unlike in v3, where assets are moved in and out of pools after every swap, the v4 system only transfers based on net balances. This significantly reduces the cost of accounting. Transient storage (proposed in <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.eip1153.com/">EIP-1153</a>) makes it cheaper to set and clear a storage slot which is necessary for flash accounting to operate effectively.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/10d565190e2c620823f826d79f9fd7292cd73b6d6e652215345dc65652dc2bcc.png" alt="Source: Uniswap" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Source: Uniswap</figcaption></figure><h3 id="h-native-eth" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Native ETH</h3><p>Uniswap v4 reintroduces support for trading against native ETH, which brings several benefits. Traders can enjoy reduced gas costs for cheaper transfers and the elimination of additional wrapping costs.</p><h2 id="h-customization" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Customization</h2><h3 id="h-hooks" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Hooks</h3><p>Hook contracts (or hooks), are externally deployed contracts that execute pre-defined logic at specific points during the execution of a pool. This is what makes v4 so expressive and customizable. Hooks allow for the implementation of features that were previously built into the protocol, such as oracles, as well as new features that previously required independent protocol implementations.</p><p>Uniswap v4 currently supports eight such hook callbacks:</p><ul><li><p>beforeInitialize/afterInitialize</p></li><li><p>beforeModifyPosition/afterModifyPosition</p></li><li><p>beforeSwap/afterSwap</p></li><li><p>beforeDonate/afterDonate</p></li></ul><p>The figure below illustrates the logic flow for a Swap Hook. Before and after executing a swap, there is a dedicated boolean flag that enables the execution of custom code at these specific points. This serves as the basis for developing advanced features like oracles, dynamic fee structures, auctions, and advanced order types, etc. We will delve deeper into these concepts in the following sections.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/03ad0528258e85988af3c8f5d763b3eaa2763cb5b33a952a7a99a8f14b5e1503.png" alt="Swap Hook Flow" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Swap Hook Flow</figcaption></figure><h4 id="h-oracles" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0"><strong>Oracles</strong></h4><p>In previous versions, oracles were integrated into the core Uniswap protocol. While this made integration easier and cheaper for other protocols, it came at the expense of customization options and higher costs for swappers. However, with the introduction of hooks, the design possibilities for oracles have significantly expanded. This opens up the opportunity to create manipulation-resistant oracles such as winsorized price oracles as well as volatility oracles. Additionally, the choice of who bears the costs of updating oracles can now be customized. For example, instead of burdening the first swapper with the cost, which may not be sustainable, a hook contract with an ETH balance could be used for gas payment. Despite these advancements, designing oracles still presents challenges. For instance, TWAP oracles are sometimes susceptible to manipulation and tend to lag behind current prices.</p><p>Uniswap Labs has introduced another intriguing price oracle known as the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.uniswap.org/uniswap-v4-truncated-oracle-hook">truncated price oracle</a>. This oracle calculates the geometric mean price of an asset in a liquidity pool and imposes a limit on price movement within a single block. By truncating the price, this on-chain oracle mitigates the price impact of significant trades, enhancing resistance to manipulation attempts.</p><h4 id="h-dynamic-fees" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0"><strong>Dynamic Fees</strong></h4><p>While Uniswap v3 introduced additional fee tiers for LPs to select from, these fee structures remain static and do not consider current market conditions. Consequently, LPs are not adequately compensated for their services.</p><p>Alex Nezlobin (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/0x94305">@0x94305</a>) proposed a simple yet effective dynamic fee structure that considers the price impact of the previous block and applies different fees for buyers and sellers. The following figure illustrates an example: when the CEX price moves to p*, which is higher than the current AMM price p_AMM, the fee for sales decreases by δ, while the fee for buys increases by δ. The value of δ is proportional to the change in AMM price. The purpose of this dynamic fee structure is to differentiate between arbitrageurs and uninformed flows. Arbitrage flows are more likely to be autocorrelated with price movements.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/ad65033b1604826e15962b5cfc02c222a71038e6be1eec91b5a8c7ec51f438e5.png" alt="Source: https://twitter.com/0x94305/status/1674857993740111872" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Source: https://twitter.com/0x94305/status/1674857993740111872</figcaption></figure><p>Designing a robust dynamic fee structure presents several challenges. One challenge is how to incorporate off-chain signals, such as CEX price, liquidity depth, and volatility. Additionally, various on-chain signals, including address, size, and execution time, can be unreliable for differentiating between informed and uninformed flow, making it difficult to assess their effectiveness. Furthermore, it is important to ensure that fees do not go below zero in order to limit losses for LPs.</p><h4 id="h-auctions" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0"><strong>Auctions</strong></h4><p>Hooks can also serve as a means to implement auctions, which can aid in redistributing value back to LPs. Depending on the timing, auctions can be categorized as either ex ante or ex post auctions.</p><p><strong><em>Ex ante auctions</em></strong> take place prior to the block. This concept was initially introduced in a research article that discussed <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://ethresear.ch/t/mev-capturing-amm-mcamm/13336">MEV capturing AMM (McAMM)</a>. In this approach, the right to make the first swap in an AMM before a block is auctioned off, and the bid values are subsequently redistributed. However, there are challenges associated with this bidding process, as it essentially involves pricing an option, which can be highly complex. Additionally, since block proposers hold the ultimate decision-making power regarding whether to accept a block containing the trades, issues of censorship may arise. Ensuring fair and efficient distribution of bid values can also prove to be a complicated task. Moreover, there is no guarantee that the winners of the bids would exercise their right to swap first, potentially resulting in a deteriorating experience for other traders.</p><p><strong><em>Ex post auctions</em></strong> are conducted after volatility has been realized, meaning that CEX prices have already moved but before the subsequent block has been committed. The advantage of these auctions is their increased effectiveness. However, they pose challenges as they require off-chain infrastructure that relies either on trusted parties or trustless systems. If trusted parties are used, concerns arise regarding censorship and bid privacy. On the other hand, designing trustless systems is much more complex. Ex post auctions also face the issue of proposers potentially playing games with bidders, such as excluding arbitrage trades from being included in a timely manner. Additionally, there is the significant problem of extra latency involved in bidding, running consensus on winning bids, and distributing those bids to block builders—all of which need to be completed before the subsequent block is committed. Finally, it may be difficult to ensure sufficient competitive conditions in these auctions to capture enough value. Sorella Labs (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/SorellaLabs">@SorellaLabs</a>) is leading the charge in addressing these challenges by leveraging its advanced infrastructure and mechanism designs.</p><h4 id="h-diamond-hook" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0"><strong>Diamond Hook</strong></h4><p>The <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://arxiv.org/abs/2210.10601">Dimond Protocol</a> was initially designed as an LVR-minimizing AMM. In Diamond, block producers conduct auctions to capture any arbitrage opportunities between the external market price of a Diamond pool and the pool&apos;s own price. The proceeds from these auctions are shared between the Diamond pool and the block producer in a manner that remains incentive compatible for the block producer.</p><p>A variation of the Dimond Protocol, as discussed in this <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://ethresear.ch/t/lvr-minimization-in-uniswap-v4/15900">post</a>, involves implementing a collateral pool to maintain the end-of-block price in accordance with the committed price by block producers. Swaps will only execute if there is sufficient collateral available to restore the price to the committed value. Arrakis (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/ArrakisFinance">@ArrakisFinance</a>) is currently collaborating with Conor McMenamin (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/ConorMcMenamin9">@ConorMcMenamin9</a>), one of the authors of the Diamond Protocol, to develop <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x916563f8476b988855af0b8b8A3D56072E1917FA/ZhTQJ6qiurBTHBNuF08GudWBQ8x9p3P-12vo-C9czKE">an implementation</a> using v4 hooks.</p><p><strong>Advanced Order Types</strong></p><p>Hooks could also enable more advanced order types that greatly improve trader experience. Some common order types include limit orders, stop loss, take-profit, TWAP</p><p>Limit Orders</p><p>Traders have the option to submit on-chain limit orders to the hook contract. When the price reaches the specified tick price, the order is filled. However, these on-chain limit orders have a significant disadvantage compared to traditional finance (tradfi) limit orders. This is primarily because on-chain orders cannot be cancelled without incurring gas fees. As a result, this creates a problem known as a <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/0x94305/status/1669111840272683008">low order-to-trade ratio</a>.</p><p>TWAMM</p><p>One possible solution for facilitating the execution of large orders over time is to implement a time-weighted average market maker (TWAMM). This approach involves breaking down large orders into smaller blocks and ensuring they are executed as the first trades, thus preventing sandwich attacks. Additionally, reducing TWAP order fees could be considered since they typically involve uninformed flow. However, a challenge arises with the high gas costs and determining who should bear these expenses.</p><p><strong>Other Hooks</strong></p><p>There are several other features that could be implemented using hooks. Here are some ideas:</p><ul><li><p>A yield-bearing hook that lends out-of-range liquidity into money markets to increase capital efficiency.</p></li><li><p>A pool with both xy=k liquidity curve and concentrated liquidity.</p></li><li><p>A pool with withdrawal fees for LPs to reduce Just-in-time liquidity attacks.</p></li></ul><p>Suning (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/msfew_eth">@msfew_eth</a>) provides an awesome curation of hook ideas and implementations on <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/fewwwww/awesome-uniswap-hooks">Github</a>. Aiden (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/aiden0x4">@aiden0x4</a>) also publishes a nice <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://uniswaphooks.com/">open directory</a> for hooks.</p><h3 id="h-zkamm-and-zkhooks" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">zkAMM &amp; zkHooks</h3><p>ZK Coprocessors empower smart contracts with the ability to access data insights akin to those offered by Dune Analytics, all without compromising trust due to the application of Zero-Knowledge (ZK) Proof technologies. The utilization of zk Coprocessors in AMM designs has been an emerging and actively researched area. The introduction of hooks now allows for the seamless integration of zk proofs into Uniswap v4, ushering in a new era of zero knowledge AMMs, or zkAMMs.</p><p>HyperOracle (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/HyperOracle">@HyperOracle</a>) <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/hyperoracleblog.eth/Tik3nBI9mw05Ql_aHKZqm4hNxfxaEQdDAKn7JKcx0xQ">demonstrates an implementation of zkAMM based on Uniswap v2</a>, where the addLiquidity computation is offloaded off-chain. When a user adds liquidity, the token amount, price, and LP token shares need to be computed. In this particular implementation, HyperOracle&apos;s zkGraph captures the addLiquidity event, performs the necessary computation, generates the proof, and publishes it. This implementation of zkAMM includes an integrated automation layer that verifies the proof and mints the LP token for the user.</p><p>Diego (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/0xfuturistic">@0xfuturistic</a>) <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://ethresear.ch/t/zkuniswap-a-first-of-its-kind-zkamm/16839">introduces an implementation of zkAMM (zkUniswap) based on Uniswap v3</a> where a portion of the AMM swap computation is offloaded to the Risc Zero (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/RiscZero">@RiscZero</a>) zkVM. When a user performs a swap in a pool, several parameters need to be calculated to finalize the swap. These parameters include the amount to be swapped in and out, the fee, and the price after swapping. Originally, this computation was performed within the solidity contract through EVM. However, with the new implementation, the swap inputs are picked up by the relayer, and the computation is carried out off-chain. The relayer then posts the output and the proof. The AMM verifies the proof and settles the swap. zkUniswap implements a lock auction mechanism to ensure concurrency control. While its current performance is comparable to that of the EVM, the efficiency could be significantly enhanced through parallelization for batched swaps.</p><p>Proof of volume serves as another use case for AMMs. Brevis (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/brevis_zk">@brevis_zk</a>) provides an interesting example where a fee rebate hook could be designed based on users&apos; historical trading volume, similar to trading-volume-based fee rebates on centralized exchanges (CEXes). VIP traders now have the ability to calculate their monthly trading volume off-chain and then submit a low-cost ZK proof to the blockchain for asynchronous verification of their VIP status. Once verified, subsequent trades can utilize post-swap hooks to access a &quot;VIP fee-tier table&quot; populated by the ZK Coprocessors. This allows for automatic application of the appropriate fee rebates. Maru Network (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/marunetwork">@marunetwork</a>) is currently developing trustless volume oracles as their initial use case for their zk Coprocessor network. By implementing a trustless volume oracle, DEXes would be able to distribute rewards in a fair and transparent manner. This approach allows for proportional incentivization of liquidity and user activities, fostering a positive flywheel effect. The cost of proof verification can be reduced by using zero-knowledge proof aggregation services such as NEBRA (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/nebrazkp">@nebrazkp</a>) UPA (Universal Proof Aggregation), which aggregates proofs from different circuits and different parties to a single proof to achieve reduced amortized verification cost.</p><p>In summary, the concept of zkAMMs involves utilizing zkCoprocessors or zkOracles to shift computations away from the EVM and verify the proof of computation on-chain. These computations can be significantly more intricate than those related to swaps and liquidity adjustments. For instance, they could involve calculating dynamic fees based on recent market volatility, proving historic volumes of users in a given pool or implementing rebalancing strategies using complex machine learning algorithms. The possibilities are endless, as any computation ultimately results in an O(1) verification cost, no longer constrained by the computational resources of the EVM.</p><h2 id="h-v4-challenges" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0"><strong>v4 Challenges</strong></h2><p>Uniswap v4 introduces efficiency and customization to the AMM design space, enabling the creation of pools with diverse features and functionalities. However, this advancement comes with a foreseeable trade-off: an increase in liquidity fragmentation due to the proliferation of pools. As a result, routing becomes significantly more challenging.</p><h1 id="h-uniswapx" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">UniswapX</h1><p>UniswapX aims to tackle the issue of liquidity fragmentation by outsourcing the complexity of routing to a open network of third-party fillers. These fillers compete with each other to execute swaps using on-chain liquidity like AMM pools or their own private inventory. This design is intent-centric, allowing users to simply state their desired outcomes and rely on professionals to fulfill them.</p><p>These fillers are sophisticated agents equipped with advanced routing algorithms, high computational power, and substantial financial capital. They compete with each other under a predetermined auction mechanism to offer users the best possible execution. Users may also receive price improvement, ensuring that their executions are at least as good as trades directly from Uniswap AMM pools.</p><p>The architecture of the UniswapX protocol is depicted below. Swappers submit their intent orders, which are structured as <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/dragonfly-xyz/useful-solidity-patterns/tree/main/patterns/permit2">Permit2</a> executable off-chain signatures, through the Uniswap API. Permit2 is an elegant model that ensures the safe movement of tokens held by users. Fillers devise strategies to fulfill these orders using any liquidity venue available to them, whether on-chain or off-chain. Finally, Order Reactors settle UniswapX orders. They are responsible for validating orders of a specific type, resolving them into inputs and outputs, executing them based on the filler&apos;s strategy, and verifying successful fulfillment of the order.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/082b912b73d5bd6112794bef669743aec1494e66b2d569410bd03fa479765f25.png" alt="Source: Uniswap" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Source: Uniswap</figcaption></figure><p>In the current Uniswap Labs interface implementation of UniswapX, the protocol is broken into two phases. The first is the RFQ phase, where whitelisted &apos;quoters&apos; respond with quotes to the orders. The winner of the quote then has an exclusivity period to fill the order. If they don&apos;t, then it enters the second phase, the Dutch Auction phase, which is a auction that any filler can take part in. The plan is to make the quoting system fully permissionless in the near future.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/4812cb7a5818d00dbf4f19e22d896006b7d29b4db0d9b1fc64ace2248d9f6ce0.png" alt="Source: Onchain Trading by Hayden Adams, EthCC" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Source: Onchain Trading by Hayden Adams, EthCC</figcaption></figure><p>The intent-centric design offers several benefits.</p><ul><li><p>Aggregating liquidity sources for better prices.</p></li><li><p>No requirement for gas tokens, even for cross-chain swaps.</p></li><li><p>Internalization of MEV through price improvement.</p></li><li><p>No cost incurred for failed transactions.</p></li></ul><h2 id="h-challenges" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Challenges</h2><ul><li><p>Making the quoting system permissionless, e.g. Using an effective reputation system.</p></li><li><p>Attracting more fillers to ensure a competitive and permissionless auction environment.</p></li></ul><h2 id="h-the-future-an-infinite-game" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">The Future: An Infinite Game</h2><p>The development of DEXes doesn&apos;t stop here. In order for crypto to achieve mass adoption, there are several other issues that need to be addressed. Markus Schmitt (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/_haikane_">@_haikane_</a>) from PropellerHeads (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/PropellerSwap">@PropellerSwap</a>), in collaboration with Frontier Research (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/FrontierDotTech">@FrontierDotTech</a>), has written <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.propellerheads.xyz/blog/the-next-steps-in-dex-design">an outstanding article</a> that delves into what constitutes a good DEX and identifies the remaining problems that need to be solved. According to his perspective, a good exchange should offer:</p><ol><li><p><strong>Trust</strong>: Ensuring transparency and minimizing custody risks before, during, and after transactions.</p></li><li><p><strong>Best Prices</strong>: Providing confidence in obtaining the best or competitive prices consistently, eliminating the need to search elsewhere.</p></li><li><p><strong>Fairness</strong>: Preventing abuse of orders and ensuring equal treatment regarding pricing and fees for all users.</p></li><li><p><strong>Speed and Availability</strong>: Offering fast transaction processing and maintaining high availability to avoid delays and inconveniences.</p></li><li><p><strong>Information</strong>: Assisting users in making informed decisions by providing order monitoring, settlement price estimates, and helpful suggestions for limit orders and slippage.</p></li><li><p><strong>Liquidity</strong>: Demonstrating a robust liquidity pool across various asset pairs, instilling confidence in obtaining favorable prices.</p></li></ol><p>If the smart contracts of DEXes are considered safe, trust is already built-in. DEXes don&apos;t hold users&apos; assets. The information available to traders is quite extensive now. The permissionless nature of AMMs enables users to create and trade any asset pairs. However, due to blockchain characteristics, ensuring the best prices, fairness, speed, and availability is not always guaranteed. Gas fees, stale prices, and fragmented liquidity all contribute to impacting users&apos; experience.</p><p>To address these issues, we are witnessing a proliferation of L2s and DEXes on L2s. Additionally, we are seeing more sophisticated routing, order batching, and Request-for-quotes systems. To prevent front-running and ensure fair value distribution, more MEV-aware channels are being employed. Moreover, efforts are underway to develop order flow auction markets that minimize value leakage for DEX users. The introduction of hooks and zk Coprocessors also significantly expands the design possibilities for AMMs, allowing for more complex logic and heavy computations without compromising trust.</p><p>Additionally, there is a suite of protocols that build upon AMMs, effectively stacking the “money lego”. These protocols include liquidity managers that assist unsophisticated users in automating liquidity rebalancing or leveraging farming. There are also protocols that utilize Concentrated Liquidity (CL) positions to create margin trading, perpetuals, options, and structured products.</p><p>AMMs have witnessed exponential growth thanks to their permissionless listing, passive liquidity, and ease of trading. However, this convenience also brings along several issues that we have explored so far. Uniswap is consistently pushing the boundaries to address these issues and enhance the user experience. As Dan Robinson (<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/danrobinson">@danrobinson</a>) aptly puts it in his <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://youtu.be/NFJWy8oyVS0?t=7061">speech at SBC23</a>, DEX design is an infinite game. With increased adoption of DEXes in the future, new challenges and problems are likely to arise, necessitating innovative solutions.</p><h2 id="h-references" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">References</h2><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://vitalik.ca/general/2017/06/22/marketmakers.html">https://vitalik.ca/general/2017/06/22/marketmakers.html</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.reddit.com/r/ethereum/comments/55m04x/lets_run_onchain_decentralized_exchanges_the_way/">https://www.reddit.com/r/ethereum/comments/55m04x/lets_run_onchain_decentralized_exchanges_the_way/</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.gnosis.pm/building-a-decentralized-exchange-in-ethereum-eea4e7452d6e">https://blog.gnosis.pm/building-a-decentralized-exchange-in-ethereum-eea4e7452d6e</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.uniswap.org/uniswap-history">https://blog.uniswap.org/uniswap-history</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.uniswap.org/uniswap-v2">https://blog.uniswap.org/uniswap-v2</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.uniswap.org/uniswap-v3">https://blog.uniswap.org/uniswap-v3</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.uniswap.org/uniswap-v4">https://blog.uniswap.org/uniswap-v4</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.uniswap.org/uniswap-v4-truncated-oracle-hook">https://blog.uniswap.org/uniswap-v4-truncated-oracle-hook</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.uniswap.org/uniswapx-protocol">https://blog.uniswap.org/uniswapx-protocol</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://blog.uniswap.org/what-is-uniswap">https://blog.uniswap.org/what-is-uniswap</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.uniswap.org/contracts/uniswapx/overview">https://docs.uniswap.org/contracts/uniswapx/overview</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://smartbuilds.io/defi-flashloans-explained-uniswap-foundry/">https://smartbuilds.io/defi-flashloans-explained-uniswap-foundry/</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://chain.link/education-hub/flash-loans">https://chain.link/education-hub/flash-loans</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.propellerheads.xyz/blog/the-next-steps-in-dex-design">https://www.propellerheads.xyz/blog/the-next-steps-in-dex-design</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://atise.medium.com/liquidity-provider-strategies-for-uniswap-v3-table-of-contents-64725c6c0b10">https://atise.medium.com/liquidity-provider-strategies-for-uniswap-v3-table-of-contents-64725c6c0b10</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/fewwwww/awesome-uniswap-hooks">https://github.com/fewwwww/awesome-uniswap-hooks</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://uniswaphooks.com/">https://uniswaphooks.com/</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://ethresear.ch/t/zkuniswap-a-first-of-its-kind-zkamm/16839">https://ethresear.ch/t/zkuniswap-a-first-of-its-kind-zkamm/16839</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/hyperoracleblog.eth/Tik3nBI9mw05Ql_aHKZqm4hNxfxaEQdDAKn7JKcx0xQ">https://mirror.xyz/hyperoracleblog.eth/Tik3nBI9mw05Ql_aHKZqm4hNxfxaEQdDAKn7JKcx0xQ</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://hackmd.io/@Hill/coprocessors">https://hackmd.io/@Hill/coprocessors</a></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x916563f8476b988855af0b8b8A3D56072E1917FA/ZhTQJ6qiurBTHBNuF08GudWBQ8x9p3P-12vo-C9czKE">https://mirror.xyz/0x916563f8476b988855af0b8b8A3D56072E1917FA/ZhTQJ6qiurBTHBNuF08GudWBQ8x9p3P-12vo-C9czKE</a></p>]]></content:encoded>
            <author>lukewasm@newsletter.paragraph.com (lukewasm.eth)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/31e7c7e3b1a2ad91a77bc699e68d0142c2c5543e074aab9b39dcfeb661b875fe.jpg" length="0" type="image/jpg"/>
        </item>
    </channel>
</rss>