-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat[contracts]: Add block/allow and pausing to the L1 Messenger #579
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
Changes from all commits
eeeb65f
5f995e6
c5a6097
a95094f
90299b5
bb7e87a
e9e29cc
b167e62
6084267
78246e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@eth-optimism/contracts": patch | ||
| --- | ||
|
|
||
| Add pause(), blockMessage() and allowMessage() to L1 messenger |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,11 @@ import { iOVM_StateCommitmentChain } from "../../../iOVM/chain/iOVM_StateCommitm | |
| /* Contract Imports */ | ||
| import { Abs_BaseCrossDomainMessenger } from "./Abs_BaseCrossDomainMessenger.sol"; | ||
|
|
||
| /* External Imports */ | ||
| import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
| import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; | ||
| import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; | ||
|
|
||
| /** | ||
| * @title OVM_L1CrossDomainMessenger | ||
| * @dev The L1 Cross Domain Messenger contract sends messages from L1 to L2, and relays messages | ||
|
|
@@ -25,20 +30,46 @@ import { Abs_BaseCrossDomainMessenger } from "./Abs_BaseCrossDomainMessenger.sol | |
| * Compiler used: solc | ||
| * Runtime target: EVM | ||
| */ | ||
| contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, Abs_BaseCrossDomainMessenger, Lib_AddressResolver { | ||
| contract OVM_L1CrossDomainMessenger is | ||
| iOVM_L1CrossDomainMessenger, | ||
| Abs_BaseCrossDomainMessenger, | ||
| Lib_AddressResolver, | ||
| OwnableUpgradeable, | ||
| PausableUpgradeable, | ||
| ReentrancyGuardUpgradeable | ||
| { | ||
|
|
||
| /********** | ||
| * Events * | ||
| **********/ | ||
|
|
||
| event MessageBlocked( | ||
| bytes32 indexed _xDomainCalldataHash | ||
| ); | ||
|
|
||
| event MessageAllowed( | ||
| bytes32 indexed _xDomainCalldataHash | ||
| ); | ||
|
|
||
| /********************** | ||
| * Contract Variables * | ||
| **********************/ | ||
|
|
||
| mapping (bytes32 => bool) public blockedMessages; | ||
|
|
||
| /*************** | ||
| * Constructor * | ||
| ***************/ | ||
|
|
||
| /** | ||
| * Pass a default zero address to the address resolver. This will be updated when initialized. | ||
| * This contract is intended to be behind a delegate proxy. | ||
| * We pass the zero address to the address resolver just to satisfy the constructor. | ||
| * We still need to set this value in initialize(). | ||
| */ | ||
| constructor() | ||
| Lib_AddressResolver(address(0)) | ||
| {} | ||
|
|
||
|
|
||
| /********************** | ||
| * Function Modifiers * | ||
| **********************/ | ||
|
|
@@ -70,14 +101,58 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, Abs_BaseCros | |
| address _libAddressManager | ||
| ) | ||
| public | ||
| initializer | ||
| { | ||
| require( | ||
| address(libAddressManager) == address(0), | ||
| "L1CrossDomainMessenger already intialized." | ||
| ); | ||
|
|
||
| libAddressManager = Lib_AddressManager(_libAddressManager); | ||
| xDomainMsgSender = DEFAULT_XDOMAIN_SENDER; | ||
|
|
||
| // Initialize upgradable OZ contracts | ||
| __Context_init_unchained(); // Context is a dependency for both Ownable and Pausable | ||
| __Ownable_init_unchained(); | ||
| __Pausable_init_unchained(); | ||
| __ReentrancyGuard_init_unchained(); | ||
| } | ||
|
|
||
| /** | ||
| * Pause relaying. | ||
| */ | ||
| function pause() | ||
| external | ||
| onlyOwner | ||
| { | ||
| _pause(); | ||
maurelian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Block a message. | ||
| * @param _xDomainCalldataHash Hash of the message to block. | ||
| */ | ||
| function blockMessage( | ||
maurelian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| bytes32 _xDomainCalldataHash | ||
| ) | ||
| external | ||
| onlyOwner | ||
| { | ||
| blockedMessages[_xDomainCalldataHash] = true; | ||
| emit MessageBlocked(_xDomainCalldataHash); | ||
| } | ||
|
|
||
| /** | ||
| * Allow a message. | ||
| * @param _xDomainCalldataHash Hash of the message to block. | ||
| */ | ||
| function allowMessage( | ||
| bytes32 _xDomainCalldataHash | ||
| ) | ||
| external | ||
| onlyOwner | ||
| { | ||
| blockedMessages[_xDomainCalldataHash] = false; | ||
|
||
| emit MessageAllowed(_xDomainCalldataHash); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -94,7 +169,8 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, Abs_BaseCros | |
| override | ||
| public | ||
| nonReentrant | ||
| onlyRelayer() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked elsewhere: using brackets on modifiers with no args was inconsistent with other parts of the code. |
||
| onlyRelayer | ||
| whenNotPaused | ||
maurelian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| bytes memory xDomainCalldata = _getXDomainCalldata( | ||
| _target, | ||
|
|
@@ -118,6 +194,11 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, Abs_BaseCros | |
| "Provided message has already been received." | ||
| ); | ||
|
|
||
| require( | ||
| blockedMessages[xDomainCalldataHash] == false, | ||
maurelian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "Provided message has been blocked." | ||
| ); | ||
|
|
||
| xDomainMsgSender = _sender; | ||
| (bool success, ) = _target.call(_message); | ||
| xDomainMsgSender = DEFAULT_XDOMAIN_SENDER; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt like this comment was slightly misleading, as the constructor is setting nothing in the proxy.