Section 2 of 18

Build
+10 Lynx

Fixed-Point Math Library

Key takeaway: Compound V2's entire fixed-point arithmetic layer uses a 1e18 mantissa, so values like closeFactor = 0.5 are stored as 0.5e18, and multiplication or division must rescale to preserve precision. The math library implements mulExp, 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

Solution.sol
Solidity
Loading editor...

Requirements

Write your implementation, then click Run Tests. Tests execute on the server.

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 continue

Already have an account? Log in