ccf-core 1.0.1

Canonical CCF core v1 trust-update and runtime-certificate primitives for filed-Prov6 contract enforcement
Documentation
use ccf_core::min_gate::{
    hard_min_gate_step, reject_constant_alpha, MinGateInputs, RhoConfig,
    CONSTANT_ALPHA_OLD_WRONG_PATH, MIN_GATE_JOURNEY_ID, MIN_GATE_STORY_ID,
};

fn fixture(c_inst: f64, c_ctx: f64) -> MinGateInputs {
    MinGateInputs {
        c_inst,
        c_ctx,
        rho: RhoConfig::try_new(0.05, 0.75).unwrap(),
    }
}

fn expected_linear_rho(g_t: f64, rho: RhoConfig) -> f64 {
    rho.alpha_min() + (rho.alpha_max() - rho.alpha_min()) * g_t
}

#[test]
fn alpha_is_coupled_to_exact_hard_min_gate() {
    eprintln!("journey={MIN_GATE_JOURNEY_ID} story={MIN_GATE_STORY_ID}");

    let inputs = fixture(0.1, 0.9);
    let actual = hard_min_gate_step(&inputs).expect("rho gate-coupling implementation is required");
    let expected_alpha = expected_linear_rho(0.1, inputs.rho);

    assert_eq!(actual.g_t.to_bits(), 0.1_f64.to_bits());
    assert!(
        (actual.alpha_t - expected_alpha).abs() <= f64::EPSILON,
        "alpha_t must equal rho(g_t)"
    );
    eprintln!("alpha_t=rho(g_t) g_t=0.1 alpha_t={:.16e}", actual.alpha_t);
    eprintln!("rho_gate_coupling=PASS");
}

#[test]
fn constant_alpha_canonical_mode_cannot_pass_rho_gate() {
    eprintln!("journey={MIN_GATE_JOURNEY_ID} story={MIN_GATE_STORY_ID}");

    let report = reject_constant_alpha(&fixture(0.1, 0.9))
        .expect("constant alpha negative guard is required");

    assert_eq!(report.old_wrong_path, CONSTANT_ALPHA_OLD_WRONG_PATH);
    assert!(report.rejected);
    assert_eq!(report.canonical_alpha_t.to_bits(), 0.12_f64.to_bits());
    assert_eq!(report.observed_alpha_t.to_bits(), 0.35_f64.to_bits());
    eprintln!(
        "constant_alpha_negative=PASS old_wrong_path={} alpha_t_excursion={:.16e}",
        report.old_wrong_path,
        (report.observed_alpha_t - report.canonical_alpha_t).abs()
    );
}