📜 ⬆️ ⬇️

Bitcoin inside for non-understanding

A lot of ambiguous articles written about bitcoin prompted me to write an article about the internal structure of this system. I was surprised that some authors wrote about digital coins without an understanding of the internal structure, and the meaning of lengthy reasoning was an unsuccessful attempt to find out if it was a scam. Hopefully, after this article, bitcoin faith or trust will turn into confidence and awareness. I will not disclose in this article the socio-economic impact of digital coins, but focus exclusively on internal algorithms.

Electronic Digital Signature (EDS)

Unfortunately, I have not found suitable simple images to show how inside cryptography works on elliptic curves. Take this tool "on faith." The same algorithms are used in the banking sector (and not only), therefore, the collapse of EDS will lead to a crisis in many industries. So, with a private key, we sign “letters of transfer of ownership” (transactions), and thereby give our coins to someone else. With the public key we verify the authenticity of the transactions of others.

Hashing

If you understand the hashing process, skip this section. Show hashing is quite simple. Take some number ... for example the phone number +7 (495) 606-36-02. Add all the numbers together several times:
7 + 4 + 9 + 5 + 6 + 0 + 6 + 3 + 6 + 0 + 2 = 48 => 4 + 8 = 12 => 1 + 2 = 3
So you can definitely associate any number with any phone number. The summation process is called hashing, the method itself is a hash function, the resulting number is a hash sum or just a hash.
Usually achieve the following properties from hashing:
- Knowing the hash sum (in our case 3) it is impossible to determine the original phone number.
- You can not adjust the phone number to a previously known amount (in our example, it is not applicable, it is mandatory for bitcoin).
- A small change in the telephone number will lead to a fundamental change in the hash (in our example, it is not applicable, but it is mandatory for bitcoin).
There are also many other clear everyday examples of hashing in a wiki article.

Transfer of ownership. Hash sum of public key

Bitcoin operates with the public key hash sum as the address for transferring coins. To declare someone's bitcoin address publicly - is worth nothing. Finding the original key by its hash will not be possible even for the participants of the “psychic battle”. And the key pair itself will be used only once - when transferring ownership rights. The life of a pair of keys ends there.
image
PUB1 - public key
PRIV1 - secret key
HASH1 or HASH (PUB1) is the hash sum of the public key (bitcoin address).
HASH2 or HASH (PUB2) is the hash of the next owner's public key.
')
Disregard for some time from the coins. Take, for example, the owner of a car whose property is beyond doubt.
- The owner at a public meeting (fair, television show) shows everyone the hash of his public key HASH (PUB1), the serial number of the car, and everyone agrees with this - no one makes a complaint.
- Until the sale, both keys of the seller PUB1, PRIV1 remain secret. Only HASH (PUB1) and the serial number of the car corresponding to it are known.
- As soon as the owner wants to sell the car to any buyer, he writes an open letter in which he indicates the factory number and the hash sum of the public key of the second owner HASH (PUB2). And of course he signs the letter with his secret key PRIV1, enclosing the public key PUB1.
- After the transfer of property, the secret key ceases to be relevant - there can be no second such letter (see “The Unified History”). With a public key you can check the letter itself, certify the second owner.
- About the second owner nothing is known except HASH (PUB2), until he transfers the rights to the third owner. And this chain can be endless.
- By signing the transfer of rights using EDS, the owner not only certifies himself, but also imposes an obligation to transfer. As the saying goes: "the word is not a sparrow, it will fly out - you will not catch it."
- Thanks to HASH (PUB) double protection is obtained. The first riddle is to find out the public key by its hash. The second riddle is to sign with someone else's secret key.
image
If you replace the car with a bitcoin, then instead of the factory number appears the hash of the previous transaction. And the whole chain of owners is kept publicly at each user.

"And the change !?"

The change must be left to yourself. But it is conceived that the secret key is used only once, and some of their coins are sent to their new, not illuminated address. Because of this, it is difficult to understand how many coins belong to any address, and it is difficult to judge the amount of coins transferred per day / month / year.

One story. What miners dig.

In order to not be able to spend coins twice, there must be a single history of all transactions. Then only the first transaction (the letter of transfer of the rights to the coins) will be included in the journal, or, in extreme cases, one of several. For this, transactions are combined into blocks and only “beautiful” blocks are recognized. “A beautiful block” is hard to find, it’s just like out of tons of gold ore there is only one standing nugget. In our case, the block hash sum must contain a certain number of zeros.
The block consists of the previous block (hash sum), the hash sum of all included transactions, and a random number (eng: nonce).
An example of a bitcoin block from blockexplorer.com:
* Hash: 00000000000001c21dbf4715d5da1a288061faa21e950dd8df6ae25c8b55d868
* Previous block?: 000000000000056a7dcf283f627c2a17c55ffe1937a6ed2bc467d9c524311da2
* Difficulty: 1 690 895.803052 ("Bits": 1a09ec04)
* Transactions: 184
* Total BTC: 4251.63216933
* Size: 58.913 kilobytes
* Merkle root: 98c5d975bf556f0344770eee7ab31688a1c108223c14cea908ff99b0ab8fe947
* Nonce: 3723473450

See how many zeros at the beginning of the block hash amount? That's why it was so hard to find. But everyone can easily verify the authenticity of the "beauty" of the block. The number of zeros in the hash is chosen in such a way that each block is born approximately once every 6–10 minutes. For finding the block is issued a promotion, now it is 50 coins. Also, the finder is given all fees from payments (transactions fees), for those transactions that are included in his unit.
A single story is achieved due to the fact that the longest chain of blocks always wins. It’s not a problem if an isolated piece of users is split off from the bitcoin network - afterwards all the broken-off transactions will go into a longer chain (considering the complexity).

Subtleties of work

- Hashing is usually understood as double sha256, i.e. sha256 (sha256 (x)).
- Surprisingly, bitcoin does not encrypt anything. The entire transaction log is completely open information. Anyone can check the integrity of all transactions, count the number of coins in circulation. There is no chance for counterfeiting. The only possibility for evil deeds is to only suspend the work of bitcoin for a while.
- When you first start the bitcoin application creates a pair of keys. More precisely, he creates them at once 100 pairs in advance, thus it is possible to make a backup of the wallet (backup) for not more than 100 forward operations.
- In fact, the transaction specifies the verification algorithm, in addition to the bitcoin address itself. Inside Bitcoin has its own primitive, intentionally cut-off programming language that allows you to make complex transactions. For example, you can program money to be sent to several recipients (like a safe deposit box with several keys). Or include time limits for spending money (not earlier than 2013), etc.
- Transactions in the block are stacked in the form of a tree of hashes. Thus, in the future it will be possible to throw out completed transactions to save disk space without violating the integrity of the blocks.
- Bitcoin address contains a checksum. Therefore, the address can not be mistaken for missing or replacing one or more characters.

Finally

Regardless of the course of the coin (only speculators can be offended by the system), I believe that bitcoin has become very successful technically. There is something to learn and use the experience gained in the future.

Source: https://habr.com/ru/post/125572/


All Articles