Submitted by cmichel
The unstake function does not immediately update the exchange rates. It first computes the validatorSharesRemove = tokensToShares(amount, v.exchangeRate) with the old exchange rate.
Only afterwards, it updates the exchange rates (if the validator is not disabled):
More shares for the amount are burned than required and users will lose rewards in the end.
Demonstrating that users will lose rewards:
If the user had first called redeemAllRewards and unstake afterwards theyd have received their 2000 tokens.
The exchange rates always need to be updated first before doing anything.
Move the updateGlobalExchangeRate() and updateValidator(v) calls to the beginning of the function.
kitti-katy (Covalent) confirmed
GalloDaSballo (judge) commented:
