pub struct ExclusionProof {
    /// The underlying proof set.
    proof_set: Vec<b256>,
    /// The leaf associated with the exclusion proof.
    leaf: ExclusionLeaf,
}
Expand description

An Exclusion Proof for a Sparse Merkle Tree.

Fields

proof_set: Vec

The underlying proof set.

leaf: ExclusionLeaf

The leaf associated with the exclusion proof.

Implementations

pub fn new(proof_set: Vec<b256>, leaf: ExclusionLeaf) -> Self

Instantiates a new ExclusionProof from a ProofSet and ExclusionLeaf.

Arguments

  • proof_set: [ProofSet] - A raw ProofSet of hashes.
  • leaf: [ExclusionLeaf] - The leaf associated with the exclusion proof.

Returns

[ExclusionProof] - A newly created ExclusionProof.

Examples

use sway_libs::merkle::sparse::{ExclusionProof, ExclusionLeaf};

fn foo() {
    let proof_set = ProofSet::new()
    let leaf = ExclusionLeaf::Placeholder;
    let new_proof = ExclusionProof::new(proof_set, leaf);
}

pub fn proof_set(self) -> Vec<b256>

Returns the underlying ProofSet of the ExclusionProof.

Returns

  • [ProofSet] - The underlying proof set that defines the exclusion proof.

Examples

use sway_libs::merkle::sparse::{ExclusionProof, ExclusionLeaf};

fn foo() {
    let new_proof_set = ProofSet::new()
    let leaf = ExclusionLeaf::Placeholder;
    let new_proof = ExclusionProof::new(new_proof_set, leaf);
    let result_proof_set = new_proof.proof_set();
    assert(result_proof_set.len() == new_proof_set.len());
}

pub fn leaf(self) -> ExclusionLeaf

Returns the underlying ExclusionLeaf of the ExclusionProof.

Returns

  • [ExclusionLeaf] - The underlying leaf that defines the exclusion proof.

Examples

use sway_libs::merkle::sparse::{ExclusionProof, ExclusionLeaf};

fn foo() {
    let new_proof_set = ProofSet::new()
    let leaf = ExclusionLeaf::Placeholder;
    let new_proof = ExclusionProof::new(new_proof_set, leaf);
    let result_leaf = new_proof.leaf();
    assert(result_leaf == leaf);
}

pub fn verify(self, root: MerkleRoot, key: MerkleTreeKey) -> bool

Verifies some leaf is excluded in a Sparse Merkle Tree against this exclusion proof.

Arguments

  • root: [MerkleRoot] - The root of the Sparse Merkle Tree.
  • key: [MerkleTreeKey] - The key associated with the particular leaf in the Sparse Merkle Tree.

Returns

  • [bool] - true if the verification is successful, otherwise false.

Examples

use sway_libs::merkle::sparse::ExclusionProof;

fn foo(proof: ExclusionProof, root: MerkleRoot, key: MerkleTreeKey) {
    assert(proof.verify(root, key));
}

pub fn root(self, key: MerkleTreeKey) -> MerkleRoot

Computes the root of a Sparse Merkle Tree from the proof and data.

Arguments

  • key: [MerkleTreeKey] - The key associated with the particular leaf in the Sparse Merkle Tree.

Returns

  • [MerkleRoot] - The computed merkle root.

Examples

use sway_libs::merkle::sparse::ExclusionProof;

fn foo(proof: ExclusionProof, key: MerkleTreeKey) {
    assert(proof.root(root, key) != b256::zero());
}

Trait Implementations

pub fn abi_encode(self, buffer: Buffer) -> Buffer

pub fn abi_decode(refmut buffer: BufferReader) -> Self

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

pub fn neq(self, other: Self) -> bool

Evaluates if two values of the same type are not equal.

Additional Information

This function is inherited when eq() is implemented.

Arguments

  • other: [Self] - The value of the same type.

Returns

  • [bool] - true if the two values are not equal, otherwise false.

Examples

struct MyStruct {
    val: u64,
}

impl PartialEq for MyStruct {
    fn eq(self, other: Self) -> bool {
         self.val == other.val
    }
}

fn foo() {
    let struct1 = MyStruct { val: 10 };
    let struct2 = MyStruct { val: 2 };
    let result = struct1 != struct2;
    assert(result);
}

pub fn clone(self) -> Self