Skip to content
This repository was archived by the owner on May 5, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions crates/presentar-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,58 @@ fn main() {
let cdir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("contracts");
if let Ok(es) = std::fs::read_dir(&cdir) {
#[derive(serde::Deserialize, Default)]
struct CY { #[serde(default)] equations: std::collections::BTreeMap<String, EY> }
struct CY {
#[serde(default)]
equations: std::collections::BTreeMap<String, EY>,
}
#[derive(serde::Deserialize, Default)]
struct EY { #[serde(default)] preconditions: Vec<String>, #[serde(default)] postconditions: Vec<String> }
struct EY {
#[serde(default)]
preconditions: Vec<String>,
#[serde(default)]
postconditions: Vec<String>,
}
let (mut tp, mut tq) = (0, 0);
for e in es.flatten() {
let p = e.path();
if p.extension().and_then(|x| x.to_str()) != Some("yaml") { continue; }
if p.file_name().is_some_and(|n| n.to_string_lossy().contains("binding")) { continue; }
if p.extension().and_then(|x| x.to_str()) != Some("yaml") {
continue;
}
if p.file_name()
.is_some_and(|n| n.to_string_lossy().contains("binding"))
{
continue;
}
println!("cargo:rerun-if-changed={}", p.display());
let s = p.file_stem().and_then(|x| x.to_str()).unwrap_or("x").to_uppercase().replace('-', "_");
let s = p
.file_stem()
.and_then(|x| x.to_str())
.unwrap_or("x")
.to_uppercase()
.replace('-', "_");
if let Ok(c) = std::fs::read_to_string(&p) {
if let Ok(y) = serde_yaml_ng::from_str::<CY>(&c) {
for (n, eq) in &y.equations {
let k = format!("CONTRACT_{}_{}", s, n.to_uppercase().replace('-', "_"));
let k =
format!("CONTRACT_{}_{}", s, n.to_uppercase().replace('-', "_"));
if !eq.preconditions.is_empty() {
println!("cargo:rustc-env={k}_PRE_COUNT={}", eq.preconditions.len());
for (i, v) in eq.preconditions.iter().enumerate() { println!("cargo:rustc-env={k}_PRE_{i}={v}"); }
println!(
"cargo:rustc-env={k}_PRE_COUNT={}",
eq.preconditions.len()
);
for (i, v) in eq.preconditions.iter().enumerate() {
println!("cargo:rustc-env={k}_PRE_{i}={v}");
}
tp += eq.preconditions.len();
}
if !eq.postconditions.is_empty() {
println!("cargo:rustc-env={k}_POST_COUNT={}", eq.postconditions.len());
for (i, v) in eq.postconditions.iter().enumerate() { println!("cargo:rustc-env={k}_POST_{i}={v}"); }
println!(
"cargo:rustc-env={k}_POST_COUNT={}",
eq.postconditions.len()
);
for (i, v) in eq.postconditions.iter().enumerate() {
println!("cargo:rustc-env={k}_POST_{i}={v}");
}
tq += eq.postconditions.len();
}
}
Expand Down
10 changes: 7 additions & 3 deletions crates/presentar-terminal/src/app_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,9 +1195,13 @@ fn test_testable_backend_enable_mouse_capture() {
assert!(!backend.is_mouse_captured());
backend.enable_mouse_capture().unwrap();
assert!(backend.is_mouse_captured());
// Verify escape sequence was written
let output = backend.into_writer();
assert!(!output.is_empty());
// Verify escape sequence was written (Unix only — on Windows, crossterm
// uses the Console API instead of writing ANSI escape sequences)
#[cfg(not(target_os = "windows"))]
{
let output = backend.into_writer();
assert!(!output.is_empty());
}
}

#[test]
Expand Down
16 changes: 11 additions & 5 deletions crates/presentar/tests/contract_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
//! Run with: `cargo test --test contract_traits`

use provable_contracts::traits::{
ActivationKernelV1, AdamwKernelV1, AttentionKernelV1, CrossEntropyKernelV1,
FlashAttentionV1, GqaKernelV1, LayernormKernelV1, MatmulKernelV1, RmsnormKernelV1,
RopeKernelV1, SiluKernelV1, SoftmaxKernelV1, SwigluKernelV1,
ActivationKernelV1, AdamwKernelV1, AttentionKernelV1, CrossEntropyKernelV1, FlashAttentionV1,
GqaKernelV1, LayernormKernelV1, MatmulKernelV1, RmsnormKernelV1, RopeKernelV1, SiluKernelV1,
SoftmaxKernelV1, SwigluKernelV1,
};

/// Marker struct for reference scalar kernel implementations.
Expand Down Expand Up @@ -189,7 +189,10 @@ fn rmsnorm_kernel_v1_properties() {
// out ≈ [3/3.5355, 4/3.5355] ≈ [0.8485, 1.1314]
assert!(out.len() == 2);
let rms_out = (out.iter().map(|v| v * v).sum::<f32>() / out.len() as f32).sqrt();
assert!((rms_out - 1.0).abs() < 1e-3, "rmsnorm output should have ~unit RMS");
assert!(
(rms_out - 1.0).abs() < 1e-3,
"rmsnorm output should have ~unit RMS"
);
}

#[test]
Expand Down Expand Up @@ -221,7 +224,10 @@ fn cross_entropy_kernel_v1_properties() {
}
// exp(log_softmax) should sum to 1
let sum_exp: f32 = lsm.iter().map(|v| v.exp()).sum();
assert!((sum_exp - 1.0).abs() < 1e-5, "exp(log_softmax) must sum to 1");
assert!(
(sum_exp - 1.0).abs() < 1e-5,
"exp(log_softmax) must sum to 1"
);

// cross_entropy with one-hot target
let targets = vec![0.0, 0.0, 1.0];
Expand Down
Loading