LPsLux Proposals
Network
LP-4010

Crypto Implementation Architecture

Final

The implementation contract every Lux cryptographic primitive obeys — a first-party CPU canonical, first-party GPU kernels byte-equal to it, and audited upstream libraries used only as adversarial test oracles

Abstract

Every cryptographic primitive in Lux is built the same way, and this LP is that way. Three rules:

CPU is the first-party canonical, byte-equal to a Go reference. GPU is first-party Metal/CUDA/WGSL, byte-equal to the CPU canonical. Audited upstreams (mcl, blst, BoringSSL, PQClean, c-kzg) are vendored as TEST ORACLES ONLY — never linked into a shipped library.

Why the CPU body is first-party

The obvious shortcut is to wrap an audited upstream library as the production CPU path and test the GPU kernel against it. That is wrong, and the reason is worth spelling out because it is not obvious.

The value of a byte-equality test is adversarial distance: the two sides must be able to fail independently. If the CPU path is the oracle, or is derived from the same algorithm family as the oracle — both vendored from gnark-crypto, say, or both from blst — then a bug in upstream flows through both sides of the comparison and the test passes while the code is wrong. The test would be checking that a thing equals itself.

First-party CPU + vendored test oracle is the correct structure: a bug on either side breaks the equality, and the test tells you so.

The byte-equality chain

                 +---------------------+
                 |  Reference (Go)     |
                 |  gnark-crypto, etc. |
                 +----------+----------+
                            |
                       byte-equal
                            |
                 +----------v----------+
                 |  CPU canonical      |
                 |  first-party C++    |  <-- ground truth for all backends
                 +----------+----------+
                            |
                       byte-equal
                            |
        +-------------------+-------------------+
        |                   |                   |
+-------v------+    +-------v------+    +-------v------+
|  Metal       |    |  CUDA        |    |  WGSL        |
|  first-party |    |  first-party |    |  first-party |
+--------------+    +--------------+    +--------------+

One equality contract, three hops. Every backend is coupled to the same ground truth transitively, so "does the CUDA kernel agree with the Metal kernel" never has to be asked separately — both agree with the CPU canonical, therefore with each other.

Layout

Each algorithm <alg> has:

  • luxcpp/crypto/<alg>/cpp/ — first-party C++ CPU body
  • luxcpp/crypto/<alg>/gpu/metal/<alg>.metal
  • luxcpp/crypto/<alg>/gpu/cuda/<alg>.cu
  • luxcpp/crypto/<alg>/gpu/wgsl/<alg>.wgsl
  • luxcpp/crypto/<alg>/c-abi/<alg>_capi.h — the only surface consumers call
  • luxcpp/crypto/<alg>/test/cmake/<oracle>.cmake — the vendored oracle, pinned to a luxfi-controlled tag, never linked into lib<alg>.a

The determinism harness runs N = 100…1000 random inputs through the CPU body and each available GPU backend and asserts byte-equality.

Implementation status

PARTIAL. The architecture above is the contract; coverage against it is uneven. A minority of C-ABI shims dispatch to a real body; the rest return CRYPTO_ERR_NOTIMPL, which is an honest placeholder rather than a wrong answer. Several C++ bodies exist but are blocked on the intx / blst / evmmax bootstrap not yet present in luxcpp/crypto. Go remains the production path for every primitive whose C++ body is not yet wired.

The C-ABI shim, not the kernel, is the real bottleneck. A C++ body and a byte-equal Metal kernel can both exist while the shim between them and the caller still returns NOTIMPL — and an audit that measures body presence plus kernel equality will report that algorithm as working when production cannot reach it. Measure the C-ABI → body dispatch chain that consumers actually call, not the pieces.

Rejected: replacing the first-party CPU body with a vendored library

Proposed and rejected. The reasons, in order of weight:

  1. It destroys the oracle's adversarial distance (above) — the whole test structure collapses.
  2. It creates dual-implementation divergence: CPU wraps the upstream while GPU stays first-party, so the two production paths no longer derive from one algorithm description.
  3. Vendor symbols leak into shipped binaries.
  4. The "5–10× faster" argument was never established for the cold path, and the cold path is the only path a CPU body serves — GPU is the hot path.
  5. Build fragility on aarch64.

Hard rules

  • One CPU implementation per algorithm.
  • One GPU implementation per backend per algorithm.
  • The byte-equality oracle is vendored and test-only.
  • No NOTIMPL stubs in production paths. NOTIMPL is acceptable in a C-ABI shim as a documented placeholder; it is never acceptable behind a caller that expects an answer.
  • Names are algorithm names. The algorithm name is the namespace — no vendor prefix, in symbols or in domain separation tags.

Copyright (C) 2024-2026, Lux Industries Inc. All rights reserved.

Licensed under the MIT License.