referrerpolicy=no-referrer-when-downgrade

Module streams_root

Module streams_root 

Source
Expand description

StreamsRoot: the sender’s stream commitment.

Each block that sends commits one hash, the root of a keyed binary Patricia trie over (StreamId, current stream root) for every active stream. The relay records it as the sender’s Provides, and a receiver proves the streams it consumed against it, without a sender-state proof.

§Why a keyed trie

The trie is keyed by StreamId::to_bytes, so a proof is a walk driven by the key: verification recomputes the leaf from the caller’s StreamId and takes each branch direction from that key’s bits. A proof built for stream A cannot verify as stream B. Requires-lift synthesis depends on this, since lifts are matched to the consumption record’s streams by position. A positional Merkle tree does not give it. Patricia compression also keeps proofs O(log S) in the number of streams rather than O(64) in the key width.

Roles: the sender builds the root (streams_root) and its node serves proofs (gen_stream_proof), checking its own header digest (read_streams_root); a receiver’s lift walks a proof up to the committed root (streams_root_from_proof).

A leaf hash binds the full key, an inner hash its split bit.

Structs§

StreamProof
A membership proof that (stream, stream_root) is committed under a StreamsRoot. Served by the sender, verified by the receiver. Carries no leaf index; the key drives the walk.
StreamsRoot
The sender’s per-block stream commitment root. Defined relay-side and re-exported here. Root of a sender’s stream commitment tree: a compact binary trie keyed by the 8-byte StreamId encoding, with the streams’ MMR roots as leaves.
TreeStep
One step of a trie walk. The branch direction is not stored; verification takes it from the proven key’s bit at split_bit.

Functions§

gen_stream_proof
Build the trie over entries and return (StreamsRoot, proof) for stream, or None if absent. Sender side.
read_streams_root
Read the sender’s StreamsRoot from its header digest. None if absent or not exactly what the sender deposits: one SPMS item with a 32-byte payload. Foreign readers must agree on validity, so nothing else is accepted.
streams_root
The StreamsRoot over (stream, stream_root) entries; None with no active streams. Sender side. Takes a BTreeMap so keys are unique; duplicates would reach first_diverging_bit with identical keys.
streams_root_from_proof
Fold a membership proof for (stream, stream_root) up to the StreamsRoot it implies, or None on a malformed step. Callers compare the root themselves (the requires-lift records it, the fetch checks it against under). Each branch direction is stream’s bit at split_bit, so a proof built for another stream folds the siblings on the wrong sides and yields a different root.