What is blockchain?

This is an append-only, immutable distributed ledger that is updateable only via consensus/agreement among peers. There is no single authority of this ledger.
This is a Peer to Peer network running over TCP. Same as HTTP, FTP over TCP.
Examples of blockchains: Tezos (Uses Proof of Stake), Bitcoin (Uses Proof of Work).

Why learn blockchain

Decentralization: No need for a trusted third party or intermediary to validate transactions; instead a consensus mechanism is used to agree on the validity of transactions.
Transparency and trust: As blockchains are shared and everyone can see what is on the blockchain, this allows the system to be transparent and as a result trust is established.
Immutable: Once the data has been written to the blockchain, it is extremely difficult to change it back.
High availability: As the system is based on thousands of nodes in a peer-to-peer network, and the data is replicated and updated on each and every node.
Highly Secure: All transactions on a blockchain are cryptographically secured and provide integrity.
Cost saving: As no third party is required in the blockchain model.

Limitations of Blockchain

Denial-of-Service Attack: An attacker can overload a node by sending a lot of data or Huge block or transactions which too long to execute.
How to mitigate? bitcoin & many cryptocurrencies have a maximum possible block size limit.
Scalability: Very few nodes can maitain complete blockchain because of its big size.
Adaptability
Regulation
Relatively immature technology
Privacy
Sybil Attack: A single person controls few nodes and persuades few other nodes to block user(bob) from the network completely. This can result in transaction censoring for user(bob). This can result in double spending. How to Avoid? look for nodes with suspiciously-low hashrate.

BlockchainAddress (Sender or Receiver)

Bitcoin address of node is calculated using Hash of Public key. Public generated using secp256k1 ECC Algorithm.
Hash is generated using RIPEMD160 + SHA256.
        K(public key) = k(pvt key) * G(constant)
        K --> |SHA256| --256bit--> |RIPEMD160| --> 160bit(Address)
        160bit(Address) --> |Encode(Base58 Check)| --> Bitcoin Address      //Base58-Check(RIPEMD160(SHA256(K)))
        

Block

Blockchain is composed of blocks(Header + payload). Block stores the transactions.
Header is metadata, while payload is actual transaction data.
Genesis Block. Bitcoin block#0
1st block in blockchain. This is hardcoded at time when blockchain started. This is same as other blocks, just it does not have pointer to prev block
        Header/Metadata => |block number | timestamp (when the block was created) | block hash | nonce |
        Data/Payload =>  |Sender address | Recipient address | amount of transaction | fee |
        
        struct block {
          struct block_header* bh;
          struct block* prev_block;   //This is Hash pointer(not normal pointer)
          long timestamp;
          long nonce;
          long transaction_counter
          struct transactions* t;
          struct other_attribute* oa;
        }
        
Block creation
The only way to add new information to the blockchain is to add a block to the end of it.
Only Qualified users create blocks and send them to other nodes.
If the block is valid, other users accept it.
If it’s invalid, they ignore it and may punish block creator. The valid block propagates through the network in a few seconds.

Transaction

1 block can store 1 or multiple transactions. Whenever a transaction(s) happens on blockchain, a block is created and stored on chain. Transactions are used to record various activities, such as cryptocurrency transfers, smart contract executions, and other changes to the blockchain’s state.

POW(Proof of Work)

There are 2 types of blockchain systems: POW & POS(Proof of Stake)
In POW system, to add a new block mining needed to be done. Miner who solves the puzzle(finds hash of transaction) is rewarded some bitcoins and transaction fee.
Problems with POW:
1. Energy efficiency: Miners compete to solve complex mathematical puzzles using huge computational power.
2. Centralization Concerns: More power more chances to solve 1st, this means more bitcoins goes with people/companies who own huge machines.
3. Accessibility: Only those having specialized mining hardware, have more bitcoins.

POS(Proof of Stake) (Ethereum uses it)

Why POS came in?
Due to problems in POW(Proof of Work), POS emerged.
How POS Works?
          Proposer                                  Validator-1                  Validator-2
                                              (Hold coins to stake)
        1. Create block
        (having transaction)  -|--broadcasted---->  block is Good
                               |------------------------------------------------> block is good
        Block included on chain
        Reward distributed to both
        
