github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/testdata-istanbul/write-protection-003.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 mapping(uint => uint) private _a; 11 event Done(); 12 13 constructor() public { 14 _a[1] = 1; 15 _a[2] = 2; 16 _a[3] = 3; 17 } 18 19 function setVars(uint _num) public payable { 20 if (_num == 0) { 21 delete _a[1]; 22 delete _a[2]; 23 } 24 if (_num == 1) { 25 delete _a[3]; 26 } 27 num = _num; 28 sender = msg.sender; 29 value = msg.value; 30 emit Done(); 31 } 32 } 33 34 contract A { 35 uint public num; 36 address public sender; 37 uint public value; 38 address private c; 39 mapping(uint => uint) private _a; 40 event Success(bool); 41 42 function make() public { 43 c = address(new B()); 44 _a[1] = 1; 45 _a[2] = 2; 46 _a[3] = 3; 47 } 48 49 function callStatic(address _contract,uint _num) public { 50 if (_num == 0) { 51 _contract.call( 52 abi.encodeWithSignature("notfund()") 53 ); 54 delete _a[1]; 55 delete _a[2]; 56 } 57 if (_num == 1) { 58 delete _a[3]; 59 } 60 (bool success, bytes memory _) = _contract.staticcall( 61 abi.encodeWithSignature("setVars(uint256)", _num) 62 ); 63 emit Success(success); 64 if (_num == 0) { 65 revert(); 66 } 67 if (_num == 1) { 68 selfdestruct(address(0)); 69 } 70 // 0x0000000000000000000000000000000000000000.call( 71 // abi.encodeWithSignature("notfund()") 72 // ); 73 } 74 75 function setVars(address _contract, uint _num) public returns (uint256) { 76 if (_contract == address(0)) { 77 _contract = c; 78 } 79 try this.callStatic(_contract,0) { 80 } catch { 81 this.callStatic(_contract,1); 82 } 83 84 return 1; 85 } 86 }