DeFiMath v3.4.0 — Foundry property-fuzz testing layer added
Two changes:
- Foundry property-based fuzz testing layer — 92 mathematical properties
across all six modules, fuzzed with 32,000 random runs each.
2.94 million random executions per CI run verifying things like
ln(exp(x)) ≈ x, put-call parity,Φ(x) + Φ(−x) = 1, and 89 others. Foundry shrinks counterexamples automatically on failure. EXP_LOWER_BOUNDrefactored fromuint256magnitude to signedint256value (−41.446e18). Letsexp's negative branch comparexdirectly against the bound — 1–3 gas saved across every function that callsexp.
Foundry property-fuzz layer
Hardhat-only testing validates each function at concrete points against external JS references. Foundry adds a complementary layer that validates the algebraic structure across the random input space.
92 properties organized into five categories — round-trips, monotonicity, identities, output bounds, symmetries. Per-module breakdowns on each module's docs page. Full suite completes in ~6 seconds locally and ~30 seconds on a 2-core CI runner.
Both layers run via npm test — Hardhat first (correctness + gas regression),
then Foundry (algebraic structure).
Gas changes
Every function calling exp internally inherits the savings:
| Function | v3.3.0 gas | v3.4.0 gas | Saved |
|---|---|---|---|
| exp | 333 | 331 | −2 |
| expm1 | 439 | 438 | −1 |
| pow | 750 | 748 | −2 |
| gamma | 1,499 | 1,496 | −3 |
| theta | 3,293 | 3,290 | −3 |
| vega | 1,439 | 1,436 | −3 |
| binaryDelta | 1,825 | 1,822 | −3 |
| binaryGamma | 1,967 | 1,964 | −3 |
| binaryTheta | 3,353 | 3,350 | −3 |
| binaryVega | 1,913 | 1,910 | −3 |
Small but uniform. No precision change, no API change.
No behavioural change
Same precision, same return values, same input domain. All 681 tests across Hardhat (589) and Foundry (92) pass — the new Foundry layer is fully additive, not a replacement.
Get it
npm install [email protected]
- Release notes: github.com/MerkleBlue/defimath/releases/tag/v3.4.0
- Package: npmjs.com/package/defimath-lib