https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L671-L675
For various reasons, Ask Maker can abort order with PreMarktes.abortAskOffer()
. In that case, Bid Taker must execute PreMarktes.abortBidTaker()
to get provided collateral back. But because of a mistake in calculation refund amount Bid Taker is getting refunded with nothing.
Incorrect calculation of refunded amount occurs on these lines:
Refund amount should be the same as user deposited when created taker. In provided code above user would get less collateral back because all values are divided by preOfferInfo.amount
which is amount of collateral token provided by Ask Maker. Because most tokens have 18 decimals numerator of expression is drastically lesser than the denominator and in most cases taker would be refunded with 0 collateral tokens.
The taker loses his order funds.
Modify test/PreMarkets.t.sol test with next code and execute this test with forge test --match-test test_abort_bid_taker_can_not_refund_tokens
:
Use the same calculation as in PreMarktes.createTaker()
:
Valid high severity, due to incorrect computation of `depositAmount` within `abortBidTaker`, when aborting bid offers created by takers, the collateral refund will be completely wrong for the taker, and depending on the difference between the value of `points` and `amount`, it can possibly even round down to zero, causing definite loss of funds. If not, if points were worth less than the collateral, this could instead be used to drain the CapitalPool contract instead.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.