Blockchain
Blockchain has become populate with the recent crypto currencies and the need for trusted distributed ledgers in business transactions.
|
Wikipedia defines it as:
A blockchain, originally block chain, is a growing list of records, called blocks, that are linked using cryptography. Each block contains a cryptographic hash of the previous block, a timestamp, and transaction data (generally represented as a Merkle tree). By design, a blockchain is resistant to modification of the data. It is "an open, distributed ledger that can record transactions between two parties efficiently and in a verifiable and permanent way". For use as a distributed ledger, a blockchain is typically managed by a peer-to-peer network collectively adhering to a protocol for inter-node communication and validating new blocks. Once recorded, the data in any given block cannot be altered retroactively without alteration of all subsequent blocks, which requires consensus of the network majority. Although blockchain records are not unalterable, blockchains may be considered secure by design and exemplify a distributed computing system with high Byzantine fault tolerance. Decentralized consensus has therefore been claimed with a blockchain. |
What does Blockchain do?
- It detects if someone edited the shared data
- It detects if someone deleted from the shared data
- That’s about it… it also puts the documents/records in chronological order (order than they were added to shared database)
- It does this without a central authority, trust in the group: not a single entity.
How does Blockchain work?
Blockchain is a decentralized and distributed digital ledger technology that records transactions across many computers in a way that ensures the security, transparency, and integrity of the data.
Here are the key components and concepts of blockchain:
Blockchain is a decentralized and distributed digital ledger technology that records transactions across many computers in a way that ensures the security, transparency, and integrity of the data.
Here are the key components and concepts of blockchain:
- Blocks: A blockchain is composed of a series of blocks, each containing a list of transactions. Each block includes a timestamp, a reference to the previous block (known as a hash), and the transaction data.
- Chain: The blocks are linked together in a chronological order, forming a chain. Each block references the previous block through its hash, creating a secure and immutable record of all transactions.
- Decentralization: Unlike traditional centralized databases, a blockchain is maintained by a network of computers (nodes) that work together to validate and record transactions. This decentralized nature makes it resistant to single points of failure and enhances security.
- Consensus Mechanisms: To add a new block to the chain, the network must reach a consensus. Common consensus mechanisms include Proof of Work (PoW) and Proof of Stake (PoS). These mechanisms ensure that all nodes agree on the validity of transactions and prevent fraudulent activities.
- Cryptography: Blockchain uses cryptographic techniques to secure transactions and control the creation of new units. Public-key cryptography is often used to create digital signatures, ensuring that transactions are authorized and authentic.
- Immutability: Once a block is added to the chain, it cannot be altered or deleted without altering all subsequent blocks. This immutability ensures the integrity of the transaction history and makes it tamper-proof.
- Smart Contracts: Some blockchains, like Ethereum, support smart contracts—self-executing contracts with the terms directly written into code. These contracts automatically enforce and execute the terms of an agreement when certain conditions are met.
- Applications: Blockchain technology has a wide range of applications beyond cryptocurrencies like Bitcoin. It is used in supply chain management, finance, healthcare, voting systems, identity verification, and more.
Blockchain Use Cases
The list of Blockchain applications is endless but the following are some examples of the more prominent use cases.
The list of Blockchain applications is endless but the following are some examples of the more prominent use cases.
- Financial Services
- Cross Border Payments
- Smart Contracts
- Decentralized Finance
- Supply Chain Management
- Real-time Tracking
- Enhanced Transparency
- Fraud Prevention
- Healthcare
- Efficient Data Sharing
- Secure Patient Records
- Drug Traceability
- Real Estate
- Smart Contracts - Purchases and Leasing
- Reduced Fraud
- Transparent Transactions
- Voting Systems
- Increased voter participation
- Reduced Fraud
- Transparent Transactions
- Intellectual Property
- Royalty Tracking
- Proof of Ownership
- Prevent Unauthorized Use
Bitcoin
Bitcoin is a digital currency, also known as a cryptocurrency, created by an unknown person or group of people using the pseudonym Satoshi Nakamoto. It was introduced in 2008 and released as open-source software in 2009. Bitcoin operates without a central authority, such as a government or financial institution, and relies on a decentralized network of computers.
How Bitcoin Works
Bitcoin is a digital currency, also known as a cryptocurrency, created by an unknown person or group of people using the pseudonym Satoshi Nakamoto. It was introduced in 2008 and released as open-source software in 2009. Bitcoin operates without a central authority, such as a government or financial institution, and relies on a decentralized network of computers.
How Bitcoin Works
- Decentralization: Bitcoin operates on a decentralized network of computers called nodes. These nodes are distributed globally and maintain a copy of the blockchain, which is a public ledger of all transactions.
- Blockchain: The blockchain is a chain of blocks, where each block contains a list of transactions. These blocks are linked together in chronological order, creating a secure and immutable record of all transactions. Once a block is added to the blockchain, it cannot be altered without altering all subsequent blocks, which requires consensus from the network.
- Mining: Mining is the process by which new bitcoins are created and transactions are confirmed. Miners use powerful computers to solve complex mathematical problems, which validate transactions and add new blocks to the blockchain. For their efforts, miners are rewarded with newly created bitcoins and transaction fees.
- Transactions: Bitcoin transactions involve sending bitcoins from one address (a unique identifier) to another. These transactions are verified by miners and recorded on the blockchain. Each transaction is secured using cryptographic algorithms, ensuring the integrity and authenticity of the data.
- Wallets: A Bitcoin wallet is a digital tool that allows users to store, send, and receive bitcoins. Wallets contain private keys, which are secret codes that enable the owner to access and manage their bitcoins. There are various types of wallets, including hardware wallets, software wallets, and paper wallets.
- Security: Bitcoin transactions are secured through cryptographic techniques, such as public and private key cryptography. The network also relies on consensus mechanisms, such as proof-of-work (PoW), to ensure that all participants agree on the state of the blockchain.
Supply Chain Management Example
Scenario: Tracking the Journey of Coffee Beans from Farm to Consumer
Scenario: Tracking the Journey of Coffee Beans from Farm to Consumer
- Farm (Origin):
- A coffee farmer harvests coffee beans and records the details of the harvest on the blockchain. This includes information like the date of harvest, the type of coffee beans, and the location of the farm.
- The farmer creates a new block containing this data. This block is then added to the blockchain, ensuring that the origin and initial details of the coffee beans are recorded immutably.
- Processing Plant:
- The coffee beans are transported to a processing plant. Upon arrival, the processing plant records details of the beans' condition, the processing methods used, and the date of processing on the blockchain.
- A new block is created with this information and added to the blockchain, linking it to the previous block that recorded the farm's data.
- Transportation:
- The processed coffee beans are then transported to a packaging facility. Each stage of transportation is recorded on the blockchain, including the carrier details, transit times, and any environmental conditions during transit (e.g., temperature and humidity).
- Blocks are added at each stage, creating a detailed and immutable record of the coffee beans' journey.
- Packaging Facility:
- At the packaging facility, the coffee beans are packaged into consumer-ready products. The details of the packaging process, including the packaging date and batch numbers, are recorded on the blockchain.
- This information is added as a new block, continuing the chain.
- Distribution:
- The packaged coffee is then distributed to retailers. Each step of the distribution process is recorded on the blockchain, ensuring transparency and traceability. This includes the distributor's details, delivery dates, and any intermediary storage locations.
- Additional blocks are added to the blockchain, maintaining the chain of custody.
- Retail and Consumer:
- Finally, the coffee reaches the retailer, where it is sold to consumers. The retailer can scan a QR code on the packaging, which links to the blockchain and provides consumers with the entire history of the coffee beans, from farm to cup.
- This final stage is recorded on the blockchain, completing the journey.
- Transparency: Consumers can verify the authenticity and quality of the coffee they purchase by accessing the complete history on the blockchain.
- Traceability: Any issues or recalls can be efficiently managed by tracing the exact journey and handling of the coffee beans.
- Security: The immutable nature of the blockchain ensures that records cannot be tampered with, enhancing trust among all parties involved.
Simple Block Chain Example:
With the following bash script, we can generate a simplistic block chain ledger. In this example, the value of the string and sequence creates a hash value that is then stored.
#!/bin/bash
for i in `seq 1 10032`
do
echo $1$i ":" `echo $1$i | sha256sum`
done
$ ./block_chain.bash hello
hello1 : 8d678c54ff53cac1efd6d62697aeb5a005491cd04b83228fd8411ba9f02b98e7 *-
hello2 : 167112362adb3b2041c11f7337437872f9d821e57e8c3edd68d87a1d0babd0f5 *-
hello3 : d14f73ffe9efb30f7e7ca5bda314561e07c1e2bb94e2692f9979b2bbe19de341 *-
hello4 : a6f961466f137118d0c7b1e0454abb88480df2bcf7ab40e6c5c2f1e25e0cfa6c *-
In practice, Block Chain is more complex as it relies on decentralized databases with voting rights to ensure that the majority 'rule' and data is not corrupted. This concept forms the basis for the BitCoin ecosystem.
I have created a simple block chain python program that allows the user to create a 'database', add records, and then show the records. It lacks other features such as support for multiple servers - but gives the user a view of what block chain is.
BlockChain Sample Programs: github.com/douglaskruger/Coding-Python/tree/main/Block%20Chain
The following is the output of this program "BlockChain-2.py" with 5 records automatically created with the script and two additional data elements created with my feedback.
Menu:
1 - Initialize database
2 - Add blockchain record
3 - Read blockchain records and print to screen
0 - Exit
Enter your choice: 3
Index: 0
Previous Hash: 0
Timestamp: 1721371461.0646932
Data: Genesis Block
Hash: ba2e5c379efda37bf1ac20911d2f112adf248fb08eb6a4d5e6884e7318a4fca7
Index: 1
Previous Hash: ba2e5c379efda37bf1ac20911d2f112adf248fb08eb6a4d5e6884e7318a4fca7
Timestamp: 1721371461.074017
Data: Block #1 data
Hash: 26bf346736c1d2e72f86d1a3beec4fdbb9a77d461dc21b32690ce7eed55b3d32
Index: 2
Previous Hash: 26bf346736c1d2e72f86d1a3beec4fdbb9a77d461dc21b32690ce7eed55b3d32
Timestamp: 1721371461.0826778
Data: Block #2 data
Hash: 47e714aaa42bcad7b9951b1d26f7bae5b0ffb64bd8192fadd06652d43b52bce6
Index: 3
Previous Hash: 47e714aaa42bcad7b9951b1d26f7bae5b0ffb64bd8192fadd06652d43b52bce6
Timestamp: 1721371461.092661
Data: Block #3 data
Hash: fbaf7fe1557fd4b176651599d507e541a0172a1e00fd17ebab3bc68e2dd9eea3
Index: 4
Previous Hash: fbaf7fe1557fd4b176651599d507e541a0172a1e00fd17ebab3bc68e2dd9eea3
Timestamp: 1721371461.1026502
Data: Block #4 data
Hash: 417ecb103e8e1917cffdd7ec777927dab6a79eca0e119ccfea16ad0cce6dd265
Index: 5
Previous Hash: 417ecb103e8e1917cffdd7ec777927dab6a79eca0e119ccfea16ad0cce6dd265
Timestamp: 1721371461.1133087
Data: Block #5 data
Hash: 3aa041cedb7197a34cd088b57e4a7ffb8b8d3916aadb03f27bc90391fd4f0a3f
Index: 6
Previous Hash: 3aa041cedb7197a34cd088b57e4a7ffb8b8d3916aadb03f27bc90391fd4f0a3f
Timestamp: 1721374201.9926949
Data: my data
Hash: a2f91cd1bfaabdeb18aab21a08de599f5e254e7aaf1336b0d299b5dde4c7cb87
With the following bash script, we can generate a simplistic block chain ledger. In this example, the value of the string and sequence creates a hash value that is then stored.
#!/bin/bash
for i in `seq 1 10032`
do
echo $1$i ":" `echo $1$i | sha256sum`
done
$ ./block_chain.bash hello
hello1 : 8d678c54ff53cac1efd6d62697aeb5a005491cd04b83228fd8411ba9f02b98e7 *-
hello2 : 167112362adb3b2041c11f7337437872f9d821e57e8c3edd68d87a1d0babd0f5 *-
hello3 : d14f73ffe9efb30f7e7ca5bda314561e07c1e2bb94e2692f9979b2bbe19de341 *-
hello4 : a6f961466f137118d0c7b1e0454abb88480df2bcf7ab40e6c5c2f1e25e0cfa6c *-
In practice, Block Chain is more complex as it relies on decentralized databases with voting rights to ensure that the majority 'rule' and data is not corrupted. This concept forms the basis for the BitCoin ecosystem.
I have created a simple block chain python program that allows the user to create a 'database', add records, and then show the records. It lacks other features such as support for multiple servers - but gives the user a view of what block chain is.
BlockChain Sample Programs: github.com/douglaskruger/Coding-Python/tree/main/Block%20Chain
The following is the output of this program "BlockChain-2.py" with 5 records automatically created with the script and two additional data elements created with my feedback.
Menu:
1 - Initialize database
2 - Add blockchain record
3 - Read blockchain records and print to screen
0 - Exit
Enter your choice: 3
Index: 0
Previous Hash: 0
Timestamp: 1721371461.0646932
Data: Genesis Block
Hash: ba2e5c379efda37bf1ac20911d2f112adf248fb08eb6a4d5e6884e7318a4fca7
Index: 1
Previous Hash: ba2e5c379efda37bf1ac20911d2f112adf248fb08eb6a4d5e6884e7318a4fca7
Timestamp: 1721371461.074017
Data: Block #1 data
Hash: 26bf346736c1d2e72f86d1a3beec4fdbb9a77d461dc21b32690ce7eed55b3d32
Index: 2
Previous Hash: 26bf346736c1d2e72f86d1a3beec4fdbb9a77d461dc21b32690ce7eed55b3d32
Timestamp: 1721371461.0826778
Data: Block #2 data
Hash: 47e714aaa42bcad7b9951b1d26f7bae5b0ffb64bd8192fadd06652d43b52bce6
Index: 3
Previous Hash: 47e714aaa42bcad7b9951b1d26f7bae5b0ffb64bd8192fadd06652d43b52bce6
Timestamp: 1721371461.092661
Data: Block #3 data
Hash: fbaf7fe1557fd4b176651599d507e541a0172a1e00fd17ebab3bc68e2dd9eea3
Index: 4
Previous Hash: fbaf7fe1557fd4b176651599d507e541a0172a1e00fd17ebab3bc68e2dd9eea3
Timestamp: 1721371461.1026502
Data: Block #4 data
Hash: 417ecb103e8e1917cffdd7ec777927dab6a79eca0e119ccfea16ad0cce6dd265
Index: 5
Previous Hash: 417ecb103e8e1917cffdd7ec777927dab6a79eca0e119ccfea16ad0cce6dd265
Timestamp: 1721371461.1133087
Data: Block #5 data
Hash: 3aa041cedb7197a34cd088b57e4a7ffb8b8d3916aadb03f27bc90391fd4f0a3f
Index: 6
Previous Hash: 3aa041cedb7197a34cd088b57e4a7ffb8b8d3916aadb03f27bc90391fd4f0a3f
Timestamp: 1721374201.9926949
Data: my data
Hash: a2f91cd1bfaabdeb18aab21a08de599f5e254e7aaf1336b0d299b5dde4c7cb87