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(utils): fix pow for negative exponent #249

Merged
merged 2 commits into from
Apr 18, 2024
Merged

fix(utils): fix pow for negative exponent #249

merged 2 commits into from
Apr 18, 2024

Conversation

0xbok
Copy link
Collaborator

@0xbok 0xbok commented Apr 17, 2024

pow fn comment says it handles negative exponent but it doesn't. This PR fixes it. Here's the reasoning behind the fix:

$$ a^{-e} = (a^{-1})^e \mod p $$

So pow(a, -e) == pow(inv(a), e)

@0xbok 0xbok requested a review from cedoor April 17, 2024 10:50
fix pow for negative exponent
@0xbok
Copy link
Collaborator Author

0xbok commented Apr 17, 2024

note that the pow test uses 12 as the order. A field with a non-prime order may not have an inverse for every element in the set.

@cedoor cedoor merged commit 6f78156 into main Apr 18, 2024
2 checks passed
@cedoor cedoor deleted the fix-pow branch April 18, 2024 11:19
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.

2 participants