3

My understanding is that transactions are stored on the blockchain in double hashed format: ie SHA256(SHA256(rawtransaction)). But it is also possible to get access to the raw transaction. This means that the raw transaction data must be stored somewhere. So where is the raw transaction data stored, if it isn't stored on the blockchain? Or was my initial statement incorrect about transactions being stored in double hashed format? I don't think the raw transaction data can be extracted by reversing the double hash operation.

10

This is a question of definition.

The blockchain doesn't store anything, it's an abstract data structure that's collectively maintained by nodes in a network. Those nodes are the ones that store things. That may or may not include the actual transaction data - it doesn't matter.

The Bitcoin blockchain consists of hash-linked block headers. Every block header contains the hash of the previous block header. Every block header also contains a hash of all the transaction hashes in it (through a Merkle tree). Those transaction hashes obviously are hashes of the transaction data itself.

That's a definition of the structure all nodes need to agree on, because it involves hashes, and those hashes need to match. But what they actually store of that is their own business. Full nodes with unpruned history will store all transactions and all blocks. Pruned nodes may store all transactions and blocks down to a particular point in history. More lightweight nodes may only store the block headers plus transactions the user is interested in.

2
  • 1
    So the raw transaction is indeed stored in the nodes (full nodes at least, and possibly pruned ones) and each transaction stores a double hashed representation of its input transactions: bitcoin.stackexchange.com/questions/8443/… – Marc May 31 at 16:44
  • 1
    Yes, transactions are typically serialized and stored that way, but again: they don't have to be. How things are stored is up to the individual node software. E.g. some software uses a compressed representation that can omit repeated input hashes. The only thing that matters is how a txid is defined, which is a double-SH256 of the transaction data in "network serialization" which indeed includes the txids of the previous tx that created the UTXOs being spent. If somewhere can store things differently, but still agree on that hash, everything is ok. – Pieter Wuille May 31 at 16:47
0

double hashed format: ie SHA256(SHA256(rawtransaction))

Your understanding of this is very, very wrong.

The data structure stored in a blockchain is not double hashed. Instead there are two hashes stored in the data structure.

Instead of SHA256(SHA256(rawtransaction)). You should visualize the blockchain data structure as:

struct Block {
    Transactions[] transactions;
    int256 nonce;
    int256 previousHash; // SHA256(previous.transactions + previous.nonce + previous.previousHash)
    int256 hash;         // SHA256(this.transactions + this.nonce + this.previousHash)
}

You can see, the data structure is linked to the previous block by including the hash of the previous block as part of its own data. This is the "chain" part of blockchain. The definition of the entire set of blocks is recursive because to calculate the hash of the previous block you need to calculate the hash of the block before that and so on until you get to the genesis block.

The raw committed transactions are part of the block.

2
  • 2
    Um, no. Double hashing is indeed used in blockchain. I can give you lots of references, e.g. bitcoin.stackexchange.com/questions/8443/…. I know how the chain part of the blockchain works. The real answer is that in (for example) links in current transaction to input transactions, the current transaction stores the double hash of the previous transaction. Double hashing is used elsewhere too. – Marc May 31 at 16:42
  • Note: the example of the block structure given in this answer works to give a basic understanding, but it is not truly accurate. See: en.bitcoin.it/wiki/Protocol_documentation#Block_Headers – chytrik Jun 1 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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