Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: can I use isolated-vm to have deterministic execution? #511

Open
dzmitry-lahoda opened this issue Dec 2, 2024 · 2 comments
Open

Comments

@dzmitry-lahoda
Copy link

Formal definition of deterministic is https://en.wikipedia.org/wiki/Deterministic_algorithm .

Examples are,

https://github.com/facebookexperimental/hermit allows to execute native code deterministically on linux by isolating thread scheduling non determinism

Blockchains(like Ethereum) or accounting software (Cobol) do not allow code to call local clocks, randoms, or any other sources of non determinism.

Nix builds allow access only to predefined directory with fully replaced environment variables and consume only content addressable binaries.

So question, is about
Can isolated-vm make execution of JS deterministic isolating it from non determinism of local clocks, randoms, GC thread scheduling, random based sorting, any file system access?

@laverdet
Copy link
Owner

laverdet commented Dec 4, 2024

I'm familiar with the concept.

Asking about filesystems is a weird, since JavaScript does not specify access to a filesystem. This is something provided by the DOM or other APIs. I'm not sure what you mean by "random based sorting" either.

Anyway the short answer is: no, it is not a formal goal of the project because this is not a goal of the underlying runtime, v8, or even the language of JavaScript. In recent years there has been some work to fix previously implementation-defined sections of the specification-- for-in order and Array.prototype.sort stability. Off the top of the my there exists others like trigonometric functions, stack overflow height, and of course FinalizationRegistry.

I am working on a from-scratch rewrite which will have some features that would take it a bit closer. Specifically you can choose a deterministic monotonically increasing clock, and choose a random seed:

export interface Deterministic {
. If you go a step further and disable certain JavaScript features you could achieve some form of determinism on a given machine. The results may not match across platforms and architectures though.

@dzmitry-lahoda
Copy link
Author

dzmitry-lahoda commented Dec 4, 2024

Asking about filesystems is a weird, since JavaScript does not specify access to a filesystem.

Many JS/TS hosts provide IO/workers access, so it is more like how easy to disable/limit that oven-sh/bun#725

random based sorting

yes, this `for-in order and Array.prototype.sort stability.

Really good answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants