zooqueen f2e3705e96 lx: make CGO=1 build cross-platform; honest secp256k1 GPU fallback
CGO_ENABLED=1 go build ./... failed to link every binary importing
pkg/lx: signed_order_gpu.go unconditionally force-linked the Apple-only
libsecp256k1_metal.a via a hardcoded build-tree -L path and the
signed-order Metal anchor. That archive is not built by default and has
no pkg-config bundle, so the link aborted with 'library secp256k1_metal
not found'. The GPU-vs-CPU choice must be a runtime decision, never a
hard build-time link dependency on an absent accelerator.

- Gate the secp256k1 Metal force-link anchor (.go + .c) behind the
  opt-in 'lux_secp256k1_metal' build tag and move the Metal/Foundation
  LDFLAGS there. Default CGO builds now link and run the secp256k1 CPU
  ecrecover pipeline (via the working lux-crypto-secp256k1 .pc); the
  Metal accelerator, when its archive is built and the tag is set, is
  still resolved at runtime by cpp/ecrecover.cpp via dlsym gated on
  LUX_SECP256K1_METALLIB / LUX_SECP256K1_BACKEND.
- signed_order_gpu.go keeps only the CPU pkg-config; the anchor file
  documents the build + opt-in recipe.
- signed_order_cpu.go: verifyOrdersCPU returns nil for empty input,
  matching the cgo BatchVerifyOrders contract so CPU and cgo paths agree
  byte-for-byte (fixes TestBatchVerifyOrders_Empty under CGO=0).
- README: remove the non-existent 'dex_gpu' build-tag claim; document
  the real model — AMM/CLOB GPU paths live in pkg/lx, bind the luxcpp
  DEX kernels via pkg-config (lux-dex-amm-metal / -amm-cuda / -clob-cuda),
  and select GPU-vs-CPU at runtime via crypto/backend detection with a
  logged, honest CPU fallback.

The DEX AMM Metal bridge (amm_xyk_batch_metal) now compiles, links, and
its dispatch is byte-identical to the CPU oracle (parity test green
under CGO=1). CLOB GPU primitive (MatchOrderGPU) stays a flat-buffer
parity/backtest primitive, intentionally not wired into the live
linked-list MatchOrders() engine.

Verified: CGO_ENABLED=0 go test ./... green (16 pkgs, 1360 cases);
CGO_ENABLED=1 go build ./... exit 0.
2026-06-21 22:37:05 -07:00
2025-12-11 18:00:56 -08:00
2025-12-11 17:50:19 -08:00
2025-12-28 11:00:04 -08:00

LX

Lux DEX — pure-Go matching engine, order book, oracle aggregator, and JSON-RPC / WebSocket / gRPC SDKs.

CI Release Go Version License

Open core

This repository is the public, pure-Go reference implementation of the Lux DEX matching engine. It is fully functional, runs standalone, and underpins every Lux DEX deployment. Built with CGO_ENABLED=0 it is a self-contained pure-Go binary with zero native dependencies.

GPU acceleration is a runtime decision, not a build tag

The batched GPU paths (constant-product AMM curve evaluation and the flat-buffer CLOB match primitive) live in this repository under pkg/lx/ and are compiled into the CGO_ENABLED=1 build. They bind to the luxcpp DEX kernels through pkg-config:

pkg-config bundle backend consumed by
lux-dex-amm-metal Metal (macOS) pkg/lx/amm_gpu_metal.go
lux-dex-amm-cuda CUDA (Linux) pkg/lx/amm_gpu_cuda.go
lux-dex-clob-cuda CUDA (Linux) pkg/lx/orderbook_cuda.go

These bundles ship from luxcpp/dex (cmake --install). Whether a GPU is actually used is decided at runtime by github.com/luxfi/crypto/backend detection, never by a build tag:

  • GPU_DISABLE=1 forces the CPU path (recorded as reason=disabled).
  • No Metal/CUDA device, or the runtime kernel/metallib is absent → the per-platform dispatch returns its unsupported sentinel and the call transparently falls back to the pure-Go CPU CLOB / AMM oracle (recorded as reason=unsupported). The fallback is logged — a CPU result is never mislabeled as GPU.
  • macOS resolves the AMM metallib at runtime via LUX_DEX_AMM_METALLIB (default: the installed share/lux/dex/amm_xyk.metallib).

