-
Notifications
You must be signed in to change notification settings - Fork 267
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
Adds sys.Walltime and sys.Nanotime for security and determinism #616
Conversation
This adds two clock interfaces: `MonotonicClock` and `WallClock` to allow implementations to override readings for purposes of security or determinism. Once the interface is accepted, These will be added to `ModuleConfig` allowing consistent implementation of WASI, WASI 2, and wasm_exec clock imports. See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-clock_time_getid-clockid-precision-timestamp---errno-timestamp See https://github.com/WebAssembly/wasi-clocks See https://github.com/golang/go/blob/252324e879e32f948d885f787decf8af06f82be9/misc/wasm/wasm_exec.js#L243-L255 Signed-off-by: Adrian Cole <adrian@tetrate.io>
cc @pkedy @sam-at-luther. I'll implement both of these with |
PS one thing I had considered is just a Ex. @mathetake @anuraaga wdyt? |
@sam-at-luther @knqyf263 can you check the PR description to see if the design seems good for you? I noticed we broke sandbox so might as well fix that while allowing determinism in system clocks. Don't look too hard at the code yet as I have tests to backfill and editing to do. |
TODO:
|
Looks good! |
Signed-off-by: Adrian Cole <adrian@tetrate.io>
ok I added x/sys benchmarks (which underperform) and switched the default monotonic clock to use runtime.nanotime as it is routinely used to avoid performance overhead of time.Since(). Plus, it returns the actual nanotime ;) next step is to backfill tests and add godoc about overriding the clock. I don't think overriding the clock needs its own example file. |
While CI nodes are not the best examples of measuring perf. here's the results from that last commit on options to implement clock. While x/sys is a lot faster on my laptop, it is always worse. What is interesting that the speed of time.Since and runtime.nanotime are almost exactly the same in CI vs laptop 🤷
|
Signed-off-by: Adrian Cole <adrian@tetrate.io>
ok done with all the backfilling, docs and polishing |
This adds two clock interfaces:
sys.Walltime
andsys.Nanotime
toallow implementations to override readings for purposes of security or
determinism.
The default values of both are a fake timestamp, to avoid the sandbox
break we formerly had by returning the real time. This is similar to how
we don't inherit OS Env values.
To use real clocks, users can do the following:
They can also provide their own deterministic or higher performing clock like so:
This change allowing consistent implementation of WASI, WASI 2, and wasm_exec clock imports.
See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-clock_time_getid-clockid-precision-timestamp---errno-timestamp
See https://github.com/WebAssembly/wasi-clocks
See https://github.com/golang/go/blob/252324e879e32f948d885f787decf8af06f82be9/misc/wasm/wasm_exec.js#L243-L255