0

I manually inserted 2 32 bytes arguments to a function flipSwitch(bytes memory someData) whose function identifier happens to be 0x30c13ade. My manual arguments:

0000000000000000000000000000000000000000000000000000000076227e12
0000000000000000000000000000000000000000000000000000000020606e15

Remix complete calldata:

0x30c13ade
0000000000000000000000000000000000000000000000000000000000000020
0000000000000000000000000000000000000000000000000000000000000044
0000000000000000000000000000000000000000000000000000000076227e12
0000000000000000000000000000000000000000000000000000000020606e15

What are the extra arguments being passed in the calldata, why are they there?

1 Answer 1

1

This is the ABI encoded version of the calldata. The first 4 bytes is the function selector 0x30c13ade.

Then comes the arguments to the function which is a single argument of type bytes since bytes is a dynamic type in the sense that it does not have a fixed length.

To solve this, the first 32 bytes is a reference to the offset of where the actual data is stored in the calldata. In this case the offset is 0x20.

Reading from the offset the first 32 bytes stores the length of argument which is 0x44 (this should actually be 0x40 in this example I'm not sure why you are seeing 0x44). Immediately following the length is the actual data where 0x44 bytes are read.

In summary

0x30c13ade <- function selector
0x00: 0000000000000000000000000000000000000000000000000000000000000020 <- bytes offset
0x20: 0000000000000000000000000000000000000000000000000000000000000044 <- bytes length
0x40: 0000000000000000000000000000000000000000000000000000000076227e12 <- bytes data
0x60: 0000000000000000000000000000000000000000000000000000000020606e15 <- bytes data cont.

For more info I'd read up on ABI encoding of dynamic types in solidity.

https://docs.soliditylang.org/en/develop/abi-spec.html#use-of-dynamic-types

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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