Skip to content

Commit 4844149

Browse files
committed
anchor game blacklisted and getAnchorGame tests
1 parent fecbee6 commit 4844149

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

packages/contracts-bedrock/interfaces/dispute/IAnchorStateRegistry.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { GameType, Hash, OutputRoot } from "src/dispute/lib/Types.sol";
1111
interface IAnchorStateRegistry {
1212
error AnchorStateRegistry_Unauthorized();
1313
error AnchorStateRegistry_InvalidAnchorGame();
14+
error AnchorStateRegistry_AnchorGameBlacklisted();
1415

1516
event AnchorNotUpdated(IFaultDisputeGame indexed game);
1617
event AnchorUpdated(IFaultDisputeGame indexed game);

packages/contracts-bedrock/src/dispute/AnchorStateRegistry.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ contract AnchorStateRegistry is Initializable, ISemver {
5555
/// @notice Thrown when an invalid anchor game is provided.
5656
error AnchorStateRegistry_InvalidAnchorGame();
5757

58+
/// @notice Thrown when an anchor game is blacklisted.
59+
error AnchorStateRegistry_AnchorGameBlacklisted();
60+
5861
/// @notice Constructor to disable initializers.
5962
constructor() {
6063
_disableInitializers();
@@ -103,6 +106,10 @@ contract AnchorStateRegistry is Initializable, ISemver {
103106
return (startingAnchorRoot.root, startingAnchorRoot.l2BlockNumber);
104107
}
105108

109+
if (isGameBlacklisted(anchorGame)) {
110+
revert AnchorStateRegistry_AnchorGameBlacklisted();
111+
}
112+
106113
// Otherwise, return the anchor root.
107114
return (Hash.wrap(anchorGame.rootClaim().raw()), anchorGame.l2BlockNumber());
108115
}

packages/contracts-bedrock/test/dispute/AnchorStateRegistry.t.sol

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,48 @@ contract AnchorStateRegistry_GetAnchorRoot_Test is AnchorStateRegistry_Init {
7777
assertEq(root.raw(), 0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF);
7878
assertEq(l2BlockNumber, 0);
7979
}
80+
81+
/// @notice Tests that getAnchorRoot will return the correct anchor root if an anchor game exists.
82+
function test_getAnchorRoot_anchorGameExists_succeeds() public {
83+
// Mock the game to be resolved.
84+
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.resolvedAt, ()), abi.encode(block.timestamp));
85+
vm.warp(block.timestamp + optimismPortal2.disputeGameFinalityDelaySeconds() + 1);
86+
87+
// Mock the game to be the defender wins.
88+
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.status, ()), abi.encode(GameStatus.DEFENDER_WINS));
89+
90+
// Set the anchor game to the game proxy.
91+
anchorStateRegistry.setAnchorState(gameProxy);
92+
93+
// We should get the anchor root back.
94+
(Hash root, uint256 l2BlockNumber) = anchorStateRegistry.getAnchorRoot();
95+
assertEq(root.raw(), gameProxy.rootClaim().raw());
96+
assertEq(l2BlockNumber, gameProxy.l2BlockNumber());
97+
}
98+
}
99+
100+
contract AnchorStateRegistry_GetAnchorRoot_TestFail is AnchorStateRegistry_Init {
101+
/// @notice Tests that getAnchorRoot will revert if the anchor game is blacklisted.
102+
function test_getAnchorRoot_blacklistedGame_fails() public {
103+
// Mock the game to be resolved.
104+
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.resolvedAt, ()), abi.encode(block.timestamp));
105+
vm.warp(block.timestamp + optimismPortal2.disputeGameFinalityDelaySeconds() + 1);
106+
107+
// Mock the game to be the defender wins.
108+
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.status, ()), abi.encode(GameStatus.DEFENDER_WINS));
109+
110+
// Set the anchor game to the game proxy.
111+
anchorStateRegistry.setAnchorState(gameProxy);
112+
113+
// Mock the disputeGameBlacklist call to return true.
114+
vm.mockCall(
115+
address(optimismPortal2),
116+
abi.encodeCall(optimismPortal2.disputeGameBlacklist, (gameProxy)),
117+
abi.encode(true)
118+
);
119+
vm.expectRevert(IAnchorStateRegistry.AnchorStateRegistry_AnchorGameBlacklisted.selector);
120+
anchorStateRegistry.getAnchorRoot();
121+
}
80122
}
81123

