Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.6.4;
- contract C1 {
- uint256 public myUint = 1;
- function myFunc(uint256 x, uint256 y) public returns (uint256) {
- // revert('test');
- myUint = 5;
- return x + y;
- }
- }
- contract C2 {
- bytes4 private constant MY_FUNC_SELECTOR = bytes4(bytes32(uint256(keccak256("myFunc(uint256,uint256)") >> (256 - 4 * 8))));
- function callMyFunc(address dest, uint256 x, uint256 y) public view returns (uint256[1] memory) {
- uint256[1] memory ret;
- bytes memory data = abi.encodeWithSelector(MY_FUNC_SELECTOR, x, y);
- assembly {
- let success := staticcall(
- 30000, // gas remaining
- dest, // destination contract address
- add(data, 32), // input buffer (starts after the first 32 bytes in the `data` array)
- mload(data), // input length (loaded from the first 32 bytes in the `data` array)
- ret, // output buffer
- 32 // output length
- )
- }
- return ret;
- }
- }
Add Comment
Please, Sign In to add comment