mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-04-23 03:00:50 -04:00
Merge branch 'develop' into rename/prover
This commit is contained in:
@@ -50,8 +50,7 @@ contract InitializeL2BridgeContracts is Script {
|
||||
vm.startBroadcast(deployerPrivateKey);
|
||||
|
||||
// initialize L2MessageQueue
|
||||
L2MessageQueue(L2_MESSAGE_QUEUE_ADDR).initialize();
|
||||
L2MessageQueue(L2_MESSAGE_QUEUE_ADDR).updateMessenger(L2_SCROLL_MESSENGER_PROXY_ADDR);
|
||||
L2MessageQueue(L2_MESSAGE_QUEUE_ADDR).initialize(L2_SCROLL_MESSENGER_PROXY_ADDR);
|
||||
|
||||
// initialize L2TxFeeVault
|
||||
L2TxFeeVault(payable(L2_TX_FEE_VAULT_ADDR)).updateMessenger(L2_SCROLL_MESSENGER_PROXY_ADDR);
|
||||
|
||||
@@ -21,11 +21,6 @@ contract L2MessageQueue is AppendOnlyMerkleTree, OwnableBase {
|
||||
/// @param messageHash The hash of the corresponding message.
|
||||
event AppendMessage(uint256 index, bytes32 messageHash);
|
||||
|
||||
/// @notice Emits each time the owner updates the address of `messenger`.
|
||||
/// @param oldMessenger The address of old messenger.
|
||||
/// @param newMessenger The address of new messenger.
|
||||
event UpdateMessenger(address indexed oldMessenger, address indexed newMessenger);
|
||||
|
||||
/*************
|
||||
* Variables *
|
||||
*************/
|
||||
@@ -41,8 +36,15 @@ contract L2MessageQueue is AppendOnlyMerkleTree, OwnableBase {
|
||||
_transferOwnership(_owner);
|
||||
}
|
||||
|
||||
function initialize() external {
|
||||
/// @notice Initialize the state of `L2MessageQueue`
|
||||
/// @dev You are not allowed to initialize when there are some messages appended.
|
||||
/// @param _messenger The address of messenger to update.
|
||||
function initialize(address _messenger) external onlyOwner {
|
||||
require(nextMessageIndex == 0, "cannot initialize");
|
||||
|
||||
_initializeMerkleTree();
|
||||
|
||||
messenger = _messenger;
|
||||
}
|
||||
|
||||
/*****************************
|
||||
@@ -61,20 +63,4 @@ contract L2MessageQueue is AppendOnlyMerkleTree, OwnableBase {
|
||||
|
||||
return _currentRoot;
|
||||
}
|
||||
|
||||
/************************
|
||||
* Restricted Functions *
|
||||
************************/
|
||||
|
||||
/// @notice Update the address of messenger.
|
||||
/// @dev You are not allowed to update messenger when there are some messages appended.
|
||||
/// @param _newMessenger The address of messenger to update.
|
||||
function updateMessenger(address _newMessenger) external onlyOwner {
|
||||
require(nextMessageIndex == 0, "cannot update messenger");
|
||||
|
||||
address _oldMessenger = messenger;
|
||||
messenger = _newMessenger;
|
||||
|
||||
emit UpdateMessenger(_oldMessenger, _newMessenger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.16;
|
||||
|
||||
interface IGasOracle {
|
||||
/// @notice Estimate fee for cross chain message call.
|
||||
/// @param _sender The address of sender who invoke the call.
|
||||
/// @param _to The target address to receive the call.
|
||||
/// @param _message The message will be passed to the target address.
|
||||
function estimateMessageFee(
|
||||
address _sender,
|
||||
address _to,
|
||||
bytes memory _message,
|
||||
uint256 _gasLimit
|
||||
) external view returns (uint256);
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity =0.8.16;
|
||||
|
||||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||||
|
||||
import "./IGasOracle.sol";
|
||||
|
||||
/// @title Simple Gas Oracle
|
||||
contract SimpleGasOracle is OwnableUpgradeable, IGasOracle {
|
||||
/**********
|
||||
* Events *
|
||||
**********/
|
||||
|
||||
/// @notice Emitted when owner update default FeeConfig.
|
||||
/// @param _baseFees The amount base fee to pay.
|
||||
/// @param _feesPerByte The amount fee to pay per message byte.
|
||||
event UpdateDefaultFeeConfig(uint256 _baseFees, uint256 _feesPerByte);
|
||||
|
||||
/// @notice Emitted when owner update custom FeeConfig.
|
||||
/// @param _sender The address of custom message sender.
|
||||
/// @param _baseFees The amount base fee to pay.
|
||||
/// @param _feesPerByte The amount fee to pay per message byte.
|
||||
event UpdateCustomFeeConfig(address indexed _sender, uint256 _baseFees, uint256 _feesPerByte);
|
||||
|
||||
/*************
|
||||
* Variables *
|
||||
*************/
|
||||
|
||||
struct FeeConfig {
|
||||
uint128 baseFees;
|
||||
uint128 feesPerByte;
|
||||
}
|
||||
|
||||
/// @notice The default cross chain message FeeConfig.
|
||||
FeeConfig public defaultFeeConfig;
|
||||
|
||||
/// @notice Mapping from sender address to custom FeeConfig.
|
||||
mapping(address => FeeConfig) public customFeeConfig;
|
||||
|
||||
/// @notice Whether the sender should user custom FeeConfig.
|
||||
mapping(address => bool) public hasCustomConfig;
|
||||
|
||||
/***************
|
||||
* Constructor *
|
||||
***************/
|
||||
|
||||
function initialize() external initializer {
|
||||
OwnableUpgradeable.__Ownable_init();
|
||||
}
|
||||
|
||||
/*************************
|
||||
* Public View Functions *
|
||||
*************************/
|
||||
|
||||
/// @inheritdoc IGasOracle
|
||||
function estimateMessageFee(
|
||||
address _sender,
|
||||
address,
|
||||
bytes memory _message,
|
||||
uint256
|
||||
) external view override returns (uint256) {
|
||||
FeeConfig memory _feeConfig;
|
||||
if (hasCustomConfig[_sender]) {
|
||||
_feeConfig = customFeeConfig[_sender];
|
||||
} else {
|
||||
_feeConfig = defaultFeeConfig;
|
||||
}
|
||||
|
||||
unchecked {
|
||||
return _feeConfig.baseFees + uint256(_feeConfig.feesPerByte) * _message.length;
|
||||
}
|
||||
}
|
||||
|
||||
/************************
|
||||
* Restricted Functions *
|
||||
************************/
|
||||
|
||||
/// @notice Update default fee config.
|
||||
/// @param _baseFees The amount of baseFees to update.
|
||||
/// @param _feesPerByte The amount of fees per byte to update.
|
||||
function updateDefaultFeeConfig(uint128 _baseFees, uint128 _feesPerByte) external onlyOwner {
|
||||
defaultFeeConfig = FeeConfig(_baseFees, _feesPerByte);
|
||||
|
||||
emit UpdateDefaultFeeConfig(_baseFees, _feesPerByte);
|
||||
}
|
||||
|
||||
/// @notice Update custom fee config for sender.
|
||||
/// @param _sender The address of sender to update custom FeeConfig.
|
||||
/// @param _baseFees The amount of baseFees to update.
|
||||
/// @param _feesPerByte The amount of fees per byte to update.
|
||||
function updateCustomFeeConfig(
|
||||
address _sender,
|
||||
uint128 _baseFees,
|
||||
uint128 _feesPerByte
|
||||
) external onlyOwner {
|
||||
customFeeConfig[_sender] = FeeConfig(_baseFees, _feesPerByte);
|
||||
hasCustomConfig[_sender] = true;
|
||||
|
||||
emit UpdateCustomFeeConfig(_sender, _baseFees, _feesPerByte);
|
||||
}
|
||||
}
|
||||
@@ -59,8 +59,7 @@ abstract contract L2GatewayTestBase is DSTestPlus {
|
||||
|
||||
// Initialize L2 contracts
|
||||
l2Messenger.initialize(address(l1Messenger), feeVault);
|
||||
l2MessageQueue.initialize();
|
||||
l2MessageQueue.updateMessenger(address(l2Messenger));
|
||||
l2MessageQueue.initialize(address(l2Messenger));
|
||||
l1GasOracle.updateWhitelist(address(whitelist));
|
||||
|
||||
address[] memory _accounts = new address[](1);
|
||||
|
||||
@@ -11,8 +11,7 @@ contract L2MessageQueueTest is DSTestPlus {
|
||||
|
||||
function setUp() public {
|
||||
queue = new L2MessageQueue(address(this));
|
||||
queue.initialize();
|
||||
queue.updateMessenger(address(this));
|
||||
queue.initialize(address(this));
|
||||
}
|
||||
|
||||
function testConstructor() external {
|
||||
|
||||
@@ -41,8 +41,7 @@ contract L2ScrollMessengerTest is DSTestPlus {
|
||||
|
||||
// Initialize L2 contracts
|
||||
l2Messenger.initialize(address(l1Messenger), feeVault);
|
||||
l2MessageQueue.initialize();
|
||||
l2MessageQueue.updateMessenger(address(l2Messenger));
|
||||
l2MessageQueue.initialize(address(l2Messenger));
|
||||
l1GasOracle.updateWhitelist(address(whitelist));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity =0.8.16;
|
||||
|
||||
import {DSTestPlus} from "solmate/test/utils/DSTestPlus.sol";
|
||||
import {WETH} from "solmate/tokens/WETH.sol";
|
||||
|
||||
import {SimpleGasOracle} from "../libraries/oracle/SimpleGasOracle.sol";
|
||||
|
||||
contract SimpleGasOracleTest is DSTestPlus {
|
||||
SimpleGasOracle private oracle;
|
||||
|
||||
function setUp() public {
|
||||
oracle = new SimpleGasOracle();
|
||||
oracle.initialize();
|
||||
}
|
||||
|
||||
function testUpdateDefaultFeeConfig(uint128 _baseFees, uint128 _feesPerByte) external {
|
||||
// call by non-owner, should revert
|
||||
hevm.startPrank(address(1));
|
||||
hevm.expectRevert("Ownable: caller is not the owner");
|
||||
oracle.updateDefaultFeeConfig(_baseFees, _feesPerByte);
|
||||
hevm.stopPrank();
|
||||
|
||||
// call by owner, should succeed
|
||||
oracle.updateDefaultFeeConfig(111, 3333); // random set some non-zero value first
|
||||
(uint128 __baseFees, uint128 __feesPerByte) = oracle.defaultFeeConfig();
|
||||
assertEq(__baseFees, 111);
|
||||
assertEq(__feesPerByte, 3333);
|
||||
oracle.updateDefaultFeeConfig(_baseFees, _feesPerByte);
|
||||
(__baseFees, __feesPerByte) = oracle.defaultFeeConfig();
|
||||
assertEq(__baseFees, _baseFees);
|
||||
assertEq(__feesPerByte, _feesPerByte);
|
||||
}
|
||||
|
||||
function testUpdateCustomFeeConfig(
|
||||
address _sender,
|
||||
uint128 _baseFees,
|
||||
uint128 _feesPerByte
|
||||
) external {
|
||||
// call by non-owner, should revert
|
||||
hevm.startPrank(address(1));
|
||||
hevm.expectRevert("Ownable: caller is not the owner");
|
||||
oracle.updateCustomFeeConfig(_sender, _baseFees, _feesPerByte);
|
||||
hevm.stopPrank();
|
||||
|
||||
// call by owner, should succeed
|
||||
(uint128 __baseFees, uint128 __feesPerByte) = oracle.customFeeConfig(_sender);
|
||||
assertEq(__baseFees, 0);
|
||||
assertEq(__feesPerByte, 0);
|
||||
assertBoolEq(oracle.hasCustomConfig(_sender), false);
|
||||
oracle.updateCustomFeeConfig(_sender, _baseFees, _feesPerByte);
|
||||
(__baseFees, __feesPerByte) = oracle.customFeeConfig(_sender);
|
||||
assertEq(__baseFees, _baseFees);
|
||||
assertEq(__feesPerByte, _feesPerByte);
|
||||
assertBoolEq(oracle.hasCustomConfig(_sender), true);
|
||||
}
|
||||
|
||||
function testEstimateMessageFee(
|
||||
address _sender,
|
||||
address,
|
||||
bytes memory _message
|
||||
) external {
|
||||
// use default config when no custom config
|
||||
oracle.updateDefaultFeeConfig(1, 2);
|
||||
assertEq(oracle.estimateMessageFee(_sender, address(0), _message, 0), 1 + 2 * _message.length);
|
||||
|
||||
// use custom config when set
|
||||
oracle.updateCustomFeeConfig(_sender, 4, 5);
|
||||
assertEq(oracle.estimateMessageFee(_sender, address(0), _message, 0), 4 + 5 * _message.length);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user