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]: Cannot get the latest value after switching the network #25097

Closed
coding-ice opened this issue Jun 6, 2024 · 21 comments · Fixed by MetaMask/core#4388
Closed

[Bug]: Cannot get the latest value after switching the network #25097

coding-ice opened this issue Jun 6, 2024 · 21 comments · Fixed by MetaMask/core#4388
Labels
external-contributor regression-prod-11.16.7 Regression bug that was found in production in release 11.16.7 Sev2-normal Normal severity; minor loss of service or inconvenience. team-wallet-api-platform type-bug

Comments

@coding-ice
Copy link

coding-ice commented Jun 6, 2024

Describe the bug

Cannot get the latest value after switching the network
link: https://stackblitz.com/edit/vitejs-vite-9rayvh?file=src%2FApp.tsx

Expected behavior

correct version: 11.14.5 - x

No response

Screenshots/Recordings

No response

Steps to reproduce

  1. Click button change to BNB chain.
  2. Switch metamask to other chain.
  3. Can't get the latest value.

Error messages or log output

No response

Version

11.16.7

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 team Jun 6, 2024
@github-project-automation github-project-automation bot moved this to To be fixed in Bugs by severity Jun 6, 2024
@metamaskbot metamaskbot added external-contributor regression-prod-11.16.7 Regression bug that was found in production in release 11.16.7 labels Jun 6, 2024
@disappearer
Copy link

disappearer commented Jun 6, 2024

I can confirm this. Our app heavily relies on network switching and this issue is making it unusable with MetaMask. This was working a few days ago.

@coding-ice
Copy link
Author

Please check as soon as possible, thanks.

@gauthierpetetin gauthierpetetin added team-wallet-api-platform Sev2-normal Normal severity; minor loss of service or inconvenience. labels Jun 6, 2024
@adonesky1
Copy link
Contributor

adonesky1 commented Jun 6, 2024

Hey @coding-ice thanks for your report here. We have a fix for this issue that is rolling out with version 11.16.7

Edit: Actually you are reporting that you are seeing this on 11.16.7... We'll take a look!

@adonesky1
Copy link
Contributor

Can you explain what you mean by "Cannot get the latest value"? Do you mean if you call eth_chain you are not receive any response? Or you're not seeing the correct response?

@tmm
Copy link

tmm commented Jun 6, 2024

Reproducible via running RPC requests in the browser console. More info in this comment wevm/wagmi#3998 (comment)

// start with extension on mainnet, then request accounts:
> await window.ethereum.request({ method: 'eth_requestAccounts' })
[...]
> await window.ethereum.request({ method: 'eth_chainId' })
'0x1'
> await window.ethereum.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: '0x89' }] })
> await window.ethereum.request({ method: 'eth_chainId' })
'0x89'
// switch in extension ui, then run the following:
> await window.ethereum.request({ method: 'eth_chainId' })
'0x89' // should be 0x1

@Gudahtt
Copy link
Member

Gudahtt commented Jun 6, 2024

We have been able to reproduce this bug, and are currently investigating. We will post an update soon.

@Gudahtt
Copy link
Member

Gudahtt commented Jun 6, 2024

We have found the problem, and are preparing a fix. We'll have this released as soon as we can.

@coding-ice
Copy link
Author

coding-ice commented Jun 7, 2024

ok,thanks a lot~

@c0da523
Copy link

c0da523 commented Jun 7, 2024

Reproducible via running RPC requests in the browser console. More info in this comment wevm/wagmi#3998 (comment)

// start with extension on mainnet, then request accounts:
> await window.ethereum.request({ method: 'eth_requestAccounts' })
[...]
> await window.ethereum.request({ method: 'eth_chainId' })
'0x1'
> await window.ethereum.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: '0x89' }] })
> await window.ethereum.request({ method: 'eth_chainId' })
'0x89'
// switch in extension ui, then run the following:
> await window.ethereum.request({ method: 'eth_chainId' })
'0x89' // should be 0x1

I met this problem too.I thought there are somewhere cached in my browser.

a hack to resolve this problem

window.ethereum.on('chainChanged', async (chainId) => {
  console.log('Network changed to:', chainId);

  window.ethereum.request({
    method: 'wallet_switchEthereumChain',
    params: [{ chainId }],
  });
  const currentChainId = await window.ethereum.request({
    method: 'eth_chainId',
    params: [],
  });
  console.log('Current chainId from ethereum request:', currentChainId);

  // window.location.reload();
});

@Sotatek-ToanHa
Copy link

please we are also having the same problem

@adonesky1
Copy link
Contributor

Thank you for your patience. A fix will be released with 11.16.8. Should be going live today!

@danjm
Copy link
Contributor

danjm commented Jun 7, 2024

The fix for this has been published as part of the 11.16.8 release

You may need to manually update your metamask install to access this fix. https://support.metamask.io/managing-my-wallet/using-metamask/how-to-update-the-version-of-metamask/#:~:text=Chrome%2Dbased%20browsers%3A%20Click%20the,manually%20install%20it%20from%20here.

