Miri is an interpreter for Rust's mid-level intermediate representation that detects undefined behavior in unsafe code.
Miri addresses the challenge of finding memory safety violations and undefined behavior in Rust programs by executing binaries and test suites while monitoring for violations of safety requirements. It detects out-of-bounds memory accesses, use-after-free errors, uninitialized data usage, violations of intrinsic preconditions, misaligned memory accesses, invalid type invariants, data races, and memory leaks. The tool also supports experimental aliasing rule checking through Stacked Borrows and Tree Borrows implementations. By default, Miri isolates programs from the host system to ensure deterministic execution, replacing system APIs like entropy gathering and clock access with fake implementations, though this isolation can be disabled when needed.
Miri suits developers working with unsafe Rust code who need to validate correctness of low-level operations. It is particularly valuable for libraries that manipulate memory directly or handle byte-level data, and for cross-platform work where you need to verify behavior across different architectures like little-endian and big-endian systems. The tool should not be relied upon as a complete specification checker, as Miri uses its own approximation of undefined behavior rather than a formal Rust specification, and it does not catch every possible violation. Users should consult the Rust Reference for the official definition of undefined behavior. The tool is not suitable for cryptographic key generation due to its deterministic fake random number implementations.
The project maintains active engagement with real-world bug discovery, documenting cases where Miri has found actual bugs in production code. Development activity shows consistent attention to expanding detection capabilities, with ongoing work on aliasing rule implementations and refinement of undefined behavior detection. The tool is kept synchronized with compiler changes to protect against undefined behavior as understood by current Rust versions, though it makes no guarantees about future compiler versions.