mirror of
https://github.com/luxfi/precompile.git
synced 2026-09-24 00:26:21 +00:00
Under the enable-everything precompile policy these verify-only precompiles are no longer refused under strict-PQ, so any divergence between the luxfi/accel GPU/SIMD path and the pure-CPU path is a LIVE consensus split: GPU-equipped and CPU-only validators would return different verify verdicts on the same input and the chain forks. Several accel paths were also outright wrong-primitive forgery surfaces. LAW applied: the GPU verdict must be byte-identical to the CPU verdict on every input, or the accel path is a consensus hazard and is removed. CPU (pure-Go, CGO_ENABLED=0) is now the single source of truth for every on-chain verdict. None of these GPU kernels can be proven byte-identical here, and several are provably NOT, so every verdict-trusting accel branch is deleted and routed to the canonical CPU verifier. Determinism over speed. Active forgery/wrong-output in the DEFAULT build (accelcrypto CPU fallback leaked non-CPU semantics, err==nil): - sr25519: verified via the accel Ed25519 kernel -> a valid Ed25519 signature was ACCEPTED as a valid sr25519/Schnorrkel signature (wrong-curve forgery). - blake3: accelcrypto.Hash(HashBlake3) returns BLAKE2b, not BLAKE3; the "real blake3" fallback was dead code. OpHash256 + MerkleRoot emitted BLAKE2b. Latent splits (reachable only under -tags accel + a GPU backend): - frost: FROST-Schnorr verified through the SigECDSA kernel (wrong primitive + 32B x-only key mis-framed as a 33B ECDSA key). - cggmp21: SigECDSA kernel truncated the 65B key to 33B and skipped the CPU path's recover-and-compare binding (ignored the v byte). - ed25519: GPU Ed25519 kernel not proven byte-identical to the canonical verifier on cofactor / non-canonical-S / small-order edge cases. - secp256r1: P-256 inputs sent to the fixed-curve secp256k1 ECDSA kernel. - mldsa: GPU verified with EMPTY context; precompile binds the FIPS-204 ctx "lux-evm-precompile-mldsa-v1" -> different mu, different verdict. - bls12381 / zk(groth16): GPU MSM result trusted without re-verification and with no curve binding carried to the kernel. - kzg4844: GPU commitment used the backend's OWN embedded trusted setup (empty SRS) instead of the canonical EIP-4844 SRS -> breaks KZG binding. - ai_mining (BatchVerifyMLDSA/BatchAccumulator): accel batch kernel truncates messages to 32 bytes and is mode-fixed -> diverges from VerifyMLDSA. - fhe: GPU computed BFV arithmetic while CPU computes TFHE (different scheme, incompatible ciphertext, nil relin key) -> corrupt + divergent ciphertext. Cleanups (no split, vestigial): removed dead mlkem encapsulateGPU; removed the hpke GPU pre-warm that discarded its result and returned the CPU output anyway. slhdsa was already CPU-only (prior identical fix). Tests (differential / forgery proofs, all green CGO_ENABLED=0 and CGO -race): - sr25519: a valid Ed25519 sig is now REJECTED; real sr25519 still verifies. - blake3: OpHash256/MerkleRoot output == BLAKE3 and != BLAKE2b. - cggmp21: flipped recovery byte is rejected (recover-compare authoritative). - frost: a valid ECDSA sig is rejected as FROST-Schnorr. - ed25519: verdict matches the canonical ed25519.Verify oracle over 64x4 vectors. - mldsa: empty-ctx sig (the accel framing) rejected; precompileCtx sig accepted. Net -593 LOC. No consensus code touched.
63 lines
2.5 KiB
Go
63 lines
2.5 KiB
Go
// Copyright (C) 2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package sr25519
|
|
|
|
import (
|
|
stded25519 "crypto/ed25519"
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
"github.com/luxfi/geth/common"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestSR25519_RejectsEd25519Forgery is the regression proof for the
|
|
// wrong-curve accel divergence: the precompile used to route through
|
|
// luxfi/accel's Ed25519 GPU kernel ("closest GPU kernel"), so a *valid
|
|
// Ed25519* signature (same 32-byte key / 64-byte sig shape) was accepted as a
|
|
// valid sr25519/Schnorrkel signature, and accel-equipped validators returned
|
|
// a different verdict than CPU-only ones.
|
|
//
|
|
// sr25519 is Schnorrkel over Ristretto255 with a Merlin "substrate"
|
|
// transcript; an Ed25519 signature can never satisfy that verification
|
|
// equation. After the fix the precompile MUST reject this input.
|
|
func TestSR25519_RejectsEd25519Forgery(t *testing.T) {
|
|
pub, priv, err := stded25519.GenerateKey(rand.Reader)
|
|
require.NoError(t, err)
|
|
|
|
msg := []byte("cross-scheme forgery: an ed25519 signature presented as sr25519")
|
|
sig := stded25519.Sign(priv, msg)
|
|
|
|
// The input is, by construction, a genuinely valid Ed25519 signature with
|
|
// the exact byte-shape sr25519 expects -- precisely what the deleted accel
|
|
// (Ed25519 kernel) path verified and accepted.
|
|
require.True(t, stded25519.Verify(pub, msg, sig),
|
|
"vector must be a valid Ed25519 signature (the input the accel path accepted)")
|
|
require.Len(t, []byte(pub), PublicKeySize)
|
|
require.Len(t, sig, SignatureSize)
|
|
|
|
input := buildInput(pub, sig, msg)
|
|
gas := SR25519VerifyPrecompile.RequiredGas(input)
|
|
result, _, err := SR25519VerifyPrecompile.Run(
|
|
nil, common.Address{}, ContractAddress, input, gas, true,
|
|
)
|
|
require.NoError(t, err)
|
|
require.Equal(t, byte(0), result[31],
|
|
"FORGERY: ed25519 signature must NOT verify as sr25519 (wrong-curve acceptance closed)")
|
|
}
|
|
|
|
// TestSR25519_RealSignatureStillVerifies pins the positive direction: the CPU
|
|
// Schnorrkel path (now the single source of truth) still accepts Alice's
|
|
// genuine sr25519 signature. Together with the forgery test this proves the
|
|
// verdict is the CPU verdict, byte-stable across the validator set.
|
|
func TestSR25519_RealSignatureStillVerifies(t *testing.T) {
|
|
input := buildInput(alicePubKey, aliceSignature, aliceMessage)
|
|
gas := SR25519VerifyPrecompile.RequiredGas(input)
|
|
result, _, err := SR25519VerifyPrecompile.Run(
|
|
nil, common.Address{}, ContractAddress, input, gas, true,
|
|
)
|
|
require.NoError(t, err)
|
|
require.Equal(t, byte(1), result[31], "genuine sr25519 signature must verify")
|
|
}
|