The recipient receives free collateral token if an ERC20 token that deducts a fee on transfer used as baseToken
The Collateral contract uses the requested deposit amount rather than the actual amount received when the baseToken deducts a fee on transfer, so the depositor receives more collateral tokens than they should. The DepositRecord and hooks also track incorrect amounts, leading to over-minting of PPO tokens and underpayment of fees.
Koolex Follow with idkwhatimdoing, adriro and 4 others
Originally disclosed on Code4rena
Submitted by Koolex, also found by idkwhatimdoing, adriro, haku, SmartSek, KingNFT, and pavankv
Impact
-
There are some ERC20 tokens that deduct a fee on every transfer call. If these tokens are used as baseToken then:
- When depositing into the Collateral contract, the recipient will receive collateral token more than what they should receive.
- The DepositRecord contract will track wrong user deposit amounts and wrong globalNetDepositAmount as the added amount to both will be always more than what was actually deposited.
- When withdrawing from the Collateral contract, the user will receive less baseToken amount than what they should receive.
- The treasury will receive less fee and the user will receive more
PPOtokens that occur in DepositHook and WithdrawHook.
Proof of Concept
Given:
-
baseToken is an ERC20 token that deduct a fee on every transfer call.
-
FoT is the deducted fee on transfer.
-
The user deposits baseToken to the Collateral contract by calling
depositfunction passing\_amountas 100e18. -
baseToken.transferFromis called to transfer the amount from the user to the contract. -
The contract receives the _amount` - FoT. Let’s assume the FoT percentage is 1%. Therefore, the actual amount received is 99e18.
-
When the DepositHook is called. the
\_amountpassed is 100e18 which is wrong as it should be the actual amount 99e18. -
Calculating collateralMintAmount is based on the
\_amount(100e18- the fee for treasury) which will give the recipient additional collateral token that they shouldn’t receive.
Recommended Mitigation Steps
-
Consider calculating the actual amount by recording the balance before and after.
- For example:
uint256 balanceBefore = baseToken.balanceOf(address(this));
baseToken.transferFrom(msg.sender, address(this), _amount);
uint256 balanceAfter = baseToken.balanceOf(address(this));
uint256 actualAmount = balanceAfter - balanceBefore;
- Then use actualAmount instead of
\_amountto perform any further calculations or external calls.
Note: apply the same logic for DepositHook and WithdrawHook as well at:
- https://github.com/prepo-io/prepo-monorepo/blob/feat/2022-12-prepo/apps/smart-contracts/core/contracts/DepositHook.sol#L49-L50
- https://github.com/prepo-io/prepo-monorepo/blob/feat/2022-12-prepo/apps/smart-contracts/core/contracts/WithdrawHook.sol#L76-L77
ramenforbreakfast (prePO) confirmed
Picodes (judge) decreased severity to Medium
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 contract uses the requested transfer amount instead of the actual received amount when calculating collateral and recording deposits.
Impact
If a fee-on-transfer token is used as baseToken, depositors could receive excess collateral and PPO tokens, while the treasury receives less fee; the report does not state that this was exploited in practice.
What the attacker needed
BaseToken is a fee-on-transfer ERC20 token; user can call deposit
The fix
The contract should measure the actual amount received by comparing the balance before and after the transfer, and use that actual amount for further calculations and external calls.
How it was found
- User calls deposit with an amount of 100e18.
- The contract calls transferFrom, but the fee-on-transfer token deducts 1%, so only 99e18 arrives.
- The contract passes the original 100e18 to DepositHook and calculates collateralMintAmount from it.
- The user receives collateral tokens based on 100e18 instead of 99e18.
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.
Some tokens take a small fee when they are sent from one wallet to another. This contract assumed the full amount arrived and gave the user collateral tokens based on that full amount, so the user got extra tokens. The fix is to check the actual balance change after the transfer.
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.