Tadle

Tadle
DeFi
30,000 USDC
View results
Submission Details
Severity: low
Invalid

Overpayments of wrapped native tokens using `TokenManager::tillIn` are not handled by the protocol.

Description

TokenManager::tillIn accepts payments in wrapped native tokens, but it seems that possible overpayments are not returned to the msg.sender and even possibly looked up in the TokenManager contract.
The TokenManager::tillIn function is called with msg.value specifically in the PreMarkets.sol contract, while e.g. the collateral is transferred to the TokenManager contract via PreMarkets::createOffer, which is then transferred to the CapitalPool.sol, and in a few other cases. Here is an example from PreMarkets::createOffer (https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/PreMarkets.sol#L86-L101):

/// @dev transfer collateral from _msgSender() to capital pool
uint256 transferAmount = OfferLibraries.getDepositAmount(
params.offerType,
params.collateralRate,
params.amount,
true,
Math.Rounding.Ceil
);
//@audit - CHECK: What happens if msg.value != transferAmount???
ITokenManager tokenManager = tadleFactory.getTokenManager();
@> tokenManager.tillIn{value: msg.value}(
_msgSender(),
params.tokenAddress,
transferAmount,
false
);

Overpayments should be handled in an appropriate manner so that the overpaid funds can be returned to msg.sender and not be looked up in the TokenManager contract.

The TokenManager::tillIn function checks in line 86 (https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/TokenManager.sol#L86) that the caller has provided an amount of wrapped native tokens (msg.value) greater than or equal to the value of the TokenManager::tillIn function parameter _amount at the time of execution:

if (_tokenAddress == wrappedNativeToken) {
/**
* @dev token is native token
* @notice check msg value
* @dev if msg value is less than _amount, revert
* @dev wrap native token and transfer to capital pool
*/
@> if (msg.value < _amount) {
revert Errors.NotEnoughMsgValue(msg.value, _amount);
}

However, the audited contracts lack the functionality to refund the msg.sender in case of a possible overpayment. Instead, it appears that the overpayment amounts will accrue to the TokenManager contract balance.

Impact

The absence of a refund mechanism for overpayments in the TokenManager::tillIn function could lead to users losing funds. If the amount sent (msg.value) exceeds the required transfer amount, the excess funds remain locked within the contract without being utilized or accessible to the user. This could discourage user participation due to the risk of financial loss and might require users to rely on additional external processes to recover their overpaid amounts, creating a poor user experience.

Tools used

manual review, vscode

Recommended Mitigation

To address the issue of potential overpayments in TokenManager::tillIn, consider implementing the following mitigation strategies:

  1. Calculate and refund overpayment amounts to msg.sender in TokenManager.sol.

  2. As a possible solution alternative, consider implementing a check for an exact match between msg.value and _amount using the condition if (msg.value != _amount) in the TokenManager::tillIn function. If these values do not match, revert the transaction to prevent both underpayments and overpayments. However, ensure that this approach is compatible with all intended use cases for the contract.

Updates

Lead Judging Commences

0xnevi Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

[invalid] finding-TokenManager-tillin-excess

Invalid, these are by default, invalid based on codehawks [general guidelines](https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity#findings-that-may-be-invalid). The check implemented is simply a sufficiency check, it is users responsibility to only send an appropriate amount of native tokens where amount == msg.value when native token is intended to be used as collateral (which will subsequently be deposited as wrapped token). All excess ETH can be rescued using the `Rescuable.sol` contract. > Users sending ETH/native tokens > If contracts allow users to send tokens acc111identally.

Support

FAQs

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