Message Read Library
The Read Library is a specialized Message Library designed for Omnichain Queries. It combines both send and receive capabilities to process read requests and deliver verified responses across chains.
What Makes the Read Library Unique?
Unlike the standard Message Send Library and Message Receive Library, the Read Library handles a full request-and-response workflow:
- Send Side: It serializes a read command and directs it to the appropriate chain using the application's configured Decentralized Verifier Networks (DVNs).
- Receive Side: It verifies DVN attestations for the returned data and routes the final response back to the endpoint and ultimately the requesting application.
This dual nature allows a single library to manage both outbound queries and inbound responses, ensuring the correct workers are used for each step.
How It Fits Into lzRead
When an application issues a query via EndpointV2.send()
, the Read Library (ReadLib1002
) encodes the request and forwards it to the configured DVNs. Each DVN reads from an archival node on the target chain, optionally performs off-chain compute (mapping or reducing data), and submits a hash of the result. Once the required number of DVNs confirm the same payload hash, the Read Library finalizes the response and the endpoint delivers the data to OApp.lzReceive()
.
This process transforms normal cross-chain messaging into a request/response pattern:
Application → Endpoint → Read Library → DVNs → Read Library → Endpoint → Application
Configuration and Security
Applications must configure the Read Library just like any other Message Library, specifying DVN thresholds and executor addresses. Because it enforces the DVN verification on the receive side, both the send and receive pathways must use the same ReadLib1002
instance to ensure correct processing.
Reference Implementation
The reference contract for the Read Library can be found in the LayerZero V2 repository:
LayerZero-v2/packages/layerzero-v2/evm/messagelib/contracts/uln/readlib/ReadLib1002.sol
This file details how queries are encoded, how DVN submissions are validated, and how fees are handled for workers and the treasury.
Summary
- Purpose: Manage omnichain query requests and responses using the LayerZero Read workflow.
- Function: Acts as both send and receive library, serializing requests, verifying DVN responses, and routing the final data to the application.
- Learn More: For an overview of the read workflow and query language, see Omnichain Queries (lzRead).