pub struct Proof<F: Family, D: Digest> {
pub leaves: Location<F>,
pub inactive_peaks: usize,
pub digests: Vec<D>,
}Expand description
Contains the information necessary for proving the inclusion of an element, or some range of elements, in a Merkle-family data structure from its root digest.
For range proofs, the digests vector uses a fold-based layout:
-
If there are folded peaks entirely before the proven range, the first digest is a single accumulator produced by folding those peaks:
fold(fold(..., peak0), peak1). If there are no such peaks, this entry is absent. -
The digests of any non-folded peaks entirely before the proven range, in peak iteration order.
-
For
ForwardFold, the digests of peaks entirely after the proven range, in peak iteration order. ForBackwardFold, inactive after-peaks are still listed individually, while active after-peaks are collapsed into one optional suffix accumulator. -
The sibling digests needed to reconstruct each range-peak digest from the proven elements, in depth-first (forward consumption) order for each range peak.
Multi-proofs use a different, position-keyed layout: digests contains the sorted set of node
digests required by the requested inactive_peaks and bagging policy. For BackwardFold, this
may include active suffix peaks that a single range proof could collapse into a synthetic suffix
accumulator.
Fields§
§leaves: Location<F>The total number of leaves in the data structure. For MMR proofs, this is the number of leaves in the MMR, though other authenticated data structures may override the meaning of this field. For example, the authenticated crate::AuthenticatedBitMap stores the number of bits in the bitmap within this field.
inactive_peaks: usizeThe number of inactive peaks in the structure when this proof was generated.
digests: Vec<D>The digests necessary for proving inclusion.
Implementations§
Source§impl<F: Family, D: Digest> Proof<F, D>
impl<F: Family, D: Digest> Proof<F, D>
Sourcepub fn verify_element_inclusion<H>(
&self,
hasher: &H,
element: &[u8],
loc: Location<F>,
root: &D,
) -> boolwhere
H: Hasher<F, Digest = D>,
pub fn verify_element_inclusion<H>(
&self,
hasher: &H,
element: &[u8],
loc: Location<F>,
root: &D,
) -> boolwhere
H: Hasher<F, Digest = D>,
Return true if this proof proves that element appears at location loc within the
structure with root digest root, using the bagging carried by hasher.
Sourcepub fn verify_range_inclusion<H, E>(
&self,
hasher: &H,
elements: &[E],
start_loc: Location<F>,
root: &D,
) -> bool
pub fn verify_range_inclusion<H, E>( &self, hasher: &H, elements: &[E], start_loc: Location<F>, root: &D, ) -> bool
Return true if this proof verifies against the supplied root, using the bagging carried by
hasher.
Sourcepub fn matches_canonical_inactive_peaks(
&self,
size: Position<F>,
inactivity_floor: Location<F>,
) -> bool
pub fn matches_canonical_inactive_peaks( &self, size: Position<F>, inactivity_floor: Location<F>, ) -> bool
Returns true if this proof’s inactive_peaks field matches the canonical value derived
from size and inactivity_floor.
Sourcepub fn verify_multi_inclusion<H, E>(
&self,
hasher: &H,
elements: &[(E, Location<F>)],
root: &D,
) -> bool
pub fn verify_multi_inclusion<H, E>( &self, hasher: &H, elements: &[(E, Location<F>)], root: &D, ) -> bool
Verify a position-keyed multi-proof using the bagging carried by hasher.
Multi-proofs keep every witness tied to a concrete node position, so this path may include extra backward-bagged suffix peaks that range proofs can collapse into a suffix accumulator.
Sourcepub fn reconstruct_root<H, E>(
&self,
hasher: &H,
elements: &[E],
start_loc: Location<F>,
) -> Result<D, ReconstructionError>
pub fn reconstruct_root<H, E>( &self, hasher: &H, elements: &[E], start_loc: Location<F>, ) -> Result<D, ReconstructionError>
Reconstruct the root digest from this proof and the given consecutive elements using
the bagging carried by hasher, or return a ReconstructionError if the input data is
invalid.
Sourcepub fn verify_range_inclusion_and_extract_digests<H, E>(
&self,
hasher: &H,
elements: &[E],
start_loc: Location<F>,
root: &D,
) -> Result<Vec<(Position<F>, D)>, Error<F>>
pub fn verify_range_inclusion_and_extract_digests<H, E>( &self, hasher: &H, elements: &[E], start_loc: Location<F>, root: &D, ) -> Result<Vec<(Position<F>, D)>, Error<F>>
Verify this proof against root and extract all authenticated digests.
Reconstructs the root from the proof and provided elements and returns every
(position, digest) pair required by that reconstruction, including the proof’s own
digests. Returns Error::InvalidProof if the input data is malformed and
Error::RootMismatch if the reconstructed root does not match root.
Sourcepub fn verify_proof_and_pinned_nodes<H, E>(
&self,
hasher: &H,
elements: &[E],
start_loc: Location<F>,
pinned_nodes: &[D],
root: &D,
) -> bool
pub fn verify_proof_and_pinned_nodes<H, E>( &self, hasher: &H, elements: &[E], start_loc: Location<F>, pinned_nodes: &[D], root: &D, ) -> bool
Verify this proof and the pinned nodes against root.
The proof’s inactive_peaks field commits to the split boundary; peak bagging is selected
by hasher.
The pinned_nodes are the peak digests of the sub-structure at start_loc, in the order
returned by Family::nodes_to_pin. The proof authenticates the prefix [0, start_loc) via:
- fold-prefix peaks of the larger tree, and
- sibling subtrees inside the first range peak that lie wholly before
start_loc.
When the larger tree has merged smaller subtrees into a bigger parent, the pins sit below these authenticated subtrees. The verifier hashes pairs of pins up to each authenticated subtree’s root and compares against the proof.
For example, in MMB at leaves=5, start_loc=4, the proof describes [0, 4) as one
height-2 subtree p7, while the pins cover the same leaves as two height-1 subtrees
p2, p5:
proof authenticates: pins contain:
p7
/ \
p2 p5 p2 p5
/ \ / \ / \ / \
L0 L1 L2 L3 L0 L1 L2 L3The verifier walks down from p7 via F::children, pulls the pins for p2 and p5, and
hashes them back up (node_digest(p7, pin[p2], pin[p5])) to compare against the p7
digest the proof authenticates.
Returns true only if the proof reconstructs to root and every pinned node digest is
accounted for. When start_loc is 0, pinned_nodes must be empty.
Trait Implementations§
Source§impl<F: Family, D: Digest> EncodeSize for Proof<F, D>
impl<F: Family, D: Digest> EncodeSize for Proof<F, D>
Source§fn encode_size(&self) -> usize
fn encode_size(&self) -> usize
Source§fn encode_inline_size(&self) -> usize
fn encode_inline_size(&self) -> usize
BufsMut::push
during Write::write_bufs. Used to size the working buffer for inline
writes. Override alongside Write::write_bufs for types where large
Bytes fields go via push; failing to do so will over-allocate.impl<F: Eq + Family, D: Eq + Digest> Eq for Proof<F, D>
Source§impl<F: Family, D: Digest> Write for Proof<F, D>
impl<F: Family, D: Digest> Write for Proof<F, D>
Source§fn write_bufs(&self, buf: &mut impl BufsMut)
fn write_bufs(&self, buf: &mut impl BufsMut)
BufsMut, allowing existing Bytes chunks to be
appended via BufsMut::push instead of written inline. Must encode
to the same format as Write::write. Defaults to Write::write.Auto Trait Implementations§
impl<F, D> Freeze for Proof<F, D>
impl<F, D> RefUnwindSafe for Proof<F, D>where
F: RefUnwindSafe,
D: RefUnwindSafe,
impl<F, D> Send for Proof<F, D>
impl<F, D> Sync for Proof<F, D>
impl<F, D> Unpin for Proof<F, D>
impl<F, D> UnsafeUnpin for Proof<F, D>
impl<F, D> UnwindSafe for Proof<F, D>where
F: UnwindSafe,
D: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Codec for T
Source§impl<T> Encode for Twhere
T: Write + EncodeSize,
impl<T> Encode for Twhere
T: Write + EncodeSize,
Source§impl<T> EncodeExt for Twhere
T: EncodeSize + Write,
impl<T> EncodeExt for Twhere
T: EncodeSize + Write,
Source§fn encode_with_pool_mut(&self, pool: &BufferPool) -> IoBufMut
fn encode_with_pool_mut(&self, pool: &BufferPool) -> IoBufMut
Source§fn encode_with_pool(&self, pool: &BufferPool) -> IoBufs
fn encode_with_pool(&self, pool: &BufferPool) -> IoBufs
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more