Technical
LayerZero Integration

LayerZero Integration

How Brtr uses LayerZero for secure cross-chain messaging.

What is LayerZero?

LayerZero (opens in a new tab) is an omnichain interoperability protocol that enables:

  • Secure message passing between blockchains
  • Configurable security settings
  • Native token transfers via gas drop

Brtr contracts are built on LayerZero's OApp (Omnichain Application) standard.

Endpoint IDs

Each blockchain has a unique LayerZero Endpoint ID (EID):

ChainTestnet EID
Base Sepo40245
OP Sepo40232
Monad Testnet40362
MegaETHTBD

Message Types

Brtr uses three message types for cross-chain trades:

Message Encoding

// Message structure
struct Message {
    uint8 msgType;      // 1, 2, or 3
    bytes32 orderId;    // Unique order identifier
    address filler;     // Buyer address
    address requester;  // Seller address
    uint256 optionIndex;// Which payment option
    // ... additional fields per type
}

Security Features

Peer Verification

Brtr contracts only accept messages from verified peer contracts:

// Set peer on each chain
function setPeer(uint32 _eid, bytes32 _peer) external onlyOwner;
 
// Verification in _lzReceive
require(
    peers[origin.srcEid] == origin.sender,
    "Unknown peer"
);

DVN Verification

Messages are verified by LayerZero's Decentralized Verifier Network before execution.

Reentrancy Protection

All message handlers use reentrancy guards:

function _handleFillInitiate(...) internal nonReentrant {
    // Handle message
}

Nonce Tracking

Replay attacks are prevented via nonce tracking in the LayerZero protocol.

Gas Management

Gas Drop

Cross-chain messages include native tokens for subsequent operations:

// Options for FILL_INITIATE
options = OptionsBuilder
    .newOptions()
    .addExecutorLzReceiveOption(480_000, confirmationGasDrop);
 
// confirmationGasDrop covers:
// - Confirmation message execution on seller chain
// - Finalization gas drop back to buyer chain

Quote Functions

// Quote entire cross-chain fill cost
function quoteFee(
    uint32 dstEid,
    bytes32 orderId,
    address filler,
    address requester,
    uint256 optionIndex,
    address buyerToken,
    uint256 tokenAmount
) public view returns (MessagingFee memory fee);
 
// Quote individual message types
function quoteConfirmationGasFee(...) public view;
function quoteFinalizationGasFee(...) public view;

Gas Buffer

A 9x buffer (90,000 basis points) is applied to gas estimates:

uint256 constant GAS_BUFFER_BPS = 90_000; // 9x buffer
 
function _withBuffer(uint128 amount, uint256 bps)
    internal pure returns (uint128)
{
    return uint128(uint256(amount) * bps / 10_000);
}

This accounts for:

  • Gas price volatility
  • Network congestion
  • Execution overhead

Monitoring

LayerZero Scan

Track cross-chain message status at layerzeroscan.com (opens in a new tab):

  1. Find your transaction hash
  2. Search on LayerZero Scan
  3. See message status, timing, and delivery

Message Status

StatusMeaning
PendingMessage sent, not yet verified
InflightVerified, awaiting execution
DeliveredSuccessfully executed
FailedExecution failed (check logs)

Troubleshooting

Message Not Delivered

Possible causes:

  1. Insufficient gas provided
  2. Network congestion
  3. Temporary DVN delays

What To Do

  1. Check LayerZero Scan for status
  2. Wait up to 10 minutes
  3. After 30 minutes, recovery functions available
  4. Contact support if issues persist

Most delays resolve within 10 minutes. LayerZero is highly reliable.

Resources