-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quantifier optimization fix for conditionals (#1153)
* Fix for quantifier optimization
- Loading branch information
Showing
2 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
prusti-tests/tests/verify_overflow/pass/quantifiers/conditionals.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use prusti_contracts::*; | ||
|
||
struct AccountID(u32); | ||
|
||
struct Bank { | ||
|
||
} | ||
|
||
impl Bank { | ||
|
||
#[pure] | ||
#[trusted] | ||
fn balance_of(&self, acct_id: &AccountID) -> u32 { | ||
0 | ||
} | ||
|
||
#[trusted] | ||
#[requires(amt >= 0 ==> u32::MAX - self.balance_of(acct_id) >= (amt as u32))] | ||
#[ensures( | ||
forall(|acct_id2: &AccountID| | ||
self.balance_of(acct_id2) == | ||
if(acct_id === acct_id2 && amt >= 0) { | ||
old(self.balance_of(acct_id)) + (amt as u32) | ||
} else { | ||
0 | ||
} | ||
) | ||
)] | ||
fn adjust_amount(&mut self, acct_id: &AccountID, amt: i32) { | ||
} | ||
|
||
} | ||
|
||
|
||
#[requires(amt < 0 && bank.balance_of(to) >= (0 - amt) as u32)] | ||
fn go(bank: &mut Bank, to: &AccountID, amt: i32) { | ||
bank.adjust_amount(to, amt); | ||
} | ||
|
||
pub fn main(){} |