2

When I execute this:

bytes8 h = 0x000008dfe2f440000733c; t.call.gas(0x7e0b0)(bytes4(keccak256("enter(bytes8)")),0x8dfe2f440000733c0000000,h); 

the calldata is :

0: 0x3370204e000000000000000000000000000000000000000008dfe2f440000733c00000008dfe2f440000733c000000000000000000000000000000000000000000000000 

I split it by 32bytes:

3370204e000000000000000000000000000000000000000008dfe2f440000733 c00000008dfe2f440000733c0000000000000000000000000000000000000000 00000000 

Why is this?

3
  • 3
    The function selector is always 4 bytes, so that's in its own "slot" Commented Sep 20, 2018 at 10:33
  • This question demonstrates the padding in calldata, as @Mikhail answers. The actual call doesn't make usual sense because enter is a function that only has one parameter, so naively h typically won't be used. Commented Nov 14, 2019 at 8:48
  • How to find out the maximum size of the calldata? Commented Mar 16, 2021 at 10:05

2 Answers 2

3
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.

2

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.