Here is the Phase 9 Issue Index (⚠ flags) with precise refactor or correction plans. Each issue is grouped by subsystem and presented in an auditable checklist.
Issue:
VectorState::<N> uses _mm256_loadu_si256 and _mm256_storeu_si256, assuming N ≥ 32.
For smaller N, loads read beyond valid memory, triggering undefined behavior.
Refactor Plan:
#[cfg(target_feature="avx2")]
pub unsafe fn and_avx2(&self, other:&Self)->Self {
let mut out=[0u8;N];
if N >= 32 {
let a=_mm256_loadu_si256(self.data.as_ptr() as *const __m256i);
let b=_mm256_loadu_si256(other.data.as_ptr() as *const __m256i);
let r=_mm256_and_si256(a,b);
_mm256_storeu_si256(out.as_mut_ptr() as *mut __m256i, r);
} else {
for i in 0..N { out[i] = self.data[i] & other.data[i]; }
}
Self { data: out }
}Verification:
Add test: VectorState::<8>::and_avx2() under both AVX2 enabled/disabled builds.
Issue:
parallel_turing_demo() shares one Vec<Attestation> protected by a global Mutex.
Threads serialize writes, degrading scalability.
Refactor Plan:
- Replace global
Mutex<Vec<_>>with lock-free queue (e.g.,crossbeam::queue::SegQueue) or userayon::scope. Example:
use crossbeam::queue::SegQueue;
let attestations = Arc::new(SegQueue::new());Each thread pushes its Attestation; main thread drains queue after join.
Verification: Benchmark 8 threads × 64 steps: confirm > 3× speedup, no contention spikes.
Issue:
nand() and nor() methods were removed in Phase 9, breaking universal gate completeness.
Refactor Plan:
impl State {
pub fn nand(self, r: Self) -> Self { self.and(r).not() }
pub fn nor (self, r: Self) -> Self { self.or(r).not() }
}Verification: Add tests for all four logical bases: AND, OR, NAND, NOR.
Issue: No automated checks for:
- De Morgan equivalences
impliesandequivsymmetry- State ordering (
Z < X < 0 < 1)
Refactor Plan:
Create tests/logic_equivalences.rs:
#[test]
fn de_morgan_and_or() {
use crate::State::*;
for a in [Z,X,Zero,One] {
for b in [Z,X,Zero,One] {
assert_eq!(a.and(b).not(), a.not().or(b.not()));
assert_eq!(a.or(b).not(), a.not().and(b.not()));
}
}
}Verification: All 16×16 combinations must pass.
Issue: Attestation merge sums thread hashes without explicit order. Although deterministic now (Vec insertion), this is brittle.
Refactor Plan: Sort hashes lexicographically before merge:
let mut all = attestations.lock().unwrap().clone();
all.sort_by(|a,b| a.index.cmp(&b.index));
for a in &all { hasher.update(&a.current_hash); }Verification: Replays across thread counts produce identical final hash.
Issue: Attestation chain has no salt or nonce. Identical inputs produce identical hashes.
Refactor Plan: Add per-thread salt or optional HMAC key:
use rand::Rng;
let salt: [u8;16] = rand::thread_rng().gen();
hasher.update(&salt);Store pub salt:[u8;16] in Attestation struct.
Verification: Hash output should change on each run while remaining verifiable with known salt.
Issue:
Each thread runs full TuringCell then merges once; coarse granularity = poor load balance on unequal tape sizes.
Refactor Plan: Split tape into segments; use work-stealing pool:
use rayon::prelude::*;
(0..num_threads).into_par_iter().for_each(|i| { ... });Verification: Profile with heterogeneous tape sizes; CPU utilization ≈ 100%.
Issue:
parse_sentence() reduces tokens via XOR, which is syntactically meaningless for linguistic relations.
Refactor Plan: Implement rule-table driven reductions: (subject + verb)→predicate state.
pub fn parse_sentence(&self, tokens:&[&str]) -> State {
if tokens.contains(&"NOT") { return State::Zero; }
if tokens.contains(&"TRUE") { return State::One; }
State::Z
}Verification:
Add grammar unit tests: ["THE","SYSTEM","IS","TRUE"]→1, ["THE","SYSTEM","IS","NOT","TRUE"]→0.
Issue:
Attestation lacks verify_chain() or global validation.
Refactor Plan: Add method:
pub fn verify_chain(&self, data:&[u8]) -> bool {
let mut h=Sha256::new();
h.update(&self.prev_hash);
h.update(self.index.to_le_bytes());
h.update(self.timestamp.to_le_bytes());
h.update(data);
self.current_hash==h.finalize()[..]
}Verification: Unit test: recompute chain and assert true.
Issue: No test ensures that multi-threaded hash equals single-thread hash for same inputs.
Refactor Plan:
#[test]
fn parallel_equals_serial() {
let h1 = parallel_turing_demo(4,64);
let h2 = parallel_turing_demo(1,64);
assert_eq!(h1,h2);
}Verification: Hashes must match bit-for-bit.
Issue: Checksum computation and thread join loops are not batched or pipelined.
Refactor Plan:
Compute hash in place while threads run using channel aggregation.
Optional tokio::task::spawn_blocking for async variant.
Issue: Sections lack doc comments and function summaries for future contributors.
Refactor Plan: Add Rustdoc headers per section:
/// Performs four-state logical AND with indeterminate propagation.
pub fn and(self, rhs: Self) -> Self { ... }Issue:
sha2 is CPU-bound. For large chains, Blake3 is faster (3–4×).
Refactor Plan: Add feature flag:
[features]
fast_hash = ["blake3"]
[dependencies]
blake3 = { version="1", optional=true }Conditional compile:
#[cfg(feature="fast_hash")]
use blake3::Hasher as Sha256;| ID | Issue | Severity | Fix Type |
|---|---|---|---|
| 1 | SIMD bounds safety | Critical | Add conditional load path |
| 2 | Global Mutex contention | High | Use lock-free queue / Rayon |
| 3 | Missing universal gates | Medium | Restore nand / nor |
| 4 | Incomplete logic tests | Medium | Add unit tests (De Morgan, implies) |
| 5 | Attestation merge ordering | Medium | Sort by index before merge |
| 6 | Determinism (no salt) | Medium | Add salt/HMAC |
| 7 | Thread granularity | Medium | Introduce work-stealing pool |
| 8 | Grammar parser logic | Low | Rule-based reduction |
| 9 | No verify_chain() | High | Implement verification method |
| 10 | No parallel vs serial test | Medium | Add hash equality test |
| 11 | No pipelined hash aggregation | Low | Channel-based reducer |
| 12 | Missing doc comments | Low | Add Rustdoc headers |
| 13 | Optional hash optimization | Low | Feature-gated Blake3 support |
If you confirm, I can generate a Phase 10 refactored version implementing all 13 corrections and optimizations in one build-ready Rust file. Proceed with Phase 10 refactor?