Commit 154f976d authored by clabby's avatar clabby Committed by GitHub

feat: Squash libraries in dispute contracts (#10351)

* feat: Squash libraries in dispute contracts

Reorganizes the libraries in the dispute contracts to remove circular
dependencies. The existing dependency structure resolves within the
monorepo's environment, but not when the monorepo's contracts are
imported as a forge project dependency. This unblocks our ability to use
these contracts for post-checks in `superchain-ops`.

* Remove `IDisputeGame` dep in `LibUDT`

* semver lock
parent 55d8a35e
......@@ -47,7 +47,7 @@ import { Config } from "scripts/Config.sol";
import { IBigStepper } from "src/dispute/interfaces/IBigStepper.sol";
import { IPreimageOracle } from "src/cannon/interfaces/IPreimageOracle.sol";
import { AlphabetVM } from "test/mocks/AlphabetVM.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
import { ChainAssertions } from "scripts/ChainAssertions.sol";
import { Types } from "scripts/Types.sol";
import { LibStateDiff } from "scripts/libraries/LibStateDiff.sol";
......
......@@ -9,9 +9,8 @@ import { DisputeGameFactory } from "src/dispute/DisputeGameFactory.sol";
import { FaultDisputeGame } from "src/dispute/FaultDisputeGame.sol";
import { IFaultDisputeGame } from "src/dispute/interfaces/IFaultDisputeGame.sol";
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
import { LibPosition } from "src/dispute/lib/LibPosition.sol";
import "src/dispute/lib/Types.sol";
import "src/dispute/lib/Errors.sol";
/**
* @title FaultDisputeGameViz
......
......@@ -6,7 +6,7 @@ import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import { AnchorStateRegistry, IAnchorStateRegistry } from "src/dispute/AnchorStateRegistry.sol";
import { IDelayedWETH } from "src/dispute/interfaces/IDelayedWETH.sol";
import { StdAssertions } from "forge-std/StdAssertions.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
import "scripts/Deploy.s.sol";
/// @notice Deploys the Fault Proof Alpha Chad contracts.
......
......@@ -37,7 +37,7 @@
},
"src/L1/OptimismPortal2.sol": {
"initCodeHash": "0xea32d79e8297956d4f9a4c7985bb53ff8bb3735e5b307d4e118fea71f503a38e",
"sourceCodeHash": "0x2b662e100d1e282588eaaf3704aca0d0a6900ec3b8f8134e2d5d577ee372e42f"
"sourceCodeHash": "0x209d7e9ffa97a54c060f5d30e5d88684a50a7b4610336cf03880bfbc80ca669e"
},
"src/L1/ProtocolVersions.sol": {
"initCodeHash": "0x72cd467e8bcf019c02675d72ab762e088bcc9cc0f1a4e9f587fa4589f7fdd1b8",
......@@ -100,8 +100,8 @@
"sourceCodeHash": "0xa304b4b556162323d69662b4dd9a1d073d55ec661494465489bb67f1e465e7b3"
},
"src/Safe/DeputyGuardianModule.sol": {
"initCodeHash": "0x8f6adc162587ac7150045c0cf4671f23e0453417a4b7006e39eb8cb58052dc58",
"sourceCodeHash": "0x8ebf09555561d475ec51c681033b8c567281f40f310ad47312b00710f6394d34"
"initCodeHash": "0x533a9dfab7fa1f7f5e8796f0ad78b4a16f93cd8ff3cddcce946691944f6416c0",
"sourceCodeHash": "0x82c7ea737cefeb2fda38a75c7165cbad9c902a0f22a13dd46f56050223e308ce"
},
"src/Safe/LivenessGuard.sol": {
"initCodeHash": "0x16ec47f0888391638814047a1735dbac849b48e256b2e20182bbb3186d950a3c",
......@@ -120,16 +120,16 @@
"sourceCodeHash": "0x292a950cfe01923558ead684f2e014b00bc17bc07362dbd58f45b1cc121942a9"
},
"src/dispute/AnchorStateRegistry.sol": {
"initCodeHash": "0x2f8c56069e43e306b0e40fba43109188b29328e83569560021a68aa5d9f2486b",
"sourceCodeHash": "0xba941ad1f941f5a4a066182d50634fa9b190085ed82779decef71c019ba963c5"
"initCodeHash": "0x1d01bc6ff31eec22200919d7c78e1e17c13482d290386e950a3767002816164e",
"sourceCodeHash": "0x99fece0b7b5952bca60a998a8c47bfd3696e5268271d321011feea1bfb9df24d"
},
"src/dispute/DisputeGameFactory.sol": {
"initCodeHash": "0x3d65d1afd2ba6cd7ebb194859390579fd5dd95c1e18ca9a74f00d95a3a4de4fa",
"sourceCodeHash": "0xc4dbd17217b63f8117f56f78c213e57dda304fee7577fe296e1d804ebe049542"
"initCodeHash": "0xfcb7178f7ed9e9ecb095d7e5252e4353d8f964d908de6914eb61a67ce69f2a63",
"sourceCodeHash": "0x3865908f3101bbb866cb103a4f23a35e54da863b0ff11b0aa56fe5ab72786601"
},
"src/dispute/FaultDisputeGame.sol": {
"initCodeHash": "0x44407585a3dcf50d7e0d0f6c3d752fe5b18bb6837a9db138a2e0961757eb91c7",
"sourceCodeHash": "0x4f930a9e4577404887c03fd91ddfcbf9915bddcfb52e4ff8d7a00099c6ad0f29"
"initCodeHash": "0x1a645e296fa5a9a707726d9b79f5b87a9337198351c9c966e785389c1ddc745b",
"sourceCodeHash": "0xfc9256651556ac2a59b82e48b22e89c46e9a67327a84c308c9745d96ef410d1d"
},
"src/dispute/weth/DelayedWETH.sol": {
"initCodeHash": "0x7b6ec89eaec09e369426e73161a9c6932223bb1f974377190c3f6f552995da35",
......
......@@ -200,7 +200,7 @@
{
"inputs": [
{
"internalType": "ClaimHash",
"internalType": "Hash",
"name": "",
"type": "bytes32"
}
......
......@@ -223,7 +223,7 @@
{
"inputs": [
{
"internalType": "ClaimHash",
"internalType": "Hash",
"name": "",
"type": "bytes32"
}
......
......@@ -46,7 +46,7 @@
"label": "claims",
"offset": 0,
"slot": "3",
"type": "mapping(ClaimHash => bool)"
"type": "mapping(Hash => bool)"
},
{
"bytes": "32",
......
......@@ -46,7 +46,7 @@
"label": "claims",
"offset": 0,
"slot": "3",
"type": "mapping(ClaimHash => bool)"
"type": "mapping(Hash => bool)"
},
{
"bytes": "32",
......
......@@ -16,7 +16,7 @@ import { ISemver } from "src/universal/ISemver.sol";
import { Constants } from "src/libraries/Constants.sol";
import "src/libraries/PortalErrors.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
/// @custom:proxied
/// @title OptimismPortal2
......
......@@ -10,7 +10,7 @@ import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import { ISemver } from "src/universal/ISemver.sol";
import { Unauthorized } from "src/libraries/PortalErrors.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
/// @title DeputyGuardianModule
/// @notice This module is intended to be enabled on the Security Council Safe, which will own the Guardian role in the
......@@ -43,8 +43,8 @@ contract DeputyGuardianModule is ISemver {
address internal immutable DEPUTY_GUARDIAN;
/// @notice Semantic version.
/// @custom:semver 1.0.0
string public constant version = "1.0.0";
/// @custom:semver 1.0.1
string public constant version = "1.0.1";
// Constructor to initialize the Safe and baseModule instances
constructor(Safe _safe, SuperchainConfig _superchainConfig, address _deputyGuardian) {
......
......@@ -9,7 +9,7 @@ import { IFaultDisputeGame } from "src/dispute/interfaces/IFaultDisputeGame.sol"
import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import { IDisputeGameFactory } from "src/dispute/interfaces/IDisputeGameFactory.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
/// @title AnchorStateRegistry
/// @notice The AnchorStateRegistry is a contract that stores the latest "anchor" state for each available
......@@ -24,8 +24,8 @@ contract AnchorStateRegistry is Initializable, IAnchorStateRegistry, ISemver {
}
/// @notice Semantic version.
/// @custom:semver 0.1.0
string public constant version = "0.1.0";
/// @custom:semver 0.1.1
string public constant version = "0.1.1";
/// @notice DisputeGameFactory address.
IDisputeGameFactory internal immutable DISPUTE_GAME_FACTORY;
......
......@@ -8,10 +8,8 @@ import { ISemver } from "src/universal/ISemver.sol";
import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import { IDisputeGameFactory } from "src/dispute/interfaces/IDisputeGameFactory.sol";
import { LibGameId } from "src/dispute/lib/LibGameId.sol";
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
import "src/dispute/lib/Types.sol";
import "src/dispute/lib/Errors.sol";
/// @title DisputeGameFactory
/// @notice A factory contract for creating `IDisputeGame` contracts. All created dispute games are stored in both a
......@@ -23,8 +21,8 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver
using LibClone for address;
/// @notice Semantic version.
/// @custom:semver 0.6.0
string public constant version = "0.6.0";
/// @custom:semver 0.7.0
string public constant version = "0.7.0";
/// @inheritdoc IDisputeGameFactory
mapping(GameType => IDisputeGame) public gameImpls;
......@@ -68,7 +66,8 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver
returns (IDisputeGame proxy_, Timestamp timestamp_)
{
Hash uuid = getGameUUID(_gameType, _rootClaim, _extraData);
(, timestamp_, proxy_) = _disputeGames[uuid].unpack();
(, Timestamp timestamp, address proxy) = _disputeGames[uuid].unpack();
(proxy_, timestamp_) = (IDisputeGame(proxy), timestamp);
}
/// @inheritdoc IDisputeGameFactory
......@@ -77,7 +76,8 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver
view
returns (GameType gameType_, Timestamp timestamp_, IDisputeGame proxy_)
{
(gameType_, timestamp_, proxy_) = _disputeGameList[_index].unpack();
(GameType gameType, Timestamp timestamp, address proxy) = _disputeGameList[_index].unpack();
(gameType_, timestamp_, proxy_) = (gameType, timestamp, IDisputeGame(proxy));
}
/// @inheritdoc IDisputeGameFactory
......@@ -123,7 +123,7 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver
if (GameId.unwrap(_disputeGames[uuid]) != bytes32(0)) revert GameAlreadyExists(uuid);
// Pack the game ID.
GameId id = LibGameId.pack(_gameType, Timestamp.wrap(uint64(block.timestamp)), proxy_);
GameId id = LibGameId.pack(_gameType, Timestamp.wrap(uint64(block.timestamp)), address(proxy_));
// Store the dispute game id in the mapping & emit the `DisputeGameCreated` event.
_disputeGames[uuid] = id;
......@@ -167,7 +167,7 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver
// Perform a reverse linear search for the `_n` most recent games of type `_gameType`.
for (uint256 i = _start; i >= 0 && i <= _start;) {
GameId id = _disputeGameList[i];
(GameType gameType, Timestamp timestamp, IDisputeGame proxy) = id.unpack();
(GameType gameType, Timestamp timestamp, address proxy) = id.unpack();
if (gameType.raw() == _gameType.raw()) {
// Increase the size of the `games_` array by 1.
......@@ -177,8 +177,8 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver
mstore(games_, add(mload(games_), 0x01))
}
bytes memory extraData = proxy.extraData();
Claim rootClaim = proxy.rootClaim();
bytes memory extraData = IDisputeGame(proxy).extraData();
Claim rootClaim = IDisputeGame(proxy).rootClaim();
games_[games_.length - 1] = GameSearchResult({
index: i,
metadata: id,
......
......@@ -13,10 +13,9 @@ import { IAnchorStateRegistry } from "src/dispute/interfaces/IAnchorStateRegistr
import { Clone } from "@solady/utils/Clone.sol";
import { Types } from "src/libraries/Types.sol";
import { ISemver } from "src/universal/ISemver.sol";
import { LibClock } from "src/dispute/lib/LibUDT.sol";
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
import "src/dispute/lib/Types.sol";
import "src/dispute/lib/Errors.sol";
/// @title FaultDisputeGame
/// @notice An implementation of the `IFaultDisputeGame` interface.
......@@ -62,8 +61,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
Position internal constant ROOT_POSITION = Position.wrap(1);
/// @notice Semantic version.
/// @custom:semver 0.18.0
string public constant version = "0.18.0";
/// @custom:semver 0.18.1
string public constant version = "0.18.1";
/// @notice The starting timestamp of the game
Timestamp public createdAt;
......@@ -84,7 +83,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
mapping(address => uint256) public credit;
/// @notice A mapping to allow for constant-time lookups of existing claims.
mapping(ClaimHash => bool) public claims;
mapping(Hash => bool) public claims;
/// @notice A mapping of subgames rooted at a claim index to other claim indices in the subgame.
mapping(uint256 => uint256[]) public subgames;
......@@ -365,7 +364,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
// INVARIANT: There cannot be multiple identical claims with identical moves on the same challengeIndex. Multiple
// claims at the same position may dispute the same challengeIndex. However, they must have different
// values.
ClaimHash claimHash = _claim.hashClaimPos(nextPosition, _challengeIndex);
Hash claimHash = _claim.hashClaimPos(nextPosition, _challengeIndex);
if (claims[claimHash]) revert ClaimAlreadyExists();
claims[claimHash] = true;
......
......@@ -4,8 +4,8 @@ pragma solidity 0.8.15;
import { IDelayedWETH } from "src/dispute/interfaces/IDelayedWETH.sol";
import { IAnchorStateRegistry } from "src/dispute/interfaces/IAnchorStateRegistry.sol";
import { FaultDisputeGame, IFaultDisputeGame, IBigStepper, IInitializable } from "src/dispute/FaultDisputeGame.sol";
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
import "src/dispute/lib/Types.sol";
import "src/dispute/lib/Errors.sol";
/// @title PermissionedDisputeGame
/// @notice PermissionedDisputeGame is a contract that inherits from `FaultDisputeGame`, and contains two roles:
......
......@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
import { IDisputeGameFactory } from "src/dispute/interfaces/IDisputeGameFactory.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
/// @title IAnchorStateRegistry
/// @notice Describes a contract that stores the anchor state for each game type.
......
......@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
import { IInitializable } from "src/dispute/interfaces/IInitializable.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
/// @title IDisputeGame
/// @notice The generic interface for a DisputeGame contract.
......
......@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
import { IDisputeGame } from "./IDisputeGame.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
/// @title IDisputeGameFactory
/// @notice The interface for a DisputeGameFactory contract.
......
......@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
import { IDisputeGame } from "./IDisputeGame.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
/// @title IFaultDisputeGame
/// @notice The interface for a fault proof backed dispute game.
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/LibUDT.sol";
////////////////////////////////////////////////////////////////
// `DisputeGameFactory` Errors //
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import "src/libraries/DisputeTypes.sol";
import "src/dispute/interfaces/IDisputeGame.sol";
/// @title LibGameId
/// @notice Utility functions for packing and unpacking GameIds.
library LibGameId {
/// @notice Packs values into a 32 byte GameId type.
/// @param _gameType The game type.
/// @param _timestamp The timestamp of the game's creation.
/// @param _gameProxy The game proxy address.
/// @return gameId_ The packed GameId.
function pack(
GameType _gameType,
Timestamp _timestamp,
IDisputeGame _gameProxy
)
internal
pure
returns (GameId gameId_)
{
assembly {
gameId_ := or(or(shl(224, _gameType), shl(160, _timestamp)), _gameProxy)
}
}
/// @notice Unpacks values from a 32 byte GameId type.
/// @param _gameId The packed GameId.
/// @return gameType_ The game type.
/// @return timestamp_ The timestamp of the game's creation.
/// @return gameProxy_ The game proxy address.
function unpack(GameId _gameId)
internal
pure
returns (GameType gameType_, Timestamp timestamp_, IDisputeGame gameProxy_)
{
assembly {
gameType_ := shr(224, _gameId)
timestamp_ := and(shr(160, _gameId), 0xFFFFFFFFFFFFFFFF)
gameProxy_ := and(_gameId, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import "src/libraries/DisputeTypes.sol";
/// @title Hashing
/// @notice This library contains all of the hashing utilities used in the Cannon contracts.
library LibHashing {
/// @notice Hashes a claim and a position together.
/// @param _claim A Claim type.
/// @param _position The position of `claim`.
/// @param _challengeIndex The index of the claim being moved against.
/// @return claimHash_ A hash of abi.encodePacked(claim, position|challengeIndex);
function hashClaimPos(
Claim _claim,
Position _position,
uint256 _challengeIndex
)
internal
pure
returns (ClaimHash claimHash_)
{
assembly {
mstore(0x00, _claim)
mstore(0x20, or(shl(128, _position), and(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, _challengeIndex)))
claimHash_ := keccak256(0x00, 0x40)
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
using LibPosition for Position global;
/// @notice A `Position` represents a position of a claim within the game tree.
/// @dev This is represented as a "generalized index" where the high-order bit
/// is the level in the tree and the remaining bits is a unique bit pattern, allowing
/// a unique identifier for each node in the tree. Mathematically, it is calculated
/// as 2^{depth} + indexAtDepth.
type Position is uint128;
/// @title LibPosition
/// @notice This library contains helper functions for working with the `Position` type.
......@@ -156,7 +162,13 @@ library LibPosition {
returns (Position ancestor_)
{
// This function only works for positions that are below the upper bound.
if (_position.depth() <= _upperBoundExclusive) revert ClaimAboveSplit();
if (_position.depth() <= _upperBoundExclusive) {
assembly {
// Revert with `ClaimAboveSplit()`
mstore(0x00, 0xb34b5c22)
revert(0x1C, 0x04)
}
}
// Grab the global trace ancestor.
ancestor_ = traceAncestor(_position);
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/LibPosition.sol";
using LibClaim for Claim global;
using LibHash for Hash global;
using LibDuration for Duration global;
using LibClock for Clock global;
using LibGameId for GameId global;
using LibTimestamp for Timestamp global;
using LibVMStatus for VMStatus global;
using LibGameType for GameType global;
/// @notice A `Clock` represents a packed `Duration` and `Timestamp`
/// @dev The packed layout of this type is as follows:
/// ┌────────────┬────────────────┐
/// │ Bits │ Value │
/// ├────────────┼────────────────┤
/// │ [0, 64) │ Duration │
/// │ [64, 128) │ Timestamp │
/// └────────────┴────────────────┘
type Clock is uint128;
/// @title LibClock
/// @notice This library contains helper functions for working with the `Clock` type.
......@@ -47,6 +66,60 @@ library LibClock {
}
}
/// @notice A `GameId` represents a packed 4 byte game ID, a 8 byte timestamp, and a 20 byte address.
/// @dev The packed layout of this type is as follows:
/// ┌───────────┬───────────┐
/// │ Bits │ Value │
/// ├───────────┼───────────┤
/// │ [0, 32) │ Game Type │
/// │ [32, 96) │ Timestamp │
/// │ [96, 256) │ Address │
/// └───────────┴───────────┘
type GameId is bytes32;
/// @title LibGameId
/// @notice Utility functions for packing and unpacking GameIds.
library LibGameId {
/// @notice Packs values into a 32 byte GameId type.
/// @param _gameType The game type.
/// @param _timestamp The timestamp of the game's creation.
/// @param _gameProxy The game proxy address.
/// @return gameId_ The packed GameId.
function pack(
GameType _gameType,
Timestamp _timestamp,
address _gameProxy
)
internal
pure
returns (GameId gameId_)
{
assembly {
gameId_ := or(or(shl(224, _gameType), shl(160, _timestamp)), _gameProxy)
}
}
/// @notice Unpacks values from a 32 byte GameId type.
/// @param _gameId The packed GameId.
/// @return gameType_ The game type.
/// @return timestamp_ The timestamp of the game's creation.
/// @return gameProxy_ The game proxy address.
function unpack(GameId _gameId)
internal
pure
returns (GameType gameType_, Timestamp timestamp_, address gameProxy_)
{
assembly {
gameType_ := shr(224, _gameId)
timestamp_ := and(shr(160, _gameId), 0xFFFFFFFFFFFFFFFF)
gameProxy_ := and(_gameId, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
}
}
}
/// @notice A claim represents an MPT root representing the state of the fault proof program.
type Claim is bytes32;
/// @title LibClaim
/// @notice This library contains helper functions for working with the `Claim` type.
library LibClaim {
......@@ -58,8 +131,33 @@ library LibClaim {
claim_ := _claim
}
}
/// @notice Hashes a claim and a position together.
/// @param _claim A Claim type.
/// @param _position The position of `claim`.
/// @param _challengeIndex The index of the claim being moved against.
/// @return claimHash_ A hash of abi.encodePacked(claim, position|challengeIndex);
function hashClaimPos(
Claim _claim,
Position _position,
uint256 _challengeIndex
)
internal
pure
returns (Hash claimHash_)
{
assembly {
mstore(0x00, _claim)
mstore(0x20, or(shl(128, _position), and(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, _challengeIndex)))
claimHash_ := keccak256(0x00, 0x40)
}
}
}
/// @notice A dedicated duration type.
/// @dev Unit: seconds
type Duration is uint64;
/// @title LibDuration
/// @notice This library contains helper functions for working with the `Duration` type.
library LibDuration {
......@@ -73,6 +171,9 @@ library LibDuration {
}
}
/// @notice A custom type for a generic hash.
type Hash is bytes32;
/// @title LibHash
/// @notice This library contains helper functions for working with the `Hash` type.
library LibHash {
......@@ -86,6 +187,9 @@ library LibHash {
}
}
/// @notice A dedicated timestamp type.
type Timestamp is uint64;
/// @title LibTimestamp
/// @notice This library contains helper functions for working with the `Timestamp` type.
library LibTimestamp {
......@@ -99,6 +203,9 @@ library LibTimestamp {
}
}
/// @notice A `VMStatus` represents the status of a VM execution.
type VMStatus is uint8;
/// @title LibVMStatus
/// @notice This library contains helper functions for working with the `VMStatus` type.
library LibVMStatus {
......@@ -112,6 +219,9 @@ library LibVMStatus {
}
}
/// @notice A `GameType` represents the type of game being played.
type GameType is uint32;
/// @title LibGameType
/// @notice This library contains helper functions for working with the `GameType` type.
library LibGameType {
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import { LibHashing } from "src/dispute/lib/LibHashing.sol";
import {
LibClaim,
LibHash,
LibDuration,
LibClock,
LibTimestamp,
LibVMStatus,
LibGameType
} from "src/dispute/lib/LibUDT.sol";
import { LibPosition } from "src/dispute/lib/LibPosition.sol";
import { LibGameId } from "src/dispute/lib/LibGameId.sol";
using LibClaim for Claim global;
using LibHashing for Claim global;
using LibHash for Hash global;
using LibPosition for Position global;
using LibDuration for Duration global;
using LibClock for Clock global;
using LibGameId for GameId global;
using LibTimestamp for Timestamp global;
using LibVMStatus for VMStatus global;
using LibGameType for GameType global;
/// @notice A custom type for a generic hash.
type Hash is bytes32;
/// @notice A claim represents an MPT root representing the state of the fault proof program.
type Claim is bytes32;
/// @notice A claim hash represents a hash of a claim and a position within the game tree.
/// @dev Keccak hash of abi.encodePacked(Claim, Position);
type ClaimHash is bytes32;
/// @notice A bondamount represents the amount of collateral that a user has locked up in a claim.
type BondAmount is uint256;
/// @notice A dedicated timestamp type.
type Timestamp is uint64;
/// @notice A dedicated duration type.
/// @dev Unit: seconds
type Duration is uint64;
/// @notice A `GameId` represents a packed 4 byte game ID, a 8 byte timestamp, and a 20 byte address.
/// @dev The packed layout of this type is as follows:
/// ┌───────────┬───────────┐
/// │ Bits │ Value │
/// ├───────────┼───────────┤
/// │ [0, 32) │ Game Type │
/// │ [32, 96) │ Timestamp │
/// │ [96, 256) │ Address │
/// └───────────┴───────────┘
type GameId is bytes32;
/// @notice A `Clock` represents a packed `Duration` and `Timestamp`
/// @dev The packed layout of this type is as follows:
/// ┌────────────┬────────────────┐
/// │ Bits │ Value │
/// ├────────────┼────────────────┤
/// │ [0, 64) │ Duration │
/// │ [64, 128) │ Timestamp │
/// └────────────┴────────────────┘
type Clock is uint128;
/// @notice A `Position` represents a position of a claim within the game tree.
/// @dev This is represented as a "generalized index" where the high-order bit
/// is the level in the tree and the remaining bits is a unique bit pattern, allowing
/// a unique identifier for each node in the tree. Mathematically, it is calculated
/// as 2^{depth} + indexAtDepth.
type Position is uint128;
/// @notice A `GameType` represents the type of game being played.
type GameType is uint32;
/// @notice A `VMStatus` represents the status of a VM execution.
type VMStatus is uint8;
import "src/dispute/lib/LibUDT.sol";
/// @notice The current status of the dispute game.
enum GameStatus {
......
......@@ -22,7 +22,7 @@ import { SuperchainConfig } from "src/L1/SuperchainConfig.sol";
import { OptimismPortal2 } from "src/L1/OptimismPortal2.sol";
import { FaultDisputeGame, IDisputeGame } from "src/dispute/FaultDisputeGame.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
import "src/libraries/PortalErrors.sol";
contract OptimismPortal2_Test is CommonTest {
......
......@@ -9,7 +9,7 @@ import "test/safe-tools/SafeTestTools.sol";
import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import { DeputyGuardianModule } from "src/Safe/DeputyGuardianModule.sol";
import { GameType } from "src/libraries/DisputeTypes.sol";
import { GameType } from "src/dispute/lib/Types.sol";
contract DeputyGuardianModule_TestInit is CommonTest, SafeTestTools {
using SafeTestLib for SafeInstance;
......@@ -241,8 +241,9 @@ contract DeputyGuardianModule_NoPortalCollisions_Test is DeputyGuardianModule_Te
/// @dev tests that no function selectors in the L1 contracts collide with the OptimismPortal2 functions called by
/// the DeputyGuardianModule.
function test_noPortalCollisions_succeeds() external {
string[] memory excludes = new string[](1);
string[] memory excludes = new string[](2);
excludes[0] = "src/L1/OptimismPortal2.sol";
excludes[1] = "src/dispute/lib/*";
Abi[] memory abis = ForgeArtifacts.getContractFunctionAbis("src/{L1,dispute,universal}/", excludes);
for (uint256 i; i < abis.length; i++) {
for (uint256 j; j < abis[i].entries.length; j++) {
......
......@@ -6,7 +6,7 @@ import { CommonBase } from "forge-std/Base.sol";
import { FaultDisputeGame } from "src/dispute/FaultDisputeGame.sol";
import { IFaultDisputeGame } from "src/dispute/interfaces/IFaultDisputeGame.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
/// @title GameSolver
/// @notice The `GameSolver` contract is a contract that can produce an array of available
......
......@@ -4,7 +4,7 @@ pragma solidity 0.8.15;
import { CommonTest } from "test/setup/CommonTest.sol";
import { MIPS } from "src/cannon/MIPS.sol";
import { PreimageOracle } from "src/cannon/PreimageOracle.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
contract MIPS_Test is CommonTest {
MIPS internal mips;
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
import "src/dispute/lib/Types.sol";
import "src/dispute/lib/Errors.sol";
import { Test } from "forge-std/Test.sol";
import { FaultDisputeGame_Init, _changeClaimStatus } from "test/dispute/FaultDisputeGame.t.sol";
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
import "src/dispute/lib/Types.sol";
import "src/dispute/lib/Errors.sol";
import { Test } from "forge-std/Test.sol";
import { DisputeGameFactory, IDisputeGameFactory } from "src/dispute/DisputeGameFactory.sol";
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
import "src/dispute/lib/Types.sol";
import "src/dispute/lib/Errors.sol";
import { Test } from "forge-std/Test.sol";
import { DisputeGameFactory, IDisputeGameFactory } from "src/dispute/DisputeGameFactory.sol";
......@@ -272,7 +272,7 @@ contract DisputeGameFactory_FindLatestGames_Test is DisputeGameFactory_Init {
games = disputeGameFactory.findLatestGames(GameType.wrap(0), gameCount - 1, 1);
assertEq(games.length, 1);
assertEq(games[0].index, 30);
(GameType gameType, Timestamp createdAt, IDisputeGame game) = games[0].metadata.unpack();
(GameType gameType, Timestamp createdAt, address game) = games[0].metadata.unpack();
assertEq(gameType.raw(), 0);
assertEq(createdAt.raw(), block.timestamp);
......
......@@ -9,8 +9,8 @@ import { FaultDisputeGame } from "src/dispute/FaultDisputeGame.sol";
import { DelayedWETH } from "src/dispute/weth/DelayedWETH.sol";
import { PreimageOracle } from "src/cannon/PreimageOracle.sol";
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
import "src/dispute/lib/Types.sol";
import "src/dispute/lib/Errors.sol";
import { LibClock } from "src/dispute/lib/LibUDT.sol";
import { LibPosition } from "src/dispute/lib/LibPosition.sol";
import { IPreimageOracle } from "src/dispute/interfaces/IBigStepper.sol";
......
......@@ -11,8 +11,8 @@ import { L2OutputOracle } from "src/L1/L2OutputOracle.sol";
import { PreimageOracle } from "src/cannon/PreimageOracle.sol";
import { PreimageKeyLib } from "src/cannon/PreimageKeyLib.sol";
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
import "src/dispute/lib/Types.sol";
import "src/dispute/lib/Errors.sol";
import { Types } from "src/libraries/Types.sol";
import { LibClock } from "src/dispute/lib/LibUDT.sol";
import { LibPosition } from "src/dispute/lib/LibPosition.sol";
......
......@@ -3,7 +3,7 @@ pragma solidity ^0.8.15;
import { Test } from "forge-std/Test.sol";
import { LibClock } from "src/dispute/lib/LibUDT.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
/// @notice Tests for `LibClock`
contract LibClock_Test is Test {
......
......@@ -3,25 +3,24 @@ pragma solidity ^0.8.15;
import { Test } from "forge-std/Test.sol";
import { LibGameId } from "src/dispute/lib/LibGameId.sol";
import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
contract LibGameId_Test is Test {
/// @dev Tests that a round trip of packing and unpacking a GameId maintains the same values.
function testFuzz_gameId_roundTrip_succeeds(
GameType _gameType,
Timestamp _timestamp,
IDisputeGame _gameProxy
address _gameProxy
)
public
pure
{
GameId gameId = LibGameId.pack(_gameType, _timestamp, _gameProxy);
(GameType gameType_, Timestamp timestamp_, IDisputeGame gameProxy_) = LibGameId.unpack(gameId);
(GameType gameType_, Timestamp timestamp_, address gameProxy_) = LibGameId.unpack(gameId);
assertEq(GameType.unwrap(gameType_), GameType.unwrap(_gameType));
assertEq(Timestamp.unwrap(timestamp_), Timestamp.unwrap(_timestamp));
assertEq(address(gameProxy_), address(_gameProxy));
assertEq(gameProxy_, _gameProxy);
}
}
......@@ -3,7 +3,7 @@ pragma solidity ^0.8.15;
import { Test } from "forge-std/Test.sol";
import { LibPosition } from "src/dispute/lib/LibPosition.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
/// @notice Tests for `LibPosition`
contract LibPosition_Test is Test {
......
......@@ -6,8 +6,8 @@ import { StdUtils } from "forge-std/StdUtils.sol";
import { FaultDisputeGame } from "src/dispute/FaultDisputeGame.sol";
import { FaultDisputeGame_Init } from "test/dispute/FaultDisputeGame.t.sol";
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
import "src/dispute/lib/Types.sol";
import "src/dispute/lib/Errors.sol";
contract FaultDisputeGame_Solvency_Invariant is FaultDisputeGame_Init {
Claim internal constant ROOT_CLAIM = Claim.wrap(bytes32(uint256(10)));
......
......@@ -15,7 +15,7 @@ import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol";
import { Types } from "src/libraries/Types.sol";
import { FaultDisputeGame } from "src/dispute/FaultDisputeGame.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
contract OptimismPortal2_Depositor is StdUtils, ResourceMetering {
Vm internal vm;
......
......@@ -3,7 +3,7 @@ pragma solidity ^0.8.15;
import { IBigStepper, IPreimageOracle } from "src/dispute/interfaces/IBigStepper.sol";
import { PreimageOracle, PreimageKeyLib } from "src/cannon/PreimageOracle.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
/// @title AlphabetVM
/// @dev A mock VM for the purpose of testing the dispute game infrastructure. Note that this only works
......
......@@ -11,7 +11,7 @@ import { ResourceMetering } from "src/L1/ResourceMetering.sol";
import { OptimismPortal } from "src/L1/OptimismPortal.sol";
import { ForgeArtifacts } from "scripts/ForgeArtifacts.sol";
import "src/L1/ProtocolVersions.sol";
import "src/libraries/DisputeTypes.sol";
import "src/dispute/lib/Types.sol";
import "scripts/Deployer.sol";
/// @title Initializer_Test
......
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