MetaMask / metamask-mobile

Mobile web browser providing access to websites that use the Ethereum blockchain
https://metamask.io
Other
2.14k stars 1.1k forks source link

[Bug]: Metamask mobile encodes function calls in a wrong way #7901

Closed Sap333 closed 2 months ago

Sap333 commented 10 months ago

Describe the bug

The mobile Metamask (at least on Android) in it's embedded browser encodes all calls to a blockchain in a wrong way. Let's say we use Binance Testnet (id = 97) and smart contract's address is 0x19C9B23c79415A558e29297E579FA37FB725453d.

The ABI is:

[{
    {
        "inputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "name": "achievementPrices",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    }]

Then we call "achievementPrices(0)". And it sends what? It sends the next nonsense:

{                                                                                                                                                                                           
    "id": 2010558494,                                                                                                                                                                       
    "jsonrpc": "2.0",                                                                                                                                                                       
    "method": "eth_call",                                                                                                                                                                   
    "params": [                                                                                                                                                                             
        {                                                                                                                                                                                   
            "from": "0x5e1f7aec9ae688aac9d5aa2600b9feb333e92d87",                                                                                                                           
            "to": "0x19C9B23c79415A558e29297E579FA37FB725453d"                                                                                                                              
        },                                                                                                                                                                                  
        "latest"                                                                                                                                                                            
    ]                                                                                                                                                                                       
}

And then fails with wrong reply error. And the very same code (absolutely and literally same) works properly on a desktop (chrome extension) version.

Expected behavior

The correct encoding would be something like:

{                                                                                                                                                                                           
    "id": 2152987482,                                                                                                                                                                       
    "jsonrpc": "2.0",                                                                                                                                                                       
    "method": "eth_call",                                                                                                                                                                   
    "params": [                                                                                                                                                                             
        {                                                                                                                                                                                   
            "from": "0x5e1f7aec9ae688aac9d5aa2600b9feb333e92d87",                                                                                                                           
            "input": "0x35dc2e960000000000000000000000000000000000000000000000000000000000000000",                                                                                          
            "to": "0x19C9B23c79415A558e29297E579FA37FB725453d"                                                                                                                              
        },                                                                                                                                                                                  
        "0x5d"                                                                                                                                                                              
    ]                                                                                                                                                                                       
}

Screenshots/Recordings

No response

Steps to reproduce

  1. Connect to the injected provider in Metamask mobile's browser. 3. Add and switch to a custom blockchain network (Binance Testnet is Ok but is also fails on a local Ganache testnet).
  2. Load ABI and create a contract instance.
  3. Call and method of the contract.
  4. Get an error about wrong reply.

Error messages or log output

No response

Version

7.10.0 (1187)

Build type

None

Device

Android 11 mobile phone

Operating system

Android

Additional context

I didn't test on a Binance Mainnet and my applications adds a networks and switches to it. Probably this may somehow affect behavior. But it also fails on a Binance Testnet so it must be easy to reproduce.

Severity

Major critical bug which makes the whole application unsable. And the very same code works on a desktop version!

I also attach the full ABI of a smart contract ( 0x19C9B23c79415A558e29297E579FA37FB725453d ) on a Binance Testnet so everyone could easily reproduce the bug. Any call to this smart contract fails (even "registrationFee()" which doesn't require any parameters).

abi.txt

anaamolnar commented 10 months ago

Hello, @Sap333. Thanks for reporting! I will assign this to the appropriate team. They will follow up on this as soon as they can. Thanks for your patience and understanding!

Sap333 commented 10 months ago

I investigated a little bit and found that current mobile Metamask version (for all platforms) doesn't work with "web3-eth" and "web3-eth-contract" npm-package versions higher than 4.0.3, when a DApp is executed form the Metamask's embedded browser. For some reason smart method's parameter encoding becomes completely broken in such case. Desktop version of Metamask and all other mobile wallets work with all versions of "web3-eth" perfectly, which means that the problem is on mobile Metamask's side.

This make current version of mobile Metamask wallet unusable with a big (majority?) number of modern Web3 projects and on all projects that update their code base! Give that the current version "web3-eth" 4.3 the situation becomes worse and worse because Metamask can only work on outdated library version, that has outdated dependencies.

vandan commented 8 months ago

Relates to a discrepancy in the Ethereum Execution APIs: https://github.com/ethereum/execution-apis/issues/507

shanejonas commented 8 months ago

use data not input

vandan commented 8 months ago

Based on developments in this thread: https://github.com/ethereum/execution-apis/issues/507, we may consider resolving this issue by changing the spec to support either data OR input fields in these method calls.

github-actions[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity in the last 90 days. It will be closed in 7 days. Thank you for your contributions.

github-actions[bot] commented 2 months ago

This issue was closed because there has been no follow activity in 7 days. If you feel this was closed in error please provide evidence on the current production app in a new issue or comment in the existing issue to a maintainer. Thank you for your contributions.