Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: RoeiDimi on May 22, 2018, 09:11:43 AM



Title: Selfish miner implementation
Post by: RoeiDimi on May 22, 2018, 09:11:43 AM
Hello,
im an exprienced software developer but im new to bitcoin core
as part of my 2nd degree theses i wanna implement a selfish miner such as mentioned in this paper - https://arxiv.org/abs/1311.0243
the general idea is pretty known in the community -
every selfish miner in a selfish miners pool maintains 2 different blockchains, and when a new block is found, the selfish pool miners dont necessarily always tell the rest of the network about it.

i downloaded the bitcoin core code, its a pretty big and not that organized code and seems to me that i only need to make a few changes
1. give the node another blockchain
2. patch the code of receiving a new block so that it updates both blockchains according to the algorithm
3. patch the code that broadcasts a new found block so that it wont always broadcast it to everyone etc...

my question is - can someone point me to the places in the code where these features are found?
would also appreciate any other suggestions or tips regarding the implementation

thanks


Title: Re: Selfish miner implementation
Post by: DevilOper on May 23, 2018, 08:45:58 AM
I am not familiar with bitcoin core code, just an idea: you can maintain the second blockchain the same way as orphan blocks (AFAIK they are kept in blockchain).
For "sefish mining" you have to hack the "consensus algorithm" code part.


Title: Re: Selfish miner implementation
Post by: QRC on May 24, 2018, 05:30:55 AM
As blockchain name suggests, it's a chain of blocks.
So if your selfish miner works on its own private chain, you don't have to accept blocks from the main chain.
AcceptBlock function and other functions which are related to accepting blocks are located in validation.cpp


Title: Re: Selfish miner implementation
Post by: DevilOper on May 24, 2018, 09:02:11 AM
So if your selfish miner works on its own private chain, you don't have to accept blocks from the main chain.

AFAIK above some treshold selfish miner may decide to drop his chain (fork) and restart a new one over the new point of main chain.
Another concern is to compare chain lengths in order to decide when to publish his 'private'.


Title: Re: Selfish miner implementation
Post by: QRC on May 24, 2018, 12:22:11 PM
So if your selfish miner works on its own private chain, you don't have to accept blocks from the main chain.

AFAIK above some treshold selfish miner may decide to drop his chain (fork) and restart a new one over the new point of main chain.
Another concern is to compare chain lengths in order to decide when to publish his 'private'.
Of course, you're right on that, it can have some elaborated program logic behind it. (when release private blockchain, when to drop it and follow the main chain, ect.)
But I think RoeiDimi can first implement something simple. Something like:
Code:
if (privateChainLen > 4) 
   ReleasePrivateChain();
else (nBlocksBehindMainChain > 2)
   DropPrivateChain();


Title: Re: Selfish miner implementation
Post by: ranochigo on May 24, 2018, 12:40:31 PM
Of course, you right on that, it can have some elaborated program logic behind it. (when release private blockchain, when to drop it and follow the main chain, ect.)
But I think RoeiDimi can first implement something simple. Something like:
Code:
if (privateChainLen > 4) 
   releasePrivateChain();
else (nBlocksBehindOfMainChain > 2)
   dropPrivateChain();
Agreed, some refinements could be made. Selfish mining works the best if you can at least compete with others when they are at the same block height as you. When you're in this attack, you should be connected to the peers which are the major mining pools. If any of them relay a block, you would also broadcast your own block. As such, there is still a chance for the network to build on your chain.