Unregulated joining fees
The TrueFi pool's join function deducts a joining fee that can be set up to 100% of the deposit, and the Sherlock strategy does not check the minted shares, so all deposited funds could be lost to fees. An attacker cannot directly exploit this, but a malicious or compromised pool owner could set the fee to 100%, causing the strategy to lose all funds.
Anurag Jain Follow with defsec
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-09-sherlock-judging/tree/main/001-M
Found by
csanuragjain, defsec
Summary
tfUSDC.join deducts fees from deposited balance. Now this fees is unregulated and could be 100% of amount passed as can be seen at setJoiningFee function at https://github.com/trusttoken/contracts-pre22/blob/main/contracts/truefi2/TrueFiPool2.sol#L449. Since minting will not fail even with zero amount, our contract will end up everything given as fees
Vulnerability Detail
- Observe the _deposit function
function _deposit() internal override whenNotPaused {
// https://github.com/trusttoken/contracts-pre22/blob/main/contracts/truefi2/TrueFiPool2.sol#L469
tfUSDC.join(want.balanceOf(address(this)));
...
}
- This makes call to join function
function join(uint256 amount) external override joiningNotPaused {
uint256 fee = amount.mul(joiningFee).div(BASIS_PRECISION);
uint256 mintedAmount = mint(amount.sub(fee));
claimableFees = claimableFees.add(fee);
// TODO: tx.origin will be deprecated in a future ethereum upgrade
latestJoinBlock[tx.origin] = block.number;
token.safeTransferFrom(msg.sender, address(this), amount);
emit Joined(msg.sender, amount, mintedAmount);
}
- As we can see this join function deducts a fees from the deposited amount before minting. Lets see this joining fees
- The joining fees is introduced using setJoiningFee function
function setJoiningFee(uint256 fee) external onlyOwner {
require(fee <= BASIS_PRECISION, "TrueFiPool: Fee cannot exceed transaction value");
joiningFee = fee;
emit JoiningFeeChanged(fee);
}
- This means the joiningFee will always be in between 0 to BASIS_PRECISION. This BASIS_PRECISION can be 100% as shown
uint256 private constant BASIS_PRECISION = 10000;
- This means if joiningFee is set to BASIS_PRECISION then all user deposit will goto joining fees with user getting nothing
Impact
Contract will lose all deposited funds
Code Snippet
Tool used
Manual Review
Recommendation
Post calling join, check amount of shares minted for this user (use balanceOF on TrueFiPool2.sol) and if it is below minimum expected revert the transaction
uint256 tfUsdcBalance = tfUSDC.balanceOf(address(this));
require(tfUsdcBalance>=minSharesExpected, "Too high fees");
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The strategy contract does not verify the number of shares minted after joining the TrueFi pool, allowing a 100% joining fee to consume the entire deposit.
Impact
The contract could lose all deposited funds if the joining fee is set to 100%.
What the attacker needed
JoiningFee set to 100% by pool owner
The fix
After calling join, check the number of shares minted and revert if it is below a minimum expected amount.
How it was found
- Observe the _deposit function which calls tfUSDC.join with the contract's balance.
- The join function deducts a fee from the amount before minting shares.
- The joining fee is set by setJoiningFee, which allows up to BASIS_PRECISION (100%).
- If the fee is set to 100%, all deposited funds go to fees and the user receives no shares.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract deposits user funds into an external pool. That pool charges a fee when joining, and the fee can be set as high as 100%. The contract does not check how many shares it receives, so if the fee is 100%, all the money goes to fees and the contract gets nothing in return.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.