0% found this document useful (0 votes)
30 views

Unit 2 Notes

it is useful for all

Uploaded by

jagadiish21
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Unit 2 Notes

it is useful for all

Uploaded by

jagadiish21
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

UNIT II BITCOIN AND CRYPTOCURRENCY

A basic crypto currency, Creation of coins, Payments and double spending, FORTH – the precursor
for Bitcoin scripting, Bitcoin Scripts, Bitcoin P2P Network, Transaction in Bitcoin Network, Block
Mining, Block propagation and block relay
A basic crypto currency
A basic cryptocurrency is a digital or virtual currency that uses cryptography for
security and operates on a decentralized network, typically a blockchain. It is designed to
function as a medium of exchange, allowing users to securely send and receive transactions
without the need for intermediaries like banks.
The most well-known and widely used basic cryptocurrency is Bitcoin, which was
created in 2009 by an anonymous individual or group of individuals using the pseudonym
Satoshi Nakamoto. Bitcoin introduced the concept of a decentralized digital currency, built on
a blockchain that enables secure, transparent, and peer-to-peer transactions.
How To Create Your Own Cryptocurrency: Step-by-Step
Coins in a cryptocurrency are typically created through mining, staking, or predetermined
issuance rules defined by the protocol.
 Mining: Miners compete to solve complex mathematical puzzles through
computational power, validating transactions and adding new blocks to the
blockchain. Successful miners are rewarded with newly created coins as a
mining reward.
 Staking: In some cryptocurrencies, coins can be created through a staking
mechanism where users lock their coins as collateral to participate in the
network's consensus. Validators are chosen based on their stake and earn
rewards by creating new blocks or validating transactions.
 Predetermined Issuance: Some cryptocurrencies have predetermined issuance
rules that define the total supply, issuance rate, and distribution mechanism of
coins. For example, a fixed number of coins may be distributed during an initial
coin offering (ICO) or token generation event (TGE).
Step 1: Research the Use Cases
Before you start building, figure out the following as we covered earlier: What are your use
case and unique selling proposition (USP)? What problem does your crypto solve? What
benefits will it offer to potential users? Is any other chain already doing it, and if so, can you
do it better?
Creating a new crypto asset is no different from launching a new startup business in many
ways, and the same planning is required to garner enough hype, something that the new
generation of NFT founders is becoming very adept at. Do a lot of marketing analysis and
research in order to boost your chances of achieving real product/market fit.
Knowing what problem your token solves will also help you identify a responsive target
audience and create a highly targeted marketing plan post-launch.
Step 2: Choose a Consensus Mechanism
Choose a mechanism that aligns with your goals and requirements, such as computation-
intensive Proof of Work or energy-efficient Proof of Stake. Some mechanisms are very
innovative, such as Solana’s Proof of History (PoH), but can come with other problems.
Step 3: Select a Blockchain Platform
Choose a blockchain platform to host your token. Ethereum and Binance Smart Chain are
popular choices, but there are many other options to consider. Consider factors such as cost,
scalability and security when making your decision.
Step 4: Publish the Whitepaper on Your Website and Social Media
With steps 1 to 3 behind you, you should really understand what you’re trying to build inside
out by now. It’s time to put all this information together in your own manifesto. Research
successful launches by other chains and figure out what they did right and wrong. Compare
their post-launch results with their tokenomics and network emissions. Create your own
tokenomics structure in response. Now, write your whitepaper and publish it on your website.
Then share it far and wide.
Step 5: Design the Nodes
Nodes are the building blocks of a blockchain that store and verify your transactions.
Get the necessary hardware such as processors, memory, and disk size if it’s required.
Step 5: Establish Your Blockchain's Internal Architecture
Now, create your blockchain's internal architecture and its rules and parameters, such as
address and public/private key formats, permissions and how the crypto asset will be issued.
Be sure to carefully consider these factors as they cannot be changed without a software
upgrade once the platform is running.
Step 6: Create Your Coin or Token
Now, it’s finally time to create your crypto asset. If you’re going the ERC20 route, you can
take an online course first and use one of many free online tools, but be sure to do thorough
research first. Make sure the platform can be trusted and is capable enough, in order to avoid
malicious code and scams. Alternatively, hire a blockchain developer with good ratings on a
crowdsourcing freelancer site if you can afford it.
Step 7: Design the API and User Interface (UI)
Next, design a user-friendly interface to help your blockchain communicate with its
participants. Depending on its complexity, you may need web, mail and FTP servers, external
databases, and front-end programming languages, such as HTML5, CSS, PHP, C++, Java,
Javascript, or Python.
Step 8: Promote Your Crypto and Build a Community
OK, proud new parent, it’s time to spread the word about the newly chosen one to build their
devoted followership. Reach out to crypto influencers (but not pump-and-dump shillers!), find
a partner IDO launchpad or exchange to list your asset, develop a campaign, do airdrops if
viable, and participate in relevant online communities and forums. If you’re in the US,
understand what the Howey Test is to avoid securities-related legal issues later.
Payments in Cryptocurrency
 Cryptocurrency payments involve the transfer of coins or tokens from one digital wallet
to another.
 Each user has a unique digital wallet address, which is a cryptographic representation
of their account.
 To make a payment, the sender specifies the recipient's wallet address, the amount to
be sent, and possibly other optional details.
 The transaction is broadcasted to the network and validated by miners or validators,
ensuring that the sender has sufficient funds and the transaction is valid.
 Once the transaction is confirmed and added to the blockchain, the recipient's wallet
balance is updated, reflecting the received funds.
 Cryptocurrency payments offer advantages such as faster cross-border transactions,
lower fees compared to traditional payment systems, and increased privacy.
Payment in cryptocurrency involves the transfer of digital coins or tokens from one party to
another in a secure and decentralized manner. Here is an elaboration on the process of making
payments in cryptocurrency:
Wallets:
To engage in cryptocurrency payments, users need a digital wallet. Wallets can be software-
based (desktop, mobile, or web) or hardware devices designed to securely store private keys.
Wallets generate unique addresses for each user, which are used as the destination for receiving
payments.
Address Generation:
The recipient shares their cryptocurrency wallet address with the sender. This address is a long
string of alphanumeric characters that serves as the destination for the payment.
Transaction Initiation:
The sender creates a transaction specifying the recipient's wallet address, the amount of
cryptocurrency to send, and any additional transaction details required by the cryptocurrency
protocol.
Transaction Broadcast:
The sender broadcasts the transaction to the cryptocurrency network. This involves sharing the
transaction information with nodes in the network, which then propagate it to other nodes.
Transaction Validation:
Miners or validators in the network validate the transaction by confirming that the sender has
sufficient funds, the transaction is properly signed, and it adheres to the consensus rules of the
cryptocurrency network. The validation process varies depending on the consensus mechanism
employed, such as Proof-of-Work (PoW) or Proof-of-Stake (PoS).
Inclusion in a Block:
Once the transaction is validated, it waits to be included in a block. Miners or validators
compete to add the transaction to a block by solving cryptographic puzzles or following
consensus rules.The transaction is typically added to the blockchain as part of a block
containing other validated transactions.
Confirmation:
As subsequent blocks are added to the blockchain, the transaction gains confirmations,
indicating that it is increasingly secure and less likely to be reversed or double-spent. The
number of confirmations required for a transaction to be considered finalized varies depending
on the cryptocurrency. In Bitcoin, for example, it is common to wait for six or more
confirmations.
Payment Finalization:
Once the transaction is confirmed and added to the blockchain, the recipient's wallet balance is
updated to reflect the received funds. The recipient can then use the received cryptocurrency
for further transactions, hold it as an investment, or convert it to another currency as desired.
Double spending
Double spending means spending the same money twice. Double spending is a potential
vulnerability in digital currency systems where a user spends the same amount of
cryptocurrency more than once. It occurs when someone attempts to use the same funds for
multiple transactions, taking advantage of the digital nature of the currency and attempting to
deceive the network participants.
How Does Double Spending Happen?
Double spending can never arise physically. It can happen in online transactions. This mostly
occurs when there is no authority to verify the transaction. It can also happen if the user’s
wallet is not secured. Suppose a user wants to avail of services from Merchant ‘A’ and
Merchant ‘B’.
 The user first made a digital transaction with Merchant ‘A’.
 The copy of the cryptocurrency is stored on the user’s computer.
 So the user uses the same cryptocurrency to pay Merchant ‘B’
 Now both the merchants have the illusion that the money has been credited since the
transactions were not confirmed by the miners.
 This is the case of double spending.
Example: Suppose a user has 1 BTC. He/She wants to avail of services from merchant A and
merchant B. The user creates multiple copies of the same BTC and stores it. The user first sends
the original BTC to Merchant A and gets the service. Simultaneously, the user sends the copied
version of 1 BTC to Merchant B. Since the second transaction was not confirmed by other
miners, the merchant accepts the bitcoin and sends the service. But the cryptocurrency that was
sent is invalid. This is the case of Double Spending.

Types of Double Spending Attacks

There are different types of Double Spending attacks:


 Finney Attack: Finney Attack is a type of Double spending Attack. In this, a merchant
accepts an unauthorized transaction. The original block is eclipsed by the hacker using an
eclipse attack. The transaction is performed on an unauthorized one. After that, the real
block shows up and again the transaction is done automatically for the real block. Thus the
merchant loses money two times.
 Race attack: is an attack in which there is a ‘race’ between two transactions. The attacker
sends the same money using different machines to two different merchants. The merchants
send their goods but transactions get invalid.
 51% Attack: This type of attack is prevalent in small blockchains. Hackers usually take
over 51% of the mining power of blockchain and therefore can do anything of their own
will.

How Bitcoin Handles Double Spending?

Bitcoin is one of the most popular blockchains. To combat Double spending it uses some
security measures. There are two types of examples of double spending in BTC.

1. The first case is making duplicates of the same bitcoin and sending it to multiple users.
2. The second case is performing the transaction and reversing the already sent transaction
after getting the service.

To tackle these double-spending issues, some security measures are taken. They are:
 Validation: Validation of transactions by a maximum number of nodes in the network.
Once a block is created, it is added to a list of pending transactions. Users send validation
for the block. If the verifications are done then only the block is added to the blockchain.
 Timestamp: The confirmed transactions are timestamped, therefore they are irreversible.
If a transaction is involved with a bitcoin it is verified and done. But in the future, if other
transactions are made with the same bitcoin, the transactions will be canceled.
 Block Confirmations: Merchants get block confirmations so that they are assured that
there was no case of double spending. In bitcoin, a minimum of 6 confirmations are done.
 Saving copies: A copy of each transaction is kept at each node so in case of network failure
