Skip to content

Commit

Permalink
IBlockDisputeGame interface abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
zobront committed Jun 5, 2024
1 parent 541ada1 commit d131cbb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
30 changes: 23 additions & 7 deletions packages/contracts-bedrock/src/dispute/OptimisticZKGame.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
pragma solidity ^0.8.15;

import { IDisputeGame } from "./interfaces/IDisputeGame.sol";
import { IFaultDisputeGame } from "./interfaces/IFaultDisputeGame.sol";
import { IBlockDisputeGame } from "./interfaces/IBlockDisputeGame.sol";
import { IDelayedWETH } from "./interfaces/IDelayedWETH.sol";
import { IInitializable } from "./interfaces/IInitializable.sol";
import { IOptimisticZKGame } from "./interfaces/IOptimisticZKGame.sol";
import { IDisputeGameFactory } from "./interfaces/IDisputeGameFactory.sol";

import { DisputeGameFactory } from "./DisputeGameFactory.sol";
import { OutputRoot, GameStatus, Timestamp, Clock, Duration, GameType, Claim, Hash } from "src/dispute/lib/Types.sol";
import { LibClock, LibDuration, LibTimestamp } from "./lib/LibUDT.sol";
import "src/dispute/lib/Types.sol";

import { Clone } from "@solady/utils/Clone.sol";
import { SP1Verifier } from "@sp1-contracts/SP1Verifier.sol";
Expand All @@ -27,7 +26,7 @@ contract OptimisticZKGame is IOptimisticZKGame, Clone, SP1Verifier {
uint constant GLOBAL_CHALLENGE_ID = type(uint64).max;

/// @notice The DisputeGameFactory contract.
DisputeGameFactory immutable FACTORY;
IDisputeGameFactory immutable FACTORY;

/// @notice The game type ID.
GameType immutable GAME_TYPE;
Expand Down Expand Up @@ -97,7 +96,7 @@ contract OptimisticZKGame is IOptimisticZKGame, Clone, SP1Verifier {
if (_maxGameDuration.raw() != _maxProposerDuration.raw() * 2) revert InvalidDurations();

// Set all the immutable values in the implementation contract.
FACTORY = DisputeGameFactory(_factory);
FACTORY = IDisputeGameFactory(_factory);
GAME_TYPE = _gameType;
MAX_GAME_DURATION = _maxGameDuration;
MAX_PROPOSER_DURATION = _maxProposerDuration;
Expand All @@ -117,7 +116,7 @@ contract OptimisticZKGame is IOptimisticZKGame, Clone, SP1Verifier {

// Pull the L2 block number from the previous game.
// @audit this is a hack because it's not fault dispute game. why isn't this is core interface?
uint prevL2BlockNumber = IFaultDisputeGame(address(prevGame)).l2BlockNumber();
uint prevL2BlockNumber = IBlockDisputeGame(address(prevGame)).l2BlockNumber();

// Set the anchorStateRoot to the previous game's root.
anchorStateRoot = OutputRoot({ root: Hash.wrap(prevGame.rootClaim().raw()), l2BlockNumber: prevL2BlockNumber });
Expand Down Expand Up @@ -375,6 +374,7 @@ contract OptimisticZKGame is IOptimisticZKGame, Clone, SP1Verifier {
// BONDS //
////////////////////////////////////////////////////////////////

// Deposit the bond into the DelayedWETH contract and increment the total bonds for the given challenge.
function _depositBond(uint _challengeId) internal {
if (msg.value != getRequiredBond(_challengeId)) revert WrongBondAmount();
if (_challengeId != GLOBAL_CHALLENGE_ID) challenges[_challengeId].totalBonds += msg.value;
Expand Down Expand Up @@ -487,6 +487,22 @@ contract OptimisticZKGame is IOptimisticZKGame, Clone, SP1Verifier {
proposerAddr_ = _getArgAddress(0x94);
}

/// @notice Starting output root and block number of the game.
function startingOutputRoot() external view returns (Hash startingRoot_, uint256 l2BlockNumber_) {
startingRoot_ = Hash.wrap(anchorStateRoot.root.raw());
l2BlockNumber_ = anchorStateRoot.l2BlockNumber;
}

/// @notice Only the starting block number of the game.
function startingBlockNumber() external view returns (uint256 startingBlockNumber_) {
startingBlockNumber_ = anchorStateRoot.l2BlockNumber;
}

/// @notice Only the starting output root of the game.
function startingRootHash() external view returns (Hash startingRootHash_) {
startingRootHash_ = Hash.wrap(anchorStateRoot.root.raw());
}

/// @inheritdoc IDisputeGame
function gameData() external view returns (GameType gameType_, Claim rootClaim_, bytes memory extraData_) {
gameType_ = gameType();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

import "src/dispute/lib/Types.sol";

/// @title IBlockDisputeGame
/// @notice The interface for a game meant to resolve an L2 Block.
interface IBlockDisputeGame is IDisputeGame {
/// @notice The l2BlockNumber of the disputed output root in the `L2OutputOracle`.
function l2BlockNumber() external view returns (uint256 l2BlockNumber_);

/// @notice Starting output root and block number of the game.
function startingOutputRoot() external view returns (Hash startingRoot_, uint256 l2BlockNumber_);

/// @notice Only the starting block number of the game.
function startingBlockNumber() external view returns (uint256 startingBlockNumber_);

/// @notice Only the starting output root of the game.
function startingRootHash() external view returns (Hash startingRootHash_);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import { IDisputeGame } from "./IDisputeGame.sol";
import { IBlockDisputeGame } from "./IBlockDisputeGame.sol";
import "src/dispute/lib/Types.sol";

interface IOptimisticZKGame is IDisputeGame {
interface IOptimisticZKGame is IBlockDisputeGame {
enum IntermediateClaimStatus {
NONE,
ACCEPTED,
Expand Down

0 comments on commit d131cbb

Please sign in to comment.