github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/testdata-istanbul/write-protection.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              _contract.call(
    38                  abi.encodeWithSignature("notfund()")
    39              );
    40              delete _a[1];
    41              delete _a[2];
    42          }
    43          if (_num == 1) {
    44              delete _a[3];
    45          }
    46          (bool success, bytes memory _) = _contract.staticcall(
    47              abi.encodeWithSignature("setVars(uint256)", _num)
    48          );
    49          emit Success(success);
    50          if (_num == 0) {
    51              revert();
    52          }
    53          if (_num == 1) {
    54              selfdestruct(address(0));
    55          }
    56          // 0x0000000000000000000000000000000000000000.call(
    57          //     abi.encodeWithSignature("notfund()")
    58          // );
    59      }
    60  
    61      function setVars(address _contract, uint _num) public returns (uint256) {
    62          if (_contract == address(0)) {
    63              _contract = c;
    64          }
    65          try this.callStatic(_contract,0) {
    66          } catch {
    67              this.callStatic(_contract,1);
    68          }
    69  
    70          return 1;
    71      }
    72  }