Recently, no matter in the technical forum or group sharing meeting, we are all talking about blockchain in full swing. So today, I would like to share with you my own understanding of what is blockchain.

I have to talk about Bitcoin

The reason why blockchain suddenly became popular is because bitcoin suddenly skyrocketed at the end of 2017. You can see the spike from November to December in the graph, which increased people’s awareness of Bitcoin, but also because there were more people speculating, recently started to fall.

You can click here to see how much it’s worth.

Bitcoin is a virtual currency that circulates across the Internet. Blockchain is the underlying core technology of Bitcoin. The increase of attention to bitcoin indirectly leads to the exploration of blockchain technology.

Let’s start with the origin of Bitcoin.

Start with the original deal

Q: If two strangers are going to conduct a long-distance transaction, how can they ensure trust?

A: Through a third party — such as a treasure.

The buyer transfers the money to a third party, the seller delivers the goods, and the third party pays the seller.

This transaction mode that requires the participation of a third party is called “centralized transaction mode”.

At present, most transactions are centralized mode, such as bank transfer and stock trading. It proves that this mode is indeed the optimal solution in the real world, but it also has disadvantages.

Disadvantages of centralized trading model

1. There must be a reliable centre – what if the centre is unreliable and runs off with the money?

2. The Center needs to obtain unnecessary personal information to build trust — the Center also needs to build trust between party A and Party B, which is your personal information (ID card, mobile phone number, etc.). (And the process is a waste of resources.)

3. Restricted by the center – you transfer money to others, may be delayed for a few days because of the bookkeeping institution holiday, may be because bookkeeping institutions to profit and pay high handling fees, may be because of the bookkeeping institution cheating or system crash and suffer losses.

So the question is —

Can it be done without the need for a third party?

Some have proposed a new scheme, in the hearing in 2008 published a paper on November 1, “the white paper currency: a point-to-point electronic cash system, this paper proposes a completely through peer-to-peer technology to realize electronic cash system, it can make the online payment directly by party a and pay to the other party, don’t need to any financial institution in the middle.

That’s where the decentralized lending model comes in. For example —

A borrowed 100 yuan from B. At this time, A shouted in the crowd “I’m A, I lent 100 yuan to B!” “B also shouted in the crowd” I am B, A lent me 100 yuan! At this time, passers-by A, b, b, d heard the news, so everyone silently wrote down “A lent B100 yuan”.

The result is A decentralized system that requires no banks, no loan agreements, no receipts, and, strictly speaking, no long-term trust between people (e.g., “I don’t owe A lot of money!” “That’s when people come out and say,” No, my little book says you borrowed $A100 the other day!” ).

In the model above, the “100 dollars” doesn’t matter. In other words, anything can be exchanged in this model, and you can even make something up out of thin air, so long as everyone acknowledges it, you can make it circulate.

For example, I shouted “I created 10,000 Tencent coins!” in the crowd. “, I don’t even need to know what Tencent coin is, nor do I need to care about whether there is really Tencent coin in the world, as long as everyone hears it, and then write down “A has 1W Tencent coin” on his little book, so I really have 1W Tencent coin.

From then on, I can claim that I gave XXX Tencent coins to someone, and as long as passers-by a, B, C and D receive and acknowledge the message, I have completed the transaction, even if there are no Tencent coins in the world.

Yeah, that’s where bitcoin came from.

A, b, and D are the addresses of other nodes on the network.

AB gentleman is the address of two nodes. Any transaction between two nodes will be broadcast to all nodes.

A b B D: How can I give you accounts??

You may ask, “Why should I take notes when you shout? I don’t want to face “. To encourage you to help me with my message and bookkeeping, I’ve decided to give a prize to the first person who hears my message and writes it down in a notebook: You get tencent 50 COINS out of thin air, this is the whole system fortunately, pay charge to an account for you, and you recorded this sentence after, want to tell other people you’ve had a good record right away, let others give up continue to record the words, and give your own record number let others well documented, and then you take my words and your record number to shout out, for the next person to charge to an account. When this rule is set, there will be a group of people in the system who will start listening for noises around them to claim the right to be the first to charge.

