How is deterministic execution of WebAssembly ensured?

Hi there. I am an engineer at DFINITY and want to share an answer to one of frequently asked questions: “How do we ensure that the WebAssembly code in canisters runs deterministically?”

The sources of nondeterminism in WebAssembly are known and listed here:

We disable features that may lead to nondeterminism. Specifically:

  • Threads are disabled.
  • SIMD instructions are disabled. In the future we may enable deterministic parts of SIMD.
  • Floating-point NaN values are canonicalized.
7 Likes

We were discussing Testing floats and it seemed like this topic might fit with this thread. Are floats deterministic in motoko? Can we test them for exactness? Or should we be using ranges?

The semantics of floats is fully determined by the Wasm standard, with the exception of the bit-wise representation of NaNs, and to address this, the replica instruments your wasm code before execution to normalize the NaNs, so go ahead using them :slight_smile: