Files
zeekay fae2d6ad56 crypto/merkle: canonical tagged binary Merkle state-root (keccak-256)
Native-Go authority for the Lux VM state roots — the byte-for-byte
reference the GPU accelerators (CUDA/HIP/Metal/Vulkan/WGSL) match.

- crypto/hash/keccak.go: ComputeKeccak256{,Array} via
  sha3.NewLegacyKeccak256 (Ethereum Keccak-256, 0x01 pad) — NOT
  sha3.Sum256 (FIPS-202 SHA3, 0x06 pad), which would diverge from the
  GPU kernels and split consensus.
- crypto/merkle: Root/LeafHash/NodeHash/EmptyRoot. leaf=keccak(0x00|d),
  node=keccak(0x01|L|R), RFC-6962 lone-right promotion, keccak256("")
  empty root. Shape depends only on leaf count -> bit-identical to the
  gpu-kernels lux::merkle::merkle_root spec across all backends.

Reproduces the spec's 7 canonical KAT vectors byte-for-byte
(n=0,1,2,3,4,5,8). CGO_ENABLED=0 clean, pure-Go, luxfi deps only.
Computation + tests ONLY — consensus wiring (fill xvm StandardBlock.Root
+ executor activation gate) is the separate next phase.
2026-06-15 13:57:24 -07:00

35 lines
1.0 KiB
Go

// Copyright (C) 2020-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package hash
import (
// Ethereum Keccak-256 (0x01 domain pad), NOT FIPS-202 SHA3-256 (0x06 pad).
// NewLegacyKeccak256 is the legacy (pre-standardization) Keccak that every
// Lux GPU backend and EVM-compatible consumer hashes against; sha3.Sum256
// would diverge byte-for-byte. Do not swap it.
"golang.org/x/crypto/sha3"
)
// KeccakSize is the byte length of a Keccak-256 digest.
const KeccakSize = 32
// ComputeKeccak256Array computes the Ethereum Keccak-256 hash of the
// concatenation of the input byte slices.
func ComputeKeccak256Array(data ...[]byte) [KeccakSize]byte {
h := sha3.NewLegacyKeccak256()
for _, b := range data {
h.Write(b)
}
var out [KeccakSize]byte
h.Sum(out[:0])
return out
}
// ComputeKeccak256 computes the Ethereum Keccak-256 hash of the concatenation
// of the input byte slices.
func ComputeKeccak256(data ...[]byte) []byte {
out := ComputeKeccak256Array(data...)
return out[:]
}