mirror of
https://github.com/luxfi/p3q.git
synced 2026-10-30 15:22:47 +00:00
Red-team confirmed the DEEP-STARK soundness core correct (15 forgery attempts survived). These fix the hardening defects AROUND it, smallest correct change each. The soundness core (constraint identity, OOD/DEEP binding, FRI fold) is byte-for-byte unchanged. F1 (latent remote-DoS): verify_air/prove_air validate the attacker-controlled shape (log_trace_rows in 1..=20, log_blowup in 1..=5, log_n+log_blowup <= 31) at the top, before any 1<<.. shift - mirrors the audited wire::Header::decode bounds. Out-of-range now returns a typed StarkVerification error instead of a shift-overflow panic (file is panic-free by contract). F2 (latent panic, published crate): new engine::FriShape::validate() (checked log_lde, log_final_poly < log_lde, num_queries >= 1) is called first in engine::prove + engine::verify, replacing the old num_rounds==0 checks. Kills the num_rounds subtraction-underflow and shift-overflow panics when a downstream caller passes an arbitrary FriShape by value. F3 (soundness landmine - doc lied): delete the never-called AirBuilder::is_transition() (1 def, 0 call sites) and rewrite air.rs docs. The prover divides by the FULL Z_H = x^n-1 (vanishes on ALL rows incl. the cyclic wrap-around n-1 -> 0); there is NO last-row mask. The Air::eval contract now states every emitted constraint must hold on all rows including wrap-around, and a terminating/non-cyclic recurrence must not be written as a bare transition constraint (close the trace cyclically or pin endpoints with boundary constraints). F4 (fail-open): num_constraints()==0 AIR is now rejected by both prove_air and verify_air - a STARK with no constraints certifies nothing (was a proof of nothing for arbitrary junk). F6 (fragile defense-in-depth): remove the impl Air blocks (with unimplemented!() eval) from the 6 audit-gated p3q-zchain stubs. The structs remain as typed placeholders, but with no Air impl they cannot be passed to prove_air/verify_air at all - fully sealed, cleaner than a panicking eval. build_air still returns Err(not_yet_audit_gated). Regressions: f1_*/f3_*/f4_* in prover.rs and f2_* in engine.rs, as #[cfg(test)]; throwaway red-team harnesses removed. cargo build/test --workspace green (123 passed, 0 failed, 1 ignored); cargo fmt --check clean.