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

Possible inconsistency in LooseTokens #1870

Closed
4 tasks done
hendrikhofstadt opened this issue Jul 29, 2018 · 9 comments
Closed
4 tasks done

Possible inconsistency in LooseTokens #1870

hendrikhofstadt opened this issue Jul 29, 2018 · 9 comments
Assignees

Comments

@hendrikhofstadt
Copy link
Contributor

hendrikhofstadt commented Jul 29, 2018

Summary of Bug

When a validator is slashed and an individual share is is now a floating point number like 1.6 a delegator will get 2 steaks back when he unrevokes because of bankers rounding.

balance := sdk.Coin{params.BondDenom, returnAmount.RoundInt()}

However LooseTokens will only be incremented by the Rat value of 1.6

issuedTokens := v.DelegatorShareExRate().Mul(delShares)
v.Tokens = v.Tokens.Sub(issuedTokens)
v.DelegatorShares = v.DelegatorShares.Sub(delShares)
if v.Status == sdk.Bonded {
pool = pool.bondedTokensToLoose(issuedTokens)
}

p.LooseTokens = p.LooseTokens.Add(bondedTokens)

This will lead to an inconsistency between the real staking tokens in circulation and LooseTokens.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@ValarDragon
Copy link
Contributor

ValarDragon commented Jul 29, 2018

Wow, great catch! ref #1471

/cc @rigelrozanski , @cwgoes

@cwgoes
Copy link
Contributor

cwgoes commented Jul 30, 2018

Yup, this needs to be fixed - ref #1807.

@rigelrozanski rigelrozanski self-assigned this Jul 30, 2018
@ValarDragon
Copy link
Contributor

I guess we just need to double check whether or not this is still a concern with the decimal implementation.

@alexanderbez
Copy link
Contributor

We should verify this once staking refactor has been completed.

@cwgoes
Copy link
Contributor

cwgoes commented Oct 9, 2018

We should verify this once staking refactor has been completed.

This is still an issue; the staking refactor did not change the delegation/undelegation logic.

@cwgoes
Copy link
Contributor

cwgoes commented Oct 9, 2018

I think we need to change the approach here altogether, this seems like an attack vector - if it's possible to get "extra" tokens by rounding, there's likely some way to create such delegations en masse and mint currency. Either we need to round down instead, or we need to restrict unbonding to whole-token amounts.

@jaekwon
Copy link
Contributor

jaekwon commented Oct 9, 2018

rounding down seems fine for now...

@cwgoes
Copy link
Contributor

cwgoes commented Oct 9, 2018

rounding down seems fine for now...

OK, let's also update the pool accordingly so supply tracking remains consistent.

@rigelrozanski
Copy link
Contributor

I think rounding down is fine because this is going to be such a fractionally small amount of tokens (10^-8 of an atom) should be okay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants