spacedb_query/corroborate.rs
1//! The verifiable result — *trust the math, not the machine*.
2//!
3//! A [`FunctionRun`] is the deterministic attestation a host emits for one
4//! execution: the workload it ran, the input it ran on, the output it produced,
5//! and the resources it consumed — all content-addressed. Because the runtime is
6//! deterministic (no ambient nondeterminism, bounded by fuel not wall-clock), two
7//! honest hosts running the same workload on the same input produce **identical**
8//! attestations. [`corroborate`] compares two and returns whether they agree, so
9//! a host that returns a different answer than its peers is caught.
10//!
11//! S1 ships the attestation + the comparison. Fanning a query across N independent
12//! hosts and gathering their attestations is the MATA seam (M6-S2+); the property
13//! it relies on — that an honest run is reproducible — lives here.
14
15use serde::{Deserialize, Serialize};
16
17/// The deterministic record of one function execution. The fields are exactly
18/// what must match across honest hosts; nothing device-dependent (e.g. wall time)
19/// is included.
20#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
21pub struct FunctionRun {
22 /// BLAKE3 of the WASM module — the workload's identity.
23 pub workload_hash: [u8; 32],
24 /// BLAKE3 of the input bytes.
25 pub input_digest: [u8; 32],
26 /// BLAKE3 of the output bytes — what the function actually computed.
27 pub output_digest: [u8; 32],
28 /// Fuel consumed (a deterministic instruction count).
29 pub fuel_used: u64,
30 /// Peak linear memory, in whole MB.
31 pub mem_peak_mb: u32,
32}
33
34/// The verdict of comparing two attestations of the *same* workload + input.
35#[derive(Clone, Copy, Debug, PartialEq, Eq)]
36pub enum Corroboration {
37 /// The two runs match on every deterministic field — the result is trusted.
38 Agree,
39 /// The two runs diverge — at least one host is wrong (or malicious).
40 Disagree,
41}
42
43/// Compare two attestations. Honest runs of the same `(workload, input)` agree on
44/// all fields; any divergence (a wrong output, a padded fuel count) disagrees.
45pub fn corroborate(a: &FunctionRun, b: &FunctionRun) -> Corroboration {
46 if a == b {
47 Corroboration::Agree
48 } else {
49 Corroboration::Disagree
50 }
51}