use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum PropertyClass {
ComplianceCoverage,
EffectRowSoundness,
CapabilityIsolation,
ResourceBounds,
ShieldHaltGuarantee,
CapabilityContainment,
ToolCallSoundness,
EffectBudgeted,
JsonShapeSoundness,
ChannelDeliverySoundness,
AggregateSoundness,
ChannelEgressSoundness,
InterruptibleSessionSoundness,
ParkedResidualSoundness,
UpstreamProjectionSoundness,
CorsPolicyConsistency,
TechnicianCommandSafety,
CacheSoundness,
ForgeSoundness,
SavantSoundness,
WardenSoundness,
AuthorizationCoverage,
CapabilityGrantability,
TemporalContextSoundness,
CredentialAttenuation,
SecretCustodySoundness,
ScrapeProvenanceSoundness,
DocumentProvenanceSoundness,
DeliveryProvenanceSoundness,
QuerySafetySoundness,
DataspaceSchemaSoundness,
GradientSoundness,
NotificationProvenanceSoundness,
DocumentIngestionSoundness,
InferredCeilingSoundness,
}
pub const VALID_BUDGET_PERIODS: &[&str] = &["second", "minute", "hour", "day"];
pub const VALID_ON_EXHAUSTED: &[&str] = &["block", "defer", "shed"];
pub const VALID_BREACH_POLICIES: &[&str] =
&["deflect", "escalate", "halt", "quarantine", "sanitize_and_retry"];
pub const MAX_RETRIES: i64 = 100;
impl PropertyClass {
pub fn slug(&self) -> &'static str {
match self {
PropertyClass::ComplianceCoverage => "compliance_coverage",
PropertyClass::EffectRowSoundness => "effect_row_soundness",
PropertyClass::CapabilityIsolation => "capability_isolation",
PropertyClass::ResourceBounds => "resource_bounds",
PropertyClass::ShieldHaltGuarantee => "shield_halt_guarantee",
PropertyClass::CapabilityContainment => "capability_containment",
PropertyClass::ToolCallSoundness => "tool_call_soundness",
PropertyClass::EffectBudgeted => "effect_budgeted",
PropertyClass::JsonShapeSoundness => "json_shape_soundness",
PropertyClass::ChannelDeliverySoundness => "channel_delivery_soundness",
PropertyClass::AggregateSoundness => "aggregate_soundness",
PropertyClass::ChannelEgressSoundness => "channel_egress_soundness",
PropertyClass::InterruptibleSessionSoundness => "interruptible_session_soundness",
PropertyClass::ParkedResidualSoundness => "parked_residual_soundness",
PropertyClass::UpstreamProjectionSoundness => "upstream_projection_soundness",
PropertyClass::CorsPolicyConsistency => "cors_policy_consistency",
PropertyClass::TechnicianCommandSafety => "technician_command_safety",
PropertyClass::CacheSoundness => "cache_soundness",
PropertyClass::ForgeSoundness => "forge_soundness",
PropertyClass::SavantSoundness => "savant_soundness",
PropertyClass::WardenSoundness => "warden_soundness",
PropertyClass::AuthorizationCoverage => "authorization_coverage",
PropertyClass::CapabilityGrantability => "capability_grantability",
PropertyClass::TemporalContextSoundness => "temporal_context_soundness",
PropertyClass::CredentialAttenuation => "credential_attenuation",
PropertyClass::SecretCustodySoundness => "secret_custody_soundness",
PropertyClass::ScrapeProvenanceSoundness => "scrape_provenance_soundness",
PropertyClass::DocumentProvenanceSoundness => "document_provenance_soundness",
PropertyClass::DeliveryProvenanceSoundness => "delivery_provenance_soundness",
PropertyClass::QuerySafetySoundness => "query_safety_soundness",
PropertyClass::DataspaceSchemaSoundness => "dataspace_schema_soundness",
PropertyClass::GradientSoundness => "gradient_soundness",
PropertyClass::NotificationProvenanceSoundness => "notification_provenance_soundness",
PropertyClass::DocumentIngestionSoundness => "document_ingestion_soundness",
PropertyClass::InferredCeilingSoundness => "inferred_ceiling_soundness",
}
}
}
pub const CALL_INTERRUPT_CAUSES: &[&str] =
&["CallerSpeech", "Dtmf", "SilenceTimeout", "AgentFault"];
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ComplianceCoverageWitness {
pub endpoint_name: String,
pub required_classes: Vec<String>,
pub shield_ref: String,
pub shield_present: bool,
pub provided_classes: Vec<String>,
pub unknown_classes: Vec<String>,
pub uncovered_classes: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct EffectRowSoundnessWitness {
pub tool_name: String,
pub declared_effects: Vec<String>,
pub unknown_bases: Vec<String>,
pub missing_qualifier: Vec<String>,
pub invalid_stream_qualifier: Vec<String>,
pub purity_violation: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CapabilityIsolationWitness {
pub store_name: String,
pub capability: String,
pub malformed: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "subject")]
pub enum ResourceBoundsWitness {
EndpointRetry {
endpoint_name: String,
retries: i64,
in_bounds: bool,
},
SocketCredit {
socket_name: String,
credit: i64,
positive: bool,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ShieldHaltGuaranteeWitness {
pub shield_name: String,
pub on_breach: String,
pub known_policy: bool,
pub scan_count: usize,
pub vacuous_halt: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CapabilityContainmentWitness {
pub endpoint_name: String,
pub execute_flow: String,
pub flow_resolved: bool,
pub declared_requires: Vec<String>,
pub reached_gates: Vec<String>,
pub uncovered_gates: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ToolCallSoundnessWitness {
pub flow_name: String,
pub call_index: usize,
pub tool_name: String,
pub arg_names: Vec<String>,
pub declared_params: Vec<String>,
pub schema_present: bool,
pub unknown_args: Vec<String>,
pub duplicate_args: Vec<String>,
pub missing_required: Vec<String>,
pub type_mismatches: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct EffectBudgetedWitness {
pub daemon_name: String,
pub quota_count: usize,
pub declared_tools: Vec<String>,
pub unresolved_effects: Vec<String>,
pub nonpositive_limits: Vec<String>,
pub invalid_periods: Vec<String>,
pub on_exhausted: String,
pub on_exhausted_valid: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct JsonShapeSoundnessWitness {
pub store_name: String,
pub declared_types: Vec<String>,
pub lens_columns: Vec<String>,
pub unresolved_shapes: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ChannelDeliverySoundnessWitness {
pub channel_name: String,
pub persistence: String,
pub qos: String,
pub has_producer: bool,
pub has_consumer: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AggregateSoundnessWitness {
pub flow_name: String,
pub store_name: String,
pub aggregate: String,
pub group_by: String,
pub order_by: String,
pub limit_expr: String,
pub function: String,
pub column: String,
pub group_columns: Vec<String>,
pub violations: Vec<String>,
}
pub const VALID_SIGN_ALGORITHMS: &[&str] = &["hmac_sha256"];
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ChannelEgressSoundnessWitness {
pub channel_name: String,
pub declared_egress_sign: String,
pub derived_sign: String,
pub shield_ref: String,
pub persistence: String,
pub durable: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct InterruptibleSessionSoundnessWitness {
pub session_name: String,
pub role_name: String,
pub signal: String,
pub signal_in_catalog: bool,
pub has_body: bool,
pub has_handler: bool,
pub handler_reaches_exit: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ParkedResidualSoundnessWitness {
pub socket_name: String,
pub session_name: String,
pub session_has_interrupt: bool,
pub reconnect_cognitive_state: bool,
pub legal_basis_declared: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct UpstreamProjectionSoundnessWitness {
pub upstream_name: String,
pub session_name: String,
pub role_name: String,
pub required_sends: Vec<String>,
pub required_receives: Vec<String>,
pub covered_sends: Vec<String>,
pub covered_receives: Vec<String>,
pub projection_total: bool,
pub config_keys_valid: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CorsPolicyConsistencyWitness {
pub declared_cors_names: Vec<String>,
pub endpoint_cors_refs: Vec<(String, String)>,
pub all_references_resolve: bool,
pub wildcard_credential_violations: Vec<String>,
pub cross_method_conflicts: Vec<(String, String)>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TechnicianCommandSafetyWitness {
pub tool_name: String,
pub target_socket: String,
pub session_name: String,
pub risk: String,
pub argv: Vec<String>,
pub argv_present: bool,
pub unbound_placeholders: Vec<String>,
pub partial_tokens: Vec<String>,
pub confirm_branch_reachable: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CacheSoundnessWitness {
pub cache_names: Vec<String>,
pub default_count: usize,
pub widened_without_ttl: Vec<String>,
pub unresolved_refs: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ForgeSoundnessWitness {
pub forge_name: String,
pub flow_name: String,
pub mode: String,
pub novelty_milli: i64,
pub depth: i64,
pub branches: i64,
pub constraints_ref: String,
pub mode_ok: bool,
pub novelty_in_range: bool,
pub bounds_ok: bool,
pub seed_and_type_present: bool,
pub constraints_ok: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SavantSoundnessWitness {
pub savant_name: String,
pub mandate_count: i64,
pub max_iterations: i64,
pub domain_present: bool,
pub mandate_ok: bool,
pub budget_bounded: bool,
pub cognition_ok: bool,
pub memory_ref_ok: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WardenSoundnessWitness {
pub warden_target: String,
pub flow_name: String,
pub scope_ref: String,
pub scope_resolves: bool,
pub targets_nonempty: bool,
pub depth_ok: bool,
pub approver_present: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AuthorizationCoverageWitness {
pub endpoint_name: String,
pub dispatches: bool,
pub has_requires: bool,
pub has_shield: bool,
pub has_compliance: bool,
pub public: bool,
pub authorized: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CapabilityGrantabilityWitness {
pub required: Vec<String>,
pub authorities: Vec<String>,
pub all_grantable: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TemporalContextSoundnessWitness {
pub declarations: Vec<(String, String, String)>,
pub format_violations: Vec<String>,
pub unknown_zones: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CredentialAttenuationWitness {
pub contracts: Vec<(String, u64, Vec<String>)>,
pub mints: Vec<(String, String, String)>,
pub unresolved_mints: Vec<String>,
pub invalid_contracts: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SecretCustodySoundnessWitness {
pub stores: Vec<(String, String)>,
pub rotates: Vec<(String, String, String, String)>,
pub unresolved_stores: Vec<String>,
pub unresolved_tools: Vec<String>,
pub invalid_classes: Vec<String>,
pub write_violations: Vec<(String, String, String)>,
#[serde(default)]
pub partition_violations: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ScrapeProvenanceSoundnessWitness {
pub scrape_tools: Vec<(String, String)>,
pub tools_missing_web: Vec<String>,
pub dom_tools_with_network: Vec<String>,
pub unshielded_flows: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DocumentProvenanceSoundnessWitness {
pub documents: Vec<(String, String)>,
pub bad_targets: Vec<String>,
pub sensitive_without_legal: Vec<String>,
pub unattributed_slots: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DeliveryProvenanceSoundnessWitness {
pub deliveries: Vec<(String, String)>,
pub bad_targets: Vec<String>,
pub sensitive_without_legal: Vec<String>,
pub laundered_deliveries: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct QuerySafetySoundnessWitness {
pub query_endpoints: Vec<(String, String)>,
pub unsafe_queries: Vec<String>,
pub egress_declarations: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GradientSoundnessWitness {
pub grads: Vec<(String, String, String, String)>,
pub violations: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NotificationProvenanceSoundnessWitness {
pub notifications: Vec<(String, String)>,
pub bad_structure: Vec<String>,
pub bad_windows: Vec<String>,
pub laundered_notifications: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DataspaceSchemaSoundnessWitness {
pub dataspaces: Vec<(String, String)>,
pub violations: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DocumentIngestionSoundnessWitness {
pub ingest_tools: Vec<(String, String)>,
pub inferred_ceiling_violations: Vec<String>,
pub unshielded_flows: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct InferredCeilingSoundnessWitness {
pub inferred_producers: Vec<String>,
pub ceiling_violations: Vec<String>,
pub unshielded_flows: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind")]
pub enum Witness {
ComplianceCoverage(ComplianceCoverageWitness),
EffectRowSoundness(EffectRowSoundnessWitness),
EffectBudgeted(EffectBudgetedWitness),
CapabilityIsolation(CapabilityIsolationWitness),
ResourceBounds(ResourceBoundsWitness),
ShieldHaltGuarantee(ShieldHaltGuaranteeWitness),
CapabilityContainment(CapabilityContainmentWitness),
ToolCallSoundness(ToolCallSoundnessWitness),
JsonShapeSoundness(JsonShapeSoundnessWitness),
ChannelDeliverySoundness(ChannelDeliverySoundnessWitness),
AggregateSoundness(AggregateSoundnessWitness),
ChannelEgressSoundness(ChannelEgressSoundnessWitness),
InterruptibleSessionSoundness(InterruptibleSessionSoundnessWitness),
ParkedResidualSoundness(ParkedResidualSoundnessWitness),
UpstreamProjectionSoundness(UpstreamProjectionSoundnessWitness),
CorsPolicyConsistency(CorsPolicyConsistencyWitness),
TechnicianCommandSafety(TechnicianCommandSafetyWitness),
CacheSoundness(CacheSoundnessWitness),
ForgeSoundness(ForgeSoundnessWitness),
SavantSoundness(SavantSoundnessWitness),
WardenSoundness(WardenSoundnessWitness),
AuthorizationCoverage(AuthorizationCoverageWitness),
CapabilityGrantability(CapabilityGrantabilityWitness),
TemporalContextSoundness(TemporalContextSoundnessWitness),
CredentialAttenuation(CredentialAttenuationWitness),
SecretCustodySoundness(SecretCustodySoundnessWitness),
ScrapeProvenanceSoundness(ScrapeProvenanceSoundnessWitness),
DocumentProvenanceSoundness(DocumentProvenanceSoundnessWitness),
DeliveryProvenanceSoundness(DeliveryProvenanceSoundnessWitness),
QuerySafetySoundness(QuerySafetySoundnessWitness),
DataspaceSchemaSoundness(DataspaceSchemaSoundnessWitness),
GradientSoundness(GradientSoundnessWitness),
NotificationProvenanceSoundness(NotificationProvenanceSoundnessWitness),
DocumentIngestionSoundness(DocumentIngestionSoundnessWitness),
InferredCeilingSoundness(InferredCeilingSoundnessWitness),
}
impl Witness {
pub fn subject_name(&self) -> &str {
match self {
Witness::ComplianceCoverage(w) => &w.endpoint_name,
Witness::EffectRowSoundness(w) => &w.tool_name,
Witness::EffectBudgeted(w) => &w.daemon_name,
Witness::CapabilityIsolation(w) => &w.store_name,
Witness::ResourceBounds(ResourceBoundsWitness::EndpointRetry {
endpoint_name,
..
}) => endpoint_name,
Witness::ResourceBounds(ResourceBoundsWitness::SocketCredit {
socket_name,
..
}) => socket_name,
Witness::ShieldHaltGuarantee(w) => &w.shield_name,
Witness::CapabilityContainment(w) => &w.endpoint_name,
Witness::ToolCallSoundness(w) => &w.tool_name,
Witness::JsonShapeSoundness(w) => &w.store_name,
Witness::ChannelDeliverySoundness(w) => &w.channel_name,
Witness::AggregateSoundness(w) => &w.store_name,
Witness::ChannelEgressSoundness(w) => &w.channel_name,
Witness::InterruptibleSessionSoundness(w) => &w.session_name,
Witness::ParkedResidualSoundness(w) => &w.socket_name,
Witness::UpstreamProjectionSoundness(w) => &w.upstream_name,
Witness::CorsPolicyConsistency(_) => "<program>",
Witness::TechnicianCommandSafety(w) => &w.tool_name,
Witness::CacheSoundness(_) => "<program>",
Witness::ForgeSoundness(w) => &w.forge_name,
Witness::SavantSoundness(w) => &w.savant_name,
Witness::WardenSoundness(w) => &w.warden_target,
Witness::AuthorizationCoverage(w) => &w.endpoint_name,
Witness::CapabilityGrantability(_) => "<program>",
Witness::TemporalContextSoundness(_) => "<program>",
Witness::CredentialAttenuation(_) => "<program>",
Witness::SecretCustodySoundness(_) => "<program>",
Witness::ScrapeProvenanceSoundness(_) => "<program>",
Witness::DocumentProvenanceSoundness(_) => "<program>",
Witness::DeliveryProvenanceSoundness(_) => "<program>",
Witness::QuerySafetySoundness(_) => "<program>",
Witness::DataspaceSchemaSoundness(_) => "<program>",
Witness::GradientSoundness(_) => "<program>",
Witness::NotificationProvenanceSoundness(_) => "<program>",
Witness::DocumentIngestionSoundness(_) => "<program>",
Witness::InferredCeilingSoundness(_) => "<program>",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProofTerm {
pub property: PropertyClass,
pub artifact_digest: String,
pub witness: Witness,
pub axon_version: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProofBundle {
pub axon_version: String,
pub artifact_digest: String,
pub proofs: Vec<ProofTerm>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CallSoundnessCertificate {
pub socket_name: String,
pub session_name: String,
pub artifact_digest: String,
pub axon_version: String,
pub proofs: Vec<ProofTerm>,
}