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

[Sentry] [Bug] Bug/Error: div() number type has more than 15 significant digits #13738

Closed
hilvmason opened this issue Feb 23, 2022 · 13 comments · Fixed by #25799
Closed

[Sentry] [Bug] Bug/Error: div() number type has more than 15 significant digits #13738

hilvmason opened this issue Feb 23, 2022 · 13 comments · Fixed by #25799
Assignees
Labels
area-Sentry error reporting to sentry INVALID-ISSUE-TEMPLATE Issue's body doesn't match any issue template. regression-prod-11.7.2 Regression bug that was found in production in release 11.7.2 release-12.3.0 Issue or pull request that will be included in release 12.3.0 Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. team-confirmations Push issues to confirmations team team-swaps type-bug

Comments

@hilvmason
Copy link
Contributor

  • This is a previously solved bug: “MM_bug_2” but actually appears to have not gone away
  • Affected users are reporting this happening upon opening the extension, and also upon executing transactions.
  • Not super high volume of inquiries on this one.
@hilvmason hilvmason added Sev2-normal Normal severity; minor loss of service or inconvenience. type-bug labels Feb 23, 2022
@danjm danjm unassigned ryanml Nov 1, 2022
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity in the last 90 days. It will be closed in 45 days if there is no further activity. The MetaMask team intends on reviewing this issue before close, and removing the stale label if it is still a bug. We welcome new comments on this issue. We do not intend on closing issues if they report bugs that are still reproducible. Thank you for your contributions.

@github-actions github-actions bot added the stale issues and PRs marked as stale label Jul 21, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2023

This issue was closed because there has been no follow up activity in the last 45 days. If you feel this was closed in error, please reopen and provide evidence on the latest release of the extension. Thank you for your contributions.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2023
Copy link

sentry-io bot commented Jan 18, 2024

Sentry issue: METAMASK-X885

@gauthierpetetin gauthierpetetin added Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. and removed Sev2-normal Normal severity; minor loss of service or inconvenience. labels Jan 18, 2024
@gauthierpetetin
Copy link
Contributor

Elevating this to a sev1 as it occurs in calcTokenAmount function and can potentially lead to wrong balances being displayed.

@gauthierpetetin gauthierpetetin added team-swaps and removed stale issues and PRs marked as stale labels Jan 18, 2024
@metamaskbot metamaskbot changed the title [Bug] Bug/Error: div() number type has more than 15 significant digits [Sentry] [Bug] Bug/Error: div() number type has more than 15 significant digits Jan 19, 2024
@metamaskbot metamaskbot added area-Sentry error reporting to sentry regression-prod-11.7.2 Regression bug that was found in production in release 11.7.2 INVALID-ISSUE-TEMPLATE Issue's body doesn't match any issue template. labels Jan 19, 2024
@github-project-automation github-project-automation bot moved this to To be fixed in Bugs by severity Feb 19, 2024
@gauthierpetetin
Copy link
Contributor

Probably not a bug anymore, but we shall investigate why it was solved.

@vpintorico
Copy link

Hi team, any update on this one?

@vpintorico
Copy link

@MetaMask/swaps-engineers Hi team, can you please confirm this is still happening?

@klejeune
Copy link
Contributor

klejeune commented Jul 3, 2024

@vpintorico happened twice in the last 3 months:

  • June 20th on 11.16.11
  • June 17th on 11.17.10

@infiniteflower @nikoferro I can reproduce with this:

BigNumber.DEBUG = true;
calcTokenAmount(1, 0.0000999999999999999) // "1" is not important, the error is triggered by the second parameter alone

// Error: [BigNumber Error] Number primitive has more than 15 significant digits: 1.0002302850208247

@digiwand digiwand self-assigned this Jul 12, 2024
@digiwand
Copy link
Contributor

hi there 👋🏼 I dug into a separate, related issue in the repo (See "Technical Details" here)

I see the issue in calcTokenAmount and am working on a solution

@digiwand digiwand added the team-confirmations Push issues to confirmations team label Jul 12, 2024
@digiwand
Copy link
Contributor

Q: how may the app pass a fractional value as the decimals for calcTokenAmount?

cc: @klejeune

@digiwand
Copy link
Contributor

cc: @klejeune

It turns out there was a way to cause the error without decimals being fractional. For example, when decimals = 36 it would cause the error reported in Sentry:

BigNumber Error:
div() number type has more than 15 significant digits: 9.999999999999999e+35

Created the fix for this here #25799

@digiwand digiwand added needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) and removed needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) labels Jul 15, 2024
digiwand added a commit that referenced this issue Jul 17, 2024
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

#### This PR:
- Fixes a BigNumber Error on calcTokenAmount 
- Fixes Swaps destinationAmount type. '0' should take place of null
occurrences
- Adds calcTokenAmount tests

