Commit cd9a27dc authored by clabby's avatar clabby

Update viz script

parent 4022aed3
......@@ -3,7 +3,7 @@ pragma solidity ^0.8.15;
import { Script } from "forge-std/Script.sol";
import { console2 as console } from "forge-std/console2.sol";
import { DisputeGameFactory_Init } from "../contracts/test/DisputeGameFactory.t.sol";
import { FaultDisputeGame_Init } from "../contracts/test/FaultDisputeGame.t.sol";
import { DisputeGameFactory } from "../contracts/dispute/DisputeGameFactory.sol";
import { FaultDisputeGame } from "../contracts/dispute/FaultDisputeGame.sol";
import { IFaultDisputeGame } from "../contracts/dispute/interfaces/IFaultDisputeGame.sol";
......@@ -17,45 +17,20 @@ import { LibPosition } from "../contracts/dispute/lib/LibPosition.sol";
* @title FaultDisputeGameViz
* @dev To run this script, make sure to install the `dagviz` & `eth_abi` python packages.
*/
contract FaultDisputeGameViz is Script, DisputeGameFactory_Init {
/**
* @dev The root claim of the game.
*/
contract FaultDisputeGameViz is Script, FaultDisputeGame_Init {
/// @dev The root claim of the game.
Claim internal constant ROOT_CLAIM = Claim.wrap(bytes32(uint256(10)));
/**
* @dev The extra data passed to the game for initialization.
*/
bytes internal constant EXTRA_DATA = abi.encode(1);
/**
* @dev The type of the game being tested.
*/
GameType internal constant GAME_TYPE = GameType.wrap(0);
/**
* @dev The implementation of the game.
*/
FaultDisputeGame internal gameImpl;
/**
* @dev The `Clone` proxy of the game.
*/
FaultDisputeGame internal gameProxy;
/// @dev The absolute prestate of the trace.
Claim internal constant ABSOLUTE_PRESTATE = Claim.wrap(bytes32(uint256(0)));
function setUp() public override {
super.setUp();
// Deploy an implementation of the fault game
gameImpl = new FaultDisputeGame();
// Register the game implementation with the factory.
factory.setImplementation(GAME_TYPE, gameImpl);
// Create a new game.
gameProxy = FaultDisputeGame(address(factory.create(GAME_TYPE, ROOT_CLAIM, EXTRA_DATA)));
// Label the proxy
vm.label(address(gameProxy), "FaultDisputeGame_Clone");
super.init(ROOT_CLAIM, ABSOLUTE_PRESTATE);
}
/**
* @dev Entry point
*/
function run() public {
function local() public {
// Construct the game by performing attacks, defenses, and steps.
// ...
......@@ -63,6 +38,15 @@ contract FaultDisputeGameViz is Script, DisputeGameFactory_Init {
console.log("Saved graph to `./dispute_game.svg");
}
/**
* @dev Entry point
*/
function remote(address _addr) public {
gameProxy = FaultDisputeGame(_addr);
buildGraph();
console.log("Saved graph to `./dispute_game.svg");
}
/**
* @dev Uses the `dag-viz` python script to generate a visual model of the game state.
*/
......
......@@ -16,11 +16,11 @@ t = decode(['(uint32,bool,bytes32,uint128,uint128)[]'], bytes.fromhex(b))[0]
G = nx.DiGraph()
for c in t:
claim = c[2].hex()
key = f"Position: {c[3]} | Claim: 0x{claim[:4]}..{claim[60:64]}"
key = f"Position: {bin(c[3])[2:]} | Claim: 0x{claim[:4]}..{claim[60:64]}"
G.add_node(key)
if int(c[0]) != ROOT_PARENT:
pclaim = t[c[0]][2].hex()
G.add_edge(f"Position: {t[c[0]][3]} | Claim: 0x{pclaim[:4]}..{pclaim[60:64]}", key)
G.add_edge(f"Position: {bin(t[c[0]][3])[2:]} | Claim: 0x{pclaim[:4]}..{pclaim[60:64]}", key)
r = dagviz.render_svg(G)
f = open('dispute_game.svg', 'w')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment