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

Comments

@hwwhww
Copy link
Contributor

@hwwhww 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)
@vbuterin
Copy link
Contributor

@vbuterin vbuterin commented Mar 7, 2019

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

Loading

@JustinDrake
Copy link
Collaborator

@JustinDrake JustinDrake commented Mar 28, 2019

decrement_balance implemented 🎉

Loading

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

Successfully merging a pull request may close this issue.

None yet
3 participants