Skip to content

bug: inverse_mod returns invalid value #11

@nils-mathieu

Description

@nils-mathieu

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 and 12 % 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:

#[test]
fn inverse_mod_in_range(x in nonzero_felt(), p in nonzero_felt()) {
    let nzp = NonZeroFelt(p.0);
    prop_assert!(x.inverse_mod(&nzp) <= Some(Felt::MAX));
    prop_assert!(x.inverse_mod(&nzp) < Some(p));
}

Which only checks whether the resulting inverse is less than p. It should probably check something like x.inverse_mod(&nzp).mul_mod(x, &nzp) == 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions