Commit 4cc16840 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge branch 'develop' into inphi/oracle-test

parents 8b45eb33 73d6cfa9
......@@ -522,12 +522,12 @@ Now start `op-proposer`, which proposes new state roots.
cd ~/optimism/op-proposer
./bin/op-proposer \
--poll-interval 12s \
--rpc.port 8560 \
--rollup-rpc http://localhost:8547 \
--l2oo-address $L2OO_ADDR \
--private-key $PROPOSER_KEY \
--l1-eth-rpc $L1_RPC
--poll-interval=12s \
--rpc.port=8560 \
--rollup-rpc=http://localhost:8547 \
--l2oo-address=$L2OO_ADDR \
--private-key=$PROPOSER_KEY \
--l1-eth-rpc=$L1_RPC
```
......
......@@ -3,6 +3,8 @@ package fault
import (
"context"
"sync"
"github.com/ethereum/go-ethereum/log"
)
type Agent struct {
......@@ -12,15 +14,17 @@ type Agent struct {
trace TraceProvider
responder Responder
maxDepth int
log log.Logger
}
func NewAgent(game Game, maxDepth int, trace TraceProvider, responder Responder) Agent {
func NewAgent(game Game, maxDepth int, trace TraceProvider, responder Responder, log log.Logger) Agent {
return Agent{
game: game,
solver: NewSolver(maxDepth, trace),
trace: trace,
responder: responder,
maxDepth: maxDepth,
log: log,
}
}
......@@ -45,12 +49,23 @@ func (a *Agent) PerformActions() {
// move determines & executes the next move given a claim pair
func (a *Agent) move(claim, parent Claim) error {
move, err := a.solver.NextMove(claim)
if err != nil || move == nil {
nextMove, err := a.solver.NextMove(claim)
if err != nil {
a.log.Warn("Failed to execute the next move", "err", err)
return err
}
if a.game.IsDuplicate(*move) {
if nextMove == nil {
a.log.Info("No next move")
return nil
}
move := *nextMove
log := a.log.New("is_defend", move.DefendsParent(), "depth", move.Depth(), "index_at_depth", move.IndexAtDepth(), "value", move.Value,
"letter", string(move.Value[31:]), "trace_index", move.Value[30],
"parent_letter", string(claim.Value[31:]), "parent_trace_index", claim.Value[30])
if a.game.IsDuplicate(move) {
log.Debug("Duplicate move")
return nil
}
return a.responder.Respond(context.TODO(), *move)
log.Info("Performing move")
return a.responder.Respond(context.TODO(), move)
}
pragma solidity ^0.8.15;
import { Script } from "forge-std/Script.sol";
import { console2 as console } from "forge-std/console2.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";
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, FaultDisputeGame_Init {
/// @dev The root claim of the game.
Claim internal constant ROOT_CLAIM = Claim.wrap(bytes32(uint256(10)));
/// @dev The absolute prestate of the trace.
Claim internal constant ABSOLUTE_PRESTATE = Claim.wrap(bytes32(uint256(0)));
function setUp() public override {
super.init(ROOT_CLAIM, ABSOLUTE_PRESTATE);
}
/**
* @dev Entry point
*/
function local() public {
// Construct the game by performing attacks, defenses, and steps.
// ...
buildGraph();
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.
*/
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);
}
}
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: {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: {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')
f.write(r)
f.close()
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