TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Prusti: Static Analyzer for Rust

285 pointsby aviramhaover 2 years ago

13 comments

insanitybitover 2 years ago
This is great. I&#x27;m building something similar, an effects system for rust, and it looks quite a bit like this. The difference is that my effects system compiles to a seccomp + apparmor profile so that your rust program is sandboxed at runtime based on info at compile time.<p>I have a notion of purity as well :P<p>I think the applications of this sort of thing are pretty limitless. Maybe rust has `unsafe` but with further verification extensions to the language we can really push confidence in a working, safe product.
评论 #33193618 未加载
评论 #33195852 未加载
评论 #33194687 未加载
评论 #33308626 未加载
评论 #33199455 未加载
wongarsuover 2 years ago
That looks incredibly useful. Proving the absence of panics and overflows is already great, and with the annotations you can guarantee properties you&#x27;d normally write property tests for, like in this example from the docs:<p><pre><code> impl List { #[ensures(self.len() == old(self.len()) + 1)] pub fn push(&amp;mut self, elem: i32) { &#x2F;&#x2F; TODO } }</code></pre>
评论 #33193098 未加载
评论 #33224300 未加载
nerdponxover 2 years ago
According to the Readme, this is based on a more-general verification framework called Viper, which apparently works for several languages (including Rust): <a href="https:&#x2F;&#x2F;www.pm.inf.ethz.ch&#x2F;research&#x2F;viper.html" rel="nofollow">https:&#x2F;&#x2F;www.pm.inf.ethz.ch&#x2F;research&#x2F;viper.html</a><p>There also appear to be equivalents of this tool in Python (&quot;Nagini&quot; <a href="https:&#x2F;&#x2F;www.pm.inf.ethz.ch&#x2F;research&#x2F;nagini.html" rel="nofollow">https:&#x2F;&#x2F;www.pm.inf.ethz.ch&#x2F;research&#x2F;nagini.html</a>) and Go (&quot;Gobra&quot; <a href="https:&#x2F;&#x2F;www.pm.inf.ethz.ch&#x2F;research&#x2F;gobra.html" rel="nofollow">https:&#x2F;&#x2F;www.pm.inf.ethz.ch&#x2F;research&#x2F;gobra.html</a>).<p>I&#x27;ll definitely be checking out Nagini for my work!
Klasiasterover 2 years ago
It doesn&#x27;t mention unsafe in the README but the website says:<p><pre><code> The first versions of our tools are under development, and target a small but interesting fragment of Rust without unsafe features; in the future, we plan to extend our work to tackle a large portion of the language, including certain patterns of unsafe Rust code. </code></pre> I wonder if this can be used to prove that unsafe code is memory safe.
评论 #33195061 未加载
hn92726819over 2 years ago
I don&#x27;t understand how this could work from looking at the readme. It says:<p>&gt; verifies absence of integer overflows and panics by proving that statements such as unreachable!() and panic!() are unreachable<p>But integer overflows in release builds don&#x27;t panic! and aren&#x27;t unreachable!. Additionally, clippy already checks this for you if you enable an optional lint.<p>So if it detects any panic! Then that&#x27;s amazing. But if it only detects panic for integer operations, we already have that feature. Either way, the overflow&#x2F;panic! wording is confusing because it either only applies to debug builds or applies to more than integer operations
评论 #33192827 未加载
评论 #33192972 未加载
评论 #33192634 未加载
评论 #33192655 未加载
Animatsover 2 years ago
That&#x27;s nice. Classic verification. Someday the compiler should do this as part of optimizing run-time checks. Most of the time, either overflow is impossible, or you really needed a run time check.<p>The static analysis I&#x27;d like for Rust is deadlock analysis. If you lock things in different orders in different threads, you can deadlock. That is, if thread A locks X, then Y, and thread B locks Y, then X, there is a potential deadlock. Whole-program static analysis can detect that. It&#x27;s a good check to have, because infrequent deadlocks of this type may pass testing.
za3faranover 2 years ago
What are people&#x27;s experiences with static analyzers at companies? Many people I have spoken with have either never heard of them, or expressed no interest. Usually those same people use dynamic languages like Ruby or Python.
评论 #33192598 未加载
评论 #33193259 未加载
评论 #33191788 未加载
评论 #33192878 未加载
评论 #33192164 未加载
评论 #33192576 未加载
评论 #33197812 未加载
评论 #33192392 未加载
评论 #33191906 未加载
评论 #33191835 未加载
评论 #33192141 未加载
评论 #33191847 未加载
评论 #33192684 未加载
haskellandchillover 2 years ago
This looks good, I&#x27;m going to have to try out their work for Go, Gobra, since that&#x27;s what I&#x27;m mostly writing these days.
WalterBrightover 2 years ago
Looks like I need to fix my binary search code!
评论 #33206662 未加载
dochtmanover 2 years ago
Was a bit disappointed to discover that the advertised Prusti Assistant VS Code assistant sort of silently sits there waiting (&quot;Checking requirements...&quot;) if you don&#x27;t have Java installed.<p>I feel like assuming Java is installed doesn&#x27;t really fit the audience.
评论 #33196559 未加载
temp123789246over 2 years ago
Out of curiosity, does anyone know how this compares to something like Liquid Haskell? Is one more or less powerful than the other?
评论 #33196499 未加载
nextaccounticover 2 years ago
Here&#x27;s a 2020 overview of Rust verification tools <a href="https:&#x2F;&#x2F;alastairreid.github.io&#x2F;rust-verification-tools&#x2F;" rel="nofollow">https:&#x2F;&#x2F;alastairreid.github.io&#x2F;rust-verification-tools&#x2F;</a> - it says<p>&gt; Auto-active verification tools<p>&gt; While automatic tools focus on things not going wrong, auto-active verification tools help you verify some key properties of your code: data structure invariants, the results of functions, etc. The price that you pay for this extra power is that you may have to assist the tool by adding function contracts (pre&#x2F;post-conditions for functions), loop invariants, type invariants, etc. to your code.<p>&gt; The only auto-active verification tool that I am aware of is Prusti. Prusti is a really interesting tool because it exploits Rust’s unusual type system to help it verify code. Also Prusti has the slickest user interface: a VSCode extension that checks your code as you type it!<p>&gt; <a href="https:&#x2F;&#x2F;marketplace.visualstudio.com&#x2F;items?itemName=viper-admin.prusti-assistant" rel="nofollow">https:&#x2F;&#x2F;marketplace.visualstudio.com&#x2F;items?itemName=viper-ad...</a><p>Now, on that list, there is also <a href="https:&#x2F;&#x2F;github.com&#x2F;facebookexperimental&#x2F;MIRAI" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;facebookexperimental&#x2F;MIRAI</a> that, alongside the crate <a href="https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;contracts" rel="nofollow">https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;contracts</a> (with the mirai_assertion feature enabled) enables writing code like this<p><pre><code> #[ensures(person_name.is_some() -&gt; ret.contains(person_name.unwrap()))] fn geeting(person_name: Option&lt;&amp;str&gt;) -&gt; String { let mut s = String::from(&quot;Hello&quot;); if let Some(name) = person_name { s.push(&#x27; &#x27;); s.push_str(name); } s.push(&#x27;!&#x27;); s } </code></pre> And have it checked at compile time that the assertion holds! Which is a bit like Liquid Haskell in capability: <a href="https:&#x2F;&#x2F;ucsd-progsys.github.io&#x2F;liquidhaskell&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ucsd-progsys.github.io&#x2F;liquidhaskell&#x2F;</a><p>... and now I just noticed that prusti has a crate prusti_contracts that can do the same thing!! <a href="https:&#x2F;&#x2F;github.com&#x2F;viperproject&#x2F;prusti-dev&#x2F;blob&#x2F;master&#x2F;prusti-tests&#x2F;tests&#x2F;verify_overflow&#x2F;pass&#x2F;overflow&#x2F;bisect.rs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;viperproject&#x2F;prusti-dev&#x2F;blob&#x2F;master&#x2F;prust...</a><p>Now I&#x27;m wondering which tool is more capable (as I understand, they leverage a SMT solver like Z3 to discharge the proof obligations, right?)
piterdevriesover 2 years ago
Why would you need a static analyzer for a language that promotes itself as safe out of the box.
评论 #33192105 未加载
评论 #33192095 未加载
评论 #33192511 未加载
评论 #33192766 未加载
评论 #33192168 未加载
评论 #33196303 未加载
评论 #33192032 未加载