wormhole-foundation / wormhole-connect

Wormhole Connect brings all the functionality and utility of Wormhole right into your application and removes all of the complexity.
https://connect-in-style.wormhole.com/
Other
78 stars 58 forks source link

[Bug] Wrong provider returned after rejecting a TX and swapping chains #1769

Open kev1n-peters opened 6 months ago

kev1n-peters commented 6 months ago

Steps to reproduce:

Approve a TX for any route and then reject the TX from Metamask. Now swap the chains and approve the TX again. Notice that wh.mustGetProvider(sourceChain) and wh.mustGetProvider(targetChain) are the same provider (have the same EVM chain ID).

kev1n-peters commented 6 months ago

I suspect that registerSigner is setting the source chain's provider as a reference to signer.provider which is problematic when switching chains (because different chains reference the same provider). https://github.com/wormhole-foundation/wormhole-connect/blob/f52e719da48d81c8e5bb2630445aa0ef94bf3203/wormhole-connect/src/utils/wallet/index.ts#L65. Calling wh.registerProviders() before switching chains fixes this, but it seems like a potential bug in the @nomad-xyz/multi-provider package.

kev1n-peters commented 6 months ago

The issue stems from the @nomad-xyz/multi-provider package. When calling registerSigner, if the call to signer.connect fails, then the provider for the domain will be set to signer.provider. https://github.com/nomad-xyz/monorepo/blob/9b6f68278cf687f9f19065d52b0fac6a128346b1/packages/multi-provider/src/provider.ts#L242-L256 This is an issue, because signer.provider may be connected to a chain different than the domain. This is the exception thrown when signer.connect is called: https://github.com/ethers-io/ethers.js/issues/1088#issuecomment-704347898