How layerzero-labs/layerzero-v2 works
1. What this repo is
LayerZero V2 is a multi-chain protocol monorepo. The architecture is not one application, but several chain-specific implementations of the same cross-chain messaging system: protocol core, message libraries, worker/verifier components, and example OApp/OFT application layers.
2. Primary architectural pattern
The core flow is consistent across chains:
sender app → endpoint/protocol contract → message library → fee quoting → verification network (DVN) + executor → destination endpoint → app callback/compose handling.
The repo is organized around these boundaries rather than around one shared runtime.
3. Move-based chain families
The aptos, initia, iota, and sui trees are parallel Move implementations. They all contain the same conceptual subsystems:
- endpoint-v2 / endpoint_v2: the protocol entrypoint and packet lifecycle
- message-libs / msglib: library selection and verification logic
- workers: DVN/executor identities, hashes, fee logic, and registry
- oapps: OApp/OFT application code
- ptb-builders: transaction-building helpers for chains that require structured transaction construction
- utils / endpoint_v2_common: shared codecs, packet types, and config types
4. Move protocol boundary
In the Move chains, the endpoint is the on-chain control plane. It maintains channel state, message receipts, registration, timeouts, and message composer state through internal modules. The message library layer is the policy/transport abstraction that decides how packets are quoted, verified, and delivered.
5. Move worker subsystem
The workers and worker_peripherals packages model the off-chain actors on-chain:
- DVN modules and fee libs for verification pricing and signatures
- Executor modules and fee libs for delivery pricing and execution options
- worker registry / worker-common / multisig stores for authorization and metadata
- price feed modules/routers for dynamic fee conversion
These are separate from the endpoint so verification and execution policy can be swapped or extended.
6. Move application layer
The oapps and oft_common packages are the app-facing surface. OApp handles generic cross-chain messages and peer/enforced-option configuration; OFT adds token-transfer-specific codecs, limits, fees, and compose-message logic. layerzero_views exposes read-only helpers over endpoint and ULN state.
7. EVM implementation
The evm folder mirrors the same architecture in Solidity. It splits into:
- protocol: immutable endpoint/protocol contracts and shared libs
- messagelib: ULN implementations, DVN adapters, read libs, upgradeable proxy support
- oapp: application standards and OFT/precrime helpers
The EVM side includes Foundry-based test suites and an upgradeable boundary, which is a material difference from the Move deployments.
8. Solana implementation
The Solana subtree is Anchor/Rust-based and is the most explicit runtime split:
- programs/endpoint, programs/uln, programs/simple-messagelib, programs/executor, programs/pricefeed, programs/oft
- libs/* shared CPI/codec helpers
- worker-interface for worker interaction contracts
The Solana architecture separates state accounts, instruction handlers, and codec helpers, with build.rs and Anchor/Xargo tooling driving compilation.
9. TON implementation
The TON tree uses FunC and a more granular contract layout:
- protocol/endpoint, protocol/msglibs, protocol/msglibs/ultralightnode
- workers/* for DVN, executor, proxy, and price feed cache
- apps/* for OApp-style application contracts
- multisig, jettons/zro, and funC++ support libraries
TON’s architecture is heavily message-based, with explicit handler/interface/storage separation in each contract package.
10. Cross-chain codecs and type packages
A major shared concern is serialization. Every chain has dedicated packet/message codecs and type packages for:
- packet v1 encoding/decoding
- messaging fees and receipts
- worker options and config types
- endpoint/send/receive/quote call payloads
This is important for diagramming because most subsystem boundaries are enforced by codec layers, not by direct object sharing.
11. Testing and verification strategy
The repo is test-heavy and organizes tests next to each package, often mirroring production module names. There are also chain-specific harnesses:
- run_tests.sh for Move packages
- Foundry tests for EVM
- Anchor/Rust tests for Solana
- TS/Jest and FunC test scaffolding for TON
This suggests each chain package is independently buildable and testable, not a single centralized build graph.
12. Tooling and repo orchestration
Root-level yarn, .yarnrc.yml, and GitHub Actions indicate a workspace-level orchestration layer, but the actual contract ecosystems use their native toolchains: Move, Foundry, Anchor/Rust, and TON FunC. .gitmodules and lib/forge-std support external testing dependencies.
13. How to draw the diagram
A good architecture diagram should show:
- separate chain runtimes as first-class vertical lanes
- within each lane: endpoint/protocol, message library, workers, and app layer
- shared horizontal concerns: codecs, fee config, verification, and tests
- arrows from OApp/OFT to endpoint, then to message lib, then to DVN/executor, and back to destination receive/compose handlers
The key is that LayerZero V2 is a replicated protocol architecture across chains, not a single deployed system.
Main entry points: aptos/contracts Aptos · solana Solana · src TON · initia/contracts Initia
Components 26
Shared
Cross-chain concerns shared by all runtimes
- LayerZero V2 · Multi-chain protocol monorepo with replicated endpoint, message library, worker, and app layers
Move chains
Parallel Move implementations across Aptos, Initia, Iota, and Sui
- Aptos · Move implementation of endpoint, message libraries, workers, and apps
packages/layerzero-v2/aptos/contracts - Initia · Parallel Move implementation mirroring the Aptos layout
packages/layerzero-v2/initia/contracts - Iota · Move implementation with PTB builders and explicit worker call types
packages/layerzero-v2/iota/contracts - Sui · Move implementation with PTB builders and worker subsystems
packages/layerzero-v2/sui/contracts - Endpoint · On-chain control plane for channels, registration, receipts, timeouts, and composer state
packages/layerzero-v2/aptos/contracts/endpoint_v2 - Msglib · Message library layer for quoting, configuration, verification, and delivery selection
packages/layerzero-v2/aptos/contracts/msglib - Workers · DVN, executor, fee libraries, price feeds, and worker metadata infrastructure
packages/layerzero-v2/aptos/contracts/workers - OApps · App-facing OApp and OFT contracts built on endpoint and message libraries
packages/layerzero-v2/aptos/contracts/oapps - Codecs · Shared packet, fee, receipt, and worker option types used across Move packages
packages/layerzero-v2/aptos/contracts/endpoint_v2_common
EVM
Solidity implementation and standards
- EVM · Solidity protocol, message library, and OApp standards
packages/layerzero-v2/evm - Endpoint · Immutable endpoint and protocol contracts for send, quote, receive, and config flows
packages/layerzero-v2/evm/protocol - Msglib · ULN message library implementations, DVN adapters, read libs, and upgradeable support
packages/layerzero-v2/evm/messagelib - OApp · Application standards including OApp, OFT, and precrime helpers
packages/layerzero-v2/evm/oapp
Solana
Anchor/Rust programs and helper crates
- Solana · Anchor/Rust programs for endpoint, ULN, executor, price feed, and OFT
packages/layerzero-v2/solana - Endpoint · Endpoint program handling send, quote, verify, and OApp configuration instructions
packages/layerzero-v2/solana/programs/programs/endpoint - ULN · ULN program for message verification, confirmations, and endpoint-linked send flows
packages/layerzero-v2/solana/programs/programs/uln - Executor · Executor program for quoting and executing delivered messages
packages/layerzero-v2/solana/programs/programs/executor - Price Feed · Price feed program that prices worker fees for message delivery
packages/layerzero-v2/solana/programs/programs/pricefeed - OFT · Token transfer application program built on the endpoint
packages/layerzero-v2/solana/programs/programs/oft
TON
FunC-based protocol, worker, and app contracts
- TON · FunC contracts for endpoint, ULN, workers, apps, and supporting codecs
packages/layerzero-v2/ton/src - Endpoint · TON endpoint contract split into handler, interface, storage, and tests
packages/layerzero-v2/ton/src/protocol/endpoint - Msglibs · TON message library layer including simple msglib and ULN variants
packages/layerzero-v2/ton/src/protocol/msglibs - Workers · TON DVN, executor, proxy, price feed cache, and worker fee libraries
packages/layerzero-v2/ton/src/workers - Apps · TON application contracts such as base OApp and counter example
packages/layerzero-v2/ton/src/apps - Codecs · TON shared message data, LZ classes, and serialization helpers
packages/layerzero-v2/ton/src/classes
Connections 41
- LayerZero V2 → Aptos: Move lane · Workspace includes an Aptos Move implementation
- LayerZero V2 → Initia: Move lane · Workspace includes an Initia Move implementation
- LayerZero V2 → Iota: Move lane · Workspace includes an Iota Move implementation
- LayerZero V2 → Sui: Move lane · Workspace includes a Sui Move implementation
- LayerZero V2 → EVM: EVM lane · Workspace includes Solidity protocol packages
- LayerZero V2 → Solana: Solana lane · Workspace includes Anchor/Rust programs and libraries
- LayerZero V2 → TON: TON lane · Workspace includes FunC-based protocol packages
- Aptos → Endpoint: endpoint · Move runtime endpoint control plane
- Aptos → Msglib: message libs · Move runtime message library layer
- Aptos → Workers: workers · Move runtime DVN/executor and fee infrastructure
- Aptos → OApps: apps · Move runtime OApp/OFT surface
- Aptos → Codecs: types · Shared endpoint and packet codecs
- Initia → Endpoint: endpoint · Parallel Move endpoint implementation
- Initia → Msglib: message libs · Parallel Move message library layer
- Initia → Workers: workers · Parallel Move worker subsystem
- Initia → OApps: apps · Parallel Move application layer
- Iota → Codecs: shared utils · Iota relies on shared packet and option codecs
- Iota → Workers: workers · Iota mirrors worker pricing and verification concerns
- Sui → Codecs: shared utils · Sui relies on shared packet and option codecs
- Sui → Workers: workers · Sui mirrors worker pricing and verification concerns
- EVM → Endpoint: protocol · Solidity endpoint/protocol contracts
- EVM → Msglib: messagelib · Solidity ULN and adapter contracts
- EVM → OApp: oapp · Solidity application standards
- Endpoint → Msglib: select lib · Endpoint routes send/quote/receive through message libraries
- Msglib → OApp: deliver · Message library supports OApp delivery and compose handling
- Solana → Endpoint: endpoint · Endpoint program handles cross-chain send and receive
- Solana → ULN: uln · ULN program handles verification and confirmation state
- Solana → Executor: executor · Executor program handles delivery execution
- Solana → Price Feed: pricing · Price feed program computes worker fees
- Solana → OFT: oft · OFT program implements token transfer application behavior
- Endpoint → ULN: verify · Endpoint verification flows are backed by ULN
- Endpoint → Executor: execute · Endpoint delivery flows rely on executor handling
- OFT → Endpoint: send/receive · OFT uses endpoint CPI for messaging
- TON → Endpoint: endpoint · TON endpoint contract
- TON → Msglibs: msglibs · TON message library contracts
- TON → Workers: workers · TON worker contracts and fee libraries
- TON → Apps: apps · TON application contracts
- TON → Codecs: codecs · TON shared serialization and message data
- Apps → Endpoint: send/receive · Apps call into endpoint contracts
- Endpoint → Msglibs: route · Endpoint delegates through message libraries
- Msglibs → Workers: fee/verify · ULN and simple msglib flows invoke worker fee and verification logic