Back to Home

Bitcoin from the inside for the uncomprehending

bitcoin · hashcash

Bitcoin from the inside for the uncomprehending

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

Electronic Digital Signature (EDS)

Unfortunately, I did not find suitable simple images to show how cryptography works on elliptic curves from the inside. Take this tool "on faith." The same algorithms are used in the banking sector (and not only), so the collapse of the digital signature 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 other people's transactions.

Hashing

If you understand the hashing process, skip this section. Show hashing is pretty simple. Take a number ... for example, the phone number is +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 unambiguously match any phone number some number. The process of summing is called hashing, the method itself is a hash function, the resulting number is a hash sum or just a hash.
Usually, the following properties from hashing are achieved:
- Knowing the hash amount (in our case 3), you cannot determine the original phone number.
- You can’t adjust the phone number to a predetermined amount (in our example, not applicable, mandatory for bitcoin).
- A small change in the phone number will lead to a fundamental change in the hash (in our example, not applicable, but required for bitcoin).
There are also many other useful everyday hashing examples in the wiki article.

Transfer of ownership. Public key hash

Bitcoin operates with a hash of the public key as an address for the transfer of coins. Announcing someone’s bitcoin address publicly costs nothing. Learning the source key by its hash will not be possible even for participants in the “battle of psychics”. And the key pair itself will be used only once - when transferring ownership. This ends the life of the key pair.
image
PUB1 - public key
PRIV1 - private key
HASH1 or HASH (PUB1) - hash of the public key (bitcoin address).
HASH2 or HASH (PUB2) - hash of the public key of the next owner.

Let's digress for some time from the coins. Take, for example, the owner of a car whose ownership is not in 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 moment of sale, both keys PUB1, PRIV1 of the seller remain secret. Only HASH (PUB1) and the corresponding vehicle serial number 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 serial number and hash of the public key of the second HASH owner (PUB2). And of course he signs the letter with his private key PRIV1, enclosing the public key PUB1.
- After the transfer of ownership, the secret key ceases to be relevant - there cannot be a second such letter (see. "One story"). You can check the letter itself with a public key and certify the second owner.
- Nothing is known about the second owner 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 - not a sparrow, fly out - you will not catch."
- 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 up with someone else's secret key.
image
If you replace the car with bitcoin, then the hash of the previous transaction appears instead of the serial number. And the entire chain of owners is kept publicly by each user.

“And the change !?”

Change must be left to itself. But it is conceived that the secret key is used only once, and part of its coins is sent to its own new, unlit 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 are miners digging.

In order not to be able to spend coins twice, there should be a single history of all transactions. Then only the first transaction (letter of transfer of rights to coins), or in extreme cases, one of several, will be logged. For this, transactions are combined into blocks and only “beautiful” blocks are recognized. It’s hard to find a “Beautiful Block”, it’s just like a ton of gold ore comes across only one standing nugget. In our case, the block hash must contain a certain number of zeros.
A block consists of a previous block (hash sum), a hash sum of all included transactions, and a randomly sorted 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 are at the beginning of the block hash sum? 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 selected so that each block is born approximately every 6 to 10 minutes. A reward is given for finding a block, now it is 50 coins. Also, the finder is given all transaction fees, for those transactions that are included in his block.
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 - subsequently, all split-off transactions will enter a longer chain (taking into account 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, calculate the number of coins in circulation. There is no chance for counterfeiting. The only possibility for the atrocities is only to suspend the work of Bitcoin for a while.
- At the first start, the bitcoin application creates a key pair. More precisely, he creates them immediately 100 pairs in advance, thereby making it possible to make a backup of the wallet (backup) no more than 100 operations in advance.
- Actually, the verification algorithm is indicated in the transaction, in addition to the bitcoin address itself. Inside Bitcoin has its own primitive, deliberately cropped programming languagewhich allows you to make complex transactions. For example, you can program so that money is sent to several recipients (like a safe deposit box with several keys). Or include time limits on spending money (not earlier than 2013), etc.
- Transactions in the block are stacked in the form of a hash tree. Thus, in the future, it will be possible to throw out completed transactions to save disk space without violating the integrity of the blocks.
- The Bitcoin address contains a checksum. Therefore, the address cannot be mistaken by skipping or replacing one or more characters.

Finally

Regardless of the rate of the coin (only speculators can take offense at the system), I believe that bitcoin has become very successful in technical terms. There is much to learn and use the experience gained in the future.

Read Next