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

Prevent balance underflow #727

Closed
hwwhww opened this issue Mar 7, 2019 · 2 comments
Closed

Prevent balance underflow #727

hwwhww opened this issue Mar 7, 2019 · 2 comments
Labels
general:question Further information is requested

Comments

@hwwhww
Copy link
Contributor

hwwhww commented Mar 7, 2019

Issue

  • There are several places that we deduct the state.validator_balances[validator_index] for penalties.
  • Logically, the validator would be ejected before the balance field is under the risk of underflow.
  • But, when we read the function separately, do we need to add some protection to prevent balance underflow? For example, change
state.validator_balances[index] -= penalty

to

state.validator_balances[index] = max(state.validator_balances[index] - penalty, 0)
@hwwhww hwwhww added the general:question Further information is requested label Mar 7, 2019
@vbuterin
Copy link
Contributor

vbuterin commented Mar 7, 2019

One way to fix this generally would be to define decrement_balance that way in #728.

@JustinDrake
Copy link
Contributor

decrement_balance implemented 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
general:question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants