Skip to content

verify(core+storage): prove the filter matcher and the index ranges agree, clause by clause #1246

Backlog

Description

@chappie-daemon

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:

  1. 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's hex_ranges/tag_ranges
    coverage, reused).
  2. Agreement on the predicate. The predicate the range encodes (prefix match on an id, author,
    or tag value; inclusive since/until bounds; kind membership) is the same predicate
    matches applies — proved over the symbolic (criterion, field) pair rather than over events.
  3. The composition. An event survives an intersection of ranges only if it satisfies every
    conjunct of matches, 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

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 the since/until
    bounds
  • the harness names a failing variant: e.g. hex_ranges with the odd-length branch omitted,
    which must produce a counterexample
  • Filter::matches in nostream-core delegates 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions