LPsLux Proposals
Cryptography
LP-5627

GPU-Native Crypto Stack

Final

The substrate every per-algorithm crypto LP shares — a first-party CPU canonical plus first-party Metal/CUDA/WGSL kernels, all byte-equal to one ground truth, with audited upstreams admitted only as test oracles so byte-equality keeps its adversarial distance

Category
Core
Created
2025-12-15

Abstract

A GPU-native crypto substrate for the nine-chain Lux topology. Every primitive ships a first-party CPU canonical (Go reference) and first-party Metal / CUDA / WGSL kernels, all byte-equal to the same ground truth. Audited upstreams (blst, c-kzg-4844, gnark-crypto, PQClean) appear only as test oracles — never linked into shipped libraries — so the byte-equality test retains its adversarial-distance property: a bug on either side fails the test.

The stack covers 29 algorithms across hashes, AEAD, elliptic curves and pairings, post-quantum signatures, lattice primitives, FHE building blocks, threshold schemes, and composite remote-attestation parsers. It satisfies the GPU-residency invariant (LP-5625): no chain-local hot path leaves attested GPU memory in production. The CPU touches reality only at packet ingress, cold-state page service, attestation handshake, and watchdog.

This LP specifies the GPU mode — substrate, build topology, byte-equality contract, residency invariant, C-ABI surface — that all per-algorithm crypto LPs share. It carries no per-algorithm content; each algorithm's formal specification is its own LP in the 4xxx crypto range.

1. Motivation

A fragmented crypto substrate makes the byte-equivalence contract impossible to enforce. Three failure modes this LP closes:

  1. Oracle bypass. When the CPU implementation and the test oracle come from the same upstream family — both from blst, or both from gnark-crypto — the byte-equality test loses its adversarial distance: an upstream bug passes through both sides and the test reports agreement. First-party CPU plus an audited independent test oracle is the correct adversarial structure; a bug on either side fails the test.
  2. Vendor symbol leak. Production binaries that link blst, mcl or BoringSSL into the production graph re-expose vendor branding and tie the security boundary to upstream release cycles. Those libraries are pinned to test-only oracles at <alg>/test/cmake/.
  3. Namespace fragmentation. Per-org symbol prefixes (LUX_*, LUXFI_*, HANZO_*) make one algorithm look like five different libraries. The algorithm name is the namespace.

2. Specification

2.1 Per-algorithm architecture

CPU = first-party canonical, byte-equal to the Go reference. GPU = first-party Metal/CUDA/WGSL, byte-equal to CPU. Audited upstreams = vendored TEST ORACLES ONLY.

                 +---------------------+
                 |  Reference (Go)     |
                 |  gnark-crypto, etc. |
                 +----------+----------+
                            |
                       byte-equal
                            |
                 +----------v----------+
                 |  CPU canonical      |
                 |  vendored audited   |  <-- ground truth
                 |  (mcl, blst, ...)   |
                 +----------+----------+
                            |
                       byte-equal
                            |
        +-------------------+-------------------+
        |                   |                   |
+-------v------+    +-------v------+    +-------v------+
|  Metal       |    |  CUDA        |    |  WGSL        |
|  first-party |    |  first-party |    |  first-party |
+--------------+    +--------------+    +--------------+

Per-algorithm target structure:

  • luxcpp/crypto/<alg>/cpp/<alg>.cpp — first-party C++ CPU body.
  • luxcpp/crypto/<alg>/c-abi/c_<alg>.cpp — production C-ABI shim; dispatches to cpp/, never NOTIMPL once wired.
  • luxcpp/crypto/<alg>/gpu/metal/<alg>.metal — first-party Metal kernel.
  • luxcpp/crypto/<alg>/gpu/cuda/<alg>.cu — first-party CUDA kernel.
  • luxcpp/crypto/<alg>/gpu/wgsl/<alg>.wgsl — first-party WGSL kernel.
  • luxcpp/crypto/<alg>/test/cmake/<oracle>.cmake — pinned vendor oracle (blst, c-kzg-4844, bitcoin-core/secp256k1) used at test-link only.
  • luxcpp/crypto/<alg>/test/<alg>_metal_test.{cpp,mm} — N = 100…1000 random-input determinism harness asserting byte-equality.