@jxom
Copy link

jxom commented Jun 7, 2024

For the future, bugs like these should be tagged as sev-critical.

Most libraries perform chainId checks to assert the user is on the right chain before executing a transaction.

@Sotatek-ToanHa
Copy link

Thank you for your patience. A fix will be released with 11.16.8. Should be going live today!

I have found it to work properly. Thank

@matthewlilley
Copy link

matthewlilley commented Jun 8, 2024

For the future, bugs like these should be tagged as sev-critical.

Most libraries perform chainId checks to assert the user is on the right chain before executing a transaction.

Absolutely is a critical bug that caused real users to lose funds. We had a case of a user losing ETH because of this. A synchronicity bug like this is one we fear most, because of the behaviour when a method call is made to a non-contract address with ETH, it will succeed in sending the ETH and will be lost permanently. Damage here could've been substantial.

Any ideas on what we could do to safe guard against bugs like these in future?

jiexi added a commit to MetaMask/core that referenced this issue Jun 10, 2024
…uePreference guard (#4388)

## Explanation

Our previous SelectedNetworkController fix that [added a guard to
permission state changes](#4368)
was not sufficient. This PR properly addresses the underlying issue of
setting networkClientId for domains when the `useRequestQueuePreference`
flag is false by moving the guard into the `setNetworkClientId()` method
itself

## References

* Fixes: MetaMask/metamask-extension#25097

## 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/selected-network-controller`

- **FIXED**: `setNetworkClientId()` will now result in a noop if
`useRequestQueuePreference` is false


## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate

---------

Co-authored-by: Alex Donesky <[email protected]>
@github-project-automation github-project-automation bot moved this from To be fixed to Fixed in Bugs by severity Jun 10, 2024
@simonazhang68
Copy link

I have lost my 0.332eth when I use Across procotol to bridge my eth from zks to other chain use metamask wallet? Who will compensate me? Can I ask metamask refund me? My address is 0x41e3A8766E0FF11eEF0c4D8eBe35a4F8d9772765,last transation hash is 0x912eff9e32127a10acfe325b2a9bcb8a848e401cdf08103ba5f21e9f2e446c24.

@simonazhang68
Copy link

Hey @coding-ice thanks for your report here. We have a fix for this issue that is rolling out with version 11.16.7

Edit: Actually you are reporting that you are seeing this on 11.16.7... We'll take a look!
I have lost my 0.332eth when I use Across procotol to bridge my eth from zks to other chain use metamask wallet? Who will compensate me? Can I ask metamask refund me? My address is 0x41e3A8766E0FF11eEF0c4D8eBe35a4F8d9772765,last transation hash is 0x912eff9e32127a10acfe325b2a9bcb8a848e401cdf08103ba5f21e9f2e446c24.

@MarcelCloud
Copy link

It would help if you also looked into the rabby and metamask sync issue. Rabby has more connection control and it affects interacting with metamask when we have to

@monokh
Copy link

monokh commented Jun 19, 2024

Any ideas on what we could do to safe guard against bugs like these in future?

14 ETH lost on arbitrum, in only one scenario. Granted this is not solely on metamask, but it highlights what is at stake.

Many clients attach a chainId in eth_sendTransaction requests. If the chainId in the request doesn't match the chainId of the connected chain - metamask should reject or give a big warning. This common sense check would have likely prevented loss in the scenario that started this issue.

There should also be a warning when sending ETH with call data to a non existent contract. This again would have raised flags and prevented loss.

@simonazhang68
Copy link

Hey @coding-ice thanks for your report here. We have a fix for this issue that is rolling out with version 11.16.7
Edit: Actually you are reporting that you are seeing this on 11.16.7... We'll take a look!
I have lost my 0.332eth when I use Across procotol to bridge my eth from zks to other chain use metamask wallet? Who will compensate me? Can I ask metamask refund me? My address is 0x41e3A8766E0FF11eEF0c4D8eBe35a4F8d9772765,last transation hash is 0x912eff9e32127a10acfe325b2a9bcb8a848e401cdf08103ba5f21e9f2e446c24.

You have fixed this issue but who will refund my loss? I can't get my money back now!

tiagofilipenunes added a commit to bancorprotocol/carbon-app that referenced this issue Jul 9, 2024
@rosewinlet
Copy link

Many bugs for Metamask nowadays. I regconise these problems also:

  • Chain switching problem like above. Switching chain is quite slow.
  • Some RPC is suspended and metamask spins forever.
  • The transaction was made successfully, but still the dapp connected with Metamask does not recognise, while other wallets like OKX, C98, ... are working very well. This problem just happens for some days.
  • Some signing (only signing) but the token was transacted ( I've losted for more than 2000 usdt equivalent token).

Please take care these problems as soon as possible. We still believe in you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external-contributor regression-prod-11.16.7 Regression bug that was found in production in release 11.16.7 Sev2-normal Normal severity; minor loss of service or inconvenience. team-wallet-api-platform type-bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.