Skip to content
Business logic Audit finding Intermediate

Wrong fee calculation after totalSupply was 0

The fee calculation function does not update the last fee timestamp when the total supply is zero, so when tokens are minted again after a period of inactivity, fees are charged for the entire inactive period. This causes extra fee tokens to be minted, diluting the value of existing basket tokens and leading to a loss of user funds.

kenzo Follow

Originally disclosed on Code4rena

Submitted by kenzo

handleFees does not update lastFee if startSupply == 0. This means that wrongly, extra fee tokens would be minted once the basket is resupplied and handleFees is called again.

Impact

Loss of user funds. The extra minting of fee tokens comes on the expense of the regular basket token owners, which upon withdrawal would get less underlying than their true share, due to the dilution of their tokens’ value.

Proof of Concept

Scenario:

  • All basket token holders are burning their tokens. The last burn would set totalSupply to 0.
  • After 1 day, somebody mints basket tokens.

handleFees would be called upon mint, and would just return since totalSupply == 0. Note: It does not update lastFee.

} else if (startSupply == 0) {
            return;

Basket.sol#L136:#L137

  • The next block, somebody else mints a token. Now handleFees will be called and will calculate the fees according to the current supply and the time diff between now and lastFee:
uint256 timeDiff = (block.timestamp - lastFee);

Basket.sol#L139 But as we saw, lastFee wasn’t updated in the previous step. lastFee is still the time of 1 day before - when the last person burned his tokens and the basket supply was 0. So now the basket will mint fees as if a whole day has passed since the last calculation, but actually it only needs to calculate the fees for the last block, since only then we had tokens in the basket.

Recommended Mitigation Steps

Set lastFee = block.timestamp if startSupply == 0.

frank-beard (Kuiper) confirmed

0xleastwood (judge) commented:

The issue can be outlined as follows:

  • A user interacts with the basket and mints some amount of tokens, which sets lastFee = block.timestamp.
  • The same user decides to exit the basket and burn their tokens.
  • Some amount of time passes and another user enters the basket, but handleFees() did not set lastFee = block.timestamp. As a result, fees are charged on the user’s deposit for the entire time that the basket was inactive for.

It seems that the basket is severely flawed in calculating fees on partially inactive baskets. This puts users’ funds at direct risk of being lost. Malicious publishers can setup baskets as a sort of honeypot to abuse this behaviour.

This was an interesting find! Kudos to the warden.


The original report as published on Code4rena, by kenzo. 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 function returns early when total supply is zero without updating the last fee timestamp, so subsequent fee calculations use an outdated timestamp.

Impact

Extra fee tokens are minted, diluting the value of existing basket tokens and causing a loss of user funds.

What the attacker needed

Basket total supply becomes zero; time passes before next mint

The fix

Set lastFee to the current block timestamp when startSupply is zero.

How it was found

  1. All basket token holders burn their tokens, setting totalSupply to 0.
  2. After 1 day, somebody mints basket tokens; handleFees is called but returns early because totalSupply == 0, and lastFee is not updated.
  3. The next block, somebody else mints a token; handleFees calculates fees using the time difference between now and the old lastFee, charging for the entire inactive period.

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 basket charges fees based on time passed since the last fee update. If all tokens are burned, the total supply becomes zero, and the fee update is skipped without recording the current time. When someone mints new tokens later, the contract thinks a long time has passed and mints excessive fees, which reduces the value of everyone's tokens.

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 kenzo

View all

53 more disclosed reports, best first.

More from Kuiper 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.