mirror of
https://github.com/luxfi/ai.git
synced 2026-10-30 17:02:43 +00:00
lux/ai had a SECOND attestation system (stubbed NVIDIA nvtrust local verifier + hand-rolled SEV-SNP/TDX byte parsers) parallel to the canonical cc/attest. This decomplects verify from policy: the VERIFY primitive is now the single github.com/luxfi/cc/attest, and only the AI trust-score POLICY lives here. - DELETE pkg/attestation/nvtrust.go: the NvtrustVerifier with its fake verifyCertificateChain/verifySPDMSignature/verifyAgainstRIM and empty nvidiaCCRootCert placeholder. No real crypto was being done. - DELETE the hand-rolled ParseSEVSNPReport/ParseTDXQuote + verifySGX/SEV/TDX quote methods (parallel CPU primitives that duplicated cc/attest). - verify_cc.go (NEW): the bridge to cc/attest. VerifyCPUAttestation delegates CPU TEE verification to cc/attest (real SEV-SNP chain verify; TDX routed; SGX/ARM fail-closed). VerifyGPULocalEvidence runs the cloud-free NVIDIA KindNVTrust verifier (signed-RIM match) and returns a verified GPUAttestation. - attestation.go: KEEPS the AI semantics intact as POLICY ON TOP of the unified verify — trust-score tiers (calculateLocal/SoftwareTrustScore), ModeLocal vs ModeSoftware, IsHardwareCCCapable, DeviceStatus tracking, software-GPU attestation. VerifyGPUAttestation scores a verified attestation (unchanged behaviour ⇒ aivm provider Reputation gating preserved). - go.mod: require the leaf github.com/luxfi/cc (local replace ../cc until tagged). ai gains ZERO luxfi/mpc dependency — confidential-AI stays decoupled from the MPC custody system; attestation is the orthogonal concern both share. Tests: policy tests preserved verbatim; CPU tests reframed to assert real fail-closed delegation; new verify_cc_test proves the KindNVTrust crypto path + trust-score policy end to end. attestation/aivm/cc/rewards all green.
422 lines
12 KiB
Go
422 lines
12 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package attestation
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
ErrInvalidQuote = errors.New("invalid attestation quote")
|
|
ErrInvalidMeasurement = errors.New("measurement mismatch")
|
|
ErrQuoteExpired = errors.New("quote expired")
|
|
ErrUnsupportedTEE = errors.New("unsupported TEE type")
|
|
ErrInvalidSignature = errors.New("invalid signature")
|
|
)
|
|
|
|
// AttestationMode indicates the type of attestation
|
|
// NOTE: This is a BLOCKCHAIN - all attestation is LOCAL, no cloud dependencies
|
|
type AttestationMode uint8
|
|
|
|
const (
|
|
// ModeLocal - Local nvtrust verification (PRIMARY for CC-capable GPUs)
|
|
// Uses SPDM reports, certificate chains, RIM verification - all local
|
|
// Supported: H100, H200, B100, B200, GB200, RTX PRO 6000
|
|
ModeLocal AttestationMode = iota
|
|
|
|
// ModeSoftware - Software attestation for non-CC GPUs
|
|
// Lower trust but allows participation: RTX 5090, DGX Spark (GB10), etc
|
|
ModeSoftware
|
|
|
|
// Legacy aliases for backward compatibility
|
|
ModeHardwareCC = ModeLocal // Deprecated: use ModeLocal
|
|
ModeLocalVerifier = ModeLocal // Deprecated: use ModeLocal
|
|
)
|
|
|
|
// TEEType represents the type of Trusted Execution Environment
|
|
type TEEType uint8
|
|
|
|
const (
|
|
TEETypeUnknown TEEType = iota
|
|
TEETypeSGX // Intel SGX (DCAP)
|
|
TEETypeSEVSNP // AMD SEV-SNP
|
|
TEETypeTDX // Intel TDX
|
|
TEETypeNVIDIA // NVIDIA H100 Confidential Computing
|
|
TEETypeARM // ARM CCA
|
|
)
|
|
|
|
func (t TEEType) String() string {
|
|
switch t {
|
|
case TEETypeSGX:
|
|
return "SGX"
|
|
case TEETypeSEVSNP:
|
|
return "SEV-SNP"
|
|
case TEETypeTDX:
|
|
return "TDX"
|
|
case TEETypeNVIDIA:
|
|
return "NVIDIA-CC"
|
|
case TEETypeARM:
|
|
return "ARM-CCA"
|
|
default:
|
|
return "Unknown"
|
|
}
|
|
}
|
|
|
|
// AttestationQuote represents a TEE attestation quote
|
|
type AttestationQuote struct {
|
|
Type TEEType `json:"type"`
|
|
Version uint32 `json:"version"`
|
|
Quote []byte `json:"quote"`
|
|
Measurement []byte `json:"measurement"`
|
|
ReportData []byte `json:"report_data"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Nonce []byte `json:"nonce"`
|
|
}
|
|
|
|
// GPUAttestation represents GPU-specific attestation (NVIDIA H100/Blackwell)
|
|
// All attestation is LOCAL - no NVIDIA cloud (NRAS) dependency
|
|
type GPUAttestation struct {
|
|
DeviceID string `json:"device_id"`
|
|
Model string `json:"model"`
|
|
CCEnabled bool `json:"cc_enabled"`
|
|
TEEIOEnabled bool `json:"tee_io_enabled"`
|
|
DriverVersion string `json:"driver_version"`
|
|
VBIOSVersion string `json:"vbios_version"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Mode AttestationMode `json:"mode"`
|
|
|
|
// For local nvtrust verification (ModeLocal) - CC-capable GPUs
|
|
// This is the PRIMARY attestation method
|
|
LocalEvidence *LocalGPUEvidence `json:"local_evidence,omitempty"`
|
|
|
|
// For software attestation (ModeSoftware) - non-CC GPUs
|
|
// DGX Spark (GB10), RTX 5090, RTX 4090, etc
|
|
SoftwareAttestation *SoftwareGPUAttestation `json:"software_attestation,omitempty"`
|
|
}
|
|
|
|
// LocalGPUEvidence represents evidence from nvtrust local verifier
|
|
// See: https://github.com/NVIDIA/nvtrust
|
|
type LocalGPUEvidence struct {
|
|
// SPDM measurement report from GPU
|
|
SPDMReport []byte `json:"spdm_report"`
|
|
// GPU certificates chain
|
|
CertChain []byte `json:"cert_chain"`
|
|
// RIM (Reference Integrity Manifest) verification result
|
|
RIMVerified bool `json:"rim_verified"`
|
|
// Driver attestation report
|
|
DriverReport []byte `json:"driver_report"`
|
|
// Nonce used for freshness
|
|
Nonce [32]byte `json:"nonce"`
|
|
}
|
|
|
|
// SoftwareGPUAttestation for consumer GPUs without hardware CC
|
|
// Lower trust score but still useful for the network
|
|
type SoftwareGPUAttestation struct {
|
|
// GPU identity from nvidia-smi
|
|
GPUSerial string `json:"gpu_serial"`
|
|
PCIID string `json:"pci_id"`
|
|
BoardID string `json:"board_id"`
|
|
GPUPartNum string `json:"gpu_part_num"`
|
|
ComputeCaps string `json:"compute_caps"` // e.g., "8.9" for RTX 5090
|
|
|
|
// Driver/firmware info
|
|
DriverVersion string `json:"driver_version"`
|
|
CUDAVersion string `json:"cuda_version"`
|
|
VBIOSVersion string `json:"vbios_version"`
|
|
|
|
// Performance attestation - prove the GPU ran computation
|
|
BenchmarkHash [32]byte `json:"benchmark_hash"` // Hash of benchmark result
|
|
BenchmarkTime uint64 `json:"benchmark_time_ms"`
|
|
|
|
// Provider signature (signed with provider's key)
|
|
ProviderPubKey []byte `json:"provider_pubkey"`
|
|
Signature []byte `json:"signature"`
|
|
|
|
// Timestamp and freshness
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Nonce [32]byte `json:"nonce"`
|
|
}
|
|
|
|
// DeviceStatus tracks attested device status
|
|
type DeviceStatus struct {
|
|
Attested bool `json:"attested"`
|
|
TrustScore uint8 `json:"trust_score"`
|
|
LastSeen time.Time `json:"last_seen"`
|
|
Operator string `json:"operator"`
|
|
Vendor TEEType `json:"vendor"`
|
|
JobHistory []string `json:"job_history"`
|
|
Mode AttestationMode `json:"mode"`
|
|
HardwareCC bool `json:"hardware_cc"` // True if hardware CC verified
|
|
}
|
|
|
|
// Verifier verifies TEE attestations
|
|
type Verifier struct {
|
|
trustedMeasurements map[string][]byte
|
|
attestedDevices map[string]*DeviceStatus
|
|
}
|
|
|
|
// NewVerifier creates a new attestation verifier
|
|
func NewVerifier() *Verifier {
|
|
return &Verifier{
|
|
trustedMeasurements: make(map[string][]byte),
|
|
attestedDevices: make(map[string]*DeviceStatus),
|
|
}
|
|
}
|
|
|
|
// RegisterTrustedMeasurement registers a trusted measurement
|
|
func (v *Verifier) RegisterTrustedMeasurement(name string, measurement []byte) {
|
|
v.trustedMeasurements[name] = measurement
|
|
}
|
|
|
|
// VerifyGPUAttestation verifies GPU attestation based on mode
|
|
// All attestation is LOCAL - no cloud dependencies (blockchain requirement)
|
|
func (v *Verifier) VerifyGPUAttestation(att *GPUAttestation) (*DeviceStatus, error) {
|
|
if att == nil {
|
|
return nil, ErrInvalidQuote
|
|
}
|
|
|
|
var status *DeviceStatus
|
|
var err error
|
|
|
|
switch att.Mode {
|
|
case ModeLocal:
|
|
// Local nvtrust verification - PRIMARY method for CC-capable GPUs
|
|
status, err = v.verifyLocalGPUAttestation(att)
|
|
case ModeSoftware:
|
|
// Software attestation for non-CC GPUs (DGX Spark, RTX 5090, etc)
|
|
status, err = v.verifySoftwareGPUAttestation(att)
|
|
default:
|
|
// Auto-detect based on evidence provided
|
|
if att.LocalEvidence != nil {
|
|
status, err = v.verifyLocalGPUAttestation(att)
|
|
} else if att.SoftwareAttestation != nil {
|
|
status, err = v.verifySoftwareGPUAttestation(att)
|
|
} else {
|
|
return nil, ErrInvalidQuote
|
|
}
|
|
}
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
v.attestedDevices[att.DeviceID] = status
|
|
return status, nil
|
|
}
|
|
|
|
// verifyLocalGPUAttestation verifies via local nvtrust
|
|
// This is the PRIMARY attestation method - no cloud dependencies
|
|
// See: https://github.com/NVIDIA/nvtrust
|
|
func (v *Verifier) verifyLocalGPUAttestation(att *GPUAttestation) (*DeviceStatus, error) {
|
|
if att.LocalEvidence == nil {
|
|
return nil, ErrInvalidQuote
|
|
}
|
|
|
|
// Check if GPU model supports CC
|
|
if !IsHardwareCCCapable(att.Model) {
|
|
return nil, errors.New("GPU model does not support confidential computing: " + att.Model)
|
|
}
|
|
|
|
ev := att.LocalEvidence
|
|
|
|
// Structural sanity on the raw evidence envelope. The cryptographic
|
|
// verification — SPDM/RIM signature and measurement match against the
|
|
// NVIDIA-signed Reference Integrity Manifest — is NOT done here: it is
|
|
// the one canonical primitive in github.com/luxfi/cc/attest, reached via
|
|
// (*Verifier).VerifyGPULocalEvidence (see verify_cc.go). This method is
|
|
// the trust-score POLICY that scores an already-shaped attestation whose
|
|
// ev.RIMVerified reflects that verification.
|
|
if len(ev.SPDMReport) < 256 {
|
|
return nil, ErrInvalidQuote
|
|
}
|
|
|
|
trustScore := calculateLocalTrustScore(att, ev)
|
|
|
|
return &DeviceStatus{
|
|
Attested: true,
|
|
TrustScore: trustScore,
|
|
LastSeen: time.Now(),
|
|
Operator: att.DeviceID,
|
|
Vendor: TEETypeNVIDIA,
|
|
JobHistory: []string{},
|
|
Mode: ModeLocal,
|
|
HardwareCC: ev.RIMVerified, // True if RIM verification passed
|
|
}, nil
|
|
}
|
|
|
|
// verifySoftwareGPUAttestation verifies consumer GPU software attestation
|
|
func (v *Verifier) verifySoftwareGPUAttestation(att *GPUAttestation) (*DeviceStatus, error) {
|
|
if att.SoftwareAttestation == nil {
|
|
return nil, ErrInvalidQuote
|
|
}
|
|
|
|
sw := att.SoftwareAttestation
|
|
|
|
// Verify basic fields
|
|
if sw.GPUSerial == "" || sw.DriverVersion == "" {
|
|
return nil, ErrInvalidQuote
|
|
}
|
|
|
|
// Verify provider signature exists
|
|
if len(sw.Signature) < 64 || len(sw.ProviderPubKey) < 32 {
|
|
return nil, ErrInvalidSignature
|
|
}
|
|
|
|
// Verify timestamp freshness
|
|
if time.Since(sw.Timestamp) > time.Hour {
|
|
return nil, ErrQuoteExpired
|
|
}
|
|
|
|
// In production: verify signature against provider's public key
|
|
// signedData := hashSoftwareAttestation(sw)
|
|
// if !verifySignature(sw.ProviderPubKey, signedData, sw.Signature) {
|
|
// return nil, ErrInvalidSignature
|
|
// }
|
|
|
|
trustScore := calculateSoftwareTrustScore(att, sw)
|
|
|
|
return &DeviceStatus{
|
|
Attested: true,
|
|
TrustScore: trustScore,
|
|
LastSeen: time.Now(),
|
|
Operator: att.DeviceID,
|
|
Vendor: TEETypeNVIDIA,
|
|
JobHistory: []string{},
|
|
Mode: ModeSoftware,
|
|
HardwareCC: false, // Software attestation cannot claim hardware CC
|
|
}, nil
|
|
}
|
|
|
|
// calculateLocalTrustScore for local nvtrust verification
|
|
// This is the PRIMARY trust score calculation for CC-capable GPUs
|
|
// Max score: 100 for datacenter GPUs with full CC features
|
|
func calculateLocalTrustScore(att *GPUAttestation, ev *LocalGPUEvidence) uint8 {
|
|
score := uint8(70) // Base for local nvtrust verification
|
|
|
|
// CC features bonus
|
|
if att.CCEnabled {
|
|
score += 15
|
|
}
|
|
if att.TEEIOEnabled {
|
|
score += 5
|
|
}
|
|
|
|
// RIM verification bonus
|
|
if ev != nil && ev.RIMVerified {
|
|
score += 5 // Bonus for RIM verification
|
|
}
|
|
|
|
// GPU model bonus
|
|
switch att.Model {
|
|
case "GB200", "B200", "B100": // Blackwell datacenter
|
|
score += 10
|
|
case "H200", "H100": // Hopper datacenter
|
|
score += 8
|
|
case "RTX PRO 6000": // Blackwell professional
|
|
score += 5
|
|
}
|
|
|
|
if score > 100 {
|
|
score = 100
|
|
}
|
|
return score
|
|
}
|
|
|
|
// calculateSoftwareTrustScore for consumer GPU software attestation
|
|
// Max score: 60 (significantly lower - no hardware CC)
|
|
func calculateSoftwareTrustScore(att *GPUAttestation, sw *SoftwareGPUAttestation) uint8 {
|
|
score := uint8(20) // Base for software attestation
|
|
|
|
// GPU model bonuses (consumer GPUs)
|
|
switch att.Model {
|
|
case "RTX 5090", "RTX 5080": // Blackwell consumer
|
|
score += 15
|
|
case "GB10": // DGX Spark
|
|
score += 12
|
|
case "RTX 4090", "RTX 4080": // Ada consumer
|
|
score += 10
|
|
case "RTX 3090", "RTX 3080":
|
|
score += 8
|
|
default:
|
|
score += 5
|
|
}
|
|
|
|
// Benchmark verification bonus
|
|
if sw.BenchmarkHash != [32]byte{} && sw.BenchmarkTime > 0 {
|
|
score += 10 // Proves GPU actually ran computation
|
|
}
|
|
|
|
// Signature verification bonus
|
|
if len(sw.Signature) >= 64 && len(sw.ProviderPubKey) >= 32 {
|
|
score += 10 // Provider accountability
|
|
}
|
|
|
|
// Driver version bonus (newer = better)
|
|
if sw.DriverVersion != "" {
|
|
score += 5
|
|
}
|
|
|
|
if score > 60 {
|
|
score = 60 // Cap at 60 for software attestation
|
|
}
|
|
return score
|
|
}
|
|
|
|
// IsHardwareCCCapable returns true if the GPU model supports hardware CC
|
|
func IsHardwareCCCapable(model string) bool {
|
|
switch model {
|
|
case "H100", "H200", "B100", "B200", "GB200", "RTX PRO 6000":
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// GetDeviceStatus returns the status of an attested device
|
|
func (v *Verifier) GetDeviceStatus(deviceID string) (*DeviceStatus, bool) {
|
|
status, ok := v.attestedDevices[deviceID]
|
|
return status, ok
|
|
}
|
|
|
|
// RecordJobCompletion records job completion for a device
|
|
func (v *Verifier) RecordJobCompletion(deviceID, jobID string) {
|
|
if status, ok := v.attestedDevices[deviceID]; ok {
|
|
status.JobHistory = append(status.JobHistory, jobID)
|
|
status.LastSeen = time.Now()
|
|
}
|
|
}
|
|
|
|
// ComputeAttestationHash computes hash for on-chain anchoring
|
|
func ComputeAttestationHash(quote *AttestationQuote) [32]byte {
|
|
h := sha256.New()
|
|
h.Write([]byte{byte(quote.Type)})
|
|
h.Write(quote.Quote)
|
|
h.Write(quote.Measurement)
|
|
h.Write(quote.Nonce)
|
|
var hash [32]byte
|
|
copy(hash[:], h.Sum(nil))
|
|
return hash
|
|
}
|
|
|
|
// FormatDeviceID formats device ID from attestation
|
|
func FormatDeviceID(teeType TEEType, identifier []byte) string {
|
|
return fmt.Sprintf("%s-%s", teeType.String(), hex.EncodeToString(identifier[:8]))
|
|
}
|
|
|
|
func bytesEqual(a, b []byte) bool {
|
|
if len(a) != len(b) {
|
|
return false
|
|
}
|
|
for i := range a {
|
|
if a[i] != b[i] {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|