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: use platform independent method for counting new multiplication overflow from result limb count #916

Merged
merged 3 commits into from
Nov 15, 2023

Conversation

ivokub
Copy link
Collaborator

@ivokub ivokub commented Nov 15, 2023

Description

When we count the new overflow for the multiplication result in field emulation, then part of the computation depends on the number of limbs of the multiplication result. Previously, we used uint(math.Log2(float64(2*nbResLimbs-1)))+1, but this lead to inconsistent results when nbResLimbs was 0. In that case we take log2 of a negative value which is NaN. However, on ARM uint(NaN) = 0 but on x86 uint(NaN) = math.Max.

We now use bits.Len which is correct for all platforms and avoids doing cast to floating point values.

Additionally, added a check that in case we compute number of limbs for two inputs both having zero inputs. Reviewing code-base, this edge case does not happen, but adding as a protective measure.

This bug appeared when we compoute inverse and division overflows. There, we reused multiplication precondition for computing overflow, but had omitted the number of limbs for the result from the hint. This PR also fixes these calls.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

Test suite.

How has this been benchmarked?

Not benchmarked.

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@ivokub ivokub added bug Something isn't working P2: Medium Issue priority: medium labels Nov 15, 2023
@ivokub ivokub self-assigned this Nov 15, 2023
@gbotrel gbotrel self-requested a review November 15, 2023 22:47
@ivokub ivokub merged commit 5c18f45 into master Nov 15, 2023
5 checks passed
@ivokub ivokub deleted the fix/mulprecond-edgecase branch November 15, 2023 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2: Medium Issue priority: medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants