底层函数解析
1. abi.encode, abi.encodePacked, abi.encodeWithSelector and abi.encodeWithSignature
Example:
bytes memory payload = abi.encodeWithSignature("register(string)", "MyName");
(bool success, bytes memory returnData) = address(nameReg).call(payload);
require(success);
It is possible to adjust the supplied gas with the gas
modifier:
address(nameReg).call{gas: 1000000}(abi.encodeWithSignature("register(string)", "MyName"));
Similarly, the supplied Ether value can be controlled too:
address(nameReg).call{value: 1 ether}(abi.encodeWithSignature("register(string)", "MyName"));
Lastly, these modifiers can be combined. Their order does not matter:
address(nameReg).call{gas: 1000000, value: 1 ether}(abi.encodeWithSignature("register(string)", "MyName"));
2. shr,calldataload,sub,calldatasize
EVM Dialect: https://docs.soliditylang.org/en/v0.8.9/yul.html#evm-dialect
assembly {
ret := shr(96,calldataload(sub(calldatasize(),20)))
}
- shr(x, y) : logical shift right y by x bits
- calldataload(p) : call data starting from position p (32 bytes)
- sub(x, y) : x - y
- calldatasize() : size of call data in bytes
网友评论