I debugged a simple function execution on Remix:

  function megaTest(uint256[] memory p) external pure returns(uint256[] memory r) {}

What I noticed is that CALLDATALOAD and MSTORE were used to copy calldata to memory.

  1. Is CALLDATACOPY a set of CALLDATALOAD AND MSTORE of 32bytes until end is reached ?
  2. Why not use CALLDATACOPY ?

Furthermore, I had the following calldata when I called it with params [1,2,3]:

  1. What is the 1st word (0x20) representing after 4-bytes of selector ? Is it pointer ?
  2. After selector's 4-bytes, isn't 2nd word which represents length of array to be copied sufficient for EVM ? Can't the EVM interpret what is to be expected in the calldata from selector matching ?
  • I figured out myself: 1. Represents pointer. Absolute pointer not relative. 4 bytes selector is not the start of indexing. 2. It is not sufficient. If we had two dynamic types, things will get messed up. So, the slot points to data after the arguments
    – Xirexor
    Nov 21, 2023 at 17:54

1 Answer 1

  • Represents pointer. Pointing is absolute not relative to the slot itself. Absolute indexing starts after the first 4 bytes selector.
  • Not sufficient. Arguments will consume their slots as how they are defined. Dynamic types will only point to a location after the arguments in memory where length and actual elements are stored.

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.