Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
4022aed3
Commit
4022aed3
authored
Jun 17, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add vizualizer script for the `FaultDisputeGame`
parent
15660862
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
0 deletions
+124
-0
FaultDisputeGameViz.s.sol
packages/contracts-bedrock/scripts/FaultDisputeGameViz.s.sol
+96
-0
dag-viz.py
packages/contracts-bedrock/scripts/dag-viz.py
+28
-0
No files found.
packages/contracts-bedrock/scripts/FaultDisputeGameViz.s.sol
0 → 100644
View file @
4022aed3
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 { DisputeGameFactory } from "../contracts/dispute/DisputeGameFactory.sol";
import { FaultDisputeGame } from "../contracts/dispute/FaultDisputeGame.sol";
import { IFaultDisputeGame } from "../contracts/dispute/interfaces/IFaultDisputeGame.sol";
import "../contracts/libraries/DisputeTypes.sol";
import "../contracts/libraries/DisputeErrors.sol";
import { LibClock } from "../contracts/dispute/lib/LibClock.sol";
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.
*/
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;
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");
}
/**
* @dev Entry point
*/
function run() public {
// Construct the game by performing attacks, defenses, and steps.
// ...
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.
*/
function buildGraph() internal {
uint256 numClaims = uint256(vm.load(address(gameProxy), bytes32(uint256(1))));
IFaultDisputeGame.ClaimData[] memory gameData = new IFaultDisputeGame.ClaimData[](numClaims);
for (uint256 i = 0; i < numClaims; i++) {
(
uint32 parentIndex,
bool countered,
Claim claim,
Position position,
Clock clock
) = gameProxy.claimData(i);
gameData[i] = IFaultDisputeGame.ClaimData({
parentIndex: parentIndex,
countered: countered,
claim: claim,
position: position,
clock: clock
});
}
string[] memory commands = new string[](3);
commands[0] = "python3";
commands[1] = "scripts/dag-viz.py";
commands[2] = vm.toString(abi.encode(gameData));
vm.ffi(commands);
}
}
packages/contracts-bedrock/scripts/dag-viz.py
0 → 100644
View file @
4022aed3
import
sys
import
dagviz
import
networkx
as
nx
from
eth_abi
import
decode
# The parent of the root claim is uint32 max.
ROOT_PARENT
=
4294967295
# Get the abi-encoded input
b
=
sys
.
argv
[
1
]
.
removeprefix
(
'0x'
)
# Decode the input
t
=
decode
([
'(uint32,bool,bytes32,uint128,uint128)[]'
],
bytes
.
fromhex
(
b
))[
0
]
# Create the graph
G
=
nx
.
DiGraph
()
for
c
in
t
:
claim
=
c
[
2
]
.
hex
()
key
=
f
"Position: {c[3]} | 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
)
r
=
dagviz
.
render_svg
(
G
)
f
=
open
(
'dispute_game.svg'
,
'w'
)
f
.
write
(
r
)
f
.
close
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment