Open hats-bug-reporter[bot] opened 9 months ago
This is not a vulnerability and will not lead to loss of funds. If the approve is not successful the subsequent transfer of funds to the exchange may fail, as it may for other reasons even if the approve was successful. Success of the transfer is checked, so there is no need for an additional check here.
Github username: @YowiSec Twitter username: YowiSec Submission hash (on-chain): 0x24e77e64fb763309e0e27e4d28612c7ed62eb6cbea216860ef936081c719e28e Severity: low
Description:
Description
The
_doDeposit
internal function in theBfxVault
contract fails to check the return value of thepaymentToken.approve(address(bfx), amount)
call. According to the ERC20 standard, the approve function returns a boolean value indicating the success or failure of the operation. Ignoring this return value can lead to the contract incorrectly assuming that the approval succeeded even if it did not. This assumption is problematic when the subsequent bfx.deposit(amount) call is made, as it relies on the approval being successful to function correctly.Impact
If the approve operation fails but the contract proceeds without acknowledging the failure, any mechanisms depending on the successful approval and subsequent deposit (e.g., staking mechanisms, reward calculations) may behave unexpectedly, potentially leading to loss of funds, locked assets, or a compromised state of the contract's logic. This unchecked return value poses a risk of silent failures, where the contract's state becomes inconsistent with the actual holdings and permissions, leading to operational discrepancies and security vulnerabilities.
Proof of Concept (PoC)
To see how the
BfxVault
contract handles a failed deposit, we must first create a scenario where the approval of a deposit fails.Start by first adding the following code to
DummyToken.sol
:Then for the test function, add the following to
BfxVault.sol
:Finally, run the test function with:
Recommended Mitigation
There are a few ways to mitigate this issue including but not limited to:
Check Return Values:
Modify the _doDeposit function to check the return value of the approve call and revert if the operation fails. For example:
Use SafeERC20 Library:
Utilize OpenZeppelin's SafeERC20 library for token operations. SafeERC20 wraps ERC20 functions with checks that revert on failure, abstracting away the need to manually check return values and improving code readability and safety.
Incorporating these mitigations will enhance the contract's security and robustness, ensuring that the
deposit
operations proceed only when prerequisites are successfully met, thereby safeguarding against unintended behaviors and potential vulnerabilities.