Optimized
DeFi & Math
Primitives

Introducing DeFiMath
The math layer for on-chain finance
Pricing options on-chain used to mean off-chain oracles or hand-rolled approximations. DeFiMath gives you 40+ Solidity primitives - Black-Scholes, Greeks, implied vol, rates, statistics - at gas costs lower than a single storage read, with precision under 1e-12.
2,729 gas - full Black-Scholes option pricing (call or put)
< 1e-12 error - verified against off-chain reference implementations
40+ primitives - Black-Scholes, binaries, Greeks, IV solver, futures, rates, statistics. See the full list →
0 dependencies - pure Solidity ^0.8.31, MIT licensed
100% test coverage - + 92 property-based fuzz tests, 2.94M random executions per CI run. See testing methodology →

FAQ
Common questions
Is DeFiMath right for me?
Which Solidity version and EVM target does it require?
^0.8.31 and evmVersion: "osaka". The 0.8.31 floor is the first version to expose the clz Yul builtin (EIP-7939), which powers sqrt, cbrt, and ln. Add both to your hardhat.config.js / foundry.toml.What use cases does this unlock?
What's the license?
How does it compare to PRBMath, ABDK, Solady?
callOptionPrice 2,729 vs Derivexyz 13,360 (~4.9× cheaper); sqrt 245 vs Solady 341; ln 375 vs Solady 518, PRBMath 6,901. Precision matches Solady within 1 ulp on the shared functions. Full reproducible benchmarks at defimath-compare.Will it work on Ethereum L2s?
CLZ opcode availability). See supported chains for the live list.Is the precision good enough for production?
1e-12 on all math primitives, below 1e-10 on Black-Scholes option pricing. Every function is validated continuously against simple-statistics, black-scholes, greeks, and math-erf reference libraries. 100% test branch coverage.How do I install it?
npm install defimath-lib, then import the module you need:import "defimath-lib/contracts/derivatives/Options.sol";See getting started →Custom Development
We can help you with your next Solidity Project
Contact us today to discuss your project and find out how we can help you bring your vision to life.
Development & Optimization | |
Testing & Audits | |
Web3 Integrations |
