use crate::ir_nodes::IRProgram;
use super::generate::{
artifact_digest, derive_aggregate_soundness_witnesses,
derive_capability_containment_witness, derive_capability_isolation_witness,
derive_channel_egress_witness, derive_compliance_coverage_witness,
derive_channel_delivery_soundness_witness,
derive_effect_budgeted_witness, derive_effect_row_soundness_witness,
derive_endpoint_retry_witness, derive_interruptible_session_witness,
derive_json_shape_soundness_witness, derive_parked_residual_witness,
derive_shield_halt_witness, derive_socket_credit_witness, derive_tool_call_soundness_witness,
derive_upstream_projection_witness,
};
use super::proof_term::{
CallSoundnessCertificate, ProofTerm, PropertyClass, ResourceBoundsWitness, Witness,
CALL_INTERRUPT_CAUSES, VALID_SIGN_ALGORITHMS,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CheckOutcome {
Verified,
Refuted { reason: String },
DigestMismatch,
UnknownProperty,
}
pub fn check_proof(proof: &ProofTerm, ir: &IRProgram) -> CheckOutcome {
if proof.artifact_digest != artifact_digest(ir) {
return CheckOutcome::DigestMismatch;
}
match (&proof.property, &proof.witness) {
(PropertyClass::ComplianceCoverage, Witness::ComplianceCoverage(w)) => {
check_compliance_coverage(w, ir)
}
(PropertyClass::EffectRowSoundness, Witness::EffectRowSoundness(w)) => {
check_effect_row_soundness(w, ir)
}
(PropertyClass::CapabilityIsolation, Witness::CapabilityIsolation(w)) => {
check_capability_isolation(w, ir)
}
(PropertyClass::ResourceBounds, Witness::ResourceBounds(w)) => {
check_resource_bounds(w, ir)
}
(PropertyClass::ShieldHaltGuarantee, Witness::ShieldHaltGuarantee(w)) => {
check_shield_halt_guarantee(w, ir)
}
(PropertyClass::CapabilityContainment, Witness::CapabilityContainment(w)) => {
check_capability_containment(w, ir)
}
(PropertyClass::ToolCallSoundness, Witness::ToolCallSoundness(w)) => {
check_tool_call_soundness(w, ir)
}
(PropertyClass::EffectBudgeted, Witness::EffectBudgeted(w)) => {
check_effect_budgeted(w, ir)
}
(PropertyClass::JsonShapeSoundness, Witness::JsonShapeSoundness(w)) => {
check_json_shape_soundness(w, ir)
}
(PropertyClass::ChannelDeliverySoundness, Witness::ChannelDeliverySoundness(w)) => {
check_channel_delivery_soundness(w, ir)
}
(PropertyClass::AggregateSoundness, Witness::AggregateSoundness(w)) => {
check_aggregate_soundness(w, ir)
}
(PropertyClass::ChannelEgressSoundness, Witness::ChannelEgressSoundness(w)) => {
check_channel_egress_soundness(w, ir)
}
(
PropertyClass::InterruptibleSessionSoundness,
Witness::InterruptibleSessionSoundness(w),
) => check_interruptible_session_soundness(w, ir),
(PropertyClass::ParkedResidualSoundness, Witness::ParkedResidualSoundness(w)) => {
check_parked_residual_soundness(w, ir)
}
(PropertyClass::UpstreamProjectionSoundness, Witness::UpstreamProjectionSoundness(w)) => {
check_upstream_projection_soundness(w, ir)
}
(PropertyClass::CorsPolicyConsistency, Witness::CorsPolicyConsistency(w)) => {
check_cors_policy_consistency(w, ir)
}
(PropertyClass::TechnicianCommandSafety, Witness::TechnicianCommandSafety(w)) => {
check_technician_command_safety(w, ir)
}
(PropertyClass::CacheSoundness, Witness::CacheSoundness(w)) => {
check_cache_soundness(w, ir)
}
(PropertyClass::ForgeSoundness, Witness::ForgeSoundness(w)) => {
check_forge_soundness(w, ir)
}
(PropertyClass::SavantSoundness, Witness::SavantSoundness(w)) => {
check_savant_soundness(w, ir)
}
(PropertyClass::WardenSoundness, Witness::WardenSoundness(w)) => {
check_warden_soundness(w, ir)
}
(PropertyClass::AuthorizationCoverage, Witness::AuthorizationCoverage(w)) => {
check_authorization_coverage(w, ir)
}
(PropertyClass::CapabilityGrantability, Witness::CapabilityGrantability(w)) => {
check_capability_grantability(w, ir)
}
(PropertyClass::TemporalContextSoundness, Witness::TemporalContextSoundness(w)) => {
check_temporal_context_soundness(w, ir)
}
(PropertyClass::CredentialAttenuation, Witness::CredentialAttenuation(w)) => {
check_credential_attenuation(w, ir)
}
(PropertyClass::SecretCustodySoundness, Witness::SecretCustodySoundness(w)) => {
check_secret_custody_soundness(w, ir)
}
(PropertyClass::ScrapeProvenanceSoundness, Witness::ScrapeProvenanceSoundness(w)) => {
check_scrape_provenance_soundness(w, ir)
}
(PropertyClass::ScopeCoverageSoundness, Witness::ScopeCoverageSoundness(w)) => {
check_scope_coverage_soundness(w, ir)
}
(PropertyClass::DocumentProvenanceSoundness, Witness::DocumentProvenanceSoundness(w)) => {
check_document_provenance_soundness(w, ir)
}
(PropertyClass::DeliveryProvenanceSoundness, Witness::DeliveryProvenanceSoundness(w)) => {
check_delivery_provenance_soundness(w, ir)
}
(PropertyClass::DataspaceSchemaSoundness, Witness::DataspaceSchemaSoundness(w)) => {
check_dataspace_schema_soundness(w, ir)
}
(PropertyClass::GradientSoundness, Witness::GradientSoundness(w)) => {
check_gradient_soundness(w, ir)
}
(PropertyClass::NotificationProvenanceSoundness, Witness::NotificationProvenanceSoundness(w)) => {
check_notification_provenance_soundness(w, ir)
}
(PropertyClass::QuerySafetySoundness, Witness::QuerySafetySoundness(w)) => {
check_query_safety_soundness(w, ir)
}
(PropertyClass::DocumentIngestionSoundness, Witness::DocumentIngestionSoundness(w)) => {
check_document_ingestion_soundness(w, ir)
}
(PropertyClass::InferredCeilingSoundness, Witness::InferredCeilingSoundness(w)) => {
check_inferred_ceiling_soundness(w, ir)
}
_ => CheckOutcome::UnknownProperty,
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProofCheck {
pub index: usize,
pub property: PropertyClass,
pub subject: String,
pub outcome: CheckOutcome,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BundleReport {
pub results: Vec<ProofCheck>,
}
impl BundleReport {
pub fn all_verified(&self) -> bool {
self.results
.iter()
.all(|r| r.outcome == CheckOutcome::Verified)
}
pub fn refutations(&self) -> Vec<&ProofCheck> {
self.results
.iter()
.filter(|r| r.outcome != CheckOutcome::Verified)
.collect()
}
}
pub fn check_bundle(bundle: &super::proof_term::ProofBundle, ir: &IRProgram) -> BundleReport {
let results = bundle
.proofs
.iter()
.enumerate()
.map(|(index, proof)| ProofCheck {
index,
property: proof.property.clone(),
subject: proof.witness.subject_name().to_string(),
outcome: check_proof(proof, ir),
})
.collect();
BundleReport { results }
}
fn check_compliance_coverage(
claimed: &super::proof_term::ComplianceCoverageWitness,
ir: &IRProgram,
) -> CheckOutcome {
let ep = match ir.endpoints.iter().find(|e| e.name == claimed.endpoint_name) {
Some(e) => e,
None => {
return CheckOutcome::Refuted {
reason: format!(
"endpoint '{}' not present in artifact",
claimed.endpoint_name
),
}
}
};
let actual = derive_compliance_coverage_witness(
&ep.name,
&ep.compliance,
&ep.shield_ref,
ir,
);
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.shield_present {
return CheckOutcome::Refuted {
reason: format!(
"endpoint '{}' declares compliance {:?} but has no resolvable shield (shield_ref={:?})",
actual.endpoint_name, actual.required_classes, actual.shield_ref
),
};
}
if !actual.unknown_classes.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"endpoint '{}' declares unknown regulatory class(es) {:?} (not in the closed registry)",
actual.endpoint_name, actual.unknown_classes
),
};
}
if !actual.uncovered_classes.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"endpoint '{}' requires regulatory class(es) {:?} that its shield '{}' does not provide (shield provides {:?})",
actual.endpoint_name,
actual.uncovered_classes,
actual.shield_ref,
actual.provided_classes
),
};
}
CheckOutcome::Verified
}
fn check_effect_row_soundness(
claimed: &super::proof_term::EffectRowSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let tool = match ir.tools.iter().find(|t| t.name == claimed.tool_name) {
Some(t) => t,
None => {
return CheckOutcome::Refuted {
reason: format!(
"tool '{}' not present in artifact",
claimed.tool_name
),
}
}
};
let ext_members = super::generate::extension_effect_members(ir);
let actual =
derive_effect_row_soundness_witness(&tool.name, &tool.effect_row, &ext_members);
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.unknown_bases.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"tool '{}' declares effect entr(ies) with unknown base(s) {:?} (not in the closed effect catalog)",
actual.tool_name, actual.unknown_bases
),
};
}
if !actual.missing_qualifier.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"tool '{}' declares qualifier-requiring effect(s) {:?} without a qualifier (bare stream/trust is unenforceable)",
actual.tool_name, actual.missing_qualifier
),
};
}
if !actual.invalid_stream_qualifier.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"tool '{}' declares stream effect(s) {:?} with an invalid backpressure policy qualifier",
actual.tool_name, actual.invalid_stream_qualifier
),
};
}
if actual.purity_violation {
return CheckOutcome::Refuted {
reason: format!(
"tool '{}' declares `pure` alongside other effects {:?} — a pure tool cannot be effectful",
actual.tool_name, actual.declared_effects
),
};
}
CheckOutcome::Verified
}
fn check_capability_isolation(
claimed: &super::proof_term::CapabilityIsolationWitness,
ir: &IRProgram,
) -> CheckOutcome {
let store = match ir
.axonstore_specs
.iter()
.find(|s| s.name == claimed.store_name)
{
Some(s) => s,
None => {
return CheckOutcome::Refuted {
reason: format!(
"axonstore '{}' not present in artifact",
claimed.store_name
),
}
}
};
let actual = derive_capability_isolation_witness(&store.name, &store.capability);
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if actual.malformed {
return CheckOutcome::Refuted {
reason: format!(
"axonstore '{}' declares a malformed capability gate {:?} (not a valid §32.g scope: ^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)*$)",
actual.store_name, actual.capability
),
};
}
CheckOutcome::Verified
}
fn check_resource_bounds(
claimed: &ResourceBoundsWitness,
ir: &IRProgram,
) -> CheckOutcome {
match claimed {
ResourceBoundsWitness::EndpointRetry { endpoint_name, .. } => {
let ep = match ir.endpoints.iter().find(|e| e.name == *endpoint_name) {
Some(e) => e,
None => {
return CheckOutcome::Refuted {
reason: format!(
"endpoint '{}' not present in artifact",
endpoint_name
),
}
}
};
let actual = derive_endpoint_retry_witness(&ep.name, ep.retries);
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if let ResourceBoundsWitness::EndpointRetry { retries, in_bounds, .. } = &actual {
if !in_bounds {
return CheckOutcome::Refuted {
reason: format!(
"endpoint '{}' declares retries={} outside the bound [0, {}] (negative is nonsensical; above the ceiling is a retry storm)",
ep.name,
retries,
super::proof_term::MAX_RETRIES
),
};
}
}
CheckOutcome::Verified
}
ResourceBoundsWitness::SocketCredit { socket_name, .. } => {
let socket = match ir.sockets.iter().find(|s| s.name == *socket_name) {
Some(s) => s,
None => {
return CheckOutcome::Refuted {
reason: format!(
"socket '{}' not present in artifact",
socket_name
),
}
}
};
let credit = match socket.backpressure_credit {
Some(k) => k,
None => {
return CheckOutcome::Refuted {
reason: format!(
"socket '{}' has no declared backpressure credit in the artifact, but the witness claims one (forged or stale proof)",
socket_name
),
}
}
};
let actual = derive_socket_credit_witness(&socket.name, credit);
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if let ResourceBoundsWitness::SocketCredit { credit, positive, .. } = &actual {
if !positive {
return CheckOutcome::Refuted {
reason: format!(
"socket '{}' declares backpressure credit({}) — a window < 1 deadlocks the §Fase 41.b typed-resource gate",
socket.name, credit
),
};
}
}
CheckOutcome::Verified
}
}
}
fn check_shield_halt_guarantee(
claimed: &super::proof_term::ShieldHaltGuaranteeWitness,
ir: &IRProgram,
) -> CheckOutcome {
let shield = match ir.shields.iter().find(|s| s.name == claimed.shield_name) {
Some(s) => s,
None => {
return CheckOutcome::Refuted {
reason: format!(
"shield '{}' not present in artifact",
claimed.shield_name
),
}
}
};
let actual = derive_shield_halt_witness(
&shield.name,
&shield.on_breach,
&shield.scan,
&shield.sign,
);
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.known_policy {
return CheckOutcome::Refuted {
reason: format!(
"shield '{}' declares an unknown on_breach policy {:?} (not in the closed breach-policy catalog)",
actual.shield_name, actual.on_breach
),
};
}
if actual.vacuous_halt {
return CheckOutcome::Refuted {
reason: format!(
"shield '{}' declares `on_breach: halt` but neither `scan:` nor `sign:` — the halt can never fire (nothing enforced ⟹ no breach ⟹ no halt): a vacuous guarantee",
actual.shield_name
),
};
}
CheckOutcome::Verified
}
fn check_capability_containment(
claimed: &super::proof_term::CapabilityContainmentWitness,
ir: &IRProgram,
) -> CheckOutcome {
let ep = match ir.endpoints.iter().find(|e| e.name == claimed.endpoint_name) {
Some(e) => e,
None => {
return CheckOutcome::Refuted {
reason: format!(
"endpoint '{}' not present in artifact",
claimed.endpoint_name
),
}
}
};
let actual = derive_capability_containment_witness(
&ep.name,
&ep.execute_flow,
&ep.requires_capabilities,
ir,
);
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.flow_resolved {
return CheckOutcome::Refuted {
reason: format!(
"endpoint '{}' executes flow '{}' which is not present in the artifact — cannot certify capability containment",
actual.endpoint_name, actual.execute_flow
),
};
}
if !actual.uncovered_gates.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"endpoint '{}' reaches store(s) gated by capabilit(ies) {:?} that its declared `requires:` {:?} does not cover — a capability leak (a request satisfying the declared requires could reach a store it is not authorized for)",
actual.endpoint_name, actual.uncovered_gates, actual.declared_requires
),
};
}
CheckOutcome::Verified
}
fn check_tool_call_soundness(
claimed: &super::proof_term::ToolCallSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match derive_tool_call_soundness_witness(
&claimed.flow_name,
claimed.call_index,
ir,
) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: format!(
"flow '{}' has no structured `use` call at index {} in this artifact",
claimed.flow_name, claimed.call_index
),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.schema_present {
return CheckOutcome::Verified;
}
if !actual.unknown_args.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"call to tool '{}' in flow '{}' passes argument(s) {:?} the tool does not declare (declared parameters: {:?})",
actual.tool_name, actual.flow_name, actual.unknown_args, actual.declared_params
),
};
}
if !actual.duplicate_args.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"call to tool '{}' in flow '{}' supplies duplicate argument(s) {:?}",
actual.tool_name, actual.flow_name, actual.duplicate_args
),
};
}
if !actual.missing_required.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"call to tool '{}' in flow '{}' omits required argument(s) {:?}",
actual.tool_name, actual.flow_name, actual.missing_required
),
};
}
if !actual.type_mismatches.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"call to tool '{}' in flow '{}' has literal-argument type mismatch(es) {:?} (each `arg:expected:got`)",
actual.tool_name, actual.flow_name, actual.type_mismatches
),
};
}
CheckOutcome::Verified
}
fn check_effect_budgeted(
claimed: &super::proof_term::EffectBudgetedWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match derive_effect_budgeted_witness(&claimed.daemon_name, ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: format!(
"daemon '{}' has no `budget {{ }}` in this artifact",
claimed.daemon_name
),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.unresolved_effects.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"daemon '{}' budget targets undefined tool(s) {:?} — no matching `tool` declaration",
actual.daemon_name, actual.unresolved_effects
),
};
}
if !actual.nonpositive_limits.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"daemon '{}' budget has non-positive quota limit(s) {:?} (each `effect:kind`)",
actual.daemon_name, actual.nonpositive_limits
),
};
}
if !actual.invalid_periods.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"daemon '{}' budget has out-of-catalog period(s) {:?} (each `effect:period`; valid: {:?})",
actual.daemon_name, actual.invalid_periods, super::proof_term::VALID_BUDGET_PERIODS
),
};
}
if !actual.on_exhausted_valid {
return CheckOutcome::Refuted {
reason: format!(
"daemon '{}' budget has an out-of-catalog `on_exhausted` policy '{}' (valid: {:?})",
actual.daemon_name, actual.on_exhausted, super::proof_term::VALID_ON_EXHAUSTED
),
};
}
CheckOutcome::Verified
}
fn check_json_shape_soundness(
claimed: &super::proof_term::JsonShapeSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match derive_json_shape_soundness_witness(&claimed.store_name, ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: format!(
"axonstore '{}' declares no inline `Json<T>` lens column in this artifact",
claimed.store_name
),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.unresolved_shapes.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axonstore '{}' declares `Json<T>` lens column(s) {:?} (each `column:Shape`) \
whose shape is not a declared `type` — the lens cannot be field-checked, so \
navigation soundness is unprovable. Declare the struct, or use open `Json`.",
actual.store_name, actual.unresolved_shapes
),
};
}
CheckOutcome::Verified
}
fn check_channel_delivery_soundness(
claimed: &super::proof_term::ChannelDeliverySoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match derive_channel_delivery_soundness_witness(&claimed.channel_name, ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: format!(
"channel '{}' has no `daemon` `listen`er in this artifact (no delivery \
contract to certify)",
claimed.channel_name
),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.has_producer {
return CheckOutcome::Refuted {
reason: format!(
"channel '{}' has a `daemon` `listen`er but NO producer — nothing `emit`s to \
it, so the listener can never fire. Add an `emit {}(…)` in a flow, or remove \
the listener (the Kivi brief #39 defect, now machine-checked).",
actual.channel_name, actual.channel_name
),
};
}
CheckOutcome::Verified
}
fn check_aggregate_soundness(
claimed: &super::proof_term::AggregateSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let derived = derive_aggregate_soundness_witnesses(ir);
if !derived.iter().any(|w| w == claimed) {
return CheckOutcome::Refuted {
reason: format!(
"no aggregate-retrieve site in this artifact matches the witness \
(flow '{}', store '{}', aggregate '{}') — forged or stale proof",
claimed.flow_name, claimed.store_name, claimed.aggregate
),
};
}
if !claimed.violations.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"aggregate-retrieve on store '{}' in flow '{}' is UNSOUND: {}",
claimed.store_name,
claimed.flow_name,
claimed.violations.join("; ")
),
};
}
CheckOutcome::Verified
}
fn check_channel_egress_soundness(
claimed: &super::proof_term::ChannelEgressSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match derive_channel_egress_witness(&claimed.channel_name, ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: format!(
"channel '{}' carries no egress contract in this artifact (no declared \
`egress_sign`, no signing publish site) — forged or stale proof",
claimed.channel_name
),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if actual.declared_egress_sign != actual.derived_sign {
return CheckOutcome::Refuted {
reason: format!(
"channel '{}' egress marking '{}' disagrees with the program's publish \
sites (derived '{}') — the egress surface is not derivable from the \
source (forged handle or stale lowering)",
actual.channel_name, actual.declared_egress_sign, actual.derived_sign
),
};
}
if !VALID_SIGN_ALGORITHMS.contains(&actual.derived_sign.as_str()) {
return CheckOutcome::Refuted {
reason: format!(
"channel '{}' declares egress signing '{}' — not in the closed signing \
catalog {:?}",
actual.channel_name, actual.derived_sign, VALID_SIGN_ALGORITHMS
),
};
}
if !actual.durable {
return CheckOutcome::Refuted {
reason: format!(
"channel '{}' is egress-published under shield '{}' (`sign: {}`) but its \
persistence is '{}' — signed egress requires `persistence: \
persistent_axonstore` (axon-T848)",
actual.channel_name, actual.shield_ref, actual.derived_sign, actual.persistence
),
};
}
CheckOutcome::Verified
}
fn check_cors_policy_consistency(
claimed: &super::proof_term::CorsPolicyConsistencyWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_cors_policy_consistency_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no cors contract exists in this artifact (no `cors` declarations, \
no `cors:` references) — forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.all_references_resolve {
return CheckOutcome::Refuted {
reason: format!(
"axon-T856 an `axonendpoint.cors:` reference does not resolve to a declared \
`cors` — declared: {:?}, referenced: {:?}",
actual.declared_cors_names, actual.endpoint_cors_refs
),
};
}
if !actual.wildcard_credential_violations.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T853 cors declaration(s) combine an any-origin `allow_origins` with \
`allow_credentials: true` (CORS spec violation): {:?}",
actual.wildcard_credential_violations
),
};
}
if !actual.cross_method_conflicts.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T857 axonendpoints sharing a path disagree on `cors:` \
(endpoint_a, endpoint_b) pairs: {:?}",
actual.cross_method_conflicts
),
};
}
CheckOutcome::Verified
}
fn check_credential_attenuation(
claimed: &super::proof_term::CredentialAttenuationWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_credential_attenuation_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no credential contract exists in this artifact (no `credential` \
declarations, no `mint` sites) — forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.unresolved_mints.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T895 `mint` reference(s) do not resolve to a declared `credential`: {:?}",
actual.unresolved_mints
),
};
}
if !actual.invalid_contracts.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T893/axon-T894 ill-formed credential contract(s) (empty/invalid \
grants, or TTL outside the (0, 24h] ephemeral ceiling): {:?}",
actual.invalid_contracts
),
};
}
CheckOutcome::Verified
}
fn check_secret_custody_soundness(
claimed: &super::proof_term::SecretCustodySoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_secret_custody_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no custody contract exists in this artifact (no `backend: \
secrets` store, no `rotate` sites) — forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.unresolved_stores.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T898 `rotate` target(s) do not resolve to a declared `backend: \
secrets` store: {:?}",
actual.unresolved_stores
),
};
}
if !actual.unresolved_tools.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T899 `rotate` tool(s) do not resolve to a declared `tool`: {:?}",
actual.unresolved_tools
),
};
}
if !actual.invalid_classes.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T900 secrets store(s) with a missing or shape-invalid `class:`: {:?}",
actual.invalid_classes
),
};
}
if !actual.write_violations.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T897 write verb(s) against a secrets store (custody is written \
only by the seed API and the mediated rotate commit): {:?}",
actual.write_violations
),
};
}
if !actual.partition_violations.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T903 tool(s) with an ill-formed `secret_partition:` — a partition \
must name a required `String` parameter of the SAME tool, alongside a \
`secret:`, and never on a technician tool. The \
`selection_without_revelation` class-containment guarantee (the resolved \
dispatch key never leaves the tool's class) rests on this: {:?}",
actual.partition_violations
),
};
}
CheckOutcome::Verified
}
fn check_temporal_context_soundness(
claimed: &super::proof_term::TemporalContextSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_temporal_context_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no temporal contract exists in this artifact (no `now:` \
declarations on any step or context) — forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.format_violations.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T892 declared `now:` zone(s) violate the IANA shape law \
(expected \"Area/Location\" or \"UTC\"): {:?}",
actual.format_violations
),
};
}
if !actual.unknown_zones.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"declared `now:` zone(s) pass the shape law but are NOT in this build's \
IANA tz database (tzdb {}) — the run would fail closed at the first \
`now:`-bearing step: {:?}",
crate::window::tz_db_version(),
actual.unknown_zones
),
};
}
CheckOutcome::Verified
}
fn check_technician_command_safety(
claimed: &super::proof_term::TechnicianCommandSafetyWitness,
ir: &IRProgram,
) -> CheckOutcome {
let tool = match ir.tools.iter().find(|t| t.name == claimed.tool_name) {
Some(t) => t,
None => {
return CheckOutcome::Refuted {
reason: format!(
"no technician tool '{}' exists in this artifact — forged or stale proof",
claimed.tool_name
),
}
}
};
let actual = match super::generate::derive_technician_command_safety_witness(tool, ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: format!(
"tool '{}' is not a technician tool (no `target:`) — forged or stale proof",
claimed.tool_name
),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.argv_present {
return CheckOutcome::Refuted {
reason: format!(
"axon-T858 technician tool '{}' binds `target:` on `provider: bash` but declares \
no `argv:` template",
actual.tool_name
),
};
}
if !actual.unbound_placeholders.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T859 technician tool '{}' has argv placeholder(s) not bound to a declared \
parameter: {:?}",
actual.tool_name, actual.unbound_placeholders
),
};
}
if !actual.partial_tokens.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T859 technician tool '{}' has partial/fused argv token(s) (a `${{param}}` \
must be a whole argv element): {:?}",
actual.tool_name, actual.partial_tokens
),
};
}
if !actual.confirm_branch_reachable {
return CheckOutcome::Refuted {
reason: format!(
"axon-T860 technician tool '{}' is `risk: destructive` but its bound session '{}' \
offers no reachable `branch{{ approved / denied }}` confirmation",
actual.tool_name, actual.session_name
),
};
}
CheckOutcome::Verified
}
fn check_forge_soundness(
claimed: &super::proof_term::ForgeSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let mut found = None;
for flow in &ir.flows {
if flow.name != claimed.flow_name {
continue;
}
let mut forges = Vec::new();
super::generate::__collect_forge_for_check(&flow.steps, &mut forges);
if let Some(f) = forges.into_iter().find(|f| f.name == claimed.forge_name) {
found = Some(f);
break;
}
}
let forge = match found {
Some(f) => f,
None => {
return CheckOutcome::Refuted {
reason: format!(
"no forge '{}' in flow '{}' — forged or stale proof",
claimed.forge_name, claimed.flow_name
),
}
}
};
let actual = super::generate::derive_forge_soundness_witness(&claimed.flow_name, forge, ir);
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.mode_ok {
return CheckOutcome::Refuted {
reason: format!("axon-T868 forge '{}' has an unknown creativity mode", actual.forge_name),
};
}
if !actual.novelty_in_range {
return CheckOutcome::Refuted {
reason: format!("axon-T869 forge '{}' novelty is outside [0,1]", actual.forge_name),
};
}
if !actual.bounds_ok {
return CheckOutcome::Refuted {
reason: format!("axon-T870 forge '{}' depth/branches < 1", actual.forge_name),
};
}
if !actual.seed_and_type_present {
return CheckOutcome::Refuted {
reason: format!("axon-T872 forge '{}' missing seed or return type", actual.forge_name),
};
}
if !actual.constraints_ok {
return CheckOutcome::Refuted {
reason: format!(
"axon-T871 forge '{}' `constraints:` does not resolve to an anchor with a \
confidence_floor",
actual.forge_name
),
};
}
CheckOutcome::Verified
}
fn check_savant_soundness(
claimed: &super::proof_term::SavantSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let savant = match ir.savants.iter().find(|s| s.name == claimed.savant_name) {
Some(s) => s,
None => {
return CheckOutcome::Refuted {
reason: format!(
"no savant '{}' in program — forged or stale proof",
claimed.savant_name
),
}
}
};
let actual = super::generate::derive_savant_soundness_witness(savant, ir);
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.domain_present {
return CheckOutcome::Refuted {
reason: format!("axon-T873 savant '{}' has no `domain:`", actual.savant_name),
};
}
if !actual.mandate_ok {
return CheckOutcome::Refuted {
reason: format!(
"axon-T874 savant '{}' has no well-formed `mandate` (objective + output)",
actual.savant_name
),
};
}
if !actual.budget_bounded {
return CheckOutcome::Refuted {
reason: format!(
"axon-T877 savant '{}' declares no positive `budget.max_iterations` — an \
unbounded autonomous loop is fail-open",
actual.savant_name
),
};
}
if !actual.cognition_ok {
return CheckOutcome::Refuted {
reason: format!(
"axon-T876 savant '{}' has an out-of-catalog cognition parameter",
actual.savant_name
),
};
}
if !actual.memory_ref_ok {
return CheckOutcome::Refuted {
reason: format!(
"axon-T875 savant '{}' `memory.backend` does not resolve to a memory/corpus",
actual.savant_name
),
};
}
CheckOutcome::Verified
}
fn check_warden_soundness(
claimed: &super::proof_term::WardenSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let mut found = None;
for flow in &ir.flows {
if flow.name != claimed.flow_name {
continue;
}
let mut wardens = Vec::new();
super::generate::__collect_warden_for_check(&flow.steps, &mut wardens);
if let Some(w) = wardens
.into_iter()
.find(|w| w.target == claimed.warden_target && w.scope_ref == claimed.scope_ref)
{
found = Some(w);
break;
}
}
let warden = match found {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: format!(
"no warden '{}' within '{}' in flow '{}' — forged or stale proof",
claimed.warden_target, claimed.scope_ref, claimed.flow_name
),
}
}
};
let actual = super::generate::derive_warden_soundness_witness(&claimed.flow_name, warden, ir);
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.scope_resolves {
return CheckOutcome::Refuted {
reason: format!(
"axon-T887 warden '{}' `within {}` does not resolve to a declared scope",
actual.warden_target, actual.scope_ref
),
};
}
if !actual.targets_nonempty {
return CheckOutcome::Refuted {
reason: format!(
"axon-T884 scope '{}' has an empty `targets` allowlist",
actual.scope_ref
),
};
}
if !actual.depth_ok {
return CheckOutcome::Refuted {
reason: format!("axon-T885 scope '{}' has an out-of-catalog depth", actual.scope_ref),
};
}
if !actual.approver_present {
return CheckOutcome::Refuted {
reason: format!("axon-T886 scope '{}' names no approver", actual.scope_ref),
};
}
CheckOutcome::Verified
}
fn check_authorization_coverage(
claimed: &super::proof_term::AuthorizationCoverageWitness,
ir: &IRProgram,
) -> CheckOutcome {
let ep = match ir.endpoints.iter().find(|e| e.name == claimed.endpoint_name) {
Some(e) => e,
None => {
return CheckOutcome::Refuted {
reason: format!(
"no axonendpoint '{}' in the artifact — forged or stale proof",
claimed.endpoint_name
),
}
}
};
let actual = super::generate::derive_authorization_coverage_witness(ep);
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.authorized {
return CheckOutcome::Refuted {
reason: format!(
"axon-T890 axonendpoint '{}' dispatches a flow but declares no authorization \
coverage (no `requires:`/`shield:`/`compliance:`) and is not `public: true` \
— an unguarded boundary (doctrine `every_boundary_is_guarded`)",
actual.endpoint_name
),
};
}
CheckOutcome::Verified
}
fn check_capability_grantability(
claimed: &super::proof_term::CapabilityGrantabilityWitness,
ir: &IRProgram,
) -> CheckOutcome {
use std::collections::BTreeSet;
let required: Vec<String> = ir
.endpoints
.iter()
.filter(|e| !e.execute_flow.is_empty())
.flat_map(|e| e.requires_capabilities.iter().cloned())
.collect::<BTreeSet<String>>()
.into_iter()
.collect();
if required != claimed.required {
return CheckOutcome::Refuted {
reason: "requires-set disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
let grantable = crate::auth_scope::build_grantable_set(claimed.authorities.iter());
if !grantable.collisions.is_empty() {
let (a, b, cap) = &grantable.collisions[0];
return CheckOutcome::Refuted {
reason: format!(
"fractured capability namespace: authorities '{a}' and '{b}' both project to \
'{cap}' — the grantable set is ambiguous (doctrine \
`every_requirement_is_grantable`)"
),
};
}
if !grantable.unprojectable.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"authority '{}' does not project to a valid capability slug — malformed catalog",
grantable.unprojectable[0]
),
};
}
match crate::auth_scope::check_grantable(&required, &grantable.caps) {
crate::auth_scope::GrantabilityVerdict::Grantable => {}
crate::auth_scope::GrantabilityVerdict::Ungrantable { ungrantable, .. } => {
return CheckOutcome::Refuted {
reason: format!(
"axon-T891 `requires: [{}]` is not grantable — no authority in the catalog \
grants it (a dead boundary, declarable but never satisfiable; doctrine \
`every_requirement_is_grantable`)",
ungrantable.join(", ")
),
};
}
}
if !claimed.all_grantable {
return CheckOutcome::Refuted {
reason: "witness claims all_grantable=false but re-derivation found every requirement \
grantable (forged or stale proof)"
.to_string(),
};
}
CheckOutcome::Verified
}
fn check_cache_soundness(
claimed: &super::proof_term::CacheSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_cache_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no cache contract exists in this artifact (no `cache` declarations, no \
`tool.cache:` references) — forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if actual.default_count > 1 {
return CheckOutcome::Refuted {
reason: format!(
"axon-T863 {} caches declare `default: true` (must be ≤ 1)",
actual.default_count
),
};
}
if !actual.widened_without_ttl.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T865 cache(s) widen `apply_to_effects:` beyond [pure] with no `ttl:`: {:?}",
actual.widened_without_ttl
),
};
}
if !actual.unresolved_refs.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T864 unresolved cache/channel reference(s): {:?}",
actual.unresolved_refs
),
};
}
CheckOutcome::Verified
}
fn check_scrape_provenance_soundness(
claimed: &super::proof_term::ScrapeProvenanceSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_scrape_provenance_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no web-acquisition contract exists in this artifact (no scrape tool) — \
forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.tools_missing_web.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T904 scrape tool(s) omit the `web` effect (scraped values must be born \
Untrusted): {:?}",
actual.tools_missing_web
),
};
}
if !actual.dom_tools_with_network.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T904 scrape_dom tool(s) dishonestly declare `network` (they do no I/O): {:?}",
actual.dom_tools_with_network
),
};
}
if !actual.unshielded_flows.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T908 content-injection barrier: flow(s) feed web content to an agent's \
beliefs with no shield: {:?}",
actual.unshielded_flows
),
};
}
CheckOutcome::Verified
}
fn check_scope_coverage_soundness(
claimed: &super::proof_term::ScopeCoverageSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_scope_coverage_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no scope-coverage contract exists in this artifact (no tool declares \
`requires:`) — forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.uncovered_uses.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T956 scope coverage: tool use(s) require a scope the program's granted set \
does not cover (flow, tool, missing_scope): {:?}",
actual.uncovered_uses
),
};
}
CheckOutcome::Verified
}
fn check_document_provenance_soundness(
claimed: &super::proof_term::DocumentProvenanceSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_document_provenance_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no document contract exists in this artifact (no `document`) — forged or \
stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.bad_targets.is_empty() {
return CheckOutcome::Refuted {
reason: format!("axon-T910 document(s) with an invalid target: {:?}", actual.bad_targets),
};
}
if !actual.sensitive_without_legal.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T913 document(s) bind sensitive data with no legal basis: {:?}",
actual.sensitive_without_legal
),
};
}
if !actual.unattributed_slots.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T916 assertion-laundering barrier: unattributed flow value(s) in assertive \
slots: {:?}",
actual.unattributed_slots
),
};
}
CheckOutcome::Verified
}
fn check_delivery_provenance_soundness(
claimed: &super::proof_term::DeliveryProvenanceSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_delivery_provenance_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no delivery contract exists in this artifact (no `deliver`) — forged or \
stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.bad_targets.is_empty() {
return CheckOutcome::Refuted {
reason: format!("axon-T921 delivery(ies) with an invalid target: {:?}", actual.bad_targets),
};
}
if !actual.sensitive_without_legal.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T924 delivery(ies) bind sensitive data with no legal basis: {:?}",
actual.sensitive_without_legal
),
};
}
if !actual.laundered_deliveries.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T920 provenance-stripping barrier: `provenance: cleared` delivery(ies) \
laundering an unshielded flow value into a CRM: {:?}",
actual.laundered_deliveries
),
};
}
CheckOutcome::Verified
}
fn check_notification_provenance_soundness(
claimed: &super::proof_term::NotificationProvenanceSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_notification_provenance_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no notify declaration exists in this artifact — forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.bad_structure.is_empty()
|| !actual.bad_windows.is_empty()
|| !actual.laundered_notifications.is_empty()
{
return CheckOutcome::Refuted {
reason: format!(
"axon-T933/T934/T935 notification law violated (stale or hand-edited \
artifact): structure={:?} windows={:?} laundered={:?}",
actual.bad_structure, actual.bad_windows, actual.laundered_notifications
),
};
}
CheckOutcome::Verified
}
fn check_gradient_soundness(
claimed: &super::proof_term::GradientSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_gradient_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no grad step exists in this artifact — forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.violations.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T931/axon-T932 gradient law violated (a stored derivative does not \
match its re-derivation — hand-edited or stale artifact): {:?}",
actual.violations
),
};
}
CheckOutcome::Verified
}
fn check_dataspace_schema_soundness(
claimed: &super::proof_term::DataspaceSchemaSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_dataspace_schema_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no dataspace surface exists in this artifact — forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.violations.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T928/axon-T930 dataspace-schema law violated (the compile-time check \
did not run over this IR — stale or hand-edited artifact): {:?}",
actual.violations
),
};
}
CheckOutcome::Verified
}
fn check_query_safety_soundness(
claimed: &super::proof_term::QuerySafetySoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_query_safety_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no QUERY endpoint exists in this artifact — forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.unsafe_queries.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T927 QUERY-safety: endpoint(s) declare `method: QUERY` but their flow \
performs a declared write (RFC 10008 §2 — a QUERY MUST be safe and idempotent; \
caches, proxies and clients may retry it freely): {:?}",
actual.unsafe_queries
),
};
}
if !actual.egress_declarations.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T927 QUERY-safety: this program declares an egress that fires for every \
flow, so no QUERY endpoint here can be safe: {:?}",
actual.egress_declarations
),
};
}
CheckOutcome::Verified
}
fn check_document_ingestion_soundness(
claimed: &super::proof_term::DocumentIngestionSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_document_ingestion_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no ingestion contract exists in this artifact (no `ingest:*` tool) — \
forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.inferred_ceiling_violations.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T1001 tool(s) declare `ingest:inferred` + `epistemic:know` (an inferred \
read can never be `know`): {:?}",
actual.inferred_ceiling_violations
),
};
}
if !actual.unshielded_flows.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T908 ingestion barrier: flow(s) feed ingested content to an agent's beliefs \
with no shield: {:?}",
actual.unshielded_flows
),
};
}
CheckOutcome::Verified
}
fn check_inferred_ceiling_soundness(
claimed: &super::proof_term::InferredCeilingSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match super::generate::derive_inferred_ceiling_soundness_witness(ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: "no `ingest:inferred` producer exists in this artifact — the §100 vacuum \
holds; forged or stale proof"
.to_string(),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.ceiling_violations.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T1001 `ingest:inferred` producer(s) also declare `epistemic:know` (an \
inferred read can never be `know`, D101.1): {:?}",
actual.ceiling_violations
),
};
}
if !actual.unshielded_flows.is_empty() {
return CheckOutcome::Refuted {
reason: format!(
"axon-T908 barrier: flow(s) feed an inferred read to an agent's beliefs with no \
shield: {:?}",
actual.unshielded_flows
),
};
}
CheckOutcome::Verified
}
fn check_interruptible_session_soundness(
claimed: &super::proof_term::InterruptibleSessionSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match derive_interruptible_session_witness(
&claimed.session_name,
&claimed.role_name,
&claimed.signal,
ir,
) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: format!(
"no interrupt region with signal '{}' in session '{}' role '{}' — \
forged or stale proof",
claimed.signal, claimed.session_name, claimed.role_name
),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.signal_in_catalog {
return CheckOutcome::Refuted {
reason: format!(
"interrupt signal '{}' is not a CallInterruptCause {:?}",
actual.signal, CALL_INTERRUPT_CAUSES
),
};
}
if !actual.has_body || !actual.has_handler {
return CheckOutcome::Refuted {
reason: format!(
"interrupt region in session '{}' role '{}' is missing its {} arm",
actual.session_name,
actual.role_name,
if !actual.has_body { "body" } else { "resumable handler" }
),
};
}
if !actual.handler_reaches_exit {
return CheckOutcome::Refuted {
reason: format!(
"interrupt handler in session '{}' role '{}' does not reach a two-exit \
terminal (`resume` or `end`, D79.11a)",
actual.session_name, actual.role_name
),
};
}
CheckOutcome::Verified
}
fn check_parked_residual_soundness(
claimed: &super::proof_term::ParkedResidualSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match derive_parked_residual_witness(&claimed.socket_name, ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: format!(
"socket '{}' carries no interruptible session in this artifact (no parked-\
residual obligation) — forged or stale proof",
claimed.socket_name
),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.reconnect_cognitive_state {
return CheckOutcome::Refuted {
reason: format!(
"socket '{}' parks an interruptible residual but does not declare `reconnect: \
cognitive_state` — the at-rest κ would be an unsealed second store (paper §7)",
actual.socket_name
),
};
}
if !actual.legal_basis_declared {
return CheckOutcome::Refuted {
reason: format!(
"socket '{}' parks a possibly-PII-bearing residual but declares no `legal_basis` \
— the at-rest retention TTL has no legal ceiling (paper §7)",
actual.socket_name
),
};
}
CheckOutcome::Verified
}
fn check_upstream_projection_soundness(
claimed: &super::proof_term::UpstreamProjectionSoundnessWitness,
ir: &IRProgram,
) -> CheckOutcome {
let actual = match derive_upstream_projection_witness(&claimed.upstream_name, ir) {
Some(w) => w,
None => {
return CheckOutcome::Refuted {
reason: format!(
"upstream '{}' does not exist in this artifact — forged or stale proof",
claimed.upstream_name
),
}
}
};
if actual != *claimed {
return CheckOutcome::Refuted {
reason: "witness disagrees with artifact re-derivation (forged or stale proof)"
.to_string(),
};
}
if !actual.projection_total {
return CheckOutcome::Refuted {
reason: format!(
"upstream '{}': the `map:` projection is not a total, unambiguous cover of \
session '{}' role '{}' — a message would cross the boundary untranscoded (T849)",
actual.upstream_name, actual.session_name, actual.role_name
),
};
}
if !actual.config_keys_valid {
return CheckOutcome::Refuted {
reason: format!(
"upstream '{}': `resolve:`/`secret:` are not policy-shaped config keys — an \
endpoint or credential literal is in the artifact (T850)",
actual.upstream_name
),
};
}
CheckOutcome::Verified
}
pub fn check_call_soundness_certificate(
cert: &CallSoundnessCertificate,
ir: &IRProgram,
) -> CheckOutcome {
for proof in &cert.proofs {
let outcome = check_proof(proof, ir);
if outcome != CheckOutcome::Verified {
return outcome;
}
}
CheckOutcome::Verified
}