Close Menu
  • Home
  • Altcoin
  • Bitcoin
  • Crypto
  • Forex
  • Online Money
What's Hot

7 Reasons Your Card Might Not Work — and What to Do 

April 6, 2026

The Best Trades Will Find You…If You Stop Looking for Them » Learn To Trade The Market

April 6, 2026

GSC Logging Error Yielded Inflated Impressions Since May 2025

April 6, 2026
Facebook X (Twitter) Instagram
  • Altcoin
  • Bitcoin
  • Crypto
  • Forex
  • Online Money
Facebook X (Twitter) Instagram
Cointelegraphe
  • Home
  • Altcoin
  • Bitcoin
  • Crypto
  • Forex
  • Online Money
Cointelegraphe
Home»Bitcoin»bitcoin core – Decoding chainstate UTXOs: TXID, block height, and balance misalignment
bitcoin core – Decoding chainstate UTXOs: TXID, block height, and balance misalignment
Bitcoin

bitcoin core – Decoding chainstate UTXOs: TXID, block height, and balance misalignment

adminBy adminJuly 28, 2025No Comments3 Mins Read
Share
Facebook Twitter LinkedIn Pinterest Email


I am trying to make a rust toolset for reading UTXOs directly from chain state. I am following bitcoin source almost to the letter (at least I think I am).

I have a decode_varint

pub fn decode_varint(data: &[u8]) -> Option<(u32, usize)> {
    let mut n: u32 = 0;
    let mut shift = 0;

    for (i, &byte) in data.iter().enumerate().take(5) {
        let part = (byte & 0x7F) as u32;
        n |= part << shift;

        if byte & 0x80 == 0 {
            return Some((n, i + 1));
        }

        // Bitcoin adds this quirk:
        n = n.wrapping_add(1 << shift);
        shift += 7;
    }

    None
}

I have a decompress_amount

pub fn decompress_amount(x: u64) -> u64 {
    if x == 0 {
        return 0;
    }
    let mut x = x - 1;
    let e = x % 10;
    x /= 10;
    let mut n;
    if e < 9 {
        let d = (x % 9) + 1;
        x /= 9;
        n = x * 10 + d;
    } else {
        n = x + 1;
    }
    for _ in 0..e {
        n *= 10;
    }
    n
}

I am making sure to only get UTXO entries

pub fn decode_utxo_key(mut key: &[u8]) -> Option<(Vec, u32)> {
    if key.is_empty() || key[0] != b'C' {
        return None;
    }
    key = &key[1..];
    let txid = key.get(..32)?.to_vec();
    key = &key[32..];
    let (vout, _) = decode_varint(key)?;
    Some((txid, vout as u32))
}

Yet for some reason my keys are showing different txids than the block height.

key: `BytesKey([67, 0, 0, 0, 0, 1, 236, 58, 152, 94, 229, 61, 50, 239, 22, 75, 88, 246, 154, 181, 7, 146, 209, 249, 113, 25, 180, 120, 10, 150, 212, 118, 209, 0]), value: [60, 114, 185, 97, 43, 211, 164, 127, 45, 124, 28, 164, 166, 210, 240, 182, 238, 220, 41, 24, 211, 153, 185, 205, 199])

txid: f349b3a497e29738638c27654d3125deb8d90702dc51ab3bc993370900000000

thats txid at block 684,608

I am getting the XOR obfuscation key:

    let read_opts = ReadOptions::new();
    let xor_iter = db.iter(read_opts);
    let mut obfuscation_key: Vec = Vec::new();

    for (key, value) in xor_iter {
        if key.0.starts_with(&[0x0e]) {
            obfuscation_key = value;
            break;
        }
    }

This returns value bytes decoded as: [52, 148, 23, 67, 104 , 115, 134, 222, 130, 10, 78, 153, 93, 115, 228, 159, 196, 86, 17, 179, 224, 72, 222, 228, 185, 255, 26, 46, 229, 73, 140, 125, 129, 241, 246, 106, 170, 3, 94, 35]

Yet 52, is clearly not the correct byte for block 684,608.

What am I missing?



Source link

Balance bitcoin block chainstate Core Decoding height misalignment TXID UTXOs
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
admin
  • Website

Related Posts

7 Reasons Your Card Might Not Work — and What to Do 

April 6, 2026

Kiyosaki Says 1974 Shift Drives Debt Crisis, Backs Bitcoin and gold

April 5, 2026

Who Is Really Selling Bitcoin? Analyst Uncovers The On-chain Dynamics 

April 4, 2026

This Analyst Thinks Bitcoin’s 50% Crash Was A ‘Victory’

April 3, 2026
Add A Comment
Leave A Reply Cancel Reply

Top Insights

7 Reasons Your Card Might Not Work — and What to Do 

April 6, 2026

The Best Trades Will Find You…If You Stop Looking for Them » Learn To Trade The Market

April 6, 2026

GSC Logging Error Yielded Inflated Impressions Since May 2025

April 6, 2026

Polymarket just revealed a ‘full exchange upgrade’ to take control of its own trading and truth

April 6, 2026
ads

Subscribe to Updates

Get the latest creative news from Cointelegraphe about Crypto, bItcoin and Altcoin.

About Us
About Us

At CoinTelegraphe, we are dedicated to bringing you the latest and most insightful news, analysis, and updates from the dynamic world of cryptocurrency. Our mission is to provide our readers with accurate, timely, and comprehensive information to help them navigate the complexities of the crypto market.

Facebook X (Twitter) Instagram Pinterest YouTube
Top Insights

7 Reasons Your Card Might Not Work — and What to Do 

April 6, 2026

The Best Trades Will Find You…If You Stop Looking for Them » Learn To Trade The Market

April 6, 2026

GSC Logging Error Yielded Inflated Impressions Since May 2025

April 6, 2026
Get Informed

Subscribe to Updates

Get the latest creative news from Cointelegraphe about Crypto, bItcoin and Altcoin.

Please enable JavaScript in your browser to complete this form.
Loading
  • About us
  • Contact Us
  • Shop
  • Privacy Policy
  • Terms and Conditions
Copyright 2024 Cointelegraphe Design By Horaam Sultan.

Type above and press Enter to search. Press Esc to cancel.