..

Week of the 12/30/2024 - #53

Contents

tech

  • Bitcoins the hard way

science

  • The Dome: A Simple Violation of Determinism in Newtonian Mechanics

Bitcoins the hard way

Recently I remembered a great article I read a few year ago about how to create a bitcoin transaction, feed it into the network and get it confirmed. It’s a great way to understand how the blockchain works and how transactions are processed. The article is called Bitcoins the hard way: Using the raw Bitcoin protocol and it’s written by Ken Shirriff. It’s a great read and I highly recommend it if you’re interested in how the blockchain works. The author also has another very interesting article about how the mining process works, called Bitcoin mining the hard way: the algorithms, protocols, and bytes. I think these two articles are key to understand how the blockchain works.

In here I’ll break down the general description of the bitcoin protocol as described in the article:

Bitcoin transactions

  • Bitcoins consist of entries in a distributed database that keeps track of the ownership of bitcoins
  • They are not tied to users or accounts.
  • Bitcoins are owned by a Bitcoin address, for example 1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa
  • A transaction is the mechanism for spending bitcoins.
  • In a transaction, the owner of some bitcoins transfers ownership to a new address.
  • Transactions are recorded in the distributed database through mining
  • Transactions are grouped into blocks and about every 10 minutes a new block of transactions is sent out, becoming part of the transaction log known as the blockchain
  • Bitcoin mining is the process that puts transactions into a block, to make sure everyone has a consistent view of the transaction log.
  • To mine a block, miners must find an extremely rare solution to an (otherwise-pointless) cryptographic problem.
  • Finding this solution generates a mined block, which becomes part of the official block chain.
  • Mining is also the mechanism for new bitcoins to enter the system.
  • When a block is successfully mined, new bitcoins are generated in the block and paid to the miner.
  • In addition, the miner gets any fees associated with the transactions in the block.
  • Because of this, mining is very competitive with many people attempting to mine blocks.
  • There is no centralized Bitcoin server.

The peer-to-peer network

  • Bitcoin runs on a peer-to-peer network.
  • If you run a Bitcoin client, you become part of that network.
  • The nodes on the network exchange transactions, blocks, and addresses of other peers with each other.
  • When you first connect to the network, your client downloads the blockchain from some random node or nodes.
  • In turn, your client may provide data to other nodes.
  • When you create a Bitcoin transaction, you send it to some peer, who sends it to other peers, and so on, until it reaches the entire network.
  • Miners pick up your transaction, generate a mined block containing your transaction, and send this mined block to peers.
  • Eventually your client will receive the block and your client shows that the transaction was processed.

Cryptography

  • Bitcoin uses digital signatures to ensure that only the owner of bitcoins can spend them.
  • The owner of a Bitcoin address has the private key associated with the address.
  • To spend bitcoins, they sign the transaction with this private key
  • Blocks and transactions are identified by a 256-bit cryptographic hash of their contents
  • There are three types of keys:
    • the private key
    • the public key
    • the hash of the public key
  • They are represented externally in ASCII using Base58Check encoding.
  • The private key is the important key, since it is required to access the bitcoins and the other keys can be generated from it.
  • The public key hash is the Bitcoin address you see published.

Inside a transaction

  • A Bitcoin transaction moves bitcoins between one or more inputs and outputs.
  • Each input is a transaction and address supplying bitcoins.
  • Each output is an address receiving bitcoin, along with the amount of bitcoins going to that address.
  • Each input used must be entirely spent in a transaction. If an address received 100 bitcoins in a transaction and you just want to spend 1 bitcoin, the transaction must spend all 100. The solution is to use a second output for change, which returns the 99 leftover bitcoins back to you.
  • Transactions can also include fees. If there are any bitcoins left over after adding up the inputs and subtracting the outputs, the remainder is a fee paid to the miner.
  • The fee isn’t strictly required, but transactions without a fee will be a low priority for miners and may not be processed for days or may be discarded entirely
  • If you connect your bitcoin client to the network you will receive a feed of transactions.
  • You can view transactions and blocks online in pages such as: blockchain.com

Blockchain.com explorer screen

You can view a single block and all the transacions stored in it:

Blockchain.com block view

And a single transaction:

Blockchain.com transaction view

Block chain

  • The block chain provides Bitcoin’s public ledger, an ordered and timestamped record of transactions
  • Each full node in the Bitcoin network independently stores a block chain containing only blocks validated by that node.
  • The validation rules these nodes follow to maintain consensus are called consensus rules.
  • Any Bitcoin miner who successfully hashes a block header to a value below the target threshold can add the entire block to the block chain (assuming the block is otherwise valid).
  • These blocks are commonly addressed by their block height—the number of blocks between them and the first Bitcoin block (block 0, most commonly known as the genesis block).
  • Multiple blocks can all have the same block height, as is common when two or more miners each produce a block at roughly the same time.
  • This creates an apparent fork in the block chain
  • When miners produce simultaneous blocks at the end of the block chain, each node individually chooses which block to accept.
  • Eventually a miner produces another block which attaches to only one of the competing simultaneously-mined blocks.
  • This makes that side of the fork stronger than the other side.
  • Each block has a header and a list of transcations
  • The first one of these transactions must be a coinbase transaction which should collect and spend the block reward
  • The UTXO of a coinbase transaction has the special condition that it cannot be spent (used as an input) for at least 100 blocks.
  • This temporarily prevents a miner from spending the transaction fees and block reward from a block that may later be determined to be stale (and therefore the coinbase transaction destroyed) after a block chain fork.

References

  • Bitcoin protocol documentation - “This page describes the behavior of the reference client. The Bitcoin protocol is specified by the behavior of the reference client, not by this page. In particular, while this page is quite complete in describing the network protocol, it does not attempt to list all of the rules for block or transaction validity.”
  • P2P Network - “The Bitcoin network protocol allows full nodes (peers) to collaboratively maintain a peer-to-peer network for block and transaction exchange.”
  • Bitcoing develop - Learn Bitcoin and start building Bitcoin-based applications.

The Dome: A Simple Violation of Determinism in Newtonian Mechanics

Recently I saw a really interesting video about an article the violates determinism in Newtonian mechanics. The video is called The Dome Paradox: A Loophole in Newton’s Laws. The article can be found here: The Dome: A Simple Violation of Determinism in Newtonian Mechanics.