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

Set initial pricePerUnit #117

Merged
merged 25 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
902a4f7
Report 0 batch poster spendings for rollups using custom fee token
gvladika Jan 12, 2024
02075fc
Add unit test for fee token based chain
gvladika Jan 12, 2024
600b090
Add test for arbitrum hosted ETH-based chain
gvladika Jan 12, 2024
120065a
Make it more readable
gvladika Jan 12, 2024
8447048
Add missing deployment block
gvladika Jan 12, 2024
1698e1a
Merge branch 'develop' into fee-token-reports
gvladika Jan 17, 2024
505c024
Report 0 data cost in init msg for fee token based chains
gvladika Jan 18, 2024
87f3dde
Add Foundry test for rollup event inbox, init function
gvladika Jan 18, 2024
396a26d
Add rollupInitialized tests
gvladika Jan 18, 2024
8dd2e18
Check event MessageDelivered params
gvladika Jan 19, 2024
764c1b8
Merge branch 'develop' into fee-token-reports
gvladika Jan 19, 2024
0e8e684
Instead of reporting 0 basefee, don't send report at all in case fee …
gvladika Jan 22, 2024
e8b785b
Merge branch 'fee-token-reports' of github.com:OffchainLabs/nitro-con…
gvladika Jan 22, 2024
4c994f6
Make 'isUsingFeeToken' immutable to avoid nativeToken() calls
gvladika Jan 22, 2024
deb18fb
Add constructor/initialization unit tests
gvladika Jan 22, 2024
6bc4de6
Merge branch 'fee-token-reports' into init-price
gvladika Jan 22, 2024
94cbde1
Merge branch 'fee-token-reports' into init-price
gvladika Jan 23, 2024
4dc3898
Merge branch 'develop' into init-price
gvladika Feb 2, 2024
10cf2d1
Merge branch 'develop' into init-price
gvladika Feb 28, 2024
b2b37dd
Merge branch 'develop' into init-price
gvladika Mar 5, 2024
4255d5a
Merge branch 'develop' into init-price
gvladika Apr 23, 2024
b34e450
Merge branch 'develop' into init-price
gzeoneth Jul 1, 2024
06e6d6b
Merge branch 'develop' into init-price
gzeoneth Jul 1, 2024
a7fb67a
Merge branch 'develop' into init-price
gzeoneth Jul 2, 2024
de1852c
Merge branch 'develop' into init-price
gzeoneth Jul 3, 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
7 changes: 3 additions & 4 deletions src/rollup/AbsRollupEventInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ abstract contract AbsRollupEventInbox is
{
require(bytes(chainConfig).length > 0, "EMPTY_CHAIN_CONFIG");
uint8 initMsgVersion = 1;
uint256 currentDataCost = block.basefee;
if (ArbitrumChecker.runningOnArbitrum()) {
currentDataCost += ArbGasInfo(address(0x6c)).getL1BaseFeeEstimate();
}
uint256 currentDataCost = _currentDataCostToReport();
bytes memory initMsg = abi.encodePacked(
chainId,
initMsgVersion,
Expand All @@ -68,4 +65,6 @@ abstract contract AbsRollupEventInbox is
}

function _enqueueInitializationMsg(bytes memory initMsg) internal virtual returns (uint256);

function _currentDataCostToReport() internal virtual returns (uint256);
}
5 changes: 5 additions & 0 deletions src/rollup/ERC20RollupEventInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ contract ERC20RollupEventInbox is AbsRollupEventInbox {
tokenAmount
);
}

function _currentDataCostToReport() internal pure override returns (uint256) {
// at the moment chains using fee token in Anytrust mode do not charge for the data posting fees
return 0;
}
}
8 changes: 8 additions & 0 deletions src/rollup/RollupEventInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ contract RollupEventInbox is AbsRollupEventInbox {
keccak256(initMsg)
);
}

function _currentDataCostToReport() internal view override returns (uint256) {
uint256 currentDataCost = block.basefee;
if (ArbitrumChecker.runningOnArbitrum()) {
currentDataCost += ArbGasInfo(address(0x6c)).getL1BaseFeeEstimate();
}
return currentDataCost;
}
}
44 changes: 44 additions & 0 deletions test/foundry/AbsRollupEventInbox.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

import "forge-std/Test.sol";
import "../../src/rollup/AbsRollupEventInbox.sol";
import {IBridge} from "../../src/bridge/IBridge.sol";
import {IInboxBase} from "../../src/bridge/IInbox.sol";

abstract contract AbsRollupEventInboxTest is Test {
IRollupEventInbox public rollupEventInbox;
IBridge public bridge;

address public rollup = makeAddr("rollup");

uint256 public constant MAX_DATA_SIZE = 104_857;

/* solhint-disable func-name-mixedcase */
function test_initialize() public {
assertEq(address(rollupEventInbox.bridge()), address(bridge), "Invalid bridge ref");
assertEq(address(rollupEventInbox.rollup()), rollup, "Invalid rollup ref");
}

function test_initialize_revert_AlreadyInit() public {
vm.expectRevert(AlreadyInit.selector);
rollupEventInbox.initialize(bridge);
}

/**
*
* Event declarations
*
*/
event MessageDelivered(
uint256 indexed messageIndex,
bytes32 indexed beforeInboxAcc,
address inbox,
uint8 kind,
address sender,
bytes32 messageDataHash,
uint256 baseFeeL1,
uint64 timestamp
);
event InboxMessageDelivered(uint256 indexed messageNum, bytes data);
}
98 changes: 98 additions & 0 deletions test/foundry/ERC20RollupEventInbox.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

import "./AbsRollupEventInbox.t.sol";
import {TestUtil} from "./util/TestUtil.sol";
import {ERC20RollupEventInbox} from "../../src/rollup/ERC20RollupEventInbox.sol";
import {ERC20Bridge, IERC20Bridge, IOwnable} from "../../src/bridge/ERC20Bridge.sol";
import {ERC20PresetMinterPauser} from
"@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";

contract ERC20RollupEventInboxTest is AbsRollupEventInboxTest {
function setUp() public {
rollupEventInbox =
IRollupEventInbox(TestUtil.deployProxy(address(new ERC20RollupEventInbox())));
bridge = IBridge(TestUtil.deployProxy(address(new ERC20Bridge())));
address nativeToken = address(new ERC20PresetMinterPauser("Appchain Token", "App"));
IERC20Bridge(address(bridge)).initialize(IOwnable(rollup), nativeToken);

vm.prank(rollup);
bridge.setDelayedInbox(address(rollupEventInbox), true);

rollupEventInbox.initialize(bridge);
}

/* solhint-disable func-name-mixedcase */
function test_initialize_revert_ZeroInit() public {
ERC20RollupEventInbox rollupEventInbox =
ERC20RollupEventInbox(TestUtil.deployProxy(address(new ERC20RollupEventInbox())));

vm.expectRevert(HadZeroInit.selector);
rollupEventInbox.initialize(IBridge(address(0)));
}

function test_rollupInitialized_ArbitrumHosted() public {
uint256 chainId = 400;
string memory chainConfig = "chainConfig";

uint8 expectedInitMsgVersion = 1;
uint256 expectedCurrentDataCost = 0;
bytes memory expectedInitMsg =
abi.encodePacked(chainId, expectedInitMsgVersion, expectedCurrentDataCost, chainConfig);

// expect event
vm.expectEmit(true, true, true, true);
emit MessageDelivered(
0,
bytes32(0),
address(rollupEventInbox),
INITIALIZATION_MSG_TYPE,
address(0),
keccak256(expectedInitMsg),
uint256(0),
uint64(block.timestamp)
);

vm.expectEmit(true, true, true, true);
emit InboxMessageDelivered(0, expectedInitMsg);

/// this will result in 'hostChainIsArbitrum = true'
vm.mockCall(
address(100),
abi.encodeWithSelector(ArbSys.arbOSVersion.selector),
abi.encode(uint256(11))
);

vm.prank(rollup);
rollupEventInbox.rollupInitialized(chainId, chainConfig);
}

function test_rollupInitialized_NonArbitrumHosted() public {
uint256 chainId = 500;
string memory chainConfig = "chainConfig2";

uint8 expectedInitMsgVersion = 1;
uint256 expectedCurrentDataCost = 0;
bytes memory expectedInitMsg =
abi.encodePacked(chainId, expectedInitMsgVersion, expectedCurrentDataCost, chainConfig);

// expect event
vm.expectEmit(true, true, true, true);
emit MessageDelivered(
0,
bytes32(0),
address(rollupEventInbox),
INITIALIZATION_MSG_TYPE,
address(0),
keccak256(expectedInitMsg),
uint256(0),
uint64(block.timestamp)
);

vm.expectEmit(true, true, true, true);
emit InboxMessageDelivered(0, expectedInitMsg);

vm.prank(rollup);
rollupEventInbox.rollupInitialized(chainId, chainConfig);
}
}
110 changes: 110 additions & 0 deletions test/foundry/RollupEventInbox.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