the whole network does not go down.

These security features have reduced double spending to a large extent. Let us discuss a detailed
example of how bitcoin handles double-spending.
 A user wants to spend 2 BTC. He/She can create multiple copies of the same
cryptocurrency.
 The user can send the same cryptocurrency to two different addresses say ‘Bob’ and
‘Alice’.
 Both of these transactions are sent to the pool of unconfirmed transactions.
 The first transaction T1 would be approved via the confirmation mechanism.
 The confirmation mechanism states that a minimum of six confirmations by miners should
be done for block validation. The block is added to the network.
 However, the second transaction T2 didn’t get sufficient confirmation so it would be
recognized as invalid by the confirmation process. The block with the highest number of
confirmations is accepted and the other one is rejected. So transaction T1 is valid, and Alice
received the bitcoin.
Solutions To Prevent Double Spending

Double Spending can be prevented using two approaches: Centralized and Decentralized
 Centralized Approach: In this case, a secured third party is employed to verify the
transactions. The third-party can track each of the user’s balances. Suppose a user makes a
transaction. The third-party identifies the transaction with a unique identity. Then it verifies
the transaction and allows the transaction. The problem is that suppose we want to make
transactions with other countries where a third party is not required. So in such cases,
decentralized systems come into play. another drawback is if the whole system fails, the
users cannot have access.
 Decentralized Approach: This approach is used by Bitcoin. In this, there is no
involvement of central authority. Each transaction is verified using powerful algorithms.
The decentralized approach proved to be more secure than the centralized approach.
Protocols are established and each protocol does its job at each step. Therefore this also
promotes transparency.

How to Combat Double Spending?

Double spending has been minimized to a large extent as companies are using many security
features. But we as users also have some responsibility so that such attacks don’t happen.
 Any user should wait for a minimum of six confirmations of the transaction before
performing another transaction. In the blockchain, more the confirmations by different
users, lesser will be double spending attacks.
 Users should keep their hardware resources safe so that hackers do not misuse them for
their own purposes. Often hackers target the hardware part because the hardware is costly.
If they somehow steal the hardware, they can roll back any transaction or alter information.
 Users should delete spam mails and avoid phishing to avoid unnecessary malware attacks
Phishing is a very common attack by hackers as hackers target login credentials.
 Software should be updated regularly with the latest antivirus installed. If the software is
not up to date then the bugs present can cause major damage.
FORTH – the precursor for Bitcoin scripting
FORTH is a programming language that influenced the scripting language used in
Bitcoin. FORTH is a stack-based, extensible programming language developed by Charles H.
Moore in the 1970s. It is known for its simplicity, efficiency, and the use of a stack to
manipulate data. FORTH programs are composed of a series of words (functions) that operate
on a stack of data elements. Bitcoin's scripting language, on the other hand, is a custom
scripting system designed specifically for Bitcoin's transaction processing and smart contract
capabilities. It is a minimalistic and intentionally limited scripting language that enables the
implementation of conditions and constraints for spending bitcoins. While both FORTH and
Bitcoin's scripting language have stack-based execution models in common, they are distinct
and unrelated.
Bitcoin scripts
Bitcoin scripts are a fundamental component of the Bitcoin protocol that enable the creation of
conditions and constraints for spending bitcoins. They are written in a simple scripting
language specifically designed for Bitcoin.
Script is a mini programming language used as a locking mechanism for outputs. A locking
script is placed on every output. An unlocking script must be provided to unlock an output (i.e.
when you’re using it as an input). If a full script (unlocking + locking) is valid, the output is
“unlocked” and can be spent. There are two parts to every transaction – a key (to unlock your
box) and a lock.
Script is a very basic programming language. It consists of two types of things:
 Data - For example; public keys and signatures.
 OPCODES - Simple functions that operate on the data.
The cheques (coins) you hold are called unspent transaction outputs (UTXOs). The funds can
be used by anyone that can provide the key that fits the lock. Specifically, the key is the
scriptSig and the lock is the scriptPubKey.
Pay-to-Pubkey (P2PK) is type of Bitcoin script. P2PK script step by step:
1. Script Initialization:
The sender (Alice) initiates a Bitcoin transaction and specifies the recipient (Bob) and
the amount of bitcoins to send.
2. Recipient's Public Key:
Bob generates a public-private key pair. His public key is a cryptographic
representation of his identity and is derived from his private key.
3. Locking Script (Output Script):
Bob's locking script is created and included in the output section of the transaction. The
P2PK script typically takes the following structure:

When the script runs, the CHECKSIG opcode compares the signature against the public
key, and pushes a 1 on to the stack if it is valid.
Example
<Bob's public key> OP_CHECKSIG
<Bob's public key> is the actual public key associated with Bob's identity.
OP_CHECKSIG is an opcode that verifies the digital signature using Bob's public key.
4. Funding the Transaction:
Alice funds the transaction by referencing an unspent output (UTXO) from a previous
transaction. This UTXO must be associated with an output script that matches Bob's
locking script (P2PK).
5. Unlocking Script (Input Script):
To spend the funds, Alice creates an unlocking script that satisfies Bob's locking script.
In the case of P2PK, Alice's unlocking script simply includes her digital signature.
Alice's unlocking script typically follows this structure:
<Alice's signature>
6. Transaction Validation:
When the transaction is broadcasted to the network and validated, the unlocking script
(input script) is combined with the locking script (output script) to execute and evaluate
the script. The inputs are pushed onto the stack, and the opcodes are executed in
sequence.
7. Validation Result:
If the script execution completes without errors and the resulting stack is not empty, the
transaction is considered valid. The bitcoins are then transferred from Alice's UTXO to
Bob's address.
It's note that P2PK scripts are less commonly used in Bitcoin transactions due to privacy
concerns. P2PK reveals the full public key of the recipient, potentially exposing more
information than desired. P2PKH, which utilizes a hashed version of the public key, is more
widely used to address these privacy concerns.
Pay-to-Public-Key-Hash (P2PKH) is the most common script type used for regular
transactions in Bitcoin.
The P2PKH script involves the following steps:
1. Script Initialization:
The sender (Alice) initiates a Bitcoin transaction and specifies the recipient (Bob) and
the amount of bitcoins to send.
2. Recipient's Public Key Hash:
Bob generates a public-private key pair. From his public key, he calculates the hash
value, which is known as the public key hash (PKH). This hash serves as an identifier
for Bob's address.
3. Locking Script (Output Script):
Bob's locking script is created and included in the output section of the transaction. It
typically follows this structure:

 The original public key is DUPlicated and then HASH160’ed.


 This hashed value is compared with the hashed public key in the scriptPubKey to make
sure it is EQUALVERIFY.
 If it matches, the script continues and the CHECKSIG checks the signature against the
