# Message Handlers

The [`L1MessageHandler`](https://github.com/Othentic-Labs/core-contracts/blob/main/src/NetworkManagement/L1/L1MessageHandler.sol) and [`L2MessageHandler`](https://github.com/Othentic-Labs/core-contracts/blob/main/src/NetworkManagement/L2/L2MessageHandler.sol) 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.

Leveraging `L1MessageHandler`, and `L2MessageHandler` in conjunction with [Decentralized Verifier Networks (DVNs)](https://docs.layerzero.network/v2/home/modular-security/security-stack-dvns), the AVS enables message-passing interactions between L1 and L2.&#x20;

### Contract Addresses

During the AVS deployment, the L1 and L2 Message Handlers are deployed. The contract addresses can be obtained from the `L1MessageHandlerDeployed` and `L2MessageHandlerDeployed` events, emitted in the respective L1 and L2 transactions.

{% hint style="info" %}
To avoid failed message executions, ensure that Message Handler Contracts are funded with the native tokens of their respective chains.
{% endhint %}

## **Core Functions**

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

<figure><img src="https://4144525652-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYlSi30nrcEOossIDFFua%2Fuploads%2FXn90CsAKGVDYJouU7oR3%2Fimage.png?alt=media&#x26;token=a28e233b-6512-4adf-93ff-89be32a1bd55" alt="" width="563"><figcaption></figcaption></figure>

### L1 Message Handler

[View source code](https://github.com/Othentic-Labs/core-contracts/blob/main/src/NetworkManagement/L1/L1MessageHandler.sol)

**Access Control:** Only the AVS governance contract can [send](https://github.com/Othentic-Labs/core-contracts/blob/main/src/NetworkManagement/L2/L2MessageHandler.sol#L44) messages from L1.

**Functionality:**

* AVS governance contract calls the L1 messageHandler to notify L2 about processed payments and Operator status updates.
* **Message Processing:** Implements [\_lzReceive](https://github.com/Othentic-Labs/core-contracts/blob/main/src/NetworkManagement/L2/L2MessageHandler.sol#L72C14-L72C24) method to handle incoming messages from L2, including:
  * Payment request&#x20;
  * Batch Payment request

***

### L2 Message Handler

[View source code](https://github.com/Othentic-Labs/core-contracts/blob/main/src/NetworkManagement/L2/L2MessageHandler.sol)

**Access Control:** Only the Attestation Center contract can [send](https://github.com/Othentic-Labs/core-contracts/blob/main/src/NetworkManagement/L2/L2MessageHandler.sol#L44) messages from L2.

**Functionality:**

* The Attestation Center contract calls the L2MessageHandler to forward payment or slashing requests to L1.
* **Message Processing:** Implements [\_lzReceive](https://github.com/Othentic-Labs/core-contracts/blob/main/src/NetworkManagement/L2/L2MessageHandler.sol#L72C14-L72C24) method to handle incoming messages from L1, including:
  * Operator registration&#x20;
  * Operator de-registration
  * Payment success&#x20;
  * Batch payment success&#x20;
