Skip to content

Commit

Permalink
feat: Add PrestateNotSet error and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maurelian committed Jan 25, 2025
1 parent 68398cf commit 3b128f6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ interface IOPContractsManager {

error SuperchainProxyAdminMismatch();

error PrestateNotSet(GameType gameType);

// -------- Methods --------

function __constructor__(
Expand Down
19 changes: 9 additions & 10 deletions packages/contracts-bedrock/src/L1/OPContractsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ contract OPContractsManager is ISemver {
/// @notice Thrown when the SuperchainProxyAdmin does not match the SuperchainConfig's admin.
error SuperchainProxyAdminMismatch();

/// @notice Thrown when a prestate is not set for a game.
error PrestateNotSet(GameType gameType);

// -------- Methods --------

constructor(
Expand Down Expand Up @@ -1091,11 +1094,9 @@ contract OPContractsManager is ISemver {

IDisputeGame newGame;
if (GameType.unwrap(_gameType) == GameType.unwrap(GameTypes.PERMISSIONED_CANNON)) {
// TODO: custom error
require(
Claim.unwrap(_opChain.permissionedDisputeGamePrestateHash) != bytes32(0),
"No absolutePrestate for permissioned game"
);
if (Claim.unwrap(_opChain.permissionedDisputeGamePrestateHash) == bytes32(0)) {
revert PrestateNotSet(GameTypes.PERMISSIONED_CANNON);
}

// modify the params to set the permissioned game specific absolutePrestate
params.absolutePrestate = _opChain.permissionedDisputeGamePrestateHash;
Expand All @@ -1111,11 +1112,9 @@ contract OPContractsManager is ISemver {
)
);
} else {
// TODO: custom error
require(
Claim.unwrap(_opChain.permissionlessDisputeGamePrestateHash) != bytes32(0),
"No absolutePrestate for permissionless game"
);
if (Claim.unwrap(_opChain.permissionlessDisputeGamePrestateHash) == bytes32(0)) {
revert PrestateNotSet(GameTypes.CANNON);
}

// modify the params to set the permissionless game specific absolutePrestate
params.absolutePrestate = _opChain.permissionlessDisputeGamePrestateHash;
Expand Down
26 changes: 26 additions & 0 deletions packages/contracts-bedrock/test/L1/OPContractsManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,32 @@ contract OPContractsManager_Upgrade_TestFails is OPContractsManager_Upgrade_Harn
address(opcm), abi.encodeCall(IOPContractsManager.upgrade, (proxyAdmin, opChainConfigs))
);
}

function test_permissionedPrestateNotSet_reverts() public {
opChainConfigs[0].permissionedDisputeGamePrestateHash = Claim.wrap(bytes32(0));
address delegateCaller = makeAddr("delegateCaller");
vm.etch(delegateCaller, vm.getDeployedCode("test/mocks/Callers.sol:DelegateCaller"));

vm.expectRevert(
abi.encodeWithSelector(IOPContractsManager.PrestateNotSet.selector, (GameTypes.PERMISSIONED_CANNON))
);
DelegateCaller(delegateCaller).dcForward(
address(opcm), abi.encodeCall(IOPContractsManager.upgrade, (proxyAdmin, opChainConfigs))
);
}

function test_permissionlessPrestateNotSet_reverts() public {
opChainConfigs[0].permissionlessDisputeGamePrestateHash = Claim.wrap(bytes32(0));
address delegateCaller = makeAddr("delegateCaller");
vm.etch(delegateCaller, vm.getDeployedCode("test/mocks/Callers.sol:DelegateCaller"));

vm.expectRevert(
abi.encodeWithSelector(IOPContractsManager.PrestateNotSet.selector, (GameTypes.CANNON))
);
DelegateCaller(delegateCaller).dcForward(
address(opcm), abi.encodeCall(IOPContractsManager.upgrade, (proxyAdmin, opChainConfigs))
);
}
}

contract OPContractsManager_SetRC_Test is OPContractsManager_Upgrade_Harness {
Expand Down

0 comments on commit 3b128f6

Please sign in to comment.