Tadle

Tadle
DeFiFoundry
27,750 USDC
View results
Submission Details
Severity: high
Invalid

tokenManager::_transfer will fail due to race conditions

Summary

The transfer function in token manager compares the balances before and after the transfer to determine if the transfer was successful. However, this approach is flawed because it assumes that no other transfers or balance changes occur between the balance checks. In reality, balances could be altered by other transactions or contracts during the execution of this function, leading to incorrect conclusions about the transfer's success.

Vulnerability Details

race conditions on balances can lead to unexpected outcomes, especially when multiple transactions or contract calls are interacting with the same balance.

uint256 fromBalanceBef = IERC20(\_token).balanceOf(\_from);\
uint256 toBalanceBef = IERC20(\_token).balanceOf(\_to);
if (
_from == _capitalPoolAddr &&
IERC20(_token).allowance(_from, address(this)) == 0x0
) {
ICapitalPool(_capitalPoolAddr).approve(address(this));
}
_safe_transfer_from(_token, _from, _to, _amount);
uint256 fromBalanceAft = IERC20(_token).balanceOf(_from);
uint256 toBalanceAft = IERC20(_token).balanceOf(_to);
if (fromBalanceAft != fromBalanceBef - _amount) {
revert TransferFailed();
}

In this scenario, the race condition might occur as follows:

Initial Balance Check: The contract records the initial balance of _from.

External Call: Before or during the execution of transferFrom, an external contract or another transaction modifies the balance of _from. This could happen through a reentrancy attack, where the called contract (during the transferFrom operation) calls back into this contract or another contract to perform an additional transfer.

Final Balance Check: After the transferFrom operation, the contract checks the balance again and expects it to be the initial balance minus the _amount transferred. However, due to the external modification, the final balance might not match this expectation.

Impact

The transfer function will revert even when transfers go through

Tools Used

Manual Review

Recommendations

Use the safeTransfer module from openZeppelin, anything other than logging balance Before and after

Updates

Lead Judging Commences

0xnevi Lead Judge
about 1 year ago
0xnevi Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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