Skip to content

Commit

Permalink
contracts-bedrock: add errors in L1BlockInterop
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfuturistic committed May 16, 2024
1 parent 0997319 commit 89dbd3f
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/contracts-bedrock/src/L2/L1BlockInterop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ import { L1Block } from "src/L2/L1Block.sol";
import { EnumerableSetLib } from "@solady/utils/EnumerableSetLib.sol";
import { GasPayingToken } from "src/libraries/GasPayingToken.sol";

/// @notice Thrown when a non-depositor account attempts to set L1 block values.
error NotDepositor();

/// @notice Thrown when dependencySetSize does not match the length of the dependency set.
error DependencySetSizeMismatch();

/// @notice Error when a chain ID is not in the interop dependency set.
error NotDependency();

/// @notice Enum representing different types of configurations that can be set on L1Block.
/// @custom:value GAS_PAYING_TOKEN Represents the config type for the gas paying token.
/// @custom:value ADD_DEPENDENCY Represents the config type for adding a chain to the interchain dependency set.
Expand All @@ -31,6 +22,18 @@ enum ConfigType {
contract L1BlockInterop is L1Block {
using EnumerableSetLib for EnumerableSetLib.Uint256Set;

/// @notice Thrown when a non-depositor account attempts to set L1 block values.
error NotDepositor();

/// @notice Error when a chain ID is not in the interop dependency set.
error NotDependency();

/// @notice Error when the interop dependency set size is too large.
error DependencySetSizeTooLarge();

/// @notice Error when the chain's chain ID is attempted to be removed from the interop dependency set.
error CantRemovedChainId();

/// @notice Event emitted when a new dependency is added to the interop dependency set.
event DependencyAdded(uint256 indexed chainId);

Expand Down Expand Up @@ -81,6 +84,8 @@ contract L1BlockInterop is L1Block {
if (_type == ConfigType.ADD_DEPENDENCY) {
uint256 chainId = abi.decode(_value, (uint256));

if (dependencySet.length() == type(uint8).max) revert DependencySetSizeTooLarge();

dependencySet.add(chainId);

emit DependencyAdded(chainId);
Expand All @@ -91,6 +96,8 @@ contract L1BlockInterop is L1Block {
if (_type == ConfigType.REMOVE_DEPENDENCY) {
uint256 chainId = abi.decode(_value, (uint256));

if (chainId == block.chainid) revert CantRemovedChainId();

if (!dependencySet.remove(chainId)) revert NotDependency();
}
}
Expand Down

0 comments on commit 89dbd3f

Please sign in to comment.