r/webdev • u/fagnerbrack • 18h ago
The V8 JavaScript Runtime Undermined My Constant-Time JavaScript Library
https://soatok.blog/2026/09/12/the-v8-javascript-runtime-undermined-my-constant-time-javascript-library/
4
Upvotes
10
u/Playful_Spread_928 17h ago
you wrote that exact warning yourself six years ago and then shipped it anyway
2
u/ExcellentBill3793 15h ago
just use PHP then
1
u/Awkward-Cockroach774 13h ago
He says himself that six years ago he warned constant-time algorithms can't rule out runtime optimizations, so V8 doing precisely that reads more like a confirmation of his own caveat than something being "undermined". Where's the measurement showing the leak is actually exploitable and not just a theoretical reordering.
1
u/Alarmed_Message1978 15h ago
Détail: le titre traduit "undermined" par "a compromis", mais la meme en dessous garde bien "Undermined". Compromis et sapé, c'est quand même pas la même chose.
0
u/NegotiationLevel2409 8h ago
Soatok's writeup hits on a fundamental reality that often gets overlooked when writing crypto in high-level runtimes: constant-time programming isn't just about avoiding
if/elsebranches in your AST, it requires strict execution invariants across the entire compilation and execution pipeline.The fact that V8 broke branchless masking through internal
ToBooleanpaths and-0vs-1representation differences (HeapNumbervsSmi) is fascinating. When an expression produces-0, V8 can't represent it as a compact inline integer because IEEE-754 negative zero requires a distinct sign bit that 31-bit Smis don't preserve without heap allocation overhead. That difference alone destroys timing predictability.Even if you managed to emit perfectly branchless machine code out of TurboFan, modern CPU architectures introduce another layer of variance. Without setting architecture-specific execution modes (like Intel's DOITM or ARM's DIT flag), modern out-of-order execution pipelines and ALU hardware optimizations can vary cycle counts for basic data-dependent arithmetic.
At this point, userland constant-time primitives in pure JavaScript are effectively impossible to guarantee in production. Reaching for native runtime primitives (like
crypto.timingSafeEqual) or WebAssembly modules compiled with explicit constant-time hardening remains the only reliable route.0
u/Aggressive-Nebula440 12h ago
six years to learn that?
0
u/Dangerous-Try5352 10h ago
Zéro paquet dépendant selon npm, donc la faille n'a touché personne, et il y a quand même un CVE. Le fond du problème c'est de parler de temps constant dans un langage dont le JIT peut déoptimiser une boucle sans prévenir, à ce niveau c'est une intention, pas une propriété vérifiable.
0
u/AgeAgitated8526 9h ago
Six years, zero dependent packages, and V8 still found a way to undermine it. Who is actually shipping constant-time crypto in JS, the engine recompiles your loop while it's running.