DeFiHardhatFoundry
250,000 USDC
View results
Submission Details
Severity: low
Invalid

Front-Running Vulnerability in spendAllowance Function of LibTokenApprove.sol

Summary

The LibTokenApprove.sol contract in the Beanstalk project has a front-running vulnerability in the spendAllowance function. This vulnerability can be exploited to spend beyond the approved token allowance, causing inconsistencies in balances and potentially leading to loss of funds.

Vulnerability Details

The spendAllowance function in LibTokenApprove.sol performs two separate steps:

  • Check allowance: Checks if the current allowance is sufficient to spend the desired amount of tokens.

  • Update allowance: If sufficient, the function decreases the allowance by the amount of tokens spent.

However, separating these two steps creates a small window of time between checking and updating the allowance. An attacker can exploit this window to perform another transaction before the allowance is updated, resulting in spending beyond the original approved allowance.

function spendAllowance(address owner, address spender, IERC20 token, uint256 amount) internal {
uint256 currentAllowance = allowance(owner, spender, token);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "Token: insufficient allowance");
approve(owner, spender, token, currentAllowance - amount); // Hạn mức chưa được cập nhật tại đây
}
}

Impact

The attacker can spend tokens beyond the approved allowance, causing loss of funds for the token owner.

Tools Used

Manual

Recommendations

use the _spendAllowance function from OpenZeppelin Contracts, combining the allowance check and update into a single atomic step

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
// ...
using SafeERC20 for IERC20;
// ...
function spendAllowance(address owner, address spender, IERC20 token, uint256 amount) internal {
SafeERC20.safeDecreaseAllowance(token, owner, spender, amount);
}
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational/Gas

Invalid as per docs https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity

Support

FAQs

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