22//! Uses the Cassowary algorithm to evaluate constraints against transaction populations.
33
44use serde:: { Deserialize , Serialize } ;
5+ use ledger_attest:: attested;
6+ use crate :: attest:: { Attested , AttestationSpec } ;
57
68/// Constraint strength levels (matching Kasuari).
79#[ derive( Debug , Clone , Copy , PartialEq , Eq , Serialize , Deserialize ) ]
@@ -17,6 +19,7 @@ pub enum ConstraintStrength {
1719}
1820
1921/// Result of constraint evaluation.
22+ #[ attested( "constraint_evaluation_bounded" ) ]
2023#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
2124pub struct ConstraintEvaluation {
2225 /// Whether REQUIRED constraints passed.
@@ -98,6 +101,7 @@ impl ConstraintEvaluation {
98101}
99102
100103/// Structured result from invoice verification.
104+ #[ attested( "invoice_arithmetic_valid" ) ]
101105#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
102106pub struct InvoiceVerification {
103107 pub evaluation : ConstraintEvaluation ,
@@ -106,6 +110,18 @@ pub struct InvoiceVerification {
106110 pub audit_note : String ,
107111}
108112
113+
114+ impl Attested for ConstraintEvaluation {
115+ fn attestation_spec ( ) -> AttestationSpec {
116+ AttestationSpec {
117+ invariant : "constraint_evaluation_bounded" ,
118+ z3_predicate : None ,
119+ kasuari_description : Some ( "strong_ratio, medium_ratio, weak_ratio in [0.0, 1.0]" ) ,
120+ kani_module : Some ( "kani_proofs::vendor_constraints" ) ,
121+ }
122+ }
123+ }
124+
109125/// A historical constraint set for a vendor or category.
110126#[ derive( Debug , Clone , Serialize , Deserialize ) ]
111127pub struct VendorConstraintSet {
@@ -213,6 +229,18 @@ impl LayoutSolver {
213229 }
214230}
215231
232+
233+ impl Attested for InvoiceVerification {
234+ fn attestation_spec ( ) -> AttestationSpec {
235+ AttestationSpec {
236+ invariant : "invoice_arithmetic_valid" ,
237+ z3_predicate : Some ( "total = subtotal + gst" ) ,
238+ kasuari_description : None ,
239+ kani_module : Some ( "kani_proofs::invoice_arithmetic" ) ,
240+ }
241+ }
242+ }
243+
216244#[ cfg( test) ]
217245mod tests {
218246 use super :: * ;
0 commit comments