There is no dex_gpu build tag. The one optional opt-in tag is lux_secp256k1_metal, which force-links the Apple-only batched secp256k1-ecrecover Metal archive; without it the signed-order batch verifier runs the secp256k1 CPU pipeline. See pkg/lx/signed_order_metal_anchor_darwin.go for the build + opt-in recipe.

For commercial deployments that need the heavier accelerators (NUMA-aware C++ order book, FPGA fast paths) the same Go interfaces are implemented by the private lux-private/dex tier, which fails closed unless the operator's environment carries a Lux commercial license token whose scope list includes dex. Contact [email protected] for commercial licensing.

Features

  • Ultra-high performance: 13M+ orders/sec achieved with planet-scale architecture
  • Sub-microsecond latency: 75.9ns order matching, 636ns position updates
  • Multi-engine architecture: Pure Go, C++, and GPU (CUDA/MLX)
  • Quantum-resistant consensus: DAG with post-quantum signatures
  • Cross-platform: Linux, macOS (Intel & Apple Silicon), Windows
  • Professional Market Data: Real-time oracle integration with multiple sources
  • Cross-Chain Support: Universal bridge for all major blockchains
  • 100% Test Coverage: All critical paths tested and verified

Quick Start

# Install dependencies
go mod download

# Build all binaries
make build

# Run tests
make test

# Run demo
./bin/demo

# Run benchmarks
make bench

Installation

From Source

git clone https://github.com/luxfi/dex
cd dex
make build

From Release

# Download latest release for your platform
curl -L https://github.com/luxfi/dex/releases/latest/download/lx-dex-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m) -o lx-dex
chmod +x lx-dex
./lx-dex

Performance

Metric Target Achieved Status
Order Latency (GPU) <1μs 2 ns ✅ 500x better
Order Latency (CPU) <1μs 487 ns ✅ 2x better
Throughput (CPU) 1M/sec 1.01M/sec ✅ Exceeded
Throughput (GPU) 100M/sec 434M/sec ✅ 4.34x
Test Coverage 100% pass 100% pass ✅ Complete
Code Coverage 30% 39.1% ✅ Exceeded

*With MLX GPU acceleration on Apple Silicon M2 Ultra

Architecture

The DEX uses a multi-engine architecture:

  • Pure Go Engine: Portable, 830K orders/sec
  • C++ Engine: Low latency, 800K+ orders/sec
  • Rust Engine: High performance, 585K+ orders/sec
  • MLX GPU Engine: Apple Silicon Metal, 6M+ msgs/sec (FIX), 434M+ orders/sec

FIX Protocol Performance (December 2024)

Engine NewOrderSingle ExecutionReport MarketDataSnapshot
Pure Go 163K/sec 124K/sec 332K/sec
Hybrid Go/C++ 167K/sec 378K/sec 616K/sec
Pure C++ 444K/sec 804K/sec 1.08M/sec
Rust 484K/sec 232K/sec 586K/sec
MLX (Apple Silicon) 3.12M/sec 4.27M/sec 5.95M/sec

*MLX achieves sub-2μs average latency (0.68-1.75μs) via GPU parallelism

See docs/ for detailed documentation.

Development

Requirements

  • Go 1.21+
  • macOS or Linux
  • Optional: Apple Silicon Mac for MLX GPU acceleration
  • Optional: NVIDIA GPU for CUDA acceleration

Building with GPU Support

# Apple Silicon (Metal)
CGO_ENABLED=1 make build

# Linux with CUDA
CGO_ENABLED=1 CUDA=1 make build

Running Tests

# Unit tests
make test

# Benchmarks
make bench

# All tests including integration
go test ./...

CI/CD

The project uses GitHub Actions for CI/CD:

  • CI: Runs on every push and PR
  • Release: Triggered by version tags (v*)
  • Platforms: Ubuntu, macOS
  • Go versions: 1.21, 1.22

See .github/workflows/ for workflow definitions.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing)
  5. Open a Pull Request

License

Copyright (C) 2020-2025, Lux Industries Inc.

S
Description
Lux DEX — pure-Go matching engine, JSON-RPC/WebSocket/gRPC SDKs. Commercial GPU acceleration via lux-private/dex.
Readme
100 MiB
Languages
Go 71.1%
Rust 9.6%
TypeScript 6.4%
Python 6.1%
Shell 3.1%
Other 3.6%