Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimisations in the sequencer inbox #68

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ee52a74
Added test sequencer inbox opt
yahgwai Oct 4, 2023
cb72410
Made state vars immutable
yahgwai Oct 4, 2023
2b17df0
Added commentson max time variation
yahgwai Oct 4, 2023
ad06124
Removed deprecated method
yahgwai Oct 4, 2023
a4c3800
Updated tests
yahgwai Oct 4, 2023
90de978
Updated comments
yahgwai Oct 4, 2023
b7414fb
Formatted files
yahgwai Oct 4, 2023
87aafcf
Test file lint
yahgwai Oct 4, 2023
5890bde
Merge from develop
yahgwai Oct 5, 2023
998fe16
Updated max time variation comments
yahgwai Oct 5, 2023
a60f7ff
Updated tests
yahgwai Oct 5, 2023
b7b2f49
Storage layout checks no longer required for sequencer inbox
yahgwai Oct 5, 2023
0b9ba23
Merge from develop
yahgwai Oct 25, 2023
cd0d302
Build updates
yahgwai Oct 25, 2023
75215ba
Updated tests and added bridge.rollup() initialization tests
yahgwai Oct 25, 2023
a3111c4
Formatting
yahgwai Oct 25, 2023
90f2262
Updated arbrollup tests
yahgwai Oct 25, 2023
fe97273
Removed test events
yahgwai Oct 25, 2023
f75a8fc
Moved delayed messages read and batch delivered event into the bridge
yahgwai Oct 26, 2023
887cc47
Removed tests for now
yahgwai Oct 26, 2023
d06f2a0
Added encoder v2
yahgwai Oct 26, 2023
ce8fb88
Updated bridge storage dot
yahgwai Oct 26, 2023
3609765
Merge branch 'develop' into seq-inbox-opt
gzeoneth Oct 27, 2023
275d75b
Merge remote-tracking branch 'origin/develop' into seq-inbox-opt
gzeoneth Oct 30, 2023
22c9c75
Merge remote-tracking branch 'origin/seq-inbox-opt' into seq-inbox-br…
gzeoneth Oct 31, 2023
a4337e1
Updates from CR
yahgwai Oct 31, 2023
f3b1ceb
Merge branch 'seq-inbox-bridge' of https://github.com/OffchainLabs/ni…
yahgwai Oct 31, 2023
285b6bf
Merge from remote
yahgwai Oct 31, 2023
085e0e9
Removed old dot files
yahgwai Oct 31, 2023
3646a78
Merge pull request #87 from OffchainLabs/seq-inbox-bridge
yahgwai Oct 31, 2023
31fd3c6
Added internal max time variation func
yahgwai Nov 17, 2023
05e311d
Updated max time variation to be u64
yahgwai Nov 17, 2023
773e1ec
Merge branch 'develop' into seq-inbox-opt
Tristan-Wilson Dec 7, 2023
f3cfc60
fix: backward compatible maxTimeVariation
gzeoneth Dec 28, 2023
1fd0958
Formatting
yahgwai Jan 9, 2024
ab6855c
Updated tests
yahgwai Jan 9, 2024
a8f206b
Merge pull request #106 from OffchainLabs/g-patch-1
yahgwai Jan 9, 2024
2dda137
Update src/bridge/ISequencerInbox.sol
yahgwai Jan 9, 2024
e728f1f
Updated gas refunder to account for proxy usage
yahgwai Jan 16, 2024
1c6a328
Formatting
yahgwai Jan 16, 2024
0b7dc82
Moved calldata words inside
yahgwai Jan 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/BridgeStubCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = async hre => {
const { deploy } = deployments
const { deployer } = await getNamedAccounts()

await deploy('BridgeStub', { from: deployer, args: [] })
await deploy('BridgeStub', { from: deployer, args: [deployer] })
}

