What is merged mining bitcoin

Merged mining specification

NOTE: This standard is used by Namecoin, but new merged mining data should likely propose a new BIP to supercede it with something based on p2pool’s merged mining.

Contents

Terminology

Aux proof-of-work block

This is used to prove work on the auxiliary blockchain. In vinced’s original implementation it’s generated by calling the getworkaux RPC method on the parent blockchain client (bitcoind) and then the work is then submitted by passing it to the auxiliary chain client (namecoind) as the second parameter to getauxblock.

When receiving an Aux proof-of-work block in a «block» network message, the data received is similar to a standard block, but extra data is inserted between the nonce and txn_count elements. In the below table, the shaded rows are the same as the standard block definition:

Field Size Description Data type Comments
4 version uint32_t
32 prev_block char[32]
32 merkle_root char[32]
4 timestamp uint32_t
4 bits uint32_t
4 nonce uint32_t
? coinbase_txn txn Coinbase transaction that is in the parent block, linking the AuxPOW block to its parent block
32 block_hash char[32] Hash of the parent_block header
? coinbase_branch Merkle branch The merkle branch linking the coinbase_txn to the parent block’s merkle_root
? blockchain_branch Merkle branch The merkle branch linking this auxiliary blockchain to the others, when used in a merged mining setup with multiple auxiliary chains
80 parent_block Block header Parent block header
? txn_count var_int
? txns tx[]

