Rust-proofã使ã£ã¦ã¿ã
æ¦è¦: Rust-proofã¯Electrolysisã¨åæ§ã«Rustããã°ã©ã ããæ¤è¨¼æ¡ä»¶ãæ½åºããããLeanã§ã¯ãªãSMTã½ã«ãã§ããZ3åãã®æ¤è¨¼æ¡ä»¶ãåºåããããã¡ããéçºãæ¾æ£ããã¦ããããã«è¦ãããç¾å¨ããã«ãå¯è½ã§ããã
æºå
ãã¹ãç¨ãªãã¸ããªãæºåãã
$ cargo new rustproof-test $ cd rustproof-test
該å½ã®nightlyãã¼ã¸ã§ã³ãåå¾ãã (Electrolysisã¨åæ§ãRust-proofãã³ã³ãã¤ã©ãã©ã°ã¤ã³ã®ãããç¹å®ã®nightlyãã¼ã¸ã§ã³ã«å¼·ãä¾åãã¦ãã)
$ rustup override set nightly-2016-08-12
Z3ãã¤ã³ã¹ãã¼ã«
$ sudo apt install z3
使ã£ã¦ã¿ã
Cargo.toml
ã«ä»¥ä¸ã®ä¾åé¢ä¿ãæ¸ã
[dependencies] rustproof = { git = "https://github.com/Rust-Proof/rustproof.git", rev = "654b004" }
src/lib.rs
ã«ä»¥ä¸ã®ããã«é¢æ°ãæ¸ããããã¯EXAMPLESã«æ²è¼ããã¦ãããã®ã¨ã»ã¼åæ§ã ãã5:i32
ã®ãããªåã¤ããªãã©ã«ã¯5i32
ã«ç½®ãæãã¦ããã
// feature(plugin) ãæå¹åãã¦rustproofããã¼ã #![feature(plugin)] #![plugin(rustproof)] // #[condition] ã«ããã³ã³ãã¤ã«æã«rustproofã«ãããã§ãã¯ãèµ°ã #[condition(pre="(x:i32 <= i32::MAX - 5i32)", post="return:i32 == (x:i32 + 5i32)")] pub fn add_five(x:i32) -> i32 { assert!(x <= 2147483647-5); x+5 } #[condition(pre="(x:i32 <= i32::MAX - 4i32)", post="return:i32 == (x:i32 + 5i32)")] pub fn add_five_invalid(x:i32) -> i32 { assert!(x <= 2147483647-5); x+5 } #[condition(pre="true", post="(x:bool==true IMPLIES return:bool==false) && (x:bool==false IMPLIES return:bool==true)")] pub fn boolean_not(x:bool) -> bool { if x == true { false } else { true } }
æ¤è¨¼ãå®è¡ããã«ã¯åã«ã³ã³ãã¤ã©ãèµ·åããã°ããã
$ cargo build Compiling rustproof-test v0.1.0 fn add_five(..) Verification Condition is valid. fn boolean_not(..) Verification Condition is valid. fn add_five_invalid(..) Verification Condition is not valid. (model (define-fun x () (_ BitVec 32) #x7ffffffb) ) Finished debug [unoptimized + debuginfo] target(s) in 42.84 secs
ã¾ã¨ã
大å¤ãã試ã¿ã ããå¤ãããã®ãæ®å¿µã ã¨æããrust-proofãéçºãããçµç·¯ã¯ä¸æã ããdocumentsã¨ãããã£ã¬ã¯ããªã«ä¸ç©ãªè³æãæ®ããã¦ããã®ã§è¦ã¦ã¿ãã¨é¢ç½ããããããªãã