DeFiMath - Gas-optimized Solidity math for on-chain finance
DeFiMath is an open-source Solidity library that brings fast, cheap, and accurate mathematics to smart contracts. It provides the cheapest transcendental and fixed-point math primitives on the EVM, purpose-built for DeFi protocols that need real numerical power without burning gas.
The library spans 40+ functions across four modules: core math (exp, ln, sqrt, cbrt, and more), derivatives pricing, interest-rate math, and statistics. Every function uses fixed-point 18-decimal arithmetic and is fuzz-tested against high-precision reference implementations, so you get tight error bounds you can actually rely on in production.
Performance is the whole point. DeFiMath prices a Black-Scholes call option in just 2,729 gas — a fraction of the cost of conventional implementations. That efficiency comes from low-level optimizations like CLZ-based seeding and carefully minimized intermediate computation, making previously impractical on-chain models viable.
Built by MerkleBlue out of real options-AMM engineering, DeFiMath is designed for Solidity developers, smart contract auditors, and DeFi protocol builders who need options pricing, Greeks, implied volatility, and statistical functions directly in their contracts.
Open source, MIT. 👌👌