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

[Bug]: Precision is lost displaying Permit value in simulation and data tree #25755

Closed
digiwand opened this issue Jul 10, 2024 · 4 comments · Fixed by #25968
Closed

[Bug]: Precision is lost displaying Permit value in simulation and data tree #25755

digiwand opened this issue Jul 10, 2024 · 4 comments · Fixed by #25968
Assignees
Labels
regression-RC-12.1.0 release-12.1.0 Issue or pull request that will be included in release 12.1.0 Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. team-confirmations Push issues to confirmations team type-bug

Comments

@digiwand
Copy link
Contributor

digiwand commented Jul 10, 2024

Describe the bug

formatAmount in ui/pages/confirmations/components/simulation-details/formatAmount.ts utilizes Intl.NumberFormat, which requires a BigInt or number passed to it causing a loss in precision when computing large numbers. It does not accept strings. Currently, it will display 0s for the digits after 15 digits.

we should update the logic to preserve the precision

Example:

  • 30001231231212312138768 → 30,001,231,231,212,312,000,000
  • 115792089237316195423570985008687907853269984665640564039457584007913129639935 → 115,792,089,237,316,200,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000

Related: #25741
Related: #25438

Expected behavior

No response

Screenshots/Recordings

Steps to reproduce

  1. run yarn storybook
  2. go to http://localhost:6006/?path=/story/pages-confirmations-confirm-signatures-signedtypeddatav3orv4--permit-story&args=msgParams.data:3.0001231231212312e+22
  3. copy and paste the following into data
"{\"types\":{\"EIP712Domain\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"version\",\"type\":\"string\"},{\"name\":\"chainId\",\"type\":\"uint256\"},{\"name\":\"verifyingContract\",\"type\":\"address\"}],\"Permit\":[{\"name\":\"owner\",\"type\":\"address\"},{\"name\":\"spender\",\"type\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\"},{\"name\":\"nonce\",\"type\":\"uint256\"},{\"name\":\"deadline\",\"type\":\"uint256\"}]},\"primaryType\":\"Permit\",\"domain\":{\"name\":\"MyToken\",\"version\":\"1\",\"verifyingContract\":\"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC\",\"chainId\":1},\"message\":{\"owner\":\"0x935e73edb9ff52e23bac7f7e043a1ecd06d05477\",\"spender\":\"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4\",\"value\":30001231231212312138768,\"nonce\":0,\"deadline\":50000000000}}"

Error messages or log output

No response

Version

12.1.0

Build type

None

Browser

Chrome

Operating system

MacOS

Hardware wallet

No response

Additional context

No response

Severity

No response

@github-project-automation github-project-automation bot moved this to To be fixed in Bugs by severity Jul 10, 2024
@github-project-automation github-project-automation bot moved this to To be fixed in Bugs by team Jul 10, 2024
@digiwand digiwand added the team-confirmations Push issues to confirmations team label Jul 10, 2024
@metamaskbot metamaskbot added the regression-prod-12.1.0 Regression bug that was found in production in release 12.1.0 label Jul 10, 2024
digiwand added a commit that referenced this issue Jul 12, 2024
…25741)

<!--
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**

Plan is to cherry-pick this PR for V12.1
- Adds ellipsis to Permit value
- Fixes error: 
```    
BigNumber Error: new BigNumber() number type has more than 15 significant digits
```

Note that the precision is lost through formatAmount. Fix will be added
#25755

Most file updates are snapshot updates

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

## **Related issues**

Fixes: MetaMask/MetaMask-planning#2730
(ellipsis)
Fixes: #25751
(Error)

## Technical Details

- `JSON.parse` coerces number values into scientific notation if they
are greater than Number.MAX_SAFE_INTEGER, which is the max safe integer
in JavaScript.
e.g. 30001231231212312138768 → 3.0001231231212312e+22
- `JSON.parse` reviver cannot help since the value will be coerced by
the time it
 reaches the reviver function.
