Documentation
¶
Overview ¶
Package gpu is the one place a Lux chain asks for a primitive.
The boundary ¶
Kernels are private and live in their own repository. This package contains no kernel source and never will: what crosses the line is a C ABI — four symbol names — opened at run time if the library happens to be installed.
The rule ¶
The CPU backend is COMPLETE. A node with nothing installed computes every primitive itself and is a full node, not a degraded one. The plugin is a strict positive overlay: it may only ever be faster, never different. Two backends that disagree about a hash disagree about a block, so every plugin answer is either byte-identical to the CPU answer or a bug.
The knob ¶
LUX_GPU picks the policy, once, at first use:
off CPU only; nothing is opened.
on plugin for batch work when a library is installed. The default,
and it degrades to off on its own when nothing is installed.
verify compute BOTH and stop on the first byte that differs.
LUX_GPU_LIB names the library path when it is not on the loader's path.
What actually has two paths ¶
- Keccak256Batch — CPU and plugin (lux_gpu_keccak256_batch), and so MerkleRoot, which is a batch of keccaks per level.
- Sha256, Ripemd160 — CPU only. The plugin ABI has no such op: its hash surface is keccak256, SHA3-256, SHAKE256, BLAKE3, Poseidon2, and SHA3-256 is not SHA-256.
- Recover — CPU only. The plugin's lux_gpu_ecrecover_batch answers a different question: it returns an Ethereum address, keccak(Q.x‖Q.y)[12:], where a Lux address is ripemd160(sha256(compressed Q)). The recovered key never leaves that call, so its answer cannot be turned into this one's.
A note on CGO ¶
A CGO_ENABLED=0 build has no way to open a shared library, so it never has a plugin. That is the point: it is still a whole node.
Index ¶
- Constants
- func Backend() string
- func Recover(h Hash256, sig [SignatureLen]byte) ([]byte, bool)
- func Same(got, want []Hash256) bool
- type Hash160
- type Hash256
- func CPUKeccak256(parts ...[]byte) Hash256
- func CPUKeccak256Batch(inputs [][]byte) []Hash256
- func EmptyRoot() Hash256
- func Keccak256(parts ...[]byte) Hash256
- func Keccak256Batch(inputs [][]byte) []Hash256
- func LeafHash(d Hash256) Hash256
- func MerkleRoot(leaves []Hash256) Hash256
- func NodeHash(l, r Hash256) Hash256
- func Sha256(b []byte) Hash256
- type Policy
Constants ¶
const ( LeafTag byte = 0x00 NodeTag byte = 0x01 )
The RFC 6962 domain tags. leaf(d) = keccak(0x00 ‖ d), node(L,R) = keccak(0x01 ‖ L ‖ R). They separate the domains, so a leaf preimage can never be read as a node's.
const SignatureLen = 65
SignatureLen is a secp256k1 signature: 64 bytes of (r,s) plus the recovery byte.
Variables ¶
This section is empty.
Functions ¶
func Backend ¶
func Backend() string
Backend names which backend is answering: "cpu", or "plugin:<name>" naming the device the installed library selected for itself.
This is a diagnostic, and it is the honest one: a host with the library installed but no device driver reports "plugin:cpu", not "plugin:cuda".
func Recover ¶
func Recover(h Hash256, sig [SignatureLen]byte) ([]byte, bool)
Recover returns the compressed public key that signed h, or false.
The 65 bytes are r ‖ s ‖ recovery_id, and the answer is the 33-byte compressed SEC1 encoding — the shape a Lux address is derived from, which is not the shape the EVM ecrecover precompile returns.
Types ¶
type Hash160 ¶
type Hash160 = [20]byte
Hash160 is a 160-bit digest — the width of an address.
func PubkeyToAddress ¶
PubkeyToAddress is the address of a public key: RIPEMD-160 of its SHA-256.
type Hash256 ¶
type Hash256 = [32]byte
Hash256 is a 256-bit digest.
func CPUKeccak256 ¶
CPUKeccak256 is Keccak256 with the plugin never consulted.
func CPUKeccak256Batch ¶
CPUKeccak256Batch is Keccak256Batch with the plugin never consulted.
func Keccak256 ¶
Keccak256 is Ethereum Keccak-256 — the 0x01 pad, NOT FIPS-202 SHA3 — over the concatenation of the parts.
One hash is not a batch: there is nothing to parallelise and a dispatch costs more than the answer. This is the CPU backend, always.
func Keccak256Batch ¶
Keccak256Batch is one Keccak-256 per input — the shape that has somewhere else to go.
func MerkleRoot ¶
MerkleRoot folds a dense, already-compacted, ascending leaf-digest list. A lone right node is promoted unchanged rather than paired with itself, which is what keeps two different leaf sets from folding to one root.
A level is a batch: every node on it is independent of every other, which is the only reason a device can help at all. The preimages are built here and hashed together, so the whole level makes one dispatch.