Add an optional energy_attestation field: a content-id commitment to the raw attestation-report bytes from sandbox-tee::energy, sealed into the signed preimage via Efficiency::with_energy_attestation. Keeps the receipt crate free of any attestation dependency — the receipt commits, the attestation layer adjudicates trust (IntegrityAttested vs PhysicallyRooted), so the receipt never asserts a level it cannot prove. MAPPING §4 documents the composed verification. Round-trip test; example unchanged. No new deps. Co-authored-by: Transaction Science <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]>
77 lines
2.9 KiB
Rust
77 lines
2.9 KiB
Rust
//! A live agentic-fleet efficiency demo: five coding tasks, each sealed as an
|
|
//! `efficiency/1` receipt, then verified and aggregated — surfacing the waste a
|
|
//! "cost per token" number is designed to hide.
|
|
//!
|
|
//! cargo run -p jcp-efficiency --example session
|
|
|
|
use ed25519_dalek::SigningKey;
|
|
use jcp_efficiency::{aggregate, verify_chain, Efficiency, EfficiencyLog};
|
|
use jcp_schema::Energy;
|
|
|
|
fn task(
|
|
id: &str,
|
|
completed: bool,
|
|
tokens_out: u64,
|
|
uj: u64,
|
|
wall_ns: u64,
|
|
value_uusd: Option<u64>,
|
|
) -> Efficiency {
|
|
Efficiency {
|
|
task: id.into(),
|
|
completed,
|
|
verdict: if completed { "tests-pass".into() } else { "gate-failed".into() },
|
|
tokens_in: tokens_out * 8, // agentic loops: accumulated context dwarfs output
|
|
tokens_out,
|
|
energy: Energy::measured(uj), // a HwShunt reading in this demo
|
|
wall_ns,
|
|
value_uusd,
|
|
energy_attestation: None,
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let sk = SigningKey::from_bytes(&[0xed; 32]);
|
|
let mut log = EfficiencyLog::new(sk, "did:jcp:efficiency-demo");
|
|
|
|
// A fleet running five coding tasks. Two burn tokens and never reach green.
|
|
let tasks = [
|
|
task("fix-auth-bug", true, 1_200, 3_500_000, 42_000_000_000, Some(5_000_000)),
|
|
task("add-rate-limit", true, 900, 2_800_000, 31_000_000_000, Some(4_000_000)),
|
|
task("refactor-parser", false, 4_500, 9_800_000, 120_000_000_000, None), // gave up
|
|
task("upgrade-deps", true, 600, 1_900_000, 18_000_000_000, Some(2_000_000)),
|
|
task("migrate-schema", false, 3_800, 8_200_000, 95_000_000_000, None), // wrong → reverted
|
|
];
|
|
|
|
println!("sealing {} efficiency/1 receipts…\n", tasks.len());
|
|
for t in &tasks {
|
|
log.append(t);
|
|
let mark = if t.completed { "✓" } else { "✗ spend bought nothing" };
|
|
println!(
|
|
" {:16} {:>5} tok {:>7} µJ/tok {:>6.0} tok/s {}",
|
|
t.task,
|
|
t.tokens_out,
|
|
t.uj_per_accepted_token(),
|
|
t.tokens_per_sec(),
|
|
mark
|
|
);
|
|
}
|
|
|
|
// Verify the whole chain, then aggregate — the honest efficiency ledger.
|
|
let recs = verify_chain(log.receipts(), log.steward(), &log.steward_pubkey())
|
|
.expect("chain verifies under the steward key");
|
|
let t = aggregate(&recs);
|
|
|
|
println!("\n── the honest efficiency ledger ({} receipts, all verified) ──", recs.len());
|
|
println!(" completed units : {}", t.completed_units);
|
|
println!(" wasted units : {} (tokens burned, no result)", t.wasted_units);
|
|
println!(
|
|
" tokens/completed : {} ← charges EVERY attempt (incl. failures) to results delivered",
|
|
t.tokens_per_completed_unit()
|
|
);
|
|
println!(" µJ/completed : {}", t.uj_per_completed_unit());
|
|
println!(" value / joule : {:.4} µUSD/J", t.value_per_joule());
|
|
println!(
|
|
" WASTE FRACTION : {:.0}% ← the number a 'cost per token' rate hides",
|
|
t.waste_fraction() * 100.0
|
|
);
|
|
}
|