|
| 1 | +# RAPx |
| 2 | +RAPx is a static analysis platform for Rust programs. It can serve as a companion to the Rust compiler in detecting semantic bugs related to unsafe code. |
| 3 | + |
| 4 | +Using abstract interpretation, RAPx checks for undefined behavior (UB) by pre-tagging unsafe APIs. When a caller calls such a pre-tagged API, RAPx examines all program paths to verify whether the program state meets the tag's conditions—ensuring the caller remains sound under any input and does not trigger UB. Currently, RAPx can detect various types of UB, such as misaligned or dangling pointers, out-of-bounds memory access, and uninitialized memory usage. |
| 5 | + |
| 6 | +## Safety Property Verification |
| 7 | +This section will briefly describe several key steps of UB validation by RAPx. |
| 8 | + |
| 9 | +RAPx has a specialized verification module for unsafe Rust code that systematically prevents undefined behavior (UB) through two core steps: |
| 10 | + |
| 11 | ++ Audit Unit Generation: Segment code into verifiable units by analyzing unsafe code propagation patterns. |
| 12 | + |
| 13 | ++ Safety Property Verification: Use contract-based abstract interpretation to validate safety properties. |
| 14 | + |
| 15 | +For comprehensive methodology details and practical examples, see the [module of verification in RAPx-Book](https://artisan-lab.github.io/RAPx-Book/6.4-unsafe.html). |
| 16 | + |
| 17 | +## Installation |
| 18 | +See the [quick start section](https://github.com/Artisan-Lab/RAPx?tab=readme-ov-file#quick-start) to learn how to install RAPx. The version of rustc used by RAPx is continuously updated and tries to match the `verify-rust-std` project's version whenever possible. |
| 19 | + |
| 20 | +## Usage |
| 21 | +### Usage in verifying third-party crate |
| 22 | +After ensuring that RAPx with the correct rustc version has been installed, you can verify the soundness of your code by doing the following steps: |
| 23 | ++ Navigate to the root directory of the crate you wish to analyze: |
| 24 | +``` |
| 25 | +cd /to-be-verified-crate/ |
| 26 | +``` |
| 27 | ++ Set the required environment variables. Since RAPx by default checks all unsafe calls in the standard library, __CARGO_TESTS_ONLY_SRC_ROOT must point to a pre-annotated version of std. A fully annotated std repository for RAPx linking will be released in the future. |
| 28 | +``` |
| 29 | +export RUSTUP_TOOLCHAIN=$RUSTUP_TOOLCHAIN_OF_RAPX |
| 30 | +export __CARGO_TESTS_ONLY_SRC_ROOT=/path-to-pre-annotated-std-lib/library |
| 31 | +``` |
| 32 | ++ Run the verification using the -verify subcommand. RAPx requires linking to the annotated standard library, so the -Zbuild-std argument is necessary: |
| 33 | +``` |
| 34 | +# In Linux |
| 35 | +cargo +$RUSTUP_TOOLCHAIN rapx -verify -- -Zbuild-std=panic_abort,core,alloc,std --target x86_64-unknown-linux-gnu |
| 36 | +# In Mac(Arm) |
| 37 | +cargo +$RUSTUP_TOOLCHAIN rapx -verify -- -Zbuild-std=panic_abort,core,alloc,std --target aarch64-apple-darwin |
| 38 | +``` |
| 39 | +Upon completion, RAPx will output the analysis results regarding the contract compliance of APIs containing unsafe code: |
| 40 | +``` |
| 41 | +|RAP|INFO|: --------In safe function "alloc::vec::into_raw_parts_with_alloc"--------- |
| 42 | +|RAP|INFO|: Use unsafe api "core::ptr::read". |
| 43 | +|RAP|INFO|: Argument 1's passed Sps: {"ValidPtr", "Typed", "Align"} |
| 44 | +``` |
| 45 | + |
| 46 | +### Usage in verifying the the Rust Standard Library |
| 47 | +Apart from the need to set up a `dummy_crate` as the entry point for the verification command, the process is the same as validating third-party libraries. However, RAPx offers a customized command, `-verify-std`, specifically for standard library verification. When using this command, RAPx scans all APIs in the standard library and verifies those annotated with `proof` targets. For example: |
| 48 | +```rust |
| 49 | +#[cfg_attr(rapx, safety {proof})] |
| 50 | +pub fn pop(&mut self) -> Option<T> { |
| 51 | + ... |
| 52 | +} |
| 53 | +``` |
| 54 | +This annotation will be conditionally expanded and verified during RAPx's compilation process. |
| 55 | + |
| 56 | +## Caveats |
| 57 | +RAPx provides sound detection of undefined behavior - if any path in the program contains UB, it will be reported. But this guarantee comes with inherent over-approximation of program paths, which may yield false positives where reported UB paths are infeasible in concrete execution. |
| 58 | + |
| 59 | +Besides, RAPx is still under heavy development and can currently validate some SPs mentioned in [tag-std](https://github.com/Artisan-Lab/tag-std/blob/main/primitive-sp.md#21-summary-of-primitive-sps). Continued development and integration are needed to support the verification of the remaining ones. |
| 60 | + |
| 61 | +Finally, RAPx ensures the absence of undefined behavior (UB) on all paths by (i) checking the callee’s preconditions or (ii) tracking subsequent [hazard conditions](https://github.com/Artisan-Lab/tag-std/blob/main/primitive-sp.md#1-overall-idea). RAPx can not provide any proof for the logic correctness of function. |
| 62 | + |
0 commit comments