-> Transfer
-> New Balance
-> Check points (user uses old balance, but total supply is the new one)
-> User lost rewards
-> New total Supply and correct total debt
In fixing this be careful not to cause a division by zero (as the initial deposit would)
This can only happen on deposits (which dilute rewards), if the same mistake was done on withdrawals, then value could be stolen
Mitigation
Because the code is tightly coupled, I think accruing and then transferring the tokens could be sufficient
Alternatively the scalable fix is to track the previous balance in storage as you suggested
I think tracking in storage is the best fix long term (allows to re-use the contract separately without bugs)
Impact
-> Transfer -> New Balance -> Check points (user uses old balance, but total supply is the new one) -> User lost rewards -> New total Supply and correct total debt
In fixing this be careful not to cause a division by zero (as the initial deposit would)
This can only happen on deposits (which dilute rewards), if the same mistake was done on withdrawals, then value could be stolen
Mitigation
Because the code is tightly coupled, I think accruing and then transferring the tokens could be sufficient
Alternatively the scalable fix is to track the previous balance in storage as you suggested
I think tracking in storage is the best fix long term (allows to re-use the contract separately without bugs)