Proof

Struct Proof 

Source
pub struct Proof<D: Digest> {
    pub size: u64,
    pub digests: Vec<D>,
}
Expand description

Contains the information necessary for proving the inclusion of an element, or some range of elements, in the MMR from its root digest.

The digests vector contains:

1: the digests of each peak corresponding to a mountain containing no elements from the element range being proven in decreasing order of height, followed by:

2: the nodes in the remaining mountains necessary for reconstructing their peak digests from the elements within the range, ordered by the position of their parent.

Fields§

§size: u64

The total number of nodes in the MMR.

§digests: Vec<D>

The digests necessary for proving the inclusion of an element, or range of elements, in the MMR.

Implementations§

Source§

impl<D: Digest> Proof<D>

Source

pub fn verify_element_inclusion<I, H>( &self, hasher: &mut H, element: &[u8], element_pos: u64, root: &D, ) -> bool
where I: CHasher<Digest = D>, H: Hasher<I>,

Return true if proof proves that element appears at position element_pos within the MMR with root digest root.

Source

pub fn verify_range_inclusion<I, H, E>( &self, hasher: &mut H, elements: &[E], start_element_pos: u64, root: &D, ) -> bool
where I: CHasher<Digest = D>, H: Hasher<I>, E: AsRef<[u8]>,

Return true if proof proves that the elements appear consecutively starting at position start_element_pos within the MMR with root digest root.

Source

pub fn verify_range_inclusion_and_extract_digests<I, H, E>( &self, hasher: &mut H, elements: &[E], start_element_pos: u64, root: &D, ) -> Result<Vec<(u64, D)>, Error>
where I: CHasher<Digest = D>, H: Hasher<I>, E: AsRef<[u8]>,

Reconstructs the root digest of the MMR from the digests in the proof and the provided range of elements, returning the (position,digest) of every node whose digest was required by the process (including those from the proof itself). Returns a Error::InvalidProof if the input data is invalid and Error::RootMismatch if the root does not match the computed root.

Source

pub fn nodes_to_pin(start_pos: u64) -> impl Iterator<Item = u64>

Return the list of pruned (pos < start_pos) node positions that are still required for proving any retained node.

This set consists of every pruned node that is either (1) a peak, or (2) has no descendent in the retained section, but its immediate parent does. (A node meeting condition (2) can be shown to always be the left-child of its parent.)

This set of nodes does not change with the MMR’s size, only the pruning boundary. For a given pruning boundary that happens to be a valid MMR size, one can prove that this set is exactly the set of peaks for an MMR whose size equals the pruning boundary. If the pruning boundary is not a valid MMR size, then the set corresponds to the peaks of the largest MMR whose size is less than the pruning boundary.

Source

pub fn nodes_required_for_range_proof( size: u64, start_element_pos: u64, end_element_pos: u64, ) -> Vec<u64>

Return the list of node positions required by the range proof for the specified range of elements, inclusive of both endpoints.

Source

pub async fn range_proof<S: Storage<D>>( mmr: &S, start_element_pos: u64, end_element_pos: u64, ) -> Result<Proof<D>, Error>

Return an inclusion proof for the specified range of elements, inclusive of both endpoints. Returns ElementPruned error if some element needed to generate the proof has been pruned.

Source

pub async fn historical_range_proof<S: Storage<D>>( mmr: &S, size: u64, start_element_pos: u64, end_element_pos: u64, ) -> Result<Proof<D>, Error>

Analogous to range_proof but for a previous database state. Specifically, the state when the MMR had size elements.

Source

pub async fn multi_proof<S: Storage<D>>( mmr: &S, positions: &[u64], ) -> Result<Proof<D>, Error>

Return an inclusion proof for the specified positions. This is analogous to range_proof but supports non-contiguous positions.

The order of positions does not affect the output (sorted internally).

Source

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

Return true if proof proves that the elements at the specified positions are included in the MMR with the root digest root.

The order of the elements does not affect the output.

Source

pub fn extract_pinned_nodes( &self, start_element_pos: u64, end_element_pos: u64, ) -> Result<Vec<D>, Error>

Extract the hashes of all nodes that should be pinned at the given pruning boundary from a proof that proves a range starting at that boundary.

§Arguments
  • start_element_pos - Start of the proven range (must equal pruning_boundary)
  • end_element_pos - End of the proven range
§Returns

A Vec of digest values for all nodes in nodes_to_pin(pruning_boundary), in the same order as returned by nodes_to_pin (decreasing height order)

Trait Implementations§

Source§

impl<D: Clone + Digest> Clone for Proof<D>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<D: Debug + Digest> Debug for Proof<D>

Source§

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

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

impl<D: Digest> Default for Proof<D>

Source§

fn default() -> Self

Create an empty proof. The empty proof will verify only against the root digest of an empty (size == 0) MMR.

Source§

impl<D: Digest> EncodeSize for Proof<D>

Source§

fn encode_size(&self) -> usize

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

impl<D: Digest> PartialEq for Proof<D>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<D: Digest> Read for Proof<D>

Source§

type Cfg = usize

The maximum number of digests in the proof.

Source§

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

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

impl<D: Digest> Write for Proof<D>

Source§

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

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

impl<D: Eq + Digest> Eq for Proof<D>

Auto Trait Implementations§

§

impl<D> Freeze for Proof<D>

§

impl<D> RefUnwindSafe for Proof<D>
where D: RefUnwindSafe,

§

impl<D> Send for Proof<D>

§

impl<D> Sync for Proof<D>

§

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

§

impl<D> UnwindSafe for Proof<D>
where 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> 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<X, T> DecodeExt<X> for T
where X: Default, T: Decode<Cfg = X>,

Source§

fn decode(buf: impl Buf) -> Result<Self, Error>

Decodes a value using the default () config.
Source§

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

Source§

fn encode(&self) -> BytesMut

Encodes self into a new BytesMut buffer. Read more
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<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: 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: 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> 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
Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

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