Section 2 of 18
Fixed-Point Math Library
Key takeaway: Compound V2's entire fixed-point arithmetic layer uses a 1e18 mantissa, so values like
closeFactor = 0.5are stored as0.5e18, and multiplication or division must rescale to preserve precision. The math library implementsmulExp,divExp, and rounding helpers that protect against the 18-decimal-place errors that surface across Compound V2 forks (notably Canto v2's H-03 oracle mantissa bug). Get the rounding direction wrong on liquidation seizure math and the protocol pays out more collateral than it should.
What You Are Building
Every interest rate and exchange rate calculation in Compound V2 uses fixed-point arithmetic. Solidity has no floating-point numbers. You cannot write 0.05 or 1.5. The ExponentialNoError contract solves this by representing all fractional values as integers scaled by 1e18. A "mantissa" of 1e18 means 1.0. A mantissa of 5e17 means 0.5. A mantissa of 1.05e18 means 1.05.
This is the first contract you build because every other contract in the protocol inherits from it. Get this wrong and every calculation downstream is broken.
Your Code
Requirements
Sign up free — keep reading + earn 10 Lynx
Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.
Sign up free to continueAlready have an account? Log in