Introduction to blockchain
Blockchain is a technology that has gained a great deal of attention in recent years. The goal of a blockchain network is to create an immutable digital ledger that is maintained in a decentralized fashion. This eliminates the need to trust a single authority to appropriately maintain the ledger.
Instead, much of the trust in a blockchain network is transferred to protocols and algorithms. Cryptographic algorithms, such as asymmetric cryptography and hash functions, are integral to blockchain’s ability to fulfill its promises.
Blockchain and asymmetric cryptography
Blockchain makes heavy use of asymmetric cryptography due to its ability to uniquely identify and authenticate the owner of a private key. In particular, blockchain uses asymmetric cryptography for addressing and digital signatures.
Public key addressing
Many blockchains are designed to be anonymous. Anyone can create an account on the network, create transactions and maintain a blockchain node without revealing their identity.
However, the blockchain network needs a means for tracking user identities on the blockchain. Without this, it would be impossible to ensure that a particular transaction was directed to the correct user.
For this, blockchain uses addresses that are tied to a user’s public key (often derived from it). In addition to providing a means of identifying users in a unique way — the security of an asymmetric cryptographic algorithm should make it infeasible for two users to have the same public key — it also enables the effective use of digital signatures within the blockchain.
Digitally signed data
Blockchain is designed to eliminate the need to trust a centralized authority or anyone else in the blockchain network. Each node maintains their own copy of the blockchain’s digital ledger and updates it with new blocks after verifying the validity of the transactions contained within a block.
Such a decentralized system needs protections to ensure data authenticity. Otherwise, a malicious user could create fake transactions on behalf of another user, potentially sending money to the attacker’s account.
Blockchain uses digital signatures to provide this authenticity. Every transaction and block is signed using a private key tied to the public key associated with a user’s account on the blockchain. This makes it easy to verify that a particular piece of data originates where it claims.
Blockchain and hash functions
Hash functions are useful for protecting data integrity due to their built-in collision resistance. Two major uses of hash functions in blockchain are the blocks’ “chains” and the Proof of Work consensus algorithm.
The blocks’ chains
The blockchain is named the way it is because its digital ledger is implemented as a collection of blocks chained together. The chains in the blockchain are created using hash functions.
Within the structure of blockchain, each block header in the blockchain contains a hash of the previous block header in the chain. This means that if one block is changed, the headers of every block after it in the blockchain changes as well.
This also shows that a block header contains the root value of a Merkle Tree used to store transactions within a block. Merkle Trees are designed so that every node in the tree’s value is the hash of the value(s) of its child(ren). Changing a single transaction in a block changes the value of every node between it and the root. Due to hash function collision resistance, it is infeasible to find two versions of a Merkle Tree with the same root hash.
This enables hash functions to protect the immutability of the digital ledger. Changing a transaction changes a Merkle Tree root hash, which changes the block header value, which changes the values of the headers of all following blocks. Blockchains are designed to make it so that these changes make the blocks no longer valid, and finding a new, valid version of all of the modified blocks (in order to replace them using the longest chain rule) is difficult.
Proof of Work
Consensus algorithms are how blockchains make this replacement process difficult. Proof of Work is the oldest and most well-known blockchain consensus algorithm. It also happens to make heavy use of hash functions for its security.
In a Proof of Work blockchain, a block header is only considered valid if its hash value is below a certain threshold. Creating a valid block that will be accepted by the rest of the blockchain network requires finding one that contains legitimate transactions and meets this requirement.
Due to hash function collision resistance, it is difficult to find a hash function input that produces a certain output and only a little bit easier to find one that is below a certain threshold. The best method of accomplishing this is a brute-force search.
Proof of Work uses this for its security by making the ability to create new blocks dependent on computational power. The node with the most CPU power can try potential block headers the fastest and is most likely to find the next block. However, CPU power is expensive, making it difficult to buy enough to completely control the block creation process (which is important to blockchain decentralization and security).
Blockchain cryptography: Beyond the basics
Asymmetric cryptography and hash functions are examples of cryptographic algorithms that are used in the core blockchain protocol to provide the basic guarantees of blockchain. However, they are not the only uses of cryptography in blockchain systems. Other algorithms, such as zero-knowledge proofs and ring signatures, are also used to provide additional functionality and guarantees in blockchain systems.
- Collision resistance, Cryptography Wiki
- A Formal Verification Framework for Security Issues of Blockchain Smart Contracts, MDPI
- Longest Chain, Learn Me a Bitcoin