Then i will expand my thought experiment. Let's say that Bitcoin network has grown, and people use it to trade 100.000.000$ worth of goods & currencies weekly.
1. A powerful adversary spends 50.000.000$ to buy 1.000.000 Bitcoins from MTGOX
2. He builds his alternate double - spending chain for a week, while in the meantime, people buy 100.000.000$ worth of goods & currencies using Bitcoin
3. After a week, adversary introduces his chain fork which double-spends his 1.000.000BTC to his address
4. At least 100.000.000$ worth of currencies & goods that were bought through the week are lost
5. This causes major havoc in the Bitcoin world, people's trust in the currency is seriously undermined.
6. ?? ??
7. PROFIT !
So how do we avoid this ?
If even I have produced this scenario, it is reasonable to think that powerful adversaries may already be working on it.
Also, another logical conclusion of mine is that all alt-currencies like Litecoin are useless, because attack like above can be arranged with ease using little hashing power.
There is no step 7. This attack is non-economic, meaning that the attacker has to be willing to burn a lot of wealth to do the attack. This alone severely limits the categories of potential attackers, but it is not unreasonable to think that such an attacker might show up some day, so it deserves some attention.
To counter this, I proposed an exponential difficulty ramp for reorganizations. Reorgs of up to X blocks (6 might be a good value for X) happen normally, with the longer chain winning. Reorgs beyond X blocks require Y
(B-X) more difficulty in the new chain than the old chain, where B is the number of blocks to be thrown out. Y could be pretty small and still give good safety, maybe 1.1 or 1.05. For example, for X=6 and Y=1.05, reversing 100 blocks would need ~50 times the total network power, not half. And replacing 144 blocks (1 day) would require ~400 times the network power. Recipients of large transactions would be able to decide on their own how long they needed to wait to meet their own safety requirements. Selling a billion dollar widget? Wait a week, and then the attacker would need 1*10
21 times the total network hashing power to unbury it.
I think that if a block is invalidated, all transactions in it which are not double-spent go back to the memory pool and can be included in the next block. Even if not, the client that originally sent the transaction still has it and can rebroadcast it, it is still just as valid.
Yes, but will the client rebroadcast it ? Was such scenario already tested ?
Yes, reorgs happen naturally every few days. All transactions from the discarded blocks go back into the memory pool, and if they are still valid in the new context, they will be retransmitted and eventually end up in new blocks.
c) Will the original chain be erased from every client's database instantly the moment when a longer valid chain is supplied, or is there some other mechanism at work here ?
See a, the client keeps forks, however this might change when pruning enters the picture.
Ok, so my logical conclusion is that pruning
cannot be implemented, until we solve this problem once and for all.
ultraprune stores rollback information for exactly this reason, even though it doesn't actually do any pruning yet.
Transactions that are in the orphaned blocks become invalid only if their input was also used in the now longest chain (say the trunk of the tree). Quite a few transactions will actually already be in the trunk (if it is not a real and nasty attack). Those transactions that remain valid but are not already in the trunk should enter the unconfirmed pool of the node.
The unconfirmed pool is most likely in memory for all node implementations therefore there remains the chance that valid but unconfirmed transactions will cease at some (long) delay from the memory of the network.
But when they do, there will be no way to fix the mess.
Well, even if the rest of the network forgets, each node scans their own wallet from time to time, and any transactions they see in their local wallet database but not in blocks and not in memory get retransmitted. So, as long as your wallet is still live, the transactions still have a way to get back on the network. Hilariously, this causes problems today because if you realize that a transaction isn't going to make it into a block within a reasonable amount of time, there isn't a simple way to prevent your wallet from keeping it alive. You have to hack your wallet database to delete that transaction so that the network can forget about it, so that you can double spend it with a fee or whatever.
Also, there are ways to fix it, but they aren't particularly pleasant. One ad hoc way to get things right would be to trace the fork back to the initial divergence, and then hardcode that first block's hash into a blacklist. This would only help people that upgrade to the new blacklist-enabled version, but basically everyone would want to make that upgrade. The blacklist could just be a text file in the datadir, managed by each node's user individually; they would have a powerful incentive to not put anything other than obvious attack blocks in it.
What I think really saves us from this scenario is that hashing capacity of sufficient power for the attack does not currently exist in the world,
in a readily available form. There just aren't enough physical Radeon's in the world, in purchasable form, for someone to gather them easily or quickly, even with a huge budget. The attacker's best bet would be to spend about a year developing an ASIC, but that attack window is not going to stay open much longer.