From 8e1693b2787366b196d87f74bf05182c90025026 Mon Sep 17 00:00:00 2001 From: gzeon Date: Thu, 15 Feb 2024 20:01:56 +0800 Subject: [PATCH] feat: safe cast in setMaxTimeVariation --- src/bridge/SequencerInbox.sol | 31 +++++++++++++++++++++---------- src/libraries/Error.sol | 3 +++ 2 files changed, 24 insertions(+), 10 deletions(-) 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();