Repository navigation
Description
Part of the formal-verification plan in docs/infra/nostream-formal-verification.md (workspace).
Depends on #1244 (key codecs) and #1245 (kind classification) landing first.
Why
Filter::matches (crates/nostream-core/src/filter.rs:75) and the LMDB range builder
(hex_ranges, tag_ranges in lmdb/encoding.rs) are two implementations of one rule: which
events satisfy a filter. Drift between them is silent in both directions — the store returns fewer
events than the filter says match (a missing page nobody notices until a client complains), or it
returns a superset the caller trusts without re-checking.
Neither unit tests nor a differential test can state the pair over all filters and events. That is
the property worth a verifier.
The property
For every filter f and every event e, the storage query built from f returns e only if
matches(f, e) — soundness of the index against the matcher. Stated where it can be checked, this
splits into:
- Coverage of the ranges. For every criterion in
f, the key of every event admitting that
criterion lies inside the ranges built from it (this is verify(storage): extract the key codecs into a dependency-free crate and prove order, injection and range coverage #1244'shex_ranges/tag_ranges
coverage, reused). - Agreement on the predicate. The predicate the range encodes (prefix match on an id, author,
or tag value; inclusivesince/untilbounds; kind membership) is the same predicate
matchesapplies — proved over the symbolic (criterion, field) pair rather than over events. - The composition. An event survives an intersection of ranges only if it satisfies every
conjunct ofmatches, which follows from 1 and 2 per clause; the harness asserts it for the
two-clause composition (a hex field plus a tag) and relies on induction for the rest, stated as
such in the harness comment.
Scope
filter.rs::matchesextracted to a form over primitives:(id: [u8;32], pubkey: [u8;32], created_at: i64, kind: i32, tags: &[[&str]])and a criterion type, so noEventor
serde_jsonis in the symbolic input.- the range builders from verify(storage): extract the key codecs into a dependency-free crate and prove order, injection and range coverage #1244, already dependency-free.
- the two live in one crate (
nostream-filter) or two that both depend on nothing; either way the
proof needs both in the same compilation unit.
Acceptance
- a harness proves range coverage against the matcher for a hex criterion (odd and even
lengths), a tag criterion (with and without the*geohash suffix), and thesince/until
bounds - the harness names a failing variant: e.g.
hex_rangeswith the odd-length branch omitted,
which must produce a counterexample -
Filter::matchesinnostream-coredelegates to the verified code, so the relay and the
store cannot drift from it - the filter parity tests ported from the capture keep passing unchanged
Notes
The largest of the three (about two days). Worth it only for the ids/authors/tags clauses the
LMDB backend actually narrows on — a DVM-shaped or niche clause that the store scans rather than
ranges is not part of this property.
Activity