Skip to content

Instantly share code, notes, and snippets.

@tyler-smith
Last active November 6, 2024 05:19
Show Gist options
  • Save tyler-smith/aca1516bc70964f226f44942be136f21 to your computer and use it in GitHub Desktop.
Save tyler-smith/aca1516bc70964f226f44942be136f21 to your computer and use it in GitHub Desktop.
Interop Relayer hackathon notes

OP Interop Relayer

Contract Interface

    /// @notice Emitted whenever a message is sent to a destination
    /// @param destination  Chain ID of the destination chain.
    /// @param target       Target contract or wallet address.
    /// @param messageNonce Nonce associated with the messsage sent
    /// @param sender       Address initiating this message call
    /// @param message      Message payload to call target with.
    event SentMessage(
        uint256 indexed destination, address indexed target, uint256 indexed messageNonce, address sender, bytes message
    );

    /// @notice Emitted whenever a message is successfully relayed on this chain.
    /// @param source       Chain ID of the source chain.
    /// @param messageNonce Nonce associated with the messsage sent
    /// @param messageHash  Hash of the message that was relayed.
    event RelayedMessage(uint256 indexed source, uint256 indexed messageNonce, bytes32 indexed messageHash);
    
    /// @notice Sends a message to some target address on a destination chain. Note that if the call
    ///         always reverts, then the message will be unrelayable, and any ETH sent will be
    ///         permanently locked. The same will occur if the target on the other chain is
    ///         considered unsafe (see the _isUnsafeTarget() function).
    /// @param _destination Chain ID of the destination chain.
    /// @param _target      Target contract or wallet address.
    /// @param _message     Message to trigger the target address with.
    /// @return msgHash_ The hash of the message being sent, which can be used for tracking whether
    ///                  the message has successfully been relayed.
    function sendMessage(uint256 _destination, address _target, bytes calldata _message) external returns (bytes32);
    
    /// @notice Relays a message that was sent by the other CrossDomainMessenger contract. Can only
    ///         be executed via cross-chain call from the other messenger OR if the message was
    ///         already received once and is currently being replayed.
    /// @param _id          Identifier of the SentMessage event to be relayed
    /// @param _sentMessage Message payload of the `SentMessage` event
    function relayMessage(Identifier calldata _id, bytes calldata _sentMessage) external payable;

Design

  • Create list of RPCs for each chain
  • Create list of Inbox contracts for each chain
  • Create ChainRelay struct that is instantiated for each chain
    • Listens to the RPC for that chain for SentMessage events
    • Construct a relayMessage transaction for the target chain
    • Send the transaction to the target chain with that chain's RPC
  • Use Tokio to create a ChainRelay for each chain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment