Skip to content

Commit 32bba12

Browse files
simpler api for boolean functions
1 parent 3908a52 commit 32bba12

File tree

6 files changed

+68
-84
lines changed

6 files changed

+68
-84
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import { IOptimismPortal2 } from "interfaces/L1/IOptimismPortal2.sol";
99
import { GameType, Hash, OutputRoot } from "src/dispute/lib/Types.sol";
1010

1111
interface IAnchorStateRegistry {
12-
error InvalidAnchorGame(string reason);
13-
error Unauthorized();
12+
error AnchorStateRegistry_Unauthorized();
13+
error AnchorStateRegistry_ImproperAnchorGame();
14+
error AnchorStateRegistry_InvalidAnchorGame();
1415

15-
event AnchorNotUpdated(IFaultDisputeGame indexed game, string reason);
16+
event AnchorNotUpdated(IFaultDisputeGame indexed game);
1617
event AnchorUpdated(IFaultDisputeGame indexed game);
1718
event Initialized(uint8 version);
1819

@@ -25,7 +26,7 @@ interface IAnchorStateRegistry {
2526
function isGameBlacklisted(IDisputeGame _game) external view returns (bool);
2627
function isGameRespected(IDisputeGame _game) external view returns (bool);
2728
function isGameRetired(IDisputeGame _game) external view returns (bool);
28-
function isGameProper(IDisputeGame _game) external view returns (bool, string memory);
29+
function isGameProper(IDisputeGame _game) external view returns (bool);
2930
function portal() external view returns (IOptimismPortal2);
3031
function setAnchorState(IFaultDisputeGame _game) external;
3132
function superchainConfig() external view returns (ISuperchainConfig);

packages/contracts-bedrock/snapshots/abi/AnchorStateRegistry.json

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@
145145
"internalType": "bool",
146146
"name": "",
147147
"type": "bool"
148-
},
149-
{
150-
"internalType": "string",
151-
"name": "",
152-
"type": "string"
153148
}
154149
],
155150
"stateMutability": "view",
@@ -279,12 +274,6 @@
279274
"internalType": "contract IFaultDisputeGame",
280275
"name": "game",
281276
"type": "address"
282-
},
283-
{
284-
"indexed": false,
285-
"internalType": "string",
286-
"name": "reason",
287-
"type": "string"
288277
}
289278
],
290279
"name": "AnchorNotUpdated",
@@ -317,19 +306,18 @@
317306
"type": "event"
318307
},
319308
{
320-
"inputs": [
321-
{
322-
"internalType": "string",
323-
"name": "reason",
324-
"type": "string"
325-
}
326-
],
327-
"name": "InvalidAnchorGame",
309+
"inputs": [],
310+
"name": "AnchorStateRegistry_ImproperAnchorGame",
311+
"type": "error"
312+
},
313+
{
314+
"inputs": [],
315+
"name": "AnchorStateRegistry_InvalidAnchorGame",
328316
"type": "error"
329317
},
330318
{
331319
"inputs": [],
332-
"name": "Unauthorized",
320+
"name": "AnchorStateRegistry_Unauthorized",
333321
"type": "error"
334322
}
335323
]

