Guest User

Untitled

a guest
Apr 16th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. pragma solidity ^0.6.4;
  2.  
  3. contract C1 {
  4. uint256 public myUint = 1;
  5.  
  6. function myFunc(uint256 x, uint256 y) public returns (uint256) {
  7. // revert('test');
  8.  
  9. myUint = 5;
  10. return x + y;
  11. }
  12. }
  13.  
  14. contract C2 {
  15. bytes4 private constant MY_FUNC_SELECTOR = bytes4(bytes32(uint256(keccak256("myFunc(uint256,uint256)") >> (256 - 4 * 8))));
  16.  
  17. function callMyFunc(address dest, uint256 x, uint256 y) public view returns (uint256[1] memory) {
  18. uint256[1] memory ret;
  19. bytes memory data = abi.encodeWithSelector(MY_FUNC_SELECTOR, x, y);
  20.  
  21. assembly {
  22. let success := staticcall(
  23. 30000, // gas remaining
  24. dest, // destination contract address
  25. add(data, 32), // input buffer (starts after the first 32 bytes in the `data` array)
  26. mload(data), // input length (loaded from the first 32 bytes in the `data` array)
  27. ret, // output buffer
  28. 32 // output length
  29. )
  30. }
  31.  
  32. return ret;
  33. }
  34. }
Add Comment
Please, Sign In to add comment