Skip to content
Business logic Audit finding Intermediate

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

https://github.com/prepo-io/prepo-monorepo/blob/feat/2022-12-prepo/apps/smart-contracts/core/contracts/Collateral.sol#L45-L61

https://github.com/prepo-io/prepo-monorepo/blob/feat/2022-12-prepo/apps/smart-contracts/core/contracts/Collateral.sol#L64-L78

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

Impact

  • There are some ERC20 tokens that deduct a fee on every transfer call. If these tokens are used as baseToken then:

    1. When depositing into the Collateral contract, the recipient will receive collateral token more than what they should receive.
    2. 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.
    3. When withdrawing from the Collateral contract, the user will receive less baseToken amount than what they should receive.
    4. The treasury will receive less fee and the user will receive more PPO tokens that occur in DepositHook and WithdrawHook.

Proof of Concept

Given:

Recommended Mitigation Steps

  1. 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;
  1. Then use actualAmount instead of \_amount to perform any further calculations or external calls.

Note: apply the same logic for DepositHook and WithdrawHook as well at:

ramenforbreakfast (prePO) confirmed

Picodes (judge) decreased severity to Medium


The original report as published on Code4rena, by Koolex. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. User calls deposit with an amount of 100e18.
  2. The contract calls transferFrom, but the fee-on-transfer token deducts 1%, so only 99e18 arrives.
  3. The contract passes the original 100e18 to DepositHook and calculates collateralMintAmount from it.
  4. 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.

More by Koolex

View all

10 more disclosed reports, best first.

More from prePO contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.