packages/contracts-bedrock/snapshots/semver-lock.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@
152152
"sourceCodeHash": "0xb7b0a06cd971c4647247dc19ce997d0c64a73e87c81d30731da9cf9efa1b952a"
153153
},
154154
"src/dispute/AnchorStateRegistry.sol": {
155-
"initCodeHash": "0x00a96ace2161b2ede09cf2082d934fe60769c0120c34d61a22a953e8d6a32860",
156-
"sourceCodeHash": "0xde0d10f630e7a8911e43ea6a8545f9d1767ae356469d2a2eabbdcb029b8659d9"
155+
"initCodeHash": "0xfbeeac40d86d13e71c7add66eef6357576a93b6a175c9cff6ec6ef587fe3acc4",
156+
"sourceCodeHash": "0xe299ca0d3a1c3a22e31e94db5e62122120c6aa081bbc2424367022e77b826348"
157157
},
158158
"src/dispute/DelayedWETH.sol": {
159159
"initCodeHash": "0x759d7f9c52b7c13ce4502f39dae3a75d130c6278240cde0b60ae84616aa2bd48",

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

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable
66

77
// Libraries
88
import { GameType, OutputRoot, Claim, GameStatus, Hash } from "src/dispute/lib/Types.sol";
9-
import { Unauthorized } from "src/libraries/errors/CommonErrors.sol";
10-
import { InvalidAnchorGame } from "src/dispute/lib/Errors.sol";
119

1210
// Interfaces
1311
import { ISemver } from "interfaces/universal/ISemver.sol";
@@ -44,11 +42,22 @@ contract AnchorStateRegistry is Initializable, ISemver {
4442
OutputRoot internal startingAnchorRoot;
4543

4644
/// @notice Emitted when an anchor state is not updated.
47-
event AnchorNotUpdated(IFaultDisputeGame indexed game, string reason);
45+
/// @param game Game that was not used as the new anchor game.
46+
event AnchorNotUpdated(IFaultDisputeGame indexed game);
4847

4948
/// @notice Emitted when an anchor state is updated.
49+
/// @param game Game that was used as the new anchor game.
5050
event AnchorUpdated(IFaultDisputeGame indexed game);
5151

52+
/// @notice Thrown when an unauthorized caller attempts to set the anchor state.
53+
error AnchorStateRegistry_Unauthorized();
54+
55+
/// @notice Thrown when an improper anchor game is provided.
56+
error AnchorStateRegistry_ImproperAnchorGame();
57+
58+
/// @notice Thrown when an invalid anchor game is provided.
59+
error AnchorStateRegistry_InvalidAnchorGame();
60+
5261
/// @notice Constructor to disable initializers.
5362
constructor() {
5463
_disableInitializers();
@@ -138,28 +147,28 @@ contract AnchorStateRegistry is Initializable, ISemver {
138147
/// DO NOT USE THIS FUNCTION ALONE TO DETERMINE IF A ROOT CLAIM IS VALID.
139148
/// @param _game The game to check.
140149
/// @return Whether the game is a proper game.
141-
/// @return Reason why the game is not a proper game.
142-
function isGameProper(IDisputeGame _game) public view returns (bool, string memory) {
150+
function isGameProper(IDisputeGame _game) public view returns (bool) {
151+
// Must be registered in the DisputeGameFactory.
143152
if (!isGameRegistered(_game)) {
144-
return (false, "game not factory registered");
153+
return false;
145154
}
146155

147156
// Must be respected game type.
148157
if (!isGameRespected(_game)) {
149-
return (false, "game type not respected");
158+
return false;
150159
}
151160

152161
// Must not be blacklisted.
153162
if (isGameBlacklisted(_game)) {
154-
return (false, "game blacklisted");
163+
return false;
155164
}
156165

157166
// Must be created at or after the respectedGameTypeUpdatedAt timestamp.
158167
if (isGameRetired(_game)) {
159-
return (false, "game retired");
168+
return false;
160169
}
161170

162-
return (true, "");
171+
return true;
163172
}
164173

165174
/// @notice Callable by FaultDisputeGame contracts to update the anchor state. Pulls the anchor state directly from
@@ -170,22 +179,21 @@ contract AnchorStateRegistry is Initializable, ISemver {
170179
IFaultDisputeGame game = IFaultDisputeGame(msg.sender);
171180

172181
// Check if the game is a proper game.
173-
(bool isProper, string memory reason) = isGameProper(game);
174-
if (!isProper) {
175-
emit AnchorNotUpdated(game, reason);
182+
if (!isGameProper(game)) {
183+
emit AnchorNotUpdated(game);
176184
return;
177185
}
178186

179187
// Must be a game that resolved in favor of the state.
180188
if (game.status() != GameStatus.DEFENDER_WINS) {
181-
emit AnchorNotUpdated(game, "game not defender wins");
189+
emit AnchorNotUpdated(game);
182190
return;
183191
}
184192

185193
// No need to update anything if the anchor state is already newer.
186194
(, uint256 anchorL2BlockNumber) = getAnchorRoot();
187195
if (game.l2BlockNumber() <= anchorL2BlockNumber) {
188-
emit AnchorNotUpdated(game, "game not newer than anchor state");
196+
emit AnchorNotUpdated(game);
189197
return;
190198
}
191199

@@ -197,17 +205,19 @@ contract AnchorStateRegistry is Initializable, ISemver {
197205
/// @notice Sets the anchor state given the game.
198206
/// @param _game The game to set the anchor state for.
199207
function setAnchorState(IFaultDisputeGame _game) external {
200-
if (msg.sender != superchainConfig.guardian()) revert Unauthorized();
208+
// Function can only be triggered by the guardian.
209+
if (msg.sender != superchainConfig.guardian()) {
210+
revert AnchorStateRegistry_Unauthorized();
211+
}
201212

202213
// Check if the game is a proper game.
203-
(bool isProper, string memory reason) = isGameProper(_game);
204-
if (!isProper) {
205-
revert InvalidAnchorGame(reason);
214+
if (!isGameProper(_game)) {
215+
revert AnchorStateRegistry_ImproperAnchorGame();
206216
}
207217

208218
// The game must have resolved in favor of the root claim.
209219
if (_game.status() != GameStatus.DEFENDER_WINS) {
210-
revert InvalidAnchorGame("game not defender wins");
220+
revert AnchorStateRegistry_InvalidAnchorGame();
211221
}
212222

213223
// Update the anchor game.

packages/contracts-bedrock/src/dispute/lib/Errors.sol

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,3 @@ error L2BlockNumberChallenged();
127127

128128
/// @notice Thrown when an unauthorized address attempts to interact with the game.
129129
error BadAuth();
130-
131-
////////////////////////////////////////////////////////////////
132-
// `AnchorStateRegistry` Errors //
133-
////////////////////////////////////////////////////////////////
134-
135-
/// @notice Thrown when an invalid anchor game is provided.
136-
error InvalidAnchorGame(string reason);

0 commit comments

Comments
 (0)