Introduction to the

What does a wallet do in bitcoin? What are the characteristics of bitcoin transactions? How do you fake a bitcoin transaction? Today let’s learn about wallets and transactions in Bitcoin.

The foundation of bitcoin cryptography

As we mentioned earlier, bitcoin is not a new technology, but a clever re-application of old technologies such as P2P networks, distributed systems, cryptography, and consensus algorithms.

Cryptographic calculations are used in both wallet and transaction generation verification. Here’s a look at some of the cryptography techniques used in Bitcoin.

More highlights:

  • Blockchain from getting started to Giving up series tutorials – with ongoing updates covering cryptography, Hyperledger, Ethereum,Libra, Bitcoin and more
  • Spring Boot 2.X Series tutorials: Learn Spring Boot from Scratch in seven days – continuous updates
  • Spring 5.X Series tutorials: Everything you can think of in Spring5 – constantly updated
  • Java Programmer from Handyman to Expert to God (2020 edition) – Ongoing updates with detailed articles and tutorials

One-way hash function (hash algorithm)

Before introducing one-way hash functions, let’s look at the situations in which one-way hash functions are needed.

If you need to download a piece of software from a foreign website, but for some reason the foreign network is too slow, downloading a few gigabytes of data is almost impossible. Just domestic mirror website, you can download data from home. But how to ensure that the domestic image is not tampered with? This is where the one-way hash function comes in. Generally, websites provide MD5 or SHA values as authentication values.

A one-way hash function has one input and one output. The input is called a message and the output is a hash value.

The length of the hash value is independent of the length of the message. A fixed length hash value is computed regardless of the size of the message length.

The hash algorithm has the following characteristics:

  1. The ability to calculate a fixed-length hash value from a message of arbitrary length.

  2. Make the calculation fast.

  3. The hash value varies from message to message.

    This means that even a small change in the hash value can cause a huge change in the overall hash value.

    Because the size of the hash value is fixed, it is possible for different messages to produce the same hash value. This situation is called a collision.

    The nature of the collision that is difficult to detect is called collision resistance. When given the hash value of a message, it must be guaranteed that it is difficult to find another message with the same hash value as the message.

  4. A one-way hash function must be unidirectional. Unidirectional is the inability to reverse the properties of a message by hashing values.

Bitcoin uses SHA256, one of a family of Secure Hash Algorithms (SHA-1, SHA-224, SHA-384, and SHA-512), SHA was designed by the NATIONAL Security Agency (NSA) and published by the National Institute of Standards and Technology (NIST), It applies to the DigitalSignature Algorithm DSA defined in the DigitalSignature Standard (DSS).

RIPEMD (RACE Integrity Primitives Evaluation Message Digest) was proposed by Hans Dobbertin and other three people on the basis of MD4 and MD5 in 1996.

Asymmetric encryption algorithm

Asymmetric encryption algorithms, also called public key cryptography algorithms, encrypt and decrypt plain ciphertext by generating public and private keys.

Asymmetric encryption algorithms require two keys: a publickey and a privatekey. The public key and private key are a pair. If the public key is used to encrypt data, only the corresponding private key can be used to decrypt data. If data is encrypted with a private key, it can only be decrypted with the corresponding public key. Because encryption and decryption use two different keys, the algorithm is called asymmetric encryption.

Read more: Homomorphic encryption

Homomorphic encryption is a form of encryption that allows one to perform certain algebraic operations on the ciphertext and still obtain the same result as the same operation on the plain text. In other words, it allows people to do things like retrieve and compare encrypted data to get the right results, without decrypting the data in the process. Its significance lies in truly fundamentally solving the confidentiality problem when entrusting data and its operation to a third party, such as for various cloud computing applications.

Key, address and wallet

Ownership of bitcoin is established through digital keys, bitcoin addresses and digital signatures. Digital keys are not actually stored on the network, but are generated by users and stored in a file or simple database called a wallet. The digital key stored in the user’s wallet is completely independent of the Bitcoin protocol and can be generated and managed by the user’s wallet software without the need for a blockchain or network connection. Keys implement many interesting features of Bitcoin, including decentralized trust and control, authentication of ownership, and a security model based on cryptographic proof.

A Bitcoin wallet only contains a private key, not bitcoin. Each user has a wallet that contains multiple private keys. The wallet contains pairs of private and public keys. The user signs the transaction with these private keys, thereby proving that they own the output of the transaction (that is, the bitcoin in it). Bitcoin is stored on the blockchain as a transaction output (usually referred to as Vout or TXout).

If a wallet contains only a private key, what is the address of the wallet? The wallet address is derived from the hash value of the public key, as shown below:

  1. First, a “private key” is generated using a random number generator. This is typically a 256-bit number that allows operations on bitcoins in the corresponding “wallet address” and must be stored securely.

  2. Private key is processed by SECP256K1 algorithm to generate public key. SECP256K1 is an elliptic curve algorithm. The public key can be calculated based on a known private key, but the private key cannot be calculated backwards if the public key is known. This is the basis of the algorithm that keeps Bitcoin safe.

  3. Like SHA256, RIPEMD160 is a Hash algorithm. The public key Hash can be calculated from the public key Hash, but the reverse is not possible.

  4. The address version number of a byte is concatenated to the “public key hash” header (for pubkey addresses on the Bitcoin network, this byte is “0”), then it is SHA256 twice, and the first 4 bytes of the result are concatenated to its tail as the “public key hash” check value.

  5. Encode the result of the previous step in BASE58 (a custom version of Bitcoin), and you get the “wallet address.” For example, 1 a1zp1ep5qgefi2dmptftl5ttmv7divfna.

