Skip to content

Commit

Permalink
bugs in calling contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJepsen committed Oct 12, 2023
1 parent 2c885fa commit 1143c87
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 32 deletions.
33 changes: 20 additions & 13 deletions src/actors.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
use std::sync::Arc;

use alloy_primitives::Address;
use durin_fault::{FaultDisputeSolver, providers::AlphabetTraceProvider, FaultDisputeState, AlphaClaimSolver};

use durin_fault::{
providers::AlphabetTraceProvider, AlphaClaimSolver, FaultDisputeSolver, FaultDisputeState,
};

use arbiter_core::middleware::RevmMiddleware;
use foundry_contracts::{fault_dispute_game::FaultDisputeGame, alphabet_vm::AlphabetVM, block_oracle::BlockOracle, l2_output_oracle::L2OutputOracle};

use foundry_contracts::{
alphabet_vm::AlphabetVM, block_oracle::BlockOracle, fault_dispute_game::FaultDisputeGame,
l2_output_oracle::L2OutputOracle,
};

/// actors can call
/// Move (alias for step) is a bisection step, pass in challenge index
/// actors can call
/// Move (alias for step) is a bisection step, pass in challenge index
/// (index of claim trying to counter, called claim data), only children point to parents for the dag
/// attack (alias for move)
/// deffend (alias for move)
/// step
///
///
/// step
///
///
/// might need to make a new trait for the solver of off this
/// /Users/shufflebottomhogwood/Code/DisputeGameSimulations/lib/optimism/op-challenger/game/fault/solver/solver.go
/// make player generic over solver generics to be able to sub out any solver
pub struct HonestPlayer {
pub fault: FaultDisputeSolver<[u8;1], AlphabetTraceProvider, AlphaClaimSolver<[u8;1], AlphabetTraceProvider>>, // need to make alphaclaim solver public
pub state: FaultDisputeState, // <- needs to increment with every new state
pub fault: FaultDisputeSolver<
[u8; 1],
AlphabetTraceProvider,
AlphaClaimSolver<[u8; 1], AlphabetTraceProvider>,
>, // need to make alphaclaim solver public
pub state: FaultDisputeState, // <- needs to increment with every new state
pub address: Address,
pub client: Arc<RevmMiddleware>,
pub vm: AlphabetVM<RevmMiddleware>,
Expand Down Expand Up @@ -55,7 +62,7 @@ impl HonestPlayer {
}
}

pub struct DishonestPlayer{
pub struct DishonestPlayer {
pub address: Address,
pub client: RevmMiddleware,
pub vm: AlphabetVM<RevmMiddleware>,
Expand All @@ -82,4 +89,4 @@ impl DishonestPlayer {
// randomly select a value in some range to has as move's claim
todo!()
}
}
}
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use arbiter_core::middleware::RevmMiddleware;
use ethers::utils::keccak256 as ekeccak256;
use foundry_contracts::{
alphabet_vm::AlphabetVM, block_oracle::block_oracle::BlockOracle,
dispute_game_factory::DisputeGameFactory,
fault_dispute_game::fault_dispute_game::FaultDisputeGame,
l2_output_oracle::l2_output_oracle::L2OutputOracle,
dispute_game_factory::DisputeGameFactory,
};
use std::{error::Error, sync::Arc};
mod startup;
mod actors;
mod startup;

