-
Notifications
You must be signed in to change notification settings - Fork 85
How to verify tag when type changes #1131
Comments
This seems like something that ought to work. I'll try and have a look this weekend. |
This is quite a subtle problem and I don't have a fix for it as yet. What is going on here is that the post condition can't be proved while constructing the summary for a_to_b. It should be, given the precondition, but it is tricky and it goes wrong in this case. The summary, however, is complete enough that the calling code can prove the verify in main even without the explicit post condition. So your work around for now is just to omit the post condition. In general, post conditions are seldom needed, so omit them by default. |
Thanks for your explanation! I agree that postconditions could be avoided in most cases. I tried to reform my sample program without using postcondition but still got unexpected result: #![cfg_attr(mirai, allow(incomplete_features), feature(generic_const_exprs))]
extern crate mirai_annotations;
use mirai_annotations::*;
#[cfg(mirai)]
use mirai_annotations::TagPropagationSet;
#[cfg(mirai)]
struct SecretTaintKind<const MASK: TagPropagationSet> {}
#[cfg(mirai)]
const SECRET_TAINT: TagPropagationSet = TAG_PROPAGATION_ALL;
#[cfg(mirai)]
type SecretTaint = SecretTaintKind<SECRET_TAINT>;
#[cfg(not(mirai))]
type SecretTaint = ();
struct A(u32);
struct B(u32);
fn a_to_b(a: A) -> B {
precondition!(has_tag!(&a, SecretTaint));
let b = B(a.0 + 1);
b
}
fn b_to_a(b: B) -> A {
precondition!(has_tag!(&b, SecretTaint));
let a = A(b.0 + 1);
a
}
fn main() {
let a = A(1);
add_tag!(&a, SecretTaint);
let b = a_to_b(a);
verify!(has_tag!(&b, SecretTaint));
let a = b_to_a(b);
verify!(has_tag!(&a, SecretTaint));
// println!("reachable?");
} Output of
In this program, I add another function Besides, the last verify in I would be more than grateful if you can provide some insights about the potential reasons lead to these. I'm not pretty sure if MIRAI should be used in this way and please point out my mistakes if possible! |
Taint that propagates to other elements of a structure/collection is hard to deal with in the MIRAI heap model because the model is sparse. Also You are not doing anything wrong, just using a feature that is complicated and not yet well tested. I hope to fix these problems in the coming weeks. |
Thank you for the quick rely! I'm looking forward to seeing the updated features! |
Issue
I want to verify a typestate program but I'm hindered by some unexpected output. So I start with a minimal reproducible example.
When I have two structs (say
A
andB
for example) and have a function converting fromA
toB
. How should I maintain and propagate the tag? I checkedannotations/lib.rs
and foundSubComponent
andSuperComponent
, but the output is not as what I expected. In the example below I verified the tag after executinga_to_b
and has the same postcondition ina_to_b
, however only the postcondition is not always satisfied.Steps to Reproduce
run
cargo mirai
.Expected Behavior
no warning.
Actual Results
Besides, from the comments in
annotations/lib.rs
, I thinkpostcondition!
is flow-sensitive, butverify!
is not when using them in the same place in the function.Environment
rustc 1.60.0-nightly (bfe156467 2022-01-22)
The text was updated successfully, but these errors were encountered: