This repository has been archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Add slashing threshold to params and evidence #200
Merged
jinmannwong
merged 7 commits into
fetchai:master
from
jinmannwong:improvements/evidence_collection
Oct 9, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7219855
Add slashing threshold to params and evidence
jinmannwong a980d83
Fix unit tests
jinmannwong 28cdafc
Pass complaint threshold to sdk
jinmannwong 4380ea9
Merge remote-tracking branch 'fetchai/master' into improvements/evide…
jinmannwong da78edb
Add test for checking uniqueness of evidence hash
jinmannwong 7de5365
Prevent store from accepting duplicate evidence
jinmannwong 50f7f5c
Bug fix
jinmannwong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -482,19 +482,21 @@ type BeaconInactivityEvidence struct { | |
DefendantAddress crypto.Address // Address of validator accused of inactivity | ||
ComplainantAddress crypto.Address // Address of validator submitting complaint complaint | ||
AeonStart int64 // Height for fetching validators | ||
Threshold int64 // Threshold of complaints for slashing (depends on validator size) | ||
ComplainantSignature []byte | ||
} | ||
|
||
var _ Evidence = &BeaconInactivityEvidence{} | ||
|
||
// NewBeaconInactivityEvidence creates BeaconInactivityEvidence | ||
func NewBeaconInactivityEvidence(height int64, defAddress crypto.Address, comAddress crypto.Address, aeon int64) *BeaconInactivityEvidence { | ||
func NewBeaconInactivityEvidence(height int64, defAddress crypto.Address, comAddress crypto.Address, aeon int64, threshold int64) *BeaconInactivityEvidence { | ||
return &BeaconInactivityEvidence{ | ||
CreationHeight: height, | ||
CreationTime: time.Now(), | ||
DefendantAddress: defAddress, | ||
ComplainantAddress: comAddress, | ||
AeonStart: aeon, | ||
Threshold: threshold, | ||
} | ||
} | ||
|
||
|
@@ -510,9 +512,10 @@ func (bie *BeaconInactivityEvidence) Height() int64 { | |
return bie.CreationHeight | ||
} | ||
|
||
// Height returns validator height | ||
// ValidatorHeight returns validator height. Validators running DRB at aeon start | ||
// correspond to the DKG validators at aeon start -1 | ||
func (bie *BeaconInactivityEvidence) ValidatorHeight() int64 { | ||
return bie.AeonStart | ||
return bie.AeonStart - 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bug fix. |
||
} | ||
|
||
// Time return | ||
|
@@ -530,20 +533,36 @@ func (bie *BeaconInactivityEvidence) Bytes() []byte { | |
return cdcEncode(bie) | ||
} | ||
|
||
// Hash returns the hash of the evidence. | ||
// Hash returns the hash of the unique fields in evidence. Prevents submission | ||
// of multiple evidence by using a different creation time or signature | ||
func (bie *BeaconInactivityEvidence) Hash() []byte { | ||
return tmhash.Sum(cdcEncode(bie)) | ||
uniqueInfo := struct { | ||
AeonStart int64 | ||
DefendantAddress []byte | ||
ComplainantAddress []byte | ||
Threshold int64 | ||
}{bie.AeonStart, bie.DefendantAddress, bie.ComplainantAddress, bie.Threshold} | ||
return tmhash.Sum(cdcEncode(uniqueInfo)) | ||
} | ||
|
||
// Verify validates information contained in Evidence. Ensures signature verifies with complainant address, valid aeon start and | ||
// that the evidence was created after the aeon start | ||
func (bie *BeaconInactivityEvidence) Verify(chainID string, blockEntropy BlockEntropy, valset *ValidatorSet) error { | ||
func (bie *BeaconInactivityEvidence) Verify(chainID string, blockEntropy BlockEntropy, valset *ValidatorSet, | ||
params EntropyParams) error { | ||
// Check aeon start is correct | ||
if blockEntropy.NextAeonStart != bie.ValidatorHeight() { | ||
if blockEntropy.NextAeonStart != bie.AeonStart { | ||
return fmt.Errorf("incorrect aeon start. Got %v, expected %v", bie.ValidatorHeight(), blockEntropy.NextAeonStart) | ||
} | ||
if bie.CreationHeight <= bie.AeonStart { | ||
return fmt.Errorf("CreationHeight %v before AeonStart %v", bie.CreationHeight, bie.AeonStart) | ||
// Creation height of evidence needs to be during the entropy generation aeon | ||
if bie.CreationHeight <= bie.AeonStart || bie.CreationHeight > bie.AeonStart+params.AeonLength { | ||
return fmt.Errorf("invalid creation height %v for aeon start %v", bie.CreationHeight, bie.AeonStart) | ||
} | ||
|
||
// Check theshold is correct | ||
slashingFraction := float64(params.SlashingThresholdPercentage) * 0.01 | ||
slashingThreshold := int64(slashingFraction * float64(valset.Size())) | ||
if slashingThreshold != bie.Threshold { | ||
return fmt.Errorf("incorrect Threshold. Got %v, expected %v", bie.Threshold, slashingThreshold) | ||
} | ||
|
||
// Check both complainant and defendant addresses are in DKG validator set at aeon start - 1, and that they are in qual | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer need to send the validator who signed the complaint as we make the evidence from each validator each aeon unique so that duplicates can not be submitted into the blocks