github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/testdata-istanbul/write-protection-001.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity ^0.6.6; 3 4 // NOTE: Deploy this contract first 5 contract B { 6 // NOTE: storage layout must be the same as contract A 7 uint public num; 8 address public sender; 9 uint public value; 10 event Done(); 11 12 function setVars(uint _num) public payable { 13 num = _num; 14 sender = msg.sender; 15 value = msg.value; 16 emit Done(); 17 } 18 } 19 20 contract A { 21 uint public num; 22 address public sender; 23 uint public value; 24 address private c; 25 mapping(uint => uint) private _a; 26 event Success(bool); 27 28 function make() public { 29 c = address(new B()); 30 _a[1] = 1; 31 _a[2] = 2; 32 _a[3] = 3; 33 } 34 35 function callStatic(address _contract,uint _num) public { 36 if (_num == 0) { 37 delete _a[1]; 38 } 39 (bool success, bytes memory _) = _contract.staticcall( 40 abi.encodeWithSignature("setVars(uint256)", _num) 41 ); 42 emit Success(success); 43 if (_num == 0) { 44 revert(); 45 } 46 } 47 48 function setVars(address _contract, uint _num) public returns (uint256) { 49 if (_contract == address(0)) { 50 _contract = c; 51 } 52 try this.callStatic(_contract,0) { 53 } catch { 54 this.callStatic(_contract,1); 55 } 56 57 return 1; 58 } 59 }