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