Skip to content
Business logic Audit finding Intermediate

Rewards might be lost due to the error that _updateRewardIndex() might advance lastBalance without advancing index for a token

The reward index update function can advance the last balance without increasing the index when the accrued reward per share rounds down to zero, causing rewards to be lost. An attacker could repeatedly call getRewards to trigger this rounding loss, and the loss accumulates over time.

chaduke Follow with Evo

Originally disclosed on Code4rena

Submitted by chaduke, also found by Evo

The function _updateRewardIndex() is used to update the lastBalance and index of each reward token. This function will be called when a user deposits, withdraws collateral or claims rewards.

However, the function might not advance index when accrued.divDown(totalShares) = 0. This might happen when totalShares is too big and accrued is too small. One case is that the number of decimals for the reward token is too small.

https://github.com/code-423n4/2024-10-loopfi/blob/d219f0132005b00a68f505edc22b34f9a8b49766/src/pendle-rewards/RewardManager.sol#L74

For example, the USDC token only has 6 decimals.

Suppose accrued = $100 = 100*10**6, and totalShares = 200M = 200 * 10** 6 * 10**18; then we have  accrued.divDown(totalShares) = 0.

Furthermore, if function _updateRewardIndex() is called more frequently, either because a malicious user keeps calling getRewards() (the gas fee is low on Arbitrum) or simply because the community is large so there is a high chance that for each block (per 12 seconds on Ethereum), there is someone who calls a withdraw/deposit/getRewards function. As a result, accrued could be small, leading to accrued.divDown(totalShares) = 0. Meanwhile, _updateRewardIndex() always advances lastBalance when accrued !=0:

https://github.com/code-423n4/2024-10-loopfi/blob/d219f0132005b00a68f505edc22b34f9a8b49766/src/pendle-rewards/RewardManager.sol#L78

This means the accrued rewards are lost! Nobody will receive the rewards since index has not changed.

More importantly, due to the rounding down error for accrued.divDown(totalShares), there is always a slight loss for the rewards, which is accumulative over time.

Recommended Mitigation Steps

The fix is simple. Calculate deltaIndex = accrued.divDown(totalShares) and advance lastBalance by deltaIndex.mulDown(totalShares). In this way, index and lastBalance will always advance in the same pace; in particular if index does not advance, then lastBalance will not advance either. The rounding down error is eliminated too since the lastBalance will not be accrued but by deltaIndex.mulDown(totalShares).

Assessed type

Math

0xtj24 (LoopFi) confirmed

0xAlix2 (warden) commented:

@Koolex - I agree that this is an issue; however, the audit docs states that the ERC20s that are used by the protocol are WETH and PendleLPs which are both 18 decimals.

ERC20 used by the protocol | WETH, PendleLPs

But I’m not sure if that should be considered valid in this context.

Koolex (judge) commented:

There is another issue here.

malicious user keeps calling getRewards()


The original report as published on Code4rena, by chaduke. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the code updates lastBalance by the full accrued amount even when the per-share index increment rounds down to zero, so the two values get out of sync.

Impact

Rewards could be permanently lost and the loss may accumulate over time, especially if a malicious user repeatedly calls getRewards or if many users interact frequently.

What the attacker needed

Reward token has few decimals; accrued reward is small relative to total shares; frequent calls to getRewards or deposit/withdraw

The fix

The fix should calculate the index delta first and then advance lastBalance by that delta multiplied by total shares, so both values move together and rounding loss is eliminated.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Rewards are shared among users based on how many shares they hold. The code calculates a reward per share by dividing total rewards by total shares, but if that division rounds down to zero, the reward counter does not go up even though the contract thinks it has paid out. This means some rewards disappear and no user ever receives them.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by chaduke

View all

21 more disclosed reports, best first.

More from LoopFi

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.