ethereum / pyrlp

The python RLP serialization library
MIT License
99 stars 287 forks source link

rlp decode cant support decode EIP1559 rawtransaction #139

Open CaiJiJi opened 1 year ago

CaiJiJi commented 1 year ago

import rlp
from eth_typing import HexStr
from eth_utils import to_bytes

def hex_to_bytes(data: str) -> bytes:
    return to_bytes(hexstr=HexStr(data))

signed_transaction = '0x02f86b0580847735940085012a05f2008252089498b6ded3b7f2268e2ff997ff9371fdb11945838e7b80c080a0ea398ca69a80cdc2f11106717b1168db06503759c37e2e2fbb525d474fe4750ca00568d8b50e6e162cae79535541c367e05e80122c4f3647dea0aeff19995cd9a0'

tx = rlp.decode(hex_to_bytes(signed_transaction))

Error info

rlp.exceptions.DecodingError: RLP string ends with 109 superfluous bytes

But on https://rawtxdecode.in/

decode result is right

image

eerkaijun commented 8 months ago

EIP1559 transactions use the first byte as the typed transaction envelope (refer to https://eips.ethereum.org/EIPS/eip-2718). Therefore to decode the RLP correctly, you'll need to remove the first byte (i.e. 02 in your case).

Using your above example, 0xf86b0580847735940085012a05f2008252089498b6ded3b7f2268e2ff997ff9371fdb11945838e7b80c080a0ea398ca69a80cdc2f11106717b1168db06503759c37e2e2fbb525d474fe4750ca00568d8b50e6e162cae79535541c367e05e80122c4f3647dea0aeff19995cd9a0 should decode correctly.