What does actually miner do?
Miner just picks some unconfirmed transactions from the mempool and uses the hash of the previous block and tries to find out some output (hash of the current block) continuously. We know that output will surely come out (sometimes takes a long time than usual) but the interesting thing is the probability of the next block in the blockchain will be mined.
Well, that’s calculated by hashing power of your machine/ Total hashing power of the entire network.
Miners find the new block hash using previous block hash which satisfies the output and given difficulty level. After finding that block miner broadcast that blocks to other miners.
The most common question arises the difference between 51% attack and double spend.
One special property about the blockchain a longer chain is the survival chain.
What does that mean?
In the case of splitting a chain (Assuming fork), if any problem happens longer chains survive.
So how does it decide which one is the longest chain?
Basically, the chain which has more proof of work is considered as a longer chain and that chain survived and more likely longer chain has more proof of work because any other split chain is shorter than the parent chain and it obviously has less proof of work.
Double Spend
In simple words, double spending is an assault where the given arrangement of coins is spent more than once. In more simple words a double spend means the same coins can be used in more than one transaction.
What is BIP?
BIP stands for Bitcoin Implementation Protocols. It’s a standard for proposing changes to the Bitcoin convention. In some cases BIPs are proposed changes to the BIP procedure itself.
Now let’s dive into some deeper concepts.
Also Read: How to Buy Bitcoin?
How does Double Spend attack perform?
Assuming a bitcoin blockchain is continuously growing, miner, adding block after block in that blockchain.
Now, you join a mining pool with 51%+ hashing power (let say 55% or 60%) and the pool will mine block much faster than others and having a high probability of next block in the blockchain network. So, as far as an attacker has the advantage of mining block faster than others, attacker mined the block now its job is to broadcast that block to other miners but attacker here didn’t broadcast that block and gone offline.
Example: Assume block number is 500 is the latest block solved and attacker solved a block number 501 and gone offline and using previous block hash and every values and input and solving more blocks 502, 503, 503 and so on and till now haven’t broadcast any block yet after going offline.
The attacker still have that block and continues doing its job (this type of mining often called selfish mining). So, attacker mining more blocks corresponding to the previous block using those block values and input finds another block and continue this process and still, the attacker didn’t broadcast any block to the network.
Now, the upper scenario is the rest of the miner are still finding block 501 on the basis of the previous block (which is block 500) and so on but they take more time in producing block because the attacker has more hash power than other miners in that network means he will generate longer chain in less time w.r.t other miners but in the offline medium.
Assume attacker has 60% hash power and all other combine is 40% then the probability is higher than attacker will find the next block.
The attacker launches its chain and becomes the official chain. Now the question of how that attacker chain joins the previous chain and becomes official and legit chain?
Here is the answer as said in the above concept longer chain is the survival chain if anything wrong happens then chain which has more no. of proof of work (POW) will survive and other blocks mined by rest of the miners are wasted.
We have just learned a deeper concept of double spend but why it is a threat to the network
/*Let have one concept of bitcoin: Transaction are sum up of each and every transaction in a blockchain
Balances in the blockchain are sum up of every transaction. Assume current latest block is 500 and if you have any bitcoin address then you can your balance whatever incoming and outgoing transactions happened in already mined blocks. Basically your balances are the sum of every transaction in your address.*/
Now below image blockchain which is running by miners and the chain running by the attacker will have the longest chain as of now. The green glowing chain is a normal chain and the red one is the attacker generated chain. Now imagine a person named *Charlie* accepts bitcoin as payment in his store so he will wait for confirmation (Majority users waits for 3 confirmation). Assume a person named Bob send bitcoin (BTC) to Charlie for purchase of a product and that transaction contains in block #501 and in #502 he got 1 confirmation in #503 2nd confirmation and in #504 3rd confirmation after that *Charlie* will release/ give the product.
Now after that attacker broadcasts its chain and now his chain is the official chain due to property of longer chain rule explained above. Let’s think while mining attacker changes bitcoin address of Sunny with his own bitcoin address (and can do it with any of the receiving address), as soon is attacker broadcast its chain all the blocks mined by miner became invalid and that’s how double-spend happen, attacker invalided that miner chain and that’s the main reason he can do double spend.
CONCLUSION
Myths
Numerous individuals think double spend gives the intensity of changes in BIP which isn’t correct they just have a little monopoly on mining till they having high hashing power.
51% attack and double spend are not the same. A 51% attack offers the ability to do double spend. In a genuine model in other cryptographic money precisely 51% is not required too. On account of bitcoin, a huge mining farm also can do that because of the colossal system.
51% assault is not limited to double spend, it has an intensity of freeze the framework, stopping a specific transaction, suspend mining, keep different miners from checking transactions.