Hello,
With another student, we are currently trying to replicate a 51% attack on a private blockchain as a uni research project. In order to do that, at one point we have to isolate the malicious miners so that they mine on their own chain, so we tried using the removePeer(id) function from handler.go :
case msg.Code == HackAction:
//This message allows the master to activate the isolated mining for the
//malicious slaves
log.Info("Hack action incoming")
// pm.initialPeers.peers =pm.peers.peers
var idQuery []string
msg.Decode(&idQuery)
log.Info("peer list","list", idQuery)
temp :=0
for idd,_ := range pm.peers.peers{
temp = 0
for _,iid := range idQuery{
if idd == iid{
temp =1
}
}
if temp ==0 {
//launch the go routine to keep the peer disconnected undefinitely
pm.removePeer(idd)
}
}
This code is inserted in the switch from handleMessage (in handler.go), and basically it should remove the honest peers from the known peerset of the malicious peer (each malicious client has this code).
This works, but only for a small amount of time, after which it seems that the honest peers start importing the malicious blocks autonomously (and net.peerCount shows that all peers are connected again).
We also tried this :
case msg.Code == HackAction:
//This message allows the master to activate the isolated mining for the
//malicious slaves
log.Info("Hack action incoming")
// pm.initialPeers.peers =pm.peers.peers
var idQuery []string
msg.Decode(&idQuery)
log.Info("peer list","list", idQuery)
temp :=0
for idd,_ := range pm.peers.peers{
temp = 0
for _,iid := range idQuery{
if idd == iid{
temp =1
}
}
if temp ==0 {
//launch the go routine to keep the peer disconnected undefinitely
go pm.keepPeerDisc(idd)
}
}
with :
func (pm *ProtocolManager) keepPeerDisc(id string){
for {
if pm.hackFlag{
pm.removePeer(id)
}else{
return
}
}
}
And hackFlag a filed in the protocolmanager that is true or false depeding on the current state (hacking or not hacking). Same here, it works for some time but then the honest peers manage to see us again (or at least download the blocks we were secretely mining).
If anybody knows how to succesfully disconnect a peer for an indefinite amount of time (after which we could manually re-register it once isolated mining is finished), we would be greatly thankful!
1 ·