Skip to main content

Proof

Struct Proof 

Source
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:

  1. 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.

  2. The digests of any non-folded peaks entirely before the proven range, in peak iteration order.

  3. For ForwardFold, the digests of peaks entirely after the proven range, in peak iteration order. For BackwardFold, inactive after-peaks are still listed individually, while active after-peaks are collapsed into one optional suffix accumulator.

  4. 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: usize

The 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>

Source

pub fn verify_element_inclusion<H>( &self, hasher: &H, element: &[u8], loc: Location<F>, root: &D, ) -> bool
where 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.

Source

pub fn verify_range_inclusion<H, E>( &self, hasher: &H, elements: &[E], start_loc: Location<F>, root: &D, ) -> bool
where H: Hasher<F, Digest = D>, E: AsRef<[u8]>,

Return true if this proof verifies against the supplied root, using the bagging carried by hasher.

Source

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.

Source

pub fn verify_multi_inclusion<H, E>( &self, hasher: &H, elements: &[(E, Location<F>)], root: &D, ) -> bool
where H: Hasher<F, Digest = D>, E: AsRef<[u8]>,

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.

Source

pub fn reconstruct_root<H, E>( &self, hasher: &H, elements: &[E], start_loc: Location<F>, ) -> Result<D, ReconstructionError>
where H: Hasher<F, Digest = D>, E: AsRef<[u8]>,

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.

Source

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>>
where H: Hasher<F, Digest = D>, E: AsRef<[u8]>,

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.

Source

pub fn verify_proof_and_pinned_nodes<H, E>( &self, hasher: &H, elements: &[E], start_loc: Location<F>, pinned_nodes: &[D], root: &D, ) -> bool
where H: Hasher<F, Digest = D>, E: AsRef<[u8]>,

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 L3

The 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: Clone + Family, D: Clone + Digest> Clone for Proof<F, D>

Source§

fn clone(&self) -> Proof<F, D>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug + Family, D: Debug + Digest> Debug for Proof<F, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Family, D: Digest> Default for Proof<F, D>

Source§

fn default() -> Self

Create an empty proof. The empty proof will verify only against the root digest of an empty (leaves == 0) data structure.

Source§

impl<F: Family, D: Digest> EncodeSize for Proof<F, D>

Source§

fn encode_size(&self) -> usize

Returns the encoded size of this value (in bytes).
Source§

fn encode_inline_size(&self) -> usize

Returns the encoded size excluding bytes passed to 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.
Source§

impl<F: Eq + Family, D: Eq + Digest> Eq for Proof<F, D>

Source§

impl<F: Family, D: Digest> PartialEq for Proof<F, D>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<F: Family, D: Digest> Read for Proof<F, D>

Source§

type Cfg = usize

The maximum number of digests in the proof.

Source§

fn read_cfg(buf: &mut impl Buf, max_digests: &Self::Cfg) -> Result<Self, Error>

Reads a value from the buffer using the provided configuration cfg. Read more
Source§

impl<F: Family, D: Digest> Write for Proof<F, D>

Source§

fn write(&self, buf: &mut impl BufMut)

Writes the binary representation of self to the provided buffer buf. Read more
Source§

fn write_bufs(&self, buf: &mut impl BufsMut)

Writes to a 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>

§

impl<F, D> Send for Proof<F, D>

§

impl<F, D> Sync for Proof<F, D>

§

impl<F, D> Unpin for Proof<F, D>
where F: Unpin, D: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Codec for T
where T: Encode + Decode,

Source§

impl<T> CodecShared for T
where T: Codec + Send + Sync,

Source§

impl<T> Decode for T
where T: Read,

Source§

fn decode_cfg(buf: impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Decodes a value from buf using cfg, ensuring the entire buffer is consumed. Read more
Source§

impl<T> Encode for T
where T: Write + EncodeSize,

Source§

fn encode(&self) -> Bytes

Encodes self into a new Bytes buffer. Read more
Source§

fn encode_mut(&self) -> BytesMut

Encodes self into a new BytesMut buffer. Read more
Source§

impl<T> EncodeExt for T
where T: EncodeSize + Write,

Source§

fn encode_with_pool_mut(&self, pool: &BufferPool) -> IoBufMut

Encode this value into an IoBufMut allocated from pool. Read more
Source§

fn encode_with_pool(&self, pool: &BufferPool) -> IoBufs

Encode into IoBufs using pool allocation. Read more
Source§

impl<T> EncodeShared for T
where T: Encode + Send + Sync,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> VariableValue for T
where T: CodecShared + Clone + 'static,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more