User doesn’t have to deposit for a week into the market to get their weekly reward from the LendingLedger
The LendingLedger contract rewarded users based on weekly deposits but rounded down to the start of the week, so a user could deposit just before the week ended and withdraw immediately after, still receiving a full week's reward. An attacker could exploit this to claim rewards without providing liquidity for the required duration.
In the LendingLedger contract, a user is rewarded with CANTO tokens depending on how long he has his deposit in the market. Rewards are distributed for each week during which the deposit was inside the market. However, the user can cheat this condition because we are rounding down to the start of the week, so the user can deposit at 23:59 at the end of the week and withdraw at 00:00 and still get rewarded as if he had his deposit for the whole week.
It’s difficult to propose a solution for this exploit without major changes in the contract’s architecture. Perhaps we can somehow split the amount based on the time the sync was made inside the week, let’s say Alice’s last_sync was in the middle of week0, she deposited 1 ether, thus her amount for the current epoch will be 1/2 ether. However there is a caveat, how do we fill the gaps? We can’t fill them with 1/2 ether. We can use this struct though,
Amount {
uint256 actualAmount,
uint256 fraction
}
so we can use fraction for the current epoch and actualAmount = 1 ether to fill the gaps.
Chosen as best due to clarity, conciseness, and presence of executable PoC
The rationale behind the High severity is that the purpose of veRWA is to attract liquidity to certain contracts as voted by CANTO holders, and this vulnerability defeats the purpose of attracting liquidity completely.
Reward calculation is now based on a time-weighted balance. Btw, while implementing the fix I noticed that the PoC here does not really highlight the problem. In the PoC, there is only one lender, so even if we take the deposit time into account, this lender should receive 100% of the epoch rewards (as they provided 100% of the liquidity within the market during this epoch). I modified the PoC to a scenario where there are two lenders, with one that deposited only for one second and one for the whole week. The one that deposited for the whole week should receive ~604800 times more rewards for this epoch, which is now the case:
The original report as published on Code4rena, by SpicyMeatball. 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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the reward calculation rounds the deposit time down to the start of the week, ignoring the actual duration the funds were present.
Impact
An attacker could claim rewards without providing liquidity for the full week, undermining the purpose of attracting liquidity.
What the attacker needed
Access to the lending market; ability to deposit and withdraw
The fix
Reward calculation was changed to be based on a time-weighted balance.
How it was found
Set up the market and rewards for a week.
Deposit into the market at 23:59 at the end of week 4.
Withdraw at 00:00 at the start of week 5.
Claim rewards and observe that the user receives a full week's reward.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
This is a smart contract bug where rewards are given for keeping money in a market for a week. But because the system only checks which week it is and not how long the money was actually there, someone can put money in just before the week ends and take it out right after, still getting the full week's reward. That means they get paid without really helping the market.
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.