GPU-Native Crypto Stack
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
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:
- 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.
- 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/. - 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 tocpp/, neverNOTIMPLonce 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:
| Class | Count | Reason |
|---|---|---|
Canonical fold (commit_root, step 4) | 23 | byte-equivalent across CPU/Metal/CUDA/WGSL by canonical-order Keccak |
| Canonical locate / collision-resolved slot | 4 | must match the CPU oracle across collision sequences |
| Round-by-round protocol (one-thread canonical) | 5 | round N depends on round N−1's transcript |
| Batch-inversion serial chain (Montgomery) | 2 | algorithmic — the chain is the reduction |
| Final reduction (single output) | 4 | single-element tower output |
| Wave-tick service-drain leader | 4 | architectural 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
| Org | Repos | Purpose |
|---|---|---|
luxfi/* | crypto, mpc, threshold, hsm, lattice, evm, evmgpu, chains, gpu, lps | Go canonical implementations, Rust workspace, LP specs |
luxcpp/* | crypto, lattice, cevm, fhe, platformvm, xvm, aivm, bridgevm, mpcvm, accel, lux-cuda, lux-gpu, lux-metal, lux-webgpu | C++ canonical bodies plus Metal/CUDA/WGSL kernels |
luxgpu/* | reserved | Future 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.
| Claim | Reproduced | Source |
|---|---|---|
| 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 dispatches | crypto/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-only | lattice; fhe/bench/results/ntt_ladder_*.json |
bn254 KAT 36/36 vs gnark v0.19.2; e(P,Q)·e(P,−Q) = 1 | bn254_kat_test reports 36 passed, 0 failed; go.mod pins gnark-crypto v0.19.2 | bn254/test/tools/ |
Banderwagon Pippenger KAT MultiExpConfig{ScalarsMont:true} | verified | banderwagon/test/tools/gen_multiexp_kat.go |
| BLS aggregate verify, same message, n=1024 | 9.24× batched → 16.51× with pubkey cache; 73.91 µs/sig | cevm/BENCHMARKS.md |
| BridgeVM batched real pairing, 5k–10k messages | 8.58×–10.35×, mean 9.5× | bridgevm/BENCHMARKS.md |
| MPCVM xlarge ceremony | 18.6× Metal — 9,451 ms → 507 ms | mpcvm/BENCHMARKS.md |
| MPCVM threshold sign, 5-of-7 | 4.23× — 204.3 ms → 48.3 ms Metal | mpcvm/BENCHMARKS.md |
| Keccak per-round dedup | 4-way set-associative round cache, ≥ 0.50 hit rate | crypto/keccak/gpu/metal/keccak.metal |
| ed25519 RFC 8032 byte-equal Metal | N_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 claim | Reality | Off 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 unset | 9.4% real, not "every" |
| "240 → 24 brand-neutral residuals" | 380 hits across 78+ files; closure pending the brand-neutral sweep | 16× 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 README | 7.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 metallib | not 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-only | unverifiable 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:
KeyGenerator.GenerateKeys— every party receivesUnderlyingKey: masterSK. Shamir sharing is not happening.PartialDecrypter.PartialDecrypt— returns an HMAC tag fingerprinting(party, session, ciphertext). No lattice operation, no noise, no relation to the ciphertext's content.Protocol.CombineShares— calls single-partydecryptor.DecryptUint64against the master-key copy and ignoresp.sharesentirely.
Compensating controls, in force:
- Top-of-file UNSAFE warnings in
tfhe.goandcommittee.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-levelTestMain. - No environment-variable override for production.
Production callers:
| File | Symbol | Risk |
|---|---|---|
mpc/pkg/mpc/tfhe_session.go | tfhe.NewKeyGenerator | keygen panic in regulated MPC sessions |
mpc/pkg/mpc/tfhe_session.go | tfhe.NewProtocol | every TFHE compute session crashes |
mpc/pkg/mpc/tfhe_session.go | (*tfheComputeSession).GetProtocol | re-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:
| Stage | Action | Effort | Risk |
|---|---|---|---|
| 0 | UNSAFE markers and panic guards land | shipped | none |
| 1 | pkg/lattice/threshold exposes Shamir, partial-decrypt and combine | 1–2 weeks | medium |
| 2 | Replace protocols/tfhe/tfhe.go internals with lattice calls | 1 week | medium |
| 3 | Cryptographer review — at least one reviewer with a prior threshold-FHE publication | 4–6 weeks | high |
| 4 | Remove panic guards and the test-only environment variable | 1 week | low |
| 5 | Re-enable confidential lanes and on-chain FHE policy | 1 week | low |
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 viago-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, notLUX_PEDERSEN_SEEDED_GEN_V1. - C-ABI symbols are algorithm-prefixed:
bls12_381_pairing_check, notlux_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 tocrypto/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:
| Phase | Substrate-wide geomean |
|---|---|
| Phase 1 (initial) | 0.17× |
| Phase 2 (BLS batched) | 0.90× |
| Phase 2.5 (BLS pubkey cache) | 0.97× |
| Phase 3 | parity 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:
| Class | Count | Members |
|---|---|---|
| A — GPU-native today | 10 | sha256, keccak, ripemd160, blake2b, secp256k1, bls, ed25519, mldsa (skeleton), mlkem (skeleton), poly_mul (plus ntt via the FHE backend) |
| B — GPU-feasible, body shipped, kernel pending | 3 | ipa, pedersen, verkle |
| C — structurally CPU-only / round-by-round | 4 | attestation parsers, frost (intra-ceremony), cggmp21 (intra-ceremony), corona (intra-proof Fiat-Shamir) |
| D — NOTIMPL, no CPU body authored | 6 | blake3 (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 / evmmax | 5 | bn254, 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.
| Kernel | Primary consumers | Projected speedup |
|---|---|---|
| Batched Montgomery inversion (three-backend uniform) | secp256k1, BN254, BLS, Banderwagon | 14× measured on M1; 38–55× projected on CUDA |
| Multi-curve Pippenger MSM (one templated body) | all MSM consumers | 1.0–1.4×, plus ~3,200 LOC consolidated |
| Combined-pair Miller loop | BLS aggregate verify, BridgeVM batched pairing | 3.18× at k=4; 9.5× measured at k=1024 |
Karatsuba modexp at M_len ≥ 2048 | EIP-198, RSA attestation | 2.41× at 4096-bit |
| Six-step NTT for N up to 2²⁰ | ML-DSA-87, TFHE bootstrap | 6.8–9.2× at N=2²⁰ |
| Pedersen tree-reduce vector commit | Verkle width-256, IPA inner product | 6.0–6.4× over linear |
| Threshold batch pre-sign | M-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).
4.2 The production-link symbol invariant
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/gpuis canonical for Go bindings. Theluxgpuorg 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/accelis CPU + GPU dispatch, not GPU-only. It stays in theluxfiorg; it is not aluxgpucandidate.
6. Known limitations
Two honest blockers, recorded so they are not rediscovered:
- Batched Metal NTT crashes.
luxcpp/lattice/src/metal/metal_ntt.mmsegfaults 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
Copyright (C) 2026, Lux Industries Inc. CC0-1.0.