Solidity – Handling Calldata with Too Many Parameters

calldataevmsolidity

While reading https://solidity.readthedocs.io/en/v0.4.21/abi-spec.html#abi I was just thinking what happens when calldata contains more parameters/data than the function expects (I know first parameter is 4 bytes Keccak256 of function signature, so this cannot happen by accident). It's just that you can use arbitrary msg.data. I believe those exta bytes should be just silently ignored (never referenced) or am I mistaken? This means the exact same function invocation can be encoded in many different ways.

Additionally: what happens if dynamic array "offset" points outside of the given parameters (or size is bigger than actual number of provided values). Can you imagine that everything undefined is sort of 0 or will such tricks throw an exception?

Best Answer

Yes, the extra calldata bytes will be ignored, and yes, calldata read past the end of the length is 0s.

Related Topic