Skip to main content
Version: Endpoint V2 Docs

Message Receive Library

The Message Receive Library is a core component of the LayerZero protocol that manages the reception and verification of messages on the destination chain. It functions as a dedicated message handler on the receive side by decoding incoming encoded packets, verifying their integrity through specialized processes, and routing valid messages to the endpoint.

What Is a Message Receive Library?

The Message Receive Library is responsible for several crucial tasks that enable secure and reliable processing of inbound messages:

  • Decoding Messages:
    It parses the incoming data, ensuring the received packet information can be accurately reconstructed.

  • Verifying Integrity:
    The library performs validation steps verifying that the packet is intended for the local endpoint and meets requirements set by the receiving application.

  • Managing and Enforcing Configuration:
    Applications set configuration parameters via the LayerZero Endpoint, which are then applied to the library’s internal worker logic. This configuration determines the expected verification requirements.

    info

    Unlike the send side where fees are simply processed and workers selected, the receive library uses these settings to enforce that the workers verifying the packet match the predefined configuration.

  • Routing to the Endpoint:
    After verification, the decoded packet is passed from the library to the endpoint for further processing.

In sum, the Message Receive Library encapsulates the core logic for safely accepting and processing incoming packets.

How It Fits Into the Protocol

LayerZero’s architecture separates the receive process into clear, sequential steps:

Receive Model Flow:
Workers → Message Receive Library → Endpoint → Application

  1. Workers: These off-chain service providers receive the raw packet data and forward the encodedPacket to the destination chain.

  2. Message Receive Library: The library decodes the incoming packet, verifies its integrity using both header information and payload data, and ensures that the encodedPacket meets library requirements and application configurations.

  3. Endpoint: Once verified, the endpoint receives the validated packet and passes it to the appropriate application.

  4. Application: The final recipient processes the application’s original message from the sender and executes business logic.

Receive Ultra Light Node (ULN)

A specialized variant of the Message Receive Library is the Receive Ultra Light Node (ULN). Like its sending counterpart, the Receive ULN is tailored for a streamlined process: it not only decodes and verifies inbound messages but also enforces that only the preconfigured DVNs (or workers) validate the message.

Message Processing with Receive ULN

  1. Decoding the EncodedPacket:
    The Receive ULN begins by decoding the received encodedPacket. This packet is composed of two parts:

    • Packet Header:
      Contains vital routing and identification details, such as version information, nonce, source and destination endpoint IDs, and sender and receiver contract addresses.

    • Payload:
      Includes the GUID and the actual application’s message.

You can see how these data structures differ under Message, Packet, and Payload.

  1. Verifying DVN Submissions:
    The Receive ULN allows DVNs to call its verification function verify(), where each DVN submits a verification for a specific packet header eand payload hash. Thse attestations are stored in an internal mapping, ensuring that each DVN’s submission is recorded.

  2. Enforcing Configuration:
    Before an inbound message is accepted, the Receive ULN retrieves the UlnConfig set by the application (via the Endpoint) and verifies that the DVN meet the required criteria, both in terms of identity and the number of block confirmations. This step ensures that only messages verified by the proper, preconfigured workers are processed.

  3. Commit Verification:
    Once the DVN verifications have been checked against the configuration, the commitVerification() function is called. This function:

    • Asserts that the packet header is correctly formatted and that the destination endpoint matches the local configuration.

    • Retrieves the receive UlnConfig based on the source endpoint and receiver contract address.

    • Checks that the necessary verification conditions have been met using the stored DVN verifications.

    • Reclaims storage for the verification records and calls the destination Endpoint's verify() method, thereby adding the message to the inbound messaging channel.

In Summary

  • Purpose: The Message Receive Library governs the decoding, verification, and routing of inbound messages in the LayerZero protocol.

  • Function: It deciphers the encodedPacket and validates the integrity through predefined checks, and then hands the message off to the endpoint for delivery.

  • Design: By isolating the inbound processing logic in a dedicated module, the protocol remains modular and adaptable. Specialized variants such as the Receive ULN demonstrate how the architecture can be tailored to meet different operational needs.

  • User Benefit: For developers and users, this clear separation ensures that cross-chain communication is both secure and efficient, while also remaining flexible enough to integrate future enhancements.