MCPcopy Index your code
hub / github.com/endorlabs/MIRAI

github.com/endorlabs/MIRAI @v1.1.12

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.12 ↗ · + Follow
2,276 symbols 5,703 edges 285 files 129 documented · 6%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

MIRAI codecov deps.rs

MIRAI is an abstract interpreter for the Rust compiler's mid-level intermediate representation (MIR). It is intended to become a widely used static analysis tool for Rust.

Who should use MIRAI

MIRAI can be used as a linter that finds panics that may be unintentional or are not the best way to terminate a program. This use case generally requires no annotations and is best realized by integrating MIRAI into a CI pipeline.

MIRAI can also be used to verify correctness properties. Such properties need to be encoded into annotations of the source program.

A related use is to better document an API via explicit precondition annotations and then use MIRAI to check that the annotations match the code.

Finally, MIRAI can be used to look for security bugs via taint analysis (information leaks, code injection bugs, etc.) and constant time analysis (information leaks via side channels). Unintentional (or ill-considered) panics can also become security problems (denial of service, undefined behavior).

How to use MIRAI

You'll need to install MIRAI as described here.

Then use cargo mirai to run MIRAI over your current package. This works much like cargo check but uses MIRAI rather than rustc to analyze the targets of your current package.

cargo mirai does a top-down full-program path sensitive analysis of the entry points of your package. To analyze test functions instead, use cargo mirai --tests.

This will likely produce some warnings. Some of these will be real issues (true positives) that you'll fix by changing the offending code. Other warnings will be due to limitations of MIRAI and you can silence them by adding annotations declared in this crate.

Once MIRAI gives your code a clean bill of health, your code will be better documented and more readable. Perhaps you'll also have found and fixed a few bugs.

You can use the environment variable MIRAI_FLAGS to get cargo to provide command line options to MIRAI. The value is a string which can contain any of the following flags:

  • --diag=default|verify|library|paranoid: configures level of diagnostics. With default MIRAI will not report errors which are potential 'false positives'. With verify it will point out functions that may contain such errors. With library it will require explicit preconditions. With paranoid it will flag any issue that may be an error.
  • --single_func <name>: the name of a specific function you want to analyze.
  • --body_analysis_timeout <seconds>: the maximum number of seconds to spend analyzing a function body.
  • --call_graph_config <path_to_config>: path to configuration file for call graph generator (see Call Graph Generator documentation). No call graph will be generated if this is not specified.
  • --print_function_names: just print the source location and fully qualified function signature of every function.
  • --: any arguments after this marker are passed on to rustc.

You can get some insight into the inner workings of MIRAI by setting the verbosity level of log output to one of warn, info, debug, or trace, via the environment variable MIRAI_LOG.

Developing MIRAI

See the developer guide for instructions on how to build, run and debug MIRAI.

Full documentation

Join the MIRAI community

See the CONTRIBUTING file for how to help out.

License

MIRAI is MIT licensed, as found in the LICENSE file.

Extension points exported contracts — how you extend this code

SmtSolver (Interface)
The functionality that a solver must expose in order for MIRAI to use it. [2 implementers]
checker/src/smt_solver.rs
Ord (Interface)
(no doc) [4 implementers]
standard_contracts/src/foreign_contracts.rs
Adder (Interface)
Without using contracts crate directly, this is what #[contract_trait] will generate. [1 implementers]
checker/tests/run-pass/trait_contracts.rs
ProcessWithoutTaint (Interface)
(no doc) [1 implementers]
examples/tag_analysis/trait_methods/src/lib.rs
AbstractValueTrait (Interface)
(no doc) [1 implementers]
checker/src/abstract_value.rs
PartialOrd (Interface)
(no doc) [4 implementers]
standard_contracts/src/foreign_contracts.rs
Tr (Interface)
(no doc) [2 implementers]
checker/tests/call_graph/trait.rs
PathRoot (Interface)
(no doc) [1 implementers]
checker/src/path.rs

Core symbols most depended-on inside this repo

new
called by 530
standard_contracts/src/foreign_contracts.rs
eq
called by 206
checker/src/abstract_value.rs
from
called by 145
standard_contracts/src/foreign_contracts.rs
type_visitor
called by 111
checker/src/block_visitor.rs
update_value_at
called by 93
checker/src/body_visitor.rs
infer_type
called by 88
checker/src/expression.rs
get
called by 70
checker/src/known_names.rs
is_compile_time_constant
called by 59
checker/src/abstract_value.rs

Shape

Function 1,158
Method 844
Class 206
Enum 39
Interface 29

Languages

Rust100%

Modules by API surface

standard_contracts/src/foreign_contracts.rs241 symbols
checker/src/abstract_value.rs112 symbols
checker/src/block_visitor.rs83 symbols
checker/src/call_graph.rs78 symbols
checker/src/z3_solver.rs71 symbols
checker/src/constant_domain.rs63 symbols
checker/src/call_visitor.rs63 symbols
checker/src/path.rs57 symbols
checker/tests/run-pass/unsigned_interval_overflows.rs51 symbols
checker/tests/run-pass/signed_interval_overflows.rs51 symbols
checker/src/body_visitor.rs49 symbols
checker/src/type_visitor.rs43 symbols

For agents

$ claude mcp add MIRAI \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact