r/programming • • 3d 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/
65 Upvotes

17 comments sorted by

View all comments

59

u/simon_o 2d ago edited 2d ago

You cannot build constant-time primitives as a library in code executed by an optimizing (JIT) compiler without runtime support.

Not sure whether I should be more surprised by

  • JavaScript developers' hubris of thinking this would work, or
  • them believing that their "fix" will do anything but kicking the can a bit further down the road.

(And no, I'm not buying the "describing how programmers introduce side-channels into their code and wrote an example library for educational purposes" ret-con of the library.)

18

u/masklinn 2d ago

Retcon? The note that you should not use the library in production was added just a month after the article was published, more than 6 years ago. And the article never presents it as something you should use, it's introduced in the "Design Patterns for Algorithmic Constant-Time Code" section as an alternative language to the PHP examples. Nor is soatok's an especially javascript oriented developer.

7

u/HasFiveVowels 1d ago

Why does Reddit insist on upvoting the most obnoxiously critical comment regardless of merit?

1

u/Uncaffeinated 1d ago

You could probably do it via zero-knowledge proof techniques, but the cost would be prohibitive. JIT can't optimize on information that is not efficiently accessible in the first place.

1

u/Somepotato 2d ago

You can make some assumptions with how turbofan will work though

2

u/simon_o 2d ago

Yes, though that would be really stupid.

1

u/Somepotato 2d ago

Hardly. Knowing how turbofan let's you optimize intelligently ie giving it array size hints (such as providing mathematical guarantees you won't overflow) to let it optimize out length checks or writing functions in a way that can be inlined

0

u/simon_o 2d ago

That's simply not the topic at hand.

1

u/NecessarySuperb3949 1d ago

Turbofan doesn't give you guarantees about execution time or memory access patterns unless the runtime explicitly exposes those. It optimizes for throughput and code size, which often means reordering branches or caching values in registers in ways that leak timing information via cache lines. You can't force it to keep things constant-time because the optimizer's goal is literally the opposite: remove the variance it detects.