Skip to content

Commit 1c4c288

Browse files
committed
fix tests and add specs
1 parent 5733899 commit 1c4c288

File tree

4 files changed

+52
-49
lines changed

4 files changed

+52
-49
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ interface IAnchorStateRegistry {
2727
OutputRoot memory _startingAnchorRoot
2828
)
2929
external;
30-
function isGameRegistered(IDisputeGame _game) external view returns (bool);
30+
31+
function isGameBeyondAirgap(IDisputeGame _game) external view returns (bool);
3132
function isGameBlacklisted(IDisputeGame _game) external view returns (bool);
33+
function isGameProper(IDisputeGame _game) external view returns (bool);
34+
function isGameRegistered(IDisputeGame _game) external view returns (bool);
35+
function isGameResolved(IDisputeGame _game) external view returns (bool);
3236
function isGameRespected(IDisputeGame _game) external view returns (bool);
3337
function isGameRetired(IDisputeGame _game) external view returns (bool);
34-
function isGameResolved(IDisputeGame _game) external view returns (bool);
35-
function isGameBeyondAirgap(IDisputeGame _game) external view returns (bool);
36-
function isGameProper(IDisputeGame _game) external view returns (bool);
3738
function isGameFinalized(IDisputeGame _game) external view returns (bool);
3839
function isGameClaimValid(IDisputeGame _game) external view returns (bool);
3940
function portal() external view returns (IOptimismPortal2);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.0;
33

44
import { Types } from "src/libraries/Types.sol";
5-
import { Claim, Position, Clock, Hash, Duration, BondDistributionMode } from "src/dispute/lib/Types.sol";
5+
import { Claim, Position, Clock, Hash, Duration, Timestamp, BondDistributionMode } from "src/dispute/lib/Types.sol";
66

77
import { IAnchorStateRegistry } from "interfaces/dispute/IAnchorStateRegistry.sol";
88
import { IDelayedWETH } from "interfaces/dispute/IDelayedWETH.sol";
@@ -100,6 +100,7 @@ interface IPermissionedDisputeGame is IDisputeGame {
100100
function getNumToResolve(uint256 _claimIndex) external view returns (uint256 numRemainingChildren_);
101101
function getRequiredBond(Position _position) external view returns (uint256 requiredBond_);
102102
function hasUnlockedCredit(address) external view returns (bool);
103+
function initialize() external payable;
103104
function l2BlockNumber() external pure returns (uint256 l2BlockNumber_);
104105
function l2BlockNumberChallenged() external view returns (bool);
105106
function l2BlockNumberChallenger() external view returns (address);

packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,31 @@ contract OptimismPortal2_FinalizeWithdrawal_Test is CommonTest {
455455
}
456456

457457
/// @dev Tests that the guardian role can set the respected game type to anything they want.
458-
function testFuzz_setRespectedGameType_guardian_succeeds(GameType _ty) external {
458+
function testFuzz_setRespectedGameType_guardianCanSetRespectedGameType_succeeds(GameType _ty) external {
459+
vm.assume(_ty.raw() != type(uint32).max);
460+
uint64 respectedGameTypeUpdatedAt = optimismPortal2.respectedGameTypeUpdatedAt();
459461
vm.expectEmit(address(optimismPortal2));
460-
emit RespectedGameTypeSet(_ty, Timestamp.wrap(uint64(block.timestamp)));
462+
emit RespectedGameTypeSet(_ty, Timestamp.wrap(respectedGameTypeUpdatedAt));
461463
vm.prank(optimismPortal2.guardian());
462464
optimismPortal2.setRespectedGameType(_ty);
463465

464466
assertEq(optimismPortal2.respectedGameType().raw(), _ty.raw());
465467
}
466468

469+
/// @dev Tests that the guardian can set the `respectedGameTypeUpdatedAt` timestamp to current timestamp.
470+
function testFuzz_setRespectedGameType_guardianCanSetRespectedGameTypeUpdatedAt_succeeds(uint64 _elapsed)
471+
external
472+
{
473+
_elapsed = uint64(bound(_elapsed, 0, type(uint64).max - uint64(block.timestamp)));
474+
GameType _ty = GameType.wrap(type(uint32).max);
475+
uint64 _timestamp = uint64(block.timestamp) + _elapsed;
476+
vm.warp(_timestamp);
477+
// TODO: event?
478+
vm.prank(optimismPortal2.guardian());
479+
optimismPortal2.setRespectedGameType(_ty);
480+
assertEq(optimismPortal2.respectedGameTypeUpdatedAt(), _timestamp);
481+
}
482+
467483
/// @dev Tests that `proveWithdrawalTransaction` reverts when paused.
468484
function test_proveWithdrawalTransaction_paused_reverts() external {
469485
vm.prank(optimismPortal2.guardian());
@@ -1293,35 +1309,6 @@ contract OptimismPortal2_FinalizeWithdrawal_Test is CommonTest {
12931309
assertTrue(optimismPortal2.finalizedWithdrawals(_withdrawalHash));
12941310
}
12951311

1296-
/// @dev Tests that `finalizeWithdrawalTransaction` reverts if the respected game type has changed since the
1297-
/// withdrawal was proven.
1298-
function test_finalizeWithdrawalTransaction_respectedTypeChangedSinceProving_reverts() external {
1299-
vm.expectEmit(true, true, true, true);
1300-
emit WithdrawalProven(_withdrawalHash, alice, bob);
1301-
vm.expectEmit(true, true, true, true);
1302-
emit WithdrawalProvenExtension1(_withdrawalHash, address(this));
1303-
optimismPortal2.proveWithdrawalTransaction({
1304-
_tx: _defaultTx,
1305-
_disputeGameIndex: _proposedGameIndex,
1306-
_outputRootProof: _outputRootProof,
1307-
_withdrawalProof: _withdrawalProof
1308-
});
1309-
1310-
// Warp past the finalization period.
1311-
vm.warp(block.timestamp + optimismPortal2.proofMaturityDelaySeconds() + 1);
1312-
1313-
// Resolve the dispute game.
1314-
game.resolveClaim(0, 0);
1315-
game.resolve();
1316-
1317-
// Change the respected game type in the portal.
1318-
vm.prank(optimismPortal2.guardian());
1319-
optimismPortal2.setRespectedGameType(GameType.wrap(0xFF));
1320-
1321-
vm.expectRevert(InvalidGameType.selector);
1322-
optimismPortal2.finalizeWithdrawalTransaction(_defaultTx);
1323-
}
1324-
13251312
/// @dev Tests that `finalizeWithdrawalTransaction` reverts if the respected game type was updated after the
13261313
/// dispute game was created.
13271314
function test_finalizeWithdrawalTransaction_gameOlderThanRespectedGameTypeUpdate_reverts() external {
@@ -1343,12 +1330,12 @@ contract OptimismPortal2_FinalizeWithdrawal_Test is CommonTest {
13431330
game.resolveClaim(0, 0);
13441331
game.resolve();
13451332

1346-
// Change the respected game type in the portal.
1347-
vm.prank(optimismPortal2.guardian());
1348-
optimismPortal2.setRespectedGameType(GameType.wrap(0xFF));
1333+
// Warp past the dispute game finality delay.
1334+
vm.warp(block.timestamp + optimismPortal2.disputeGameFinalityDelaySeconds() + 1);
13491335

1350-
// Mock the game's type so that we pass the correct game type check.
1351-
vm.mockCall(address(game), abi.encodeCall(game.gameType, ()), abi.encode(GameType.wrap(0xFF)));
1336+
// Set respectedGameTypeUpdatedAt.
1337+
vm.prank(optimismPortal2.guardian());
1338+
optimismPortal2.setRespectedGameType(GameType.wrap(type(uint32).max));
13521339

13531340
vm.expectRevert("OptimismPortal: dispute game created before respected game type was updated");
13541341
optimismPortal2.finalizeWithdrawalTransaction(_defaultTx);

packages/contracts-bedrock/test/universal/Specs.t.sol

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { IProtocolVersions } from "interfaces/L1/IProtocolVersions.sol";
2323
/// @dev Specifies common security properties of entrypoints to L1 contracts, including authorization and
2424
/// pausability.
2525
/// When adding new functions to the L1 system, the `setUp` function must be updated to document the security
26-
/// properties of the new function. The `Spec` struct reppresents this documentation. However, this contract does
26+
/// properties of the new function. The `Spec` struct represents this documentation. However, this contract does
2727
/// not actually test to verify these properties, only that a spec is defined.
2828
contract Specification_Test is CommonTest {
2929
enum Role {
@@ -553,21 +553,25 @@ contract Specification_Test is CommonTest {
553553
_addSpec({ _name: "MintManager", _sel: _getSel("upgrade(address)"), _auth: Role.MINTMANAGEROWNER });
554554

555555
// AnchorStateRegistry
556+
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("anchorGame()") });
556557
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("anchors(uint32)") });
557558
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("getAnchorRoot()") });
558559
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("disputeGameFactory()") });
559-
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("portal()") });
560-
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("anchorGame()") });
561560
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("initialize(address,address,address,(bytes32,uint256))") });
562-
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("tryUpdateAnchorState()") });
563-
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("setAnchorState(address)"), _auth: Role.GUARDIAN });
564-
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("version()") });
561+
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("isGameBeyondAirgap(address)") });
562+
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("isGameBlacklisted(address)") });
563+
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("isGameClaimValid(address)") });
564+
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("isGameFinalized(address)") });
565+
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("isGameProper(address)") });
565566
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("isGameRegistered(address)") });
567+
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("isGameResolved(address)") });
566568
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("isGameRespected(address)") });
567-
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("isGameBlacklisted(address)") });
568569
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("isGameRetired(address)") });
569-
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("isGameProper(address)") });
570+
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("portal()") });
571+
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("respectedGameType()") });
572+
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("setAnchorState(address)"), _auth: Role.GUARDIAN });
570573
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("superchainConfig()") });
574+
_addSpec({ _name: "AnchorStateRegistry", _sel: _getSel("version()") });
571575

