1

According to the Bitcoin white paper, a block contains the fields "Previous Hash", "Nonce", and "Root Hash". The root hash is a merkle tree root node of all the transactions that have been confirmed in that particular block.

I read in the fifth paragraph of the top answer on What is the Merkle root?:

If we have a transaction that claims to have been from block #234133, we can get the transactions for that block, verify the Merkle tree, and know that the transaction is valid.

Say a block b somewhere in the blockchain holds t transactions. Where and how is the mapping of a particular set of transaction to a particular block stored? Because the blockchain itself only contains the root hash of all transactions to save space. So are there other hidden components that haven't been published in the white paper and are there resources to get a comprehensive idea about them?

Thanks.

1
  • 2
    The whitepaper is nothing like a statement of how the system is designed, it's at best an overview of the concepts. The actual implementation doesn't even strictly follow what is said, and you shouldn't expect a 9 page document to.
    – Claris
    Sep 26, 2020 at 0:46

3 Answers 3

2

The merkle tree is dynamically recreated to validate it in a block, the order of transactions in the block implicitly describe what the merkle tree should look like when reconstructed. The transactions are stored as part of the block, quite literally the header, a number stating the number of transactions to follow, and then a list of all the transactions follows.

2
  • But how do you find a particular transaction or a block that has the particular transaction when you wish to verify the transaction as having taken place?
    – Bittu
    Sep 26, 2020 at 0:58
  • 1
    You either read all blocks and keep an index of the transactions, or you ask a service that does know.
    – Murch
    Sep 26, 2020 at 1:35
0

The whitepaper just gives a conceptual overview of Bitcoin, but certainly isn't a full specification. Anyway, beyond the blockchain itself, keeping track of transactions and UTXOs is more of an implementation detail than a protocol concern. Various explorers, nodes, and wallets will differ in their approaches, but generally there are a few different mappings between transactions and blocks for different purposes:

Blockchain: block to transaction mapping

First and foremost, the blocks as included in the blockchain include the transactions they confirmed. The complete blockchain is retained in by archival full nodes. As Anonymous already explained, the merkle tree is only stored implicitly in the blockchain per each block simply listing its full set of transactions in order. Full nodes recreate the complete merkle tree on demand by rehashing the block's transactions during block validation as well as when a Merkle proof is requested from them.

Specific interests: Transaction to block mapping

Wallets generally retain copies of the transactions that involve their addresses. These transaction objects should generally keep the block height and the block hash, so that the wallet can deal with chain reorganizations and keep track of confirmation count. I would suspect that some wallet implementations may also keep the Merkle proof around if they e.g. want to be able to proof the existence of funds to other devices.

Bitcoin Core will keep a full transaction index around when configured with the start-up index -tindex=1.

UTXO set: Output to transaction/block mapping

Full nodes maintain the ledger of all Bitcoin funds in form of the Unspent Transaction Output (UTXO) set. UTXOs are uniquely identified via their outpoints ([txid:vout]) which means that they inherently reference the corresponding transaction. A UTXO object should generally also include a direct or indirect reference to the block that confirmed the transaction that created the UTXO.

Explorers

Explorers generally keep more comprehensive databases of transactions, blocks, addresses, and UTXOs.

-4

I'm not sure u r asking as a human want to verify a certain transaction, or as a developer wants to write code to verify a certain transaction given its block no, address,...etc

1-In general, if user A had say "n Btc" as an UTXO which changed to "n' Btc" after transaction X in block B; then u want to validate the spending of the UTXO "n" (by checking Merkle proof/witness) & the creation of UTXO "n'" in block B.

2- Or as a user, without any coding, u may go to one of these sites https://m.btc.com/ https://www.blockchain.com https://blockchair.com

-either start by the block # ( if there's say more than 1000 TXs in the block it would be hard to check this way) ex. These photos show how did I checked that the coinbase UTXO of block 100,000 got spent in block 266,668 enter image description here enter image description here enter image description here

-or by the given user address, u get something like this Then u search for the UTXO value in the given TX (whether it was input or ouput from the arrow direction & the color as u see here) enter image description hereenter image description here When u click on it, it will get u to the TX created it with block no & all info; say I clicked on in the above link, I get the transaction details & the block no enter image description here

(Yes these r probably wallet addresses, but maybe it would be easier to check from since there's a chronological order while inside one block u don't know what's the index/relative order of ur TX; I mean u didn't say it's given)

3-If u r asking as a developer, I guess this Bitcoin core code tells u how things r really stored https://github.com/bitcoin/bitcoin/blob/398dd678338971d2189934713c83c184742f293f/src/coins.h#L60-L65 I happen to find it "coincidencly" yesterday when checking this https://github.com/mit-dci/utreexo/issues/277

I hope this helps...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.