Skip to content

Commit 3646a78

Browse files
authored
Merge pull request #87 from OffchainLabs/seq-inbox-bridge
Move event and delayed inbox messages read to the bridge
2 parents 275d75b + 085e0e9 commit 3646a78

File tree

12 files changed

+213
-151
lines changed

12 files changed

+213
-151
lines changed

src/bridge/AbsBridge.sol

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ import {
1414
NotSequencerInbox,
1515
NotOutbox,
1616
InvalidOutboxSet,
17-
BadSequencerMessageNumber
17+
BadSequencerMessageNumber,
18+
EmptyDelayedMessagesRead,
19+
DelayedBackwards,
20+
DelayedTooFar
1821
} from "../libraries/Error.sol";
1922
import "./IBridge.sol";
2023
import "./Messages.sol";
2124
import "../libraries/DelegateCallAware.sol";
25+
import "./ISequencerInbox.sol";
2226

2327
import {L1MessageType_batchPostingReport} from "../libraries/MessageTypes.sol";
2428

@@ -55,8 +59,15 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
5559

5660
uint256 public override sequencerReportedSubMessageCount;
5761

62+
uint256 public totalDelayedMessagesRead;
63+
5864
address internal constant EMPTY_ACTIVEOUTBOX = address(type(uint160).max);
5965

66+
function postUpgradeInit() external onlyDelegated onlyProxyOwner {
67+
totalDelayedMessagesRead = ISequencerInbox(sequencerInbox).totalDelayedMessagesRead();
68+
if (totalDelayedMessagesRead == 0) revert EmptyDelayedMessagesRead();
69+
}
70+
6071
modifier onlyRollupOrOwner() {
6172
if (msg.sender != address(rollup)) {
6273
address rollupOwner = rollup.owner();
@@ -101,7 +112,9 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
101112
bytes32 dataHash,
102113
uint256 afterDelayedMessagesRead,
103114
uint256 prevMessageCount,
104-
uint256 newMessageCount
115+
uint256 newMessageCount,
116+
TimeBounds memory timeBounds,
117+
BatchDataLocation batchDataLocation
105118
)
106119
external
107120
onlySequencerInbox
@@ -119,6 +132,9 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
119132
) {
120133
revert BadSequencerMessageNumber(sequencerReportedSubMessageCount, prevMessageCount);
121134
}
135+
if (afterDelayedMessagesRead > delayedInboxAccs.length) revert DelayedTooFar();
136+
if (afterDelayedMessagesRead < totalDelayedMessagesRead) revert DelayedBackwards();
137+
122138
sequencerReportedSubMessageCount = newMessageCount;
123139
seqMessageIndex = sequencerInboxAccs.length;
124140
if (sequencerInboxAccs.length > 0) {
@@ -129,6 +145,18 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
129145
}
130146
acc = keccak256(abi.encodePacked(beforeAcc, dataHash, delayedAcc));
131147
sequencerInboxAccs.push(acc);
148+
totalDelayedMessagesRead = afterDelayedMessagesRead;
149+
150+
emit SequencerBatchDelivered(
151+
seqMessageIndex,
152+
beforeAcc,
153+
acc,
154+
delayedAcc,
155+
afterDelayedMessagesRead,
156+
timeBounds,
157+
batchDataLocation,
158+
msg.sender
159+
);
132160
}
133161

134162
/// @inheritdoc IBridge
@@ -304,5 +332,5 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
304332
* variables without shifting down storage in the inheritance chain.
305333
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
306334
*/
307-
uint256[40] private __gap;
335+
uint256[39] private __gap;
308336
}

src/bridge/IBridge.sol

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,24 @@
44

55
// solhint-disable-next-line compiler-version
66
pragma solidity >=0.6.9 <0.9.0;
7+
pragma experimental ABIEncoderV2;
78

89
import "./IOwnable.sol";
910

1011
interface IBridge {
12+
enum BatchDataLocation {
13+
TxInput,
14+
SeparateBatchEvent,
15+
NoData
16+
}
17+
18+
struct TimeBounds {
19+
uint64 minTimestamp;
20+
uint64 maxTimestamp;
21+
uint64 minBlockNumber;
22+
uint64 maxBlockNumber;
23+
}
24+
1125
event MessageDelivered(
1226
uint256 indexed messageIndex,
1327
bytes32 indexed beforeInboxAcc,
@@ -26,6 +40,17 @@ interface IBridge {
2640
bytes data
2741
);
2842

43+
event SequencerBatchDelivered(
44+
uint256 indexed batchSequenceNumber,
45+
bytes32 indexed beforeAcc,
46+
bytes32 indexed afterAcc,
47+
bytes32 delayedAcc,
48+
uint256 afterDelayedMessagesRead,
49+
TimeBounds timeBounds,
50+
BatchDataLocation dataLocation,
51+
address sequencerInbox
52+
);
53+
2954
event InboxToggle(address indexed inbox, bool enabled);
3055

3156
event OutboxToggle(address indexed outbox, bool enabled);
@@ -66,13 +91,17 @@ interface IBridge {
6691

6792
function sequencerMessageCount() external view returns (uint256);
6893

94+
function totalDelayedMessagesRead() external view returns (uint256);
95+
6996
// ---------- onlySequencerInbox functions ----------
7097

7198
function enqueueSequencerMessage(
7299
bytes32 dataHash,
73100
uint256 afterDelayedMessagesRead,
74101
uint256 prevMessageCount,
75-
uint256 newMessageCount
102+
uint256 newMessageCount,
103+
TimeBounds memory timeBounds,
104+
BatchDataLocation dataLocation
76105
)
77106
external
78107
returns (

src/bridge/ISequencerInbox.sol

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,6 @@ interface ISequencerInbox is IDelayedMessageProvider {
2323
uint256 futureSeconds;
2424
}
2525

26-
struct TimeBounds {
27-
uint64 minTimestamp;
28-
uint64 maxTimestamp;
29-
uint64 minBlockNumber;
30-
uint64 maxBlockNumber;
31-
}
32-
33-
enum BatchDataLocation {
34-
TxInput,
35-
SeparateBatchEvent,
36-
NoData
37-
}
38-
39-
event SequencerBatchDelivered(
40-
uint256 indexed batchSequenceNumber,
41-
bytes32 indexed beforeAcc,
42-
bytes32 indexed afterAcc,
43-
bytes32 delayedAcc,
44-
uint256 afterDelayedMessagesRead,
45-
TimeBounds timeBounds,
46-
BatchDataLocation dataLocation
47-
);
48-
4926
event OwnerFunctionCalled(uint256 indexed id);
5027

5128
/// @dev a separate event that emits batch data when this isn't easily accessible in the tx.input
@@ -57,6 +34,8 @@ interface ISequencerInbox is IDelayedMessageProvider {
5734
/// @dev a keyset was invalidated
5835
event InvalidateKeyset(bytes32 indexed keysetHash);
5936

37+
/// @notice The total number of delated messages read in the bridge
38+
/// @dev We surface this here for backwards compatibility
6039
function totalDelayedMessagesRead() external view returns (uint256);
6140

6241
function bridge() external view returns (IBridge);

0 commit comments

Comments
 (0)