Dive into the crypto mines

in bminer •  7 years ago  (edited)

The Bminer team runs a series of blog posts to deep dive into the topics of cryptocurrency mining. We hope that the deep dives help our readers to establish an overall picture of the booming ecosystem and subsequently develop their own, well-informed views of it.

Part I: Blockchains made simple

Since the prices of Bitcoin skyrocketed in 2017, mining cryptocurrency has gained a lot of tractions. A game hobbyist might use their GPUs to salvage a few coins for their own, while professional miners operates facilities that consume hundreds of megawatts for a living.

There might be quite a bit of confusions around “mining cryptocurrency”. For example, what is mining? Why mining cryptocurrency consumes more electricity than a country? What are the economics behind mining? What are the players in the ecosystems of cryptocurrency?

The Bminer team runs a series of blog posts to deep dive in the topics of cryptocurrency mining. We hope that the deep dives helps our readers to establish an overall picture of the booming ecosystem and subsequently develop their own, well-informed views of it.

The invention
The seminal Bitcoin paper describes a decentralized electronic payment system. In one sentence, it is a system that allows two parties to transfer coins securely. For example, when Alice successfully sends Bob one coin over the network, the network ensures:

Validity. Alice did have sufficient funds to send to Bob.
Integrity. Alice sends Bob exactly one coin. The transaction cannot be altered once it is confirmed.
Undeniability. Everybody in the network can see and validate the transaction easily. Therefore neither Alice, Bob or other parties can deny the transaction has happened.
Consistency and forward-progress. Eventually all participants see all transactions in order happened in the network within bounded amount of time.

Figure 1: Examples of valid transactions and possible attacks. Attacks include replaying, denying, altering the amount or the parties of the transactions, and over withdrawing funds. The network is designed to defend against various attacks listed above.

The network essentially establishes a distributed, immutable ledger. All participants of the network see a consistent view of all transactions happened in the network in the same order. The natural use case of this paradigm is the distributed ledgers and their payment networks — when everybody sees the transactions and is able to compute the balances of all participants, it is relatively straightforward to implement a payment network like Bitcoin.

A distributed immutable ledger turns out to be a very powerful paradigm. The same technology, called Blockchain, can help keep our food safer, fight human trafficking, transform medical research, etc. Using the payment network as an example, the following section describe how blockchain actually works on a very high level understanding of the technologies.

Traditional way: Central Authority
The simplest way to implement a ledger is to have an authority dictate the network. Everybody in the network trusts the authority. The model is quite similar to what happens in real-world today. An authority (e.g., bank) validates all transactions and orders all of them. Everybody in the network retrieves and validates the lists of transactions from the authority. Figure 2 describes how a payment network works with a central authority.

Figure 2: Implementing a payment network using a central authority. Users submit transactions to the authority. The authority is responsible of validating all transactions and ordering them. The authority signs and publishes the confirmed transactions to the network.

The model above is sufficiently simple. The disadvantage, however, is that the central authority is a single point of failure of the system. It is the responsibility of the authority to ensure that the ledgers are secure and scalable. Given the value of the network, it is unsurprising to see that the system demands significant amount of fees to cover the costs, or malicious people hack into stealing valuable information.

Blockchain: Distributed Immutable ledger
Instead of having a central authority, blockchain distributes the authority across all participants. The network no longer has a single point of failure, but it needs to address two new problems:

How to defend against malicious participants which include invalid transactions even tampering them?
How to reconcile if there are conflicting information in the network?
Blockchain leverages cryptographic hash function cleverly to address the above problems. A cryptographic hash function works like a fire wax seal stamp. It is difficult to fake one if you don’t have the original stamp, but it is easy to verify that the stamp and the contents that it protects are intact. Particularly, a cryptographic hash function takes a list of bytes and outputs a deterministic, fixed-length digest. Altering a single byte will make the results of the cryptographic hash function very different. There should be no quirks on a secure cryptographic hash function like SHA-256. The only way to get digests that meet certain criteria is to enumerate the input space and compute the results using the functions.

On a very high level, the Bitcoin network works as the following. To start a transaction, the originator (e.g., Alice) first broadcasts the transactions to the network. Some participants (i.e., “miners”) continuously listen to these transactions, validate them and group them as a block. Then it enumerate the nonce in the following formula so that the output digest has certain number of zero bits:

SHA256(SHA256(digestprev || block || nonce)) =0….0 || digest

Where “||” means concatenating two sequence of bytes.

The miners compete on finding such a nonce that satisfies the formula and broadcast the block to the network once such a digest is found. The participants of the network validate every transaction in the block and decide whether to accept the newly found block. The scheme is often referred as the “Proof-of-Work” scheme as it requires significant amount of work to prove the legitimate ownership of the block. Once the block is accepted across the majority of the network, the transaction is included in the blockchain.

Figure 3: The first three blocks of a blockchain. The blocks are chained together through their cryptographic signature.

One thing worth noting is that the constructs naturally form a chain of blocks as it includes the digest of previous block in the calculations. To tamper a single transaction in a block, the adversary needs to compute a matching digest of the block it resides as well as all subsequent blocks. The blockchain is effectively immutable as the costs of attack are prohibitively high. At the point of writing, mining one single block (which contains 12.5 BTC for rewards) could cost at least $40,000 in United States. Tampering a transaction that happens an hour ago requires re-mining about 6 blocks, which is equivalent to $240,000, assuming everybody else in the network makes no progress on mining.

Another problem is that the miners might have different views of the pending transactions thus they mine towards different blocks. To reconcile the effort, the blockchain enforce the “longest win” rule, that is, the participants always favor the longest chain. Since the average block time (~10 minutes) is much larger than the network latency (in the orders of milliseconds), all participants have strong incentives to switch to the latest found block, therefore the network converges well in practice.

What’s next
Blockchain uses cryptography cleverly to implement distributed immutable ledgers which open up new opportunities of transcending our everyday lives. This blog post describes the mechanism behind the blockchain technology. In the next blog post of this series we will dive into the economics of mining to understand the incentive structures of ecosystems.

What‘s Bminer
Bminer is a highly optimized Equihash miner that runs on modern NVIDIA GPUs (Maxwell and Pascal, i.e. GPUs that have compute capability 5.0 or above). Bminer is the one of the fastest publicly available Equihash miners today — we use various techniques including tiling and pipelining to realize the full potentials of the hardware.

Downloads: https://www.bminer.me/

From: https://medium.com/@realbminer/dive-into-the-crypto-mines-7efafa49787f

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @pontuslse! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @pontuslse! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!