github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/scripts/FaultDisputeGameViz.s.sol (about)

     1  // SPDX-License-Identifier: MIT
     2  pragma solidity ^0.8.15;
     3  
     4  import { Script } from "forge-std/Script.sol";
     5  import { console2 as console } from "forge-std/console2.sol";
     6  
     7  import { FaultDisputeGame_Init } from "test/dispute/FaultDisputeGame.t.sol";
     8  import { DisputeGameFactory } from "src/dispute/DisputeGameFactory.sol";
     9  import { FaultDisputeGame } from "src/dispute/FaultDisputeGame.sol";
    10  import { IFaultDisputeGame } from "src/dispute/interfaces/IFaultDisputeGame.sol";
    11  
    12  import "src/libraries/DisputeTypes.sol";
    13  import "src/libraries/DisputeErrors.sol";
    14  import { LibPosition } from "src/dispute/lib/LibPosition.sol";
    15  
    16  /**
    17   * @title FaultDisputeGameViz
    18   * @dev To run this script, make sure to install the `dagviz` & `eth_abi` python packages.
    19   */
    20  contract FaultDisputeGameViz is Script, FaultDisputeGame_Init {
    21      /// @dev The root claim of the game.
    22      Claim internal constant ROOT_CLAIM = Claim.wrap(bytes32(uint256(1)));
    23      /// @dev The absolute prestate of the trace.
    24      Claim internal constant ABSOLUTE_PRESTATE = Claim.wrap(bytes32((uint256(3) << 248) | uint256(0)));
    25  
    26      function setUp() public override {
    27          super.setUp();
    28          super.init({ rootClaim: ROOT_CLAIM, absolutePrestate: ABSOLUTE_PRESTATE, l2BlockNumber: 0x10 });
    29      }
    30  
    31      /**
    32       * @dev Entry point
    33       */
    34      function local() public {
    35          // Construct the game by performing attacks, defenses, and steps.
    36          // ...
    37  
    38          buildGraph();
    39          console.log("Saved graph to `./dispute_game.svg");
    40      }
    41  
    42      /**
    43       * @dev Entry point
    44       */
    45      function remote(address _addr) public {
    46          gameProxy = FaultDisputeGame(payable(_addr));
    47          buildGraph();
    48          console.log("Saved graph to `./dispute_game.svg");
    49      }
    50  
    51      /**
    52       * @dev Uses the `dag-viz` python script to generate a visual model of the game state.
    53       */
    54      function buildGraph() internal {
    55          uint256 numClaims = uint256(vm.load(address(gameProxy), bytes32(uint256(1))));
    56          IFaultDisputeGame.ClaimData[] memory gameData = new IFaultDisputeGame.ClaimData[](numClaims);
    57          for (uint256 i = 0; i < numClaims; i++) {
    58              (
    59                  uint32 parentIndex,
    60                  address countered,
    61                  address claimant,
    62                  uint128 bond,
    63                  Claim claim,
    64                  Position position,
    65                  Clock clock
    66              ) = gameProxy.claimData(i);
    67  
    68              gameData[i] = IFaultDisputeGame.ClaimData({
    69                  parentIndex: parentIndex,
    70                  counteredBy: countered,
    71                  claimant: claimant,
    72                  bond: bond,
    73                  claim: claim,
    74                  position: position,
    75                  clock: clock
    76              });
    77          }
    78  
    79          string[] memory commands = new string[](3);
    80          commands[0] = "python3";
    81          commands[1] = "scripts/dag-viz.py";
    82          commands[2] = vm.toString(abi.encode(gameData));
    83          vm.ffi(commands);
    84      }
    85  }