DEV Community

Ruud Christopher Saimplice
Ruud Christopher Saimplice

Posted on • Edited on

Advance Solidity Assembly: Calldata Part 1

In Solidity, calldata is a special data location that is used to store the function arguments and other data that is passed to a function when it is called. calldata is read-only, which means that the function cannot modify the data in calldata.

When a Solidity function is called, its arguments are copied to calldata, which is a portion of the transaction data. This is different from the memory data location, which is used to store data that is only used within the function and is not part of the transaction data.

Calldata in Gory Details !!!!

Calldata is a continuous sequence of bytes that is structured in the same way as memory, as opposed to other data locations like storage or stack, which are composed of 32-byte words.

When reading from calldata, the behavior is the same as memory: you can load 32 bytes at a time using calldataload or mload. However, calldata is different from memory because you cannot write to it.

Calldata is a data location that is unique to EVM-based blockchains, and it has a specific layout that includes:

1- The first 4 bytes of calldata represent the function signature selector.

2- The remaining bytes of calldata represent the input parameters of the function. Each input argument is always 32 bytes long, regardless of its actual size. If an argument's type is smaller than 32 bytes, it will be padded to fill the remaining space.

Input arguments in Solidity are padded either on the right or left depending on their type. For example, uintN and address types are padded on the left, while bytesN types are padded on the right.

Top comments (0)