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