Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/stake: Limit the size of rationals from user input #1415

Merged
merged 6 commits into from
Jun 29, 2018

Conversation

ValarDragon
Copy link
Contributor

This commit sets the maximum number of decimal points that can be
passed in from messages. This is enforced on the validate basic of
MsgBeginUnbonding and MsgBeginRedelegation. The cli has been
updated to truncate the user input to the specified precision. This
also updates types/rational to return big ints for Num() and Den().

Closes #887

  • Updated all relevant documentation in docs - what documentation should be updated
  • Updated all code comments where relevant - I think so
  • Wrote tests - wrote tests for the rational change, are more tests desired?
  • Updated CHANGELOG.md
  • Updated Gaia/Examples - n/a
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

This commit sets the maximum number of decimal points that can be
passed in from messages. This is enforced on the validate basic of
MsgBeginUnbonding and MsgBeginRedelegation. The cli has been
updated to truncate the user input to the specified precision. This
also updates types/rational to return big ints for Num() and Den().

Closes #887
@ValarDragon ValarDragon requested a review from ebuchman as a code owner June 27, 2018 22:58
@codecov
Copy link

codecov bot commented Jun 27, 2018

Codecov Report

Merging #1415 into develop will decrease coverage by 0.08%.
The diff coverage is 0%.

@@             Coverage Diff             @@
##           develop    #1415      +/-   ##
===========================================
- Coverage    63.18%   63.09%   -0.09%     
===========================================
  Files          118      118              
  Lines         6554     6563       +9     
===========================================
  Hits          4141     4141              
- Misses        2144     2151       +7     
- Partials       269      271       +2

types/int.go Outdated
@@ -214,6 +214,11 @@ func (i Int) Neg() (res Int) {
return Int{neg(i.i)}
}

// String converts int to string
func (i Int) String() string {
return i.i.String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the tendermint-lint require a comment on this function? I don't think it does - pretty straight forward probably can remove the comment (unless this needs to be added to our linter)

@@ -61,6 +61,9 @@ func NewRatFromDecimal(decimalStr string) (f Rat, err Error) {
if len(str[0]) == 0 || len(str[1]) == 0 {
return f, ErrUnknownRequest("not a decimal string")
}
if len(str[1]) > prec {
str[1] = str[1][:prec]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should actually cause an error if somebody is sending in to much precision not just truncate it - we shouldn't fail silently should let user know

numBig.Neg(numBig)
}

return NewRatFromBigInt(numBig, big.NewInt(denom)), nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh whoa so now we could take in huge stuff? cool!

@@ -70,7 +73,17 @@ func NewRatFromDecimal(decimalStr string) (f Rat, err Error) {

num, errConv := strconv.Atoi(numStr)
if errConv != nil {
return f, ErrUnknownRequest(errConv.Error())
// resort to big int, don't make this default option for efficiency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like a better thing to do would be to check the specific type of error - only if it was an (overflow?) error then we would go to this next step... shouldn't have to go inside here if the user is attempting to convert "alskgndnalsg" into a rational

@@ -31,7 +33,10 @@ func TestNewFromDecimal(t *testing.T) {
{"1.1", false, NewRat(11, 10)},
{"0.75", false, NewRat(3, 4)},
{"0.8", false, NewRat(4, 5)},
{"0.11111", false, NewRat(11111, 100000)},
{"0.11111", false, NewRat(1111, 10000)},
{"628240629832763.5738930323617075341", false, NewRat(3141203149163817869, 5000)},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned earlier we should send an error if there are to many decimal places

@ValarDragon
Copy link
Contributor Author

Addressed PR comments

Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ValarDragon
Copy link
Contributor Author

Huh, test_unit doesn't fail on my machine. I'll rerun on circle to see if its a non-deterministic failure.

@ValarDragon
Copy link
Contributor Author

It was a non-deterministic failure. Re-ran on circle and it passed.

@rigelrozanski
Copy link
Contributor

now test cover failing

@ValarDragon
Copy link
Contributor Author

I think that was non-deterministic also, re-ran and it passed.

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@cwgoes cwgoes merged commit 47e4682 into develop Jun 29, 2018
@cwgoes cwgoes deleted the dev/limit_rat_size branch June 29, 2018 20:30
adrianbrink pushed a commit that referenced this pull request Jul 2, 2018
* x/stake: Limit the size of rationals from user input

This commit sets the maximum number of decimal points that can be
passed in from messages. This is enforced on the validate basic of
MsgBeginUnbonding and MsgBeginRedelegation. The cli has been
updated to truncate the user input to the specified precision. This
also updates types/rational to return big ints for Num() and Den().

Closes #887

* Switch NewFromDecimal to error instead of truncating
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants