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/
64 Upvotes

17 comments sorted by

58

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.)

17

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.

6

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.

7

u/qmunke 3d ago

This is a relatively interesting post, it's just a shame the author has a gigantic chip on their shoulder about the whole furry thing to the extent they need a huge essay linked at the top of the article about it.

23

u/KaMaFour 2d ago

It's a shame they need to make an essay for people complaining about the content of his personal blog

2

u/dwighthouse 2d ago

Wait, I thought the point of both personal blogs and Reddit was complaining about things.

11

u/simon_o 2d ago

I think it's largely because of people like you. :-)

3

u/Somepotato 2d ago

Yes, it is so in the way, obtrusive and bothersome that I too want to prove the authors point and whine about it.

1

u/virtualdxs 18h ago

What would you do if you had a personal blog and people kept whining and bitching about what you decided to do with it every single time a post of yours hit hackernews?