TimeswapPair.sol#mint()
Lack of input validation allows attacker to set pool.state.y
to an arbitrary target value
#167
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate
This issue or pull request already exists
Handle
WatchPug
Vulnerability details
https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L186-L186
pool.state.y += yIncrease;
TimeswapPair.sol#mint()
takes a user input value ofyIncrease
without proper validation, which means that it allows the state ofpool.state.y
to increase by the arbitrary value set by the caller.Impact
pool.state.y
is extremely large, many core features of the protocol will malfunction, as the arithmetic related tostate.y
can overflow. For example:LendMath.check(): https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Core/contracts/libraries/LendMath.sol#L28-L28
BorrowMath.check(): https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Core/contracts/libraries/BorrowMath.sol#L31-L31
state.y
to a near overflow value, thenlend()
to get a large amount of extra interest (as Bond tokens) with a small amount of asset tokens. This way, the attacker can steal funds from other lenders and liquidity providers.PoC
Near the maturity time, the attacker can do the following:
mint()
with a dust amount of assets (xIncrease
= 1 wei) and increasepool.state.y
to an extremely large value;lend()
a regular amount of assets, get a large amount of bond token;burn()
the bond token and get a large portion of the assets.Recommendation
Consider making
pair.mint()
to beonlyConvenience
, so thatyIncrease
will be a computed value (based onxIncrease
and current state) rather than a user input value.The text was updated successfully, but these errors were encountered: