-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: inverse_mod
returns invalid value
#11
Comments
Update: this test do not pass. #[test]
fn inverse_mod_in_range(x in nonzero_felt(), p in nonzero_felt()) {
let nzp = NonZeroFelt(p.0);
let Some(ret) = x.inverse_mod(&nzp) else { return Ok(()) };
prop_assert!(ret <= Felt::MAX);
prop_assert!(ret < p);
prop_assert!(ret.mul_mod(&x, &nzp) == Felt::ONE);
} |
Thanks for the report @nils-mathieu |
Hi @nils-mathieu ! I just checked and we don't use this operation in the cairo-vm, I am not really sure if other projects need them. Tell me what you think! @xJonathanLEI @abdelhamidbakhta. Do you require these operations in your projects? |
@pefontana Oooh, I see. It's more a metter of naming in that case imo. |
Great @nils-mathieu ! |
I use |
Thanks @xJonathanLEI |
Bug Report
stark-felt version: 0.0.3
commit: ea52b64
Behavior:
The
inverse_mod
functions returns an invalid value:3.inverse_mod(5)
returns 4 instead of 2.Indeed
3 * 4 == 12
and12 % 5 == 2 != 1
.Other information:
I found this writing documentation (see #10). If you download that PR and run
cargo test
, you'll get the error.Currently, the only test for
inverse_mod
is this one:Which only checks whether the resulting inverse is less than
p
. It should probably check something likex.inverse_mod(&nzp).mul_mod(x, &nzp) == 1
.The text was updated successfully, but these errors were encountered: