diff --git a/contracts/contracts/opl/Enclave.sol b/contracts/contracts/opl/Enclave.sol index 30235a45..c6913ff7 100644 --- a/contracts/contracts/opl/Enclave.sol +++ b/contracts/contracts/opl/Enclave.sol @@ -1,37 +1,14 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; -import {ERC2771Context} from "@openzeppelin/contracts/metatx/ERC2771Context.sol"; -import {Context} from "@openzeppelin/contracts/utils/Context.sol"; - import {Endpoint} from "./Endpoint.sol"; /** * @title OPL Enclave * @dev The Sapphire-side of an OPL dapp. */ -contract Enclave is Endpoint, ERC2771Context { +contract Enclave is Endpoint { constructor(address _host, bytes32 _hostChain) Endpoint(_host, _hostChain) - ERC2771Context(block.chainid == 0x5aff ? address(0) : address(0)) // TODO: insert gsn deployment {} // solhint-disable-line no-empty-blocks - - // The following functions are overrides required by Solidity. - function _msgData() - internal - view - override(Context, ERC2771Context) - returns (bytes calldata) - { - return ERC2771Context._msgData(); - } - - function _msgSender() - internal - view - override(Context, ERC2771Context) - returns (address) - { - return ERC2771Context._msgSender(); - } } diff --git a/contracts/contracts/opl/Endpoint.sol b/contracts/contracts/opl/Endpoint.sol index dad51aeb..3232af77 100644 --- a/contracts/contracts/opl/Endpoint.sol +++ b/contracts/contracts/opl/Endpoint.sol @@ -5,12 +5,6 @@ import {Context} from "@openzeppelin/contracts/utils/Context.sol"; /// Unable to automatically configure OPL. Please use the manual version of the base contract. error AutoConfigUnavailable(); -/// The method can only be called by the message bus; -error NotMessageBus(); -/// Messages may only be sent by the remote endpoint (Enclave or Host). -error NotRemoteEndpoint(); -/// This message arrived too early or late. -error WrongSeqNum(uint256 expected, uint256 got); /// The remote endpoint's contract address was missing. error MissingRemoteAddr(); /// The remote endpoint's chain ID was missing. @@ -19,8 +13,6 @@ error MissingRemoteChainId(); error SelfCallDisallowed(); /// The requested endpoint does not exist. error UnknownEndpoint(); -/// Receiving endpoint did not return successfully. -error ReceiverError(); /// The outcome of the message call. enum Result { @@ -105,7 +97,8 @@ contract BaseEndpoint is Context { envelope, address(this) // executor ); - if (celerStatus != 1) revert ReceiverError(); + // Receiving endpoint did not return successfully. + require(celerStatus == 1, "ReceiverError"); if (fee > 0) payable(0).transfer(fee); // burn the fee, for fidelity } else { ICelerMessageBus(messageBus).sendMessage{value: fee}( @@ -125,14 +118,19 @@ contract BaseEndpoint is Context { bytes calldata _message, address // executor ) external payable returns (uint256) { - if (msg.sender != messageBus) revert NotMessageBus(); - if (_sender != remote || _senderChainId != remoteChainId) - revert NotRemoteEndpoint(); + // The method can only be called by the message bus; + require(_msgSender() == messageBus, "NotMessageBus"); + // Messages may only be sent by the remote endpoint (Enclave or Host). + require( + _sender == remote && _senderChainId == remoteChainId, + "NotRemoteEndpoint" + ); bytes4 epSel = bytes4(_message[:4]); uint256 seq = uint256(bytes32(_message[4:36])); bytes calldata message = _message[36:]; if (inOrder) { - if (seq != rxSeq) revert WrongSeqNum(rxSeq, seq); + // This message arrived too early or late. + require(seq == rxSeq, "WrongSeqNum"); ++rxSeq; } function(bytes calldata) returns (Result) ep = endpoints[epSel];