Skip to main content

Blockchain Basics

Blockchain Demo

Hash#

Hash is a unique fixed length string meant to identify any piece of data they are created by putting some piece of data into a hash function.

Block#

A block is a record.

  • block number
  • nonce
  • data
  • hash

when we're talking about mining we're talking about miners solving some type of very difficult problem that takes a lot of time to do.

Now in this example here the problem that the miners had to solve was they had to find a nonce(Number once随机数) or or a value in this Nonce section that when hashed with at block number 1 with this data it would start with four zeros.

So the problem here the miners had to solve was to start with four zeros. when miners are mining they're just looking there's trial and error brute force trying to find this nonce.

info

nouce is a number used once to find the solution to the block problem.

Block chain#

  • block number
  • nonce
  • data
  • previous block hash
  • hash

A blockchain is a growing list blocks, that are linked together using cryptography. As blocks each contain information about the block previous to it, they form a chain, with each additional block reinforcing the ones before it.

Therefore, blockchains are resistant to modification of their data because once recorded, the data in any given block cannot be altered retroactively without altering all subsequent blocks. (immutability)

info

The block with the previous of all zeros is going to be known as the genesis block. The genesis block is the first block in the blockchain where the previous hash points to a hash that doesn't actually exist.

The immutable blockchain#

If i go back and change anything, the entire blockchain is invalidated. Because none of these are going to have nunses that solve this math problem anymore.

This is why blockchains are immutable is because anytime you change one thing you ruin the rest of the blockchain.

remine each one of these block is going to be very computationally expensive. But it's something that i can do right if i'm the one who owns the blockchain.

Here's where the decentralized nature or the distributed nature really makes it incredibly powerful.

The discentralized blockchain#

we have a number of different peers who are running this blockchain technology they're all weighted equally. Each one of these peers (or nodes, entities) running a blockchain has the exact same power as anybody else.

note

Every node in a decentralized system has a copy of the blockchain. Data quality is maintained by massive database replication and computational trust. No centralized "official" copy exists and no user is "trusted" more than any other. Transactions are broadcast to the network using the software by miners who validate these transactions.

So the way that we can tell which blockchain is correct by looking at End Hash, or by looking at where we are in the blockchain. Because this hash that in this End Block is going to encompass all of the blocks from before. Because all last hash is going to have the previous hash and so on. So this End Hash encompasses everything.

It's very easy for their nodes to look at each other and say we are all matched up by checking the end blocks' hash.

If peer A changes and remine his blockchain, then given we have peer B and peer C in the network, peer C can verify peer B is the correct one.

Token#

Instead of having this data section we have this tx section and this represents all the transactions that are happening in this block.

But how do we know that it was Darcy who was the one to send 25 to Bingley. How do we know that actually happened?

Keys and signature#

  • private keys
  • public keys

Private key is only known to the key holder, it's used to sign the transactions. Public key is visible to all, it's used to verify the private key.

We use the digital signature algorithm (elliptic curve) to create the message(transaction) signature. And every one can verify the message signature by public key.

Consensus: Proof-of-work, Proof-of-stake#

Consensus is defined as the mechanism used to reach an agreement on the state or a single value on the blockchain, especially in a decentralized system. Proof of work(PoW) and proof of stake(PoS) fall under this umbrella of consensus.

A consensus protocol in a blockchain or decentralized system can be broken down into two pieces a chain selection algorithm and a civil resistance mechanism.

Civil resistance#

Civil resistance is a blockchain's ability to defend against users creating a large number of pseudo-anonymous identities to gain a disproportionately advantageous influence over said system and in layman's terms it's basically a way for a blockchain to defend against somebody making a bunch of fake blockchains so that they can get more and more rewards. There are two types of the civil resistance mechanisms that we're going to talk about here namely proof of work and proof of stake.

The proof of work algorithm is one Civil resistance mechanism and this is what ethereum and bitcoin currently use. It defines a way to figure out who is the block author, which node (blockchain, peer, user, server) is going to be the node, who did the work to find that mine and be the author of that block.

Chain selection#

How do we know which blockchain is actually the real blockchain and the true blockchain? Bitcoin and ethereum they both use a form of consensus called Nakamoto Consensus and this is a combination of proof of work and longest chain rule.

The decentralized network decides that whichever blockchain has the longest chain or the most number of blocks on it is going to be the chain that they use. This makes a lot of sense, because every additional block that a chain is behind, it's going to take more and more computation for it to come up.

When we saw in our transaction we actually saw confirmations. The number of confirmations is the number of additional blocks added on after our transaction went through in a block. So if we see confirmations is 2 it means that the block that our transaction was in has 2 blocks ahead of it in the longest chain.

info

The block time is the average time it takes for the network to generate one extra block in the blockchain. The block time for Ethereum is set to between 14 and 15 seconds, while for bitcoin it is on average 10 minutes.

Proof of Stake#

PoS is a different civil resistance mechanism. Instead of solving this difficult problem, proof of stake nodes put up some collateral that they're going to behave honestly, aka they stake.

In the example of ethereum 2, nodes put up some ethereum as a stake that they're going to behave honestly in the network. If they misbehave to the network they are going to be slashed or removed some of their stake.

In this system, miners are actually called validators. Because they're no longer binding anything, they're actually just validating other nodes.

Unlike proof of work which every node is racing to be the first one to find the block, in proof of stake, nodes are actually randomly chosen to propose the new block, and then the rest of the validators will validate if that node has proposed the block honestly.

randomness#

Blockchains are deterministic systems. They're walled gardens from the rest of the world. And as you know, a determinic system by definition can't have random numbers. So how do we choose the random validators in the system?

In eth2 they're using what's called randow, at least for the original implementation. This is a decentralized autonomous organization that collectively chooses the random number and collectively chooses which node is going to run next.

Transaction fee, Block Reward#

In this proof of work system all these nodes are competing against each other to find the answer to the blockchain riddle. The first node to figure out the answer to the blockchain rule is going to get that transaction fee and block reward.

Attack#

  • Sybil attack: a user creates a whole bunch of pseudo-anonymous accounts to try to influence a network.
  • 51% attach: if you have the longest chain and you have more than 51 percent of the rest of the network, you can do what's called a fork in the network and bring the network onto your now longest chain.

Scalability: Sharding#

Scalability problem: there is not enough block space for the amount of transactions to get in them, which leads to very high gas prices.

A sharded blockchain really just means that it's going to be a blockchain of blockchains. There is a main chain that's going to coordinate everything amongst several chains, that hook into this main chain. This means that there's more chains for people to make transactions on.

Layer 1#

layer one refers to any base layer blockchain implementation. Bitcoin's a layer one, Ethereum's a layer one, Avalanche is a layer one. These are the base layer block chain solutions.

Layer 2#

layer two is any application that is added on top of a layer one added on top of a block chain. Some examples of layer twos are going to be chain link, Arbitrum or Optimism. They roll up the transactions to layer 1.

Layer 2 is used to solve the scalability problem of layer 1.