module.exports.tags = ['BridgeStub', 'test']
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
"test:e2e": "hardhat test test/e2e/*.ts",
"postinstall": "patch-package",
"deploy-factory": "hardhat run scripts/deployment.ts",
"deploy-rollup": "hardhat run scripts/rollupCreation.ts",
"deploy-eth-rollup": "hardhat run scripts/createEthRollup.ts",
"deploy-erc20-rollup": "hardhat run scripts/createERC20Rollup.ts"
"deploy-erc20-rollup": "hardhat run scripts/createERC20Rollup.ts",
"test": "hardhat --network hardhat test test/contract/*.spec.ts"
},
"dependencies": {
"@offchainlabs/upgrade-executor": "1.1.0-beta.0",
Expand Down
8 changes: 4 additions & 4 deletions scripts/config.ts.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export const config = {
'{"chainId":13331370,"homesteadBlock":0,"daoForkBlock":null,"daoForkSupport":true,"eip150Block":0,"eip150Hash":"0x0000000000000000000000000000000000000000000000000000000000000000","eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"constantinopleBlock":0,"petersburgBlock":0,"istanbulBlock":0,"muirGlacierBlock":0,"berlinBlock":0,"londonBlock":0,"clique":{"period":0,"epoch":0},"arbitrum":{"EnableArbOS":true,"AllowDebugPrecompiles":false,"DataAvailabilityCommittee":false,"InitialArbOSVersion":10,"InitialChainOwner":"0x1234123412341234123412341234123412341234","GenesisBlockNum":0}}',
genesisBlockNum: ethers.BigNumber.from('0'),
sequencerInboxMaxTimeVariation: {
delayBlocks: ethers.BigNumber.from('5760'),
futureBlocks: ethers.BigNumber.from('12'),
delaySeconds: ethers.BigNumber.from('86400'),
futureSeconds: ethers.BigNumber.from('3600'),
delayBlocks: 5760,
futureBlocks: 12,
delaySeconds: 86400,
futureSeconds: 3600,
},
},
validators: [
Expand Down
12 changes: 4 additions & 8 deletions scripts/rollupCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,11 @@ export async function createRollup(feeToken?: string) {
maxDataSize: maxDataSize,
nativeToken: feeToken,
deployFactoriesToL2: true,
maxFeePerGasForRetryables: MAX_FER_PER_GAS
maxFeePerGasForRetryables: MAX_FER_PER_GAS,
}
const createRollupTx = await rollupCreator.createRollup(
deployParams,
{
value: feeCost,
}

)
const createRollupTx = await rollupCreator.createRollup(deployParams, {
value: feeCost,
})
const createRollupReceipt = await createRollupTx.wait()

const rollupCreatedEvent = createRollupReceipt.events?.find(
Expand Down
34 changes: 31 additions & 3 deletions src/bridge/AbsBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ import {
NotSequencerInbox,
NotOutbox,
InvalidOutboxSet,
BadSequencerMessageNumber
BadSequencerMessageNumber,
EmptyDelayedMessagesRead,
DelayedBackwards,
DelayedTooFar
} from "../libraries/Error.sol";
import "./IBridge.sol";
import "./Messages.sol";
import "../libraries/DelegateCallAware.sol";
import "./ISequencerInbox.sol";

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

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

uint256 public override sequencerReportedSubMessageCount;

uint256 public totalDelayedMessagesRead;

address internal constant EMPTY_ACTIVEOUTBOX = address(type(uint160).max);

function postUpgradeInit() external onlyDelegated onlyProxyOwner {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we include setSequencerInbox in here too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, I thinkn that makes sense, will update.

totalDelayedMessagesRead = ISequencerInbox(sequencerInbox).totalDelayedMessagesRead();
if (totalDelayedMessagesRead == 0) revert EmptyDelayedMessagesRead();
}

modifier onlyRollupOrOwner() {
if (msg.sender != address(rollup)) {
address rollupOwner = rollup.owner();
Expand Down Expand Up @@ -101,7 +112,9 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
bytes32 dataHash,
uint256 afterDelayedMessagesRead,
uint256 prevMessageCount,
uint256 newMessageCount
uint256 newMessageCount,
TimeBounds memory timeBounds,
BatchDataLocation batchDataLocation
)
external
onlySequencerInbox
Expand All @@ -119,6 +132,9 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
) {
revert BadSequencerMessageNumber(sequencerReportedSubMessageCount, prevMessageCount);
}
if (afterDelayedMessagesRead > delayedInboxAccs.length) revert DelayedTooFar();
if (afterDelayedMessagesRead < totalDelayedMessagesRead) revert DelayedBackwards();

sequencerReportedSubMessageCount = newMessageCount;
seqMessageIndex = sequencerInboxAccs.length;
if (sequencerInboxAccs.length > 0) {
Expand All @@ -129,6 +145,18 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
}
acc = keccak256(abi.encodePacked(beforeAcc, dataHash, delayedAcc));
sequencerInboxAccs.push(acc);
totalDelayedMessagesRead = afterDelayedMessagesRead;

emit SequencerBatchDelivered(
seqMessageIndex,
beforeAcc,
acc,
delayedAcc,
afterDelayedMessagesRead,
timeBounds,
batchDataLocation,
msg.sender
);
}

/// @inheritdoc IBridge
Expand Down Expand Up @@ -304,5 +332,5 @@ abstract contract AbsBridge is Initializable, DelegateCallAware, IBridge {
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[40] private __gap;
uint256[39] private __gap;
}
1 change: 1 addition & 0 deletions src/bridge/AbsOutbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ abstract contract AbsOutbox is DelegateCallAware, IOutbox {
});
bridge = _bridge;
rollup = address(_bridge.rollup());
if (address(rollup) == address(0)) revert RollupNotChanged();
}

