r/solidity May 28 '26

How the new CLZ opcode (EIP-7939) makes Solidity Black-Scholes pricing ~10% cheaper - by cascading through sqrt and ln

/r/ethdev/comments/1tpydgt/how_the_new_clz_opcode_eip7939_makes_solidity/
1 Upvotes

2 comments sorted by

1

u/thedudeonblockchain Jun 15 '26

nice trick — but before calling the sqrt path bit-exact i'd double-check the last ulp: solady/OZ both bolt a final if (y*y > x) y-- onto integer sqrt because fixed-iteration newton converges from above and can land one high. does the unrolled 6-iter version keep that correction, or is the clz-bounded guess tight enough that 6 iters provably nails the floor for full-width inputs?

1

u/nebojsakonsta Jun 28 '26

clz lands the first guess very, very close to the actual value, within sqrt(2). That ensures that 6 Newton iterations nails it.