Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions scripts/config.ts.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const maxDataSize = 117964

export const isUsingFeeToken = false;

export const disableMessageFromOriginEvent = false;

export const config = {
rollupConfig: {
confirmPeriodBlocks: ethers.BigNumber.from('45818'),
Expand Down
6 changes: 4 additions & 2 deletions scripts/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'hardhat'
import '@nomiclabs/hardhat-ethers'
import { deployAllContracts, _isRunningOnArbitrum } from './deploymentUtils'
import { maxDataSize } from './config'
import { maxDataSize, disableMessageFromOriginEvent } from './config'

import { ArbSys__factory } from '../build/types'

Expand All @@ -26,10 +26,12 @@ async function main() {

try {
// Deploying all contracts
const verify = false;
const contracts = await deployAllContracts(
signer,
ethers.BigNumber.from(maxDataSize),
true
disableMessageFromOriginEvent,
verify
)

// Call setTemplates with the deployed contract addresses
Expand Down
5 changes: 3 additions & 2 deletions scripts/deploymentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export async function deployUpgradeExecutor(signer: any): Promise<Contract> {
export async function deployAllContracts(
signer: any,
maxDataSize: BigNumber,
disableMessageFromOriginEvent: boolean,
verify: boolean = true
): Promise<Record<string, Contract>> {
const isOnArb = await _isRunningOnArbitrum(signer)
Expand All @@ -139,7 +140,7 @@ export async function deployAllContracts(
verify
)

const ethInbox = await deployContract('Inbox', signer, [maxDataSize], verify)
const ethInbox = await deployContract('Inbox', signer, [maxDataSize, disableMessageFromOriginEvent], verify)
const ethRollupEventInbox = await deployContract(
'RollupEventInbox',
signer,
Expand All @@ -164,7 +165,7 @@ export async function deployAllContracts(
const erc20Inbox = await deployContract(
'ERC20Inbox',
signer,
[maxDataSize],
[maxDataSize, disableMessageFromOriginEvent],
verify
)
const erc20RollupEventInbox = await deployContract(
Expand Down
8 changes: 7 additions & 1 deletion scripts/local-deployment/deployCreatorAndCreateRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ async function main() {
? ethers.BigNumber.from(process.env.MAX_DATA_SIZE)
: ethers.BigNumber.from(117964)

const disableMessageFromOriginEvent =
process.env.DISABLE_MESSAGE_FROM_ORIGIN_EVENT !== undefined
? process.env.DISABLE_MESSAGE_FROM_ORIGIN_EVENT === 'true'
: false

/// get fee token address, if undefined use address(0) to have ETH as fee token
let feeToken = process.env.FEE_TOKEN_ADDRESS as string
if (!feeToken) {
Expand All @@ -62,7 +67,8 @@ async function main() {

/// deploy templates and rollup creator
console.log('Deploy RollupCreator')
const contracts = await deployAllContracts(deployerWallet, maxDataSize, false)
const verify = false;
const contracts = await deployAllContracts(deployerWallet, maxDataSize, disableMessageFromOriginEvent, verify)

console.log('Set templates on the Rollup Creator')
await (
Expand Down
10 changes: 9 additions & 1 deletion src/bridge/AbsInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,16 @@ abstract contract AbsInbox is DelegateCallAware, PausableUpgradeable, IInboxBase

// On L1 this should be set to 117964: 90% of Geth's 128KB tx size limit, leaving ~13KB for proving
uint256 public immutable maxDataSize;
// If disableMessageFromOriginEvent is true, an InboxMessageDelivered event will be emitted instead of InboxMessageDeliveredFromOrigin
bool public immutable disableMessageFromOriginEvent;
uint256 internal immutable deployTimeChainId = block.chainid;

constructor(
uint256 _maxDataSize
uint256 _maxDataSize,
bool _disableMessageFromOriginEvent
) {
maxDataSize = _maxDataSize;
disableMessageFromOriginEvent = _disableMessageFromOriginEvent;
}

function _chainIdChanged() internal view returns (bool) {
Expand Down Expand Up @@ -143,6 +147,10 @@ abstract contract AbsInbox is DelegateCallAware, PausableUpgradeable, IInboxBase
if (!CallerChecker.isCallerCodelessOrigin()) revert NotCodelessOrigin();
if (messageData.length > maxDataSize) revert DataTooLarge(messageData.length, maxDataSize);
uint256 msgNum = _deliverToBridge(L2_MSG, msg.sender, keccak256(messageData), 0);
if (disableMessageFromOriginEvent) {
emit InboxMessageDelivered(msgNum, messageData);
return msgNum;
}
emit InboxMessageDeliveredFromOrigin(msgNum);
return msgNum;
}
Expand Down
5 changes: 3 additions & 2 deletions src/bridge/ERC20Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ contract ERC20Inbox is AbsInbox, IERC20Inbox {
using SafeERC20 for IERC20;

constructor(
uint256 _maxDataSize
) AbsInbox(_maxDataSize) {}
uint256 _maxDataSize,
bool _disableMessageFromOriginEvent
) AbsInbox(_maxDataSize, _disableMessageFromOriginEvent) {}

/// @inheritdoc IInboxBase
function initialize(
Expand Down
5 changes: 3 additions & 2 deletions src/bridge/Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
*/
contract Inbox is AbsInbox, IInbox {
constructor(
uint256 _maxDataSize
) AbsInbox(_maxDataSize) {}
uint256 _maxDataSize,
bool _disableMessageFromOriginEvent
) AbsInbox(_maxDataSize, _disableMessageFromOriginEvent) {}

/// @inheritdoc IInboxBase
function initialize(
Expand Down
5 changes: 3 additions & 2 deletions test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ contract RollupTest is Test {
uint256 constant MINI_STAKE_VALUE = 2;
uint64 constant CONFIRM_PERIOD_BLOCKS = 100;
uint256 constant MAX_DATA_SIZE = 117964;
bool constant DISABLE_MESSAGE_FROM_ORIGIN_EVENT = false;
uint64 constant CHALLENGE_GRACE_PERIOD_BLOCKS = 10;

bytes32 constant FIRST_ASSERTION_BLOCKHASH = keccak256("FIRST_ASSERTION_BLOCKHASH");
Expand Down Expand Up @@ -94,15 +95,15 @@ contract RollupTest is Test {
bridge: new Bridge(),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false, false),
delayBufferableSequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false, true),
inbox: new Inbox(MAX_DATA_SIZE),
inbox: new Inbox(MAX_DATA_SIZE, DISABLE_MESSAGE_FROM_ORIGIN_EVENT),
rollupEventInbox: new RollupEventInbox(),
outbox: new Outbox()
});
BridgeCreator.BridgeTemplates erc20BasedTemplates = BridgeCreator.BridgeTemplates({
bridge: new ERC20Bridge(),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true, false),
delayBufferableSequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true, true),
inbox: new ERC20Inbox(MAX_DATA_SIZE),
inbox: new ERC20Inbox(MAX_DATA_SIZE, DISABLE_MESSAGE_FROM_ORIGIN_EVENT),
rollupEventInbox: new ERC20RollupEventInbox(),
outbox: new ERC20Outbox()
});
Expand Down
23 changes: 15 additions & 8 deletions test/contract/sequencerInboxForceInclude.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

/* eslint-env node, mocha */

import { ethers, network } from 'hardhat'
import { Interface } from '@ethersproject/abi'
import { BigNumber } from '@ethersproject/bignumber'
import { Event } from '@ethersproject/contracts'
import { Block, TransactionReceipt } from '@ethersproject/providers'
import { expect } from 'chai'
import { constants, Signer } from 'ethers'
import { ethers, network } from 'hardhat'
import {
Bridge,
Bridge__factory,
Expand All @@ -31,17 +34,14 @@ import {
SequencerInbox__factory,
TransparentUpgradeableProxy__factory,
} from '../../build/types'
import { applyAlias, initializeAccounts } from './utils'
import { Event } from '@ethersproject/contracts'
import { Interface } from '@ethersproject/abi'
import {
BridgeInterface,
MessageDeliveredEvent,
} from '../../build/types/src/bridge/Bridge'
import { constants, Signer } from 'ethers'
import { Toolkit4844 } from './toolkit4844'
import { data } from './batchData.json'
import { seqInterface } from './testHelpers'
import { Toolkit4844 } from './toolkit4844'
import { applyAlias, initializeAccounts } from './utils'

const mineBlocks = async (count: number, timeDiffPerBlock = 14) => {
const block = (await network.provider.send('eth_getBlockByNumber', [
Expand Down Expand Up @@ -219,7 +219,11 @@ describe('SequencerInboxForceInclude', async () => {
}
}

const setupSequencerInbox = async (maxDelayBlocks = 10, maxDelayTime = 0) => {
const setupSequencerInbox = async (
maxDelayBlocks = 10,
maxDelayTime = 0,
disableMessageFromOriginEvent = false
) => {
const accounts = await initializeAccounts()
const admin = accounts[0]
const adminAddr = await admin.getAddress()
Expand Down Expand Up @@ -247,7 +251,10 @@ describe('SequencerInboxForceInclude', async () => {
const inboxFac = (await ethers.getContractFactory(
'Inbox'
)) as Inbox__factory
const inboxTemplate = await inboxFac.deploy(117964)
const inboxTemplate = await inboxFac.deploy(
117964,
disableMessageFromOriginEvent
)
const bridgeFac = (await ethers.getContractFactory(
'Bridge'
)) as Bridge__factory
Expand Down
8 changes: 6 additions & 2 deletions test/contract/testHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ export const setupSequencerInbox = async (
isDelayBufferable = false,
isBlobMock = false,
maxDelay: MaxTimeVariation = maxDelayDefault,
delayConfig: DelayConfig = delayConfigDefault
delayConfig: DelayConfig = delayConfigDefault,
disableMessageFromOriginEvent = false
) => {
const accounts = await initializeAccounts()
const admin = accounts[0]
Expand All @@ -320,7 +321,10 @@ export const setupSequencerInbox = async (
isDelayBufferable
)
const inboxFac = (await ethers.getContractFactory('Inbox')) as Inbox__factory
const inboxTemplate = await inboxFac.deploy(117964)
const inboxTemplate = await inboxFac.deploy(
117964,
disableMessageFromOriginEvent
)
const bridgeFac = (await ethers.getContractFactory(
'Bridge'
)) as Bridge__factory
Expand Down
3 changes: 2 additions & 1 deletion test/foundry/AbsInbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ abstract contract AbsInboxTest is Test {
IBridge public bridge;

uint256 public constant MAX_DATA_SIZE = 117_964;
bool public constant DISABLE_MESSAGE_FROM_ORIGIN_EVENT = false;

address public user = address(100);
address public rollup = address(1000);
Expand Down Expand Up @@ -168,7 +169,7 @@ abstract contract AbsInboxTest is Test {
}

function test_initialize_revert_NonDelegated() public {
ERC20Inbox inb = new ERC20Inbox(MAX_DATA_SIZE);
ERC20Inbox inb = new ERC20Inbox(MAX_DATA_SIZE, DISABLE_MESSAGE_FROM_ORIGIN_EVENT);
vm.expectRevert("Function must be called through delegatecall");
inb.initialize(bridge, ISequencerInbox(seqInbox));
}
Expand Down
5 changes: 3 additions & 2 deletions test/foundry/BridgeCreator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ contract BridgeCreatorTest is Test {
BridgeCreator public creator;
address public owner = address(100);
uint256 public constant MAX_DATA_SIZE = 117_964;
bool public constant DISABLE_MESSAGE_FROM_ORIGIN_EVENT = false;
IReader4844 dummyReader4844 = IReader4844(address(137));

BridgeCreator.BridgeTemplates ethBasedTemplates = BridgeCreator.BridgeTemplates({
bridge: new Bridge(),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false, false),
delayBufferableSequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false, true),
inbox: new Inbox(MAX_DATA_SIZE),
inbox: new Inbox(MAX_DATA_SIZE, DISABLE_MESSAGE_FROM_ORIGIN_EVENT),
rollupEventInbox: new RollupEventInbox(),
outbox: new Outbox()
});
BridgeCreator.BridgeTemplates erc20BasedTemplates = BridgeCreator.BridgeTemplates({
bridge: new ERC20Bridge(),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true, false),
delayBufferableSequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true, true),
inbox: new ERC20Inbox(MAX_DATA_SIZE),
inbox: new ERC20Inbox(MAX_DATA_SIZE, DISABLE_MESSAGE_FROM_ORIGIN_EVENT),
rollupEventInbox: new ERC20RollupEventInbox(),
outbox: new ERC20Outbox()
});
Expand Down
3 changes: 2 additions & 1 deletion test/foundry/ERC20Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract ERC20BridgeTest is AbsBridgeTest {
IERC20 public nativeToken;

uint256 public constant MAX_DATA_SIZE = 117_964;
bool public constant DISABLE_MESSAGE_FROM_ORIGIN_EVENT = false;

// msg details
uint8 public kind = 7;
Expand All @@ -34,7 +35,7 @@ contract ERC20BridgeTest is AbsBridgeTest {
erc20Bridge.initialize(IOwnable(rollup), address(nativeToken));

// deploy inbox
inbox = address(TestUtil.deployProxy(address(new ERC20Inbox(MAX_DATA_SIZE))));
inbox = address(TestUtil.deployProxy(address(new ERC20Inbox(MAX_DATA_SIZE, DISABLE_MESSAGE_FROM_ORIGIN_EVENT))));
IERC20Inbox(address(inbox)).initialize(bridge, ISequencerInbox(seqInbox));
}

Expand Down
Loading