//! Measure one fixture under every envelope profile that proves a public
//! nox run: succinct (1), machine (4), recursive (5), wrapped (6).
//! Reports envelope bytes, prove time, and `from_bytes` + `verify` time
//! (the first call β€” for profiles 5 and 6 it builds the keys β€” and the
//! median of 5 more).
//!
//! `cargo run --release -p zheng --example envelope_profiles -- [fixture…]`
//! fixtures: add.tri hash.tri merkle-32 tree-<k>. `ZHENG_PROFILES=1,4,5,6`
//! selects (default 1,4,5). `ZHENG_ENVELOPE_DIR=<dir>` writes each envelope
//! to `<dir>/<fixture>.p<profile>.zheng`. `ZHENG_VERIFY=<file> … <fixture>`
//! only decodes and verifies that envelope of the fixture (a fresh
//! process: cold keys).

#[path = "../../tests/common/mod.rs"]
mod common;

use std::time::Instant;
use zheng::envelope::{Envelope, SuccinctStatement, recursive};
use zheng::execution::ExecutionNoun as N;
use zheng::machine;

const BUDGET: u64 = 1 << 40;

fn fixture(name: &str) -> Option<(N, Vec<u64>)> {
    Some(match name {
        "add.tri" => (common::parse(common::ADD), vec![7, 5]),
        "hash.tri" => (common::parse(common::HASH), vec![7]),
        "merkle-32" => {
            let root = machine::execute(&common::merkle_program(32, None), &[5], BUDGET).ok()?;
            let r = machine::statement::parse(&root.statement.output).ok()?;
            (common::merkle_program(32, Some(&r)), vec![5])
        }
        t if t.starts_with("tree-") => (common::tree_program(t[5..].parse().ok()?), vec![3]),
        _ => return None,
    })
}

fn prove(profile: u8, prog: &N, input: &[u64]) -> Result<Envelope, String> {
    match profile {
        1 => {
            let (st, proof) = zheng::execution::succinct::prove_default(prog, input, BUDGET)?;
            Ok(Envelope::Succinct {
                statement: SuccinctStatement::Execution(st),
                proof,
            })
        }
        4 => {
            let params = zheng::execution::succinct::params_for(20);
            let (statement, proof) = machine::prove(prog, input, BUDGET, &params)?;
            Ok(Envelope::Machine {
                params,
                statement: statement.public(),
                proof: Box::new(proof),
            })
        }
        5 => recursive::prove(prog, input, BUDGET, &recursive::params()),
        6 => zheng::envelope::wrapped::prove(prog, input, BUDGET),
        _ => Err(format!("profile {profile}")),
    }
}

fn check(bytes: &[u8], program: &[zheng::execution::NounToken]) -> f64 {
    let t = Instant::now();
    Envelope::from_bytes_for(bytes, program)
        .expect("decode")
        .verify_program(program, None)
        .expect("verify");
    t.elapsed().as_secs_f64() * 1e3
}

fn main() {
    if let Ok(file) = std::env::var("ZHENG_VERIFY") {
        let bytes = std::fs::read(&file).expect("envelope");
        let name = std::env::args().nth(1).expect("the envelope's fixture");
        let program = machine::statement::tokens(&fixture(&name).expect("fixture").0);
        let first = check(&bytes, &program);
        let mut v: Vec<f64> = (0..5).map(|_| check(&bytes, &program)).collect();
        v.sort_by(|a, b| a.partial_cmp(b).unwrap());
        println!(
            "{file}: {} B Β· profile {} Β· decode+verify cold {first:.2} ms, warm median {:.2} ms",
            bytes.len(),
            bytes[10],
            v[2]
        );
        return;
    }
    let args: Vec<String> = std::env::args().skip(1).collect();
    let names = if args.is_empty() {
        vec!["hash.tri".into(), "merkle-32".into()]
    } else {
        args
    };
    let profiles: Vec<u8> = std::env::var("ZHENG_PROFILES")
        .ok()
        .map(|v| v.split(',').filter_map(|p| p.parse().ok()).collect())
        .unwrap_or_else(|| vec![1, 4, 5]);
    for name in names {
        let (prog, input) = fixture(&name).unwrap_or_else(|| panic!("fixture {name}"));
        for &profile in &profiles {
            let t0 = Instant::now();
            let envelope = match prove(profile, &prog, &input) {
                Ok(e) => e,
                Err(e) => {
                    println!("{name} Β· profile {profile}: not proven ({e})");
                    continue;
                }
            };
            let t_prove = t0.elapsed().as_secs_f64();
            let bytes = envelope.to_bytes();
            if let Ok(dir) = std::env::var("ZHENG_ENVELOPE_DIR") {
                std::fs::write(format!("{dir}/{name}.p{profile}.zheng"), &bytes)
                    .expect("write envelope");
            }
            let program = machine::statement::tokens(&prog);
            let first = check(&bytes, &program);
            let mut v: Vec<f64> = (0..5).map(|_| check(&bytes, &program)).collect();
            v.sort_by(|a, b| a.partial_cmp(b).unwrap());
            println!(
                "{name} Β· profile {profile}: {} B Β· prove {t_prove:.1} s Β· decode+verify first {first:.2} ms, median {:.2} ms",
                bytes.len(),
                v[2]
            );
        }
    }
}

