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):
| Chain | Testnet EID |
|---|---|
| Base Sepo | 40245 |
| OP Sepo | 40232 |
| Monad Testnet | 40362 |
| MegaETH | TBD |
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 chainQuote 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):
- Find your transaction hash
- Search on LayerZero Scan
- See message status, timing, and delivery
Message Status
| Status | Meaning |
|---|---|
| Pending | Message sent, not yet verified |
| Inflight | Verified, awaiting execution |
| Delivered | Successfully executed |
| Failed | Execution failed (check logs) |
Troubleshooting
Message Not Delivered
Possible causes:
- Insufficient gas provided
- Network congestion
- Temporary DVN delays
What To Do
- Check LayerZero Scan for status
- Wait up to 10 minutes
- After 30 minutes, recovery functions available
- Contact support if issues persist
Most delays resolve within 10 minutes. LayerZero is highly reliable.