Secure Data Research, LLCSDR

blockulator

blockulator keeps 38 digits of fixed point and 71 of float on chain.

blockulator.com is home to two math libraries for Ethereum, each in one 256-bit word: BL127, 38 digits of fixed point, and BL19, 71 digits of float. Every operation is correctly rounded, checked on chain, and competitive on gas. Across the 326 live Aave and Morpho markets we surveyed, the deployed interest accrual keeps a median 7.2 correct digits of the pending interest. BL127 keeps 30 and BL19 keeps 67.

See the results at blockulator.com →

What it is

BL127 is signed 127.128 fixed point: 38 digits against the 18 of the usual libraries, at about the same gas. BL19 is a 256-bit binary float: 71 digits against ABDKMathQuad's 34, across a range of ten to the plus or minus 78,913. Each is one Yul source that generates both a deployed contract on Ethereum's Sepolia test network, where every call is free, and an inlinable Solidity library, fuzzed to agree bit for bit. A third library, BlockulatorWad, keeps Solady's function names and returned the exact answer on all 108,000 results we tested. All three are MIT licensed.

Why we built it

The dominant Ethereum math libraries drop precision in dangerous ways: they stop at the multiplication ceiling of a 128-bit number and leave the rest of the word empty. We built BL127 for our own contracts, where errors compound, and used ABDK, Solady, and PRBMath as the benchmarks to beat, operation by operation, on precision. We kept going until the whole word was full of correct information. The first version was pure Huff and was presented at EthCC[9] in Cannes. BL19 came next, for the numbers too large or too small for fixed point.

Two things BL127 computes

A value is a signed 256-bit integer \(m\) read as a fixed-point number with 128 fractional bits:

$$ x = \frac{m}{2^{128}}, \qquad |x| < 2^{127} \approx 1.7 \times 10^{38} $$

Among its operations are both real branches of the Lambert W function, and pi itself by Ramanujan's 1914 series. The principal branch is the solution \(W_0(x)\) of

$$ W_0(x)\, e^{\,W_0(x)} = x, \qquad x \ge -\tfrac{1}{e}, \quad W_0(x) \ge -1, $$

and the secondary branch \(W_{-1}(x)\) is the other real solution of the same equation,

$$ W_{-1}(x)\, e^{\,W_{-1}(x)} = x, \qquad -\tfrac{1}{e} \le x < 0, \quad W_{-1}(x) \le -1. $$

Solady ships a principal-branch Lambert W too, and it was the benchmark to beat. BL127 computes both branches. The function appears wherever a quantity is defined through its own exponential: delay equations, bonding curves, and the closed forms of some option and queueing problems.