Skip to content

Commit 144b458

Browse files
authored
vstd: unsigned wrapping_mul spec (#1829)
* vstd: add wrapping mul spec * unsigned_wrapping_mul test
1 parent e68600d commit 144b458

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

source/rust_verify_test/tests/std.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,23 @@ test_verify_one_file! {
177177
} => Err(err) => assert_vir_error_msg(err, "index for &mut not supported")
178178
}
179179

180+
test_verify_one_file! {
181+
#[test] unsigned_wrapping_mul verus_code! {
182+
use vstd::*;
183+
184+
fn test() {
185+
let i = 255u16.wrapping_mul(253);
186+
assert(i == 64515);
187+
188+
let i = 256u16.wrapping_mul(256);
189+
assert(i == 0);
190+
191+
let i = 257u16.wrapping_mul(259);
192+
assert(i == 1027);
193+
}
194+
} => Ok(())
195+
}
196+
180197
test_verify_one_file! {
181198
#[test] signed_wrapping_mul verus_code! {
182199
use vstd::*;

source/vstd/std_specs/num.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ macro_rules! num_specs {
107107
}
108108
);
109109

110+
#[verifier::allow_in_spec]
111+
pub assume_specification[<$uN>::wrapping_mul](x: $uN, y: $uN) -> $uN
112+
returns ((x as nat * y as nat) % $range as nat) as $uN;
113+
110114
#[verifier::allow_in_spec]
111115
pub assume_specification[<$uN>::checked_add](x: $uN, y: $uN) -> Option<$uN>
112116
returns (

0 commit comments

Comments
 (0)