← Back to news
v3.3.0Jun 09, 2026

DeFiMath v3.3.0 — stdNormCDF rewrite, call/put 5% cheaper

This is a pure optimization release. No new features, no API changes — same precision, same behaviour, just fewer opcodes in stdNormCDF. Every option pricer and greek built on it gets the savings automatically.

Where the savings come from

The previous stdNormCDF scaled its argument by 1/√2 and then called an internal erfPositiveHalf helper that multiplied right back by √2 — two unnecessary MUL+DIV pairs in every call. Inlining the body into stdNormCDF and dropping the helper (which had no other callers) eliminated the round-trip and lets each branch write straight to the result. Net: 74 gas per stdNormCDF call.

That single change propagates everywhere stdNormCDF is used inside the library.

The numbers

Biggest absolute wins are on the option pricers themselves — callOptionPrice and putOptionPrice each call stdNormCDF twice (one for Φ(d₁), one for Φ(d₂)):

Function v3.2.0 gas v3.3.0 gas Saved %
callOptionPrice2,8762,729−147−5.1%
putOptionPrice2,8872,739−148−5.1%
delta1,7971,724−73−4.1%
theta3,4413,293−148−4.3%
binaryCallPrice2,0922,018−74−3.5%
binaryPutPrice2,0972,023−74−3.5%
binaryTheta3,5013,353−148−4.2%
impliedVolatility (call)13,10012,370−730−5.6%
impliedVolatility (put)13,18412,446−738−5.6%
stdNormCDF734660−74−10.1%

gamma, vega, binaryDelta, binaryGamma, binaryVega are unchanged — they're built on the standard normal PDF, not the CDF, so this optimization doesn't reach them.

impliedVolatility shows the largest absolute drop because it calls stdNormCDF inside every Newton-Raphson iteration — roughly 10 iterations to converge, each saving ~74 gas.

No behavioural change

Same input domain, same return values to the last wei. The 396 tests across Math, Options, and Binary all pass at the same precision thresholds. The strict equality assertions in the perf suite caught the change automatically and forced the threshold updates — that's exactly what they're for.

Get it

npm install [email protected]