For the coinbase_branch merkle branch, because the coinbase transaction is the first transaction in the block (if using Bitcoin as a parent chain, i.e. hash #7 in the example given below), the branch_side_mask is always going to be all zeroes, because the branch hashes will always be «on the right» of the working hash.

When only working on one auxiliary blockchain, the blockchain_branch link is not needed, and is nulled-out by being presented as 5 bytes of zeros (interpreted as a one-byte var_int indicating a branch_length of zero, and a 32-bit (4 byte) branch_side_mask of all zeroes).

Note that the block_hash element is not needed as you have the full parent_block header element and can calculate the hash from that. The current Namecoin client doesn’t check this field for validity, and as such some AuxPOW blocks have it little-endian, and some have it big-endian.

Merkle Branch

Say Alice created a Merkle tree, and it’s root element is publicly available. For example:

Now she wants to prove to Bob that a given hash (#10) was part of that tree, but Bob doesn’t have the full tree (only the public root; hash #0). Alice can send Bob all the hashes she used to make the tree in the first place (hashes #7-#14, total of 7 extra hashes), so Bob can build the whole tree to verify the root is the same, but that’s rather data-intensive. Instead, she could give Bob hashes #9, #3, and #2 (one from each level of the tree, working #10 back to the root). Without Bob knowing the structure of the tree, Alice also has to tell Bob what order to apply the hashes in (since hash(#9, #10) == #4, but hash(#10, #9) != #4). So Alice tells Bob «left, left, right» to indicate which operand #9, #3, and #2 are, respectively. That can be encoded as a bitmask and take up very little data to transmit. So, instead of transmitting 7 hashes to Bob, Alice transmits 3 hashes and a bitmask. The data savings get even more pronounced if the merkle tree gets even bigger.

That is the overall premise, and specifically for the AuxPOW protocol, it’s been termed a «merkle branch» (since it’s one pathway of a merkle tree), and is transmitted thus:

Field Size Description Data type Comments
? branch_length var_int The number of hashes making up the branch
? branch_hash[] char[32] Individual hash in the branch; repeated branch_length number of times
4 branch_side_mask int32_t Bitmask of which side of the merkle hash function the branch_hash element should go on. Zero means it goes on the right, One means on the left. It is equal to the index of the starting hash within the widest level of the merkle tree for this merkle branch.

The first branch_hash is used first, and the least-significant bit of the branch_side_mask determines its hash position. Then the second branch_hash is applied with the second-least-significant bit of the branch_side_mask, etc. So for Alice’s example, branch_length would be 3, the hashes would be given in the order #9, #3, then #2, and the branch_side_mask would be 0b011 = 3 (equal to the index of #10 in the widest level of the merkle tree).

Merged mining coinbase

Insert exactly one of these headers into the scriptSig of the coinbase transaction in the parent block.

Field Size Description Data type Comments
4 magic char[4] 0xfa, 0xbe, ‘m’, ‘m’ (only required if over 20 bytes past the start of the script; optional otherwise)
32 block_hash char[32] Hash of the AuxPOW block header / root of the chain merkle branch
4 merkle_size int32_t Number of entries in aux work merkle tree. (Must be a power of 2)
4 merkle_nonce int32_t Nonce used to calculate indexes into aux work merkle tree; you may as well leave this at zero

That string of 44 bytes being part of the coinbase script means that the miner constructed the AuxPOW Block before creating the coinbase.

Aux work merkle tree

If you’re just mining a single auxiliary chain and using getauxblock, you don’t have to worry about this — just set the merkle tree hash in the coinbase to the aux chain block’s hash as given by getauxblock, the merkle size to 1, and the merkle nonce to 0. If you’re mining more than one, this is a bit broken. It uses the following algorithm to convert the chain ID to a slot at the base of the merkle tree in which that chain’s block hash must slot:

The idea is that you can increment merkle_nonce until the chains you’re mining don’t clash for the same slot. The trouble is that this doesn’t work; because it just adds a number derived from the merkle_nonce to the chain_id, if two chains clash for one nonce they’ll still clash for all possible nonces. [1] New implementers: please pick your chain_id so that not clashing with existing chains requires as small a value of merkle_size as possible, or use a better algorithm to calculate the slot id for your chain.

Once you know where in the merkle tree the different chains go, reverse the bytes of each chain’s block hash as given you by getauxblock (so the byte at the start moves to the end, etc) and insert into the appropriate slot, filling the unused ones with arbitrary data. Now build up the merkle tree as usual by taking each pair of values in the initial row and double SHA-256 hashing them to give a new row of hashes, repeating this until you only have a single hash. This last hash is the merkle root. You need to reverse the bytes of this again before inserting it into the coinbase. If you’re not using getauxblock to get the block hash, you can skip the first reversal but still need to reverse the final merkle root when adding it to the coinbase.

Читайте также:  Рассчитать чдд индекс рентабельности срок окупаемости

The aux proof-of-work also needs a merkle branch, which is built as follows: find the location of the block’s hash in the merkle tree, and add the other value that you hashed it with in building the merkle tree. Now add the value you hashed that result with. Keep doing this until you reach the root. The merkle root itself is never included in the merkle branch. If you just have a single aux chain, this can be left entirely empty. (It also appears you don’t need to reverse these hashes.)

Example

This is the AuxPOW block at height 19200 in the Namecoin chain (the first block that allowed AuxPOW authentication). It has a hash of d8a7c3e01e1e95bcee015e6fcc7583a2ca60b79e5a3aa0a171eddd344ada903d, and only has one Namecoin transaction (coinbase sending 50 NMC to the miner’s address). The parent block that was used as Proof of Work has a hash less than the difficulty target of Namecoin at the time, but not the Bitcoin target:

Hence, this AuxPOW block was valid in the Namecoin blockchain, but not in the Bitcoin blockchain (you will find no Bitcoin block with the hash starting 3d47277359fb969c. If it were, it would be right after 4a59b7deb5c4e01b, since that’s the previous_block hash used)

Источник

How Does Bitcoin Mining Work?

What Is Bitcoin Mining?

Bitcoin mining is the process by which new bitcoins are entered into circulation, but it is also a critical component of the maintenance and development of the blockchain ledger. It is performed using very sophisticated computers that solve extremely complex computational math problems.

Cryptocurrency mining is painstaking, costly, and only sporadically rewarding. Nonetheless, mining has a magnetic appeal for many investors interested in cryptocurrency because of the fact that miners are rewarded for their work with crypto tokens. This may be because entrepreneurial types see mining as pennies from heaven, like California gold prospectors in 1849. And if you are technologically inclined, why not do it?

However, before you invest the time and equipment, read this explainer to see whether mining is really for you. We will focus primarily on Bitcoin (throughout, we’ll use «Bitcoin» when referring to the network or the cryptocurrency as a concept, and «bitcoin» when we’re referring to a quantity of individual tokens).

Key Takeaways

  • By mining, you can earn cryptocurrency without having to put down money for it.
  • Bitcoin miners receive Bitcoin as a reward for completing «blocks» of verified transactions, which are added to the blockchain.
  • Mining rewards are paid to the miner who discovers a solution to a complex hashing puzzle first, and the probability that a participant will be the one to discover the solution is related to the portion of the total mining power on the network.
  • You need either a GPU (graphics processing unit) or an application-specific integrated circuit (ASIC) in order to set up a mining rig.

A New Gold Rush

The primary draw for many mining is the prospect of being rewarded with Bitcoin. That said, you certainly don’t have to be a miner to own cryptocurrency tokens. You can also buy cryptocurrencies using fiat currency; you can trade it on an exchange like Bitstamp using another crypto (as an example, using Ethereum or NEO to buy Bitcoin); you even can earn it by shopping, publishing blog posts on platforms that pay users in cryptocurrency, or even set up interest-earning crypto accounts.

An example of a crypto blog platform is Steemit, which is kind of like Medium except that users can reward bloggers by paying them in a proprietary cryptocurrency called STEEM. STEEM can then be traded elsewhere for Bitcoin.

The Bitcoin reward that miners receive is an incentive that motivates people to assist in the primary purpose of mining: to legitimize and monitor Bitcoin transactions, ensuring their validity. Because these responsibilities are spread among many users all over the world, Bitcoin is a «decentralized» cryptocurrency, or one that does not rely on any central authority like a central bank or government to oversee its regulation.

How to Mine Bitcoins

Miners are getting paid for their work as auditors. They are doing the work of verifying the legitimacy of Bitcoin transactions. This convention is meant to keep Bitcoin users honest and was conceived by Bitcoin’s founder, Satoshi Nakamoto. By verifying transactions, miners are helping to prevent the «double-spending problem.»

Double spending is a scenario in which a Bitcoin owner illicitly spends the same bitcoin twice. With physical currency, this isn’t an issue: once you hand someone a $20 bill to buy a bottle of vodka, you no longer have it, so there’s no danger you could use that same $20 bill to buy lotto tickets next door. While there is the possibility of counterfeit cash being made, it is not exactly the same as literally spending the same dollar twice. With digital currency, however, as the Investopedia dictionary explains, «there is a risk that the holder could make a copy of the digital token and send it to a merchant or another party while retaining the original.»

Let’s say you had one legitimate $20 bill and one counterfeit of that same $20. If you were to try to spend both the real bill and the fake one, someone that took the trouble of looking at both of the bills’ serial numbers would see that they were the same number, and thus one of them had to be false. What a Bitcoin miner does is analogous to that—they check transactions to make sure that users have not illegitimately tried to spend the same bitcoin twice. This isn’t a perfect analogy—we’ll explain in more detail below.

Once miners have verified 1 MB (megabyte) worth of Bitcoin transactions, known as a «block,» those miners are eligible to be rewarded with a quantity of bitcoin (more about the bitcoin reward below as well). The 1 MB limit was set by Satoshi Nakamoto, and is a matter of controversy, as some miners believe the block size should be increased to accommodate more data, which would effectively mean that the bitcoin network could process and verify transactions more quickly.

Note that verifying 1 MB worth of transactions makes a coin miner eligible to earn bitcoin—not everyone who verifies transactions will get paid out.

1MB of transactions can theoretically be as small as one transaction (though this is not at all common) or several thousand. It depends on how much data the transactions take up.

«So after all that work of verifying transactions, I might still not get any bitcoin for it?»

That is correct.

To earn bitcoins, you need to meet two conditions. One is a matter of effort; one is a matter of luck.

1) You have to verify

1MB worth of transactions. This is the easy part.

2) You have to be the first miner to arrive at the right answer, or closest answer, to a numeric problem. This process is also known as proof of work.

