Commit eb345128 authored by clabby's avatar clabby

Add split depth footgun checks

chores
parent 9718cf44
This diff is collapsed.
......@@ -51,7 +51,7 @@
"faultGameMaxDuration": 1200,
"outputBisectionGameGenesisBlock": 0,
"outputBisectionGameGenesisOutputRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"outputBisectionGameSplitDepth": 15,
"outputBisectionGameSplitDepth": 14,
"systemConfigStartBlock": 0,
"requiredProtocolVersion": "0x0000000000000000000000000000000000000000000000000000000000000000",
"recommendedProtocolVersion": "0x0000000000000000000000000000000000000000000000000000000000000000"
......
......@@ -105,7 +105,9 @@ contract OutputBisectionGame is IOutputBisectionGame, Clone, ISemver {
Duration _gameDuration,
IBigStepper _vm
) {
if (_splitDepth >= _maxGameDepth) revert InvalidSplitDepth();
// The split depth cannot be greater than or equal to the max game depth, and it must
// be even due to the constraint laid out in `verifyExecBisectionRoot`
if (_splitDepth >= _maxGameDepth || _splitDepth % 2 != 0) revert InvalidSplitDepth();
GAME_TYPE = _gameType;
ABSOLUTE_PRESTATE = _absolutePrestate;
......
......@@ -95,6 +95,45 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init {
// `IDisputeGame` Implementation Tests //
////////////////////////////////////////////////////////////////
/// @dev Tests that the constructor of the `OutputBisectionGame` reverts when the `_splitDepth`
/// parameter is either:
/// 1. Greater than or equal to the `MAX_GAME_DEPTH`
/// 2. Odd
function test_constructor_wrongArgs_reverts(uint256 _splitDepth) public {
AlphabetVM alphabetVM = new AlphabetVM(ABSOLUTE_PRESTATE);
// Test that the constructor reverts when the `_splitDepth` parameter is greater than or equal
// to the `MAX_GAME_DEPTH` parameter.
_splitDepth = bound(_splitDepth, 2 ** 3, type(uint256).max);
vm.expectRevert(InvalidSplitDepth.selector);
new OutputBisectionGame({
_gameType: GAME_TYPE,
_absolutePrestate: ABSOLUTE_PRESTATE,
_genesisBlockNumber: GENESIS_BLOCK_NUMBER,
_genesisOutputRoot: GENESIS_OUTPUT_ROOT,
_maxGameDepth: 2**3,
_splitDepth: _splitDepth,
_gameDuration: Duration.wrap(7 days),
_vm: alphabetVM
});
// Test that the constructor reverts when the `_splitDepth` parameter is odd.
_splitDepth = bound(_splitDepth, 0, 2 ** 3 - 1);
if (_splitDepth % 2 == 0) _splitDepth += 1;
vm.expectRevert(InvalidSplitDepth.selector);
new OutputBisectionGame({
_gameType: GAME_TYPE,
_absolutePrestate: ABSOLUTE_PRESTATE,
_genesisBlockNumber: GENESIS_BLOCK_NUMBER,
_genesisOutputRoot: GENESIS_OUTPUT_ROOT,
_maxGameDepth: 2**3,
_splitDepth: _splitDepth,
_gameDuration: Duration.wrap(7 days),
_vm: alphabetVM
});
}
/// @dev Tests that the game's root claim is set correctly.
function test_rootClaim_succeeds() public {
assertEq(Claim.unwrap(gameProxy.rootClaim()), Claim.unwrap(ROOT_CLAIM));
......
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