Lux Docs
Zap

ZAP Protocol

Zero-copy Application Protocol for high-performance messaging

ZAP (Zero-copy Application Protocol) is a high-performance binary protocol for inter-process messaging on the Lux network. It provides 17x faster serialization and 11x less memory than MCP JSON-RPC while maintaining compatibility with existing MCP tools.

import "github.com/luxfi/zap"

Performance

MetricMCP JSON-RPCZAPImprovement
Serialization5,579 ns/op322 ns/op17x faster
Memory/call2,826 bytes256 bytes11x less
Allocations58/op2/op29x fewer
Parse time~1,000 ns2.9 ns345x faster

Wire Format

Every ZAP message has a 16-byte header followed by a variable-length data segment:

Header (16 bytes)
  Magic:       "ZAP\x00" (4 bytes)
  Version:     1 (2 bytes)
  Flags:       compression, etc. (2 bytes)
  Root Offset: offset to root object (4 bytes)
  Size:        total message size (4 bytes)
Data Segment (variable)
  Structs, lists, text, bytes...

Supported Types

TypeSizeDescription
Bool1Boolean (0 or 1)
Int8/Uint818-bit integer
Int16/Uint16216-bit integer
Int32/Uint32432-bit integer
Int64/Uint64864-bit integer
Float32/Float644/8IEEE 754 floating point
Text8String (offset + length)
Bytes8Byte slice (offset + length)
List8Array (offset + length)
Struct4Nested object (offset)
Address20EVM address
Hash32EVM hash
Signature65EVM signature

TLS Support

ZAP supports optional TLS via NodeConfig.TLS. When running on Go 1.26+, TLS connections default to PQ-TLS 1.3 with ML-KEM-768 + X25519 hybrid key exchange -- no additional configuration required.

node := zap.NewNode(zap.NodeConfig{
    NodeID:      "node-1",
    ServiceType: "_luxd._tcp",
    Port:        9651,
    TLS:         tlsConfig, // *tls.Config; Go 1.26 defaults to ML-KEM-768
})

Zero-copy semantics are preserved under TLS. The TLS layer operates on the same buffer without additional heap allocations.

Use Cases

  • AI Agent Orchestration: 20-tool orchestrator runs at 150K ops/sec vs 10K with JSON-RPC
  • VM-to-VM Communication: Cross-VM message routing on the Lux network
  • GPU Cluster / FHE Kernels: Zero-copy ciphertext transfer between compute nodes
  • Consensus: 5-node consensus reaching agreement in ~450 microseconds
  • MCP Bridge: Auto-discover and accelerate existing MCP servers with ZAP transport

On this page