«What do you mean, ‘the right answer to a numeric problem’?»

The good news: No advanced math or computation is involved. You may have heard that miners are solving difficult mathematical problems—that’s not exactly true. What they’re actually doing is trying to be the first miner to come up with a 64-digit hexadecimal number (a «hash») that is less than or equal to the target hash. It’s basically guesswork.

Читайте также:  Инвестиции список литературы использованной литературы

The bad news: It’s guesswork, but with the total number of possible guesses for each of these problems being on the order of trillions, it’s incredibly arduous work. In order to solve a problem first, miners need a lot of computing power. To mine successfully, you need to have a high «hash rate,» which is measured in terms of megahashes per second (MH/s), gigahashes per second (GH/s), and terahashes per second (TH/s).

That is a great many hashes.

If you want to estimate how much bitcoin you could mine with your mining rig’s hash rate, the site Cryptocompare offers a helpful calculator.

Mining and Bitcoin Circulation

In addition to lining the pockets of miners and supporting the Bitcoin ecosystem, mining serves another vital purpose: It is the only way to release new cryptocurrency into circulation. In other words, miners are basically «minting» currency. For example, as of Nov. 2020, there were around 18.5 million bitcoins in circulation.

Aside from the coins minted via the genesis block (the very first block, which was created by founder Satoshi Nakamoto), every single one of those bitcoins came into being because of miners. In the absence of miners, Bitcoin as a network would still exist and be usable, but there would never be any additional bitcoin. There will eventually come a time when Bitcoin mining ends; per the Bitcoin Protocol, the total number of bitcoins will be capped at 21 million.