const ENV_LABEL: &str = "OPTIMISM_FRAUD_PROOF";
const SUBMISSION_INTERVAL: f64 = 1800.0; // output every 30minutes
Expand All @@ -32,10 +32,10 @@ pub async fn main() -> Result<(), Box<dyn Error>> {

let _contracts = startup::deploy_contracts(admin).await?;

// make our agents
// make our agents

// main sim loop
// check for event
// main sim loop
// check for event
// make action depending on whos turns

// Things to note:
Expand Down
40 changes: 26 additions & 14 deletions src/startup.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use alloy_primitives::Bytes;
use arbiter_core::environment::{builder::EnvironmentBuilder, cheatcodes::Cheatcodes, Environment};
use ethers::types::U256 as eU256;


use super::*;


/// All the possible contracts that this simulation will actively use, but not
/// all that are deployed!
/// Each is bound to a `Client` and can be used to interact with the contract.
Expand Down Expand Up @@ -73,7 +72,6 @@ pub async fn set_up_agents() -> Result<(
}

pub async fn deploy_contracts(admin: Arc<RevmMiddleware>) -> Result<SimulationContracts> {

let sub_interval = eU256::from(SUBMISSION_INTERVAL as u64);
let l2_block_time = eU256::from(L2_BLOCK_TIME as u64);
let finalization_period = eU256::from(FINALIZATION_PERIOD_SECONDS as u64);
Expand All @@ -92,7 +90,21 @@ pub async fn deploy_contracts(admin: Arc<RevmMiddleware>) -> Result<SimulationCo
// https://github.com/ethereum-optimism/optimism/blob/develop/specs/proposals.md#l2-output-commitment-construction
// need to propose some outputs for game to run
// one in initial block and one next block
let result = admin.update_block(1, 32)?;
println!("result: {:?}", result);
let call = l2_output_oracle
.propose_l2_output(
ekeccak256("Asdfa"),
eU256::from(1),
ekeccak256(b"1"),
eU256::from("1"),
)
.send()
.await?
.await?;

let result = call.unwrap();
println!("result: {:?}", result);
let block_oracle = BlockOracle::deploy(admin.clone(), ())?.send().await?;

// checkpoint a point a block after the preposals at least 1 block after the preposals
Expand All @@ -107,20 +119,18 @@ pub async fn deploy_contracts(admin: Arc<RevmMiddleware>) -> Result<SimulationCo

// UDTs are encoded as their underlying type
let mvt = AbiEncodableU256::from(U256::from(1));
// let data: U256 = "0x0000000000000000000000000000000000000000000000000000000000000001".parse().unwrap();
let root_claim = ekeccak256(AbiEncodableU256::abi_encode(&mvt)); // replace with the actual root claim
let root_claim = ekeccak256(AbiEncodableU256::abi_encode(&mvt));

let alphabet_vm = AlphabetVM::deploy(admin.clone(), root_claim)?
.send()
.await?;


println!("AlphabetVM address: {}", alphabet_vm.address());
let game_type = GameType::from(0);
let mut claim = ekeccak256("A");
claim[0]= 0x01; // need to set zeroith byte
let mut claim = ekeccak256("A");
claim[0] = 0x01; // need to set zeroith byte
let depth = eU256::from(4); // 16 letters / numbers supports 2^(depth). Average cannon trace is 2^40 = 40ish B
let duration = Duration::from(60); // 1 week, each side has 3.5 days to respond to a dispute. Might want to make this smaller for testing
let duration = Duration::from(60);

let disputegame = FaultDisputeGame::deploy(
admin.clone(),
Expand Down Expand Up @@ -153,18 +163,20 @@ pub async fn deploy_contracts(admin: Arc<RevmMiddleware>) -> Result<SimulationCo
.await?;
println!("DisputeGameFactory address: {}", factory.address());


// use the factory and call the set implementation on the particular game we have deployed
// because they need the clones of immutable data
// let call = factory.set_implementation(0, disputegame.address());
// let reciept = call.send().await?.await?.unwrap();
// println!("reciept: {:?}", reciept.status);
// bytes calldata _extraData // abi.encode(l2 blocknumber being disputed + l1 block number (checkpointed in block oracle))

// let new_game = factory.create(game_type.into(), root_claim, );
let call = factory.set_implementation(game_type.into(), disputegame.address());
let reciept = call.send().await?.await?.unwrap();
println!("reciept: {:?}", reciept);

Ok(SimulationContracts {
l2_output_oracle,
block_oracle,
alphabet_vm,
disputegame,
factory,
factory,
})
}

0 comments on commit 1143c87

Please sign in to comment.