THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin Core CoinStatsIndex: UTXO Statistics and MuHash

permalink THAMER
#bitcoin#bitcoin-core#coinstatsindex#muhash#utxo

The UTXO set represents the outputs available for spending under the current chainstate. Measuring this set directly can require a substantial database traversal. Bitcoin Core's optional CoinStatsIndex maintains statistics as blocks are connected, enabling efficient queries for supported historical block positions.

Statistics and incremental updates

The index tracks aggregate information about the UTXO set and changes associated with blocks. When an output is created or spent, the corresponding aggregate state changes. Reorganizations require the index to follow the active chain rather than blindly accumulating statistics from disconnected blocks.

CoinStatsIndex is enabled with coinstatsindex=1. Its implementation uses MuHash, a cryptographic multiset hash that supports adding and removing elements. Unlike an ordinary hash of a serialized list, a multiset hash is designed to represent a collection independently of its ordering. Bitcoin Core defines the encoding of the coins included in its calculation.

Querying statistics

For a Bitcoin Core release supporting these arguments, inspect the available RPC options:

``
bitcoin-cli help gettxoutsetinfo
bitcoin-cli getindexinfo
bitcoin-cli gettxoutsetinfo muhash
``

Historical statistics can be requested using a block height or hash where supported by the index. For example, a query for height 800000 on mainnet is:

``
bitcoin-cli gettxoutsetinfo muhash 800000
``

This requires the relevant indexed history. The RPC's hash type and use_index options affect whether the index can satisfy the query. Do not assume every statistic is available through every query mode.

What the hash establishes

A matching MuHash value computed under the same serialization rules is evidence that two UTXO collections match, subject to the hash's security properties. It is not a proof that a remote node has independently validated every historical block. Bitcoin block headers do not generally contain this UTXO-set hash as a consensus commitment.

Aggregate UTXO value also differs from spendable supply in an economic sense. Outputs whose keys have been lost may remain in the set. The index cannot determine who controls them or whether they will ever be spent.

Operational considerations

CoinStatsIndex can operate with pruning, but initial construction requires access to the necessary historical block and undo data. Enabling it after required data has been discarded can require rebuilding with historical data. Monitor index synchronization and avoid expensive unindexed scans in latency-sensitive services.

Primary references

Bitcoin Core CoinStatsIndex: https://github.com/bitcoin/bitcoin/blob/master/src/index/coinstatsindex.cpp

MuHash implementation: https://github.com/bitcoin/bitcoin/blob/master/src/crypto/muhash.h

RPC documentation (29.0): https://bitcoincore.org/en/doc/29.0.0/rpc/blockchain/gettxoutsetinfo/

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects