Skip to content
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

Fix test_ecdsa_recover_public_key test #569

Merged
merged 2 commits into from
May 6, 2024

Conversation

tcoratger
Copy link
Collaborator

Should close #468

The modular inverse should be obtained roughly via the pseudo code:

function inverse(a, n)
    t := 0;     newt := 1
    r := n;     newr := a

    while newr ≠ 0 do
        quotient := r div newr
        (t, newt) := (newt, t − quotient × newt) 
        (r, newr) := (newr, r − quotient × newr)

    if r > 1 then
        return "a is not invertible"
    if t < 0 then
        t := t + n

    return t

In the build_u256_guarantee_inv_mod_n construction, we missed the t < 0 condition, causing this operation https://github.com/starkware-libs/cairo/blob/afeeed29b37bd394535fcf3e8d7d16db047381fb/corelib/src/ecdsa.cairo#L143 to fail in the ECDSA recover_public_key procedure. This issue is fixed and another unit test is added in the u256_inv_mod_n suite to cover this scenario.

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.75%. Comparing base (bd23b1c) to head (e3c669e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #569      +/-   ##
==========================================
+ Coverage   89.74%   89.75%   +0.01%     
==========================================
  Files         108      108              
  Lines       34534    34575      +41     
==========================================
+ Hits        30991    31032      +41     
  Misses       3543     3543              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@edg-l
Copy link
Collaborator

edg-l commented May 6, 2024

Nice find! Thanks a lot.

Copy link
Collaborator

@azteca1998 azteca1998 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thanks for the fix.

@edg-l edg-l added this pull request to the merge queue May 6, 2024
Merged via the queue into lambdaclass:main with commit 7a716f7 May 6, 2024
9 checks passed
Gerson2102 pushed a commit to Gerson2102/cairo_native that referenced this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: cairo test test_ecdsa_recover_public_key fails
4 participants