1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//! Kani model checker adapter for formal verification.
//!
//! This module adapts the generic [`Contract`] trait for use
//! with the [Kani Rust Verifier](https://github.com/model-checking/kani).
//!
//! # Kani Integration
//!
//! Kani uses **bounded model checking** to formally verify Rust programs:
//! - Symbolic execution of all possible inputs
//! - SMT solver verification of assertions
//! - Compile-time proofs (not runtime tests)
//!
//! # Example
//!
//! ```rust,ignore
//! use elicitation::verification::{Contract, kani::Tool};
//!
//! struct ValidateEmail;
//!
//! impl Contract for ValidateEmail {
//! type Input = String;
//! type Output = String;
//!
//! fn requires(input: &String) -> bool {
//! input.contains('@')
//! }
//!
//! fn ensures(_input: &String, output: &String) -> bool {
//! output.contains('@')
//! }
//! }
//!
//! #[async_trait::async_trait]
//! impl Tool for ValidateEmail {
//! async fn execute(&self, input: String) -> ElicitResult<String> {
//! // Implementation
//! Ok(input)
//! }
//! }
//!
//! // Kani proof harness
//! #[cfg(kani)]
//! #[kani::proof]
//! fn verify_email_contract() {
//! let input = String::from("test@example.com");
//! kani::assume(ValidateEmail::requires(&input));
//! assert!(input.contains('@')); // ✅ PROVEN
//! }
//! ```
//!
//! # Key Features
//!
//! - **Model Checking**: Explores all possible execution paths
//! - **Bounded Verification**: With `#[kani::unwind(n)]` for loops
//! - **Symbolic Execution**: `kani::any()` for symbolic values
//! - **Contract Checking**: Runtime verification with `verify_and_execute`
use Contract;
use crateElicitResult;
// Re-export Contract as KaniContract for backwards compatibility
pub use Contract as KaniContract;
/// Executable tool with Kani contract verification.
///
/// Extends [`Contract`] with async execution and runtime contract checking.
///
/// # Example
///
/// ```rust,ignore
/// #[async_trait::async_trait]
/// impl Tool for MyTool {
/// async fn execute(&self, input: Self::Input) -> ElicitResult<Self::Output> {
/// // Implementation
/// }
/// }
/// ```
/// Produce an empty `Vec<T>` as a verified proof boundary.
///
/// # Trust boundary
///
/// VSM harnesses verify *our* transition logic, not the correctness of
/// `std::vec::Vec`. Proving `Vec` itself is out of scope; we trust the
/// standard library.
///
/// # Why `Vec::new()` instead of `any_vec` or `bounded_any`
///
/// Both `kani::vec::any_vec::<T, 0>()` and `Vec::<T>::bounded_any::<0>()`
/// leave a symbolic `len` field visible to CBMC:
///
/// - `any_vec` routes through `exact_vec` → `<[T]>::into_vec(Box::new(any()))`,
/// which loses the compile-time `N=0`; the resulting Vec carries a
/// runtime-symbolic `len`.
/// - `bounded_any` calls `vec.truncate(symbolic_real_length)` where
/// `real_length = any_where(|s| *s <= 0)`. Even though constrained to ≤0,
/// CBMC does not reduce `symbolic_0` to the concrete value `0`, so
/// `drop_in_place` on a symbolic-length slice unwinds without bound.
///
/// Both strategies work fine for element types with trivial drop (unit enums,
/// scalar structs) because CBMC can bound the loop body. For types whose
/// destructor reaches `dealloc` (e.g. `String`-bearing structs), the loop
/// body is unbounded and CBMC diverges.
///
/// `Vec::new()` gives CBMC a **concrete** `len = 0`; no loop body is
/// generated at all. The proof scope is: "for any state whose `Vec` fields
/// are empty, the transition is structurally correct." This is the correct
/// scope for structural state-machine invariants.
///
/// Use this function in `kani::Arbitrary` impls for state-enum variants that
/// carry `Vec<T>` payload fields.