add incorrect response attack

pull/27/head
Minh Doan 6 years ago
parent 307598fdca
commit e7e5792d41
  1. 16
      attack/attack.go
  2. 14
      consensus/consensus_validator.go

@ -22,7 +22,7 @@ type AttackType byte
const (
KilledItself AttackType = iota
DelayResponse
IncorrectTransaction
IncorrectResponse
)
// AttackModel contains different models of attacking.
@ -75,7 +75,7 @@ func (attack *Attack) NodeKilledByItSelf() {
}
if rand.Intn(HitRate) == 0 {
attack.log.Debug("******Killing myself*******", "PID: ", os.Getpid())
attack.log.Debug("******************Killing myself******************", "PID: ", os.Getpid())
os.Exit(1)
}
}
@ -85,10 +85,22 @@ func (attack *Attack) DelayResponse() {
return
}
if rand.Intn(HitRate) == 0 {
attack.log.Debug("******************Attack: DelayResponse******************", "PID: ", os.Getpid())
time.Sleep(DelayResponseDuration)
}
}
func (attack *Attack) IncorrectResponse() bool {
if !attack.AttackEnabled || attack.attackType != IncorrectResponse || !attack.readyByConsensus {
return false
}
if rand.Intn(HitRate) == 0 {
attack.log.Debug("******************Attack: IncorrectResponse******************", "PID: ", os.Getpid())
return true
}
return false
}
func (attack *Attack) UpdateConsensusReady(consensusId uint32) {
if consensusId > attack.ConsensusIdThreshold {
attack.readyByConsensus = true

@ -206,6 +206,9 @@ func (consensus *Consensus) processChallengeMessage(payload []byte) {
// Verify block data and the aggregated signatures
// Update readyByConsensus for attack.
attack.GetInstance().UpdateConsensusReady(consensusId)
// check leader Id
leaderPrivKey := consensus.leader.Ip + consensus.leader.Port
reg, _ := regexp.Compile("[^0-9]+")
@ -217,6 +220,14 @@ func (consensus *Consensus) processChallengeMessage(payload []byte) {
}
consensus.mutex.Lock()
// Add attack model of IncorrectResponse.
if attack.GetInstance().IncorrectResponse() {
consensus.Log.Warn("IncorrectResponse attacked")
consensus.mutex.Unlock()
return
}
// check block hash
if bytes.Compare(blockHash[:], consensus.blockHash[:]) != 0 {
consensus.Log.Warn("Block hash doesn't match", "consensus", consensus)
@ -235,9 +246,6 @@ func (consensus *Consensus) processChallengeMessage(payload []byte) {
// If I received previous block (which haven't been processed. I will roll up to current block if everything checks.
}
// Update readyByConsensus for attack.
attack.GetInstance().UpdateConsensusReady(consensusId)
// TODO: verify aggregated commits with real schnor cosign verification
// TODO: return the signature(response) to leader

Loading…
Cancel
Save