Nice! Can you open source this?
Is the simulator accurately modeling how orphan blocks are (not) relayed?
It would also be useful to see total revenue, and total-revenue-expected-if-everybody-mines-honestly for both the entire network and the attacker.
Here's my repo for it:
https://github.com/ebfull/ebfull.github.io (same license as bitcoin-qt)
I'll be better documenting and cleaning up the code. Also, orphaned blocks are now displayed with a strikethrough if they are absent on the best chain. In addition, the proposed patch (honest miners mining on random branches rather than the first branch received) has been added as a parameter.
This is really cool. I've been watching it run on a couple of computers here.
I'm getting consistent results here, showing that the selfish mining strategy is a really good way to lose 20-30% of your mining revenue. I'll note that this is roughly what I was expecting. In every other context, the whole world considers it obvious that getting your blocks out as fast as possible is a good thing. Still, science is the art of not fooling yourself, and getting the result you expect is not the same as showing that a model has skill.
As fun as this is, it needs to be much faster to be really useful. We need hundreds or thousands of runs, covering hundreds or thousands of blocks. We also need to verify that model parameters are realistic, and that the simulation isn't adding or causing un-real effects. We should also invite the authors to verify that the attack behavior is implemented correctly.*
* To the limited extent possible.
I'd also like to know if the attack behavior is implemented correctly, as it appears the paper on the attack has many flaws -- the algorithm they describe is contradictory and has typos.
However, I think you're reading the revenue of the attacker wrong on the simulation. It's the revenue the attacker has accumulated as a percentage of all of the revenue of the best chain.
My approximate results (after 10000 blocks each):
35% normal, no attack: ~37.17% revenue
35% selfish, no sybil: ~37.57% revenue
35% sybil: ~37.05% revenue
35% selfish, sybil: ~48.8% revenue
20% normal, no attack: ~20.92% revenue
20% selfish, no sybil: ~10.9% revenue
20% sybil: ~21.55% revenue
20% selfish, sybil: ~23.11%
This is using a completely different network topology than bitcoin's network tends to have, but it does show that some mixture of parameters (like how well the attacker is connected, the propagation speed of blocks, the orphan rate) makes the attack practical. I've adjusted random things to see the effects: for example, with a higher natural orphan rate, the attack is much more effective as you might imagine, because the attacker can get a better lead on the honest miners.
Yes, I'd love to have an UI like this on top of the real simulator, right now it seems a bit more concerned (CPU wise) to re-arrange it's nodes than to actually simulate, especially if you drop a few more nodes.
I've changed the simulator, now it will not render as often as it will compute, especially at higher speeds. You can also turn off visualization if you'd like. This has improved it significantly.
Ultimately the best simulator will not be in javascript, I'll admit, but I think I can make this simulator efficient enough for rapid prototyping of ideas on a small scale.