Skip to main content

UtxoMerkleTree

Struct UtxoMerkleTree 

Source
pub struct UtxoMerkleTree { /* private fields */ }
Expand description

UTXO Merkle Tree

Provides incremental updates for UTXO set with Merkle tree commitments. Wraps sparse-merkle-tree to provide UTXO-specific operations.

Implementations§

Source§

impl UtxoMerkleTree

Source

pub fn new() -> UtxoCommitmentResult<Self>

Create a new empty UTXO Merkle tree

Source

pub fn root(&self) -> Hash

Get the Merkle root of the UTXO set

Source

pub fn insert( &mut self, outpoint: OutPoint, utxo: UTXO, ) -> UtxoCommitmentResult<Hash>

Insert a UTXO into the tree

Source

pub fn remove( &mut self, outpoint: &OutPoint, utxo: &UTXO, ) -> UtxoCommitmentResult<Hash>

Remove a UTXO from the tree (by updating with zero value)

Source

pub fn get(&self, outpoint: &OutPoint) -> UtxoCommitmentResult<Option<UTXO>>

Get a UTXO from the tree

Source

pub fn generate_commitment( &self, block_hash: Hash, block_height: Natural, ) -> UtxoCommitment

Generate a UTXO commitment

Source

pub fn total_supply(&self) -> u64

Get total supply

Source

pub fn utxo_count(&self) -> u64

Get UTXO count

Source

pub fn generate_proof( &self, outpoint: &OutPoint, ) -> UtxoCommitmentResult<MerkleProof>

Generate a Merkle proof for a specific UTXO

Returns a proof that can be used to verify the UTXO exists in the tree.

Source

pub fn serialize_proof_for_wire( proof: MerkleProof, ) -> UtxoCommitmentResult<Vec<u8>>

Serialize a Merkle proof to bytes for wire transmission.

Call this from network handlers (e.g. blvm-node) to avoid serde trait resolution issues when multiple serde versions exist in the dependency tree.

Source

pub fn deserialize_proof_from_wire( bytes: &[u8], ) -> UtxoCommitmentResult<MerkleProof>

Deserialize a Merkle proof from bytes (inverse of serialize_proof_for_wire).

Source

pub fn verify_commitment_supply( &self, commitment: &UtxoCommitment, ) -> UtxoCommitmentResult<bool>

Verify a UTXO commitment matches expected supply

Compares the total supply in the commitment against the expected Bitcoin supply at the given block height.

Source

pub fn from_utxo_set(utxo_set: &UtxoSet) -> UtxoCommitmentResult<Self>

Rebuild tree from UtxoSet

Used after connect_block() to update the Merkle tree with the validated UTXO set. This rebuilds the entire tree.

Source

pub fn update_from_utxo_set( &mut self, new_utxo_set: &UtxoSet, old_utxo_set: &UtxoSet, ) -> UtxoCommitmentResult<Hash>

Update tree from UtxoSet (incremental update)

Compares current tree state with new UtxoSet and applies only the differences. More efficient than full rebuild.

Note: This function requires knowing the previous UtxoSet to efficiently detect removals. If the previous set is not available, use from_utxo_set() to rebuild the tree.

§Arguments
  • new_utxo_set - The new UTXO set (from connect_block)
  • old_utxo_set - The previous UTXO set (for detecting removals)
Source

pub fn to_utxo_set(&self) -> UtxoCommitmentResult<UtxoSet>

Convert UtxoMerkleTree to UtxoSet

Iterates through the tree and builds a UtxoSet. Note: This is expensive as sparse merkle trees don’t support efficient iteration. Use only when necessary.

Source

pub fn verify_commitment_root(&self, commitment: &UtxoCommitment) -> bool

Verify a commitment’s Merkle root matches the tree’s root

Source

pub fn verify_utxo_proof( commitment: &UtxoCommitment, outpoint: &OutPoint, utxo: &UTXO, proof: MerkleProof, ) -> UtxoCommitmentResult<bool>

Verify a UTXO Merkle proof against a commitment’s root

This is a static/associated function - it doesn’t need a tree instance, only the commitment’s merkle root for verification.

This function cryptographically verifies that a UTXO exists in the commitment’s UTXO set without requiring the full tree.

§Arguments
  • commitment - The UTXO commitment containing the merkle root
  • outpoint - The outpoint to verify
  • utxo - The UTXO data to verify
  • proof - The Merkle proof (takes ownership)
§Returns

Ok(true) if proof is valid, Ok(false) or Err if invalid

Trait Implementations§

Source§

impl Default for UtxoMerkleTree

Available on crate feature utxo-commitments only.
Source§

fn default() -> Self

Prefer UtxoMerkleTree::new in code that can handle allocation failure.

Default panics if the underlying sparse Merkle tree cannot be constructed (e.g. severe memory pressure). This matches “default must be infallible” call sites but is not ideal for untrusted or resource-constrained environments.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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