1. 程式人生 > >How does blockchain work in 7 steps

How does blockchain work in 7 steps

The blocks on a blockchain are publicly available to anyone. So, if an alteration is supposed to stay undetected on a blockchain, all the blocks need to stay properly chained together (otherwise people can tell that certain blocks don’t properly link to each other). This means that altering a single block requires a new signature for every other block that comes after it

all the way to the end of the chain. This is considered to be impossible. In order to understand why, you will need to understand how the signatures are created.

Step 3 — How the signature (hash) is created

So, let’s picture a block again; block 1. Block 1 is a record of only one transaction. Thomas sends 100 Bitcoin to David. This specific string of data now requires a signature. In blockchain, this signature is created by a cryptographic hash function

. A cryptographic hash function is a very complicated formula that takes any string of input and turns it into a unique 64-digit string of output. You could for example insert the word ‘Jinglebells’ into this hash function, and you will see that the output for this specific string of data is:

761A7DD9CAFE34C7CDE6C1270E17F773025A61E511A56F700D415F0D3E199868

If a single digit of the input changes, including a space, changing a capital letter or adding a period for example, the output will be totally different. If you add a period to this word and make it ‘Jinglebells.’ instead, you will see that the output for this specific string of data is:

B9B324E2F987CDE8819C051327966DD4071ED72D998E0019981040958FEC291B

If we now remove the period again, we will get the same output as before:

761A7DD9CAFE34C7CDE6C1270E17F773025A61E511A56F700D415F0D3E199868

A cryptographic hash function always gives the same output for the same input, but always a different output for different input. This cryptographic hash function is used by the Bitcoin blockchain to give the blocks their signatures. The input of the cryptographic hash function in this case is the data in the block, and the output is the signature that relates to that. Let’s have a look at block 1 again. Thomas sends 100 Bitcoin to David.

Now imagine that the string of data from this block looks like this:

Block 1 Thomas -100 David +100

If this string of data is inserted in the hashing algorithm, the output (signature) will be this:

BAB5924FC47BBA57F4615230DDBC5675A81AB29E2E0FF85D0C0AD1C1ACA05BFF

This signature is now added to the data of block 2. Let’s say that David now transfers 100 Bitcoin to Jimi. The blockchain now looks like this:

The string of data of block 2 now looks like:

Block 2 David -100 Jimi +100 BAB5924FC47BBA57F4615230DDBC5675A81AB29E2E0FF85D0C0AD1C1ACA05BFF

If this string of data is inserted in the hashing algorithm, the output (signature) will be this:

25D8BE2650D7BC095D3712B14136608E096F060E32CEC7322D22E82EA526A3E5

And so, this is the signature of block 2. The cryptographic hash function is used to create the digital signature for each unique block. There is a large variety of hash functions, but the hashing function that is used by the Bitcoin blockchain is the SHA-256 hashing algorithm. But how do the signatures stop someone from simply inserting a new signature for each block after altering one (a change goes undetected if all blocks are properly linked, people won’t be able to tell there was a change)? The answer is that only hashes (signatures) that meet certain requirements are accepted on the blockchain. This is the mining process and is explained in step 4.

Step 4 — When does the signature qualify, and who signs a block?

A signature doesn’t always qualify. A block will only be accepted on the blockchain if its digital signature starts with a consecutive number of zeroes. For example; only blocks with a signature starting with at least ten consecutive zeroes qualify to be added to the blockchain. However, as explained in chapter 3, every string of data has only one unique hash bound to it. What if the signature (hash) of a block doesn’t start with ten zeroes? Well, in order to give the block a signature that meets the requirements, the string of data of a block needs to be changed repeatedly until a specific string of data is found that leads to a signature starting with ten zeroes. Because the transaction data and metadata (block number, timestamp, et cetera) need to stay the way they are, a small specific piece of data is added to every block that has no purpose except for being changed repeatedly in order to find an eligible signature. This piece of data is called the nonce of a block. The nonce is completely random and could literally form any set of digits, ranging from spaces to question marks to numbers, periods, capital letters and other digits. To summarize, a block now contains; 1) transaction data, 2) the signature of the previous block, and 3) a nonce. The process of repeatedly changing the nonce to find an eligible signature is called mining and is what miners do. Miners spend electricity in the form of computational power in order to constantly try different nonces. The more computational power they have, the faster they can insert random nonces and the more likely they are to find an eligible signature faster. It is a form of trial and error. You can picture it like this: