Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/contracts-bedrock/src/L1/StandardValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GameType, Claim, GameTypes } from "src/dispute/lib/Types.sol";
import { Duration } from "src/dispute/lib/LibUDT.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
import { Constants } from "src/libraries/Constants.sol";
import { Hash } from "src/dispute/lib/Types.sol";

// Interfaces
import { ISystemConfig } from "interfaces/L1/ISystemConfig.sol";
Expand Down Expand Up @@ -396,6 +397,16 @@ contract StandardValidator {
address _challenger = expectedChallenger(_overrides);
_errors = internalRequire(_game.challenger() == _challenger, "PDDG-120", _errors);

(Hash anchorRoot,) = _game.anchorStateRegistry().getAnchorRoot();
bytes32 _anchorRoot = Hash.unwrap(anchorRoot);

_errors = internalRequire(_anchorRoot != bytes32(0), "PDDG-130", _errors);
if (_anchorRoot == bytes32(hex"dead")) {
_errors = internalRequire(_game.l2SequenceNumber() == 0, "PDDG-140", _errors);
} else {
_errors = internalRequire(_game.l2SequenceNumber() != 0, "PDDG-150", _errors);
}

return _errors;
}

Expand Down Expand Up @@ -434,6 +445,12 @@ contract StandardValidator {
"PLDG"
);

(Hash anchorRoot,) = _game.anchorStateRegistry().getAnchorRoot();
bytes32 _anchorRoot = Hash.unwrap(anchorRoot);
_errors = internalRequire(_anchorRoot != bytes32(0), "PLDG-130", _errors);
_errors = internalRequire(_anchorRoot != bytes32(hex"dead"), "PLDG-140", _errors);
_errors = internalRequire(_game.l2SequenceNumber() != 0, "PLDG-150", _errors);

return _errors;
}

Expand Down
78 changes: 78 additions & 0 deletions packages/contracts-bedrock/test/L1/StandardValidator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { IStandardValidator } from "interfaces/L1/IStandardValidator.sol";
/// @notice Used to return a bad DisputeGameFactory address to the StandardValidator. Far easier
/// than the alternative ways of mocking this value since the normal vm.mockCall will cause
/// the validation function to revert.

contract BadDisputeGameFactoryReturner {
/// @notice Address of the StandardValidator instance.
IStandardValidator public immutable validator;
Expand Down Expand Up @@ -200,6 +201,17 @@ contract StandardValidator_TestInit is CommonTest {
vm.prank(disputeGameFactory.owner());
disputeGameFactory.setImplementation(GameTypes.CANNON, IDisputeGame(address(fdg)));
}

vm.mockCall(
address(disputeGameFactory.gameImpls(GameTypes.PERMISSIONED_CANNON)),
abi.encodeCall(IDisputeGame.l2SequenceNumber, ()),
abi.encode(1)
);
vm.mockCall(
address(disputeGameFactory.gameImpls(GameTypes.CANNON)),
abi.encodeCall(IDisputeGame.l2SequenceNumber, ()),
abi.encode(1)
);
}

/// @notice Runs the StandardValidator.validate function.
Expand Down Expand Up @@ -741,6 +753,72 @@ contract StandardValidator_validate_Test is StandardValidator_TestInit {
assertEq("PDDG-120", _validate(true));
}

/// @notice Tests that the validate function successfully returns the right error when the anchor root is
/// bytes32(hex"dead") but the l2 sequence number is not 0.
function test_validate_0xdeadAnchorRootAndNonZeroSequenceNumber_succeeds() public {
uint256 randomSequenceNumber = 1; // this does not correspond to the sequence number of the games.
vm.mockCall(
address(anchorStateRegistry),
abi.encodeCall(IAnchorStateRegistry.getAnchorRoot, ()),
abi.encode(bytes32(hex"dead"), randomSequenceNumber)
);
assertEq("PDDG-140,PLDG-140", _validate(true));
}

function test_validate_0xdeadAnchorRootAndZeroSequenceNumber_succeeds() public {
uint256 randomSequenceNumber = 1; // this does not correspond to the sequence number of the games.
vm.mockCall(
address(anchorStateRegistry),
abi.encodeCall(IAnchorStateRegistry.getAnchorRoot, ()),
abi.encode(bytes32(hex"dead"), randomSequenceNumber)
);

// Set the sequence number returned by the games to be 0
vm.mockCall(
address(disputeGameFactory.gameImpls(GameTypes.PERMISSIONED_CANNON)),
abi.encodeCall(IDisputeGame.l2SequenceNumber, ()),
abi.encode(0)
);
vm.mockCall(
address(disputeGameFactory.gameImpls(GameTypes.CANNON)),
abi.encodeCall(IDisputeGame.l2SequenceNumber, ()),
abi.encode(0)
);
assertEq("PLDG-140,PLDG-150", _validate(true));
}

function test_validate_0x00AnchorRoot_succeeds() public {
vm.mockCall(
address(anchorStateRegistry),
abi.encodeCall(IAnchorStateRegistry.getAnchorRoot, ()),
abi.encode(bytes32(hex"00"), 1)
);
assertEq("PDDG-130,PLDG-130", _validate(true));
}

function test_validate_nonZeroOrDeadAnchorRootAndZeroSequenceNumber_succeeds() public {
uint256 randomSequenceNumber = 1; // this does not correspond to the sequence number of the games.
vm.mockCall(
address(anchorStateRegistry),
abi.encodeCall(IAnchorStateRegistry.getAnchorRoot, ()),
abi.encode(bytes32(hex"01"), randomSequenceNumber)
);

// Set the sequence number returned by the games to be 0
vm.mockCall(
address(disputeGameFactory.gameImpls(GameTypes.PERMISSIONED_CANNON)),
abi.encodeCall(IDisputeGame.l2SequenceNumber, ()),
abi.encode(0)
);
vm.mockCall(
address(disputeGameFactory.gameImpls(GameTypes.CANNON)),
abi.encodeCall(IDisputeGame.l2SequenceNumber, ()),
abi.encode(0)
);

assertEq("PDDG-150,PLDG-150", _validate(true));
}

/// @notice Tests that the validate function successfully returns the right overrides error when the
/// PermissionedDisputeGame challenger is overriden but is correct.
function test_validate_overridenPermissionedDisputeGameChallenger_succeeds() public {
Expand Down