Skip to content
Business logic Audit finding Intermediate

TimeswapPair.sol#mint() Malicious user/attacker can mint new liquidity with an extremely small amount of yIncrease and malfunction the pair with the maturity

The mint function allows a caller to set an arbitrary yIncrease, so an attacker can set the initial state.y to a very small value (e.g., 1 wei). This makes the pair's state.y effectively unchangeable by normal operations, causing the pair to malfunction and become unusable.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Convenience/contracts/libraries/MintMath.sol#L14-L34

The current implementation of TimeswapPair.sol#mint() allows the caller to specify an arbitrary value for yIncrease.

However, since state.y is expected to be a large number based at 2**32, once the initial state.y is set to a small number (1 wei for example), the algorithm won’t effectively change state.y with regular market operations (borrow, lend and mint).

https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Core/contracts/libraries/BorrowMath.sol#L17-L37

The pair with the maturity will malfunction and can only be abandoned.

A malicious user/attacker can use this to frontrun other users or the platform’s newLiquidity() call to initiate a griefing attack.

If the desired maturity is a meaningful value for the user/platform, eg, end of year/quarter. This can be a noteworthy issue.

Recommendation

Consider adding validation of minimal state.y for new liquidity.

Can be 2**32 / 10000 for example.

Mathepreneur (Timeswap) confirmed

The original report as published on Code4rena, by WatchPug. 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 lacks a minimum bound on the initial state.y, allowing it to be set to an extremely small value that breaks the math for subsequent operations.

Impact

The pair with the chosen maturity malfunctions and can only be abandoned, and an attacker could frontrun other users or the platform's newLiquidity() call to cause a griefing attack.

What the attacker needed

Attacker can call mint first; victim or platform uses same maturity

The fix

The fix should add validation of a minimal state.y for new liquidity, for example 2**32 / 10000.

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.

In this smart contract, a value called state.y is supposed to be a large number. If an attacker sets it to a tiny number when first adding liquidity, later normal actions like borrowing or lending cannot change it properly. The pair then stops working and can only be abandoned.

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 WatchPug

View all

197 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.