MetaMask / MetaMask/metamask-mobile

[Bug]: Passed transaction nonce is ignored

Open
#9,118 0 comments 1 reaction 0 assignees View on GitHub
external-contributor feature-request INVALID-ISSUE-TEMPLATE team-confirmations Transactions
Dominant language
TypeScript
Stars
3k
Forks
1.7k
Avg merge
1d 14h
Merged PRs (30d)
669

Description

**Describe the bug**

At the safe wallet, we are building a speed up TX function: https://github.com/safe-global/safe-wallet-web/pull/3425
We are polling the RPC for the submitted TX and if we don't find it withing X seconds we offer the option to speed that transaction up. A transaction that needs to be sped up consist of mainly of {to, data, nonce} fields. Nonce is extremely important as it has to be the same as the TX that has been already submitted.
to speed up the transaction we call:
` result = await signer.sendTransaction({ to, data, ...txOptions })`

This works fine with the Metamask Browser Extension, but is buggy when used with Metamask Mobile.
Metamask mobile appears to ignore the provided nonce and just increase the nonce. I've looked around the MM-Mobile code and found where the problem comes from.
There are 2 cases.

**Case 1:**
The user has not enabled "customize transaction nonce" in the settings.
So here despite the fact that we've passed a nonce, the transaction.nonce is being reset to undefined:
https://github.com/MetaMask/metamask-mobile/blob/0e2c734f8c1393a11b9c223bf2b9f805cfa973e2/app/components/Views/confirmations/Approval/index.js#L412
because showCustomNonce is not true.

Please note that the Browser extension actually works fine. If we send a nonce there, it is set as the nonce of the tx that the user is executing. From our perspective the MM-Mobile behaviour is not expected

**Case 2:**
"customize transaction nonce" is set to true. If this option is on, the TransactionReview component renders the TransactionReviewInformation component. On DidMount this component sets the TX nonce to the next network nonce:
https://github.com/MetaMask/metamask-mobile/blob/0e2c734f8c1393a11b9c223bf2b9f805cfa973e2/app/components/Views/confirmations/components/TransactionReview/TransactionReviewInformation/index.js#L251
this now changes the provided transaction nonce, so we effectively end up again ignoring the nonce that the Dapp has provided.

This behaviour is also diverging from the MM Browser extension, where the nonce provided by the dapp is treated as the nonce for the "custom nonce" component.

We think that this behaviour is wrong and MM Mobile should behave as the MM Browser extension

**Expected behavior**

Provided dapp nonce should be used for submitting the TX.

**Steps to reproduce**

1. Go to: https://feat_pending_txs--walletweb.review-wallet-web.5afe.dev/home?safe=eth:0xA77DE01e157f9f57C7c4A326eeE9C4874D0598b6
2. Connect your MM Account
3. Switch to sepolia and deploy a test safe (you can use the sponsored tx)
4. Now try to submit a Transaction
5. Wait for 15 sec you should see a speed up button
![grafik](https://github.com/MetaMask/metamask-mobile/assets/693770/d00ac511-610b-4563-9a01-1702931bca90)
6. Click the button and speed up the TX
![grafik](https://github.com/MetaMask/metamask-mobile/assets/693770/9d0c3251-795a-4cad-ba0d-0536687aa16a)
Note the wallet nonce
7. Notice that on the Review screen in MM the nonce is different:
![grafik](https://github.com/MetaMask/metamask-mobile/assets/693770/15b923a9-3b54-4c30-ba70-a2708c1aa715)

**Version**

7.19.0(1292)

**Build type**

None

**Device**

Iphone and Android

**Operating system**

Other (please elaborate in the "Additional Context" section)

**Additional context**

Ios and Android Problem. Happens both on the current stable versions and with a build directly from the repo.

Contributor guide

Open the contributing guide

Research direction

Start with app/components/Views/confirmations/Approval/index.js and the TransactionReviewInformation entry point mentioned in the report, then reproduce the speed-up flow on iOS or Android using the listed steps. Compare the mobile behavior with the browser extension; done means the nonce supplied by the dapp is retained when the transaction is submitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
blockchain, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.