Search code examples
blockchainprobabilitybitcoin

In bitcoin, how do I calculate the probability for the latest n block/s to be wrong?


I learned from here that it takes 6 blocks over a block for its contents to be confirmed.

If so, what is the chance that the latest block's contents are illegitimate? What is the chance for the second to the latest?


Solution

  • ...it takes 6 blocks over a block for its contents to be confirmed.

    The number of confirmations is directly correlated to the amount of security and finality you require on the transaction. The more confirmations, the more secure it will be. 6 is not a magic number, though it is commonly used.

    If so, what is the chance that the latest block's contents are illegitimate? What is the chance for the second to the latest? . . .

    The chance that a recent block's contents are invalid are basically zero if you are using the latest Bitcoin software and it has not been tampered with (and there are no bugs). A node will reject an invalid block.

    Now, the block could become invalid for a few reasons.

    1. If a longer chain is presented, which can be validated. For example, if another miner has mined 2 blocks which replace the latest block, the node will accept them since there is more proof of work (each block has to be mined with a proof of work). This requires a majority of the network hashpower (computing power) and is also known as a 51% attack. The more blocks have been mined since the transaction occurred (aka number of confirmations), the more secure it will be from being reversed (or removed) in a reorganization or 51% attack. This is very very unlikely for Bitcoin because of how high the network hashrate is. It is much more likely for other coins which have a much lower network hashrate.

    2. A miner mines another block at nearly the same time (within seconds or less), Chain Reorganization. This could happen because of latency issues, for example. This is also unlikely because a block on average is mined every 10 minutes, and the network propagation is very fast, but probably much more likely than #1. It depends on your node's connection latency relative to the rest of the network.