Browse Source

verify evidence in block

pull/592/head
Ethan Buchman 8 years ago
parent
commit
35587658cd
4 changed files with 33 additions and 5 deletions
  1. +8
    -1
      state/execution.go
  2. +12
    -1
      types/evidence.go
  3. +11
    -0
      types/vote.go
  4. +2
    -3
      types/vote_set.go

+ 8
- 1
state/execution.go View File

@ -309,7 +309,14 @@ func (s *State) validateBlock(b *types.Block) error {
}
}
// TODO: Validate evidence
for _, ev := range block.Evidence.Evidence {
if err := ev.VoteA.Verify(s.ChainID, ev.PubKey); err != nil {
return types.ErrEvidenceInvalid(ev, err)
}
if err := ev.VoteB.Verify(s.ChainID, ev.PubKey); err != nil {
return types.ErrEvidenceInvalid(ev, err)
}
}
return nil
}


+ 12
- 1
types/evidence.go View File

@ -7,6 +7,15 @@ import (
"github.com/tendermint/go-crypto"
)
type ErrEvidenceInvalid struct {
Evidence Evidence
Error error
}
func (err *ErrEvidenceInvalid) Error() string {
return fmt.Sprintf("Invalid evidence: %v. Evidence: %v", err.Error, err.Evidence)
}
// Evidence represents any provable malicious activity by a validator
type Evidence interface {
Verify() error
@ -49,7 +58,9 @@ func (dve *DuplicateVoteEvidence) Verify() error {
}
// Signatures must be valid
// TODO
if !dve.PubKey.Verify(SignBytes(chainID, dve.VoteA), dve.VoteA.Signature) {
return ErrVoteInvalidSignature
}
return nil
}

+ 11
- 0
types/vote.go View File

@ -101,3 +101,14 @@ func (vote *Vote) String() string {
cmn.Fingerprint(vote.BlockID.Hash), vote.Signature,
CanonicalTime(vote.Timestamp))
}
func (vote *Vote) Verify(chainID string, pubKey crypto.PubKey) error {
if !bytes.Equal(pubKey.Address(), v.ValidatorAddress) {
return ErrVoteInvalidValidatorAddress
}
if !pubKey.VerifyBytes(SignBytes(chainID, vote), vote.Signature) {
return ErrVoteInvalidSignature
}
return nil
}

+ 2
- 3
types/vote_set.go View File

@ -178,9 +178,8 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
}
// Check signature.
if !val.PubKey.VerifyBytes(SignBytes(voteSet.chainID, vote), vote.Signature) {
// Bad signature.
return false, ErrVoteInvalidSignature
if err := vote.Verify(voteSet.chainID, val.PubKey); err != nil {
return false, err
}
// Add vote and get conflicting vote if any


Loading…
Cancel
Save