Simple question but I couldn’t find the answer.
Is it the datacopy precompile? and if yes, what it does?
Simple question but I couldn’t find the answer.
Is it the datacopy precompile? and if yes, what it does?
Yes, you are correct. It is the identity function.
It copies its input to its output. It can be used to copy between memory portions.
function dataCopy(bytes memory _input) internal view returns (bytes memory) {
uint length = _input.length;
bytes memory result = new bytes(length);
assembly {
// Call precompiled contract to copy data
if iszero(staticcall(gas, 0x04, add(_input, 0x20), length, add(result, 0x20), length)) {
revert(0, 0)
}
}
return result;
}
Since you only pay for chunks of 32 bytes above certain threshold it is cheaper than copy byte per byte.