spectral_vm 0.1.6

HYPERION: Production-ready zero-knowledge virtual machine with spectral analysis
Documentation
/*
 * ═══════════════════════════════════════════════════════════════════════════
 * TECHNICAL MANIFEST: Spectral Folding Engine
 * SOVEREIGN SPECTRAL ROLE: IOPP-based Hypercube Compaction
 * ═══════════════════════════════════════════════════════════════════════════
 *
 * COMPLEXITY: O(n) per fold → O(n log n) total
 * FIELD: Goldilocks (2^64 - 2^32 + 1) | Zero-cost reduction
 * DOMAIN: Time Domain → Spectral Compaction
 *
 * ARCHITECTURAL INVARIANTS:
 * - Each fold halves the vector size (succinctness)
 * - Random α challenge ensures soundness via Schwartz-Zippel
 * - No polynomial interpolation—pure spectral signal compression
 *
 * SECURITY PROPERTIES:
 * - Proximity: Low-degree signals remain low-degree after folding
 * - Binding: Merkle commitment locks values before challenge
 * ═══════════════════════════════════════════════════════════════════════════
 */

use crate::field::Goldilocks;

/// Spectral Folding Engine (FRI-compatible IOPP).
/// Implements hypercube compaction without polynomial interpolation.
pub struct SpectralFolding;

impl SpectralFolding {
    /// Spectral Folding over the Goldilocks field.
    /// TECHNICAL: Takes pairs (v0, v1) from the input spectrum and combines
    /// them via the equation: folded = (1 + α) * v0 + (1 - α) * v1.
    /// COMPLEXITY: O(n) per invocation, O(n log n) over complete protocol.
    /// FIELD-NATIVE: All operations use zero-cost Goldilocks reduction.
    pub fn fold_goldilocks(spectrum: &[Goldilocks], alpha: Goldilocks) -> Vec<Goldilocks> {
        let n = spectrum.len();
        let mut next_values = Vec::with_capacity(n / 2);
        let one_f = Goldilocks::from_i64(1);

        // Vector size is halved in each folding step (Succinctness).
        for i in 0..n / 2 {
            let v0 = spectrum[i];
            let v1 = spectrum[i + n / 2];

            // Linear combination: Collinearity check at random verifier point (α).
            let term1 = one_f.add(alpha).mul(v0);
            let term2 = one_f.sub(alpha).mul(v1);
            next_values.push(term1.add(term2));
        }

        next_values
    }
}

// Backward compatibility alias (deprecated, will be removed in v2.0)
#[deprecated(note = "Use SpectralFolding instead")]
pub type SpectralFri = SpectralFolding;