Tadle

Tadle
DeFiFoundry
27,750 USDC
View results
Submission Details
Severity: medium
Valid

Strict Balance Equality Checks Leading to Transfer Failures in TokenManager

Summary

The TokenManager contract employs strict balance checks in the _transfer function, which can cause valid transfers to revert when dealing with certain ERC20 tokens. These tokens may include fee-on-transfer tokens, rebasing tokens, or any other tokens that do not follow the standard balance update behavior.

Vulnerability Details

The _transfer function in the TokenManager contract contains strict balance checks to ensure that the transferred amounts match exactly with the expected before and after balances.

if (fromBalanceAft != fromBalanceBef - _amount) {
revert TransferFailed();
}
if (toBalanceAft != toBalanceBef + _amount) {
revert TransferFailed();
}

These conditions rely on exact arithmetic to verify the transfer amounts. While this approach works for most ERC20 tokens, it can fail for ERC20 tokens with special accounting rules, such as:

  1. Fee-on-Transfer Tokens: These tokens deduct a fee from the transferred amount. For example, if a 1% fee is deducted on a transfer of 100 tokens, the recipient receives 99 tokens. Consequently, the balance check fails as the toBalanceAft will not match toBalanceBef + _amount.

  2. Rebasing Tokens: These tokens periodically adjust balances, leading to dynamic balance updates that may not align with the simple difference expected in the balance checks.

Impact

The strict balance checks will cause valid transfers to revert for some ERC20 tokens, leading to:

  1. User Frustration: Users attempting to transfer fee-on-transfer tokens or rebasing tokens through the TokenManager contract will face failed transactions.

  2. Inaccessible Funds: The inability to transfer tokens correctly might lock user funds within the contract or prevent them from using certain tokens within the broader application context.

  3. Operational Failures: If the application relies on these token transfers for functionality, it might lead to broader operational issues and disruptions.

Tools Used

Foundry

Recommendations

  • Adjust the balance checks to accommodate potential discrepancies caused by all ERC20 token behaviors.

  • Implement a flag or mechanism to detect fee-on-transfer tokens and handle them appropriately.

Updates

Lead Judging Commences

0xnevi Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-TokenManager-FOT-Rebasing

Valid medium, there are disruptions to the ability to take market actions. The following functions will be disrupted without the possibiliy of reaching settlement, since the respective offers cannot be created/listed regardless of mode when transferring collateral token required to the CapitalPool contract or when refunding token from user to capital pool during relisting. So withdrawal is not an issue - `createOffer()` - reverts [here](https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L96-L102) - `listOffer()` - reverts [here](https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L355-L362) - `relistOffer()` - reverts [here](https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L515-L521) - `createTaker()` - reverts [here](https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L831-L836) I believe medium severity is appropriate although the likelihood is high and impact is medium (only some level of disruption i.e. FOT tokens not supported and no funds at risk)

Support

FAQs

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