572576
// PermissionedDisputeGame
573577
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("absolutePrestate()") });
@@ -578,6 +582,7 @@ contract Specification_Test is CommonTest {
578582
_sel: _getSel("attack(bytes32,uint256,bytes32)"),
579583
_auth: Role.CHALLENGER
580584
});
585+
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("bondDistributionMode()") });
581586
_addSpec({
582587
_name: "PermissionedDisputeGame",
583588
_sel: _getSel("challengeRootL2Block((bytes32,bytes32,bytes32,bytes32),bytes)"),
@@ -589,6 +594,7 @@ contract Specification_Test is CommonTest {
589594
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("claimDataLen()") });
590595
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("claims(bytes32)") });
591596
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("clockExtension()") });
597+
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("closeGame()") });
592598
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("createdAt()") });
593599
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("credit(address)") });
594600
_addSpec({
@@ -603,6 +609,7 @@ contract Specification_Test is CommonTest {
603609
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("getChallengerDuration(uint256)") });
604610
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("getNumToResolve(uint256)") });
605611
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("getRequiredBond(uint128)") });
612+
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("hasUnlockedCredit(address)") });
606613
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("initialize()") });
607614
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("l1Head()") });
608615
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("l2BlockNumber()") });
@@ -617,6 +624,7 @@ contract Specification_Test is CommonTest {
617624
_auth: Role.CHALLENGER
618625
});
619626
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("proposer()") });
627+
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("refundModeCredit(address)") });
620628
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("resolutionCheckpoints(uint256)") });
621629
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("resolve()") });
622630
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("resolveClaim(uint256,uint256)") });
@@ -636,13 +644,15 @@ contract Specification_Test is CommonTest {
636644
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("subgames(uint256,uint256)") });
637645
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("version()") });
638646
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("vm()") });
647+
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("wasRespectedGameTypeWhenCreated()") });
639648
_addSpec({ _name: "PermissionedDisputeGame", _sel: _getSel("weth()") });
640649

641650
// FaultDisputeGame
642651
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("absolutePrestate()") });
643652
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("addLocalData(uint256,uint256,uint256)") });
644653
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("anchorStateRegistry()") });
645654
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("attack(bytes32,uint256,bytes32)") });
655+
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("bondDistributionMode()") });
646656
_addSpec({
647657
_name: "FaultDisputeGame",
648658
_sel: _getSel("challengeRootL2Block((bytes32,bytes32,bytes32,bytes32),bytes)")
@@ -652,6 +662,7 @@ contract Specification_Test is CommonTest {
652662
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("claimDataLen()") });
653663
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("claims(bytes32)") });
654664
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("clockExtension()") });
665+
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("closeGame()") });
655666
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("createdAt()") });
656667
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("credit(address)") });
657668
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("defend(bytes32,uint256,bytes32)") });
@@ -661,6 +672,7 @@ contract Specification_Test is CommonTest {
661672
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("gameType()") });
662673
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("getChallengerDuration(uint256)") });
663674
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("getRequiredBond(uint128)") });
675+
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("hasUnlockedCredit(address)") });
664676
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("initialize()") });
665677
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("l1Head()") });
666678
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("l2BlockNumber()") });
@@ -673,6 +685,7 @@ contract Specification_Test is CommonTest {
673685
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("resolutionCheckpoints(uint256)") });
674686
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("resolve()") });
675687
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("getNumToResolve(uint256)") });
688+
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("refundModeCredit(address)") });
676689
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("resolveClaim(uint256,uint256)") });
677690
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("resolvedAt()") });
678691
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("resolvedSubgames(uint256)") });
@@ -686,6 +699,7 @@ contract Specification_Test is CommonTest {
686699
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("subgames(uint256,uint256)") });
687700
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("version()") });
688701
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("vm()") });
702+
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("wasRespectedGameTypeWhenCreated()") });
689703
_addSpec({ _name: "FaultDisputeGame", _sel: _getSel("weth()") });
690704

691705
// DisputeGameFactory

0 commit comments

Comments
 (0)