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