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]: Wrong token amount for vUSDC minting and withdrawing on Venus #26521

Closed
bschorchit opened this issue Aug 19, 2024 · 3 comments · Fixed by MetaMask/core#4775
Closed

[Bug]: Wrong token amount for vUSDC minting and withdrawing on Venus #26521

bschorchit opened this issue Aug 19, 2024 · 3 comments · Fixed by MetaMask/core#4775
Assignees
Labels
regression-prod-12.0.0 Regression bug that was found in production in release 12.0.0 Sev2-normal Normal severity; minor loss of service or inconvenience. team-transactions Transactions team type-bug

Comments

@bschorchit
Copy link

bschorchit commented Aug 19, 2024

Describe the bug

Wrong token amount and fiat price displayed for minting and withdrawing vUSDC on Venus

Expected behavior

Display accurate token amount and fiat price for vUSDC - currently 1 USDC = 41.131844 vUSDC

Screenshots/Recordings

Screenshot 2024-08-19 at 15 22 32

Steps to reproduce

  1. Have USDC on BNB chain
  2. Go to https://app.venus.io/#/core-pool/market/0xecA88125a5ADbe82614ffC12D0DB554E2e2867C8?chainId=56
  3. Approve USDC spending
  4. Click on Supply USDC
  5. Notice the estimated changes displayed within MM confirmation

Error messages or log output

No response

Detection stage

In production (default)

Version

12.0.0

Build type

None

Browser

Brave

Operating system

MacOS

Hardware wallet

No response

Additional context

No response

Severity

No response

@bschorchit bschorchit added type-bug Sev2-normal Normal severity; minor loss of service or inconvenience. team-confirmations Push issues to confirmations team labels Aug 19, 2024
@github-project-automation github-project-automation bot moved this to To be fixed in Bugs by team Aug 19, 2024
@github-project-automation github-project-automation bot moved this to To be fixed in Bugs by severity Aug 19, 2024
@metamaskbot metamaskbot added the regression-prod-12.0.0 Regression bug that was found in production in release 12.0.0 label Aug 19, 2024
@jpuri jpuri self-assigned this Aug 21, 2024
@jpuri
Copy link
Contributor

jpuri commented Aug 26, 2024

After debugging I found that issue in this case is simulation api returning erroneous data.

@jpuri jpuri removed their assignment Aug 28, 2024
@bschorchit bschorchit added team-transactions Transactions team and removed team-confirmations Push issues to confirmations team labels Aug 28, 2024
@dbrans
Copy link
Contributor

dbrans commented Sep 17, 2024

When querying token balances via RPC calls (e.g., eth_call to balanceOf), the response includes extra zeros appended to the actual balance value.

Affected Chains (so far):

  • BNB Chain (BSC)
  • Optimism (reported for OP token – appears to be a similar issue)

Example from BNB Chain:

curl 'https://bsc-dataseed1.binance.org/' \
  // headers removed for brevity
  --data-raw '{"jsonrpc":"2.0","id":169618779484965,"method":"eth_call","params":[{"from":"0x0000000000000000000000000000000000000000","data":"0x70a082310000000000000000000000003424b949dbc5d2d2654cb6fc622c4d723b2e8fb4","to":"0xeca88125a5adbe82614ffc12d0db554e2e2867c8"},"latest"]}'

Response:

{"jsonrpc":"2.0","id":169618779484965,"result":"0x000000000000000000000000000000000000000000000000000000134c31d25200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}
  • The first 32 bytes (64 characters after '0x') represent the correct balance: 000000000000000000000000000000000000000000000000000000134c31d252
  • This decodes to the expected decimal value: 82882712146
  • An additional 64 bytes (128 characters) of zeros are appended to the response

Verification of contract code:

The smart contract implementation of balanceOf is correct and, after delegating to an implementation, returns the proper value. Here's a simulation trace on tenderly.

The balance reported by block explorers (e.g., BscScan) matches the decoded value from the first 32 bytes of the RPC response

image

Analysis

The issue likely stems from the RPC node implementation or configuration, not from the client, simulations api, or smart contracts themselves

The problem affecting multiple chains suggests it might be related to common infrastructure or software these chains are using.

Next steps

  1. Workaround in simulation API
    While this padding is unusual, the correct data appears to still be returned. In the short-term, we could handle this extra padding in the simulation api by removing extra padding.
  2. Report to Chain Teams:
    Submit detailed bug reports to both the BNB Chain and Optimism teams.
  3. Community Awareness:
    Share findings with the broader blockchain developer community. This can help identify if other chains or tokens are affected and pool resources for a solution

@dbrans
Copy link
Contributor

dbrans commented Sep 18, 2024

Nick Hewitt noticed that if you go to the debugger it shows the raw output which matches geth:

[RAW_OUTPUT]":"0x000000000000000000000000000000000000000000000000000000134c31d25200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"

@dbrans dbrans self-assigned this Oct 8, 2024
dbrans added a commit to MetaMask/core that referenced this issue Oct 15, 2024
… changes (#4775)

## Explanation
* Use contract abi's to decode the amounts of token balance changes
– instead of the raw output from a balanceOf call.

## References

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

* Fixes: MetaMask/metamask-extension#26521

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/transaction-controller`

- **FIXED**: Use contract abi's to decode the amounts of token balance
changes – instead of the raw output from a balanceOf call.
## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
@github-project-automation github-project-automation bot moved this from To be fixed to Fixed in Bugs by team Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-prod-12.0.0 Regression bug that was found in production in release 12.0.0 Sev2-normal Normal severity; minor loss of service or inconvenience. team-transactions Transactions team type-bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants