spacedb-query
SpaceDB Layer 4 — compute-to-data.
The environment forbids hauling data to a central brain, so SpaceDB inverts it: the query travels to the data; only the answer travels back. A query is a deterministic, fuel- and memory-bounded WASM function that runs on the node holding the data — and because the runtime is deterministic, the result is corroboratable: a host that returns a different answer than its peers is caught.
Part of SpaceDB. Dual-licensed MIT OR Apache-2.0.
[]
= "0.5"
Run a function next to the data
use ;
let module_wasm: = Vecnew; // a real deterministic WASM module
let input_bytes: = Vecnew;
let runtime = new;
let limits = RunLimits ;
let exec = runtime.run.unwrap;
println!;
The runtime is wasmtime with no WASI: no clock, no filesystem, no network,
no randomness. A function that cannot observe anything nondeterministic cannot
produce a nondeterministic answer — which is what makes the next section work.
Fuel exhaustion and the memory ceiling are hard stops, so an untrusted function
cannot pin a home's CPU or RAM.
Corroboration
Every run yields a FunctionRun attestation: workload_hash, input_digest,
output_digest, fuel_used, mem_peak_mb.
use ;
// Two independent hosts ran the same (workload, input) — so every field must match.
let run_a = FunctionRun ;
let run_b = run_a.clone;
assert_eq!;
Honest runs of the same (workload, input) agree on every field. A wrong
output, or a padded fuel count billed for work not done, is Disagree. Fanning
that comparison across independent marketplace hosts is the MATA seam; the
runtime, the attestation, and the comparison are here.
Pinned snapshots and rights
Snapshot::pin(bytes, frontier) freezes exactly what a query reads, and its
hash() goes into the attestation — so two hosts corroborating a result are
provably comparing the same input state, not two different moments in time.
FunctionCtx carries that snapshot plus CtxRights { read, write } and an
explicit denied set: collections whose ciphertext the host holds but
provably cannot compute on. Serving those to server-side code would break the
zero-knowledge promise, so the context refuses them. Accumulated writes are
exposed as a writes_digest rather than applied behind the caller's back.
Partition-aware map-reduce
use ;
let runtime = new;
let plan = QueryPlan ;
let shards = vec!;
let outcome = run_query.unwrap;
if !outcome.coverage.is_complete
The planner maps over reachable shards and reduces the partials, and reports
Coverage honestly. A partial answer is labeled partial; it is never rounded up
to complete.
Open-core boundary
Built on wasmtime directly — the same engine MATA's maestro-fn-runtime
wraps — with no MATA dependency.
Testing
The workspace defaults to wasm32; this crate is native. Test on your host
triple:
Suites: runtime.rs (determinism, fuel/memory limits, module validation),
functions.rs (context, rights, denied collections), planner.rs (map-reduce,
coverage under partition).
License
MIT OR Apache-2.0, at your option. See LICENSE-MIT and LICENSE-APACHE.