This is how bitcoin works in a decentralized way. When a transaction occurs at any node in the network, other nodes account for it.

The act of being the first to account for a reward is called “mining”

  • Generally, it takes 10 minutes to dig a block, which is 1M in capacity and is used to record all transactions in 10 minutes (if not recorded, it will be postponed).
  • Start with 50 mines
  • The mining bonus is halved for every 210,000 blocks generated (approximately every four years)
  • According to the above rules, the total amount of coins does not exceed 21 million, and it is expected to be mined out in 2140 years. (This is also the reason why bitcoin maintains its value, and there will be no inflation problem.)
  • The most recent reduction was on July 9, 2016, with more than 16 million circulating in 2017
  • The equipment used to dig the ore is called a mining machine, and the men who operate it are called miners

Who can say “I” have ten thousand tencentcoins?

Assume that after a long period of time, the Tencent coin I created out of thin air has been circulated in this system, everyone began to recognize the Tencent coin. But there are only 10 million Tencecoins in the system, so someone took a bad turn and shouted “I have 10 million Tencecoins!” in the crowd. How to do? We are directly in the book on the record he has 1W Tencent coins, so not everyone can forge it?

To prevent this from happening, I decided to mark the sentence “I created 1W Tencentcoins” when I created tencentcoins, such as 001), so that in the future every transaction, I would shout “I gave one Tencentcoin to xx!” “Will be attached with an additional sentence:” The source of this Tencent coin is the record of 001, my sentence is marked 002!” . We are a little more abstract, someone shout the content of the format became: “this sentence number XXX, the number of a sentence is YYY, I gave so-and-so 1 Tencent coins!” This solves the problem of forgery.

In fact, the above model becomes a simplified version of the first version of Satoshi Bitcoin blockchain protocol.

The birth of Bitcoin

On January 3, 2009, Satoshi nakamoto created the first block, Trands block, which contained 50 Bitcoins. Along with this sentence:

“The Times 03/Jan/2009 Chancellor on brink of second Bailout for Banks” was The headline on The front page of The Times that day, confirming The birth of bitcoin.

A b B D: Who is the first to keep the books and who has the final say?

Then you ask again, what if everyone says they’re the first to do the bookkeeping?

So a new rule, the consensus algorithm, was born.

Name two ways:

Proof of workload: I stipulate that only do a set of five years of simulation, three years of college entrance examination papers of the first, just have the right to bookkeeping.

Proof of work is a mechanism where it is difficult to work out the answer, but easy to check the answer.

Bitcoin uses proof of work, which allows each computer node that wants to mine to do a difficult calculation first, and the first to do it has the right to account for it. The math is so difficult that it takes about 10 minutes to figure it out. That’s why we said we dig a block every 10 minutes.

But the trouble with proof of work is that it is unnecessarily costly, because only one person is number one, and the work done by everyone else is in vain.

Hence the claim of proof of interest:

Proof of interest: I stipulate that only those who hold the most Tencent coins and hold them for the most days have the right to keep accounts.

The problem with that, too, is that the stronger the stronger.

Proof-of-work

The miner needs a random value such that SHA256(random value + H(block header)) < some target value

The system dynamically adjusts the target value (difficulty) for every 2,016 blocks generated, so that each block generated takes about ten minutes.

The difficulty value formula can be imagined as:

New difficulty value = Old difficulty value * (20160 minutes/last 2016 blocks)


The calculation formula of the target value can be imagined as:

1. Target value = Maximum target/difficulty value

2. The biggest target for a constant value: 0 x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff

The target can imagine: 0 x00000000000000000000000000000000000000000000000017268d8a21a

