Skip to content

Commit

Permalink
Add mock dispute game factory / OP stack devnet script
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Apr 1, 2023
1 parent fb14d02 commit 6bf8ea1
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .env.devnet
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Devnet Specs: https://github.com/ethereum-optimism/optimism/blob/develop/specs/meta/devnet.md

export OP_CHALLENGER_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
export OP_CHALLENGER_KEY="ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
export OP_CHALLENGER_L1_WS="ws://127.0.0.1:8546"
export OP_CHALLENGER_TRUSTED_OP_NODE_RPC="http://localhost:7545"
export OP_CHALLENGER_L2OO="0x6900000000000000000000000000000000000000"

# TODO
export OP_CHALLENGER_DGF="0x0000000000000000000000000000000000000000"
# Paste the DisputeGameFactory env variable logged by `start_devnet.sh` here.

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "testdata/mock-dgf/lib/forge-std"]
path = testdata/mock-dgf/lib/forge-std
url = https://github.com/foundry-rs/forge-std
11 changes: 6 additions & 5 deletions bin/src/op-challenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use anyhow::{anyhow, Result};
use clap::{ArgAction, Parser};
use ethers::{
prelude::{Address, Provider, SignerMiddleware, Ws},
prelude::{Address, MiddlewareBuilder, Provider, Ws},
providers::Http,
};
use op_challenger_driver::{
Expand Down Expand Up @@ -90,10 +90,11 @@ async fn main() -> Result<()> {

// Connect to the websocket endpoint.
tracing::debug!(target: "op-challenger-cli", "Connecting to websocket endpoint...");
let ws_endpoint = Arc::new(SignerMiddleware::new(
Provider::<Ws>::connect(driver_config.l1_ws_endpoint.clone()).await?,
signer_key.parse()?,
));
let ws_endpoint = Arc::new(
Provider::<Ws>::connect(driver_config.l1_ws_endpoint.clone())
.await?
.with_signer(signer_key.parse()?),
);
tracing::info!(target: "op-challenger-cli", "Websocket connected successfully @ {}", &driver_config.l1_ws_endpoint);

// Connect to the node endpoint.
Expand Down
19 changes: 19 additions & 0 deletions start_devnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Set up environment variables
source .env.devnet

# Change accordingly
MONOREPO_DIR="$HOME/dev/optimism/monorepo"

# Boot up the devnet
(cd $MONOREPO_DIR && make devnet-up)

# Deploy the mock dispute game contract
(cd ./testdata/mock-dgf && forge script script/DeployMocks.s.sol --rpc-url http://localhost:8545 --private-key $OP_CHALLENGER_KEY --broadcast)

echo "----------------------------------------------------------------"
echo " - Paste the environment variable logged by the forge script"
echo " - into the \`.env.devnet\` file and then source it again before"
echo " - running the \`op-challenger\`."
echo "----------------------------------------------------------------"
3 changes: 3 additions & 0 deletions testdata/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `testdata`

Various periphery components used for testing the `op-challenger`.
14 changes: 14 additions & 0 deletions testdata/mock-dgf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
7 changes: 7 additions & 0 deletions testdata/mock-dgf/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[profile.default]
src = 'src'
out = 'out'
libs = ['lib']

[fmt]
bracket_spacing = true
1 change: 1 addition & 0 deletions testdata/mock-dgf/lib/forge-std
Submodule forge-std added at 8d0971
18 changes: 18 additions & 0 deletions testdata/mock-dgf/script/DeployMocks.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import { MockDisputeGameFactory } from "src/MockDisputeGameFactory.sol";
import { MockDisputeGame_OutputAttestation } from "src/MockDisputeGame_OutputAttestation.sol";

/// @notice This script deploys the mock dispute game factory.
contract DeployMocks is Script {
function run() public {
// Deploy the mock dispute game factory
vm.broadcast();
MockDisputeGameFactory mock = new MockDisputeGameFactory();

// Write the address to the devnet ENV
console.log(string.concat("ENV Variable: export OP_CHALLENGER_DGF=\"", vm.toString(address(mock)), "\""));
}
}
38 changes: 38 additions & 0 deletions testdata/mock-dgf/src/MockDisputeGameFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { MockDisputeGame_OutputAttestation } from "./MockDisputeGame_OutputAttestation.sol";

/// @notice The type of proof system being used.
enum GameType {
/// @dev The game will use a `IDisputeGame` implementation that utilizes fault proofs.
FAULT,
/// @dev The game will use a `IDisputeGame` implementation that utilizes validity proofs.
VALIDITY,
/// @dev The game will use a `IDisputeGame` implementation that utilizes attestation proofs.
ATTESTATION
}

/// @notice A `Claim` type represents a 32 byte hash or other unique identifier for a claim about
/// a certain piece of information.
/// @dev For the `FAULT` `GameType`, this will be a root of the merklized state of the fault proof
/// program at the end of the state transition.
/// For the `ATTESTATION` `GameType`, this will be an output root.
type Claim is bytes32;

/// @title MockDisputeGameFactory
/// @dev This contract is used for testing the `op-challenger`'s `OutputAttestationDriver`
/// on a local devnet.
contract MockDisputeGameFactory {
event DisputeGameCreated(address indexed disputeProxy, GameType indexed gameType, Claim indexed rootClaim);

/// @notice Creates a new DisputeGame proxy contract.
/// @param gameType The type of the DisputeGame - used to decide the proxy implementation
/// @param rootClaim The root claim of the DisputeGame.
/// @param extraData Any extra data that should be provided to the created dispute game.
function create(GameType gameType, Claim rootClaim, bytes calldata extraData) external returns (MockDisputeGame_OutputAttestation mock) {
mock = new MockDisputeGame_OutputAttestation();
emit DisputeGameCreated(address(mock), gameType, rootClaim);
extraData; // Unused
}
}
11 changes: 11 additions & 0 deletions testdata/mock-dgf/src/MockDisputeGame_OutputAttestation.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/// @title MockDisputeGame_OutputAttestation
/// @dev This contract is used for testing the `op-challenger`'s `OutputAttestationDriver`
/// on a local devnet.
contract MockDisputeGame_OutputAttestation {
function challenge(bytes calldata _signature) external {
// Do nothing
}
}
23 changes: 23 additions & 0 deletions testdata/mock-dgf/test/Mocks.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Test.sol";
import { MockDisputeGameFactory, GameType, Claim } from "src/MockDisputeGameFactory.sol";

contract MocksTest is Test {
MockDisputeGameFactory factory;

event DisputeGameCreated(address indexed disputeProxy, GameType indexed gameType, Claim indexed rootClaim);

function setUp() public {
factory = new MockDisputeGameFactory();
}

function testCreate(uint8 gameType, Claim rootClaim, bytes calldata extraData) external {
vm.assume(gameType <= 2);

vm.expectEmit(false, true, true, false);
emit DisputeGameCreated(address(0), GameType(gameType), rootClaim);
factory.create(GameType(gameType), rootClaim, extraData);
}
}

0 comments on commit 6bf8ea1

Please sign in to comment.