1. Validators/forgers/stakers(same as miners in POW system) validate transactions based on:
a. Number of coins they hold
b. And how many coins they are willing to "stake" as collateral.
2. Validators are selected in a deterministic manner, often based on factors like the amount of coins staked and the length of time they’ve been staking.
3. Validators are incentivized to act honestly because they have "their coins" – if they validate fraudulent transactions, they risk losing their staked coins.
4. Validators are rewarded with transaction fees and sometimes a portion of the transaction fees paid by users.
Advantages of POS:
1. Less power consumption wrt POW system: The need for solving computational puzzles is eliminated, which significantly reduces energy consumption compared to PoW.

BlockChain Clients

There are two main types of Bitcoin clients:
1. Full Node: These clients download and validate the entire Bitcoin blockchain
2. Lightweight Node: These clients do not download the entire blockchain. Instead, they rely on full nodes to verify transactions for them. Examples:
1. Bitcoin Core (Fullnode Bitcoin client)
Holds complete blockchain in local system. Requires ~500GB of space.
2. Electrum (Lightweight Bitcoin client)
It allows to interact with the Bitcoin network(bitcoin network is blockchain). With client we can send and receive transactions, and manage your Bitcoin holdings.
Mycelium, Electrum, Exodus
3. Kukai (Lightweight Tezos client)
This is wallet service on Tezos blockchain. Tezos is based on Proof of stake, while Bitcoin core, electrum are Proof of work blockchains

Mining

Let’s suppose Alice wants to send 1 BTC(bitcoin) to Bob, alice sends message on network.
Miner Nodes(Verfiers of transaction) recieve the Alice’s message and starts a race to find HASH of desired diffculty(defined by software).
Node(Miner) who solves it 1st is rewarded with some transaction fee(0.001 BTC) + bitcoin reward.
Miner-1, solves the puzzle and sends to network for verification. Other miners verifies it using consensus and transaction is added as a node to ledger=blockchain.
As more and more miners join the network, the total hash rate — the combined computing power of all miners — increases
        Transaction
          src_add = Alice_hash    //Hash is public address of entity on blockchain
          amount = 1 BTC
          dst_add = Bob_Hash
        

How bitcoin can be issued?

1. Using crypto exchange: Here if someone sells the bitcoin, its purchased by other
2. Mining: Miners are rewarded transaction fee + Bitcoins. Once a miner verifies a transaction and adds to blockchain.
Rate of bitcoin Issuance?
2012: 25 bitcoins/block. ie on verification of 1 transaction, adding to blockchain. 25 bitcoins
2016: 12.5
2140: 0. (All 21 million bitcoin will be issued). Miners will be rewarded solely through the transaction fees.
210000 is around every 4 years with a 10 minute block interval
Why only 21Million bitcoins. Inflation?
The finite and diminishing issuance creates a fixed monetary supply that resists inflation.

Smart Contract

These are the programs that run on blockchain having business logic. This get automatically executed when certain conditions are met. These are secure and unstoppable.
Represents aggrement b/w 2 parties & allows parties to securly conduct business.
Properties:
1. Immutable(cannot be changed): SC creates logs which are immutable, those cannot be changed.
2. Distributed: Output of contract is Validated/verified by other nodes on the network.

Solidity

High level Object oriented programming language for writing smart contracts.
Features: Based on C,C++,python, Statically typed: Checking happens at compile time, Supports inheritance: 1 smart contract can be used by other

Wallet

In the context of blockchain(eg: bitcoin, tezoz), a wallet is a digital tool that allows you to store, manage, and interact with your Bitcoin holdings. It’s used to create and manage Bitcoin addresses, which are used to send and receive Bitcoin transactions. A Bitcoin wallet consists of two main components:
1. Public Addresses(Hash number): These are account numbers in blockchain network. You share these addresses with others when you want to receive Bitcoin. They are derived from your wallet’s public key.
2. Private Keys: These are secret keys that helps control/access bitcoins associated with your addresses. Whoever has access to the private key has control over the Bitcoin at that address.