Black box function

I want to see a black box function similar to Rust's std::hint::black_box (might be misremembering the name) that prevents optimization of its value, maybe something like Function.blackBox(v). This must come a hard requirement that its argument(s) must be treated as if they are directly reachable by the global object for some unspecified non-zero duration in the function's execution, impacting both garbage collection and JIT optimization.

There's two primary applications for this:

  • Cryptography, which needs that assertion for secure equality
  • Benchmarking, which normally uses eval to prevent its test block from being optimized away.

I'm not sure I understand the JIT aspect. How is any of that observable?

For the GC aspect, it sounds like what you're looking for is a licenses barrier. That has been discussed in Liveness barriers and finalization

Maybe for the optimization aspect, a hint like recently presented would work? Of course opposite asking to not optimize.

You cannot write time-channel-secure cryptography in JS without substantially more guarantees from the engine than just this. I wouldn't want to add a feature which implies that it can be used to safely write cryptography code unless you could actually safely write cryptography code.

1 Like

That could work.