Module proof_util

Source
Expand description

This module provides utility functions for working with Utreexo proofs.

These functions can be used, for example, when verifying if a mempool transaction is valid; to consume a block (delete transactions included in it from the mempool); or to validate a block.

Structs§

UtreexoLeafError
Error while reconstructing a leaf’s scriptPubKey, returned by process_proof.

Enums§

LeafErrorKind
Errors that may occur while reconstructing a leaf’s scriptPubKey.

Functions§

get_block_adds
From a block, gets the roots that will be included on the acc, certifying that any utxo will not be spent in the same block.
get_leaf_hashes 🔒
Computes the hash of a leaf node in the utreexo accumulator.
get_pk_hash 🔒
Computes the public key hash from the pushed key in the input’s scriptSig.
get_script_hash 🔒
Computes the script hash from the input’s scriptSig.
get_script_type
This function returns the scriptPubKey type (i.e. address type) of a given script data. It can be:
get_witness_pk_hash 🔒
Computes the witness public key hash from the input’s witness data.
get_witness_script_hash 🔒
Computes the witness script hash from the input’s witness data.
is_unspendable 🔒
Checks if a script is unspendable either by its length or if it contains the OP_RETURN opcode. It follows the implementation on Bitcoin Core.
process_proof
This function processes a proof of inclusion for a given block. It takes in the CompactLeafData for this block, this block’s transactions, the height and a function to get the block hash for a given height. Then returns a Result containing a vector with hashes for deleted leaves, and a UtxoMap, which is defined as HashMap<OutPoint, UtxoData>.
reconstruct_leaf_data
Reconstructs the leaf data from a CompactLeafData, the UTXO’s block hash, and its spending tx input.
reconstruct_script_pubkey
Reconstructs the output script, also called scriptPubKey, from a CompactLeafData and the spending tx input. Returns an error if we can’t reconstruct the script (the input doesn’t contain the required data).

Type Aliases§

ProcessedProof 🔒
A processed proof is a tuple containing a vector of deleted leaf hashes and a UTXO map. This will be used to process this block
UtxoMap 🔒
A hash map that provides the UTXO data given the outpoint. We will get this data from either our own cache or the Utreexo proofs, and use it to validate blocks and transactions.