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
cd9a27dc
Commit
cd9a27dc
authored
Jun 26, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update viz script
parent
4022aed3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
34 deletions
+18
-34
FaultDisputeGameViz.s.sol
packages/contracts-bedrock/scripts/FaultDisputeGameViz.s.sol
+16
-32
dag-viz.py
packages/contracts-bedrock/scripts/dag-viz.py
+2
-2
No files found.
packages/contracts-bedrock/scripts/FaultDisputeGameViz.s.sol
View file @
cd9a27dc
...
@@ -3,7 +3,7 @@ pragma solidity ^0.8.15;
...
@@ -3,7 +3,7 @@ pragma solidity ^0.8.15;
import { Script } from "forge-std/Script.sol";
import { Script } from "forge-std/Script.sol";
import { console2 as console } from "forge-std/console2.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 { DisputeGameFactory } from "../contracts/dispute/DisputeGameFactory.sol";
import { FaultDisputeGame } from "../contracts/dispute/FaultDisputeGame.sol";
import { FaultDisputeGame } from "../contracts/dispute/FaultDisputeGame.sol";
import { IFaultDisputeGame } from "../contracts/dispute/interfaces/IFaultDisputeGame.sol";
import { IFaultDisputeGame } from "../contracts/dispute/interfaces/IFaultDisputeGame.sol";
...
@@ -17,45 +17,20 @@ import { LibPosition } from "../contracts/dispute/lib/LibPosition.sol";
...
@@ -17,45 +17,20 @@ import { LibPosition } from "../contracts/dispute/lib/LibPosition.sol";
* @title FaultDisputeGameViz
* @title FaultDisputeGameViz
* @dev To run this script, make sure to install the `dagviz` & `eth_abi` python packages.
* @dev To run this script, make sure to install the `dagviz` & `eth_abi` python packages.
*/
*/
contract FaultDisputeGameViz is Script, DisputeGameFactory_Init {
contract FaultDisputeGameViz is Script, FaultDisputeGame_Init {
/**
/// @dev The root claim of the game.
* @dev The root claim of the game.
*/
Claim internal constant ROOT_CLAIM = Claim.wrap(bytes32(uint256(10)));
Claim internal constant ROOT_CLAIM = Claim.wrap(bytes32(uint256(10)));
/**
/// @dev The absolute prestate of the trace.
* @dev The extra data passed to the game for initialization.
Claim internal constant ABSOLUTE_PRESTATE = Claim.wrap(bytes32(uint256(0)));
*/
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 {
function setUp() public override {
super.setUp();
super.init(ROOT_CLAIM, ABSOLUTE_PRESTATE);
// 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
* @dev Entry point
*/
*/
function
run
() public {
function
local
() public {
// Construct the game by performing attacks, defenses, and steps.
// Construct the game by performing attacks, defenses, and steps.
// ...
// ...
...
@@ -63,6 +38,15 @@ contract FaultDisputeGameViz is Script, DisputeGameFactory_Init {
...
@@ -63,6 +38,15 @@ contract FaultDisputeGameViz is Script, DisputeGameFactory_Init {
console.log("Saved graph to `./dispute_game.svg");
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.
* @dev Uses the `dag-viz` python script to generate a visual model of the game state.
*/
*/
...
...
packages/contracts-bedrock/scripts/dag-viz.py
View file @
cd9a27dc
...
@@ -16,11 +16,11 @@ t = decode(['(uint32,bool,bytes32,uint128,uint128)[]'], bytes.fromhex(b))[0]
...
@@ -16,11 +16,11 @@ t = decode(['(uint32,bool,bytes32,uint128,uint128)[]'], bytes.fromhex(b))[0]
G
=
nx
.
DiGraph
()
G
=
nx
.
DiGraph
()
for
c
in
t
:
for
c
in
t
:
claim
=
c
[
2
]
.
hex
()
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
)
G
.
add_node
(
key
)
if
int
(
c
[
0
])
!=
ROOT_PARENT
:
if
int
(
c
[
0
])
!=
ROOT_PARENT
:
pclaim
=
t
[
c
[
0
]][
2
]
.
hex
()
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
)
r
=
dagviz
.
render_svg
(
G
)
f
=
open
(
'dispute_game.svg'
,
'w'
)
f
=
open
(
'dispute_game.svg'
,
'w'
)
...
...
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