How Lean verification and agents 10x our ability to deliver provably correct data
Financial decision-making across blockchains is predicated on accurate data, but how do you know the data you’re using is truly accurate? Guaranteed accuracy of blockchain data requires perfect collection of the raw data (blocks), perfect transformation of the raw data (e.g., computing historic trade volume, which isn't available onchain), and proof that the result isn’t corrupted before it reaches you. Recent advances combining agentic development and Lean offer a new path to guarantee the transformation step is perfect. We’re proud to announce Cambrian’s Proof Engine, a patent-pending technique for proving the correctness of our blockchain data transformation system.
In this article, we describe how we prove that our blockchain data API calculations follow the rules of the smart contracts they are derived from. To our knowledge, we are the first to formally verify a blockchain indexing product: from contract bytecode through event logs to the SQL that serves each number.¹ We expect that formal verification of blockchain indexing software will become standard practice.

Cambrian’s Proof Engine helps us generate verified endpoints

It's common knowledge that to get agents to write good software, they need a solid specification. That holds true for using Lean as well. Writing a Lean-compatible spec is the first step in proving that one of our API endpoint calculations is correct. The spec describes what each API endpoint's return metrics should mean. Next, our Proof Engine combines AI agents, Lean, and automated checks in four steps:
1. Identify the contract running onchain. Automated checks compare the compiled bytecode of a specific smart contract version with the code deployed onchain. This establishes which version of the contract we are analyzing.
2. Describe the contract’s rules in Lean. An agent writes a Lean model of the relevant contract behavior. For example, how deposits, borrowing, and withdrawals change balances, and when those actions fail. The agent then writes proofs that the model agrees with the deployed code. Lean checks those proofs.
3. Prove the calculations, then generate SQL. An agent writes Lean calculations for the metrics defined in our spec, such as utilization or the dollar value of supplied assets. The agent then writes proofs that these calculations match the meaning in the spec. Lean checks those proofs. A code generator translates the calculations into SQL.
4. Check the SQL and the API responses. Automated checks examine how the database interprets the SQL and compare its results with the Lean calculations on the same inputs. When values disagree, AI agents help investigate the cause and propose corrections.
For each API endpoint it checks, our Proof Engine records what has been mathematically proved, what has been tested, and which assumptions or gaps remain.
Case study: Formal verification of one of our API endpoints

Cambrian’s API provides comprehensive coverage for lending protocols measured directly from smart contract activity. For example, our Morpho Markets endpoint provides loan and collateral token pairs, total supplied and borrowed amounts, utilization, annualized yield estimates, and liquidation thresholds.
We have used our Proof Engine to verify every return metric from the Morpho Markets endpoint. Accuracy matters for anyone making financial decisions based on these numbers. If a value we serve ever differs from the contract, our Proof Engine will identify the market, the return metric, and the cause.
Morpho Blue supports a fee set per market by the contract owner. When enabled, it allocates part of the accrued interest to a fee recipient, reducing the portion given to existing suppliers. Our Morpho Markets API endpoint reports current market yield as supplyApy. Our original SQL for the supply APY omitted tracking of that fee. In our supplyApy data, this made no difference, because the fee has always been 0%. Our data was correct, and a traditional audit against the chain’s history would pass.
However, if the fee were enabled, our APY-tracking logic would have been wrong and would have misreported data. We discovered this potential error using our Proof Engine. When it compared our original SQL query with the Lean model, it detected and then corrected the missing fee calculation.
Conclusion
The Morpho Blue example shows why spot-checking historical indexer results only gives surface-level confidence. By formally verifying our SQL against smart contracts, we can now uncover gaps before they affect our data or customers.
AI makes this work easier to scale. Our team still decides what each API metric means and reviews the assumptions behind it. Agents can then write models and proofs against those specs. As more of this process becomes automated, expanding coverage will increasingly benefit from compute, while our human expertise stays focused on specifying what our product should do. In traditional finance, you have to trust a data vendor. Smart contract code is usually publicly accessible and can be verified against the onchain bytecode. This is a clear advantage over traditional finance, but today it is hard to know whether an onchain data provider has applied all the correct transformations. We believe proving the transformations that underlie the aggregation and analysis of onchain data for financial decision-making will soon be expected by consumers, and required by institutions that operate onchain. We think this will give onchain agentic finance one more advantage over closed financial systems.
We are in the process of formally verifying all the EVM endpoints we offer, with a clear record of what is proved, what is tested, and what remains unchecked. We also have a path toward Solana verification. If you need blockchain data whose calculations you can inspect and verify, reach out to me on X, or hit the “Schedule call” button at the top of this page.
¹ Our work builds on concepts introduced by EquiVM, which proves that deployed EVM bytecode behaves exactly as a high-level specification, and on EVMYulLean, Nethermind’s formal model of the EVM in Lean. We extend these proving methods from the bytecode to the contract’s event logs and to the SQL that computes each served value.
