`FlashRolloverLoan_G5` will not work for certain tokens due to not setting the approval to `0` after repaying a loan
The FlashRolloverLoan_G5 contract approves TELLER_V2 for the repay amount but TELLER_V2 may pull less, leaving a dust approval. Some ERC20 tokens like USDC revert when changing a non-zero approval to another non-zero value, so the subsequent approval to POOL fails and the flash loan is blocked.
0x73696d616f Follow with EgisSecurity, MaslarovK.eth and 3 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-04-teller-finance-judging/issues/140
Found by
0x73696d616f, EgisSecurity, MaslarovK.eth, givn, merlin, mgf15
Summary
FlashRolloverLoan_G5::_repayLoanFull() approves TELLER_V2 for _repayAmount, but TELLER_V2 always pulls the principal and interest, possibly leaving some dust approval left. Some tokens revert when trying to set approvals from non null to non null, which will make FlashRolloverLoan_G5 revert.
Vulnerability Detail
Some ERC20 tokens must have 0 approval before setting an approval to a non 0 amount, such as USDC.
The interest rises with block.timestamp, so borrowers will likely take a flash loan slightly bigger than _repayAmount to take this into account, or repay will fail.
Thus, when the approval is set for TellerV2 of the _principalToken, principal + interest may be less than the approval, which will leave a dust approval.
FlashRolloverLoan_G5::executeOperation() later on approves POOL, which will revert as a dust amount was left.
Impact
FlashRolloverLoan_G5 will not work and be DoSed.
Code Snippet
https://github.com/sherlock-audit/2024-04-teller-finance/blob/main/teller-protocol-v2-audit-2024/packages/contracts/contracts/LenderCommitmentForwarder/extensions/FlashRolloverLoan_G5.sol#L243-L245 https://github.com/sherlock-audit/2024-04-teller-finance/blob/main/teller-protocol-v2-audit-2024/packages/contracts/contracts/LenderCommitmentForwarder/extensions/FlashRolloverLoan_G5.sol#L194-L196
Tool used
Manual Review
Vscode
Recommendation
Set the approval to 0 after repaying the loan.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/teller-protocol/teller-protocol-v2-audit-2024/pull/32
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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
The contract did not reset the token approval to zero after repaying the loan, leaving a dust allowance that caused a later approval to revert for tokens that require zeroing first.
Impact
FlashRolloverLoan_G5 will not work and be DoSed for tokens that require zeroing approvals, such as USDC.
What the attacker needed
Token requires zeroing approval first; flash loan amount exceeds actual repay
The fix
The protocol team fixed this issue by setting the approval to 0 after repaying the loan.
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.
Some tokens, such as USDC, require that you first set an allowance to zero before you can set it to a new non-zero amount. The contract left a tiny leftover allowance after repaying a loan, so the next attempt to set an allowance failed and the whole flash loan reverted.
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.