FeeBuyback.submit() method may fail if all allowance is not used by referral contract
The FeeBuyback contract uses safeApprove to grant the referral contract an allowance of Telcoin tokens. If the referral contract does not spend the full allowance, the next call to submit() reverts because safeApprove refuses to change a non-zero allowance to another non-zero value.
0xGoodess Follow with ddimitrov22, jasonxiale and 2 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-telcoin-judging/issues/22
Found by
0xGoodess, ddimitrov22, jasonxiale, jonatascm, spyrosonic10
Summary
Inside submit() method of FeeBuyback.sol, if token is _telcoin then it safeApprove to _referral contract. If _referral contract do not use all allowance then submit() method will fail in next call.
Vulnerability Detail
SafeApprove() method of library SafeERC20Upgradeable revert in following scenario.
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance");
Submit method is doing safeApproval of Telcoin to referral contract. If referral contract do not use full allowance then subsequent call to submit() method will fails because of SafeERC20: approve from non-zero to non-zero allowance. FeeBuyback contract should not trust or assume that referral contract will use all allowance. If it does not use all allowance in increaseClaimableBy() method then submit() method will revert in next call. This vulnerability exists at two places in submit() method. Link given in code snippet section.
Impact
Submit() call will fail until referral contract do not use all allowance.
Code Snippet
Tool used
Manual Review
Recommendation
Reset allowance to 0 before non-zero approval.
_telcoin.safeApprove(address(_referral), 0);
_telcoin.safeApprove(address(_referral), _telcoin.balanceOf(address(this)));
Discussion
amshirif
https://github.com/telcoin/telcoin-audit/pull/3
dmitriia
Looks ok
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 code calls safeApprove with a non-zero amount without first resetting the existing allowance to zero, which the SafeERC20 library forbids.
Impact
The submit() function will revert on subsequent calls until the referral contract uses the entire allowance, potentially blocking normal operation.
What the attacker needed
Referral contract does not use full allowance
The fix
Reset the allowance to zero before setting a new non-zero allowance.
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.
A smart contract can let another contract spend its tokens by setting an allowance. A safety check in the token library blocks changing an allowance from one non-zero amount to another non-zero amount. Because the code never resets the allowance to zero first, a later call fails when the previous allowance was not fully used.
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.