Struct celestia_types::nmt::NamespaceProof

source ·
pub struct NamespaceProof(/* private fields */);
Expand description

Merkle proof of inclusion or absence of some data in the Nmt.

§Example

use nmt_rs::NamespaceMerkleHasher;
use celestia_types::nmt::{Namespace, Nmt, NamespacedSha2Hasher, EMPTY_LEAVES};

let ns1 = Namespace::new_v0(&[1]).unwrap();
let ns2 = Namespace::new_v0(&[2]).unwrap();
let ns3 = Namespace::new_v0(&[3]).unwrap();
let ns4 = Namespace::new_v0(&[4]).unwrap();

let leaves = [
    (ns1, b"leaf0"),
    (ns2, b"leaf1"),
    (ns2, b"leaf2"),
    (ns4, b"leaf3"),
];

// create the nmt and feed it with data
let mut nmt = Nmt::with_hasher(NamespacedSha2Hasher::with_ignore_max_ns(true));

for (namespace, data) in leaves {
    nmt.push_leaf(data, *namespace);
}

// create and verify the proof of inclusion of namespace 2 data
let root = nmt.root();
let proof = nmt.get_namespace_proof(*ns2);
assert!(proof.is_of_presence());
assert!(
    proof.verify_complete_namespace(&root, &["leaf1", "leaf2"], *ns2).is_ok()
);

// create and verify the proof of absence of namespace 3 data
let proof = nmt.get_namespace_proof(*ns3);
assert!(proof.is_of_absence());
assert!(
    proof.verify_complete_namespace(&root, EMPTY_LEAVES, *ns3).is_ok()
);

Implementations§

source§

impl NamespaceProof

source

pub fn into_inner(self) -> NamespaceProof<NamespacedSha2Hasher, NS_SIZE>

Convert the proof to the underlying nmt_rs equivalent.

source

pub fn leaf(&self) -> Option<&NamespacedHash>

Get the hash of the leaf following the Namespace which absence is being proven.

If the tree had contained the proven namespace, it should be in the tree right before the leaf returned by this function.

This function returns None if the proof isn’t an AbsenceProof or the proven Namespace is not in the range of the tree root NamespacedHash.

source

pub fn max_ns_ignored(&self) -> bool

Returns true if the proof ignores all the leaves inserted with Namespace::PARITY_SHARE.

Methods from Deref<Target = NamespaceProof<NamespacedSha2Hasher, NS_SIZE>>§

source

pub fn verify_complete_namespace( &self, root: &NamespacedHash<NS_ID_SIZE>, raw_leaves: &[impl AsRef<[u8]>], namespace: NamespaceId<NS_ID_SIZE>, ) -> Result<(), RangeProofError>

Verify that the provided raw leaves are a complete namespace. This may be a proof of presence or absence.

source

pub fn verify_range( &self, root: &NamespacedHash<NS_ID_SIZE>, raw_leaves: &[impl AsRef<[u8]>], leaf_namespace: NamespaceId<NS_ID_SIZE>, ) -> Result<(), RangeProofError>

Verify a that the provided raw leaves are a (1) present and (2) form a contiguous subset of some namespace

source

pub fn convert_to_absence_proof(&mut self, leaf: NamespacedHash<NS_ID_SIZE>)

Convert a proof of the presence of some leaf to the proof of the absence of another leaf

source

pub fn siblings(&self) -> &[NamespacedHash<NS_ID_SIZE>]

Returns the siblings provided as part of the proof

source

pub fn start_idx(&self) -> u32

Returns the index of the first leaf in the proof

source

pub fn end_idx(&self) -> u32

Returns the index after the last leaf in the proof

source

pub fn leftmost_right_sibling(&self) -> Option<&NamespacedHash<NS_ID_SIZE>>

Returns the leftmost node to the right of the proven range, if one exists

source

pub fn rightmost_left_sibling(&self) -> Option<&NamespacedHash<NS_ID_SIZE>>

Returns the rightmost node to the left of the proven range, if one exists

source

pub fn is_of_absence(&self) -> bool

Returns true if the proof is an absence proof

source

pub fn is_of_presence(&self) -> bool

Returns true if the proof is a presence proof

Trait Implementations§

source§

impl Clone for NamespaceProof

source§

fn clone(&self) -> NamespaceProof

Returns a copy 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 Debug for NamespaceProof

source§

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

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

impl Deref for NamespaceProof

§

type Target = NamespaceProof<NamespacedSha2Hasher<NS_SIZE>, NS_SIZE>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for NamespaceProof

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'de> Deserialize<'de> for NamespaceProof

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<NamespaceProof<NamespacedSha2Hasher<NS_SIZE>, NS_SIZE>> for NamespaceProof

source§

fn from(value: NamespaceProof<NamespacedSha2Hasher, NS_SIZE>) -> NamespaceProof

Converts to this type from the input type.
source§

impl From<NamespaceProof> for NamespaceProof<NamespacedSha2Hasher, NS_SIZE>

source§

fn from(value: NamespaceProof) -> NamespaceProof<NamespacedSha2Hasher, NS_SIZE>

Converts to this type from the input type.
source§

impl From<NamespaceProof> for Proof

source§

fn from(value: NamespaceProof) -> Self

Converts to this type from the input type.
source§

impl PartialEq for NamespaceProof

source§

fn eq(&self, other: &NamespaceProof) -> 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 Protobuf<Proof> for NamespaceProof

source§

fn encode<B>(&self, buf: &mut B) -> Result<(), Error>
where B: BufMut,

Encode into a buffer in Protobuf format. Read more
source§

fn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), Error>
where B: BufMut,

Encode with a length-delimiter to a buffer in Protobuf format. Read more
source§

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

Constructor that attempts to decode an instance from a buffer. Read more
source§

fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>
where B: Buf,

Constructor that attempts to decode a length-delimited instance from the buffer. Read more
source§

fn encoded_len(&self) -> usize

Returns the encoded length of the message without a length delimiter. Read more
source§

fn encode_vec(&self) -> Result<Vec<u8>, Infallible>

Encodes into a Protobuf-encoded Vec<u8>.
source§

fn decode_vec(v: &[u8]) -> Result<Self, Error>

Constructor that attempts to decode a Protobuf-encoded instance from a Vec<u8> (or equivalent).
source§

fn encode_length_delimited_vec(&self) -> Result<Vec<u8>, Infallible>

Encode with a length-delimiter to a Vec<u8> Protobuf-encoded message.
source§

fn decode_length_delimited_vec(v: &[u8]) -> Result<Self, Error>

Constructor that attempts to decode a Protobuf-encoded instance with a length-delimiter from a Vec<u8> or equivalent.
source§

impl Serialize for NamespaceProof

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<Proof> for NamespaceProof

§

type Error = Error

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

fn try_from(value: RawProof) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl StructuralPartialEq for NamespaceProof

Auto Trait Implementations§

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, dst: *mut T)

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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

§

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<S> CondSend for S
where S: Send,

source§

impl<S> CondSync for S
where S: Send + Sync,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,