Skip to main content
This page provides a deep technical dive into the LayerZero V2 protocol implementation on Starknet, documenting the complete message lifecycle with contract-level code samples and function signatures. What you’ll find:
  • Complete send workflow (quote, approve, send, endpoint processing)
  • DVN verification process and verification status checks
  • Executor delivery and OApp receive handling
  • Recovery operations (skip, clear, nilify, burn)
  • Security considerations for payload hashes and reentrancy
Target audience: Developers who understand Starknet basics and want to deeply understand the protocol implementation.
PrerequisitesBefore reading this page, familiarize yourself with Starknet fundamentals in Technical Overview. For SDK usage and practical implementation, see OApp or OFT guides.

This page documents the complete message lifecycle with contract-level implementation details:
  • Send Workflow: Message initiation, fee calculation, nonce management, and packet dispatch
  • Verification Workflow: DVN submission, verification checks, and execution readiness
  • Receive Workflow: Executor delivery, payload clearing, and OApp processing

Send Overview

When an OApp initiates a crosschain message, the following high-level steps occur on the source chain.

Message Lifecycle Overview

The LayerZero protocol enables secure crosschain messaging through a three-phase process:

Core Data Structures

Packet

The Packet structure represents a crosschain message:

Origin

The Origin structure identifies the source of an incoming message:

MessagingParams

Parameters for sending a message:

MessagingFee

Fee structure returned by quote operations:

Send Workflow

When an OApp initiates a crosschain message, the following steps occur:

Step 1: Quote the Fee

Before sending, get a fee estimate:

Step 2: Approve Fees

The caller must approve the Endpoint to spend their tokens:

Step 3: Send the Message

The OApp calls the Endpoint’s send function:

Step 4: Endpoint Processing

The Endpoint performs the following:
  1. Creates the Packet with a unique GUID and incremented nonce
  2. Looks up the Send Library for this OApp/destination pair
  3. Routes to Message Library (ULN302) for worker fee calculation
  4. Pays Workers (DVNs, Executor) via ERC20 transfers
  5. Emits PacketSent event with encoded packet and options

Events Emitted During Send


Verification Workflow

After a PacketSent event is emitted, DVNs verify the message and the destination Endpoint records verification data.

DVN Verification Process

Step 1: DVN Monitors Source Chain

DVNs monitor the source chain for PacketSent events and extract the packet data.

Step 2: DVN Submits Verification

Once a DVN has verified the packet (e.g., confirmed finality), it submits the verification to the receive library. The receive library then calls verify on the destination Endpoint.

Step 3: Check Verification Status

The Executor (or anyone) can check if a message is ready for execution:

Events Emitted During Verification


Receive Workflow

Once verified, the Executor delivers the message to the destination OApp.

Executor Delivery

Step 1: Executor Calls lz_receive

Step 2: OApp Handles the Message

Your OApp implements the ILayerZeroReceiver interface:

Events Emitted During Receive


Recovery Operations

LayerZero provides mechanisms for handling stuck or problematic messages:

Skip

Skip an unverified message (before DVN verification):
Use Case: Skip a message that will never be verified (e.g., source chain reorg).

Clear

Clear a verified but unexecuted message:
Use Case: Clear a message that’s blocking subsequent messages due to ordering.

Nilify

Reset a verification to allow re-verification:
Use Case: Dispute a verification or handle DVN misbehavior.

Burn

Permanently block a message:
Use Case: Permanently reject a malicious or invalid message.

Security Considerations

Payload Hash Verification

The Endpoint stores only the hash of the payload, not the full message. This:
  • Saves storage costs
  • Prevents spam attacks
  • Requires Executor to provide correct message data

Reentrancy Protection

The Endpoint uses OpenZeppelin’s ReentrancyGuard component:

Clear Before Execute

The lz_receive function clears the payload hash before calling the receiver’s handler:
This “clear-then-execute” pattern prevents reentrancy attacks where a malicious receiver could attempt to re-execute the same message.

Next Steps