Therefore, the relationship between private key, public key and wallet address is shown as follows:

You see the wallet address 1 a1zp1ep5qgefi2dmptftl5ttmv7divfna have any idea?

Some people must be thinking that such a long string of letters and numbers is too hard to remember. Can you produce a wallet address that is easy to remember? Such as MyNameIsHanMeiMei… What about addresses that start like this?

Can of course, this is called beautiful number address, only need a lot of calculation power just line.

Transactions in Bitcoin

Simply put, a transaction is a notification to the entire network that the owner of a Bitcoin has authorized the transfer of bitcoin to someone else. The new owner can authorize it again, transferring it to someone else in the bitcoin ownership chain.

Note that in the world of Bitcoin there are neither accounts nor balances, only UTXOs scattered into the blockchain.

How do I understand this UTXO? There is no account and no balance, so how is the amount in the wallet calculated?

Don’t worry, let’s talk it through.

In Bitcoin, money transfers between bitcoin wallets are made through transactions.

Let’s look at a standard transaction process.

So where did the world’s first Bitcoin come from?

A: It’s from mining. Ok, our transaction 001 represents A mining process. In this transaction, the input is mining, the output number is 1, the number of BTC is 50, and the destination address is A, indicating that the 50 BTC is given to A.

Then, if A wants to send 25 BTC to B, how can we construct this transaction?

Again, we need an input, which is output 1 of the 001 transaction, denoted by 001.1. The output is divided into two parts. The number of the first output is 1, which means 25 BTC should be paid to B. The second output number, 2, means that the remaining BTC should be returned to A.

You might ask, well, the input is 50BTC, and the two outputs add up to 45 BTC, so that’s like 5 BTC missing, right? That’s right, these five BTC’s are what the miners get from digging.

Then, A continues to transfer money to C, the same way, connecting transactions one by one.

From the above example, we can see that in fact money is stored in Transaction records one by one, and the Unspent Outputs are called UTXO (Unspent Transaction Outputs).

So how do you make sure that the money that you transfer to B doesn’t get spent by someone else? This involves the encryption process of the transaction.

Let’s take a closer look at what constitutes a transaction using a single input and output as an example:

In the figure above, the input to the transaction is the TXID, which was previously generated with the transaction ID that did not cost heat output. Output index is the output ID of the transaction.

A very important ScriptSig is the validation of entered transactions, indicating that the user has transfer rights to the account.

The output is a script, and only those who meet the conditions for the script to run can spend the output. This is the script that ScriptSig validates.

Let’s see how the script does the authentication.

There are two forms of standard output for bitcoin. Pay To Public Key Hash (P2PKH) and Pay To Script Hash (P2SH). The difference between the two is that one is the hash output to the public key and the other is the hash output to any script.

In order to ensure that the output can only be spent by a specific person, it is generally output directly to the other party’s public key hash. Since only the other party’s private key can generate the public key hash, only the other party can validate the output.

However, it is a hassle to know the other party’s public key hash every time. It is easier for the sender to simply output a specific hash value, as long as the other party can generate the hash.

The following example is a script form for P2PKH.

The output of P2PKH is a script in which an important value is the PK hash.

How do you test that?

The verifier provides two values, sig and PubKey. Since the virtual machine of Bitcoin is a stack structure, we first push these two values onto the stack.

OP_DUP is then called to copy the uppermost PubKey, and the OP_HASH160 algorithm is then called to calculate the Pk Hash, and the Pk Hash saved by the sender is then pushed onto the stack. Next, OP_EQUALVERIFY is called to compare the two PK hashes.

If the comparison is successful, the last step is to verify that the Sig and PubKey match.

If both are successful, the receiver is indeed the owner of the PK Hash. Then the other person can use it as much as they want.

Extended reading: Turing incompleteness

AlanTurin, von neumann’s fellow founder of modern computing, came up in 1950 with what became known as the “Turing test” for determining whether computers could actually “think” like humans.

He imagines a supercomputer and a person hiding behind the scenes answering questions from questioners who try to tell which is which.

Alan argued that if the computer was so cleverly disguised that no one could actually tell it apart from a real person, then we could claim that it was capable of thinking, or consciousness (his original word was’ intelligence ‘).

In computability theory, if a series of rules for manipulating data (such as instruction sets, programming languages, cellular automata) can be calculated in a certain order, it is called Turing complete.

The Bitcoin scripting language is not Turing-complete and has certain limitations. It does not have loop statements or complex conditional control statements.

conclusion

This article introduces the concept of bitcoin wallet and transaction, I hope you can like it.

Author: Flydean program stuff

Link to this article: www.flydean.com/bitcoin-tra…

Source: Flydean’s blog

Welcome to pay attention to my public number: procedures those things, more wonderful waiting for you!