esaulpaugh / headlong

High-performance Contract ABI and RLP for Ethereum
Apache License 2.0
79 stars 20 forks source link

Issues decoding an Opensea `atomicMatch_` function call #41

Closed hawkaa closed 2 years ago

hawkaa commented 2 years ago

Hi @esaulpaugh ,

Thanks again for an amazing library!

I'm trying to decode the following.

Input Data:

0xab834bab0000000000000000000000007f268357a8c2552623316e2562d90e642bb538e50000000000000000000000002dba09471e78d26e42cc9b6057745bb0d430e38500000000000000000000000000000000000000000000000000000000000000000000000000000000000000005b3256965e7c3cf26e11fcaf296dfc8807c01073000000000000000000000000baf2127b49fc93cbca6269fade0f7f31df4c88a70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000007f268357a8c2552623316e2562d90e642bb538e5000000000000000000000000847236b8c34259a9bed67dcc1647cffba8fc01d40000000000000000000000002dba09471e78d26e42cc9b6057745bb0d430e3850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000baf2127b49fc93cbca6269fade0f7f31df4c88a70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001ba800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062727d6c000000000000000000000000000000000000000000000000000000006272b5fcba245d25e4e86afcbaf548aa790555f3467f38ba3078a2be2d7c057debc92214000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001ba8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000627285c000000000000000000000000000000000000000000000000000000000000000006ff1fad6168460880a98b326f4c38e93fba0037fbe4fadf60939acddf28990510000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000006a000000000000000000000000000000000000000000000000000000000000007c000000000000000000000000000000000000000000000000000000000000008e00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000b200000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001c099ee735236c1090e9eb80abde0b4ca69c81f84ba9deeab8710d7df0792ca90a1d302e1894b6bb588ab14ddf4c8c4218c30893ec9f622e7e019af865a0e96f1a099ee735236c1090e9eb80abde0b4ca69c81f84ba9deeab8710d7df0792ca90a1d302e1894b6bb588ab14ddf4c8c4218c30893ec9f622e7e019af865a0e96f1a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4fb16a59500000000000000000000000000000000000000000000000000000000000000000000000000000000000000002dba09471e78d26e42cc9b6057745bb0d430e3850000000000000000000000007d8820fa92eb1584636f4f5b8515b5476b75171a0000000000000000000000000000000000000000000000000000000000000d3d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4fb16a595000000000000000000000000847236b8c34259a9bed67dcc1647cffba8fc01d400000000000000000000000000000000000000000000000000000000000000000000000000000000000000007d8820fa92eb1584636f4f5b8515b5476b75171a0000000000000000000000000000000000000000000000000000000000000d3d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e400000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

ABI:

{
  "constant": false,
  "inputs": [
    {
      "name": "addrs",
      "type": "address[14]"
    },
    {
      "name": "uints",
      "type": "uint256[18]"
    },
    {
      "name": "feeMethodsSidesKindsHowToCalls",
      "type": "uint8[8]"
    },
    {
      "name": "calldataBuy",
      "type": "bytes"
    },
    {
      "name": "calldataSell",
      "type": "bytes"
    },
    {
      "name": "replacementPatternBuy",
      "type": "bytes"
    },
    {
      "name": "replacementPatternSell",
      "type": "bytes"
    },
    {
      "name": "staticExtradataBuy",
      "type": "bytes"
    },
    {
      "name": "staticExtradataSell",
      "type": "bytes"
    },
    {
      "name": "vs",
      "type": "uint8[2]"
    },
    {
      "name": "rssMetadata",
      "type": "bytes32[5]"
    }
  ],
  "name": "atomicMatch_",
  "outputs": [],
  "payable": true,
  "stateMutability": "payable",
  "type": "function"
}

However, I get the following error:

illegal backwards jump: (4+2368=2372)<2884
java.lang.IllegalArgumentException: illegal backwards jump: (4+2368=2372)<2884
    at com.esaulpaugh.headlong.abi.TupleType.decodeObjects(TupleType.java:307)
    at com.esaulpaugh.headlong.abi.TupleType.decode(TupleType.java:194)
    at com.esaulpaugh.headlong.abi.Function.decodeCall(Function.java:230)

Do you happen to know why? The reason why I ask is that geth seems to be able to decode it.

Thank you!

hawkaa commented 2 years ago

Data is from transaction 0x1fc5750f695708ea56d61ef204dfe6385414d03f0d0496d6bdc50c24813b1881, trace address 1, 1, 0, 3, 2, 4 on the ethereum mainnet by the way!

esaulpaugh commented 2 years ago

If you comment out the line throwing the exception, does it decode correctly? Meaning, can you tell if the resulting data is malformed in any way?

esaulpaugh commented 2 years ago

The data looks alright to me.

It looks like they are reusing a 32-byte portion of a previous element's data (index 5) to act as the array length for a later element (an empty array at index 8) because it is all zeros.

I knew such things were possible, but I wanted to see it in the wild before I allowed it.

I think I will just allow all backwards jumps.

esaulpaugh commented 2 years ago

The original intent was to fail fast if any potential data corruption was detected, but that's only useful for certain use cases. If anyone finds this behavior useful they can fork the code and add the check back in.

I will see about releasing this change soon.

hawkaa commented 2 years ago

The original intent was to fail fast if any potential data corruption was detected, but that's only useful for certain use cases. If anyone finds this behavior useful they can fork the code and add the check back in.

I will see about releasing this change soon.

Thanks a ton, Evan!

esaulpaugh commented 2 years ago

New release:

https://github.com/esaulpaugh/headlong/releases/tag/v6.3.0 https://repo1.maven.org/maven2/com/esaulpaugh/headlong/6.3.0/