82124
contract AnchorStateRegistry_Anchors_Test is AnchorStateRegistry_Init {
@@ -150,17 +192,11 @@ contract AnchorStateRegistry_IsGameRespected_Test is AnchorStateRegistry_Init {
150192

151193
/// @notice Tests that isGameRespected will return false if the game is not of the respected game
152194
/// type.
153-
/// @param _gameType The game type to use for the test.
154-
function testFuzz_isGameRespected_isNotRespected_succeeds(GameType _gameType) public {
155-
if (_gameType.raw() == gameProxy.gameType().raw()) {
156-
_gameType = GameType.wrap(_gameType.raw() + 1);
157-
}
158-
195+
function test_isGameRespected_isNotRespected_succeeds() public {
159196
// Mock that the game was not respected.
160197
vm.mockCall(
161198
address(gameProxy), abi.encodeCall(gameProxy.wasRespectedGameTypeWhenCreated, ()), abi.encode(false)
162199
);
163-
164200
assertFalse(anchorStateRegistry.isGameRespected(gameProxy));
165201
}
166202
}
@@ -308,7 +344,7 @@ contract AnchorStateRegistry_SetAnchorState_TestFail is AnchorStateRegistry_Init
308344
/// @notice Tests that setAnchorState will revert if the game is valid and the game block
309345
/// number is less than or equal to the current anchor root block number.
310346
/// @param _l2BlockNumber The L2 block number to use for the game.
311-
function testFuzz_setAnchorState_validOlderState_fails(uint256 _l2BlockNumber) public {
347+
function testFuzz_setAnchorState_olderValidGameClaim_fails(uint256 _l2BlockNumber) public {
312348
// Grab block number of the existing anchor root.
313349
(Hash root, uint256 l2BlockNumber) = anchorStateRegistry.getAnchorRoot();
314350

@@ -445,10 +481,9 @@ contract AnchorStateRegistry_SetAnchorState_TestFail is AnchorStateRegistry_Init
445481
assertEq(updatedRoot.raw(), root.raw());
446482
}
447483

448-
/// @notice Tests that setAnchorState will revert if the game is valid and the game type
449-
/// is not the respected game type.
484+
/// @notice Tests that setAnchorState will revert if the game is not respected.
450485
/// @param _l2BlockNumber The L2 block number to use for the game.
451-
function testFuzz_setAnchorState_notRespectedGameType_fails(uint256 _l2BlockNumber) public {
486+
function testFuzz_setAnchorState_isNotRespectedGame_fails(uint256 _l2BlockNumber) public {
452487
// Grab block number of the existing anchor root.
453488
(Hash root, uint256 l2BlockNumber) = anchorStateRegistry.anchors(gameProxy.gameType());
454489

@@ -465,7 +500,7 @@ contract AnchorStateRegistry_SetAnchorState_TestFail is AnchorStateRegistry_Init
465500
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.resolvedAt, ()), abi.encode(block.timestamp));
466501
vm.warp(block.timestamp + optimismPortal2.disputeGameFinalityDelaySeconds() + 1);
467502

468-
// Mock that the game was not respected.
503+
// Mock that the game was not respected when created.
469504
vm.mockCall(
470505
address(gameProxy), abi.encodeCall(gameProxy.wasRespectedGameTypeWhenCreated, ()), abi.encode(false)
471506
);

0 commit comments

Comments
 (0)