<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Brad Chase</title>
    <description>The latest articles on DEV Community by Brad Chase (@bachase).</description>
    <link>https://dev.to/bachase</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1389631%2Ffc3d6f92-913c-48d9-ad49-aadca1c9a7f6.png</url>
      <title>DEV Community: Brad Chase</title>
      <link>https://dev.to/bachase</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bachase"/>
    <language>en</language>
    <item>
      <title>November 25 XRPL Bug: Current Status and What’s Next</title>
      <dc:creator>Brad Chase</dc:creator>
      <pubDate>Wed, 27 Nov 2024 19:29:08 +0000</pubDate>
      <link>https://dev.to/ripplexdev/november-25-xrpl-bug-current-status-and-whats-next-b61</link>
      <guid>https://dev.to/ripplexdev/november-25-xrpl-bug-current-status-and-whats-next-b61</guid>
      <description>&lt;p&gt;On 13:39 UTC on November 25 2024, the XRP Ledger experienced an issue in which several nodes across the network crashed and restarted at similar times. During periods of instability, the XRPL network consensus model favors safety over progress, and as a result, the network did not process any transactions for approximately 10 minutes as it recovered. There was no loss of funds (just momentary pause of new transactions). The network resumed normal behavior and forward progress at 13:49 UTC on the same day. &lt;/p&gt;

&lt;p&gt;Thanks to the community’s quick response once the fix was introduced (1:30 UTC November 26), 33 of 35 validators on the default UNL upgraded to rippled 2.3.0 by publish time of this post, along with nearly half of known servers. While the core of the network has upgraded, unpatched nodes remain potentially susceptible, and we encourage all users to update their infrastructure to rippled 2.3.0 immediately.&lt;/p&gt;

&lt;p&gt;Last week, at the same time as completing the testing of rippled 2.3.0, the RippleX team identified the bug and included a fix in an internal release candidate. To minimize risks, we decided not to isolate the issue pre-release or create a standalone patch, as this could have enabled reverse engineering and exploitation of the bug. When a similar issue appeared on mainnet, we validated the fix and worked directly with the community and other UNL operators to coordinate upgrades and secure the network.&lt;/p&gt;

&lt;p&gt;The issue stems from a bug introduced more than 6 months ago. In some circumstances, the caching layer in rippled can return an inconsistent result type which can cause a server to crash. Although this bug went undetected during testing of this refactor, there is no prior evidence of exploitation. To minimize potential risks for unpatched users, we are still withholding specific technical details until the majority of servers are upgraded. &lt;/p&gt;

&lt;p&gt;So what's next? To give remaining node operators sufficient time to upgrade, we will wait to share more technical details until December 12. Once those details are available, the bug will become easier to identify, potentially increasing the risk for nodes that remain unpatched. Again, we strongly recommend upgrading to 2.3.0 as soon as possible.&lt;/p&gt;

&lt;p&gt;This issue is a reminder of the complexities that come with innovation and introducing new features to a decentralized system like the XRPL. There’s always room to improve, and we appreciate the close collaboration among the community to make the network stronger and safer.&lt;/p&gt;

&lt;p&gt;The XRPL depends on the global community of validators, developers, and contributors to keep it running. By learning and continuing to iterate, together, we can make the network more secure and reliable for everyone.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>XRP Ledger AMM Bug Fix Now Integrated: A Detailed Analysis</title>
      <dc:creator>Brad Chase</dc:creator>
      <pubDate>Fri, 12 Apr 2024 19:49:02 +0000</pubDate>
      <link>https://dev.to/ripplexdev/xrp-ledger-amm-bug-fix-now-integrated-a-detailed-analysis-4915</link>
      <guid>https://dev.to/ripplexdev/xrp-ledger-amm-bug-fix-now-integrated-a-detailed-analysis-4915</guid>
      <description>&lt;p&gt;The bug fix for the XRP Ledger’s Automated Market Maker (AMM feature) has been successfully integrated into the XRPL Mainnet as of April 11. This marks the resolution of an issue discovered on March 23 regarding an unexpected number of LPTokens in an AMM pool. Thanks to the collaboration with XRPL validators and community participants, we were able to work together to identify, diagnose and resolve the issue swiftly.&lt;/p&gt;

