github.com/aakash4dev/cometbft@v0.38.2/spec/consensus/evidence.md (about) 1 --- 2 --- 3 4 # Evidence 5 6 Evidence is an important component of CometBFT's security model. Whilst the core 7 consensus protocol provides correctness gaurantees for state machine replication 8 that can tolerate less than 1/3 failures, the evidence system looks to detect and 9 gossip byzantine faults whose combined power is greater than or equal to 1/3. It is worth noting that 10 the evidence system is designed purely to detect possible attacks, gossip them, 11 commit them on chain and inform the application running on top of CometBFT. 12 Evidence in itself does not punish "bad actors", this is left to the discretion 13 of the application. A common form of punishment is slashing where the validators 14 that were caught violating the protocol have all or a portion of their voting 15 power removed. Evidence, given the assumption that 1/3+ of the network is still 16 byzantine, is susceptible to censorship and should therefore be considered added 17 security on a "best effort" basis. 18 19 This document walks through the various forms of evidence, how they are detected, 20 gossiped, verified and committed. 21 22 > NOTE: Evidence here is internal to CometBFT and should not be confused with 23 > application evidence 24 25 ## Detection 26 27 ### Equivocation 28 29 Equivocation is the most fundamental of byzantine faults. Simply put, to prevent 30 replication of state across all nodes, a validator tries to convince some subset 31 of nodes to commit one block whilst convincing another subset to commit a 32 different block. This is achieved by double voting (hence 33 `DuplicateVoteEvidence`). A successful duplicate vote attack requires greater 34 than 1/3 voting power and a (temporary) network partition between the aforementioned 35 subsets. This is because in consensus, votes are gossiped around. When a node 36 observes two conflicting votes from the same peer, it will use the two votes of 37 evidence and begin gossiping this evidence to other nodes. [Verification](#duplicatevoteevidence) is addressed further down. 38 39 ```go 40 type DuplicateVoteEvidence struct { 41 VoteA Vote 42 VoteB Vote 43 44 // and abci specific fields 45 } 46 ``` 47 48 ### Light Client Attacks 49 50 Light clients also comply with the 1/3+ security model, however, by using a 51 different, more lightweight verification method they are subject to a 52 different kind of 1/3+ attack whereby the byzantine validators could sign an 53 alternative light block that the light client will think is valid. Detection, 54 explained in greater detail 55 [here](../light-client/detection/detection_003_reviewed.md), involves comparison 56 with multiple other nodes in the hope that at least one is "honest". An "honest" 57 node will return a challenging light block for the light client to validate. If 58 this challenging light block also meets the 59 [validation criteria](../light-client/verification/verification_001_published.md) 60 then the light client sends the "forged" light block to the node. 61 [Verification](#lightclientattackevidence) is addressed further down. 62 63 ```go 64 type LightClientAttackEvidence struct { 65 ConflictingBlock LightBlock 66 CommonHeight int64 67 68 // and abci specific fields 69 } 70 ``` 71 72 ## Verification 73 74 If a node receives evidence, it will first try to verify it, then persist it. 75 Evidence of byzantine behavior should only be committed once (uniqueness) and 76 should be committed within a certain period from the point that it occurred 77 (timely). Timelines is defined by the `EvidenceParams`: `MaxAgeNumBlocks` and 78 `MaxAgeDuration`. In Proof of Stake chains where validators are bonded, evidence 79 age should be less than the unbonding period so validators still can be 80 punished. Given these two propoerties the following initial checks are made. 81 82 1. Has the evidence expired? This is done by taking the height of the `Vote` 83 within `DuplicateVoteEvidence` or `CommonHeight` within 84 `LightClientAttakEvidence`. The evidence height is then used to retrieve the 85 header and thus the time of the block that corresponds to the evidence. If 86 `CurrentHeight - MaxAgeNumBlocks > EvidenceHeight` && `CurrentTime - 87 MaxAgeDuration > EvidenceTime`, the evidence is considered expired and 88 ignored. 89 90 2. Has the evidence already been committed? The evidence pool tracks the hash of 91 all committed evidence and uses this to determine uniqueness. If a new 92 evidence has the same hash as a committed one, the new evidence will be 93 ignored. 94 95 ### DuplicateVoteEvidence 96 97 Valid `DuplicateVoteEvidence` must adhere to the following rules: 98 99 - Validator Address, Height, Round and Type must be the same for both votes 100 101 - BlockID must be different for both votes (BlockID can be for a nil block) 102 103 - Validator must have been in the validator set at that height 104 105 - Vote signature must be correctly signed. This also uses `ChainID` so we know 106 that the fault occurred on this chain 107 108 ### LightClientAttackEvidence 109 110 Valid Light Client Attack Evidence must adhere to the following rules: 111 112 - If the header of the light block is invalid, thus indicating a lunatic attack, 113 the node must check that they can use `verifySkipping` from their header at 114 the common height to the conflicting header 115 116 - If the header is valid, then the validator sets are the same and this is 117 either a form of equivocation or amnesia. We therefore check that 2/3 of the 118 validator set also signed the conflicting header. 119 120 - The nodes own header at the same height as the conflicting header must have a 121 different hash to the conflicting header. 122 123 - If the nodes latest header is less in height to the conflicting header, then 124 the node must check that the conflicting block has a time that is less than 125 this latest header (This is a forward lunatic attack). 126 127 ## Gossiping 128 129 If a node verifies evidence it then broadcasts it to all peers, continously sending 130 the same evidence once every 10 seconds until the evidence is seen on chain or 131 expires. 132 133 ## Commiting on Chain 134 135 Evidence takes strict priority over regular transactions, thus a block is filled 136 with evidence first and transactions take up the remainder of the space. To 137 mitigate the threat of an already punished node from spamming the network with 138 more evidence, the size of the evidence in a block can be capped by 139 `EvidenceParams.MaxBytes`. Nodes receiving blocks with evidence will validate 140 the evidence before sending `Prevote` and `Precommit` votes. The evidence pool 141 will usually cache verifications so that this process is much quicker. 142 143 ## Sending Evidence to the Application 144 145 After evidence is committed, the block is then processed by the block executor 146 which delivers the evidence to the application via `EndBlock`. Evidence is 147 stripped of the actual proof, split up per faulty validator and only the 148 validator, height, time and evidence type is sent. 149 150 ```proto 151 enum EvidenceType { 152 UNKNOWN = 0; 153 DUPLICATE_VOTE = 1; 154 LIGHT_CLIENT_ATTACK = 2; 155 } 156 157 message Evidence { 158 EvidenceType type = 1; 159 // The offending validator 160 Validator validator = 2 [(gogoproto.nullable) = false]; 161 // The height when the offense occurred 162 int64 height = 3; 163 // The corresponding time where the offense occurred 164 google.protobuf.Timestamp time = 4 [ 165 (gogoproto.nullable) = false, (gogoproto.stdtime) = true]; 166 // Total voting power of the validator set in case the ABCI application does 167 // not store historical validators. 168 // https://github.com/tendermint/tendermint/issues/4581 169 int64 total_voting_power = 5; 170 } 171 ``` 172 173 `DuplicateVoteEvidence` and `LightClientAttackEvidence` are self-contained in 174 the sense that the evidence can be used to derive the `abci.Evidence` that is 175 sent to the application. Because of this, extra fields are necessary: 176 177 ```go 178 type DuplicateVoteEvidence struct { 179 VoteA *Vote 180 VoteB *Vote 181 182 // abci specific information 183 TotalVotingPower int64 184 ValidatorPower int64 185 Timestamp time.Time 186 } 187 188 type LightClientAttackEvidence struct { 189 ConflictingBlock *LightBlock 190 CommonHeight int64 191 192 // abci specific information 193 ByzantineValidators []*Validator 194 TotalVotingPower int64 195 Timestamp time.Time 196 } 197 ``` 198 199 These ABCI specific fields don't affect validity of the evidence itself but must 200 be consistent amongst nodes and agreed upon on chain. If evidence with the 201 incorrect abci information is sent, a node will create new evidence from it and 202 replace the ABCI fields with the correct information.