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

feat(ctb): Add initialization check in FDG (#8792)

* Add check for initialization

* :broom:

:broom:

* slither + semver lock
parent 632525f4
This diff is collapsed.
This diff is collapsed.
......@@ -88,12 +88,12 @@
"sourceCodeHash": "0x1afb1d392e8f6a58ff86ea7f648e0d1756d4ba8d0d964279d58a390deaa53b7e"
},
"src/dispute/DisputeGameFactory.sol": {
"initCodeHash": "0x84a15994d275bea8a96af83a46849e74eb573aa579db86350b6fe358bd61ec57",
"sourceCodeHash": "0x64290a5d8138c46d2ecd308e3ef62ba04663049cce8a271b9a686ddd2e630391"
"initCodeHash": "0x6dc67d5bb1496b1360aeb7447633f28689327ee1f2df632f20d257fe8fa75c70",
"sourceCodeHash": "0xb6cc80e4e2c5bb6b527d4b523eafb72facff75cb25de036052eab380cb2d3213"
},
"src/dispute/FaultDisputeGame.sol": {
"initCodeHash": "0xd93d6ae410ba47724c40094ae3a19d8e9db4c5daaf43d367c4b7af0af6fccfa0",
"sourceCodeHash": "0xeb4ef33b0134a69ddf50c59494ae05b60c07e22e0634f69aafc213fbed6e1a2b"
"initCodeHash": "0x86328a03426488472fea8ff7eca00e46c6601d5d0adab9f07ee1bc5f98605d48",
"sourceCodeHash": "0x52dd7c52bbb57fa0bdf80cc1993a5e3fc4ff6638cec13eeba59a4a17ac0570f0"
},
"src/legacy/BlockOracle.sol": {
"initCodeHash": "0x183ce41fb2842c9853f08955ddd91e345126028fad64e07ed14f593cbf9c88bc",
......@@ -104,7 +104,7 @@
"sourceCodeHash": "0xb518a9f56136a910f2450098b4823c9982f93883fe4a9ef6f6b0a89355965d38"
},
"src/legacy/FaultDisputeGame.sol": {
"initCodeHash": "0xd93d6ae410ba47724c40094ae3a19d8e9db4c5daaf43d367c4b7af0af6fccfa0",
"initCodeHash": "0x86328a03426488472fea8ff7eca00e46c6601d5d0adab9f07ee1bc5f98605d48",
"sourceCodeHash": "0x16c1020857324372169e66c57c1927c19f7763bbaa69dc9c51ae4750d9e6c7a4"
},
"src/legacy/L1BlockNumber.sol": {
......
......@@ -522,6 +522,11 @@
"name": "Resolved",
"type": "event"
},
{
"inputs": [],
"name": "AlreadyInitialized",
"type": "error"
},
{
"inputs": [],
"name": "CannotDefendRootClaim",
......
......@@ -61,5 +61,12 @@
"offset": 0,
"slot": "6",
"type": "bool"
},
{
"bytes": "1",
"label": "initialized",
"offset": 1,
"slot": "6",
"type": "bool"
}
]
\ No newline at end of file
......@@ -37,8 +37,8 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver
GameId[] internal _disputeGameList;
/// @notice Semantic version.
/// @custom:semver 0.0.6
string public constant version = "0.0.6";
/// @custom:semver 0.0.7
string public constant version = "0.0.7";
/// @notice constructs a new DisputeGameFactory contract.
constructor() OwnableUpgradeable() {
......@@ -117,41 +117,13 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, ISemver
function getGameUUID(
GameType _gameType,
Claim _rootClaim,
bytes memory _extraData
bytes calldata _extraData
)
public
pure
returns (Hash uuid_)
{
assembly {
// Grab the offsets of the other memory locations we will need to temporarily overwrite.
let gameTypeOffset := sub(_extraData, 0x60)
let rootClaimOffset := add(gameTypeOffset, 0x20)
let pointerOffset := add(rootClaimOffset, 0x20)
// Copy the memory that we will temporarily overwrite onto the stack
// so we can restore it later
let tempA := mload(gameTypeOffset)
let tempB := mload(rootClaimOffset)
let tempC := mload(pointerOffset)
// Overwrite the memory with the data we want to hash
mstore(gameTypeOffset, _gameType)
mstore(rootClaimOffset, _rootClaim)
mstore(pointerOffset, 0x60)
// Compute the length of the memory to hash
// `0x60 + 0x20 + extraData.length` rounded to the *next* multiple of 32.
let hashLen := and(add(mload(_extraData), 0x9F), not(0x1F))
// Hash the memory to produce the UUID digest
uuid_ := keccak256(gameTypeOffset, hashLen)
// Restore the memory prior to `extraData`
mstore(gameTypeOffset, tempA)
mstore(rootClaimOffset, tempB)
mstore(pointerOffset, tempC)
}
uuid_ = Hash.wrap(keccak256(abi.encode(_gameType, _rootClaim, _extraData)));
}
/// @inheritdoc IDisputeGameFactory
......
......@@ -24,6 +24,9 @@ error UnexpectedRootClaim(Claim rootClaim);
// `FaultDisputeGame` Errors //
////////////////////////////////////////////////////////////////
/// @notice Thrown when a dispute game has already been initialized.
error AlreadyInitialized();
/// @notice Thrown when a supplied bond is too low to cover the
/// cost of the next possible counter claim.
error BondTooLow();
......
......@@ -206,6 +206,12 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
assertEq(gameProxy.l1Head().raw(), blockhash(block.number - 1));
}
/// @dev Tests that the game cannot be initialized twice.
function test_initialize_onlyOnce_succeeds() public {
vm.expectRevert(AlreadyInitialized.selector);
gameProxy.initialize();
}
/// @dev Tests that a move while the game status is not `IN_PROGRESS` causes the call to revert
/// with the `GameNotInProgress` error
function test_move_gameNotInProgress_reverts() public {
......
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