Skip to content

Commit 1d8dd0b

Browse files
committed
Fix sqrt proptest
1 parent 95877d1 commit 1d8dd0b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

felt/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,11 +1356,14 @@ mod test {
13561356

13571357
#[test]
13581358
fn sqrt_is_inv_square(x in any::<Felt252>()) {
1359-
// In the regular use case the number upon which sqrt is called will always be a felt (aka a numer lower than cairo_prime)
1360-
// In order to get a number for which we know its root it is not a good enough solution to square the felt (as we might get something bigger than cairo prime)
1361-
// We can instead use the square root (using the biguint implementation), to guarantee that its square will be inside the felt range
1362-
let x = Felt252::from(x.to_biguint().sqrt());
1363-
prop_assert_eq!((&x * &x).sqrt(), x);
1359+
let x_sq = &x * &x;
1360+
let sqrt = x_sq.sqrt();
1361+
1362+
if sqrt != x {
1363+
prop_assert_eq!(Felt252::max_value() - sqrt + 1_usize, x);
1364+
} else {
1365+
prop_assert_eq!(sqrt, x);
1366+
}
13641367
}
13651368

13661369
#[test]

0 commit comments

Comments
 (0)