Moonwell Lost $1.78M After Smart Contract Bug Linked To AI-Generated Code
In Brief
Moonwell’s exploit stemmed from a critical smart‑contract pricing bug—partly introduced through AI‑generated code—that misvalued cbETH and enabled attackers to drain funds, leaving the protocol with roughly $1.78 million in bad debt.
Moonwell, a DeFi lending protocol, suffered a major financial blow in the same week when a critical smart contract bug mispriced the Coinbase Wrapped Staked Ether token (cbETH), allowing assailants and liquidation bots to empty the wallet and amass about $1.78 million of bad debt.
The initial post-mortem analysis shows the logic error was added in code that was co-written by the AI model Claude Opus 4.6, which has again raised concerns about the dangers of going directly to production with AI-written code, without the intensive human scrutiny of its code.
The pricing mistake took place following a governance update that revamped the on-chain oracle of Moonwell, the protocol, converting the off-chain market pricing into information that can be utilized in its lending logic. The system incorrectly calculated the dollar value of cbETH, which is supposed to be calculated by multiplying the exchange rate of both by the current ETH/USD price, and therefore wrongly used only the ratio between the two, which quoted the price of the cbETH at approximately $1.12 instead of the actual price in the market, which was approximately $2,200. Having such a discrepancy led to a 2,000× undervaluation that was immediately used by liquidation bots and opportunistic traders.
The smart contract traders and bots paid back a little in minutes to get a full cbETH collateral of thousands of dollars. Overall, Moonwell has lost a substantial amount of unrecoverable loans in the form of bad debt due to the distorted price of more than 1,096 cbETH that have been liquidated.
The team of Moonwell responded quickly after the problem was identified and reduced by far the number of borrowing and supplying limits of the cbETH markets to avoid additional exploitation. Nevertheless, since the fix takes a five-day period of governance voting and timelock, liquidations kept piling up in the interim. The protocol has since proposed a governance proposal that is intended to deal with the oracle misconfiguration and hardening risk checks.
AI’s Role Under Scrutiny
Although most of the past exploits in the DeFi sector are due to hacked oracle price feeds or flash loans, analysts believe that this was unique because of its link to AI-generated code. GitHub commits that have been co-authored by Claude Opus 4.6, an advanced generative model, have been pointed out by smart contract security auditor Pashov on social media regarding the pull request that added the faulty oracle logic. This has elicited controversy in blockchain and AI circles regarding the role of AI in the development of vital financial infrastructure.
The process of developers basing their writing of production-level code on the AI suggestions or hints is known by industry observers as vibe-coding. The management of a basic pricing calculation, in this instance, of not multiplying an intermediate exchange rate by the proper USD peg, was disastrous in a live money market situation.
Critics emphasize that although AIs are useful in speeding up the time-consuming routine tasks, the code generation in automation is insufficiently versed in the complex knowledge of economic invariants and edge-case logic to be used in DeFi protocols. A simple unit conversion or arithmetic error in the derivation of prices can become a huge systemic risk once used on scale, especially in highly leveraged collateralized lending systems where the solvency of the system heavily depends on the correct price of the market.
The advocates of AI in software development also admit to the productivity gains achieved when using systems such as Claude or other generative models, but note that formal verification systems and human auditors are still essential. These people claim that AI cannot, but should complement, the processes of a careful review of security, particularly in protocols with billions of on-chain liquidity.
Broader Implications for DeFi and AI Development
The defeat of Moonwell has already sparked a debate in the wider DeFi community regarding the tools, audit standards, and governance protections. Although the overall loss of about $1.78 million might be considered comparatively small in terms of historic exploits in the larger protocols, the incident highlights how even small logic errors in price feeds can lead to even greater multi-million-dollar results in the live markets.
According to security experts, oracles are still a common vulnerability point in DeFi. Lending platforms rely on accurate valuation of collateral data. Once this underpinning information is poisoned by external or internal price manipulation, the whole risk model of the protocol may fail. The incident introduces an additional twist by attributing an archetypal cause of error, poor validation of arithmetic and data flows to AI.
Since the exploit, governance forums of Moonwell have been more active, as community members suggested mitigation measures of risk, including a maximum number of wallet borrowings, extra liquidation fee buffers, and on-chain testing before oracle reconfigurations are implemented. According to protocol insiders, recovery plans are under debate to possibly compensate the affected users, but the details are still in discussion.
What This Means for AI in Smart Contract Engineering
The Moonwell accident is one of the warning examples to developers and protocol designers who may want to introduce AI into vital parts of the system. Correctness guarantees of smart contracts are much higher than those of normal application code because the financial integrity of smart contracts is at stake. Although boilerplate templates and developer productivity can be aided by automated code generation, formal verification, human inspection, and rigorous testing against economic adversarial situations is of paramount importance.
With more tools in the AI-assisted category being deployed in Web3 engineering processes, the industry is calling on new audit frameworks, which explicitly address AI provenance, decision logic, and numerical correctness. This involves automated testing software, symbolic execution, and fuzzing methods that may examine the logic of a contract on a very low level before it goes into production.
The governance performance and community reactions of Moonwell in the next several weeks will probably determine the quality at which the wider DeFi industry will treat AI-generated code risk avoidance and potentially develop more stringent guidelines on the incorporation of generative models into production-critical financial programs.
Disclaimer
In line with the Trust Project guidelines, please note that the information provided on this page is not intended to be and should not be interpreted as legal, tax, investment, financial, or any other form of advice. It is important to only invest what you can afford to lose and to seek independent financial advice if you have any doubts. For further information, we suggest referring to the terms and conditions as well as the help and support pages provided by the issuer or advertiser. MetaversePost is committed to accurate, unbiased reporting, but market conditions are subject to change without notice.
About The Author
Alisa, a dedicated journalist at the MPost, specializes in cryptocurrency, zero-knowledge proofs, investments, and the expansive realm of Web3. With a keen eye for emerging trends and technologies, she delivers comprehensive coverage to inform and engage readers in the ever-evolving landscape of digital finance.
More articles
Alisa, a dedicated journalist at the MPost, specializes in cryptocurrency, zero-knowledge proofs, investments, and the expansive realm of Web3. With a keen eye for emerging trends and technologies, she delivers comprehensive coverage to inform and engage readers in the ever-evolving landscape of digital finance.