I just found something else which is at least an inefficiency in the network and could potentially be exploited...
I looked at the cumulative difficulty checks.
When actively querying peers for blocks, the checks seem ok (except for that 720 block issue that we already discussed).
However, when I myself forged a block, I'll call the processBlock methods of my peers to get it into the network.
processBlock doesn't check cumulative difficulty, it just checks if it's the next block (i.e. newBlock.previousBlock == lastBlock).
So if it gets a worse block first, it will ignore the better block coming from me.
This, combined with the "we accept blocks that are 15 seconds into the future" can be exploited:
Say Anna can generate a block that is valid in 15 seconds. She immediately sends it to all peers, which accept that block, obviously.
Poor Bob can generate a block that is valid in 10 seconds, but waits until that time to send out that block.
Now all the peers that Bob sends his superior block to will just ignore it, if they have Anna's block and the only way for Bob to publish his block is to be asked by peers for blocks.
So sending blocks before there's time seems to increase forging chances... I think...
[edit]
Totally forgot to write the solution
Check the cumulative difficulty in a way similar to actively getting blocks from a peer in the passive case.
[edit2]
And here is the attack and the results:
Anna keeps spamming all the peers she knows with her blocks. She probably gets blacklisted by all her peers, but fortunately processBlock doesn't care about that. (slight hint at another thing you might want to fix: the blacklisting isn't checked in a lot of cases)
So Anna will get a block that shouldn't have belonged to her iff:
- her chance to forge that block is at most 15 seconds past the chance of the real block
- the forger of the real block (Bob) sits behind a firewall, so that he can't receive calls from his peers querying him for blocks
- Anna manages to send her block to all of Bob's peers before he does
So it definately increases Anna's chances and the methodology also spams the network. Neither is something you want to have.
To figure out by how much Anna's chances are increased, we'd need to estimate the ratio of blocks forged behind firewalls,
let's say, that's 30%. (I've got no clue about the real number, so feel free to replace it with anything you want)
Anna has a chance to forge 15 seconds longer, at an average 60 second forge duration. This means a 1.25x increase in chance of block generation. Combined with the 30% chance of the other block being forged behind a firewall, Anna can increase her forging chances by 7.5%.
Not much, but definately enough to start spamming the network.