public key
Example
OP_DUP OP_HASH160 <Bob's PKH> OP_EQUALVERIFY OP_CHECKSIG
OP_DUP duplicates the top stack item (the public key hash).
OP_HASH160 performs a hash operation on the duplicated value.
<Bob's PKH> is the actual public key hash.
OP_EQUALVERIFY compares the hash value with the provided PKH.
OP_CHECKSIG verifies the digital signature using Bob's public key.
4. Funding the Transaction:
Alice funds the transaction by referencing an unspent output (UTXO) from a previous
transaction. This UTXO must be associated with an output script that matches Bob's
locking script (P2PKH).
5. Unlocking Script (Input Script):
To spend the funds, Alice creates an unlocking script that satisfies Bob's locking script.
It usually includes her digital signature and her public key.
Alice's unlocking script typically follows this structure:
<Alice's signature> <Alice's public key>
6. Transaction Validation:
When the transaction is broadcasted to the network and validated, the unlocking script
(input script) is combined with the locking script (output script) to execute and evaluate
the script. The inputs are pushed onto the stack, and the opcodes are executed in
sequence.
7. Validation Result:
If the script execution completes without errors and the resulting stack is not empty, the
transaction is considered valid. The bitcoins are then transferred from Alice's UTXO to
Bob's address.
This example demonstrates the basic process of a P2PKH script in Bitcoin. It involves creating
a locking script with specific conditions (Bob's public key hash) and an unlocking script with
the necessary data (Alice's signature and public key) to satisfy those conditions.
Bitcoin P2P Network
The peer-to-peer architecture of blockchain allows all cryptocurrencies to be transferred
worldwide, without the need of any middle-man or intermediaries or central serverPeer-to-Peer
(P2P) network consists of a group of devices that collectively store and share files. Each
participant (Node) acts as an individual peer. Typically, all nodes have equal power and
perform the same tasks.
How do P2P networks work?
There are no central in peer-to-peer blockchain networks. Instead, all nodes (peers) are
connected to one another. A mesh network with a “flat” topology connects the network nodes
and there is no hierarchy. In a peer-to-peer network, nodes simultaneously give and consume
services with reciprocity serving as the motivation for participation, making P2P networks
open, decentralized and robust by nature. Diagrammatic representation of a peer-to-peer
network
Each node on the network must serve as both a client and a server to other nodes in a P2P
network, making it distinct from a traditional client-server setup. There is always a central
server in a client-server configuration from which the client downloads files. On the contrary,
in a decentralized setup, each node acts as a server that can download files and share them with
other nodes. A node may perform both the sharing and receiving functions concurrently, which
accounts for the P2P network’s speed, security and efficiency. Peer-to-peer systems may be
categorized according to their architecture. The three main types are called unstructured,
structured, and hybrid P2P networks.
Unstructured P2P networks
Unstructured P2P networks don’t present any specific organization of the nodes. The
participants communicate randomly with one another. These systems are considered robust
against high churn activity (i.e., several nodes frequently joining and leaving the network).
Although easier to build, unstructured P2P networks may require higher CPU and memory
usage because search queries are sent out to the highest number of peers possible. This tends
to flood the network with queries, especially if a small number of nodes is offering the desired
content.

Structured P2P networks


In contrast, structured P2P networks present an organized architecture, allowing nodes
to efficiently search for files, even if the content is not widely available. In most cases,
this is achieved through the use of hash functions that facilitate database lookups. While
structured networks may be more efficient, they tend to present higher levels of
centralization, and usually require higher setup and maintenance costs. Other than that,
structured networks are less robust when faced with high rates of churn.
Hybrid P2P networks
Hybrid P2P networks combine the conventional client-server model with some aspects
of the peer-to-peer architecture. For instance, it may design a central server that
facilitates the connection between peers. When compared to the other two types, hybrid
models tend to present improved overall performance. They usually combine some of
the main advantages of each approach, achieving significant degrees of efficiency and
decentralization simultaneously.
The term “bitcoin network” refers to the collection of nodes running the bitcoin P2P protocol.
In addition to the bitcoin P2P protocol, there are other protocols such as Stratum, which are
used for mining and lightweight or mobile wallets. These additional protocols are provided by
gateway routing servers that access the bitcoin network using the bitcoin P2P protocol, and
then extend that network to nodes running other protocols. For example, Stratum servers
connect Stratum mining nodes via the Stratum protocol to the main bitcoin network and bridge
the Stratum protocol to the bitcoin P2P protocol. We use the term “extended bitcoin network”
to refer to the overall network that includes the bitcoin P2P protocol, pool-mining protocols,
the Stratum protocol, and any other related protocols connecting the components of the bitcoin
system.

Nodes Types and Roles


Although nodes in the bitcoin P2P network are equal, they may take on different roles
depending on the functionality they are supporting. A bitcoin node is a collection of functions:
routing, the blockchain database, mining, and wallet services. A full node with all four of these
functions is shown in Figure.

All nodes include the routing function to participate in the network and might include other
functionality. All nodes validate and propagate transactions and blocks, and discover and
maintain connections to peers. In the full-node example in fig, the routing function is indicated
by an orange circle named “Network Routing Node.” Some nodes, called full nodes, also
maintain a complete and up-to-date copy of the blockchain. Full nodes can autonomously and
authoritatively verify any transaction without external reference. Some nodes maintain only a
subset of the blockchain and verify transactions using a method called simplified payment
verification, or SPV. These nodes are known as SPV or lightweight nodes. In the full-node
example in the figure, the full-node blockchain database function is indicated by a blue circle
named “Full Blockchain.” In Figure 6-3, SPV nodes are drawn without the blue circle, showing
that they do not have a full copy of the blockchain.

Mining nodes compete to create new blocks by running specialized hardware to solve the
proof-of-work algorithm. Some mining nodes are also full nodes, maintaining a full copy of
the blockchain, while others are lightweight nodes participating in pool mining and depending
on a pool server to maintain a full node. The mining function is shown in the full node as a
black circle named “Miner.” User wallets might be part of a full node, as is usually the case
with desktop bitcoin clients. Increasingly, many user wallets, especially those running on
resource-constrained devices such as smartphones, are SPV nodes. The wallet function is
shown in Figure 6-1 as a green circle named “Wallet”.

In addition to the main node types on the bitcoin P2P protocol, there are servers and nodes
running other protocols, such as specialized mining pool protocols and lightweight client-
access protocols.
Figure shows the most common node types on the extended bitcoin network.
The Extended Bitcoin Network
The main bitcoin network, running the bitcoin P2P protocol, consists of between 7,000 and
10,000 listening nodes running various versions of the bitcoin reference client (Bitcoin Core)
and a few hundred nodes running various other implementations of the bitcoin P2P protocol,
such as BitcoinJ, Libbitcoin, and btcd. A small percentage of the nodes on the bitcoin P2P
network are also mining nodes, competing in the mining process, validating transactions, and
creating new blocks. Various large companies interface with the bitcoin network by running
full-node clients based on the Bitcoin Core client, with full copies of the blockchain and a
network node, but without mining or wallet functions. These nodes act as network edge routers,
allowing various other services (exchanges, wallets, block explorers, merchant payment
processing) to be built on top. The extended bitcoin network includes the network running the
bitcoin P2P protocol, described earlier, as well as nodes running specialized protocols.
Attached to the main bitcoin P2P network are a number of pool servers and protocol gateways
that connect nodes running other protocols. These other protocol nodes are mostly pool mining
nodes and lightweight wallet clients, which do not carry a full copy of the blockchain. Figure
shows the extended bitcoin network with the various types of nodes, gateway servers, edge
routers, and wallet clients and the various protocols they use to connect to each other.
Transaction in Bitcoin Network
A sample bitcoin transaction
X PERSON wants to send some bitcoin to Y PERSON. Essentially, a BTC transaction is
consist of three parts:
 An input:
This is a record of the BTC address from which X initially received the bitcoin he wants
to send to Y.
 An amount:
This is the specific amount of BTC X wants to send Y.
 An output:
This is Y's public key; also known as his 'bitcoin address'
How does a bitcoin transaction work?
 Sending BTC requires having access to the public and private keys associated with that
amount of bitcoin.
 When talk about someone "having bitcoins", what actually mean is that person has
access to a key-pair consist of:
1. A public key to which some amount bitcoin was previously sent.
2. The corresponding unique private key which authorizes the BTC previously sent to the
above pub-key to be sent elsewhere.
Public keys, also called a bitcoin addresses, are random sequences of letters and numbers that
function similarly to an email address or a social-media site username. They are public so it is
safe sharing it with others.
In fact, you must give your Bitcoin address to others whenever you want them to send you
BTC. The private key is another sequence of letters and numbers. However, private keys—
like passwords to email or other accounts, are to be kept secret. In our example transaction
above, X wants to send some BTC to Y.
To do this, he uses his private key to sign a message with the transaction-specific details. This
message is then sent to the block chain and contains an:
input:
The source transaction of the coins previously sent to X's address
amount:
Some amount of BTC to be sent from X to Y
output:
Y’s public address.
This transaction is then broadcast to the Bitcoin network where miners verify that X's keys are
able to access the inputs (i.e. the address(s) from where he previously received BTC) he claims
to control. This confirmation process is known as mining because it requires resource-intensive
computational labor and rewards miners, in BTC, per block solved. This is also the process by
which new Bitcoins are 'created'.
Why do some bitcoin transaction confirmations take so long?
 All Bitcoin transactions must be verified by miners on the blockchain.
 Note, miners do not mine transactions; they mine blocks which are collections of
transactions.
 Sometimes your transaction gets left out of the current block and gets put on hold until
the next one is assembled.
 The Bitcoin protocol dynamically adjusts requirements to have each block take
approximately 10 minutes to mine.
 Another reason for long confirmation times is that blocks are limited to 1MB by the
current Bitcoin protocol.
 This arbitrary limit can be increased but for the present it limits the amount of
transactions that may enter a block which effectively slows down confirmation times
and by extension, the entire Bitcoin network.
The process of a transaction in the Bitcoin network step by step:
1. Transaction Initiation:
A user (Alice) initiates a Bitcoin transaction from her wallet software or application.
In the transaction, Alice specifies the recipient's Bitcoin address (Bob), the amount of
bitcoins she wants to send, and any additional data required by the transaction.
2. Digital Signature:
To prove ownership of the bitcoins she wants to send, Alice uses her private key to create
a digital signature for the transaction.
The digital signature is a mathematical cryptographic proof that ensures only the owner of
the private key can initiate the transaction.
3. Transaction Broadcasting:
Once the transaction is created and digitally signed, Alice's wallet broadcasts it to the
Bitcoin network.
The transaction is sent to Alice's connected nodes, which act as relays and propagate the
transaction to their respective connected peers.
4. Transaction Propagation:
As the transaction spreads across the network, each node validates the transaction's basic
structure and cryptographic signature to ensure it is not tampered with and that Alice is
the rightful owner of the bitcoins being spent.
5. Mempool Inclusion:
Valid transactions are temporarily stored in the mempool (short for "memory pool"),
which is a pool of unconfirmed transactions waiting to be included in a block.
The mempool is a buffer zone where miners select transactions to include in the next
block they are trying to mine.
6. Confirmation and Inclusion in a Block:
Miners compete to add the next block to the blockchain by solving a complex
mathematical puzzle known as Proof-of-Work (PoW).
The first miner to solve the PoW puzzle gets the right to create the next block and
includes a set of valid transactions from the mempool into the block.
Alice's transaction, along with other valid transactions, is included in the new block.
7. Block Validation and Consensus:
Nodes in the network validate the new block's contents, ensuring that all transactions
inside it are valid, and it follows the rules of the Bitcoin protocol.
If the block is valid, nodes add it to their copy of the blockchain.
8. Confirmation and Finality:
The transaction is considered confirmed once the block containing it is added to the
blockchain.
As more blocks are added to the blockchain, the transaction becomes more secure and
unlikely to be reversed or double-spent.
9. Transaction Completion:
The recipient (Bob) can now see the confirmed transaction in his wallet and has access to
the received bitcoins.
The transaction is complete, and the bitcoins are now under Bob's control.
Block Mining
A peer-to-peer computer process, Blockchain mining is used to secure and verify bitcoin
transactions. Mining involves Blockchain miners who add bitcoin transaction data to Bitcoin’s
global public ledger of past transactions. In the ledgers, blocks are secured by Blockchain miners
and /are connected to each other forming a chain.
There are two ways to mine bitcoins.
1. Mining bitcoins on cloud
2. Mining bitcoins on your own
Mining Bitcoins on Cloud
 Obtain a bitcoin wallet: Bitcoins are stored in digital wallets in an encrypted manner.
This will keep your bitcoins safe.
 Secure the wallet: Since there is no ownership on bitcoins, anyone who gains access to
your wallet can use it without any restriction. So, enable two-factor authentication and
store the wallet on a computer that does not have access to the Internet or store it in an
external device.
 Choose a cloud mining service provider: Cloud mining service providers allow users to
rent processing or hashing power to mine bitcoins remotely. Popular cloud mining service
providers are Genesis Mining and HashFlare.
 Choose a cloud mining package: To choose a package, you will need to decide on how
much you are willing to pay and keep your eyes open to the hashing power the package
will offer. Cloud mining companies will mostly envisage the Return on Investment (ROI)
based on the current market value of Bitcoins.
 Pick a mining pool: This is the best shot you can get to earn bitcoins easily. There are
many mining pools which charge a mere 2 percent of your total earnings. Over here, you
will have to create workers which are basically subaccounts that can be used to track your
contributions to the pool.
 Put your earnings in your own secure wallet: Whenever you witness an ROI, simply
withdraw your earnings and put them in your own secure wallet.
Mining Bitcoins on your own:
 Purchase a custom mining hardware: You need to purchase an Application-specific
Integrated Circuit (ASIC) miner to mine bitcoins. While purchasing an ASIC Blockchain
miner, you should consider its efficacy in hashing power and take a note of its pricing
policies.
 Purchase a power supply: Blockchain miners consume a lot of power. So, get a
dependable power supply which is compatible with the ASIC miner that you purchase.
 Obtain a bitcoin wallet: Bitcoins are stored in digital wallets in an encrypted manner.
This will keep your bitcoins safe.
 Secure the wallet: Since there is no ownership on bitcoins, anyone who gains access to
your wallet can use it without any restriction. So, enable two-factor authentication and
store the wallet on a computer that does not have access to the Internet or store it in an
external device.
 Pick a mining pool: This is the best shot you can get to earn bitcoins easily. There are
many mining pools which charge a mere 2 percent of your total earnings. Over here, you
will have to create workers which are basically subaccounts that can be used to track your
contributions to the pool.
1. Connect the power supply to the ASIC Blockchain miner.
2. Connect the ASIC Blockchain miner to your router.
3. Boot up your ASIC miner.
4. Enter your router’s IP address in a web browser.
5. Find ‘connected devices’ in the router miner page.
6. Find your ASIC miner and click on it to display the device information.
7. Copy and paste the IP address of your ASIC miner into your web browser.
8. Log in to the ASIC miner with the default username and password that are ‘Root’
and ‘Root.’
9. Select ‘Miner Configuration’ to set up the miner according to your preferences.
10. Enter the URL, username, and password for your mining pool on the Miner
Configuration page of the ASIC Miner.
11. Click ‘Save and Apply’ to save your credentials for future use.
12. Start mining and in periodic intervals check your profitability.
13. Put your earnings in your own secure wallet: Whenever you witness an ROI,
simply withdraw your earnings and put them in your own secure wallet.
How Does Bitcoin Mining Work:
Blockchain is a decentralized peer-to-peer network that has been hailed as highly secure and
transparent, hence trustworthy. This is because records in the block chain network are secured
using timestamps and cryptographic hash functions in such a way that after being added to the
ledger, it is almost impossible and impractical to alter the transactions. At the core of
blockchain security is the absence of centralized control. Here is a breakdown of what happens
during bitcoin mining.
The Mining Requirements
A bitcoin miner will first select their tools of the trade and set them up. These include:
 Hardware GPU (graphics processing unit), SSD for crypto mining, or ASIC (application-
specific integrated circuit)
 Mining software
 A wallet
 Preferred mining pool (if one chooses pool mining option instead of solo mining)
Once all these are set up and the system fired up, it performs the mining process autonomously.
Any other human involvement comes in the event of system or network failure, power outage,
or regular system maintenance.

Elements of a Bitcoin Transaction


When a transaction is initiated in the bitcoin network, three elements are involved:

 A transaction input
 A transaction output
 The transaction amount
For every transaction input, a bitcoin mining software generates a unique cryptographic hash
puzzle that is difficult to decode. The software then groups the number of transactions required
to form a block into a Merkle tree.
The Merkle Tree and the SHA-256 Algorithm
A Merkle tree is a data structure of the hashes in a block and acts as a summary of all the
transactions in the block. In the Merkle tree, hashes of individual transactions known as
transaction IDs are paired repeatedly using the SHA-256 algorithm until only one hash
identifies the entire tree. This hash is known as the Merkle root or root hash. The Merkle tree
enables the efficient verification of transactions in the bitcoin network.

The Block Header

The Merkle root, the identifier of a Merkle tree, is stored in the block header. The block
header contains information about the block and includes the following components:

 The version number of the bitcoin software

 The hash of the previous block

 The Merkle root (root hash)

 Timestamp

 Cryptographic nonce

 The target

This is the information miners will use to solve the hash puzzle and add a block transaction.

Solving the Hash Puzzle

Miners must solve the hash puzzle by finding the hash below a given target through the
difficulty requirement. The target, stored in the header, is expressed as a 67-digit number that
will determine the mining difficulty based on the number of miners competing to solve a hash
function. It is important to note that this difficulty adjusts after every 2016 blocks are created
depending on how much time it took miners in the previous 2016 blocks to solve an equation.
This also helps to maintain the rate at which transactions are appended in the blockchain at 10
minutes.

To solve the hash puzzle, miners will try to calculate the hash of a block by adding a nonce to
the block header repeatedly until the hash value yielded is less than the target. Once a mining
computer solves the puzzle, a new block is successfully created that is validated in the Bitcoin
network after a consensus between the nodes has been reached. When a block is validated, the
transactions bundled in it are verified and the block is added to the chain. As indicated above,
this happens every 10 minutes.

As there will be many miners (systems) competing to solve the puzzle, the first miner to get
the correct hash value earns a reward in Bitcoin. This process allows more Bitcoins in
circulation.
Mining and Bitcoin Circulation
Bitcoin’s upper supply limit of 21 million bitcoin set by its source code by Satoshi Nakamoto,
its inventor, is puzzling. However, experts have seen it as a huge advantage because the scarcity
of supply breeds value and a stable price for the oldest crypto.
From the genesis Bitcoin block mined in 2009 with 50 bitcoins, more bitcoins have since been
mined and released into circulation. Bitcoin mining ensures that blocks of transactions are
created and stacked in the right order in a way that can be traced and proven mathematically.
With the creation of blocks comes bitcoins as a reward, which increases the number of bitcoins
in circulation.
Bitcoin architecture was structured ingeniously such that every 10 minutes, a block is
discovered, and a fixed bitcoin award is offered for every block that is mined.
Prevention of Hacking
What if someone tries to hack the data? Blockchain, as the name implies, is a chain of blocks—
let’s call the blocks A, B and C. Each block has solved a puzzle and generated a hash value of
its own, which is its identifier. Now suppose a person tries to tamper with block B and change
the data. The data is aggregated in the block, so if the data of the block changes, then the hash
value that is the digital signature of the block will also change. It will therefore corrupt the
chain after it—the blocks ahead of block B will all get delinked, because the previous hash
value of block C will not remain valid.
For a hacker to make the entire blockchain valid for the block B that has been changed, he or
she would have to change the hash value of all the blocks ahead of block B. This would require
a huge amount of computing power and is next to impossible. With this method, blockchain is
non-hackable and prevents data modification.

Why Mine Bitcoin?


 People primarily mine Bitcoin to earn profits. Other than that, people who are curious about
this technology and how it works enjoy experimenting with this relatively new technology.

Block propagation and block relay


Block propagation and block relay are critical processes in a blockchain network that ensure
the efficient and timely dissemination of new blocks across the network. These processes are
essential to maintaining the network's security, consensus, and integrity.
Block Propagation:
Block propagation refers to the process of broadcasting a newly mined or validated block from
one node to other nodes in the blockchain network. When a miner successfully mines a new
block or a validating node confirms a new block, it needs to propagate this block to the rest of
the network to ensure that all nodes have the latest state of the blockchain.
Steps involved in block propagation:
 Miner/Validator: The miner who successfully mined the new block or the validating
node that confirmed the block initiates the process of block propagation.
 Broadcasting: The miner/validator broadcasts the new block to its directly connected
peers in the network.
 Peer-to-Peer Relay: Each receiving node (peer) that validates the new block further
broadcasts it to its connected peers, creating a peer-to-peer propagation of the block.
 Network-Wide Dissemination: The block propagates through the network in a cascade
until the majority of nodes have received and validated the new block.
Block Relay:
Block relay is the process of relaying a block from one peer to another peer in the blockchain
network. It is an essential part of block propagation and ensures that blocks are efficiently and
securely disseminated across the network.

Steps involved in block relay:


1. Receiving Block: When a peer receives a new block from one of its directly connected
peers, it validates the block's content and checks if it adheres to the network's consensus
rules.
2. Relay Decision: After successful validation, the receiving peer decides whether to relay
the block to its other connected peers based on certain conditions (e.g., the block is
valid, not already relayed, etc.).
3. Relay to Peers: If the block meets the relay conditions, the receiving peer forwards the
block to its connected peers, ensuring that other nodes in the network receive the block.
4. Multiple Hops: Block relay continues through multiple hops in the network, and each
peer makes the decision to relay the block further.
DESTRUCTURING OF BLOCK
The fundamental building blocks of blockchain, which maintains a collection of data and connects
that data to one another to create a chain of data, are blocks. According to how Bitcoin operates,
each time a transaction is carried out, it must be recorded in a block, or so-called “digital container,”
and kept unaltered forever. A procedure known as mining produces one such new block every span
of time.
THREE MAJOR PLANES OF BLOCK PROPAGATION
A simple, easier-to-visualize architecture can accommodate the aforementioned procedure.
Consider a pyramid that has three planes:

 the network plane


 the consensus plane, and
 the ledger plane
The component that mines blocks in order for a widespread consensus to be formed is called the
consensus plane, whereas the network plane is where P2P propagation runs, and the ledger plane
is the place where blocks are ultimately kept when they are mined. The consensus plane, as a
generic abstraction, takes in messages from the network plane and generates operations for
insertion into the system ledger and integration into the blockchain. While many projects have been
working on scaling blockchains over the past year with a focus on the consensus plane, the network
plane, which is the basis of the system, has mostly been seen as a black box that just functions.
BLOCK PROPAGATION ON THE NETWORK PLANE
The P2P network for Bitcoin is composed of miner nodes that connect to one another at random.
These nodes disseminate transactions and blocks throughout the network until all have received
the information. Hops are required for a transaction to spread a message throughout the network.
The network dispersion increases by a factor of 2n with each iteration as a set of two nodes are
delivered the message. After twelve to fifteen hops, the message is distributed over the whole
network, with the diffusion growing exponentially as the number of hops rises. The throughput of
a blockchain is determined by the number of transactions it can support per second and is
expressed as –

Where, TransactionsBlock is the factor of the current block capacity of the Bitcoin and average
transaction size.

With an average transaction size of about 540 bytes and the current Bitcoin block capacity of 1MB
for a block interval of ten minutes, the network now handles about 1,950 transactions each block,
or about three transactions every second (TPS). Either the transactions per block or the blocks per
second can be increased to boost throughput. It has already taken a lot of effort to use both on-chain
and off-chain techniques to increase the number of transactions per block. Teams have
experimented with expanding the block size by ten times in an effort to multiply the capacity by a
factor of ten. A higher block size typically maintains the hop count at twelve to fifteen for the whole
network, but necessitates delivering a bigger block (one block of 10MB) through the Bitcoin
connection. Although the transaction/block size grows in this case, it also raises the issue of
network throttling, which exponentially lengthens propagation times and raises the stakes in the
argument over Bitcoin splits. One such attempt is the hard fork of Bitcoin into Bitcoin Cash. On
the other hand, blocks/second is another important component to take into account for network
scaling, although it has so far frequently been overlooked owing to a variety of throttling
considerations. The absence of features like pipelining, latency optimization, redundancy,
congestion, message losses, and others prevent the Bitcoin network stack from achieving the per-
node link capacity, making the existing gossip mechanism that determines journey time on the
network plane inefficient.

You might also like