Protocol

Formally Verifying Morpho Midnight with Certora

Merlin Egalitéby Merlin Egalité/
Formally Verifying Morpho Midnight with Certora

TL;DR: For protocols built on immutable contracts and designed to handle billions, if not trillions, of dollars in deposits, a small error in the code can put everything at risk. As AI systems become increasingly capable of exploiting edge cases, rigorous security assurance becomes even more important. That is the goal of Morpho Midnight's formal verification work with Certora.

Why Formal Verification matters in the Age of AI

Smart contract exploits are now the most common kind of crypto hack. There were 207 hacks in the first half of 2026 by TRM Labs, and 125 of them exploited smart contracts. We expect increasingly automated scrutiny of protocol code: research from Anthropic shows that AI agents can identify smart contract vulnerabilities and produce working exploits.

As AI systems become increasingly capable of exploiting edge cases, rigorous security practices become even more important. Audits and unit tests remain important, but they are limited by scope and can miss edge cases due to the large number of paths to audit. Formal verification mathematically proves that specified properties hold true for every possible input and sequence of transactions the model covers, not just the cases audited.

An integral part of code design

Morpho Midnight is a fixed-rate, fixed-term credit protocol designed to bring all types of credit use cases onchain. It launched in July 2026.

For Morpho Midnight, formal verification was an integral part of the smart contract code design from the very first line of code written. Formal verification was employed throughout code design and development, serving three key functions:

  • Refining the specifications: formal verification challenges the code's design properties, making them simpler, better, and more thoroughly documented.
  • Iterating on the code: understand the impact of a change in the code design early, and gain confidence in the changes made throughout.
  • Finding bugs: because of the above two, avoid introducing bugs into the code, formal verification then serves as another security check for stronger security guarantees.

The net effect is that Midnight is secure by design, and have been repeated formally verified from the first to the last line of code written. This is the same practice employed for Morpho Blue, which has been running flawlessly since 2024, with more than $17 billion in deposits as of this writing.

Verified with Certora from the start

Since the very beginning designing Midnight, Certora engineers worked alongside Morpho's protocol team to run continuous formal verification, with Morpho engineers retaining ownership of the specifications.

The verification effort covers five areas of Midnight's behavior:

  • Accounting: credit, debt and collateral stay consistent, and can only be modified as expected by the relevant parties. Token are transferred from and to the appropriate parties.
  • Maturity and solvency: checks cover liquidation eligibility, bounded and sane incentives and bad-debt accounting.
  • Offers, fees and rounding: offers and fees respect their limits, while split settlements preserve accounting and stay within specified rounding allowances.
  • Permissions: sensitive changes follow authorization rules, privileged roles stay within their remit.
  • Implementation: checks cover arithmetic and price conversions, and verify that external calls cannot observe an inconsistent intermediate state.

Secure by Design

Morpho's core smart contracts, including Morpho Blue and Morpho Midnight, are immutable: once deployed, their core code cannot be changed.

That makes verifying their core properties before launch especially critical.

Once verified and deployed, the formally verified immutable code gives users and integrators greater confidence in the infrastructure they rely on.

Explore Midnight’s formal verified properties.

Midnight has now been trusted with more than $200 million in deposits.

Discover more with us

Morpho on XMorpho on LinkedInMorpho on Youtube