use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
pub const ATTACHMENT_SCHEMA: &str = "vela.verifier_attachment.v0.1";
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum VerifierMethod {
ComputationalSearch,
LpDualRecompute,
SatUnsatCert,
LeanKernel,
ExactArithmeticRecompute,
LiteratureCorroboration,
ManualReferee,
EvalHarness,
}
impl VerifierMethod {
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::ComputationalSearch => "computational_search",
Self::LpDualRecompute => "lp_dual_recompute",
Self::SatUnsatCert => "sat_unsat_cert",
Self::LeanKernel => "lean_kernel",
Self::ExactArithmeticRecompute => "exact_arithmetic_recompute",
Self::LiteratureCorroboration => "literature_corroboration",
Self::ManualReferee => "manual_referee",
Self::EvalHarness => "eval_harness",
}
}
#[must_use]
pub fn parse(s: &str) -> Option<Self> {
Some(match s {
"computational_search" => Self::ComputationalSearch,
"lp_dual_recompute" => Self::LpDualRecompute,
"sat_unsat_cert" => Self::SatUnsatCert,
"lean_kernel" => Self::LeanKernel,
"exact_arithmetic_recompute" => Self::ExactArithmeticRecompute,
"literature_corroboration" => Self::LiteratureCorroboration,
"manual_referee" => Self::ManualReferee,
"eval_harness" => Self::EvalHarness,
_ => return None,
})
}
pub const ALL: [VerifierMethod; 8] = [
Self::ComputationalSearch,
Self::LpDualRecompute,
Self::SatUnsatCert,
Self::LeanKernel,
Self::ExactArithmeticRecompute,
Self::LiteratureCorroboration,
Self::ManualReferee,
Self::EvalHarness,
];
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ProbeKind {
CounterexampleSearch,
CaseBConfig,
BoundaryDualFeasibility,
FiniteSizeExtrapolation,
IndependentReimplementation,
FormalismFidelity,
}
impl ProbeKind {
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::CounterexampleSearch => "counterexample_search",
Self::CaseBConfig => "case_b_config",
Self::BoundaryDualFeasibility => "boundary_dual_feasibility",
Self::FiniteSizeExtrapolation => "finite_size_extrapolation",
Self::IndependentReimplementation => "independent_reimplementation",
Self::FormalismFidelity => "formalism_fidelity",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ProbeResult {
Survived,
Refuted,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AdversarialProbe {
pub kind: ProbeKind,
pub result: ProbeResult,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub note: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub evidence_root: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MatchToClaim {
pub matches: bool,
pub checker_actor: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum AttachmentOutcome {
Passed,
Failed,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MethodIntegrity {
#[default]
Unattested,
Sound,
Compromised,
}
impl MethodIntegrity {
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::Unattested => "unattested",
Self::Sound => "sound",
Self::Compromised => "compromised",
}
}
#[must_use]
pub fn is_unattested(&self) -> bool {
*self == Self::Unattested
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct VerifierAttachment {
pub schema: String,
pub id: String,
pub target: String,
pub claim_digest: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub claim_root: String,
pub verifier_method: VerifierMethod,
pub solver_id: String,
#[serde(default)]
pub independent_of: Vec<String>,
pub match_to_claim: MatchToClaim,
#[serde(default)]
pub adversarial_probes: Vec<AdversarialProbe>,
pub outcome: AttachmentOutcome,
#[serde(default, skip_serializing_if = "MethodIntegrity::is_unattested")]
pub method_integrity: MethodIntegrity,
pub verifier_actor: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub note: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub implementation_id: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub execution_evidence_roots: Vec<String>,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub toolchain_hash: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub undischarged_hypotheses: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub lineage_couplings: Vec<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub supersedes: Option<String>,
}
#[derive(Debug, Clone)]
pub struct AttachmentDraft {
pub target: String,
pub claim_digest: String,
pub verifier_method: VerifierMethod,
pub solver_id: String,
pub independent_of: Vec<String>,
pub match_to_claim: MatchToClaim,
pub adversarial_probes: Vec<AdversarialProbe>,
pub outcome: AttachmentOutcome,
pub verifier_actor: String,
pub note: String,
}
#[must_use]
pub fn claim_digest(claim: &str) -> String {
let digest = Sha256::digest(claim.trim().as_bytes());
hex::encode(digest)[..16].to_string()
}
#[must_use]
pub fn derive_toolchain_hash(method: &VerifierMethod) -> String {
let tag = format!("{ATTACHMENT_SCHEMA}:{method:?}");
hex::encode(Sha256::digest(tag.as_bytes()))[..16].to_string()
}
impl VerifierAttachment {
pub fn build(draft: AttachmentDraft) -> Result<Self, String> {
if !draft.target.starts_with("vf_") && !draft.target.starts_with("vfr_") {
return Err(format!(
"attachment target should be a finding (`vf_`) or frontier-claim (`vfr_`) id; got `{}`",
draft.target
));
}
let mut att = VerifierAttachment {
schema: ATTACHMENT_SCHEMA.to_string(),
id: String::new(),
target: draft.target,
claim_digest: draft.claim_digest,
claim_root: String::new(),
verifier_method: draft.verifier_method,
solver_id: draft.solver_id,
independent_of: draft.independent_of,
match_to_claim: draft.match_to_claim,
adversarial_probes: draft.adversarial_probes,
outcome: draft.outcome,
method_integrity: MethodIntegrity::Unattested,
verifier_actor: draft.verifier_actor,
note: draft.note,
implementation_id: String::new(),
execution_evidence_roots: Vec::new(),
lineage_couplings: Vec::new(),
supersedes: None,
toolchain_hash: derive_toolchain_hash(&draft.verifier_method),
undischarged_hypotheses: Vec::new(),
};
att.id = att.derive_id()?;
Ok(att)
}
pub fn with_method_integrity(mut self, integrity: MethodIntegrity) -> Result<Self, String> {
self.method_integrity = integrity;
self.id = self.derive_id()?;
Ok(self)
}
pub fn with_claim_root(mut self, root: &str) -> Result<Self, String> {
if !crate::receipt_v1::is_full_sha256_root(root) {
return Err(format!(
"claim root must be a full lowercase sha256 root, got '{root}'"
));
}
self.claim_root = root.to_string();
self.id = self.derive_id()?;
Ok(self)
}
pub fn with_implementation_id(mut self, implementation_id: &str) -> Result<Self, String> {
self.implementation_id = implementation_id.to_string();
self.id = self.derive_id()?;
Ok(self)
}
pub fn with_execution_evidence_roots(mut self, roots: Vec<String>) -> Result<Self, String> {
for root in &roots {
if !crate::receipt_v1::is_full_sha256_root(root) {
return Err(format!(
"execution evidence root must be a full lowercase sha256 root, got '{root}'"
));
}
}
self.execution_evidence_roots = roots;
self.id = self.derive_id()?;
Ok(self)
}
pub fn with_undischarged_hypotheses(mut self, hyps: Vec<String>) -> Result<Self, String> {
self.undischarged_hypotheses = hyps;
self.id = self.derive_id()?;
Ok(self)
}
pub fn with_lineage_couplings(mut self, couplings: Vec<String>) -> Result<Self, String> {
self.lineage_couplings = couplings;
self.id = self.derive_id()?;
Ok(self)
}
pub fn with_supersedes(mut self, prior: &str) -> Result<Self, String> {
if !prior.starts_with("vva_") {
return Err(format!("supersedes must name a vva_… id, got '{prior}'"));
}
self.supersedes = Some(prior.to_string());
self.id = self.derive_id()?;
Ok(self)
}
pub fn derive_id(&self) -> Result<String, String> {
let mut preimage = self.clone();
preimage.id = String::new();
let bytes = crate::canonical::to_canonical_bytes(&preimage)
.map_err(|e| format!("canonicalize attachment preimage: {e}"))?;
let digest = Sha256::digest(&bytes);
Ok(format!("vva_{}", &hex::encode(digest)[..16]))
}
pub fn verify(&self) -> Result<(), String> {
if self.schema != ATTACHMENT_SCHEMA {
return Err(format!(
"attachment.schema must be `{ATTACHMENT_SCHEMA}`, got `{}`",
self.schema
));
}
if !self.id.starts_with("vva_") {
return Err(format!(
"attachment id must start with `vva_`, got `{}`",
self.id
));
}
if !self.claim_root.is_empty() && !crate::receipt_v1::is_full_sha256_root(&self.claim_root)
{
return Err(format!(
"attachment claim_root must be a full lowercase sha256 root, got '{}'",
self.claim_root
));
}
for root in &self.execution_evidence_roots {
if !crate::receipt_v1::is_full_sha256_root(root) {
return Err(format!(
"attachment execution_evidence_roots contains invalid root '{root}'"
));
}
}
for probe in &self.adversarial_probes {
if !probe.evidence_root.is_empty()
&& !crate::receipt_v1::is_full_sha256_root(&probe.evidence_root)
{
return Err(format!(
"attachment adversarial probe contains invalid evidence_root '{}'",
probe.evidence_root
));
}
}
let derived = self.derive_id()?;
if derived != self.id {
return Err(format!(
"attachment id mismatch: stored `{}`, derived `{}`",
self.id, derived
));
}
Ok(())
}
pub(crate) fn is_passing_match(&self, current_digest: &str) -> bool {
self.is_base_match(current_digest) && self.method_integrity != MethodIntegrity::Compromised
}
fn has_valid_id(&self) -> bool {
self.derive_id().is_ok_and(|d| d == self.id)
}
fn is_claim_bound(&self, current_digest: &str) -> bool {
self.id.starts_with("vva_")
&& self.outcome == AttachmentOutcome::Passed
&& self.claim_digest == current_digest
&& self.match_to_claim.matches
}
fn is_base_match(&self, current_digest: &str) -> bool {
self.is_claim_bound(current_digest) && self.has_valid_id()
}
fn is_compromised_match(&self, current_digest: &str) -> bool {
self.is_base_match(current_digest) && self.method_integrity == MethodIntegrity::Compromised
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum GateStatus {
NeedsVerification,
Verified,
Refuted,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GateOutcome {
pub status: GateStatus,
pub reasons: Vec<String>,
}
impl GateOutcome {
#[must_use]
pub fn is_verified(&self) -> bool {
self.status == GateStatus::Verified
}
}
#[must_use]
pub fn derive_gate_status(
current_claim_digest: &str,
attachments: &[VerifierAttachment],
) -> GateOutcome {
let mut reasons = Vec::new();
let passed: Vec<&VerifierAttachment> = attachments
.iter()
.filter(|a| a.outcome == AttachmentOutcome::Passed)
.collect();
let matched: Vec<&VerifierAttachment> = attachments
.iter()
.filter(|a| a.is_passing_match(current_claim_digest))
.collect();
reasons.extend(
super::independence::independence_from_attachments(current_claim_digest, attachments)
.reasons,
);
let compromised = attachments
.iter()
.filter(|a| a.is_compromised_match(current_claim_digest))
.count();
if compromised > 0 {
reasons.push(format!(
"G5: {compromised} attachment(s) excluded — method integrity compromised \
(e.g. forbidden Lean axiom or failed kernel re-check)"
));
}
let conditional: Vec<&str> = matched
.iter()
.filter(|a| !a.undischarged_hypotheses.is_empty())
.flat_map(|a| a.undischarged_hypotheses.iter().map(String::as_str))
.collect();
if !conditional.is_empty() {
reasons.push(format!(
"conditional: matched attachment(s) prove the claim only under undischarged \
hypotheses [{}] — `#print axioms`-clean but not an unconditional verification",
conditional.join("; ")
));
}
let id_invalid = attachments
.iter()
.filter(|a| a.is_claim_bound(current_claim_digest) && !a.has_valid_id())
.count();
if id_invalid > 0 {
reasons.push(format!(
"G4: {id_invalid} attachment(s) excluded — id does not content-address the body \
(forged or drifted; derive_id() != id)"
));
}
if passed.len() > matched.len() + compromised + id_invalid {
reasons.push(
"G2: an attachment passed but is unmatched to the current claim (passed_but_unmatched)"
.to_string(),
);
}
let probes: Vec<&AdversarialProbe> = matched
.iter()
.flat_map(|a| a.adversarial_probes.iter())
.collect();
if probes.iter().any(|p| p.result == ProbeResult::Refuted) {
return GateOutcome {
status: GateStatus::Refuted,
reasons: vec![
"G3: an adversarial probe REFUTED the claim -> status is refuted".to_string(),
],
};
}
if probes.is_empty() {
reasons.push("G3: no surviving adversarial probe attached (need >=1)".to_string());
}
for a in &matched {
if !a.id.starts_with("vva_") {
reasons.push(format!("G4: malformed attachment id `{}`", a.id));
}
}
let status = if reasons.is_empty() {
GateStatus::Verified
} else {
GateStatus::NeedsVerification
};
GateOutcome { status, reasons }
}
pub fn exact_lane_attachment_admit(
current_claim_digest: &str,
attachments: &[VerifierAttachment],
) -> (bool, Vec<String>) {
let mut reasons = Vec::new();
let gate = derive_gate_status(current_claim_digest, attachments);
if gate.status != GateStatus::Verified {
reasons.push(format!(
"exact-lane: gate not Verified ({:?}): {}",
gate.status,
gate.reasons.join("; ")
));
return (false, reasons);
}
let matched: Vec<&VerifierAttachment> = attachments
.iter()
.filter(|a| a.is_passing_match(current_claim_digest))
.collect();
if matched.len() < 2 {
reasons.push("exact-lane: fewer than 2 matched attachments".to_string());
return (false, reasons);
}
if let Some(bad) = matched
.iter()
.find(|a| a.method_integrity != MethodIntegrity::Sound)
{
reasons.push(format!(
"exact-lane: attachment `{}` is not MethodIntegrity::Sound ({:?}); auto-admit requires Sound (a human must clear Unattested)",
bad.id, bad.method_integrity
));
return (false, reasons);
}
let mut ff_survived = false;
for a in &matched {
for p in &a.adversarial_probes {
if p.kind == ProbeKind::FormalismFidelity {
match p.result {
ProbeResult::Survived => ff_survived = true,
ProbeResult::Refuted => {
reasons
.push("exact-lane: a FormalismFidelity probe is Refuted".to_string());
return (false, reasons);
}
}
}
}
}
if !ff_survived {
reasons.push(
"exact-lane: no present-and-Survived FormalismFidelity probe (faithfulness unproven; \
absent does not count as safe)"
.to_string(),
);
return (false, reasons);
}
let ids: std::collections::BTreeSet<&str> = matched.iter().map(|a| a.id.as_str()).collect();
let declares_independence = matched.iter().any(|a| {
a.independent_of
.iter()
.any(|other| other != &a.id && ids.contains(other.as_str()))
});
if !declares_independence {
reasons.push(
"exact-lane: no matched attachment declares independent_of another (need >=1 \
one-directional declaration)"
.to_string(),
);
return (false, reasons);
}
let impls: std::collections::BTreeSet<&str> = matched
.iter()
.map(|a| a.implementation_id.as_str())
.filter(|s| !s.is_empty())
.collect();
if impls.len() < 2 {
reasons.push(
"exact-lane: implementation monoculture (need >=2 distinct implementation_id; N runs \
of one binary are replication, not independent verification)"
.to_string(),
);
return (false, reasons);
}
(true, reasons)
}
#[cfg(test)]
mod tests {
use super::*;
fn match_to(actor: &str) -> MatchToClaim {
MatchToClaim {
matches: true,
checker_actor: actor.to_string(),
}
}
fn surviving_probe() -> AdversarialProbe {
AdversarialProbe {
kind: ProbeKind::CounterexampleSearch,
result: ProbeResult::Survived,
note: String::new(),
evidence_root: String::new(),
}
}
fn attach(
digest: &str,
method: VerifierMethod,
solver: &str,
independent_of: Vec<String>,
probes: Vec<AdversarialProbe>,
) -> VerifierAttachment {
VerifierAttachment::build(AttachmentDraft {
target: "vf_0123456789abcdef".to_string(),
claim_digest: digest.to_string(),
verifier_method: method,
solver_id: solver.to_string(),
independent_of,
match_to_claim: match_to("checker"),
adversarial_probes: probes,
outcome: AttachmentOutcome::Passed,
verifier_actor: "Opus 4.8".to_string(),
note: String::new(),
})
.unwrap()
}
fn ff_survived() -> AdversarialProbe {
AdversarialProbe {
kind: ProbeKind::FormalismFidelity,
result: ProbeResult::Survived,
note: String::new(),
evidence_root: String::new(),
}
}
#[allow(clippy::too_many_arguments)]
fn attach_full(
digest: &str,
method: VerifierMethod,
solver: &str,
independent_of: Vec<String>,
probes: Vec<AdversarialProbe>,
integrity: MethodIntegrity,
impl_id: &str,
) -> VerifierAttachment {
let mut a = attach(digest, method, solver, independent_of, probes);
if integrity != MethodIntegrity::Unattested {
a = a.with_method_integrity(integrity).unwrap();
}
if !impl_id.is_empty() {
a = a.with_implementation_id(impl_id).unwrap();
}
a
}
fn admit_pair(digest: &str) -> (VerifierAttachment, VerifierAttachment) {
let a1 = attach_full(
digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![ff_survived()],
MethodIntegrity::Sound,
"impl-cp-sat",
);
let a2 = attach_full(
digest,
VerifierMethod::ExactArithmeticRecompute,
"pari-gp",
vec![a1.id.clone()],
vec![ff_survived()],
MethodIntegrity::Sound,
"impl-pari",
);
(a1, a2)
}
#[test]
fn exact_lane_happy_path_admits() {
let digest = claim_digest("claim X");
let (a1, a2) = admit_pair(&digest);
a1.verify().expect("a1 content-addresses its body");
a2.verify().expect("a2 content-addresses its body");
assert_eq!(
derive_gate_status(&digest, &[a1.clone(), a2.clone()]).status,
GateStatus::Verified
);
let (admit, reasons) = exact_lane_attachment_admit(&digest, &[a1, a2]);
assert!(admit, "should auto-admit, refused for: {reasons:?}");
assert!(reasons.is_empty());
}
#[test]
fn durable_evidence_fields_are_content_addressed_and_root_checked() {
let root = format!("sha256:{}", "a".repeat(64));
let mut probe = surviving_probe();
probe.evidence_root = root.clone();
let attachment = attach(
&claim_digest("claim X"),
VerifierMethod::ComputationalSearch,
"frozen-checker",
vec![],
vec![probe],
)
.with_claim_root(&root)
.unwrap()
.with_implementation_id("impl:frozen-checker")
.unwrap()
.with_execution_evidence_roots(vec![root.clone()])
.unwrap();
attachment.verify().unwrap();
assert_eq!(attachment.claim_root, root);
assert_eq!(attachment.execution_evidence_roots.len(), 1);
assert!(
attachment
.clone()
.with_execution_evidence_roots(vec!["sha256:short".to_string()])
.is_err()
);
let mut forged = attachment;
forged.adversarial_probes[0].evidence_root = "sha256:short".to_string();
assert!(forged.verify().unwrap_err().contains("evidence_root"));
}
#[test]
fn exact_lane_refuses_forged_id_pair() {
let digest = claim_digest("claim X");
let (mut a1, mut a2) = admit_pair(&digest);
a1.id = "vva_forged00000a1".to_string();
a2.id = "vva_forged00000a2".to_string();
a1.independent_of = vec![a2.id.clone()];
a2.independent_of = vec![a1.id.clone()];
assert!(a1.verify().is_err(), "forged a1 must fail id-integrity");
assert!(a2.verify().is_err(), "forged a2 must fail id-integrity");
assert_eq!(
derive_gate_status(&digest, &[a1.clone(), a2.clone()]).status,
GateStatus::NeedsVerification,
"forged-id attachments must not reach Verified"
);
let (admit, reasons) = exact_lane_attachment_admit(&digest, &[a1, a2]);
assert!(!admit, "forged-id pair must never auto-admit");
assert!(reasons.iter().any(|r| r.contains("G4")
|| r.contains("content-address")
|| r.contains("not Verified")));
}
#[test]
fn exact_lane_refuses_without_formalism_fidelity_probe() {
let digest = claim_digest("claim X");
let a1 = attach_full(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
MethodIntegrity::Sound,
"impl-cp-sat",
);
let a2 = attach_full(
&digest,
VerifierMethod::ExactArithmeticRecompute,
"pari-gp",
vec![a1.id.clone()],
vec![surviving_probe()],
MethodIntegrity::Sound,
"impl-pari",
);
assert_eq!(
derive_gate_status(&digest, &[a1.clone(), a2.clone()]).status,
GateStatus::Verified,
"the bare gate tolerates a missing fidelity probe"
);
let (admit, reasons) = exact_lane_attachment_admit(&digest, &[a1, a2]);
assert!(!admit);
assert!(reasons.iter().any(|r| r.contains("FormalismFidelity")));
}
#[test]
fn exact_lane_refuses_refuted_formalism_fidelity() {
let digest = claim_digest("claim X");
let a1 = attach_full(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![AdversarialProbe {
kind: ProbeKind::FormalismFidelity,
result: ProbeResult::Refuted,
note: String::new(),
evidence_root: String::new(),
}],
MethodIntegrity::Sound,
"impl-cp-sat",
);
let a2 = attach_full(
&digest,
VerifierMethod::ExactArithmeticRecompute,
"pari-gp",
vec![a1.id.clone()],
vec![ff_survived()],
MethodIntegrity::Sound,
"impl-pari",
);
let (admit, reasons) = exact_lane_attachment_admit(&digest, &[a1, a2]);
assert!(!admit);
assert!(
reasons
.iter()
.any(|r| r.contains("Refuted") || r.contains("not Verified"))
);
}
#[test]
fn exact_lane_refuses_unattested_integrity() {
let digest = claim_digest("claim X");
let a1 = attach_full(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![ff_survived()],
MethodIntegrity::Unattested,
"impl-cp-sat",
);
let a2 = attach_full(
&digest,
VerifierMethod::ExactArithmeticRecompute,
"pari-gp",
vec![a1.id.clone()],
vec![ff_survived()],
MethodIntegrity::Sound,
"impl-pari",
);
assert_eq!(
derive_gate_status(&digest, &[a1.clone(), a2.clone()]).status,
GateStatus::Verified,
"the bare gate tolerates Unattested integrity"
);
let (admit, reasons) = exact_lane_attachment_admit(&digest, &[a1, a2]);
assert!(!admit);
assert!(reasons.iter().any(|r| r.contains("Sound")));
}
#[test]
fn exact_lane_refuses_compromised_method() {
let digest = claim_digest("claim X");
let a1 = attach_full(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![ff_survived()],
MethodIntegrity::Compromised,
"impl-cp-sat",
);
let a2 = attach_full(
&digest,
VerifierMethod::ExactArithmeticRecompute,
"pari-gp",
vec![a1.id.clone()],
vec![ff_survived()],
MethodIntegrity::Sound,
"impl-pari",
);
let (admit, _r) = exact_lane_attachment_admit(&digest, &[a1, a2]);
assert!(!admit);
}
#[test]
fn exact_lane_refuses_when_no_independence_declared() {
let digest = claim_digest("claim X");
let a1 = attach_full(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![ff_survived()],
MethodIntegrity::Sound,
"impl-cp-sat",
);
let a2 = attach_full(
&digest,
VerifierMethod::ExactArithmeticRecompute,
"pari-gp",
vec![], vec![ff_survived()],
MethodIntegrity::Sound,
"impl-pari",
);
assert_eq!(
derive_gate_status(&digest, &[a1.clone(), a2.clone()]).status,
GateStatus::NeedsVerification,
"no declaration fails the gate's G1"
);
let (admit, reasons) = exact_lane_attachment_admit(&digest, &[a1, a2]);
assert!(!admit);
assert!(reasons.iter().any(|r| r.contains("independ")));
}
#[test]
fn exact_lane_refuses_implementation_monoculture() {
let digest = claim_digest("claim X");
let a1 = attach_full(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![ff_survived()],
MethodIntegrity::Sound,
"same-binary",
);
let a2 = attach_full(
&digest,
VerifierMethod::ExactArithmeticRecompute,
"pari-gp",
vec![a1.id.clone()],
vec![ff_survived()],
MethodIntegrity::Sound,
"same-binary",
);
let (admit, reasons) = exact_lane_attachment_admit(&digest, &[a1, a2]);
assert!(!admit);
assert!(reasons.iter().any(|r| r.contains("monoculture")));
}
#[test]
fn exact_lane_refuses_single_attachment() {
let digest = claim_digest("claim X");
let (a1, _a2) = admit_pair(&digest);
let (admit, _r) = exact_lane_attachment_admit(&digest, &[a1]);
assert!(!admit);
}
#[test]
fn exact_lane_refuses_on_claim_digest_drift() {
let digest = claim_digest("claim X");
let (a1, a2) = admit_pair(&digest);
let revised = claim_digest("claim X, revised");
let (admit, _r) = exact_lane_attachment_admit(&revised, &[a1, a2]);
assert!(
!admit,
"attachments bound to the old digest must not admit the revised claim"
);
}
#[test]
fn accepted_finding_with_zero_attachments_is_needs_verification() {
let digest = claim_digest("a Sidon set of size 33 in [0,256]");
let outcome = derive_gate_status(&digest, &[]);
assert_eq!(outcome.status, GateStatus::NeedsVerification);
assert!(!outcome.is_verified());
}
#[test]
fn single_attachment_fails_g1() {
let digest = claim_digest("claim X");
let a = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
);
let outcome = derive_gate_status(&digest, &[a]);
assert_eq!(outcome.status, GateStatus::NeedsVerification);
assert!(outcome.reasons.iter().any(|r| r.starts_with("G1")));
}
#[test]
fn two_independent_matched_probed_attachments_verify() {
let digest = claim_digest("claim X");
let a1 = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
);
let a2 = attach(
&digest,
VerifierMethod::ExactArithmeticRecompute,
"pari-gp",
vec![a1.id.clone()],
vec![surviving_probe()],
);
let outcome = derive_gate_status(&digest, &[a1, a2]);
assert_eq!(
outcome.status,
GateStatus::Verified,
"{:?}",
outcome.reasons
);
assert!(outcome.reasons.is_empty());
}
#[test]
fn undischarged_hypothesis_demotes_to_needs_verification() {
let digest = claim_digest("claim X");
let a1 = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
);
let a2 = attach(
&digest,
VerifierMethod::ExactArithmeticRecompute,
"lean4@4.29.1",
vec![a1.id.clone()],
vec![surviving_probe()],
)
.with_undischarged_hypotheses(vec!["h_density : DensityHypothesis".to_string()])
.unwrap();
assert!(a2.verify().is_ok());
let outcome = derive_gate_status(&digest, &[a1, a2]);
assert_eq!(
outcome.status,
GateStatus::NeedsVerification,
"{:?}",
outcome.reasons
);
assert!(
outcome
.reasons
.iter()
.any(|r| r.contains("conditional") && r.contains("DensityHypothesis")),
"{:?}",
outcome.reasons
);
}
#[test]
fn two_attachments_same_method_fail_independence() {
let digest = claim_digest("claim X");
let a1 = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
);
let a2 = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![a1.id.clone()],
vec![surviving_probe()],
);
let outcome = derive_gate_status(&digest, &[a1, a2]);
assert_eq!(outcome.status, GateStatus::NeedsVerification);
assert!(
outcome
.reasons
.iter()
.any(|r| r.contains("same") || r.contains("one method/solver"))
);
}
#[test]
fn refuted_probe_drives_refuted() {
let digest = claim_digest("claim X");
let refuting = AdversarialProbe {
kind: ProbeKind::CaseBConfig,
result: ProbeResult::Refuted,
note: "Case B breaks it".to_string(),
evidence_root: String::new(),
};
let a1 = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
);
let a2 = attach(
&digest,
VerifierMethod::LpDualRecompute,
"pulp-cbc",
vec![a1.id.clone()],
vec![refuting],
);
let outcome = derive_gate_status(&digest, &[a1, a2]);
assert_eq!(outcome.status, GateStatus::Refuted);
}
#[test]
fn passed_but_unmatched_does_not_count() {
let digest = claim_digest("claim X");
let wrong_digest = claim_digest("a different claim Y");
let a1 = attach(
&wrong_digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
);
let a2 = attach(
&wrong_digest,
VerifierMethod::LpDualRecompute,
"pulp-cbc",
vec![a1.id.clone()],
vec![surviving_probe()],
);
let outcome = derive_gate_status(&digest, &[a1, a2]);
assert_eq!(outcome.status, GateStatus::NeedsVerification);
assert!(outcome.reasons.iter().any(|r| r.starts_with("G2")));
}
#[test]
fn no_probe_fails_g3() {
let digest = claim_digest("claim X");
let a1 = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![],
);
let a2 = attach(
&digest,
VerifierMethod::LpDualRecompute,
"pulp-cbc",
vec![a1.id.clone()],
vec![],
);
let outcome = derive_gate_status(&digest, &[a1, a2]);
assert_eq!(outcome.status, GateStatus::NeedsVerification);
assert!(outcome.reasons.iter().any(|r| r.starts_with("G3")));
}
#[test]
fn formalism_fidelity_refuted_drives_refuted() {
let digest = claim_digest("claim X");
let fidelity_refuted = AdversarialProbe {
kind: ProbeKind::FormalismFidelity,
result: ProbeResult::Refuted,
note: "statement and its negation both provable".to_string(),
evidence_root: String::new(),
};
let a1 = attach(
&digest,
VerifierMethod::LeanKernel,
"lean4@4.29.1",
vec![],
vec![fidelity_refuted],
);
let a2 = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![a1.id.clone()],
vec![surviving_probe()],
);
let outcome = derive_gate_status(&digest, &[a1, a2]);
assert_eq!(outcome.status, GateStatus::Refuted);
}
#[test]
fn compromised_attachment_excluded_from_matched() {
let digest = claim_digest("claim X");
let a1 = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
);
let a2 = attach(
&digest,
VerifierMethod::LeanKernel,
"lean4@4.29.1",
vec![a1.id.clone()],
vec![surviving_probe()],
)
.with_method_integrity(MethodIntegrity::Compromised)
.unwrap();
let outcome = derive_gate_status(&digest, &[a1, a2]);
assert_eq!(outcome.status, GateStatus::NeedsVerification);
assert!(outcome.reasons.iter().any(|r| r.starts_with("G5")));
assert!(!outcome.reasons.iter().any(|r| r.starts_with("G2")));
}
#[test]
fn sound_attachment_still_verifies() {
let digest = claim_digest("claim X");
let a1 = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
)
.with_method_integrity(MethodIntegrity::Sound)
.unwrap();
let a2 = attach(
&digest,
VerifierMethod::LeanKernel,
"lean4@4.29.1",
vec![a1.id.clone()],
vec![surviving_probe()],
)
.with_method_integrity(MethodIntegrity::Sound)
.unwrap();
let outcome = derive_gate_status(&digest, &[a1, a2]);
assert_eq!(
outcome.status,
GateStatus::Verified,
"{:?}",
outcome.reasons
);
}
#[test]
fn unattested_integrity_serializes_absent_and_id_is_stable() {
let digest = claim_digest("claim X");
let a = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
);
let json = serde_json::to_string(&a).unwrap();
assert!(
!json.contains("method_integrity"),
"default must serialize absent: {json}"
);
a.verify().unwrap();
}
#[test]
fn build_is_content_addressed_and_verifies() {
let digest = claim_digest("claim X");
let a = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
);
assert!(a.id.starts_with("vva_"));
a.verify().unwrap();
}
#[test]
fn tampered_id_rejected() {
let digest = claim_digest("claim X");
let mut a = attach(
&digest,
VerifierMethod::ComputationalSearch,
"cp-sat",
vec![],
vec![surviving_probe()],
);
a.solver_id = "totally-different".to_string();
assert!(a.verify().is_err());
}
#[test]
fn claim_digest_matches_python_rule() {
let d = claim_digest(" claim X ");
assert_eq!(d.len(), 16);
assert_eq!(d, claim_digest("claim X"));
}
}