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.
- Is CALLDATACOPY a set of CALLDATALOAD AND MSTORE of 32bytes until end is reached ?
- Why not use CALLDATACOPY ?
Furthermore, I had the following calldata when I called it with params [1,2,3]:
0x5308ae31
0000000000000000000000000000000000000000000000000000000000000020
0000000000000000000000000000000000000000000000000000000000000003
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000000000000000000000000000000000000000000003
- What is the 1st word (0x20) representing after 4-bytes of selector ? Is it pointer ?
- 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 ?