//! Sealing a computation into a signed, energy-accounted receipt — and watching //! verification reject a doctored one. //! //! cargo run --example receipt use wai_quantum::ed25519_dalek::SigningKey; use wai_quantum::quantum::{Gateset, Measure}; use wai_quantum::quantum_receipt::QuantumReceipt; use wai_quantum::quantum_toolchain as qt; fn main() { let circuit = qt::ghz(3); let key = SigningKey::from_bytes(&[42u8; 32]); // demo key; use a real one let receipt = QuantumReceipt::seal( &key, "did:key:example", &circuit, Some(Measure { seed: 7, shots: 4096 }), 0, // measured microjoules; 0 means unmetered None, ) .expect("seal"); println!("capability {}", circuit.gateset.capability()); println!("verifies {}", receipt.verify()); println!("re-simulates to claim {}", receipt.verify_reconstruction(&circuit)); // The receipt binds the circuit's gateset: the same ops in circuit/1 do not // reconstruct it, and the receipt says which gateset they need. let mut v1 = circuit.clone(); v1.gateset = Gateset::V1; println!("same ops, circuit/1 {}", receipt.verify_reconstruction(&v1)); if let Some(note) = receipt.gateset_note(&v1) { println!(" {note}"); } println!("work {} amplitude updates", receipt.work_amp_updates); println!("energy {} uJ (0 = unmetered)", receipt.joules_micro); // The work is recomputable by anyone from (n_qubits, n_ops), so a sink cannot // inflate it. The energy is only as good as the signature, and says so. let json = receipt.to_json(); let tampered = json.replace("\"work_amp_updates\":24", "\"work_amp_updates\":2400"); assert_ne!(json, tampered, "expected the work field in the JSON"); let forged = QuantumReceipt::from_json(&tampered).expect("still parses"); println!("\nclaiming 100x the work: verifies = {}", forged.verify()); }