Skip to content

Commit

Permalink
refactor: add address(0) check for constructors. (#1010)
Browse files Browse the repository at this point in the history
Co-authored-by: Péter Garamvölgyi <[email protected]>
Co-authored-by: HAOYUatHZ <[email protected]>
  • Loading branch information
3 people authored Dec 11, 2023
1 parent 566fb23 commit bf2692b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions contracts/src/L1/L1ScrollMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ contract L1ScrollMessenger is ScrollMessengerBase, IL1ScrollMessenger {
address _rollup,
address _messageQueue
) public initializer {
if (_counterpart == address(0) || _rollup == address(0) || _messageQueue == address(0)) {
revert ErrZeroAddress();
}
ScrollMessengerBase.__ScrollMessengerBase_init(_counterpart, _feeVault);

rollup = _rollup;
Expand Down
3 changes: 3 additions & 0 deletions contracts/src/L2/L2ScrollMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ contract L2ScrollMessenger is ScrollMessengerBase, IL2ScrollMessenger {
***************/

constructor(address _messageQueue) {
if (_messageQueue == address(0)) revert ErrZeroAddress();

_disableInitializers();

messageQueue = _messageQueue;
}

function initialize(address _counterpart) external initializer {
if (_counterpart == address(0)) revert ErrZeroAddress();
ScrollMessengerBase.__ScrollMessengerBase_init(_counterpart, address(0));
}

Expand Down
5 changes: 5 additions & 0 deletions contracts/src/libraries/IScrollMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
pragma solidity ^0.8.16;

interface IScrollMessenger {
/***********
* Errors *
***********/
error ErrZeroAddress();

/**********
* Events *
**********/
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/test/L1GatewayTestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ abstract contract L1GatewayTestBase is DSTestPlus {
verifier = new MockRollupVerifier();

// Deploy L2 contracts
l2Messenger = new L2ScrollMessenger(address(0));
l2Messenger = new L2ScrollMessenger(address(1));

// Initialize L1 contracts
l1Messenger.initialize(address(l2Messenger), feeVault, address(rollup), address(messageQueue));
Expand Down

0 comments on commit bf2692b

Please sign in to comment.