github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/libraries/DisputeTypes.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity ^0.8.15; 3 4 import { LibHashing } from "src/dispute/lib/LibHashing.sol"; 5 import { 6 LibClaim, 7 LibHash, 8 LibDuration, 9 LibClock, 10 LibTimestamp, 11 LibVMStatus, 12 LibGameType 13 } from "src/dispute/lib/LibUDT.sol"; 14 import { LibPosition } from "src/dispute/lib/LibPosition.sol"; 15 import { LibGameId } from "src/dispute/lib/LibGameId.sol"; 16 17 using LibClaim for Claim global; 18 using LibHashing for Claim global; 19 using LibHash for Hash global; 20 using LibPosition for Position global; 21 using LibDuration for Duration global; 22 using LibClock for Clock global; 23 using LibGameId for GameId global; 24 using LibTimestamp for Timestamp global; 25 using LibVMStatus for VMStatus global; 26 using LibGameType for GameType global; 27 28 /// @notice A custom type for a generic hash. 29 type Hash is bytes32; 30 31 /// @notice A claim represents an MPT root representing the state of the fault proof program. 32 type Claim is bytes32; 33 34 /// @notice A claim hash represents a hash of a claim and a position within the game tree. 35 /// @dev Keccak hash of abi.encodePacked(Claim, Position); 36 type ClaimHash is bytes32; 37 38 /// @notice A bondamount represents the amount of collateral that a user has locked up in a claim. 39 type BondAmount is uint256; 40 41 /// @notice A dedicated timestamp type. 42 type Timestamp is uint64; 43 44 /// @notice A dedicated duration type. 45 /// @dev Unit: seconds 46 type Duration is uint64; 47 48 /// @notice A `GameId` represents a packed 1 byte game ID, an 11 byte timestamp, and a 20 byte address. 49 /// @dev The packed layout of this type is as follows: 50 /// ┌───────────┬───────────┐ 51 /// │ Bits │ Value │ 52 /// ├───────────┼───────────┤ 53 /// │ [0, 8) │ Game Type │ 54 /// │ [8, 96) │ Timestamp │ 55 /// │ [96, 256) │ Address │ 56 /// └───────────┴───────────┘ 57 type GameId is bytes32; 58 59 /// @notice A `Clock` represents a packed `Duration` and `Timestamp` 60 /// @dev The packed layout of this type is as follows: 61 /// ┌────────────┬────────────────┐ 62 /// │ Bits │ Value │ 63 /// ├────────────┼────────────────┤ 64 /// │ [0, 64) │ Duration │ 65 /// │ [64, 128) │ Timestamp │ 66 /// └────────────┴────────────────┘ 67 type Clock is uint128; 68 69 /// @notice A `Position` represents a position of a claim within the game tree. 70 /// @dev This is represented as a "generalized index" where the high-order bit 71 /// is the level in the tree and the remaining bits is a unique bit pattern, allowing 72 /// a unique identifier for each node in the tree. Mathematically, it is calculated 73 /// as 2^{depth} + indexAtDepth. 74 type Position is uint128; 75 76 /// @notice A `GameType` represents the type of game being played. 77 type GameType is uint32; 78 79 /// @notice A `VMStatus` represents the status of a VM execution. 80 type VMStatus is uint8; 81 82 /// @notice The current status of the dispute game. 83 enum GameStatus { 84 // The game is currently in progress, and has not been resolved. 85 IN_PROGRESS, 86 // The game has concluded, and the `rootClaim` was challenged successfully. 87 CHALLENGER_WINS, 88 // The game has concluded, and the `rootClaim` could not be contested. 89 DEFENDER_WINS 90 } 91 92 /// @notice Represents an L2 output root and the L2 block number at which it was generated. 93 /// @custom:field root The output root. 94 /// @custom:field l2BlockNumber The L2 block number at which the output root was generated. 95 struct OutputRoot { 96 Hash root; 97 uint256 l2BlockNumber; 98 } 99 100 /// @title GameTypes 101 /// @notice A library that defines the IDs of games that can be played. 102 library GameTypes { 103 /// @dev A dispute game type the uses the cannon vm. 104 GameType internal constant CANNON = GameType.wrap(0); 105 106 /// @dev A permissioned dispute game type the uses the cannon vm. 107 GameType internal constant PERMISSIONED_CANNON = GameType.wrap(1); 108 109 /// @notice A dispute game type that uses an alphabet vm. 110 /// Not intended for production use. 111 GameType internal constant ALPHABET = GameType.wrap(255); 112 } 113 114 /// @title VMStatuses 115 /// @notice Named type aliases for the various valid VM status bytes. 116 library VMStatuses { 117 /// @notice The VM has executed successfully and the outcome is valid. 118 VMStatus internal constant VALID = VMStatus.wrap(0); 119 120 /// @notice The VM has executed successfully and the outcome is invalid. 121 VMStatus internal constant INVALID = VMStatus.wrap(1); 122 123 /// @notice The VM has paniced. 124 VMStatus internal constant PANIC = VMStatus.wrap(2); 125 126 /// @notice The VM execution is still in progress. 127 VMStatus internal constant UNFINISHED = VMStatus.wrap(3); 128 } 129 130 /// @title LocalPreimageKey 131 /// @notice Named type aliases for local `PreimageOracle` key identifiers. 132 library LocalPreimageKey { 133 /// @notice The identifier for the L1 head hash. 134 uint256 internal constant L1_HEAD_HASH = 0x01; 135 136 /// @notice The identifier for the starting output root. 137 uint256 internal constant STARTING_OUTPUT_ROOT = 0x02; 138 139 /// @notice The identifier for the disputed output root. 140 uint256 internal constant DISPUTED_OUTPUT_ROOT = 0x03; 141 142 /// @notice The identifier for the disputed L2 block number. 143 uint256 internal constant DISPUTED_L2_BLOCK_NUMBER = 0x04; 144 145 /// @notice The identifier for the chain ID. 146 uint256 internal constant CHAIN_ID = 0x05; 147 }