when I execute this:

bytes8 h = 0x000008dfe2f440000733c;

the calldata is :

0: 0x3370204e000000000000000000000000000000000000000008dfe2f440000733c00000008dfe2f440000733c000000000000000000000000000000000000000000000000

I split it by 32bytes:

3370204e000000000000000000000000000000000000000008dfe2f440000733 c00000008dfe2f440000733c0000000000000000000000000000000000000000

Why is this?

  • 1
    The function selector is always 4 bytes, so that's in its own "slot" – libertylocked Sep 20 '18 at 10:33

Like @libertylocked said in their comment, the function selector is 4 bytes, so you have to remove those 4 bytes before splitting by 32 bytes to get the individual words.

3370204e // bytes4(keccak256("enter(bytes8)"))
000000000000000000000000000000000000000008dfe2f440000733c0000000 // 0x8dfe2f440000733c0000000 uint96 padded to 32 bytes
8dfe2f440000733c000000000000000000000000000000000000000000000000 // 0x000008dfe2f440000733c bytes8 padded to 32 bytes

From documentation:

Furthermore, to interface with contracts that do not adhere to the ABI, the function call is provided which takes an arbitrary number of arguments of any type. These arguments are padded to 32 bytes and concatenated. One exception is the case where the first argument is encoded to exactly four bytes. In this case, it is not padded to allow the use of function signatures here.

Note that uintN is left padded and bytesN is right padded. From documentation:

uint<M>: enc(X) is the big-endian encoding of X, padded on the higher-order (left) side with zero-bytes such that the length is 32 bytes.

bytes<M>: enc(X) is the sequence of bytes in X padded with trailing zero-bytes to a length of 32 bytes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.