2 days ago · The launch of the Bitcoin blockchain started with a hardcoded block called the ‘ genesis block ’ or ‘block zero.’ Satoshi started the genesis block on Saturday, January 3, , at. A block header is like the metadata at the top of a block of transactions. The fields in the block header provide a unique summary of the entire block. The block header data is shown in the table below: The Bitcoin version number is used to keep track of upgrades and changes in the protocol. The previous block header hash is the linkage into the previous block and secures the chain.
Bitcoin genesis block headerBlock Chain — Bitcoin
Full nodes will not accept blocks with headers more than two hours in the future according to their clock. See the nBits format described below. An arbitrary number miners change to modify the header hash in order to produce a hash less than or equal to the target threshold. If all bit values are tested, the time can be updated or the coinbase transaction can be changed and the merkle root updated.
Version 2 was introduced in Bitcoin Core 0. As described in BIP34 , valid version 2 blocks require a block height parameter in the coinbase. Also described in BIP34 are rules for rejecting certain blocks; based on those rules, Bitcoin Core 0. Version 3 blocks were introduced in Bitcoin Core 0. Transactions that do not use strict DER encoding had previously been non-standard since Bitcoin Core 0.
The mechanism used for the version 2, 3, and 4 upgrades is commonly called IsSuperMajority after the function added to Bitcoin Core to manage those soft forking changes. See BIP34 for a full description of this method. Draft BIP9 describes the version bits design as of this writing, although it is still being actively edited and may substantially change while in the draft state.
The merkle root is constructed using all the TXIDs of transactions in this block, but first the TXIDs are placed in order as required by the consensus rules:. Any input within this block can spend an output which also appears in this block assuming the spend is otherwise valid.
This ensures that any program parsing block chain transactions linearly will encounter each output before it is used as an input. If a block only has a coinbase transaction and one other transaction, the TXIDs of those two transactions are placed in order, concatenated as 64 raw bytes, and then SHA SHA hashed together to form the merkle root.
If a block has three or more transactions, intermediate merkle tree rows are formed. If there are more than two hashes in the second row, the process is repeated to create a third row and, if necessary, repeated further to create additional rows. Once a row is obtained with only two hashes, those hashes are concatenated and hashed to produce the merkle root. The target threshold is a bit unsigned integer which a header hash must be equal to or below in order for that header to be a valid part of the block chain.
As a base number, nBits can be quickly parsed as bytes the same way you might parse a decimal number in base scientific notation:. Although the target threshold should be an unsigned integer, the original nBits implementation inherits properties from a signed data class, allowing the target threshold to be negative if the high bit of the significand is set.
This is useless—the header hash is treated as an unsigned number, so it can never be equal to or lower than a negative target threshold. Bitcoin Core deals with this in two ways:. When parsing nBits, Bitcoin Core converts a negative target threshold into a target of zero, which the header hash can equal in theory, at least. When creating a value for nBits, Bitcoin Core checks to see if it will produce an nBits which will be interpreted as negative; if so, it divides the significand by and increases the exponent by 1 to produce the same number with a different encoding.
Bitcoin full nodes maintain a local copy of the blockchain, starting at the genesis block. The local copy of the blockchain is constantly updated as new blocks are found and used to extend the chain. As a node receives incoming blocks from the network, it will validate these blocks and then link them to the existing blockchain. The last block the node knows about is block ,, with a block header hash of e7ba6fe7bad39faf3b5a83daedf05f7d1b71a Looking at this new block, the node finds the previousblockhash field, which contains the hash of its parent block.
It is a hash known to the node, that of the last block on the chain at height , Therefore, this new block is a child of the last block on the chain and extends the existing blockchain.
The node adds this new block to the end of the chain, making the blockchain longer with a new height of , Each block in the bitcoin blockchain contains a summary of all the transactions in the block, using a merkle tree.
A merkle tree , also known as a binary hash tree , is a data structure used for efficiently summarizing and verifying the integrity of large sets of data. Merkle trees are binary trees containing cryptographic hashes.
Merkle trees are used in bitcoin to summarize all the transactions in a block, producing an overall digital fingerprint of the entire set of transactions, providing a very efficient process to verify whether a transaction is included in a block. A Merkle tree is constructed by recursively hashing pairs of nodes until there is only one hash, called the root , or merkle root.
The merkle tree is constructed bottom-up. The transactions are not stored in the merkle tree; rather, their data is hashed and the resulting hash is stored in each leaf node as H A , H B , H C , and H D :. Consecutive pairs of leaf nodes are then summarized in a parent node, by concatenating the two hashes and hashing them together.
For example, to construct the parent node H AB , the two byte hashes of the children are concatenated to create a byte string. The process continues until there is only one node at the top, the node known as the Merkle root. That byte hash is stored in the block header and summarizes all the data in all four transactions. Because the merkle tree is a binary tree, it needs an even number of leaf nodes. If there is an odd number of transactions to summarize, the last transaction hash will be duplicated to create an even number of leaf nodes, also known as a balanced tree.
The same method for constructing a tree from four transactions can be generalized to construct trees of any size. In bitcoin it is common to have several hundred to more than a thousand transactions in a single block, which are summarized in exactly the same way, producing just 32 bytes of data as the single merkle root. Note that although the root looks bigger than the leaf nodes in the diagram, it is the exact same size, just 32 bytes. Whether there is one transaction or a hundred thousand transactions in the block, the merkle root always summarizes them into 32 bytes.
To prove that a specific transaction is included in a block, a node only needs to produce log 2 N byte hashes, constituting an authentication path or merkle path connecting the specific transaction to the root of the tree. This is especially important as the number of transactions increases, because the base-2 logarithm of the number of transactions increases much more slowly.
This allows bitcoin nodes to efficiently produce paths of 10 or 12 hashes — bytes , which can provide proof of a single transaction out of more than a thousand transactions in a megabyte-size block. The efficiency of merkle trees becomes obvious as the scale increases. As you can see from the table, while the block size increases rapidly, from 4 KB with 16 transactions to a block size of 16 MB to fit 65, transactions, the merkle path required to prove the inclusion of a transaction increases much more slowly, from bytes to only bytes.
Nodes that do not maintain a full blockchain, called simplified payment verification SPV nodes , use merkle paths to verify transactions without downloading full blocks. Merkle trees are used extensively by SPV nodes. In order to verify that a transaction is included in a block, without having to download all the transactions in the block, they use an authentication path, or merkle path.
Consider, for example, an SPV node that is interested in incoming payments to an address contained in its wallet. The SPV node will establish a bloom filter on its connections to peers to limit the transactions received to only those containing addresses of interest. When a peer sees a transaction that matches the bloom filter, it will send that block using a merkleblock message. The merkleblock message contains the block header as well as a merkle path that links the transaction of interest to the merkle root in the block.
The SPV node can use this merkle path to connect the transaction to the block and verify that the transaction is included in the block. The SPV node also uses the block header to link the block to the rest of the blockchain.
The combination of these two links, between the transaction and block, and between the block and blockchain, proves that the transaction is recorded in the blockchain. All in all, the SPV node will have received less than a kilobyte of data for the block header and merkle path, an amount of data that is more than a thousand times less than a full block about 1 megabyte currently.
Skip to main content. Start your free trial. The Blockchain. Structure of a Block. The structure of a block. Block Header. The structure of the block header. The Genesis Block. Linking Blocks in the Blockchain. Merkle Trees. Blocks linked in a chain, by reference to the previous block header hash. Duplicating one data element achieves an even number of data elements. Building a merkle tree.