&lt;p&gt;In my previous &lt;a href="https://dev.to/ripplexdev/update-on-the-xrp-ledger-amm-bug-and-the-path-forward-hkb"&gt;blog post&lt;/a&gt;, I provided an overview of the issue, immediate response, and next steps. As promised, this follow-up post will dive deeper into the details of the bug, its impact, the lessons learned, and the ongoing work to prevent similar issues from occurring in the future.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Background - Payment Engine and Liquidity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A major benefit of the XRPL is how features are composable, which enables flexibility and efficiency in payment processing. Through the XRPL’s payment engine, the AMM and built-in decentralized exchange (DEX) can both interact to provide liquidity for payments. Some payments, such as transferring XRP from one account to another, are straightforward. Others are more complex. For example, consider a scenario where a user wants to send USD and have the destination account receive EUR. In this case, the payment engine would use the USD to EUR order book to convert the funds. The process of specifying how currencies are meant to be converted is called a “&lt;a href="https://xrpl.org/docs/concepts/tokens/fungible-tokens/paths/"&gt;payment path&lt;/a&gt;.”&lt;/p&gt;

&lt;p&gt;The payment engine can use one or more paths to complete a payment. In the example, in addition to the USD to EUR order book, the sender could also specify a second path that uses an order book to convert from USD to XRP; then a second order book from XRP to EUR. Both payment paths may be used in the same payment, and the payment engine will always consume liquidity from the path that offers the most cost-effective option for the sender.&lt;/p&gt;

&lt;p&gt;AMMs provide a new way to convert between assets that complements the DEX’s order books. Unlike offers, which have fixed exchange rates, the AMM exchange rate varies continuously as liquidity is consumed from the AMM pool according to a constant product formula (see &lt;a href="https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0030-automated-market-maker"&gt;XLS-30&lt;/a&gt; for details). The payment engine needs a way to compare the discrete liquidity from an offer with the continuous liquidity from an AMM to provide the most cost-efficient path for payments.&lt;/p&gt;

&lt;p&gt;To address this challenge, the payment engine creates synthetic offers backed by the AMM. From the payment engine's point of view, these synthetic offers act the same way as users' offers. In particular, consuming liquidity from these synthetic offers does not change the exchange rate. The size of synthetic offers depends on the specific payment paths. When there is only a single payment path, the engine can use the constant-product formula to infer the right-sized exchange rate and offer size. In the multi-path case, that size depends on the liquidity from other paths, so the payment engine iteratively generates synthetic offers of increasing size to utilize liquidity from the AMM pool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Bug&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The bug occurred when a multi-path payment interacted with an AMM synthetic offer, and the synthetic offer required to fulfill the payment exceeded the AMM pool size. In this case, the payment engine attempted to use the single-path strategy to back-out the maximum liquidity available to swap against the pool. Although this condition was properly detected, there was an error on how the payment engine resized the synthetic offer to consume liquidity only up to the AMM size. Instead of using the actual swap rate, which represents the cost of fully swapping one side of an AMM pool, the new synthetic offer’s exchange rate was incorrectly set to the spot exchange rate of the AMM (that is, the rate it takes to execute an infinitesimally sized order). Consequently, an AMM operation that should have been expensive became relatively cheap, effectively violating the constant-product invariant of the pool. In this state, another user could deposit funds into the drained side of the pool, generating a large number of LP tokens and taking ownership of the pool. Now that the fix amendment is active, the team has opened a &lt;a href="https://github.com/XRPLF/rippled/pull/4986"&gt;PR&lt;/a&gt; with a unit test demonstrating this behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At the time of the bug report, there was only a &lt;a href="https://livenet.xrpl.org/accounts/rPWwcnDhvZg3x2KrW6UXRdeKMkvFQApyw6"&gt;single impacted AMM pool&lt;/a&gt; holding USD.rvYA and USD.rhub. Prior to the bug, the pool had $273 of USD.rhub and $3 of USD.rvYA. After a subsequent &lt;a href="https://livenet.xrpl.org/transactions/21B2322CC577A3F889A0D0F1E999DA9016D04344689CE43A55505C38AE100C6D/simple"&gt;payment&lt;/a&gt; that caused the constant product rule to be violated, the pool had nearly $0 of USD.rhub and $16 of USD.rvYA. The payment was instructed to swap out $272.455 of USD.rhub by spending up to $50 of USD.rvYA, but was fully executed by spending only $13 of USD.rvYA. This left the pool in an unbalanced state, where a subsequent deposit in the pool enabled a single depositor to own nearly all the pool’s LP tokens. Since that time, a large &lt;a href="https://livenet.xrpl.org/transactions/F26587F8AC1B54777909C4247B99D6BBA688BBB1C044B9B5DA895D533DDB14CE"&gt;AMMBid transaction&lt;/a&gt; burned enough LP tokens to restore the constant product invariant of the pool.&lt;/p&gt;

&lt;p&gt;During the time after the release of the bug fix but before the amendment became enabled, there appears to only be one other &lt;a href="https://livenet.xrpl.org/accounts/rfAf1ZqW9HYVt8fN6vb4TAkWppiBiF7phS"&gt;AMM pool&lt;/a&gt; impacted by this bug, this time holding EUR.rhub and SeagullCash.rNHe. For this pool, an &lt;a href="https://livenet.xrpl.org/transactions/7D9202118144429218572CB59A0683C847DB40F1F5F66119B195D51124784816"&gt;OfferCreate&lt;/a&gt; transaction, which automatically leverages &lt;a href="https://xrpl.org/docs/concepts/tokens/decentralized-exchange/autobridging/"&gt;auto-bridging&lt;/a&gt; to execute against available liquidity sources, was able to withdraw the entire €6.103 from the pool in exchange for 1 billion SeagullCash.rNHe. Due to the bug that fully drained one side, the pool is in a stuck state where assets cannot be added to or removed from the pool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Timeline &amp;amp; Response&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As a brief recap of events:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Bug Discovery: Early morning March 23, the Ripple dev team received a report from Tequ, a member of the XRPL community, regarding an unexpected number of LP Tokens in an AMM pool.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Issue Diagnosis: By the evening of March 23, the Ripple dev team, alongside community members Tequ and Orchestra, swiftly investigated the issue to identify the root cause and assessed the impact on AMM pools.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fix Development and Testing: Once the bug was reproduced, the team quickly had a fix prepared, but worked through March 24 to add an additional invariant check to enforce the properties of AMM pools during transaction processing. This check took extended time to develop in order to validate the numerical sensitivity of the invariant across a broad range of liquidity scenarios.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Community Communication: We promptly &lt;a href="https://x.com/RippleXDev/status/1771680918895558913"&gt;communicated the issue to the XRPL community through X&lt;/a&gt; (formerly Twitter) and direct outreach to community members including AMM UIs, ensuring transparency and collaboration throughout the process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hotfix Release: On March 26, a hotfix &lt;a href="https://github.com/XRPLF/rippled/pull/4968#issue-2209526207"&gt;PR was opened&lt;/a&gt;. It was merged on the morning of March 27.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Amendment Voting: The amendment for the bug fix was supported by XRPL validators  and reached 80% consensus on &lt;a href="https://twitter.com/RippleXDev/status/1773437741583192160?s=20"&gt;March 28&lt;/a&gt; and &lt;a href="https://livenet.xrpl.org/transactions/64144409D991726D108B89D79F9305438D61928A322EF1CD14DC3A5F24CE64BC"&gt;activated&lt;/a&gt; on April 11, showcasing the community's commitment to the XRPL’s stability and security.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lessons Learned and Fortifying the Future&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The initial focus was on fixing the bug and mitigating the impact. Since releasing the fix, the team has spent significant time reflecting on how to prevent a similar issue from occurring in the future, and on how the community can best respond and manage incidents like this. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Invariants are key&lt;/em&gt;. &lt;a href="https://xrpl.org/docs/concepts/consensus-protocol/invariant-checking/"&gt;Invariant checking&lt;/a&gt; is a safety feature of the XRP Ledger. It consists of a set of checks, separate from normal transaction processing, that guarantee that certain invariants hold true across all transactions and helps eliminate any adverse edge conditions or error case mishandling. The AMM feature has an obvious invariant from the constant product formula -- the number of issued LP tokens should always be less than or equal to the product of the square root of the assets in the pool. Although the team had built an invariant check during development, it was inadvertently removed before release. This was a huge miss. &lt;/p&gt;

