The report reveals a vulnerability where a flashloan can be used to steal staking rewards. The provided proof of concept demonstrates the issue, where a user can take advantage of the earned rewards calculation using the spot balance. By flashloaning a large amount of tokens, staking them, and immediately withdrawing, the user can unfairly claim a significant portion of the staking rewards.
The vulnerability stems from the fact that the earned function calculates rewards based on the user's balance (balanceOf). By flashloaning a significant amount of tokens, staking them, and immediately withdrawing, users can manipulate the balance and claim a higher portion of the staking rewards than they should be entitled to.
Tools Used
Manual Review
Recommended Mitigation Steps
To address this vulnerability, it is recommended to avoid using the spot balance (balanceOf) to calculate rewards. Instead, consider using a different approach that mitigates the risk of flashloan-based manipulation. By employing alternative methods to calculate rewards that are not affected by flashloaned tokens, the vulnerability can be effectively mitigated.
Lines of code
https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/miner/stakerewardV2pool.sol#L107
Vulnerability details
Impact
The report reveals a vulnerability where a flashloan can be used to steal staking rewards. The provided proof of concept demonstrates the issue, where a user can take advantage of the earned rewards calculation using the spot balance. By flashloaning a large amount of tokens, staking them, and immediately withdrawing, the user can unfairly claim a significant portion of the staking rewards.
Proof of Concept
The vulnerability stems from the fact that the
earned
function calculates rewards based on the user's balance (balanceOf
). By flashloaning a significant amount of tokens, staking them, and immediately withdrawing, users can manipulate the balance and claim a higher portion of the staking rewards than they should be entitled to.Tools Used
Manual Review
Recommended Mitigation Steps
To address this vulnerability, it is recommended to avoid using the spot balance (
balanceOf
) to calculate rewards. Instead, consider using a different approach that mitigates the risk of flashloan-based manipulation. By employing alternative methods to calculate rewards that are not affected by flashloaned tokens, the vulnerability can be effectively mitigated.Assessed type
Token-Transfer