Difficulty adjustments occur independently and automatically within each full node. Every 2016 blocks, all nodes will automatically adjust the difficulty by unified formula, this formula is by the cost of the latest 2016 block length and the expected time (expected duration of 20160 minutes, or two weeks, is per 10 minutes a block production rate to calculate the total length) is concluded, according to the actual length and expectations long ratio, Adjust accordingly (or make it harder or easier). That is, if the block generation rate is faster than 10 minutes, the difficulty increases, and slower than 10 minutes, the difficulty decreases.

We can also simply understand that the process of proving the work of Bitcoin is to find a hash value of a particular format by constantly changing the block head (i.e., trying different NOUce values) as the input for SHA256 hash operation (i.e., requiring a certain number of leading zeros). The more leading zeros you need, the harder it is.

Block header structure

The block header contains the version number, the parent block’s hash value, the Merkle root, the timestamp, the difficulty value, and the nonce (number once)…

Wait, what’s a Merkle root?

Merkle (Merkle tree or Merkle tree)

Merkle is a binary tree that has several transactions per block, doing Hash0 for each transaction, merging Hash1 for every two transactions, and merging Hash2 for every two hash1s… As an example, transactions 1 and 2 hash separately to become Hash12, hash with Hash34 to become Hash1234, hash with Hash5678 to become hash1-8…

Features:

  1. Fast comparison of large amounts of data: When two Merkle roots are identical, it means that the data they represent must be the same.

  2. Quick modification: For example, if data in N4 is modified, N34, N1234, and Root will be affected. Therefore, following Root – >N1234 – >N34, you can quickly locate the changed D1;

  3. Zero-knowledge proof: for example, how to prove that a certain data (H1-8) includes a given content of transaction 6 is very simple, construct a Merkle tree, declare H1-8, H5678, H56, H6, transaction 6 owner can easily detect the existence of transaction 6, but do not know the other content.

Calculate the force

We started by saying bitcoin is so valuable and anyone can mine it, so can we just go home and mine it now?

In theory, yes. In practice, considering the computing power of the computer, as we said earlier, mining is very difficult… Search for a mining machine on Taobao, and this is what you’ll find.

But there are people who do nothing but dig, and some companies hire people to keep the mining machines running. The power consumption of these mining machines can run into hundreds of thousands.

Bifurcation problem

The nodes on “Zhang Heng Road, Pudong New Area, Shanghai, China” and the nodes on “Fifth Avenue, Manhattan, New York, United States” shouted out in unchorused voice: “I dug a block! All transactions are valid! The prize is mine!” . Other nodes also checked the two blocks at about the same time and found that neither of them was faulty.

This violates the first fundamental principle of blockchain — that all nodes maintain the same data. So, to solve this problem, the blockchain world has introduced a new rule —

The branch with the most blocks will be recognized, and the shorter branch will be discarded.

We all know that mining is a huge amount of work, and that in the silicon-based world of computers, there is no such thing as “simultaneity,” even nanoseconds apart, always in order. So in theory, this “fork” deadlock will be broken quickly when the next block is mined (and verified), or the next, or the next… In short, the whole forked blockchain world can be quickly stabilized.

In addition, at the same time, blocks on shorter branches are immediately discarded, and transactions within them are freed up and re-marked as “unconfirmed.”

Double flower problem and 51% attack

Once upon a time, there was an X-man, a very rich and very clever Man. He said:

I’m x-Man. I’m rich. I have a powerful computer network.

I first created a separate chain of blocks from a block, and then recorded that I transferred 1000 Bitcoins to myself.

This separate block chain is not broadcast to the entire web. And then I went to Joe and I gave him 1,000 bitcoins for 10 million RMB,

When the deal was confirmed three times (three blocks were dug up), Zhang SAN gave me 10 million.

At this time, I broadcast my independent block chain, my chain became the longest chain, my transaction with Zhang SAN was abandoned, but I got his 10 million yuan.”

This is the double-spending problem — the exploitation of a loophole in the system to make money spend more than once.

X-man’s idea worked, but his computers were up against all the computers in the world, and unless X-Man had 51 percent of the computing power of the network, it wouldn’t have worked. This is a 51 percent attack, and 51 percent computing power is no longer possible.