&lt;p&gt;The team is taking several corrective actions – first, the missing invariant check was restored as &lt;a href="https://github.com/XRPLF/rippled/pull/4968/files#diff-44ad01c5cc043ade1595acea21a321cc97f8a5c89f5d677be425d8826084d620R140"&gt;part&lt;/a&gt; of the fix. Second, the team is also working to add additional invariants for other AMM transactions, and will initiate a workstream to review existing XRPL features and propose additional invariants that would make those features more robust. Going forward, the team will also propose updating the XLS and PR process with an explicit section on invariants, as well as a section to address any numerical sensitivity decisions (which was a proximate issue for this AMM bug).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Composability comes with complexity&lt;/em&gt;. As mentioned above, a major benefit of the XRPL is the way features like the DEX, AMM and payments compose and work together; there aren’t any other protocols that seamlessly integrate these types of features. But this also creates a large set of interactions and edge cases to test. Although the XRPL has a strong track record of performance and stability due to the existing software development and testing processes, there are always ways to improve. The team is finalizing a PR that significantly increases unit test coverage of the AMM feature, with a goal of 100% coverage for any new features added to the Ledger going forward. Leveraging the added invariant checks, the team will also start a workstream to build out context-aware fuzz testing to thoroughly stress the protocol in a controlled manner. We are excited to learn more about community proposals for a Canary Network, and are also iterating on the existing &lt;a href="https://ripple.com/legal/bug-bounty/"&gt;Bug Bounty program&lt;/a&gt; to ensure it has the right visibility and support for extensive testing in the test and dev networks in addition to the main network.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;It takes a village&lt;/em&gt;. A huge thank you to the community members who responsibly disclosed the bug, the projects who quickly responded to limit further deposits into AMMs, the devs who worked around the clock on the fix, validator operators who voted in favor of the amendment fix, and the broader community for the support and patience during this process. These last few weeks should serve as a starting point for a playbook for future incidents, a foundation that the XRPL community can collectively develop and improve.&lt;/p&gt;

&lt;p&gt;A major challenge in responding quickly was the 2 week window for approving amendments. The two week period is meant to give sufficient time for node operators to upgrade to the version of rippled that supports that amendment, for validator operators to review the changes to decide their vote, and also change their vote based on feedback from other operators and the community. For new features, this is an appropriate mechanism for the community to decide the best path forward for the ledger. For urgent bug fixes, 2 weeks is an eternity. The team will work on XLS proposals for alternative ways to deploy fixes, such as fast-track amendments that have an accelerated voting process. We look forward to hearing similar ideas and innovations from the community on ways to respond quickly when necessary.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As we move forward, Ripple will continue to monitor the AMM feature closely alongside the XRPL community to ensure its stability and reliability. As with any new functionality, we encourage the community to test and educate themselves on how it works. Together, we can work towards building a stronger, more resilient XRP Ledger that empowers innovation and drives the future of on-chain finance. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Update on the XRP Ledger AMM Bug and the Path Forward</title>
      <dc:creator>Brad Chase</dc:creator>
      <pubDate>Wed, 27 Mar 2024 16:14:11 +0000</pubDate>
      <link>https://dev.to/ripplexdev/update-on-the-xrp-ledger-amm-bug-and-the-path-forward-hkb</link>
      <guid>https://dev.to/ripplexdev/update-on-the-xrp-ledger-amm-bug-and-the-path-forward-hkb</guid>
      <description>&lt;p&gt;Last Friday, after over two years in the making, XLS-30, the Automated Market Maker (AMM) amendment, went live on XRP Ledger mainnet. The native feature was designed to provide on-chain liquidity and trading capabilities for DeFi developers and users. &lt;/p&gt;

&lt;p&gt;Despite the multiple rounds of rigorous &lt;a href="https://engineering.ripple.com/amm-performance-testing-report/"&gt;testing&lt;/a&gt; and &lt;a href="https://dev.to/ripplexdev/fortifying-trust-certik-completes-security-audit-for-xls-30d-bdb"&gt;audits&lt;/a&gt; leading up to the mainnet launch, on Saturday, &lt;a href="https://twitter.com/_tequ_"&gt;Tequ&lt;/a&gt; and &lt;a href="https://twitter.com/OrchestraFi"&gt;Orchestra Finance&lt;/a&gt;, members of the XRPL community, discovered a bug affecting the AMM functionality. Over the past few days, the bug prompted swift action from developers and the RippleX team to ensure the security and efficiency of the XRPL AMM feature. Following thorough testing, the AMM bug fix was released Tuesday evening, and is now available under the 2.1.1 release of rippled.&lt;/p&gt;