Homonyms

cyber/src/main.rs
cyb/cli/src/main.rs
soft3/nox/cli/main.rs
neural/trident/src/main.rs
cyb/optica/src/main.rs
soft3/glia/import/main.rs
cyberia/cyberia-my/src/main.rs
cyb/apps/src/main.rs
soft3/tru/cli/main.rs
neural/rune/cli/main.rs
warriors/trisha/cli/main.rs
warriors/joy/cli/main.rs
cyb/shell/src/main.rs
soft3/conformance/rs/src/main.rs
neural/eidos/cli/src/main.rs
soft3/radio/iroh-dns-server/src/main.rs
soft3/radio/iroh-relay/src/main.rs
soft3/radio/particle/src/main.rs
soft3/strata/cli/src/main.rs
soft3/zheng/cli/src/main.rs
neural/rs/pure-rust-check/src/main.rs
soft3/hemera/cli/src/main.rs
soft3/neuron/cli/src/main.rs
soft3/glia/run/cli/main.rs
neural/rs/link/src/main.rs
soft3/radio/radio-cli/src/main.rs
soft3/foculus/src/bin/main.rs
neural/rs/macho-linker/src/main.rs
soft3/bbg/cli/src/main.rs
neural/rs/rsc/src/main.rs
neural/rs/cli/src/main.rs
soft3/lens/cli/src/main.rs
soft3/cybergraph/cli/src/main.rs
warriors/erga/cli/src/main.rs
soft3/zheng/rs/examples/ivc_bench/main.rs
soft3/zheng/rs/examples/wrap_plan/main.rs
cyb/honeycrisp/acpu/src/probe/main.rs
soft3/strata/jali/cli/src/main.rs
soft3/zheng/rs/examples/wrap_keys/main.rs
soft3/mudra/audit/quantus-mldsa-crosscheck/src/main.rs
soft3/zheng/specs/proto/zheng_spartan/main.rs
soft3/zheng/rs/examples/wrap_chain/main.rs
warriors/erga/rs/rtable-bench/src/main.rs
soft3/strata/kuro/cli/src/main.rs
soft3/strata/trop/cli/src/main.rs
soft3/zheng/rs/examples/wrap_flip/main.rs
soft3/zheng/rs/examples/wrap_bench/main.rs
warriors/trisha/tools/neptune-policy-oracle/src/main.rs
soft3/zheng/specs/proto/zheng_bug/main.rs
soft3/zheng/specs/proto/zheng_inner/main.rs
soft3/zheng/rs/examples/fast_path/main.rs
soft3/zheng/specs/proto/zheng_spartan_fixed/main.rs
warriors/erga/rs/mine-bench/src/main.rs
soft3/zheng/rs/examples/wrapped_sizes/main.rs
soft3/zheng/rs/examples/wrap_verify/main.rs
soft3/zheng/rs/examples/ivc_plan/main.rs
soft3/zheng/rs/examples/ivc_flip/main.rs
soft3/zheng/rs/examples/machine_bench/main.rs
soft3/zheng/rs/examples/succinct_bakeoff/main.rs
soft3/zheng/specs/proto/zheng_outer/main.rs
neural/inf/rs/cli/src/main.rs
cyb/wysm/crates/cli/src/main.rs
warriors/erga/rs/blake-bench/src/main.rs
soft3/strata/nebu/cli/src/main.rs
soft3/lytics/rs/agent/src/main.rs
cyb/honeycrisp/rane/src/probe/main.rs
neural/trident/silicon/src/bin/main.rs
soft3/strata/genies/cli/src/main.rs
soft3/lytics/rs/ingest/src/main.rs
soft3/radio/audit/2026-10-12-bao-bounded-proof/nostd/src/main.rs
soft3/radio/audit/2026-10-12-bao-proof-research/probe/src/main.rs
soft3/mudra/audit/signature-optimality/xnt-predicate-check/src/main.rs
cyb/honeycrisp/unimem/experiments/hyp_probe/src/main.rs
soft3/radio/audit/2026-10-12-bao-bounded-proof/fixture-probe/src/main.rs
soft3/radio/audit/2026-10-12-bao-bounded-proof/nostd-parent/src/main.rs
soft3/radio/audit/2026-10-12-bao-proof-research/primary-probe/src/main.rs
cyb/honeycrisp/unimem/experiments/iosurface_probe/src/main.rs
cyb/honeycrisp/unimem/experiments/dext_contiguous_alloc/client/src/main.rs
cyb/honeycrisp/unimem/experiments/dext_iosurface_pa/client/src/main.rs

Graph