Skip to main content

cbcl_parser/
checkpoint_dialect.rs

1//! Bundled native checkpoint coordination dialect (SPEC-035 CON-3504).
2//! Installation proves native well-formedness, never checkpoint truth. Exact
3//! payload recognition and independently pinned policy checks belong to the
4//! certificate verifier; the source label is not an authority identifier.
5
6use alloc::format;
7use alloc::string::String;
8use cbcl_core::canonical::dialect_name;
9use cbcl_core::dialect::Dialect;
10use cbcl_core::sexpr::{Atom, SExpr};
11
12/// Native definition bundled with this build; its human label is untrusted.
13pub const SOURCE: &str = include_str!("checkpoint.cbcl");
14
15/// Compute the native self-address and install through the shared R1–R7 path.
16/// The returned `hash` is the native code pin for certificate verification.
17pub fn builtin() -> Result<Dialect, String> {
18    let mut form = crate::parse(SOURCE).map_err(|e| format!("checkpoint parse: {e}"))?;
19    let draft = crate::parse_dialect(&form).map_err(|e| format!("checkpoint dialect: {e}"))?;
20    let name = dialect_name(&draft);
21    if let SExpr::List(items) = &mut form {
22        items[1] = SExpr::Atom(Atom::Symbol(name));
23    }
24    let registry = crate::parse_and_install_dialect(&form)?;
25    registry
26        .iter()
27        .last()
28        .cloned()
29        .ok_or_else(|| String::from("checkpoint dialect was not installed"))
30}