Repository navigation
Conversation
Also deal with possible overflow issues.
|
I agree negative voting power is VERY bad. It is a backdoor in the system. A, B, C, D all have 1 vote and 3 are needed for consensus. Grant E -3 votes, and suddenly 1 vote = 100% of total votes. Oops! On the other hand, if we make it a uint, and some logic goes I would leave it as int64, so we can detect underflow better. But add checks everytime it is set to return an error upon setting it negative. Just my two cents... Ex. see code sample: |
Underflow case in covered in this PR. Just to let you know. Not judging your opinion in any way. Let's wait what @ebuchman will say. |
| } | ||
|
|
||
| // addOrMax performs safe addition: if result overflows, it returns MaxUint64 | ||
| func addOrMax(accum, value uint64) uint64 { |
There was a problem hiding this comment.
Yes, I see. Very important functions here.
There was a problem hiding this comment.
These should probably be moved to https://github.com/tendermint/go-common
|
Hm. Obviously @akalyaev , how did you find the negative voting power in the first place? Isn't it something we can just prevent when the validator diffs are returned? |
| votePower := minPower | ||
| if randPower { | ||
| votePower += int64(RandUint32()) | ||
| votePower += RandUint64() |
There was a problem hiding this comment.
Doesn't this have a (tiny) chance of overflowing. Like (minPower / 2^64). Still not quite 0....
addOrMax(votePower, RandUint64())
Also, in this case with eg. 5 validators, it will be likely that the sum of all power is greater than math.MaxUint64. Maybe RandUint32() is better?
|
@ebuchman here #344 (comment) |
Maybe, but it will break the app logic/tests (like this PR does).
|
|
|
||
| address := pubkey.Address() | ||
| power := int64(v.Power) | ||
| power := uint64(v.Power) |
There was a problem hiding this comment.
This is the check @ebuchman was referring to I think. We make sure they can't overflow when the TMSP app sends a validator set update. This worked for int64 or int32, since it is clear when there is a negative value.
Let's say the tmsp app has a tx that reduces a voting power by 2. And it doesn't check underflow. If the user was already at 1, they would do the bad math in the app => math.Maxunit64, which is sent to tendermint core, which cannot reliably distinguish if there was an error in the app, or this validator is suddenly REALLY important.
The old code at least would catch and report errors in app code. But I do agree, internally it is a bit annoying to have ints when you want uints...
Not sure the solution, but core should be defensive against errors in tmsp apps.
|
I'm in agreement with EthanFrey. I used to think that uintxx's were better, but their usage w/ arithmetic operations makes it more bug prone, and the code more complicated. It's much easier to add/subtract as necessary and check the sign. Take validator diffs for example... a diff should be signed because it could make the validator voting power go up or down. So it should be an int64, but if VotingPower is a uint64, it creates an annoying type mismatch. We can use special functions to check for overflow/underflow, but somebody will forget somewhere. So now I prefer to think of int64's sometimes as uint63's with a magical underflow check. |
|
I'd even change abci.Validator's voting power to be an int64. Whenever addition/subtraction will happen frequently with a number, I'd opt for signed numbers. This doesn't happen often with block.Height, or partSet.Total, for example, so they are uintxx's. |
|
BTW not sure why I missed this, but if I don't respond to an issue in 2 days feel free to just ping me on Slack. |
|
@jaekwon good point! I think we can close this now. |
) by moving the `codecov.yml` file from .github the root folder. --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments (cherry picked from commit c906604) Co-authored-by: Lasaro <[email protected]>
Also, deal with possible overflow issues.
This change breaks the test right now.
Is this a correct move? or should we let
votingPowerbe negative? need to know before doing anything else.