#### Explanation:
When certain large params are passed, e.g. when the decimal passed is
36, the calculation of `Math.pow(10, Number(decimals || 0))` is expected
→ 100000000. Then, when we pass this to BigNumber div() we get the
error:
```
BigNumber Error:
div() number type has more than 15 significant digits: 9.999999999999999e+35
```
however, if we pass the same value as a BigNumber, we do not get the
error. That is, instead of passing the result of `Math.pow(10,
Number(decimals || 0))`, we pass the result of `new
BigNumber(10).pow(decimals)`

honestly, I don't quite understand why this is. We can see the
[bignumber.js#div code
here](https://github.com/MikeMcl/bignumber.js/blob/v4.1.0/bignumber.js#L750)

#### Other notes:
- It turns out that updating the bignumber.js package from 4.1.0 → 9.1.2
could also fix this issue
- There is another, less-used BigNumber class that exists in our code
([this BigNumber div
code](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/bignumber/src.ts/bignumber.ts#L81))

---

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25799?quickstart=1)

## **Related issues**

Fixes: #13738
Related:
#25741 (comment)

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**
(divisor was previously called multiplier)
![CleanShot 2024-07-16 at 01 07
09@2x](https://github.com/user-attachments/assets/f1444f58-ca02-404a-aba9-153455bb177c)

### **After**

![CleanShot 2024-07-16 at 01 19
06@2x](https://github.com/user-attachments/assets/c5251516-f8b1-459a-be5f-06f99d66b3f7)

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@github-project-automation github-project-automation bot moved this from To be fixed to Fixed in Bugs by team Jul 17, 2024
@github-project-automation github-project-automation bot moved this from To be fixed to Fixed in Bugs by severity Jul 17, 2024
@metamaskbot metamaskbot added the release-12.3.0 Issue or pull request that will be included in release 12.3.0 label Jul 17, 2024
@benjisclowder
Copy link
Contributor

Collaborative Effort Required for Root Cause Analysis (RCA) on Critical Issues

We are quickly approaching the end of the quarter and we encourage you once again to take some moments and perform RCA on this critical issue. You may do so by answering the questions below:

1. What PR fixed the issue?
2. Can you pinpoint the commit from which the issue originated?
3. Write a short explanation of the technical cause of the bug
4. How could we have avoided merging this bug? What would have had to be different about our code, tests or processes?

4.1. Were there any missing unit, e2e or manual tests that could have preempted this issue?
4.2. Were there any other elements lacking, such as typed code, comprehensive documentation, well-architected APIs, etc., that might have prevented this issue?
4.3. If your answer to a and b is no, then is there anything at all that you can think of that, if it had been different before this bug was introduced, would have prevented it from being merged?

Please provide your answers as a reply to this comment and tag me as well.

You can read more about the initiative here. Thank you!

Tagging eng. who added the fix: @digiwand

@digiwand
Copy link
Contributor

Hello again @benjisclowder, just sent a related RCA, which was focused on a related precision issue. Backlinking here: (Ref). Please reach out if any of this is unclear and I can update it. Thank you!

  1. What PR fixed the issue?
    fix: calcTokenAmount BigNumber more than 15 digits error #25799

  2. Can you pinpoint the commit from which the issue originated?
    BigNumber was introduced into calcTokenAmount 6 years ago: 79976b7. I think it's possible similar 15 digit errors have occurred since then.

    Minor and related update to calcTokenAmount: 4c87c05#diff-38dd5378373982fd486d27410ed95f012dcfb238960362b3cb3612bbea1ff2baL110 (Linking this as the filepath for the related util has changed overtime making these commits harder to track.)

  3. Write a short explanation of the technical cause of the bug
    [Sentry] [Bug] Bug/Error: div() number type has more than 15 significant digits #13738 (comment):

    It turns out there was a way to cause the error [... e.g.] when decimals = 36 it would cause the error reported in Sentry:

    BigNumber Error:
    div() number type has more than 15 significant digits: 9.999999999999999e+35

    Please see "Explanation:" in fix: calcTokenAmount BigNumber more than 15 digits error #25799 (comment) and "Technical Details" in fix: Error: new BigNumber() more than 15 digits feat: apply ellipsis #25741 for further technical details.

  4. How could we have avoided merging this bug? What would have had to be different about our code, tests or processes?
    4.1. Were there any missing unit, e2e or manual tests that could have preempted this issue?
    Yes, we could test larger integers and integers that may cause values greater than MAX_SAFE_INTEGER passed to BigNumber.
    4.2. Were there any other elements lacking, such as typed code, comprehensive documentation, well-architected APIs, etc., that might have prevented this issue?
    updating the bignumber.js package from 4.1.0 → 9.1.2 could also fix this issue. bignumber.js has not been updated since the beginning of MM.
    4.3. If your answer to a and b is no, then is there anything at all that you can think of that, if it had been different before this bug was introduced, would have prevented it from being merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Sentry error reporting to sentry INVALID-ISSUE-TEMPLATE Issue's body doesn't match any issue template. regression-prod-11.7.2 Regression bug that was found in production in release 11.7.2 release-12.3.0 Issue or pull request that will be included in release 12.3.0 Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. team-confirmations Push issues to confirmations team team-swaps type-bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

8 participants