Reward computation is wrong
The reward distribution function in a lending protocol calculates a user's share of rewards using outdated total supply and debt values, because it distributes rewards before updating the accrual state. This can cause users to receive incorrect reward amounts, with some users getting more than their fair share and others getting less.
Submitted by cmichel
The LendingPair.accrueAccount function distributes rewards before updating the cumulative supply / borrow indexes as well as the index + balance for the user (by minting supply tokens / debt). This means the percentage of the user’s balance to the total is not correct as the total can be updated several times in between.
function accrueAccount(address _account) public {
// distributes before updating accrual state
_distributeReward(_account);
accrue();
_accrueAccountInterest(_account);
if (_account != feeRecipient()) {
_accrueAccountInterest(feeRecipient());
}
}
Example: Two users deposit the same amounts in the same block. Thus, after some time they should receive the same tokens.
- User A and B deposit 1000 tokens (in the same block) and are minted 1000 tokens in return. Total supply =
2000 - Assume after 50,000 blocks,
AcallsaccrueAccount(A)which first calls_distributeReward. A is paid out 1000/2000 = 50% of the 50,000 blocks reward since deposit. Afterwards,accrue+_accrueAccountInterest(A)is called andAis minted 200 more tokens due to supplier lending rate. The supply totalSupply is now 2200. - After another 50,000 blocks,
AcallsaccrueAccount(A)again. which first calls_distributeReward. A is paid out 1200/2200 = 54.5454% of the 50,000 blocks reward since deposit.
From here, you can already see that A receives more than 50% of the 100,000 block rewards although they deposited at the same time as B and didn’t deposit or withdraw any funds. B will receive ~1000/2200 = 45% (ignoring any new LP supply tokens minted for A’s second claim.)
The impact is that wrong rewards will be minted users which do not represent their real fair share. Usually, users will get fewer rewards than they should receive, as their individual interest was not updated yet, but the totals (total debt and total supply) could have been updated by other accounts in between.
There are two issues that both contribute to it:
- total LP supply and total debt must be updated by the total new interest when
accrueis called, not only increased by an individual user’s interest. See my other issue “Reward computation is wrong” that goes into more depth - Lending/borrow accrual must happen before reward distribution
talegift (Wild Credit) acknowledged but disagreed with severity:
Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.
Update to severity - 2
Disagree with sponsor about severity, this is significant accounting error.
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 reward distribution occurs before the accrual of interest and update of total supply/debt, so the user's share is computed with stale totals.
Impact
Wrong rewards will be minted, not representing users' fair share; usually users get fewer rewards than they should, but some could get more.
What the attacker needed
Users deposit into the lending pair; Time passes to accrue interest; User calls accrueAccount
The fix
The fix is to update total LP supply and total debt by the total new interest when accrue is called, and to perform lending/borrow accrual before reward distribution.
How it was found
- User A and B deposit 1000 tokens each in the same block, total supply becomes 2000.
- After 50,000 blocks, A calls accrueAccount(A), which distributes rewards based on A's 1000 out of 2000 total supply (50%).
- Then accrue and _accrueAccountInterest(A) mint 200 more tokens to A, increasing total supply to 2200.
- After another 50,000 blocks, A calls accrueAccount(A) again, and rewards are distributed based on A's 1200 out of 2200 total supply (54.5454%).
- As a result, A receives more than 50% of the total rewards over 100,000 blocks, while B receives less.
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.
In a lending protocol, users earn rewards based on how much they have deposited compared to the total deposits. This report shows that the code pays out rewards before updating the total deposit amounts, so the calculation uses old numbers. As a result, some users can get more rewards than they should, while others get less.
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.