I was hoping to gain some knowledge around specific assembly codes, particularly the ones used in the Instadapp project to forward user calls to their proxy integration contracts.
The function in question is:
/**
* @dev Delegate the calls to Connector And this function is ran by cast().
* @param _target Target to of Connector.
* @param _data CallData of function in Connector.
*/
function spell(address _target, bytes memory _data) internal {
require(_target != address(0), "target-invalid");
assembly {
let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0)
switch iszero(succeeded)
case 1 {
// throw if delegatecall failed
let size := returndatasize()
returndatacopy(0x00, 0x00, size)
revert(0x00, size)
}
}
}
Specifically, what does this do, and how would one use it? I haven’t found actual docs explaining how delegatecall()
, and _mload()
function/parameters they take.
I do understand the delegatecall will return the status of the txn as a zero or 1 (and won’t auto-fail upon error) and the switch()
checks if the transaction did fail (indicated by a zero return). Though I don’t know what returndatasize
or returndatacopy
does.
Thanks for any explanation/knowledge share. On a side-note, where are good sources to learn assembly? The official Solidity docs don’t do a great job in explanation.