Skip to content

Commit

Permalink
feat: safe cast in setMaxTimeVariation
Browse files Browse the repository at this point in the history
  • Loading branch information
gzeoneth committed Feb 15, 2024
1 parent fa2dafd commit 8e1693b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/bridge/SequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
NotOwner,
InvalidHeaderFlag,
NativeTokenMismatch,
BadMaxTimeVariation,
Deprecated
} from "../libraries/Error.sol";
import "./IBridge.sol";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Error.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 8e1693b

Please sign in to comment.