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

fix(contracts): OZ-L2-L06 Initialization Performed Outside of Initialization Function #652

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions contracts/scripts/foundry/InitializeL2BridgeContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 8 additions & 22 deletions contracts/src/L2/predeploys/L2MessageQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
*************/
Expand All @@ -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;
}

/*****************************
Expand All @@ -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);
}
}
3 changes: 1 addition & 2 deletions contracts/src/test/L2GatewayTestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions contracts/src/test/L2MessageQueue.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions contracts/src/test/L2ScrollMessenger.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down