&lt;p&gt;In this update, we want to provide transparency regarding the recent events surrounding the AMM bug, discuss the work done to address it, and outline the path forward. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happened&lt;/strong&gt;&lt;br&gt;
Saturday morning, March 23, Ripple received a report of an inconsistency in an AMM liquidity pool. Alongside community members Orchestra Finance and Tequ, analysis was conducted on the corresponding transactions and an error was identified in how the payment engine interacts with order books and AMM pools. In rare cases, complex payment path scenarios draw an incorrect amount of liquidity from an AMM pool.&lt;/p&gt;

&lt;p&gt;This issue was not related or caused by the single-sided deposit feature, which is an intended functionality of the AMM, as it offers a more streamlined user experience, and could result in price impacts when pools have less liquidity. We acknowledge the concerns raised by some users regarding the challenges associated with single-sided deposits. While the feature is functioning as designed, it’s important to address these concerns. As such, we and others will explore and propose potential future improvements for the community to consider to enhance the overall user experience.&lt;/p&gt;

&lt;p&gt;Given that this AMM bug fix requires an amendment voting process to correct, the issue remains present on the network in the interim period. Although this appears to be a rare occurrence, out of an abundance of caution, it’s best for users to limit their AMM usage until an amendment addressing the bug is passed by the validators. To prevent exploitation, the in-depth details about the issue are being withheld at this time but AMM UIs have been advised to close deposits. However, after the fix has been activated post amendment voting process, more information will be shared.&lt;/p&gt;

&lt;p&gt;It would be remiss not to mention the quick response from many community participants – including Sologenic, Anodos Finance, Orchestra Finance, Dex Finance Pro, XPMarket, and others – in acting quickly to close deposit functionality, as well as many individuals who were vital in spreading the word on the issue and fix. The team will continue to stay in close contact with them as monitoring is still in place. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How the team responded&lt;/strong&gt;&lt;br&gt;
Once the bug was identified, two parallel workstreams kicked off; the first to assess the scope and impact on AMM pools, and the second to reproduce and fix the bug. Regarding scope and impact, the bug has not affected additional pools since the initial report. There is ongoing monitoring in place to detect if the issue were to re-occur.&lt;/p&gt;

&lt;p&gt;The bug was successfully recreated in a unit test environment, facilitating the development of a fix alongside a new invariant check to enforce properties of AMM pools during transaction processing. Since the payment engine rules reside in the protocol layer, implementing the fix necessitates an amendment voting process which is reviewed by UNL validators at minimum of two weeks, requiring over 80% consensus. Extensive internal reviews, performance testing, and quality assurance measures have been conducted on the code changes. The code is viewable on &lt;a href="https://github.com/XRPLF/rippled/pull/4968"&gt;GitHub&lt;/a&gt;, but excludes the unit tests to minimize the risk of retriggering the bug on the network. These tests will be incorporated into a subsequent release once the amendment activates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is next&lt;/strong&gt;&lt;br&gt;
The top priorities these last few days have been to (1) mitigate the impact of the bug on the network for XRPL users, and (2) prepare and thoroughly test a fix – thus intentionally limiting the amount of details shared about the bug to minimize the risk of additional impacts while the fix is being released and voted on by the network. All validators are encouraged to commence the voting process to quickly address this issue. Note that the default vote in the source code has been set to “yes” given the importance of the fix, though as always, the amendment must hold over 80% support for two weeks to activate, so there is time for operators to review and change their support as they see fit.&lt;/p&gt;

&lt;p&gt;Post-activation, more specific details of the bug, the fix, as well as additional follow-on actions will be shared via a root cause analysis of the incident. A key part of this will be addressing how Ripple and the larger XRPL community can work more closely together to build, test, deliver and improve the XRPL for all its users.&lt;/p&gt;

&lt;p&gt;Lastly, a huge thank you to the community members who responsibly disclosed the bug, the projects who quickly responded to limit further deposits into AMMs, the devs who worked around the clock on the fix, and the broader community for the support and patience during this process. It’s been great to see the community involvement in initiating discussions on ways to improve the XRPL and we are on the front lines with you. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
