Commit 7bfe391c authored by smartcontracts's avatar smartcontracts Committed by GitHub

style[contracts]: Various minor stylistic improvements (#574)

* style[contracts]: Various minor stylistic improvements

* style[contracts]: Another few tweaks
parent fc730148
...@@ -10,26 +10,28 @@ import { Lib_ReentrancyGuard } from "../../../libraries/utils/Lib_ReentrancyGuar ...@@ -10,26 +10,28 @@ import { Lib_ReentrancyGuard } from "../../../libraries/utils/Lib_ReentrancyGuar
/** /**
* @title Abs_BaseCrossDomainMessenger * @title Abs_BaseCrossDomainMessenger
* @dev The Base Cross Domain Messenger is an abstract contract providing the interface and common functionality used in the * @dev The Base Cross Domain Messenger is an abstract contract providing the interface and common
* L1 and L2 Cross Domain Messengers. It can also serve as a template for developers wishing to implement a custom bridge * functionality used in the L1 and L2 Cross Domain Messengers. It can also serve as a template for
* contract to suit their needs. * developers wishing to implement a custom bridge contract to suit their needs.
* *
* Compiler used: defined by child contract * Compiler used: defined by child contract
* Runtime target: defined by child contract * Runtime target: defined by child contract
*/ */
abstract contract Abs_BaseCrossDomainMessenger is iAbs_BaseCrossDomainMessenger, Lib_ReentrancyGuard { abstract contract Abs_BaseCrossDomainMessenger is iAbs_BaseCrossDomainMessenger, Lib_ReentrancyGuard {
/**************
* Constants * /*************
**************/ * Constants *
*************/
// The default x-domain message sender being set to a non-zero value makes // The default x-domain message sender being set to a non-zero value makes
// deployment a bit more expensive, but in exchange the refund on every call to // deployment a bit more expensive, but in exchange the refund on every call to
// `relayMessage` by the L1 and L2 messengers will be higher. // `relayMessage` by the L1 and L2 messengers will be higher.
address internal constant DEFAULT_XDOMAIN_SENDER = 0x000000000000000000000000000000000000dEaD; address internal constant DEFAULT_XDOMAIN_SENDER = 0x000000000000000000000000000000000000dEaD;
/**********************
* Contract Variables * /*************
**********************/ * Variables *
*************/
mapping (bytes32 => bool) public relayedMessages; mapping (bytes32 => bool) public relayedMessages;
mapping (bytes32 => bool) public successfulMessages; mapping (bytes32 => bool) public successfulMessages;
...@@ -37,13 +39,26 @@ abstract contract Abs_BaseCrossDomainMessenger is iAbs_BaseCrossDomainMessenger, ...@@ -37,13 +39,26 @@ abstract contract Abs_BaseCrossDomainMessenger is iAbs_BaseCrossDomainMessenger,
uint256 public messageNonce; uint256 public messageNonce;
address internal xDomainMsgSender = DEFAULT_XDOMAIN_SENDER; address internal xDomainMsgSender = DEFAULT_XDOMAIN_SENDER;
/***************
* Constructor *
***************/
constructor() Lib_ReentrancyGuard() {}
/******************** /********************
* Public Functions * * Public Functions *
********************/ ********************/
constructor() Lib_ReentrancyGuard() {} function xDomainMessageSender()
public
function xDomainMessageSender() public override view returns (address) { override
view
returns (
address
)
{
require(xDomainMsgSender != DEFAULT_XDOMAIN_SENDER, "xDomainMessageSender is not set"); require(xDomainMsgSender != DEFAULT_XDOMAIN_SENDER, "xDomainMessageSender is not set");
return xDomainMsgSender; return xDomainMsgSender;
} }
...@@ -76,6 +91,7 @@ abstract contract Abs_BaseCrossDomainMessenger is iAbs_BaseCrossDomainMessenger, ...@@ -76,6 +91,7 @@ abstract contract Abs_BaseCrossDomainMessenger is iAbs_BaseCrossDomainMessenger,
emit SentMessage(xDomainCalldata); emit SentMessage(xDomainCalldata);
} }
/********************** /**********************
* Internal Functions * * Internal Functions *
**********************/ **********************/
......
...@@ -19,9 +19,9 @@ import { Abs_BaseCrossDomainMessenger } from "./Abs_BaseCrossDomainMessenger.sol ...@@ -19,9 +19,9 @@ import { Abs_BaseCrossDomainMessenger } from "./Abs_BaseCrossDomainMessenger.sol
/** /**
* @title OVM_L1CrossDomainMessenger * @title OVM_L1CrossDomainMessenger
* @dev The L1 Cross Domain Messenger contract sends messages from L1 to L2, and relays messages from L2 onto L1. * @dev The L1 Cross Domain Messenger contract sends messages from L1 to L2, and relays messages
* In the event that a message sent from L1 to L2 is rejected for exceeding the L2 epoch gas limit, it can be resubmitted * from L2 onto L1. In the event that a message sent from L1 to L2 is rejected for exceeding the L2
* via this contract's replay function. * epoch gas limit, it can be resubmitted via this contract's replay function.
* *
* Compiler used: solc * Compiler used: solc
* Runtime target: EVM * Runtime target: EVM
...@@ -39,26 +39,14 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, Abs_BaseCros ...@@ -39,26 +39,14 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, Abs_BaseCros
Lib_AddressResolver(address(0)) Lib_AddressResolver(address(0))
{} {}
/**
* @param _libAddressManager Address of the Address Manager.
*/
function initialize(
address _libAddressManager
)
public
{
require(address(libAddressManager) == address(0), "L1CrossDomainMessenger already intialized.");
libAddressManager = Lib_AddressManager(_libAddressManager);
xDomainMsgSender = DEFAULT_XDOMAIN_SENDER;
}
/********************** /**********************
* Function Modifiers * * Function Modifiers *
**********************/ **********************/
/** /**
* Modifier to enforce that, if configured, only the OVM_L2MessageRelayer contract may successfully call a method. * Modifier to enforce that, if configured, only the OVM_L2MessageRelayer contract may
* successfully call a method.
*/ */
modifier onlyRelayer() { modifier onlyRelayer() {
address relayer = resolve("OVM_L2MessageRelayer"); address relayer = resolve("OVM_L2MessageRelayer");
...@@ -76,6 +64,23 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, Abs_BaseCros ...@@ -76,6 +64,23 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, Abs_BaseCros
* Public Functions * * Public Functions *
********************/ ********************/
/**
* @param _libAddressManager Address of the Address Manager.
*/
function initialize(
address _libAddressManager
)
public
{
require(
address(libAddressManager) == address(0),
"L1CrossDomainMessenger already intialized."
);
libAddressManager = Lib_AddressManager(_libAddressManager);
xDomainMsgSender = DEFAULT_XDOMAIN_SENDER;
}
/** /**
* Relays a cross domain message to a contract. * Relays a cross domain message to a contract.
* @inheritdoc iOVM_L1CrossDomainMessenger * @inheritdoc iOVM_L1CrossDomainMessenger
...@@ -207,7 +212,9 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, Abs_BaseCros ...@@ -207,7 +212,9 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, Abs_BaseCros
bool bool
) )
{ {
iOVM_StateCommitmentChain ovmStateCommitmentChain = iOVM_StateCommitmentChain(resolve("OVM_StateCommitmentChain")); iOVM_StateCommitmentChain ovmStateCommitmentChain = iOVM_StateCommitmentChain(
resolve("OVM_StateCommitmentChain")
);
return ( return (
ovmStateCommitmentChain.insideFraudProofWindow(_proof.stateRootBatchHeader) == false ovmStateCommitmentChain.insideFraudProofWindow(_proof.stateRootBatchHeader) == false
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
// @unsupported: ovm // @unsupported: ovm
pragma solidity >0.5.0 <0.8.0; pragma solidity >0.5.0 <0.8.0;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
/* Interface Imports */ /* Interface Imports */
import { iOVM_L1CrossDomainMessenger } from "../../../iOVM/bridge/messaging/iOVM_L1CrossDomainMessenger.sol"; import { iOVM_L1CrossDomainMessenger } from "../../../iOVM/bridge/messaging/iOVM_L1CrossDomainMessenger.sol";
import { iOVM_L1MultiMessageRelayer } from "../../../iOVM/bridge/messaging/iOVM_L1MultiMessageRelayer.sol"; import { iOVM_L1MultiMessageRelayer } from "../../../iOVM/bridge/messaging/iOVM_L1MultiMessageRelayer.sol";
/* Contract Imports */ /* Library Imports */
import { Lib_AddressResolver } from "../../../libraries/resolver/Lib_AddressResolver.sol"; import { Lib_AddressResolver } from "../../../libraries/resolver/Lib_AddressResolver.sol";
/** /**
* @title OVM_L1MultiMessageRelayer * @title OVM_L1MultiMessageRelayer
* @dev The L1 Multi-Message Relayer contract is a gas efficiency optimization which enables the * @dev The L1 Multi-Message Relayer contract is a gas efficiency optimization which enables the
...@@ -24,12 +24,17 @@ contract OVM_L1MultiMessageRelayer is iOVM_L1MultiMessageRelayer, Lib_AddressRes ...@@ -24,12 +24,17 @@ contract OVM_L1MultiMessageRelayer is iOVM_L1MultiMessageRelayer, Lib_AddressRes
/*************** /***************
* Constructor * * Constructor *
***************/ ***************/
/**
* @param _libAddressManager Address of the Address Manager.
*/
constructor( constructor(
address _libAddressManager address _libAddressManager
) )
Lib_AddressResolver(_libAddressManager) Lib_AddressResolver(_libAddressManager)
{} {}
/********************** /**********************
* Function Modifiers * * Function Modifiers *
**********************/ **********************/
...@@ -42,6 +47,7 @@ contract OVM_L1MultiMessageRelayer is iOVM_L1MultiMessageRelayer, Lib_AddressRes ...@@ -42,6 +47,7 @@ contract OVM_L1MultiMessageRelayer is iOVM_L1MultiMessageRelayer, Lib_AddressRes
_; _;
} }
/******************** /********************
* Public Functions * * Public Functions *
********************/ ********************/
...@@ -50,12 +56,17 @@ contract OVM_L1MultiMessageRelayer is iOVM_L1MultiMessageRelayer, Lib_AddressRes ...@@ -50,12 +56,17 @@ contract OVM_L1MultiMessageRelayer is iOVM_L1MultiMessageRelayer, Lib_AddressRes
* @notice Forwards multiple cross domain messages to the L1 Cross Domain Messenger for relaying * @notice Forwards multiple cross domain messages to the L1 Cross Domain Messenger for relaying
* @param _messages An array of L2 to L1 messages * @param _messages An array of L2 to L1 messages
*/ */
function batchRelayMessages(L2ToL1Message[] calldata _messages) function batchRelayMessages(
L2ToL1Message[] calldata _messages
)
override override
external external
onlyBatchRelayer onlyBatchRelayer
{ {
iOVM_L1CrossDomainMessenger messenger = iOVM_L1CrossDomainMessenger(resolve("Proxy__OVM_L1CrossDomainMessenger")); iOVM_L1CrossDomainMessenger messenger = iOVM_L1CrossDomainMessenger(
resolve("Proxy__OVM_L1CrossDomainMessenger")
);
for (uint256 i = 0; i < _messages.length; i++) { for (uint256 i = 0; i < _messages.length; i++) {
L2ToL1Message memory message = _messages[i]; L2ToL1Message memory message = _messages[i];
messenger.relayMessage( messenger.relayMessage(
......
...@@ -14,7 +14,6 @@ import { iOVM_L2ToL1MessagePasser } from "../../../iOVM/predeploys/iOVM_L2ToL1Me ...@@ -14,7 +14,6 @@ import { iOVM_L2ToL1MessagePasser } from "../../../iOVM/predeploys/iOVM_L2ToL1Me
/* Contract Imports */ /* Contract Imports */
import { Abs_BaseCrossDomainMessenger } from "./Abs_BaseCrossDomainMessenger.sol"; import { Abs_BaseCrossDomainMessenger } from "./Abs_BaseCrossDomainMessenger.sol";
/** /**
* @title OVM_L2CrossDomainMessenger * @title OVM_L2CrossDomainMessenger
* @dev The L2 Cross Domain Messenger contract sends messages from L2 to L1, and is the entry point * @dev The L2 Cross Domain Messenger contract sends messages from L2 to L1, and is the entry point
...@@ -126,7 +125,9 @@ contract OVM_L2CrossDomainMessenger is iOVM_L2CrossDomainMessenger, Abs_BaseCros ...@@ -126,7 +125,9 @@ contract OVM_L2CrossDomainMessenger is iOVM_L2CrossDomainMessenger, Abs_BaseCros
) )
{ {
return ( return (
iOVM_L1MessageSender(resolve("OVM_L1MessageSender")).getL1MessageSender() == resolve("OVM_L1CrossDomainMessenger") iOVM_L1MessageSender(
resolve("OVM_L1MessageSender")
).getL1MessageSender() == resolve("OVM_L1CrossDomainMessenger")
); );
} }
......
...@@ -16,7 +16,6 @@ import { iOVM_ChainStorageContainer } from "../../iOVM/chain/iOVM_ChainStorageCo ...@@ -16,7 +16,6 @@ import { iOVM_ChainStorageContainer } from "../../iOVM/chain/iOVM_ChainStorageCo
/* Contract Imports */ /* Contract Imports */
import { OVM_ExecutionManager } from "../execution/OVM_ExecutionManager.sol"; import { OVM_ExecutionManager } from "../execution/OVM_ExecutionManager.sol";
/** /**
* @title OVM_CanonicalTransactionChain * @title OVM_CanonicalTransactionChain
* @dev The Canonical Transaction Chain (CTC) contract is an append-only log of transactions * @dev The Canonical Transaction Chain (CTC) contract is an append-only log of transactions
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.8.0; pragma solidity >0.5.0 <0.8.0;
/* Interface Imports */ /* Interface Imports */
import { iAbs_BaseCrossDomainMessenger } from "../../iOVM/bridge/messaging/iAbs_BaseCrossDomainMessenger.sol"; import { iAbs_BaseCrossDomainMessenger } from "../../iOVM/bridge/messaging/iAbs_BaseCrossDomainMessenger.sol";
...@@ -11,25 +12,37 @@ import { iAbs_BaseCrossDomainMessenger } from "../../iOVM/bridge/messaging/iAbs_ ...@@ -11,25 +12,37 @@ import { iAbs_BaseCrossDomainMessenger } from "../../iOVM/bridge/messaging/iAbs_
* Runtime target: defined by inheriting contract * Runtime target: defined by inheriting contract
*/ */
contract OVM_CrossDomainEnabled { contract OVM_CrossDomainEnabled {
/*************
* Variables *
*************/
// Messenger contract used to send and recieve messages from the other domain. // Messenger contract used to send and recieve messages from the other domain.
address public messenger; address public messenger;
/*************** /***************
* Constructor * * Constructor *
***************/ ***************/
/**
* @param _messenger Address of the CrossDomainMessenger on the current layer.
*/
constructor( constructor(
address _messenger address _messenger
) { ) {
messenger = _messenger; messenger = _messenger;
} }
/********************** /**********************
* Function Modifiers * * Function Modifiers *
**********************/ **********************/
/** /**
* @notice Enforces that the modified function is only callable by a specific cross-domain account. * Enforces that the modified function is only callable by a specific cross-domain account.
* @param _sourceDomainAccount The only account on the originating domain which is authenticated to call this function. * @param _sourceDomainAccount The only account on the originating domain which is
* authenticated to call this function.
*/ */
modifier onlyFromCrossDomainAccount( modifier onlyFromCrossDomainAccount(
address _sourceDomainAccount address _sourceDomainAccount
...@@ -47,18 +60,20 @@ contract OVM_CrossDomainEnabled { ...@@ -47,18 +60,20 @@ contract OVM_CrossDomainEnabled {
_; _;
} }
/********************** /**********************
* Internal Functions * * Internal Functions *
**********************/ **********************/
/** /**
* @notice Gets the messenger, usually from storage. This function is exposed in case a child contract needs to override. * Gets the messenger, usually from storage. This function is exposed in case a child contract
* @return The address of the cross-domain messenger contract which should be used. * needs to override.
* @return The address of the cross-domain messenger contract which should be used.
*/ */
function getCrossDomainMessenger() function getCrossDomainMessenger()
internal internal
virtual virtual
returns( returns (
iAbs_BaseCrossDomainMessenger iAbs_BaseCrossDomainMessenger
) )
{ {
...@@ -66,16 +81,19 @@ contract OVM_CrossDomainEnabled { ...@@ -66,16 +81,19 @@ contract OVM_CrossDomainEnabled {
} }
/** /**
* @notice Sends a message to an account on another domain * Sends a message to an account on another domain
* @param _crossDomainTarget The intended recipient on the destination domain * @param _crossDomainTarget The intended recipient on the destination domain
* @param _data The data to send to the target (usually calldata to a function with `onlyFromCrossDomainAccount()`) * @param _data The data to send to the target (usually calldata to a function with
* `onlyFromCrossDomainAccount()`)
* @param _gasLimit The gasLimit for the receipt of the message on the target domain. * @param _gasLimit The gasLimit for the receipt of the message on the target domain.
*/ */
function sendCrossDomainMessage( function sendCrossDomainMessage(
address _crossDomainTarget, address _crossDomainTarget,
bytes memory _data, bytes memory _data,
uint32 _gasLimit uint32 _gasLimit
) internal { )
internal
{
getCrossDomainMessenger().sendMessage(_crossDomainTarget, _data, _gasLimit); getCrossDomainMessenger().sendMessage(_crossDomainTarget, _data, _gasLimit);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment