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