function postUpgradeInit() external onlyDelegated onlyProxyOwner {
Expand Down
31 changes: 30 additions & 1 deletion src/bridge/IBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@

// solhint-disable-next-line compiler-version
pragma solidity >=0.6.9 <0.9.0;
pragma experimental ABIEncoderV2;

import "./IOwnable.sol";

interface IBridge {
enum BatchDataLocation {
TxInput,
SeparateBatchEvent,
NoData
}

struct TimeBounds {
uint64 minTimestamp;
uint64 maxTimestamp;
uint64 minBlockNumber;
uint64 maxBlockNumber;
}

event MessageDelivered(
uint256 indexed messageIndex,
bytes32 indexed beforeInboxAcc,
Expand All @@ -26,6 +40,17 @@ interface IBridge {
bytes data
);

event SequencerBatchDelivered(
uint256 indexed batchSequenceNumber,
bytes32 indexed beforeAcc,
bytes32 indexed afterAcc,
bytes32 delayedAcc,
uint256 afterDelayedMessagesRead,
TimeBounds timeBounds,
BatchDataLocation dataLocation,
address sequencerInbox
);

event InboxToggle(address indexed inbox, bool enabled);

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

function sequencerMessageCount() external view returns (uint256);

function totalDelayedMessagesRead() external view returns (uint256);

// ---------- onlySequencerInbox functions ----------

function enqueueSequencerMessage(
bytes32 dataHash,
uint256 afterDelayedMessagesRead,
uint256 prevMessageCount,
uint256 newMessageCount
uint256 newMessageCount,
TimeBounds memory timeBounds,
BatchDataLocation dataLocation
)
external
returns (
Expand Down
67 changes: 17 additions & 50 deletions src/bridge/ISequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,18 @@ import "./IDelayedMessageProvider.sol";
import "./IBridge.sol";

interface ISequencerInbox is IDelayedMessageProvider {
/// @notice The maximum amount of time variatin between a message being posted on the L1 and being executed on the L2
/// @param delayBlocks The max amount of blocks in the past that a message can be received on L2
/// @param futureBlocks The max amount of blocks in the future that a message can be received on L2
/// @param delaySeconds The max amount of seconds in the past that a message can be received on L2
/// @param futureSeconds The max amount of seconds in the future that a message can be received on L2
struct MaxTimeVariation {
uint256 delayBlocks;
uint256 futureBlocks;
uint256 delaySeconds;
uint256 futureSeconds;
uint64 delayBlocks;
uint64 futureBlocks;
uint64 delaySeconds;
uint64 futureSeconds;
}

struct TimeBounds {
uint64 minTimestamp;
uint64 maxTimestamp;
uint64 minBlockNumber;
uint64 maxBlockNumber;
}

enum BatchDataLocation {
TxInput,
SeparateBatchEvent,
NoData
}

event SequencerBatchDelivered(
uint256 indexed batchSequenceNumber,
bytes32 indexed beforeAcc,
bytes32 indexed afterAcc,
bytes32 delayedAcc,
uint256 afterDelayedMessagesRead,
TimeBounds timeBounds,
BatchDataLocation dataLocation
);

event OwnerFunctionCalled(uint256 indexed id);

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

/// @notice The total number of delated messages read in the bridge
yahgwai marked this conversation as resolved.
Show resolved Hide resolved
/// @dev We surface this here for backwards compatibility
function totalDelayedMessagesRead() external view returns (uint256);

function bridge() external view returns (IBridge);
Expand All @@ -78,21 +62,11 @@ interface ISequencerInbox is IDelayedMessageProvider {
uint64 creationBlock;
}

function maxTimeVariation()
external
view
returns (
uint256,
uint256,
uint256,
uint256
);
/// @notice Returns the max time variation settings for this sequencer inbox
function maxTimeVariation() external view returns (ISequencerInbox.MaxTimeVariation memory);

function dasKeySetInfo(bytes32) external view returns (bool, uint64);

/// @notice Remove force inclusion delay after a L1 chainId fork
function removeDelayAfterFork() external;

/// @notice Force messages from the delayed inbox to be included in the chain
/// Callable by any address, but message can only be force-included after maxTimeVariation.delayBlocks and
/// maxTimeVariation.delaySeconds has elapsed. As part of normal behaviour the sequencer will include these
Expand Down Expand Up @@ -127,7 +101,9 @@ interface ISequencerInbox is IDelayedMessageProvider {
uint256 sequenceNumber,
bytes calldata data,
uint256 afterDelayedMessagesRead,
IGasRefunder gasRefunder
IGasRefunder gasRefunder,
uint256 prevMessageCount,
uint256 newMessageCount
) external;

function addSequencerL2Batch(
Expand All @@ -141,12 +117,6 @@ interface ISequencerInbox is IDelayedMessageProvider {

// ---------- onlyRollupOrOwner functions ----------

/**
* @notice Set max delay for sequencer inbox
* @param maxTimeVariation_ the maximum time variation parameters
*/
function setMaxTimeVariation(MaxTimeVariation memory maxTimeVariation_) external;

/**
* @notice Updates whether an address is authorized to be a batch poster at the sequencer inbox
* @param addr the address
Expand Down Expand Up @@ -174,9 +144,6 @@ interface ISequencerInbox is IDelayedMessageProvider {
*/
function setIsSequencer(address addr, bool isSequencer_) external;

// ---------- initializer ----------

function initialize(IBridge bridge_, MaxTimeVariation calldata maxTimeVariation_) external;

/// @notice Allows the rollup owner to sync the rollup address
function updateRollupAddress() external;
}
Loading
Loading