Beginner FriendlyFoundryBridge
100 EXP
View results
Submission Details
Severity: high
Invalid

Unchecked return of approveTo() function, resulting in contract entering in an error prone state or behaving in a way that the developer did not anticipate

Summary

The approveTo function calls the approve function of the IERC20 interface, which is a standard interface for ERC20 tokens. The approve function returns a boolean value indicating whether the operation was successful or not. However, in this contract, this return value is not stored or used in any way.

Vulnerability Details

Since the return value is not saved or used in any way, if the approveTo function fails for any reason, the contract will not be aware of this and will proceed as if the operation was successful. This could lead to unexpected behavior or security issues.

Impact

There are several unexpected situations that could arise in a smart contract due to not handling return values properly. Here are a few examples:

  1. Failed External Calls: If an external function call fails and you're not checking the return value, your contract might continue to operate under the assumption that the call was successful. This could lead to incorrect states or behaviors in your contract. For example, if the approve function in your contract fails (perhaps due to insufficient gas), your contract would not know this and might continue to operate as if the approval was successful.

  2. Incorrect Interpretation of Return Values: If your contract incorrectly interprets the return value of an external function call, it might behave in a way that the developer did not intend. For example, if an external function returns a boolean value and your contract interprets false as true, your contract might make incorrect decisions based on this incorrect interpretation.

  3. Unchecked Return Values: If your contract does not check the return value of an external function call, it might ignore important information. For example, if an external function returns a success indicator and your contract does not check this indicator, your contract might not know whether the function call was successful or not.

By properly handling return values, you can prevent these unexpected situations and make your contract more robust and easier to debug.

Tools Used

Recommendations

Modify the approveTo function to store and handle the return value of the approve function.

Here's how you could do it:

- function approveTo(address target, uint256 amount) external onlyOwner {
+ function approveTo(address target, uint256 amount) external onlyOwner returns (bool) {
- token.approve(target, amount);
+ bool success = token.approve(target, amount);
+ require(success, "Approval failed");
+ return success;
}

In this modified version of the function, the return value of the approve function is stored in the success variable. Then, the require function is used to ensure that the approve operation was successful. If the approve operation failed (i.e., if success is false), the require function will throw an exception and revert all changes made in the current function call. If the approve operation was successful, the function will return true.

This way, you ensure that all return values of function calls are used, which can help prevent unexpected behaviour and make your contract easier to debug.

Updates

Lead Judging Commences

0xnevi Lead Judge
over 1 year ago
0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.