Bitcoin ledger fundamentals - The public ledger (also known as the blockchain) contains all transactions on the network. - Everyone has access to and/or has a copy of the ledger that they can edit individually (Bitcoin nodes). - All transaction history must always be known, this is to confirm balances and prevent overspending. - When one user adds a transaction, it is broadcast to all other ledgers (nodes). - Bitcoin trusts whichever ledger has the most computaional work put into it. This prevents fraudulent ledgers from being accepted. - Trust is dependant on computaional work, and only the longest ledger is trusted. A modified ledger would require an infeasible amount of computational power to generate a valid, longer version. Transaction verification - There are public keys and private keys. A private/public key pair can be created nearly infinite times. Anyone can create a private/public key pair. - Wallet addresses can be derived from the public key as another layer of security and privacy. - Digital signatures are used to sign transactions to prove that the owner verified that transaction, and are made with the private key. - Valid signatures are made with a message (the transaction), unique ID (usually sequential), and the private key, using the elliptic curve digital signature algorithm. - The dependance on the private key verifies that only people with access to it can produce that signature. - The dependance on the message verifies that it cannot be copied to another message. - The dependance on a unique ID verifies that any signature and message cannot be copied. - To verify the signature, a function uses the message, signature, and public key to output true or false. A true result verifies that the signature was created with the corresponding private key. Hash functions - Mining (hashing), is based on cryptographic hash functions. - A hash function can take any string as input, and output another string with a fixed number of bits. The output is called the 'hash' or 'digest'. SHA256's output is 256 bits (32B). - A hash function's output appears seemingly random and is completely unpredictable, any change to the input will completely change the output. Cryptographic hash functions will always produce the same output for any specifc input. - Cryptographic hash functions are also used to verify file integrity by finding the hash of the entire file. It is virtually impossible to have a different file with the same hash. - Cryptographic hash functions, such as SHA256, can only find a specific output by guessing every possible input. Proof of Work - The blockchain (ledger) can be visualized as a chain of blocks, which each contain: a list of transactions, the nonce (a guessed number, also called the 'proof of work'), and the hash of the previous block (to it dependant on all previous blocks). - When the entire block is hashed with SHA256, the digest (256 bit binary number) must be less than or equal to a chosen number to be valid. - The chosen number is based on the difficulty. It is chosen automatically every 2016 blocks to maintain an average of 10 minute block times regardless of total computaional power. - The nonce is also known as the proof of work (PoW), because it proves that the miner who found it performed the computaional work of guessing until they found a valid digest. - Changing any information in a block would invalidate it and require rehashing that block, every block after it, and new blocks being made. - To successfully change a past transaction, you would have to be faster than everyone else combined in order to make your (now unique, and shorter) ledger the longest again. - Older blocks are much more difficult to change, and are usually considered immutable after a few hours. Mining (hashing) - Miners (hashers) operate a node which listens for transactions being broadcast, and collects them into a block. If they can find a valid nonce and hash a valid answer in time, will broadcast the block they made to be verified by others. - The first transaction in every block goes to the successful miner as the 'block reward' for their computaional effort in creating it, this is new currency being created. Incentive and scarcity - Every transaction can include a small fee that will go to whoever mines the block with that transaction. This incentivizes miners to include and prioritize your transaction in the next block. - Bitcoin block rewards started at 50btc and halve every 210000 blocks, or roughly every 4 years. This is called the halvening and will continue until there are 21000000 bitcoin in existence, at which point the block rewards will disappear, and miners will rely on transaction fees as incentive. - Bitcoin blocks have a theoretical limit of 4MB in size