- We preserve the value by extracting the value with a regex and
overwriting the `JSON.parse` value. The preserved value should never be
converted to a JavaScript number since it will lose its precision.
Instead, we can preserve the value as a string, BigNumber, or Numeric
type. BigInt also has rounding limitations.
- BigNumber errors out when constructed with numbers with 15+ digits. It
can accept strings to preserve digits.
- formatAmount in
`ui/pages/confirmations/components/simulation-details/formatAmount.ts`
utilizes Intl.NumberFormat, which requires a BigInt or number passed to
it causing a loss in precision when computing large numbers. It does not
accept strings. Currently, it will display 0s for the digits after 15
digits.
e.g. 30001231231212312138768 → 30,001,231,231,212,312,000,000
Issue ticket to address this
#25755

## **Manual testing steps**

1. run `yarn storybook`
2. go to
http://localhost:6006/?path=/story/pages-confirmations-confirm-signatures-signedtypeddatav3orv4--permit-story&args=msgParams.data:3.0001231231212312e+22
3. copy and paste the following into data
```
"{\"types\":{\"EIP712Domain\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"version\",\"type\":\"string\"},{\"name\":\"chainId\",\"type\":\"uint256\"},{\"name\":\"verifyingContract\",\"type\":\"address\"}],\"Permit\":[{\"name\":\"owner\",\"type\":\"address\"},{\"name\":\"spender\",\"type\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\"},{\"name\":\"nonce\",\"type\":\"uint256\"},{\"name\":\"deadline\",\"type\":\"uint256\"}]},\"primaryType\":\"Permit\",\"domain\":{\"name\":\"MyToken\",\"version\":\"1\",\"verifyingContract\":\"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC\",\"chainId\":1},\"message\":{\"owner\":\"0x935e73edb9ff52e23bac7f7e043a1ecd06d05477\",\"spender\":\"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4\",\"value\":30001231231212312138768,\"nonce\":0,\"deadline\":50000000000}}"
```

## **Screenshots/Recordings**

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

