From 5886e760c11e0283844213f183adb80efc4dd06a Mon Sep 17 00:00:00 2001 From: Maurelian <23033765+maurelian@users.noreply.github.com> Date: Sat, 9 Jan 2021 11:30:08 -0500 Subject: [PATCH 1/3] Add nonReentrant to all public functions on CrossDomainMessengers --- .../OVM/bridge/OVM_BaseCrossDomainMessenger.sol | 3 ++- .../OVM/bridge/OVM_L1CrossDomainMessenger.sol | 4 ++++ .../OVM/bridge/OVM_L2CrossDomainMessenger.sol | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/contracts/optimistic-ethereum/OVM/bridge/OVM_BaseCrossDomainMessenger.sol b/contracts/optimistic-ethereum/OVM/bridge/OVM_BaseCrossDomainMessenger.sol index 372fde6e2..7c4730b4e 100644 --- a/contracts/optimistic-ethereum/OVM/bridge/OVM_BaseCrossDomainMessenger.sol +++ b/contracts/optimistic-ethereum/OVM/bridge/OVM_BaseCrossDomainMessenger.sol @@ -40,9 +40,10 @@ abstract contract OVM_BaseCrossDomainMessenger is iOVM_BaseCrossDomainMessenger, address _target, bytes memory _message, uint32 _gasLimit - ) nonReentrant + ) override public + nonReentrant { bytes memory xDomainCalldata = _getXDomainCalldata( _target, diff --git a/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol b/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol index b8988645b..f0c484fe0 100644 --- a/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol +++ b/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol @@ -7,6 +7,7 @@ import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol"; import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol"; import { Lib_AddressManager } from "../../libraries/resolver/Lib_AddressManager.sol"; import { Lib_SecureMerkleTrie } from "../../libraries/trie/Lib_SecureMerkleTrie.sol"; +import { Lib_ReentrancyGuard } from "../../libraries/utils/Lib_ReentrancyGuard.sol"; /* Interface Imports */ import { iOVM_L1CrossDomainMessenger } from "../../iOVM/bridge/iOVM_L1CrossDomainMessenger.sol"; @@ -18,6 +19,7 @@ import { OVM_BaseCrossDomainMessenger } from "./OVM_BaseCrossDomainMessenger.sol /** * @title OVM_L1CrossDomainMessenger + * @dev This contract lives on L1. It sends messages to L2, and relays them from L2 */ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCrossDomainMessenger, Lib_AddressResolver { @@ -81,6 +83,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros ) override public + nonReentrant onlyRelayer() { bytes memory xDomainCalldata = _getXDomainCalldata( @@ -140,6 +143,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros ) override public + nonReentrant { bytes memory xDomainCalldata = _getXDomainCalldata( _target, diff --git a/contracts/optimistic-ethereum/OVM/bridge/OVM_L2CrossDomainMessenger.sol b/contracts/optimistic-ethereum/OVM/bridge/OVM_L2CrossDomainMessenger.sol index 39b1db236..cfed88754 100644 --- a/contracts/optimistic-ethereum/OVM/bridge/OVM_L2CrossDomainMessenger.sol +++ b/contracts/optimistic-ethereum/OVM/bridge/OVM_L2CrossDomainMessenger.sol @@ -5,6 +5,7 @@ pragma experimental ABIEncoderV2; /* Library Imports */ import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol"; +import { Lib_ReentrancyGuard } from "../../libraries/utils/Lib_ReentrancyGuard.sol"; /* Interface Imports */ import { iOVM_L2CrossDomainMessenger } from "../../iOVM/bridge/iOVM_L2CrossDomainMessenger.sol"; @@ -17,6 +18,7 @@ import { OVM_BaseCrossDomainMessenger } from "./OVM_BaseCrossDomainMessenger.sol /** * @title OVM_L2CrossDomainMessenger * @dev L2 CONTRACT (COMPILED) + * This contract lives on L2. It sends messages to L1, and relays them from L1 */ contract OVM_L2CrossDomainMessenger is iOVM_L2CrossDomainMessenger, OVM_BaseCrossDomainMessenger, Lib_AddressResolver { @@ -50,6 +52,7 @@ contract OVM_L2CrossDomainMessenger is iOVM_L2CrossDomainMessenger, OVM_BaseCros uint256 _messageNonce ) override + nonReentrant public { require( From 25925e28a8f74c0a900501fdcddc3c03d39e088f Mon Sep 17 00:00:00 2001 From: Maurelian <23033765+maurelian@users.noreply.github.com> Date: Mon, 11 Jan 2021 19:38:09 -0500 Subject: [PATCH 2/3] Improve contract description comments Co-authored-by: ben-chain --- .../OVM/bridge/OVM_L1CrossDomainMessenger.sol | 2 +- .../OVM/bridge/OVM_L2CrossDomainMessenger.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol b/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol index f0c484fe0..36d0db3f2 100644 --- a/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol +++ b/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol @@ -19,7 +19,7 @@ import { OVM_BaseCrossDomainMessenger } from "./OVM_BaseCrossDomainMessenger.sol /** * @title OVM_L1CrossDomainMessenger - * @dev This contract lives on L1. It sends messages to L2, and relays them from L2 + * @dev This contract lives on L1. It sends L1->L2 messages into L2, and relays L2->L1 messages from L2 to their target on L1. */ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCrossDomainMessenger, Lib_AddressResolver { diff --git a/contracts/optimistic-ethereum/OVM/bridge/OVM_L2CrossDomainMessenger.sol b/contracts/optimistic-ethereum/OVM/bridge/OVM_L2CrossDomainMessenger.sol index cfed88754..3ce1dc112 100644 --- a/contracts/optimistic-ethereum/OVM/bridge/OVM_L2CrossDomainMessenger.sol +++ b/contracts/optimistic-ethereum/OVM/bridge/OVM_L2CrossDomainMessenger.sol @@ -18,7 +18,7 @@ import { OVM_BaseCrossDomainMessenger } from "./OVM_BaseCrossDomainMessenger.sol /** * @title OVM_L2CrossDomainMessenger * @dev L2 CONTRACT (COMPILED) - * This contract lives on L2. It sends messages to L1, and relays them from L1 + * This contract lives on L2. It sends messages to L1, and relays them from L1. */ contract OVM_L2CrossDomainMessenger is iOVM_L2CrossDomainMessenger, OVM_BaseCrossDomainMessenger, Lib_AddressResolver { From a3e3f56d4795ad229129729a7276b388cebc3c40 Mon Sep 17 00:00:00 2001 From: Maurelian <23033765+maurelian@users.noreply.github.com> Date: Mon, 11 Jan 2021 20:10:31 -0500 Subject: [PATCH 3/3] remove extraneous modifier --- .../OVM/bridge/OVM_BaseCrossDomainMessenger.sol | 1 - .../OVM/bridge/OVM_L1CrossDomainMessenger.sol | 1 - 2 files changed, 2 deletions(-) diff --git a/contracts/optimistic-ethereum/OVM/bridge/OVM_BaseCrossDomainMessenger.sol b/contracts/optimistic-ethereum/OVM/bridge/OVM_BaseCrossDomainMessenger.sol index 7c4730b4e..5a0e99d62 100644 --- a/contracts/optimistic-ethereum/OVM/bridge/OVM_BaseCrossDomainMessenger.sol +++ b/contracts/optimistic-ethereum/OVM/bridge/OVM_BaseCrossDomainMessenger.sol @@ -43,7 +43,6 @@ abstract contract OVM_BaseCrossDomainMessenger is iOVM_BaseCrossDomainMessenger, ) override public - nonReentrant { bytes memory xDomainCalldata = _getXDomainCalldata( _target, diff --git a/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol b/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol index 36d0db3f2..e6912ef84 100644 --- a/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol +++ b/contracts/optimistic-ethereum/OVM/bridge/OVM_L1CrossDomainMessenger.sol @@ -143,7 +143,6 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros ) override public - nonReentrant { bytes memory xDomainCalldata = _getXDomainCalldata( _target,