The pay() function can still be DOSed
The pay() function in TimeswapPair can be front-run by an attacker who repays a tiny amount of the victim's debt, causing the victim's full repayment to underflow and revert. This blocks users from repaying their full debt, a denial-of-service.
Submitted by IllIllI
From the prior contest:
in the pay() function users repay their debt and in line 364: https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L364 it decreases their debt.
lets say a user wants to repay all his debt, he calls the pay() function with his full debt. an attacker can see it and frontrun to repay a single token for his debt (since it’s likely the token uses 18 decimals, a single token is worth almost nothing) and since your solidity version is above 0.8.0 the line: due.debt -= assetsIn[i]; will revert due to underflow
The attacker can keep doing it everytime the user is going to pay and since 1 token is baisicly 0$ (18 decimals) the attacker doesn’t lose real money
code-423n4/2022-01-timeswap-findings#86 (comment)
The sponsor said this about the fix:
The convenience contract will implement how much asset to pay in.
code-423n4/2022-01-timeswap-findings#86 (comment)
The pay() function however is still DOSable. Having the Convenience contract contain a workaround means the Convenience contract is no longer a convenience but a requirement.
due.debt -= param.assetsIn[i];
Proof of Concept
From the prior contest:
A DoS on every user that repay his full debt (or enough that the difference between his total debt to what he pays his negligible)
code-423n4/2022-01-timeswap-findings#86
Recommended Mitigation Steps
Move the DOS protection to TimeswapPair.pay()
amateur-dev (Timeswap) confirmed
0xleastwood (judge) commented:
I believe this is a potential security risk and
mediumrisk is appropriate. It is important to ensure protocol availability cannot be negatively impacted by nefarious actors.
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 pay() function subtracts the full repayment amount from the debt without checking for underflow, so a prior partial repayment by an attacker makes the subtraction revert.
Impact
Users can be repeatedly blocked from repaying their full debt, and the attacker loses almost nothing because a single token is worth very little.
What the attacker needed
Attacker can front-run transactions; victim repays full or near-full debt; attacker pays a tiny amount of victim's debt
The fix
The DOS protection should be moved into TimeswapPair.pay() rather than relying on a separate Convenience contract.
How it was found
- A user calls pay() with their full debt to repay it.
- An attacker front-runs and repays a single token of the user's debt.
- The user's pay() call then subtracts the full amount from the reduced debt, causing an underflow revert.
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.
When you repay a loan, the contract subtracts what you pay from what you owe. If someone else pays a tiny part of your debt just before you do, your full payment becomes larger than the remaining debt, and the subtraction fails, so your repayment is rejected. An attacker can repeat this cheaply to stop you from ever repaying in full.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.