However, because the rate of bitcoin «mined» is reduced over time, the final bitcoin won’t be circulated until around the year 2140. This does not mean that transactions will cease to be verified. Miners will continue to verify transactions and will be paid in fees for doing so in order to keep the integrity of Bitcoin’s network.

Aside from the short-term Bitcoin payoff, being a coin miner can give you «voting» power when changes are proposed in the Bitcoin network protocol. In other words, miners have a degree of influence on the decision-making process on such matters as forking.

How Much a Miner Earns

The rewards for Bitcoin mining are reduced by half every four years. When bitcoin was first mined in 2009, mining one block would earn you 50 BTC. In 2012, this was halved to 25 BTC. By 2016, this was halved again to 12.5 BTC. On May 11, 2020, the reward halved again to 6.25 BTC. In November of 2020, the price of Bitcoin was about $17,900 per bitcoin, which means you’d earn $111,875 (6.25 x 17,900) for completing a block. Not a bad incentive to solve that complex hash problem detailed above, it might seem.

If you want to keep track of precisely when these halvings will occur, you can consult the Bitcoin Clock, which updates this information in real-time. Interestingly, the market price of Bitcoin has, throughout its history, tended to correspond closely to the reduction of new coins entered into circulation. This lowering inflation rate increased scarcity and historically the price has risen with it.

If you are interested in seeing how many blocks have been mined thus far, there are several sites, including Blockchain.info, that will give you that information in real-time.

What Do I Need To Mine Bitcoins?

Although early on in Bitcoin’s history individuals may have been able to compete for blocks with a regular at-home computer, this is no longer the case. The reason for this is that the difficulty of mining Bitcoin changes over time.

In order to ensure the smooth functioning of the blockchain and its ability to process and verify transactions, the Bitcoin network aims to have one block produced every 10 minutes or so. However, if there are one million mining rigs competing to solve the hash problem, they’ll likely reach a solution faster than a scenario in which 10 mining rigs are working on the same problem. For that reason, Bitcoin is designed to evaluate and adjust the difficulty of mining every 2,016 blocks, or roughly every two weeks.

When there is more computing power collectively working to mine for bitcoins, the difficulty level of mining increases in order to keep block production at a stable rate. Less computing power means the difficulty level decreases. To get a sense of just how much computing power is involved, when Bitcoin launched in 2009 the initial difficulty level was one. As of Nov. 2019, it is more than 13 trillion.

All of this is to say that, in order to mine competitively, miners must now invest in powerful computer equipment like a GPU (graphics processing unit) or, more realistically, an application-specific integrated circuit (ASIC). These can run from $500 to the tens of thousands. Some miners—particularly Ethereum miners—buy individual graphics cards (GPUs) as a low-cost way to cobble together mining operations.

The photo below is a makeshift, homemade mining machine. The graphics cards are those rectangular blocks with whirring fans. Note the sandwich twist-ties holding the graphics cards to the metal pole. This is probably not the most efficient way to mine, and as you can guess, many miners are in it as much for the fun and challenge as for the money.

The «Explain It Like I’m Five» Version

The ins and outs of Bitcoin mining can be difficult to understand as is. Consider this illustrative example of how the hash problem works: I tell three friends that I’m thinking of a number between one and 100, and I write that number on a piece of paper and seal it in an envelope. My friends don’t have to guess the exact number; they just have to be the first person to guess any number that is less than or equal to the number I am thinking of. And there is no limit to how many guesses they get.

Let’s say I’m thinking of the number 19. If Friend A guesses 21, they lose because of 21>19. If Friend B guesses 16 and Friend C guesses 12, then they’ve both theoretically arrived at viable answers, because of 16

What Is a «64-Digit Hexadecimal Number»?

Well, here is an example of such a number:

The number above has 64 digits. Easy enough to understand so far. As you probably noticed, that number consists not just of numbers, but also letters of the alphabet. Why is that?

To understand what these letters are doing in the middle of numbers, let’s unpack the word «hexadecimal.»

As you know, we use the «decimal» system, which means it is base 10. This, in turn, means that every digit of a multi-digit number has 10 possibilities, zero through nine.

«Hexadecimal,» on the other hand, means base 16, as «hex» is derived from the Greek word for six and «deca» is derived from the Greek word for 10. In a hexadecimal system, each digit has 16 possibilities. But our numeric system only offers 10 ways of representing numbers (zero through nine). That’s why you have to stick letters in, specifically letters a, b, c, d, e, and f.

If you are mining Bitcoin, you do not need to calculate the total value of that 64-digit number (the hash). I repeat: You do not need to calculate the total value of a hash.

So, what do «64-digit hexadecimal numbers» have to do with Bitcoin mining?

Remember that ELI5 analogy, where I wrote the number 19 on a piece of paper and put it in a sealed envelope?

Читайте также:  Usd криптовалюта как майнить

In Bitcoin mining terms, that metaphorical undisclosed number in the envelope is called the target hash.

What miners are doing with those huge computers and dozens of cooling fans is guessing at the target hash. Miners make these guesses by randomly generating as many «nonces» as possible, as fast as possible. A nonce is short for «number only used once,» and the nonce is the key to generating these 64-bit hexadecimal numbers I keep talking about. In Bitcoin mining, a nonce is 32 bits in size—much smaller than the hash, which is 256 bits. The first miner whose nonce generates a hash that is less than or equal to the target hash is awarded credit for completing that block and is awarded the spoils of 6.25 BTC.

In theory, you could achieve the same goal by rolling a 16-sided die 64 times to arrive at random numbers, but why on earth would you want to do that?

The screenshot below, taken from the site Blockchain.info, might help you put all this information together at a glance. You are looking at a summary of everything that happened when block #490163 was mined. The nonce that generated the «winning» hash was 731511405. The target hash is shown on top. The term «Relayed by Antpool» refers to the fact that this particular block was completed by AntPool, one of the more successful mining pools (more about mining pools below).

As you see here, their contribution to the Bitcoin community is that they confirmed 1768 transactions for this block. If you really want to see all 1768 of those transactions for this block, go to this page and scroll down to the heading «Transactions.»

«So how do I guess at the target hash?»

All target hashes begin with zeros—at least eight zeros and up to 63 zeros.

There is no minimum target, but there is a maximum target set by the Bitcoin Protocol. No target can be greater than this number:

Here are some examples of randomized hashes and the criteria for whether they will lead to success for the miner:

«How do I maximize my chances of guessing the target hash before anyone else does?»

