For the complete documentation index, see llms.txt. This page is also available as Markdown.

Block Structure

Block structure, Merkle Trees and transaction format


“Miners build blocks, but nodes decide which blocks to follow.” — Fundamental principle of Bitcoin


1. Introduction

Bitcoin is a distributed network whose operation depends on two central structures:

  1. blocks

  2. transactions

Both are chained cryptographically using Merkle trees and protected by Proof of Work (PoW). Understanding their design is essential to understand:

  • how information is organized

  • how incentives work

  • how immutability is guaranteed

  • how consensus is reached without a central authority


2. The blockchain: general structure

A Bitcoin block is composed of two main parts:

┌────────────────────┐ │ Header (80B) │ ← Block hash └────────────────────┘ ┌────────────────────┐ │ Body: transactions │ └────────────────────┘


2.1. Header fields

The block header is exactly 80 bytes, structured as follows:

Field
Size
Description

version

4 bytes

Indicates validation rules

prev_block_hash

32 bytes

Previous block hash

merkle_root

32 bytes

Merkle tree root

timestamp

4 bytes

Approximate time

bits

4 bytes

Difficulty target

nonce

4 bytes

Counter for PoW

Final block hash:


3. Block body: transactions

A block contains:

  • 1 coinbase transaction (the first)

  • N normal transactions

Conceptual representation:

Block ├─ Coinbase TX ├─ TX1 ├─ TX2 ├─ ... └─ TXn

The current limit is a maximum weight of:

4,000,000 unidades de weight\text{4,000,000 unidades de weight}

after the activation of SegWit (BIP141).


4. Merkle trees in Bitcoin

Merkle trees allow:

  • to prove inclusion of transactions

  • to reduce the amount of information required for SPV clients

  • to protect against modifications

4.1. Step-by-step construction

  1. Take the hash of each transaction: hi=SHA256d(txi)h_i = SHA256d(tx_i)

  2. Group pairs and hash them again:

Hi,j=SHA256d(hi∣∣hj)H_{i,j} = SHA256d(h_i || h_j)

  1. Repeat until reaching the root.


4.2. Representation


4.3. Inclusion proofs (Merkle Proof)

An SPV client can prove that:

txj∈bloquetx_j \in \text{bloque}

with a proof of size O(log⁡n)O(\log n).


5. Bitcoin transactions: technical structure

A transaction consists of:

  • inputs (inputs)

  • outputs (outputs)

The inputs consume previous UTXOs. The outputs create new UTXOs.


5.1. General format

Transaction ├─ Version (4 bytes) ├─ TX_IN_COUNT ├─ [Inputs] ├─ TX_OUT_COUNT ├─ [Outputs] └─ locktime


5.2. UTXO: Bitcoin's accounting model

Bitcoin does not use accounts. It uses a global set of unspent outputs (Unspent Transaction Outputs).

Advantages:

  • parallelization

  • easy verifiability

  • protection against double spending

  • simplicity in validation

Formalization:

UTXOnew=UTXOold−inputs+outputsUTXO_{new} = UTXO_{old} - inputs + outputs


6. Inputs: consuming previous transactions

An input contains:

Field
Description

prev_txid

hash of the previous transaction

prev_index

index of the consumed output

scriptSig

signature + unlocking data

sequence

used in locktime

The input proves that the user owns the private key associated with the UTXO.


6.1. scriptSig (classic)

Example:

<ECDSA signature> <public key>

With SegWit, the signature goes in a different field (witness).


7. Outputs: creating new UTXOs

An output contains:

Field
Description

value

amount in satoshis

scriptPubKey

spending conditions


7.1. Most common scriptPubKey (P2PKH)

OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG


7.2. P2SH

Type introduced by BIP16:

OP_HASH160 <script_hash> OP_EQUAL


7.3. P2WPKH (SegWit)

Witness format:

0 <20-byte-key-hash>

Benefits:

  • lower signature weight

  • eliminates malleability

  • reduces fees


8. Signatures in transactions

Bitcoin uses ECDSA over the curve secp256k1.

To sign a transaction a message is constructed:

m=serializacioˊn modificada(TX)m = \text{serialización modificada}(\text{TX})

Then:

firma=ECDSAsign(privkey,m)firma = ECDSA_sign(privkey, m)


8.1. Sighash types

Bitcoin allows different signing modes:

Code
Effect

SIGHASH_ALL

Signs inputs and outputs

SIGHASH_NONE

Signs inputs, outputs are free

SIGHASH_SINGLE

Signs the corresponding input

ANYONECANPAY

Modifies allowed inputs


9. The coinbase transaction

It is the first transaction in each block.

9.1. Features:

  • it has no valid inputs

  • it creates new bitcoins

  • includes the reward (subsidy + fees)

  • contains an arbitrary script with optional messages

Classic example: the genesis block's message.


9.2. Subsidy

Subsidio actual=50⋅2−n\text{Subsidio actual} = 50 \cdot 2^{-n}

where

  • nn = number of halvings that have occurred


10. How transactions are verified

A node verifies:

  1. Correct format

  2. Valid signatures

  3. UTXOs exist

  4. No double spending

  5. Outputs do not exceed inputs

  6. Valid sighash

  7. Script executed without error


10.1. Script evaluation

Bitcoin Script is a simple, non-Turing-complete language.

Evaluation example P2PKH:

scriptSig: <signature> <pubKey> scriptPub: OP_DUP OP_HASH160 <hash> OP_EQUALVERIFY OP_CHECKSIG


11. Block validation

To accept a block:

  1. Block hash < Target

  2. All transactions valid

  3. Correct size

  4. Correct reward

  5. Prev_block_hash matches

  6. The Merkle Root matches

  7. Reasonable timestamp


12. Mathematical representation of the chaining

If:

  • BiB_i = Block i

  • H(Bi)H(B_i) = Hash of block i header

then:

which produces:

B0→B1→B2→…B_0 \rightarrow B_1 \rightarrow B_2 \rightarrow \dots

Security depends on:

Costo de reorganizacioˊn≈PoW acumulado\text{Costo de reorganización} \approx \text{PoW acumulado}


13. Chapter conclusion

In this chapter we have seen:

  • how a block is structured

  • how transactions are organized and verified

  • what role the Merkle tree plays

  • how the integrity of the chain is ensured

  • why the UTXO system is superior to an account-based model

All these elements are the basis of Bitcoin's fundamental layer.


If you understand a block, you understand Bitcoin. If you understand the Merkle tree, you understand why it is immutable.


Last updated

Was this helpful?