Skip to main content

mimir_node_map/
inline.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2//! Serialized observations for the common inlined-binding contract.
3//! These records do not themselves establish runtime acceptance.
4use crate::proof::Premise;
5use serde::{Deserialize, Serialize};
6
7#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "kebab-case")]
9pub enum InlineKind {
10    Syscall,
11    /// Competing ordinary call origin, never an inline syscall proof.
12    Call,
13    Hole,
14}
15
16#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
17pub struct InlinePosition {
18    pub file: String,
19    pub line: u32,
20    pub column: u32,
21    pub source: String,
22}
23
24#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
25#[serde(rename_all = "kebab-case")]
26pub enum InlineRefusal {
27    EvidenceMissing,
28    BodyEvidence,
29    BodyAmbiguous,
30    Version,
31    Identity,
32    PositionMismatch,
33    ScopeMismatch,
34    NestedScope,
35    CopyUnaccounted,
36    OriginAmbiguous,
37    TargetMismatch,
38    EventCoverage,
39    KernelIp,
40    NumberUnknown,
41    ResidualTransfer,
42    OrderUnproven,
43    PremiseMismatch,
44}
45
46impl InlineRefusal {
47    pub fn name(&self) -> &'static str {
48        match self {
49            Self::BodyEvidence => "inline-body-evidence",
50            Self::BodyAmbiguous => "inline-body-ambiguous",
51            Self::EvidenceMissing => "inline-evidence-missing",
52            Self::Version => "inline-version",
53            Self::Identity => "inline-identity",
54            Self::PositionMismatch => "inline-position-mismatch",
55            Self::NestedScope => "inline-nested-scope",
56            Self::ScopeMismatch => "inline-scope-mismatch",
57            Self::CopyUnaccounted => "inline-copy-unaccounted",
58            Self::OriginAmbiguous => "inline-origin-ambiguous",
59            Self::TargetMismatch => "inline-target-mismatch",
60            Self::EventCoverage => "inline-event-coverage",
61            Self::KernelIp => "inline-kernel-ip",
62            Self::NumberUnknown => "inline-number-unknown",
63            Self::ResidualTransfer => "inline-residual-transfer",
64            Self::OrderUnproven => "inline-order-unproven",
65            Self::PremiseMismatch => "inline-premise-mismatch",
66        }
67    }
68}
69
70#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
71pub struct InlineScope {
72    pub id: u32,
73    pub parent: Option<u32>,
74    pub linkage: Option<String>,
75    pub ranges: Vec<(u64, u64)>,
76    pub call: Option<InlinePosition>,
77}
78
79#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
80pub struct InlineEvent {
81    pub address: u64,
82    pub length: u8,
83    pub kernel_ip: Option<u64>,
84    pub kind: String,
85    pub position: Option<InlinePosition>,
86    /// None is own code; Some names the selected child scope.
87    pub scope: Option<u32>,
88}
89
90#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
91pub struct InlineCopy {
92    /// Complete decoded instruction inventory for hole-boundary elimination.
93    /// Missing on legacy and syscall-only witnesses; never an empty proof.
94    #[serde(default, skip_serializing_if = "Option::is_none")]
95    pub instructions: Option<Vec<InlineInstruction>>,
96    pub id: u32,
97    pub linkage: String,
98    pub entry: u64,
99    pub outer: u64,
100    pub ranges: Vec<(u64, u64)>,
101    pub own_ranges: Vec<(u64, u64)>,
102    pub scopes: Vec<InlineScope>,
103    /// All decoded syscalls in the copy, before source/scope selection.
104    pub observed_syscalls: Vec<InlineEvent>,
105    /// Exactly the selected events; the consumer must recompute this selection.
106    pub events: Vec<InlineEvent>,
107    pub refusal: Option<InlineRefusal>,
108}
109
110#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
111pub struct InlineInstruction {
112    pub address: u64,
113    pub length: u8,
114    pub kind: String,
115    pub target: Option<u64>,
116    /// Raw linkage identities at a direct target; no name normalization guess.
117    pub symbols: Vec<String>,
118}
119
120#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
121pub struct InlineBinding {
122    pub version: u32,
123    pub node: String,
124    pub site: u32,
125    pub instance: String,
126    pub position: InlinePosition,
127    pub kind: InlineKind,
128    pub targets: Vec<String>,
129    pub copies: Vec<InlineCopy>,
130    pub premises: Vec<Premise>,
131}
132
133/// Independent projection read from pinned exec.nodes, not from this witness.
134#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
135pub struct InlineRow {
136    pub site: u32,
137    pub node: String,
138    pub instance: String,
139    pub position: InlinePosition,
140    pub kind: InlineKind,
141    pub targets: Vec<String>,
142    pub numbers_known: bool,
143}
144
145#[path = "inline_check.rs"]
146mod check;
147pub use check::check_hole;
148pub use check::check_syscalls;
149
150pub use check::check_syscall_bound;