Why we need calldatacopy(ptr, 0, calldatasize)
thcrnk opened this issue · 2 comments
thcrnk commented
From few months we are using the same pattern for upgradability with proxy, only difference is we do not have this line:
calldatacopy(ptr, 0, calldatasize)
Here is the code we are using and currently is working fine, how calldatacopy is improving it:
assembly {
switch extcodesize(_dst) case 0 { revert(0, 0) }
let result := delegatecall(sub(gas, 10000), _dst, add(_calldata, 0x20), mload(_calldata), 0, 0)
let size := returndatasize
let ptr := mload(0x40)
returndatacopy(ptr, 0, size)
switch result
case 0 { revert(ptr, size) }
default { return(ptr, size) }
}
Just asking to be sure and if we need to implement it.
frangio commented
What is the _calldata
variable your assembly code is using? I suspect it refers to an array that you created via bytes _calldata = msg.data
. This compiles down to a calldatacopy
. We're using the opcode directly as an optimization. See zeppelinos/zos-lib#13 where we introduced this change.
thcrnk commented
Thanks, now is all clear!