But even if X-Man does have 51% of the network’s computing power, in the real world it would be cheaper to use that 51% for other purposes (such as mining or other computing services) than to attack the Bitcoin system.

With all that said, what exactly is blockchain?

Blockchain is a tamper-proof, shared, traceable distributed ledger database technology

Tamper-proof: the modification of a single point must be recognized by consensus of multiple other nodes before it can be successfully traceable: blockchain ledger, only writing is allowed, not deleting sharing is allowed: ledger is transparent to participating nodes

Why is it called “blockchain”?

In the Bitcoin network, a new block is created every 10 minutes, which contains all transactions made in the network within the last 10 minutes. One miner hashes the block to get the record, synchronizing it with the other miner nodes.

Each block is added to the last block to form a long chain, hence the term “blockchain”.

The technical classification of blockchain

Public chain: 1, no official organization and management organization maintenance 2, all nodes have the same authority 3, free to join and exit

Typical applications: Bitcoin, Ethereum

(Public chains have their value, but they are too extreme, resulting in slightly more centralised federation chains.)

Alliance chain: 1. Initiated and maintained jointly by several agencies; 2. Authority of nodes is usually mixed; 3

Typical application: Tencent Blockchain (trustSQL)

Example of blockchain application value — Public welfare search

Public welfare seeking platform is numerous, goose factory is more than the following:

Existing problems:

Solution: use blockchain to let everyone share a chain, information synchronization is fast, one party to report, multi-party broadcast.

Blockchain game value example — Ethereum masturbation

Recently in the coin circle, there is a game of cat stroking that is also very popular on the Internet (we don’t feel it because it is a rich game and we can’t afford to play it).

How to get started: Players use ETH as “currency” to buy and sell cats, starting with a cat at the market. Buy cheap first, there is a fee for buying cats (to prevent congestion on the Ethereum blockchain).

After buying two: can let it two give birth to kitten. Each cat has 256 attributes that control coat color, pattern, whiskers, teeth, and so on, which can be understood as 256 different genes. When two cats breed, the gene is passed on with a certain probability. Genes also mutate, and when they do, they give birth to oddly shaped kittens.

These kittens often fetch high prices because of genetic mutations.

After each birth, the parents go into Cooldown mode and must “recover” for a period of time before they can continue to breed. The recovery time of each cat varies, and the longer the cat grows, the longer the recovery time increases. Recovery time is also a factor in cat prices.

If you have only one cat and want to mate with someone else’s cat, you can also check out the market. Player 1 can bid a “stud price”, which player 2 will pay player 1 if he wants to mate, and the cat born to player 2 will own it. Cats with good genes can command a high price on the breeding market.

It also takes some time (from a few hours) to reproduce after a successful mating. After the kitten is born, you can see the new kitten on the My Kitties page.

Each cat has a Gen logo, Gen 0 means it’s a Genesis Cat, Gen 1 is the first generation, Gen 2 is the second generation, and so on. Every 15 minutes or so, a Gen 0 Genesis Cat is created and automatically auctioned by contract, with the proceeds going to the developer’s wallet.

What’s the difference between blockchain and cloud?

The big difference is that once the rules of the game are established, your cat is always your cat, and the developer has no right or ability to take away anyone’s cat. Cloud Cat is a centralized game, all the cats are registered in the developer’s database, developers can tamper with, deprived of anyone’s cat, developers can also arbitrarily create their own high-priced cat. When you think about it, an item in an online game is nothing more than a digital asset created and sold by the developer himself, and there is no guarantee that the developer won’t cheat.


Refrences:

What is blockchain and how to introduce it in a simple and understandable way? – zhihu

What is the relationship between Blockchain and Bitcoin? – zhihu

Bitcoin – Wikipedia

Distributed Consistency and Consensus Algorithms

Bitcoin and blockchain: What is blockchain? – InfoQ

In-depth interpretation of blockchain Masturbating — Liao Xuefeng

The workload that | Proof Of the Work – “” bitcoins Developer Guide” in Chinese