diff --git a/src/bridge/SequencerInbox.sol b/src/bridge/SequencerInbox.sol index bc912132..16a65e77 100644 --- a/src/bridge/SequencerInbox.sol +++ b/src/bridge/SequencerInbox.sol @@ -28,6 +28,7 @@ import { NotOwner, InvalidHeaderFlag, NativeTokenMismatch, + BadMaxTimeVariation, Deprecated } from "../libraries/Error.sol"; import "./IBridge.sol"; @@ -196,11 +197,8 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox bridge = bridge_; rollup = bridge_.rollup(); - // TODO: safe cast - delayBlocks = uint64(maxTimeVariation_.delayBlocks); - futureBlocks = uint64(maxTimeVariation_.futureBlocks); - delaySeconds = uint64(maxTimeVariation_.delaySeconds); - futureSeconds = uint64(maxTimeVariation_.futureSeconds); + + _setMaxTimeVariation(maxTimeVariation_); } /// @notice Allows the rollup owner to sync the rollup address @@ -714,16 +712,29 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox return bridge.sequencerMessageCount(); } - /// @inheritdoc ISequencerInbox - function setMaxTimeVariation(ISequencerInbox.MaxTimeVariation memory maxTimeVariation_) - external - onlyRollupOwner + function _setMaxTimeVariation(ISequencerInbox.MaxTimeVariation memory maxTimeVariation_) + internal { - // TODO: safe cast + if ( + maxTimeVariation_.delayBlocks > type(uint64).max || + maxTimeVariation_.futureBlocks > type(uint64).max || + maxTimeVariation_.delaySeconds > type(uint64).max || + maxTimeVariation_.futureSeconds > type(uint64).max + ) { + revert BadMaxTimeVariation(); + } delayBlocks = uint64(maxTimeVariation_.delayBlocks); futureBlocks = uint64(maxTimeVariation_.futureBlocks); delaySeconds = uint64(maxTimeVariation_.delaySeconds); futureSeconds = uint64(maxTimeVariation_.futureSeconds); + } + + /// @inheritdoc ISequencerInbox + function setMaxTimeVariation(ISequencerInbox.MaxTimeVariation memory maxTimeVariation_) + external + onlyRollupOwner + { + _setMaxTimeVariation(maxTimeVariation_); emit OwnerFunctionCalled(0); } diff --git a/src/libraries/Error.sol b/src/libraries/Error.sol index d7849599..0d5a2a8d 100644 --- a/src/libraries/Error.sol +++ b/src/libraries/Error.sol @@ -196,3 +196,6 @@ error NativeTokenMismatch(); /// @dev Thrown when a deprecated function is called error Deprecated(); + +/// @dev Thrown when any component of maxTimeVariation is over uint64 +error BadMaxTimeVariation();