Solidity 0.4.25.
Consider this code
contract A{
function test() public view returns (bytes){
bytes memory output = abi.encodePacked(bytes32(1));
return output;
}
}
The returned data is:
0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000001
If you look at how bytes are laid out in memory then the first bytes32 is the length of the bytes (in numbers of bytes, e.g. a bytes with 32 bytes length has 0x20 on the first bytes32 padded left). However apparently this returndata has TWO 0x20's in it. If you expand the length of the returned bytes the first bytes32 still stays 0x20.
I don't get why this is. What is the purpose of this 0x20? Is this a solidity bug or does it have any purpose?
The expected returndata would be:
0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000001