The four-kernel canonical template, formalized at luxcpp/crypto/gpukit/:

expand_inputs   →   parallel_eval   →   reduce_or_batch_verify   →   commit_root

Step 1 hoists per-input scratch into device-resident arenas. Step 2 fans one thread per input. Step 3 reduces partials — Merkle leaf hashes, MSM windows, batch-pairing folds — parallel where associative, serial where not. Step 4 emits the commitment in canonical order, single-threaded by design: it is the determinism oracle.

Lane-0-leader audit

The 42 if (tid != 0u) return; sites across the codebase classify as:

ClassCountReason
Canonical fold (commit_root, step 4)23byte-equivalent across CPU/Metal/CUDA/WGSL by canonical-order Keccak
Canonical locate / collision-resolved slot4must match the CPU oracle across collision sequences
Round-by-round protocol (one-thread canonical)5round N depends on round N−1's transcript
Batch-inversion serial chain (Montgomery)2algorithmic — the chain is the reduction
Final reduction (single output)4single-element tower output
Wave-tick service-drain leader4architectural choice, §wave scheduler

Zero parallelization-opportunity hits. Every lane-0 leader is structural, not deferred work. This distinction is what makes the audit worth running: a serialization point that exists because the algorithm is serial is correct; one that exists because nobody parallelized it is debt.

2.2 Repository and namespace layout

OrgReposPurpose
luxfi/*crypto, mpc, threshold, hsm, lattice, evm, evmgpu, chains, gpu, lpsGo canonical implementations, Rust workspace, LP specs
luxcpp/*crypto, lattice, cevm, fhe, platformvm, xvm, aivm, bridgevm, mpcvm, accel, lux-cuda, lux-gpu, lux-metal, lux-webgpuC++ canonical bodies plus Metal/CUDA/WGSL kernels
luxgpu/*reservedFuture C++ GPU kernel source repos

luxfi/gpu is canonical for Go GPU bindings.

2.3 Performance claim ledger

Reproduced on Apple M1 Max, median of ≥ 10 runs.

ClaimReproducedSource
BLS fused 148.35× (warm-affine, n=1024)144.22× — linear-affine 386,285 µs / fused-affine 2,678.5 µs; fused critical path = 4 dispatchescrypto/bls/cpp/bls_fused.cpp
FHE Metal NTT 16.71× (N=4096, B=2048)16.92× — Metal 9.71 ms / Go 164.27 ms; 10-iteration median, kernel-onlylattice; fhe/bench/results/ntt_ladder_*.json
bn254 KAT 36/36 vs gnark v0.19.2; e(P,Q)·e(P,−Q) = 1bn254_kat_test reports 36 passed, 0 failed; go.mod pins gnark-crypto v0.19.2bn254/test/tools/
Banderwagon Pippenger KAT MultiExpConfig{ScalarsMont:true}verifiedbanderwagon/test/tools/gen_multiexp_kat.go
BLS aggregate verify, same message, n=10249.24× batched → 16.51× with pubkey cache; 73.91 µs/sigcevm/BENCHMARKS.md
BridgeVM batched real pairing, 5k–10k messages8.58×–10.35×, mean 9.5×bridgevm/BENCHMARKS.md
MPCVM xlarge ceremony18.6× Metal — 9,451 ms → 507 msmpcvm/BENCHMARKS.md
MPCVM threshold sign, 5-of-74.23× — 204.3 ms → 48.3 ms Metalmpcvm/BENCHMARKS.md
Keccak per-round dedup4-way set-associative round cache, ≥ 0.50 hit ratecrypto/keccak/gpu/metal/keccak.metal
ed25519 RFC 8032 byte-equal MetalN_threshold = 256, 26.7× at N=4096; 100 vectors byte-equal (4 spec + 96 byte-flip)crypto/ed25519/test/ed25519_metal_test.mm

Inflated claims, corrected

A performance ledger is only trustworthy if it also records what did not reproduce. These claims were made and are hereby retracted:

Original claimRealityOff by
"every algorithm has CPU↔GPU determinism"3 of 32 algorithms have unconditional GPU tests; 6 of 8 *_metal_test* gate on a LUX_CRYPTO_*_METALLIB environment variable and stub-pass when it is unset9.4% real, not "every"
"240 → 24 brand-neutral residuals"380 hits across 78+ files; closure pending the brand-neutral sweep16× higher
"23 publish-ready Rust crates"the workspace declares 3 members — lux-crypto, lux-crypto-keccak, lux-crypto-secp256k1; cargo publish --dry-run fails on a missing README7.7× off
"AEAD AES-GCM Metal 26.7× at N=8192"cipher misattributed — the measured commit is ChaCha20-Poly1305; AES-GCM was added later. The 26.7× figure appears only in a commit message and docs, with no bench JSON, and aead_metal_bench skips without its metallibnot currently reproducible
"BatchEvaluate 4.61× under -race"the bench process ran over 13 minutes wall-clock at 558 MB resident without output on M1 Max; the in-tree harness is correct, the number is commit-message-onlyunverifiable on M1

A test that stub-passes when its environment variable is unset is the sharpest item on this list: it converts "not run" into "green", which is worse than a failure because nobody investigates it.

2.4 Pedersen domain-separation tags

Domain-separation tags are algorithm-named, never org-prefixed:

NewGenerators G          → PEDERSEN_G_V1
NewGenerators H          → PEDERSEN_H_V1
NewGeneratorsFromSeed    → PEDERSEN_SEEDED_GEN_V1

Hash-to-curve: BN254 G1 via RFC 9380 SVDW; cofactor 1, no clearing. Seed format for FromSeed is msg_i = seed[32] || u64_le(i).

Golden vectors, seed = [0, 1, …, 31]:

G[0..31] = c563aa8a283f268b65b4210a0a78ee1341f76b59d94c1ac626effe1a5aa0c6b7
H[0..31] = e9ebf4392683dcb418584dd8ecd1e1dd16b486147e676dbf4b62779a340f3186

The C++ body MUST hard-code the DST string PEDERSEN_SEEDED_GEN_V1 and reproduce the G/H bytes byte for byte. KAT harness: pedersen/pedersen_seed_test.go::TestNewGeneratorsFromSeed_GoldenVector.

2.5 MSM is variable-time — the caller audit

Banderwagon Pippenger MSM is variable-time. Five prover-side callers consuming secret scalars are blinded via MultiExpBlinded — Pedersen-style scalar re-randomization before the MSM, unblinding after. Three verifier-side callers over public scalars remain unchanged; public scalars do not require a constant-time MSM.

Categorization rule. Any caller that consumes a secret scalar — witness, key share, signing nonce — MUST use MultiExpBlinded. Verification over public-input batched scalars uses MultiExp directly.

This is a per-caller property, not a per-primitive one, which is why it needs an audit rather than a flag: the same MSM routine is correct in one call site and a timing oracle in the next.

2.6 Threshold FHE — unsafe, and why it fails closed

Status: security blocker. The current luxfi/threshold/protocols/tfhe is not a threshold scheme. It is master-key replication wrapped in HMAC theatre. Three independent failures:

  1. KeyGenerator.GenerateKeys — every party receives UnderlyingKey: masterSK. Shamir sharing is not happening.
  2. PartialDecrypter.PartialDecrypt — returns an HMAC tag fingerprinting (party, session, ciphertext). No lattice operation, no noise, no relation to the ciphertext's content.
  3. Protocol.CombineShares — calls single-party decryptor.DecryptUint64 against the master-key copy and ignores p.shares entirely.

Compensating controls, in force:

  • Top-of-file UNSAFE warnings in tfhe.go and committee.go.
  • Panic guards on all four entry points (KeyGenerator.GenerateKeys, PartialDecrypter.PartialDecrypt, Protocol.CombineShares, NewProtocol). All panic in production.
  • Tests opt in via LUX_ALLOW_FAKE_TFHE_FOR_TESTING_ONLY=1, set in a package-level TestMain.
  • No environment-variable override for production.

Production callers:

FileSymbolRisk
mpc/pkg/mpc/tfhe_session.gotfhe.NewKeyGeneratorkeygen panic in regulated MPC sessions
mpc/pkg/mpc/tfhe_session.gotfhe.NewProtocolevery TFHE compute session crashes
mpc/pkg/mpc/tfhe_session.go(*tfheComputeSession).GetProtocolre-exposes the broken Protocol to MPC callers

Confidential lanes and on-chain FHE policy MUST NOT be enabled while the panic guards are in force — they will tombstone the relevant MPC node. That is intentional: a loud crash beats a silent non-threshold decryption.

Real-implementation contract (Go, package tfhe):

// GenerateShares performs t-of-n distributed key generation.
// share_i is a Shamir polynomial evaluation at point x_i, NOT the master key.
GenerateShares(ctx, t, n int, sessionID [32]byte) (
    pk *fhe.PublicKey, shares map[party.ID]*SecretKeyShare, err error)

// PartialDecrypt produces party_i's lattice contribution.
// partial_i = a_i * s_i + e_i (BFV/CKKS partial-decryption sense).
// MUST NOT return an HMAC tag.
PartialDecrypt(ctx, share *SecretKeyShare, ct *fhe.BitCiphertext) (
    *PartialDec, error)

// CombineShares Lagrange-interpolates t partials at x = 0.
// MUST NOT call decryptor.DecryptUint64.
CombineShares(ctx, ct *fhe.BitCiphertext, partials []*PartialDec) (
    cleartext []byte, err error)

The *fhe.SecretKey field on SecretKeyShare is removed. There is no master-key copy on any party.

Path to a real implementation:

StageActionEffortRisk
0UNSAFE markers and panic guards landshippednone
1pkg/lattice/threshold exposes Shamir, partial-decrypt and combine1–2 weeksmedium
2Replace protocols/tfhe/tfhe.go internals with lattice calls1 weekmedium
3Cryptographer review — at least one reviewer with a prior threshold-FHE publication4–6 weekshigh
4Remove panic guards and the test-only environment variable1 weeklow
5Re-enable confidential lanes and on-chain FHE policy1 weeklow

Total 6–10 weeks, gated on cryptographer availability.

2.7 Attestation architecture

Two layers, split by responsibility:

  • C++ parsers (luxcpp/crypto/attestation/cpp/): parser only. Decode SEV-SNP, TDX and NVIDIA NRAS / RIM into structured fields. Signature verification is the caller's responsibility.
  • Go full-chain (luxd/cc/attest/): full chain verification. Production SEV-SNP via go-sev-guest — signature, chain and revocation. TDX and NRAS ship as stubs pending host-side keys and RIM endpoint contracts.

Composite attestation root: 11 + 16 = 27 byte-equal C++ ↔ Go test cases.

require_* flags replace the "wildcards-on-zero" pattern: explicit require_sev_snp, require_tdx, require_nv_nras booleans on CompositeAttestationConfig. Zero-byte fields no longer wildcard — a fail-open default in an attestation config is a hole, not a convenience.

Fixtures are genuine: attestation/test/fixtures/ carries real SEV-SNP report blobs from AMD reference machines, TDX quotes from Intel SGX-DCAP test vectors, and NV NRAS responses from documented NVIDIA test endpoints. A second, independent oracle keeps byte-equality from collapsing into self-comparison.

2.8 Namespace neutrality

  • DST strings are algorithm-named: PEDERSEN_SEEDED_GEN_V1, not LUX_PEDERSEN_SEEDED_GEN_V1.
  • C-ABI symbols are algorithm-prefixed: bls12_381_pairing_check, not lux_bls_pairing.
  • Header guards, macros and namespaces are algorithm-named throughout luxcpp/crypto/<alg>/.
  • Production binaries link zero _blst_* symbols, CI-asserted (§4.2). blst is pinned to crypto/bls/test/cmake/blst.cmake, test oracle only.

3. GPU classification

3.1 Substrate geometric mean

Measured on Apple M1 Max, against the CPU reference:

PhaseSubstrate-wide geomean
Phase 1 (initial)0.17×
Phase 2 (BLS batched)0.90×
Phase 2.5 (BLS pubkey cache)0.97×
Phase 3parity neighbourhood

Three measured production workloads beat CPU end to end:

  • F-Chain NTT: 23.6× at N=4096, B=128
  • B-Chain BLS aggregate: 9.5× mean across 5k–10k messages
  • C-Chain BLS aggregate, same message: 16.51× with pubkey cache, n=1024

Two architecturally correct chains lag on M1, pending a discrete GPU:

  • PlatformVM 0.025× — the saved per-thread work is matched by ~1 ms of M1 dispatch overhead. The substrate is durable for discrete CUDA, where per-dispatch latency is ~10 µs.
  • AIVM 0.06× — the locate-plus-writeback split is correct; M1 integrated-GPU dispatch overhead dominates.

Reporting a 0.025× is the point. A substrate that only publishes its wins cannot tell an architecture problem from a hardware one.

3.2 Per-primitive GPU class

Across 29 primitives plus helpers and composites:

ClassCountMembers
A — GPU-native today10sha256, keccak, ripemd160, blake2b, secp256k1, bls, ed25519, mldsa (skeleton), mlkem (skeleton), poly_mul (plus ntt via the FHE backend)
B — GPU-feasible, body shipped, kernel pending3ipa, pedersen, verkle
C — structurally CPU-only / round-by-round4attestation parsers, frost (intra-ceremony), cggmp21 (intra-ceremony), corona (intra-proof Fiat-Shamir)
D — NOTIMPL, no CPU body authored6blake3 (was fold-aliased to keccak in an old shim — a bug, fixed), sr25519, slhdsa, lamport, poseidon, aead
E — bootstrap-blocked, C++ body needs intx / blst / evmmax5bn254, secp256r1, kzg, modexp, evm256

Of working primitives (denominator = 11 with a shipped CPU body): 6 of 10 Metal-shipping = 60% pure GPU-native. Counting FHE-backed NTT and the four class-C intra-ceremony primitives whose cross-ceremony batch is template-fit, the residency-correct fraction is 8 of 10 = 80% GPU-native at the architectural ceiling.

All 29 remain template-fit at the algorithmic level. The bound is set by NOTIMPL body authoring (13 of 29) and intx / blst / evmmax bootstrap (5 of 29), not by parallelization shape.

3.3 Acceleration kernels

Per-target speedup kernels applied across the 29 primitives. Each kernel has its own specification covering the algorithm, the three-backend implementation paths (Metal, CUDA, WGSL), the determinism harness, and the crossover threshold.

KernelPrimary consumersProjected speedup
Batched Montgomery inversion (three-backend uniform)secp256k1, BN254, BLS, Banderwagon14× measured on M1; 38–55× projected on CUDA
Multi-curve Pippenger MSM (one templated body)all MSM consumers1.0–1.4×, plus ~3,200 LOC consolidated
Combined-pair Miller loopBLS aggregate verify, BridgeVM batched pairing3.18× at k=4; 9.5× measured at k=1024
Karatsuba modexp at M_len ≥ 2048EIP-198, RSA attestation2.41× at 4096-bit
Six-step NTT for N up to 2²⁰ML-DSA-87, TFHE bootstrap6.8–9.2× at N=2²⁰
Pedersen tree-reduce vector commitVerkle width-256, IPA inner product6.0–6.4× over linear
Threshold batch pre-signM-Chain (MPCVM), B-Chain (BridgeVM)5.0–7.2× at M=7, N=64

Each kernel records the threshold N* below which CPU is faster; the substrate dispatcher routes through the per-kernel crossover table at luxcpp/crypto/CROSSOVER.md. Where the underlying algorithm is variable-time in a secret scalar — Pippenger, Karatsuba windowing, threshold nonce generation — the kernel spec enumerates the constant-time or blinded path the prover-side caller MUST use.

4. Security Considerations

4.1 Threshold FHE fails closed

luxfi/threshold/protocols/tfhe panic-guards every entry point. Confidential lanes and on-chain FHE policy are closed until the real Shamir + lattice + combine pipeline lands (§2.6).

A no-blst-in-production check runs after every cevm build:

build/lib/libevm.dylib
build/lib/libevm.so
build/lib/cevm_precompiles/libcevm_precompiles.a
build/lib/evm/libevm-precompiles.a
build/lib/evm/libevm-kernel-metal.a
build/lib/evm/libevm-gpu.a
build/lib/evm/libevm-metal-hosts.a
build/lib/evm/libprecompile-service.a

Every binary above MUST report zero _blst_* symbols. This is the mechanical enforcement of §1's oracle-bypass rule: if an oracle library reaches a shipped binary, the byte-equality test has been comparing a library against itself.

4.3 Subgroup policy

enum class SubgroupPolicy {
    AssumeChecked,
    CheckAndReject,
    ClearIfHashToCurve   // ONLY for hash-to-curve outputs
};

Validator public keys are checked and rejected, never modified. Cofactor clearing applies to hash-to-curve outputs and only where the relevant specification requires it. Silently clearing a cofactor on an input you were handed converts an invalid key into a valid one, which is the small-subgroup attack with extra steps.

5. Rationale — the irreversible decisions

  • First-party CPU plus an audited, independent test oracle. Vendoring a CPU canonical from the same family as the test oracle was rejected: it destroys adversarial distance.
  • bn254 first-party, not mcl. A 2,498-LOC first-party C++ body, byte-equal to gnark v0.19.2 across 36 KAT vectors. mcl was rejected for the same adversarial-distance reason.
  • luxfi/gpu is canonical for Go bindings. The luxgpu org is reserved for future C++ GPU kernel source repositories only.
  • Namespace neutrality. Algorithm names are the namespace. No org-prefixed DSTs, symbols, headers or namespaces on production paths.
  • Threshold FHE fails closed. Panic guards, no environment-variable override in production, and an opt-in only for tests.
  • Explicit require_* flags over wildcards-on-zero. A default that means "no requirement" must be spelled, not inferred from a zero byte.
  • lux/accel is CPU + GPU dispatch, not GPU-only. It stays in the luxfi org; it is not a luxgpu candidate.

6. Known limitations

Two honest blockers, recorded so they are not rediscovered:

  • Batched Metal NTT crashes. luxcpp/lattice/src/metal/metal_ntt.mm segfaults at every (N, B). Without batch mode, single-polynomial Metal NTT is ~12× slower than CPU on M1 Max. Estimated ~1 week of Objective-C++ debugging.
  • Batch-bootstrap Metal kernel is unwritten. This is the single largest FHE-on-M1 win and a prerequisite for FHE in any block-time-bounded path. Estimated ~6 weeks, plus a Metal kernel author, plus rewriting the gadget chain in standard form. It blocks confidential lanes and on-chain FHE policy on the hot path.

Copyright (C) 2026, Lux Industries Inc. CC0-1.0.