import "./AbsRollupEventInbox.t.sol";
import {TestUtil} from "./util/TestUtil.sol";
import {RollupEventInbox, IRollupEventInbox} from "../../src/rollup/RollupEventInbox.sol";
import {Bridge, IOwnable, IEthBridge} from "../../src/bridge/Bridge.sol";
import "../../src/libraries/MessageTypes.sol";

contract RollupEventInboxTest is AbsRollupEventInboxTest {
function setUp() public {
rollupEventInbox = IRollupEventInbox(TestUtil.deployProxy(address(new RollupEventInbox())));

bridge = IBridge(TestUtil.deployProxy(address(new Bridge())));
IEthBridge(address(bridge)).initialize(IOwnable(rollup));

vm.prank(rollup);
bridge.setDelayedInbox(address(rollupEventInbox), true);

rollupEventInbox.initialize(bridge);
}

/* solhint-disable func-name-mixedcase */
function test_initialize_revert_ZeroInit() public {
RollupEventInbox rollupEventInbox =
RollupEventInbox(TestUtil.deployProxy(address(new RollupEventInbox())));

vm.expectRevert(HadZeroInit.selector);
rollupEventInbox.initialize(IBridge(address(0)));
}

function test_rollupInitialized_NonArbitrumHosted() public {
uint256 chainId = 123;
string memory chainConfig = "chainConfig";

// 80 gwei basefee
uint256 basefee = 80_000_000_000;
vm.fee(basefee);

uint8 expectedInitMsgVersion = 1;
uint256 expectedCurrentDataCost = basefee;
bytes memory expectedInitMsg =
abi.encodePacked(chainId, expectedInitMsgVersion, expectedCurrentDataCost, chainConfig);

// expect event
vm.expectEmit(true, true, true, true);
emit MessageDelivered(
0,
bytes32(0),
address(rollupEventInbox),
INITIALIZATION_MSG_TYPE,
address(0),
keccak256(expectedInitMsg),
basefee,
uint64(block.timestamp)
);

vm.expectEmit(true, true, true, true);
emit InboxMessageDelivered(0, expectedInitMsg);

vm.prank(rollup);
rollupEventInbox.rollupInitialized(chainId, chainConfig);
}

function test_rollupInitialized_ArbitrumHosted() public {
uint256 chainId = 1234;
string memory chainConfig = "chainConfig2";

// 0.35 gwei basefee
uint256 l2Fee = 350_000_000;
vm.fee(l2Fee);

// 50 gwei L1 basefee
uint256 l1Fee = 50_000_000_000;
vm.mockCall(
address(0x6c), abi.encodeWithSignature("getL1BaseFeeEstimate()"), abi.encode(l1Fee)
);

uint8 expectedInitMsgVersion = 1;
uint256 expectedCurrentDataCost = l2Fee + l1Fee;
bytes memory expectedInitMsg =
abi.encodePacked(chainId, expectedInitMsgVersion, expectedCurrentDataCost, chainConfig);

/// this will result in 'hostChainIsArbitrum = true'
vm.mockCall(
address(100),
abi.encodeWithSelector(ArbSys.arbOSVersion.selector),
abi.encode(uint256(11))
);

// expect event
vm.expectEmit(true, true, true, true);
emit MessageDelivered(
0,
bytes32(0),
address(rollupEventInbox),
INITIALIZATION_MSG_TYPE,
address(0),
keccak256(expectedInitMsg),
l2Fee,
uint64(block.timestamp)
);

vm.expectEmit(true, true, true, true);
emit InboxMessageDelivered(0, expectedInitMsg);

vm.prank(rollup);
rollupEventInbox.rollupInitialized(chainId, chainConfig);
}
}
Loading