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)
}
_ => 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_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_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_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
}