Message Handlers

WIP

Overview

The L1MessageHandler and L2MessageHandler contracts represent an abstraction for cross-chain message communication used within the Othentic Stack. Each AVS deploys its own message handlers to facilitate message-passing between Layer 1 and Layer 2 blockchains. These handlers play a critical role in ensuring seamless and secure communication across different layers.

The primary goal of the contracts is to handle infrequent operations such as the registration and deregistration of Operators, slashing events, and the distribution of rewards.

Leveraging LayerZero messaging protocol, L1MessageHandler, and L2MessageHandler in conjunction with Decentralized Verifier Networks (DVNs), the Othentic Stack enables message-passing interactions between different layers.

L1MessageHandler

function _lzReceive(
        Origin calldata /* _origin */,
        bytes32 /* _guid */,
        bytes calldata _message,
        address /* _executor */,
        bytes calldata /* _extraData */
    ) override internal virtual {
        (bytes4 _sig, bytes memory _body) = _payloadToSig(_message);
        if (_sig == MessagesLibrary.PAYMENT_SIG) {
            _handlePaymentRequestMessage(_body);
        } else if (_sig == MessagesLibrary.BATCH_PAYMENT_SIG) {
            _handleBatchPaymentRequestMessage(_body);
        } else if (_sig == MessagesLibrary.SLASH_SIG) {
            _handleSlashMessage(_body);
        } else {
            revert("L1MessageHandler: Unknown message signature");
        }
    }

    function sendMessage(bytes memory _message) external onlyRole(RolesLibrary.AVS_GOVERNANCE) {
        _lzSendMessage(_message);
    }

L2MessageHandler

function _lzReceive(
        Origin calldata /* _origin */,
        bytes32 /* _guid */,
        bytes calldata _message,
        address /* _executor */,
        bytes calldata /* _extraData */
    ) override internal virtual {
        (bytes4 _sig, bytes memory _body) = _payloadToSig(_message);
        if (_sig == MessagesLibrary.REGISTER_SIG) {
            _handleRegisterOperatorMessage(_body);
        } else if (_sig == MessagesLibrary.CLEAR_SIG) {
            _handlePaymentSuccessMessage(_body);
        } else if (_sig == MessagesLibrary.BATCH_CLEAR_SIG) {
            _handleBatchPaymentSuccessMessage(_body);
        } else if (_sig == MessagesLibrary.MODIFY_SHARES_SIG) {
            _handleModifyNumberOfSharesMessage(_body);
        } else if (_sig == MessagesLibrary.UNREGISTER_SIG) {
            _handleUnregisterOperatorMessage(_body);
        } else {
            revert("L2MessageHandler: Unknown message signature");
        }    
    }

function sendMessage(bytes memory _payload) external onlyRole(RolesLibrary.ATTESTATION_CENTER) {
        _lzSendMessage(_payload);
    }

Last updated