rust-ethereum / ethabi

Encode and decode smart contract invocations
Apache License 2.0
517 stars 186 forks source link

Issue decoding input data of a function consisting of dynamic arrays #246

Closed Sanghren closed 3 years ago

Sanghren commented 3 years ago

Hello,

am currently trying to decode the following input

0xd7bf98a300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000f00000000000000000000000000000000000000000000000000000000000000002700000000000000000000000000000000000000000000000000000000000004e00000000000000000000000000000000000000000000000000000000000000520000000000000000000000000000000000000000000000000000000000000056000000000000000000000000000000000000000000000000000000000000005a000000000000000000000000000000000000000000000000000000000000005e00000000000000000000000000000000000000000000000000000000000000620000000000000000000000000000000000000000000000000000000000000066000000000000000000000000000000000000000000000000000000000000006a000000000000000000000000000000000000000000000000000000000000006e00000000000000000000000000000000000000000000000000000000000000720000000000000000000000000000000000000000000000000000000000000076000000000000000000000000000000000000000000000000000000000000007a000000000000000000000000000000000000000000000000000000000000007e00000000000000000000000000000000000000000000000000000000000000820000000000000000000000000000000000000000000000000000000000000086000000000000000000000000000000000000000000000000000000000000008a000000000000000000000000000000000000000000000000000000000000008e00000000000000000000000000000000000000000000000000000000000000920000000000000000000000000000000000000000000000000000000000000096000000000000000000000000000000000000000000000000000000000000009a000000000000000000000000000000000000000000000000000000000000009e00000000000000000000000000000000000000000000000000000000000000a200000000000000000000000000000000000000000000000000000000000000a600000000000000000000000000000000000000000000000000000000000000aa00000000000000000000000000000000000000000000000000000000000000ae00000000000000000000000000000000000000000000000000000000000000b200000000000000000000000000000000000000000000000000000000000000b600000000000000000000000000000000000000000000000000000000000000ba00000000000000000000000000000000000000000000000000000000000000be00000000000000000000000000000000000000000000000000000000000000c200000000000000000000000000000000000000000000000000000000000000c600000000000000000000000000000000000000000000000000000000000000ca00000000000000000000000000000000000000000000000000000000000000ce00000000000000000000000000000000000000000000000000000000000000d200000000000000000000000000000000000000000000000000000000000000d600000000000000000000000000000000000000000000000000000000000000da00000000000000000000000000000000000000000000000000000000000000de00000000000000000000000000000000000000000000000000000000000000e200000000000000000000000000000000000000000000000000000000000000e600000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000163000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000027000000000000000000000000000000000000000000000000000000000000001300000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000000000000000000000000000000000000013000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001500000000000000000000000000000000000000000000000000000000000000150000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001700000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000017000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001900000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000019000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001d000000000000000000000000000000000000000000000000000000000000001d000000000000000000000000000000000000000000000000000000000000001d0000000000000000000000000000000000000000000000000000000000001957000000000000000000000000000000000000000000000000000000000000195700000000000000000000000000000000000000000000000000000000000019570000000000000000000000000000000000000000000000000000000000001b710000000000000000000000000000000000000000000000000000000000001b710000000000000000000000000000000000000000000000000000000000001b71

which correspond to this abi :

[
{
    "type": "function",
    "stateMutability": "nonpayable",
    "outputs": [],
    "name": "levelUpAll",
    "inputs": [
      {
        "type": "string[]",
        "name": "structureIds",
        "internalType": "string[]"
      },
      {
        "type": "uint256[]",
        "name": "planetIds",
        "internalType": "uint256[]"
      }
    ]
  }
]

Running it via ethabi decode function abi.json levelUpAll 000000000.... yield nothing .

In my code I do the following :

let abi = {
    let file = File::open("pathtomyabi").expect("failed to open ABI file");
    Abi::from_reader(file).expect("failed to parse ABI")
};
// Where the tx is coming from a call to my node via rust-web3 crate .
let encoded_input = tx.input.clone();
// Decode
let maybe_a_result = abi
    .decode_input_from_slice(&encoded_input.0.as_slice());

The piece of code above always crash with

thread 'tokio-runtime-worker' panicked at 'Integer overflow when casting to usize', /home/tbrunain/.cargo/registry/src/github.com-1ecc6299db9ec823/primitive-types-0.8.0/src/lib.rs:38:1

Any idea if there is something wrong am doing, or if it is a bug in the code ?

(Here is the transaction am trying to decode the input of programatically : https://cchain.explorer.avax.network/tx/0xf2c0a3b014592969546762ad5c49b9644819f7de7f4017e41e398b98d22f94e2/token-transfers)