Skip to content

Commit

Permalink
Merge pull request #234 from oasisprotocol/CedarMist/opl/use-require
Browse files Browse the repository at this point in the history
contracts: remove custom reverts and ERC2771Context
  • Loading branch information
CedarMist authored Dec 6, 2023
2 parents 1d0fdee + af31d8d commit 7c4fe94
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
25 changes: 1 addition & 24 deletions contracts/contracts/opl/Enclave.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
24 changes: 11 additions & 13 deletions contracts/contracts/opl/Endpoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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}(
Expand All @@ -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];
Expand Down

0 comments on commit 7c4fe94

Please sign in to comment.