Closed JanRuettinger closed 1 year ago
I apologize for the late response here @JanRuettinger but it looks like this was an outdated version of eth-abi
. I'm actually not sure that [bad assumption, see next comments for answer]bytes32[]
is the right type for this call. I believe these are integers.
>>> from eth_abi import abi
>>> from eth_utils import to_bytes
>>> raw_output_hex = "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000006aeaeff8cc50ece0000000000000000000000000000000000000000000000000000000000000000"
>>> output_bytes = to_bytes(hexstr=raw_output_hex)
>>> abi.decode(["uint256[]"], output_bytes)
((64, 128),)
>>> # with bytes32[]
>>> abi.decode(["bytes[]"], output_bytes)
((b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@',
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80'),)
I'm going to close this as I can't reproduce with the latest version. But please ask to re-open if there are still any issues.
Oh I see. That is my mistake for using bytes32[]
and not bytes[]
. I can reproduce what you have there but are you sure this is the type you need? Are you sure these aren't integers to decode to? [see next comment]
I did some snooping and looked for bytes[]
return types on the methods in that contract and I do see that it was a call to multicall(uint256,bytes[])
which matches the function signature on that call.
However, what eth-abi returns is exactly what Solidity returns, so I don't see a bug here.
function decode(bytes memory _bytes) external pure returns (bytes[] memory) {
bytes[] memory _decoded = abi.decode(_bytes, (bytes[]));
return _decoded;
}
This is what I get as the return, notice the 0x
(b""
) at the end of the array
"bytes[]: 0x00000000000000000000000000000000000000000000000006aeaeff8cc50ece,0x"
edit: It looks like Action [13]
in that trace link you sent (the very last trace) is actually the call with 0x
. multicall(uint256,bytes[])
iterates on each value passed in to it and makes a call with each of them. That's why you only see one of the arguments in the next step... and you see the second argument in another step. Hope that clarifies what you were seeing.
What was wrong?
Can't decode type 'bytes[]' properly using the eth_abi.decode function. Instead of one, two elements of type byte are returned whereas the second element is always empty.
Code that produced the error
Expected Result
Environment