Skip to content
Business logic Audit finding Beginner

users might pay enormous amounts of gas

When a user mints liquidity for a pair that does not exist, the contract deploys a new pair contract, which is very expensive on Ethereum. The user ends up paying thousands of dollars in gas fees.

danb Follow

Originally disclosed on Code4rena

Submitted by danb

https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Convenience/contracts/libraries/Mint.sol#L141

when a user mints new liquidity, it the pair doesn’t already exist, it deploys it.

deploying a new contract on ethereum is super expensive, especially when it’s such a large contract like TimeswapPair, it can cost thousands of dollars.

https://medium.com/the-capital/how-much-does-it-cost-to-deploy-a-smart-contract-on-ethereum-11bcd64da1

Impact

user who try to mint liquidity on pair that doesn’t exist will end up paying thousands of dollars.

Recommended Mitigation Steps

If the pair doesn’t exist, revert instead of deploying it. deploying a new contract should be the user’s choice, since it’s so expensive.

Mathepreneur (Timeswap) acknowledged:

We plan to have a better documentation to show this behavior.

0xean (judge) commented:

Downgrading to med risk, this isn’t an attack vector and is working as designed. Funds aren’t being lost or compromised in any way.

The issue is with the design, which could be potentially improved.

The original report as published on Code4rena, by danb. 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

Likely, the mint function automatically deploys a new pair contract when the pair does not exist, without warning the user about the high gas cost.

What the attacker needed

User initiates mint for non-existent pair; user pays gas for deployment

The fix

The contract should revert if the pair does not exist, leaving deployment as a separate, explicit user action.

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.

On Ethereum, creating a new smart contract costs a lot of gas, which translates to real money. This report says that if you try to add liquidity to a trading pair that hasn't been created yet, the system automatically creates it for you, and you foot the bill. That can be thousands of dollars, which is a nasty surprise.

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 danb

View all

12 more disclosed reports, best first.

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