You’d have to get a fast mining rig, or, more realistically, join a mining pool—a group of coin miners who combine their computing power and split the mined Bitcoin. Mining pools are comparable to those Powerball clubs whose members buy lottery tickets en masse and agree to share any winnings. A disproportionately large number of blocks are mined by pools rather than by individual miners.

In other words, it’s literally just a numbers game. You cannot guess the pattern or make a prediction based on previous target hashes. The difficulty level of the most recent block at the time of writing is about 17.59 trillion, meaning that the chance of any given nonce producing a hash below the target is one in 17.59 trillion. Not great odds if you’re working on your own, even with a tremendously powerful mining rig.

«How do I decide whether Bitcoin will be profitable for me?»

Not only do miners have to factor in the costs associated with expensive equipment necessary to stand a chance of solving a hash problem. They must also consider the significant amount of electrical power mining rigs utilize in generating vast quantities of nonces in search of the solution. All told, Bitcoin mining is largely unprofitable for most individual miners as of this writing. The site Cryptocompare offers a helpful calculator that allows you to plug in numbers such as your hash speed and electricity costs to estimate the costs and benefits.

What Are Coin Mining Pools?

Mining rewards are paid to the miner who discovers a solution to the puzzle first, and the probability that a participant will be the one to discover the solution is equal to the portion of the total mining power on the network.

Participants with a small percentage of the mining power stand a very small chance of discovering the next block on their own. For instance, a mining card that one could purchase for a couple of thousand dollars would represent less than 0.001% of the network’s mining power. With such a small chance at finding the next block, it could be a long time before that miner finds a block, and the difficulty going up makes things even worse. The miner may never recoup their investment. The answer to this problem is mining pools.

Mining pools are operated by third parties and coordinate groups of miners. By working together in a pool and sharing the payouts among all participants, miners can get a steady flow of bitcoin starting the day they activate their miners. Statistics on some of the mining pools can be seen on Blockchain.info.

«I’ve done the math. Forget mining. Is there a less onerous way to profit from cryptocurrencies?»

As mentioned above, the easiest way to acquire Bitcoin is to simply buy it on one of the many exchanges. Alternately, you can always leverage the «pickaxe strategy.» This is based on the old saw that during the 1849 California gold rush, the smart investment was not to pan for gold, but rather to make the pickaxes used for mining.

To put it in modern terms, invest in the companies that manufacture those pickaxes. In a cryptocurrency context, the pickaxe equivalent would be a company that manufactures equipment used for Bitcoin mining. You may consider looking into companies that make ASICs equipment or GPUs instead, for example.

The legality of Bitcoin mining depends entirely on your geographic location. The concept of Bitcoin can threaten the dominance of fiat currencies and government control over the financial markets. For this reason, Bitcoin is completely illegal in certain places.

Bitcoin ownership and mining are legal in more countries than not. Some examples of places where it is illegal are Algeria, Egypt, Morocco, Bolivia, Ecuador, Nepal, and Pakistan.   Overall, Bitcoin use and mining are legal across much of the globe.

Risks of Mining

The risks of mining are often that of financial risk and a regulatory one. As mentioned, Bitcoin mining, and mining in general, is a financial risk. One could go through all the effort of purchasing hundreds or thousands of dollars worth of mining equipment only to have no return on their investment. That said, this risk can be mitigated by joining mining pools. If you are considering mining and live in an area that it is prohibited you should reconsider. It may also be a good idea to research your countries regulation and overall sentiment towards cryptocurrency before investing in mining equipment.

One additional potential risk from the growth of Bitcoin mining (and other proof-of-work systems as well) is the increasing energy usage required by the computer systems running the mining algorithms. While microchip efficiency has increased dramatically for ASIC chips, the growth of the network itself is outpacing technological progress. As a result, there are concerns about the environmental impact and carbon footprint of Bitcoin mining.

There are, however, efforts to mitigate this negative externality by seeking cleaner and green energy sources for mining operations (such as geo-thermal or solar), as well as utilizing carbon offset credits. Switching to less energy-intensive consensus mechanisms like proof-of-stake (PoS), which Ethereum is planning to do, is another strategy; however, PoS comes with its own set of drawbacks and inefficiencies.

Источник

Оцените статью