### **Before**

 
![CleanShot 2024-07-10 at 01 14
52](https://github.com/MetaMask/metamask-extension/assets/20778143/7a7ff9e3-07a9-4a3b-b8f4-7f672998cdab)


### **After**

![CleanShot 2024-07-11 at 00 37
25@2x](https://github.com/MetaMask/metamask-extension/assets/20778143/df6b1f0e-fa12-4b6e-9ae1-0486feb7571a)
![CleanShot 2024-07-11 at 00 37
37@2x](https://github.com/MetaMask/metamask-extension/assets/20778143/faffb8e0-6eae-4ef9-8f3b-c399b7f9f7ae)



## **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.
digiwand added a commit that referenced this issue Jul 12, 2024
…25741)

<!--
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.
-->

Plan is to cherry-pick this PR for V12.1
- Adds ellipsis to Permit value
- Fixes error:
```
BigNumber Error: new BigNumber() number type has more than 15 significant digits
```

Note that the precision is lost through formatAmount. Fix will be added
#25755

Most file updates are snapshot updates

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

Fixes: MetaMask/MetaMask-planning#2730
(ellipsis)
Fixes: #25751
(Error)

- `JSON.parse` coerces number values into scientific notation if they
are greater than Number.MAX_SAFE_INTEGER, which is the max safe integer
in JavaScript.
e.g. 30001231231212312138768 → 3.0001231231212312e+22
- `JSON.parse` reviver cannot help since the value will be coerced by
the time it
 reaches the reviver function.
- We preserve the value by extracting the value with a regex and
overwriting the `JSON.parse` value. The preserved value should never be
converted to a JavaScript number since it will lose its precision.
Instead, we can preserve the value as a string, BigNumber, or Numeric
type. BigInt also has rounding limitations.
- BigNumber errors out when constructed with numbers with 15+ digits. It
can accept strings to preserve digits.
- formatAmount in
`ui/pages/confirmations/components/simulation-details/formatAmount.ts`
utilizes Intl.NumberFormat, which requires a BigInt or number passed to
it causing a loss in precision when computing large numbers. It does not
accept strings. Currently, it will display 0s for the digits after 15
digits.
e.g. 30001231231212312138768 → 30,001,231,231,212,312,000,000
Issue ticket to address this
#25755

1. run `yarn storybook`
2. go to
http://localhost:6006/?path=/story/pages-confirmations-confirm-signatures-signedtypeddatav3orv4--permit-story&args=msgParams.data:3.0001231231212312e+22
3. copy and paste the following into data
```
"{\"types\":{\"EIP712Domain\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"version\",\"type\":\"string\"},{\"name\":\"chainId\",\"type\":\"uint256\"},{\"name\":\"verifyingContract\",\"type\":\"address\"}],\"Permit\":[{\"name\":\"owner\",\"type\":\"address\"},{\"name\":\"spender\",\"type\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\"},{\"name\":\"nonce\",\"type\":\"uint256\"},{\"name\":\"deadline\",\"type\":\"uint256\"}]},\"primaryType\":\"Permit\",\"domain\":{\"name\":\"MyToken\",\"version\":\"1\",\"verifyingContract\":\"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC\",\"chainId\":1},\"message\":{\"owner\":\"0x935e73edb9ff52e23bac7f7e043a1ecd06d05477\",\"spender\":\"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4\",\"value\":30001231231212312138768,\"nonce\":0,\"deadline\":50000000000}}"
```

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

![CleanShot 2024-07-10 at 01 14
52](https://github.com/MetaMask/metamask-extension/assets/20778143/7a7ff9e3-07a9-4a3b-b8f4-7f672998cdab)

![CleanShot 2024-07-11 at 00 37
25@2x](https://github.com/MetaMask/metamask-extension/assets/20778143/df6b1f0e-fa12-4b6e-9ae1-0486feb7571a)
![CleanShot 2024-07-11 at 00 37
37@2x](https://github.com/MetaMask/metamask-extension/assets/20778143/faffb8e0-6eae-4ef9-8f3b-c399b7f9f7ae)

- [ ] 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.

- [ ] 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.
digiwand added a commit that referenced this issue Jul 12, 2024
…25741)

<!--
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.
-->

Plan is to cherry-pick this PR for V12.1
- Adds ellipsis to Permit value
- Fixes error:
```
BigNumber Error: new BigNumber() number type has more than 15 significant digits
```

Note that the precision is lost through formatAmount. Fix will be added
#25755

Most file updates are snapshot updates

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

Fixes: MetaMask/MetaMask-planning#2730
(ellipsis)
Fixes: #25751
(Error)

- `JSON.parse` coerces number values into scientific notation if they
are greater than Number.MAX_SAFE_INTEGER, which is the max safe integer
in JavaScript.
e.g. 30001231231212312138768 → 3.0001231231212312e+22
- `JSON.parse` reviver cannot help since the value will be coerced by
the time it
 reaches the reviver function.
- We preserve the value by extracting the value with a regex and
overwriting the `JSON.parse` value. The preserved value should never be
converted to a JavaScript number since it will lose its precision.
Instead, we can preserve the value as a string, BigNumber, or Numeric
type. BigInt also has rounding limitations.
- BigNumber errors out when constructed with numbers with 15+ digits. It
can accept strings to preserve digits.
- formatAmount in
`ui/pages/confirmations/components/simulation-details/formatAmount.ts`
utilizes Intl.NumberFormat, which requires a BigInt or number passed to
it causing a loss in precision when computing large numbers. It does not
accept strings. Currently, it will display 0s for the digits after 15
digits.
e.g. 30001231231212312138768 → 30,001,231,231,212,312,000,000
Issue ticket to address this
#25755

1. run `yarn storybook`
2. go to
http://localhost:6006/?path=/story/pages-confirmations-confirm-signatures-signedtypeddatav3orv4--permit-story&args=msgParams.data:3.0001231231212312e+22
3. copy and paste the following into data
```
"{\"types\":{\"EIP712Domain\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"version\",\"type\":\"string\"},{\"name\":\"chainId\",\"type\":\"uint256\"},{\"name\":\"verifyingContract\",\"type\":\"address\"}],\"Permit\":[{\"name\":\"owner\",\"type\":\"address\"},{\"name\":\"spender\",\"type\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\"},{\"name\":\"nonce\",\"type\":\"uint256\"},{\"name\":\"deadline\",\"type\":\"uint256\"}]},\"primaryType\":\"Permit\",\"domain\":{\"name\":\"MyToken\",\"version\":\"1\",\"verifyingContract\":\"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC\",\"chainId\":1},\"message\":{\"owner\":\"0x935e73edb9ff52e23bac7f7e043a1ecd06d05477\",\"spender\":\"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4\",\"value\":30001231231212312138768,\"nonce\":0,\"deadline\":50000000000}}"
```

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

![CleanShot 2024-07-10 at 01 14
52](https://github.com/MetaMask/metamask-extension/assets/20778143/7a7ff9e3-07a9-4a3b-b8f4-7f672998cdab)

![CleanShot 2024-07-11 at 00 37
25@2x](https://github.com/MetaMask/metamask-extension/assets/20778143/df6b1f0e-fa12-4b6e-9ae1-0486feb7571a)
![CleanShot 2024-07-11 at 00 37
37@2x](https://github.com/MetaMask/metamask-extension/assets/20778143/faffb8e0-6eae-4ef9-8f3b-c399b7f9f7ae)

- [ ] 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.

- [ ] 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.
montelaidev pushed a commit that referenced this issue Jul 12, 2024
…25741)

<!--
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**

Plan is to cherry-pick this PR for V12.1
- Adds ellipsis to Permit value
- Fixes error: 
```    
BigNumber Error: new BigNumber() number type has more than 15 significant digits
```

Note that the precision is lost through formatAmount. Fix will be added
#25755

Most file updates are snapshot updates

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

## **Related issues**

Fixes: MetaMask/MetaMask-planning#2730
(ellipsis)
Fixes: #25751
(Error)

## Technical Details

- `JSON.parse` coerces number values into scientific notation if they
are greater than Number.MAX_SAFE_INTEGER, which is the max safe integer
in JavaScript.
e.g. 30001231231212312138768 → 3.0001231231212312e+22
- `JSON.parse` reviver cannot help since the value will be coerced by
the time it
 reaches the reviver function.
- We preserve the value by extracting the value with a regex and
overwriting the `JSON.parse` value. The preserved value should never be
converted to a JavaScript number since it will lose its precision.
Instead, we can preserve the value as a string, BigNumber, or Numeric
type. BigInt also has rounding limitations.
- BigNumber errors out when constructed with numbers with 15+ digits. It
can accept strings to preserve digits.
- formatAmount in
`ui/pages/confirmations/components/simulation-details/formatAmount.ts`
utilizes Intl.NumberFormat, which requires a BigInt or number passed to
it causing a loss in precision when computing large numbers. It does not
accept strings. Currently, it will display 0s for the digits after 15
digits.
e.g. 30001231231212312138768 → 30,001,231,231,212,312,000,000
Issue ticket to address this
#25755

## **Manual testing steps**

1. run `yarn storybook`
2. go to
http://localhost:6006/?path=/story/pages-confirmations-confirm-signatures-signedtypeddatav3orv4--permit-story&args=msgParams.data:3.0001231231212312e+22
3. copy and paste the following into data
```
"{\"types\":{\"EIP712Domain\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"version\",\"type\":\"string\"},{\"name\":\"chainId\",\"type\":\"uint256\"},{\"name\":\"verifyingContract\",\"type\":\"address\"}],\"Permit\":[{\"name\":\"owner\",\"type\":\"address\"},{\"name\":\"spender\",\"type\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\"},{\"name\":\"nonce\",\"type\":\"uint256\"},{\"name\":\"deadline\",\"type\":\"uint256\"}]},\"primaryType\":\"Permit\",\"domain\":{\"name\":\"MyToken\",\"version\":\"1\",\"verifyingContract\":\"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC\",\"chainId\":1},\"message\":{\"owner\":\"0x935e73edb9ff52e23bac7f7e043a1ecd06d05477\",\"spender\":\"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4\",\"value\":30001231231212312138768,\"nonce\":0,\"deadline\":50000000000}}"
```

## **Screenshots/Recordings**

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

### **Before**

 
![CleanShot 2024-07-10 at 01 14
52](https://github.com/MetaMask/metamask-extension/assets/20778143/7a7ff9e3-07a9-4a3b-b8f4-7f672998cdab)


### **After**

![CleanShot 2024-07-11 at 00 37
25@2x](https://github.com/MetaMask/metamask-extension/assets/20778143/df6b1f0e-fa12-4b6e-9ae1-0486feb7571a)
![CleanShot 2024-07-11 at 00 37
37@2x](https://github.com/MetaMask/metamask-extension/assets/20778143/faffb8e0-6eae-4ef9-8f3b-c399b7f9f7ae)



## **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.
@gauthierpetetin gauthierpetetin added the Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. label Jul 15, 2024
@gauthierpetetin
Copy link
Contributor

Can this issue be closed? (since this PR's been merged)

@jpuri jpuri self-assigned this Jul 19, 2024
@github-project-automation github-project-automation bot moved this from To be fixed to Fixed in Bugs by severity Jul 26, 2024
@github-project-automation github-project-automation bot moved this from To be fixed to Fixed in Bugs by team Jul 26, 2024
@metamaskbot metamaskbot added the release-12.4.0 Issue or pull request that will be included in release 12.4.0 label Jul 26, 2024
@gauthierpetetin gauthierpetetin added regression-RC-12.1.0 and removed regression-prod-12.1.0 Regression bug that was found in production in release 12.1.0 labels Jul 30, 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 / cc: @jpuri

@metamaskbot metamaskbot added the release-12.1.0 Issue or pull request that will be included in release 12.1.0 label Aug 19, 2024
@metamaskbot
Copy link
Collaborator

Missing release label release-12.1.0 on issue. Adding release label release-12.1.0 on issue, as issue is linked to PR #25968 which has this release label.

@digiwand digiwand removed the release-12.4.0 Issue or pull request that will be included in release 12.4.0 label Aug 20, 2024
@digiwand
Copy link
Contributor Author

Hi @benjisclowder, thanks for reaching out and the information for this! @jpuri did create the fix for the specific precision error. I do have details on its cause, so I can provide the RCA here. @jpuri feel free to edit or update this as you see fit as well

  1. What PR fixed the issue?
    Fix BigNumber() more than 15 digits error: fix: Error: new BigNumber() more than 15 digits feat: apply ellipsis #25741
    &
    Fix value precision for large values: fix: change in number format to fix loss of precision for very big values #25968

  2. Can you pinpoint the commit from which the issue originated?
    Generally, Redesigned Confirmations (new UI created 2024) has been built to display entire values rather than their scientific notation forms. Old confirmations would display the scientific notation form (e.g. 3.0001231231212312e+22). Since I believe the precision bug has existed since the Redesigned Confirmation's inauguration, I cannot pinpoint its exact origin commit. I can however add...

    BigNumber() more than 15 digits error has been a common bug that has appeared in various parts of the codebase dating back even years. There have been past workarounds which included turning inputs into strings (which may result in loss of precision) or not accepting large inputs. In this context, I think the error was created here: #25438 line 55. We added a calculation that could result in a large number being passed to BigNumber. Fixing this error uncovered the precision error.

    re: precision - feat: reduce the number of decimals shown for simulation detail amounts #24036 - This PR introduces the formatAmount method we use to display values for the signature redesign. Notice that in the tests, we didn't test numbers greater than the JavaScript MAX_SAFE_INTEGER. If we created tests for these large values, we might have noticed the precision error earlier on.

    console showing largest tested value in PR is below MAX_SAFE_INTEGER:

    > Number.MAX_SAFE_INTEGER
    > 9007199254740991
    > 1213098292340944.5 < Number.MAX_SAFE_INTEGER
    > true
    
  3. Write a short explanation of the technical cause of the bug
    Please see "Technical Details" in fix: Error: new BigNumber() more than 15 digits feat: apply ellipsis #25741

  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, testing large numbers greater than MAX_SAFE_INTEGER where they may exist.
    4.2. Were there any other elements lacking, such as typed code, comprehensive documentation, well-architected APIs, etc., that might have prevented this issue?
    We have various coding patterns to handle numbers. Deciding between Numeric, BigNumber, or other number-value types isn't clear. The libraries can easily be mishandled. e.g. If a large number could be passed to BigNumber it could break the application, but there is no lint warning. As a counter-example, if a string-number value was passed to BigNumber, there would be no runtime error that could break the application.
    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
regression-RC-12.1.0 release-12.1.0 Issue or pull request that will be included in release 12.1.0 Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. team-confirmations Push issues to confirmations team type-bug
Projects
Archived in project
5 participants