Skip to content

Commit 31fd3c6

Browse files
committed
Added internal max time variation func
1 parent 3646a78 commit 31fd3c6

File tree

2 files changed

+48
-35
lines changed

2 files changed

+48
-35
lines changed

src/bridge/SequencerInbox.sol

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,35 +111,54 @@ contract SequencerInbox is GasRefundEnabled, ISequencerInbox {
111111

112112
function getTimeBounds() internal view virtual returns (IBridge.TimeBounds memory) {
113113
IBridge.TimeBounds memory bounds;
114-
ISequencerInbox.MaxTimeVariation memory maxTimeVariation_ = maxTimeVariation();
115-
if (block.timestamp > maxTimeVariation_.delaySeconds) {
116-
bounds.minTimestamp = uint64(block.timestamp - maxTimeVariation_.delaySeconds);
114+
(
115+
uint256 delayBlocks_,
116+
uint256 futureBlocks_,
117+
uint256 delaySeconds_,
118+
uint256 futureSeconds_
119+
) = maxTimeVariationInternal();
120+
if (block.timestamp > delaySeconds_) {
121+
bounds.minTimestamp = uint64(block.timestamp - delaySeconds_);
117122
}
118-
bounds.maxTimestamp = uint64(block.timestamp + maxTimeVariation_.futureSeconds);
119-
if (block.number > maxTimeVariation_.delayBlocks) {
120-
bounds.minBlockNumber = uint64(block.number - maxTimeVariation_.delayBlocks);
123+
bounds.maxTimestamp = uint64(block.timestamp + futureSeconds_);
124+
if (block.number > delayBlocks_) {
125+
bounds.minBlockNumber = uint64(block.number - delayBlocks_);
121126
}
122-
bounds.maxBlockNumber = uint64(block.number + maxTimeVariation_.futureBlocks);
127+
bounds.maxBlockNumber = uint64(block.number + futureBlocks_);
123128
return bounds;
124129
}
125130

126131
function maxTimeVariation() public view returns (ISequencerInbox.MaxTimeVariation memory) {
132+
(
133+
uint256 delayBlocks_,
134+
uint256 futureBlocks_,
135+
uint256 delaySeconds_,
136+
uint256 futureSeconds_
137+
) = maxTimeVariationInternal();
138+
139+
return
140+
ISequencerInbox.MaxTimeVariation({
141+
delayBlocks: delayBlocks_,
142+
futureBlocks: futureBlocks_,
143+
delaySeconds: delaySeconds_,
144+
futureSeconds: futureSeconds_
145+
});
146+
}
147+
148+
function maxTimeVariationInternal()
149+
internal
150+
view
151+
returns (
152+
uint256,
153+
uint256,
154+
uint256,
155+
uint256
156+
)
157+
{
127158
if (_chainIdChanged()) {
128-
return
129-
ISequencerInbox.MaxTimeVariation({
130-
delayBlocks: 1,
131-
futureBlocks: 1,
132-
delaySeconds: 1,
133-
futureSeconds: 1
134-
});
159+
return (1, 1, 1, 1);
135160
} else {
136-
return
137-
ISequencerInbox.MaxTimeVariation({
138-
delayBlocks: delayBlocks,
139-
futureBlocks: futureBlocks,
140-
delaySeconds: delaySeconds,
141-
futureSeconds: futureSeconds
142-
});
161+
return (delayBlocks, futureBlocks, delaySeconds, futureSeconds);
143162
}
144163
}
145164

@@ -162,12 +181,10 @@ contract SequencerInbox is GasRefundEnabled, ISequencerInbox {
162181
baseFeeL1,
163182
messageDataHash
164183
);
165-
ISequencerInbox.MaxTimeVariation memory maxTimeVariation_ = maxTimeVariation();
184+
(uint256 delayBlocks_, , uint256 delaySeconds_, ) = maxTimeVariationInternal();
166185
// Can only force-include after the Sequencer-only window has expired.
167-
if (l1BlockAndTime[0] + maxTimeVariation_.delayBlocks >= block.number)
168-
revert ForceIncludeBlockTooSoon();
169-
if (l1BlockAndTime[1] + maxTimeVariation_.delaySeconds >= block.timestamp)
170-
revert ForceIncludeTimeTooSoon();
186+
if (l1BlockAndTime[0] + delayBlocks_ >= block.number) revert ForceIncludeBlockTooSoon();
187+
if (l1BlockAndTime[1] + delaySeconds_ >= block.timestamp) revert ForceIncludeTimeTooSoon();
171188

172189
// Verify that message hash represents the last message sequence of delayed message to be included
173190
bytes32 prevDelayedAcc = 0;

src/rollup/BridgeCreator.sol

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,10 @@ contract BridgeCreator is Ownable {
5858
emit ERC20TemplatesUpdated();
5959
}
6060

61-
function _createBridge(
62-
address adminProxy,
63-
BridgeTemplates storage templates,
64-
ISequencerInbox.MaxTimeVariation calldata maxTimeVariation,
65-
uint256 maxDataSize
66-
) internal returns (BridgeContracts memory) {
61+
function _createBridge(address adminProxy, BridgeTemplates storage templates)
62+
internal
63+
returns (BridgeContracts memory)
64+
{
6765
BridgeContracts memory frame;
6866
frame.bridge = IBridge(
6967
address(new TransparentUpgradeableProxy(address(templates.bridge), adminProxy, ""))
@@ -92,9 +90,7 @@ contract BridgeCreator is Ownable {
9290
// create ETH-based bridge if address zero is provided for native token, otherwise create ERC20-based bridge
9391
BridgeContracts memory frame = _createBridge(
9492
adminProxy,
95-
nativeToken == address(0) ? ethBasedTemplates : erc20BasedTemplates,
96-
maxTimeVariation,
97-
maxDataSize
93+
nativeToken == address(0) ? ethBasedTemplates : erc20BasedTemplates
9894
);
9995

10096
// init contracts

0 commit comments

Comments
 (0)