Commit cbb7c3b2 authored by clabby's avatar clabby Committed by GitHub

feat(ctb): Set L1 head hash in DGF rather than the FDG (#9499)

* Set L1 head in dispute game factory

* semver
parent 70bd6234
This diff is collapsed.
This diff is collapsed.
...@@ -92,12 +92,12 @@ ...@@ -92,12 +92,12 @@
"sourceCodeHash": "0x1afb1d392e8f6a58ff86ea7f648e0d1756d4ba8d0d964279d58a390deaa53b7e" "sourceCodeHash": "0x1afb1d392e8f6a58ff86ea7f648e0d1756d4ba8d0d964279d58a390deaa53b7e"
}, },
"src/dispute/DisputeGameFactory.sol": { "src/dispute/DisputeGameFactory.sol": {
"initCodeHash": "0x2ca7307516f9d0bb0abb299df67f2483f3168eed4055e46e377f637a719cfb77", "initCodeHash": "0x80d749a56c1776930fe0deb5c3c646217716e5875ace99c4d036af0452236476",
"sourceCodeHash": "0xe1891e7e6a1928b9a2ddc47d1f010650f1125a0617b8bf32190176a3bb674b4f" "sourceCodeHash": "0x1e5a6deded88804971fc1847c9eac65921771bff353437c0b29ed2f55513b984"
}, },
"src/dispute/FaultDisputeGame.sol": { "src/dispute/FaultDisputeGame.sol": {
"initCodeHash": "0xca9b1b10500ef59c60f0d575cc3bad28bf6554fbbd1edc26ee0e9225e2c36c86", "initCodeHash": "0x206faab5d19598def839adac4f85427b945b222adc8401626fd1d7a58ec52262",
"sourceCodeHash": "0xd1e1f952c6112f5126601740cfabfdd3e5692cfaadcc9f5316a30bd48c10cc0b" "sourceCodeHash": "0xfafd5423f3ffb2101cba4feb023127a887838423146f1838a9d8c6e9853c73c7"
}, },
"src/legacy/DeployerWhitelist.sol": { "src/legacy/DeployerWhitelist.sol": {
"initCodeHash": "0x8de80fb23b26dd9d849f6328e56ea7c173cd9e9ce1f05c9beea559d1720deb3d", "initCodeHash": "0x8de80fb23b26dd9d849f6328e56ea7c173cd9e9ce1f05c9beea559d1720deb3d",
......
...@@ -357,11 +357,11 @@ ...@@ -357,11 +357,11 @@
"outputs": [ "outputs": [
{ {
"internalType": "Hash", "internalType": "Hash",
"name": "", "name": "l1Head_",
"type": "bytes32" "type": "bytes32"
} }
], ],
"stateMutability": "view", "stateMutability": "pure",
"type": "function" "type": "function"
}, },
{ {
......
...@@ -367,11 +367,11 @@ ...@@ -367,11 +367,11 @@
"outputs": [ "outputs": [
{ {
"internalType": "Hash", "internalType": "Hash",
"name": "", "name": "l1Head_",
"type": "bytes32" "type": "bytes32"
} }
], ],
"stateMutability": "view", "stateMutability": "pure",
"type": "function" "type": "function"
}, },
{ {
......
...@@ -20,53 +20,46 @@ ...@@ -20,53 +20,46 @@
"slot": "0", "slot": "0",
"type": "enum GameStatus" "type": "enum GameStatus"
}, },
{
"bytes": "32",
"label": "l1Head",
"offset": 0,
"slot": "1",
"type": "Hash"
},
{ {
"bytes": "32", "bytes": "32",
"label": "claimData", "label": "claimData",
"offset": 0, "offset": 0,
"slot": "2", "slot": "1",
"type": "struct IFaultDisputeGame.ClaimData[]" "type": "struct IFaultDisputeGame.ClaimData[]"
}, },
{ {
"bytes": "32", "bytes": "32",
"label": "credit", "label": "credit",
"offset": 0, "offset": 0,
"slot": "3", "slot": "2",
"type": "mapping(address => uint256)" "type": "mapping(address => uint256)"
}, },
{ {
"bytes": "32", "bytes": "32",
"label": "claims", "label": "claims",
"offset": 0, "offset": 0,
"slot": "4", "slot": "3",
"type": "mapping(ClaimHash => bool)" "type": "mapping(ClaimHash => bool)"
}, },
{ {
"bytes": "32", "bytes": "32",
"label": "subgames", "label": "subgames",
"offset": 0, "offset": 0,
"slot": "5", "slot": "4",
"type": "mapping(uint256 => uint256[])" "type": "mapping(uint256 => uint256[])"
}, },
{ {
"bytes": "1", "bytes": "1",
"label": "subgameAtRootResolved", "label": "subgameAtRootResolved",
"offset": 0, "offset": 0,
"slot": "6", "slot": "5",
"type": "bool" "type": "bool"
}, },
{ {
"bytes": "1", "bytes": "1",
"label": "initialized", "label": "initialized",
"offset": 1, "offset": 1,
"slot": "6", "slot": "5",
"type": "bool" "type": "bool"
} }
] ]
\ No newline at end of file
...@@ -20,53 +20,46 @@ ...@@ -20,53 +20,46 @@
"slot": "0", "slot": "0",
"type": "enum GameStatus" "type": "enum GameStatus"
}, },
{
"bytes": "32",
"label": "l1Head",
"offset": 0,
"slot": "1",
"type": "Hash"
},
{ {
"bytes": "32", "bytes": "32",
"label": "claimData", "label": "claimData",
"offset": 0, "offset": 0,
"slot": "2", "slot": "1",
"type": "struct IFaultDisputeGame.ClaimData[]" "type": "struct IFaultDisputeGame.ClaimData[]"
}, },
{ {
"bytes": "32", "bytes": "32",
"label": "credit", "label": "credit",
"offset": 0, "offset": 0,
"slot": "3", "slot": "2",
"type": "mapping(address => uint256)" "type": "mapping(address => uint256)"
}, },
{ {
"bytes": "32", "bytes": "32",
"label": "claims", "label": "claims",
"offset": 0, "offset": 0,
"slot": "4", "slot": "3",
"type": "mapping(ClaimHash => bool)" "type": "mapping(ClaimHash => bool)"
}, },
{ {
"bytes": "32", "bytes": "32",
"label": "subgames", "label": "subgames",
"offset": 0, "offset": 0,
"slot": "5", "slot": "4",
"type": "mapping(uint256 => uint256[])" "type": "mapping(uint256 => uint256[])"
}, },
{ {
"bytes": "1", "bytes": "1",
"label": "subgameAtRootResolved", "label": "subgameAtRootResolved",
"offset": 0, "offset": 0,
"slot": "6", "slot": "5",
"type": "bool" "type": "bool"
}, },
{ {
"bytes": "1", "bytes": "1",
"label": "initialized", "label": "initialized",
"offset": 1, "offset": 1,
"slot": "6", "slot": "5",
"type": "bool" "type": "bool"
} }
] ]
\ No newline at end of file
...@@ -24,8 +24,8 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver ...@@ -24,8 +24,8 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver
using ClonesWithImmutableArgs for address; using ClonesWithImmutableArgs for address;
/// @notice Semantic version. /// @notice Semantic version.
/// @custom:semver 0.1.0 /// @custom:semver 0.2.0
string public constant version = "0.1.0"; string public constant version = "0.2.0";
/// @inheritdoc IDisputeGameFactory /// @inheritdoc IDisputeGameFactory
mapping(GameType => IDisputeGame) public gameImpls; mapping(GameType => IDisputeGame) public gameImpls;
...@@ -102,8 +102,11 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver ...@@ -102,8 +102,11 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver
// If the required initialization bond is not met, revert. // If the required initialization bond is not met, revert.
if (msg.value < initBonds[_gameType]) revert InsufficientBond(); if (msg.value < initBonds[_gameType]) revert InsufficientBond();
// Get the hash of the parent block.
bytes32 parentHash = blockhash(block.number - 1);
// Clone the implementation contract and initialize it with the given parameters. // Clone the implementation contract and initialize it with the given parameters.
proxy_ = IDisputeGame(address(impl).clone(abi.encodePacked(_rootClaim, _extraData))); proxy_ = IDisputeGame(address(impl).clone(abi.encodePacked(_rootClaim, parentHash, _extraData)));
proxy_.initialize{ value: msg.value }(); proxy_.initialize{ value: msg.value }();
// Compute the unique identifier for the dispute game. // Compute the unique identifier for the dispute game.
......
...@@ -62,9 +62,6 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { ...@@ -62,9 +62,6 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
/// @inheritdoc IDisputeGame /// @inheritdoc IDisputeGame
GameStatus public status; GameStatus public status;
/// @inheritdoc IFaultDisputeGame
Hash public l1Head;
/// @notice An append-only array of all claims made during the dispute game. /// @notice An append-only array of all claims made during the dispute game.
ClaimData[] public claimData; ClaimData[] public claimData;
...@@ -84,8 +81,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { ...@@ -84,8 +81,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
bool internal initialized; bool internal initialized;
/// @notice Semantic version. /// @notice Semantic version.
/// @custom:semver 0.3.0 /// @custom:semver 0.4.0
string public constant version = "0.3.0"; string public constant version = "0.4.0";
/// @param _gameType The type ID of the game. /// @param _gameType The type ID of the game.
/// @param _absolutePrestate The absolute prestate of the instruction trace. /// @param _absolutePrestate The absolute prestate of the instruction trace.
...@@ -318,7 +315,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { ...@@ -318,7 +315,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
IPreimageOracle oracle = VM.oracle(); IPreimageOracle oracle = VM.oracle();
if (_ident == LocalPreimageKey.L1_HEAD_HASH) { if (_ident == LocalPreimageKey.L1_HEAD_HASH) {
// Load the L1 head hash // Load the L1 head hash
oracle.loadLocalData(_ident, uuid.raw(), l1Head.raw(), 32, _partOffset); oracle.loadLocalData(_ident, uuid.raw(), l1Head().raw(), 32, _partOffset);
} else if (_ident == LocalPreimageKey.STARTING_OUTPUT_ROOT) { } else if (_ident == LocalPreimageKey.STARTING_OUTPUT_ROOT) {
// Load the starting proposal's output root. // Load the starting proposal's output root.
oracle.loadLocalData(_ident, uuid.raw(), starting.raw(), 32, _partOffset); oracle.loadLocalData(_ident, uuid.raw(), starting.raw(), 32, _partOffset);
...@@ -344,9 +341,14 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { ...@@ -344,9 +341,14 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
} }
} }
/// @inheritdoc IFaultDisputeGame
function l1Head() public pure returns (Hash l1Head_) {
l1Head_ = Hash.wrap(_getArgFixedBytes(0x20));
}
/// @inheritdoc IFaultDisputeGame /// @inheritdoc IFaultDisputeGame
function l2BlockNumber() public pure returns (uint256 l2BlockNumber_) { function l2BlockNumber() public pure returns (uint256 l2BlockNumber_) {
l2BlockNumber_ = _getArgUint256(0x20); l2BlockNumber_ = _getArgUint256(0x40);
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
...@@ -457,7 +459,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { ...@@ -457,7 +459,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
function extraData() public pure returns (bytes memory extraData_) { function extraData() public pure returns (bytes memory extraData_) {
// The extra data starts at the second word within the cwia calldata and // The extra data starts at the second word within the cwia calldata and
// is 32 bytes long. // is 32 bytes long.
extraData_ = _getArgDynBytes(0x20, 0x20); extraData_ = _getArgDynBytes(0x40, 0x20);
} }
/// @inheritdoc IDisputeGame /// @inheritdoc IDisputeGame
...@@ -495,9 +497,9 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { ...@@ -495,9 +497,9 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
// This is to prevent adding extra bytes to the `extraData` that result in a different game UUID in the factory, // This is to prevent adding extra bytes to the `extraData` that result in a different game UUID in the factory,
// but are not used by the game, which would allow for multiple dispute games for the same output proposal to // but are not used by the game, which would allow for multiple dispute games for the same output proposal to
// be created. // be created.
// Expected length: 0x46 (0x04 selector + 0x20 root claim + 0x20 extraData + 0x02 CWIA bytes) // Expected length: 0x66 (0x04 selector + 0x20 root claim + 0x20 l1 head + 0x20 extraData + 0x02 CWIA bytes)
assembly { assembly {
if gt(calldatasize(), 0x46) { if gt(calldatasize(), 0x66) {
// Store the selector for `ExtraDataTooLong()` & revert // Store the selector for `ExtraDataTooLong()` & revert
mstore(0x00, 0xc407e025) mstore(0x00, 0xc407e025)
revert(0x1C, 0x04) revert(0x1C, 0x04)
...@@ -520,9 +522,6 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { ...@@ -520,9 +522,6 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
// Set the game's starting timestamp // Set the game's starting timestamp
createdAt = Timestamp.wrap(uint64(block.timestamp)); createdAt = Timestamp.wrap(uint64(block.timestamp));
// Persist the blockhash of the parent block.
l1Head = Hash.wrap(blockhash(block.number - 1));
// Set the game as initialized. // Set the game as initialized.
initialized = true; initialized = true;
} }
......
...@@ -350,6 +350,10 @@ contract FakeClone { ...@@ -350,6 +350,10 @@ contract FakeClone {
return hex"FF0420"; return hex"FF0420";
} }
function parentHash() external pure returns (bytes32) {
return bytes32(0);
}
function rootClaim() external pure returns (Claim) { function rootClaim() external pure returns (Claim) {
return Claim.wrap(bytes32(0)); return Claim.wrap(bytes32(0));
} }
......
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