In the function abortBidTaker
, the deposited amount is not implemented properly. This can lead to some situations:
Taker can not get his deposited fund back if maker aborts.
Taker steals large amount of collateral from the protocol.
An attacker can drain the protocol without any honest maker or taker are involved.
In the function abortBidTaker
, during calculation of deposit amount, instead of using the formula stockInfo.points * preOfferInfo.amount / preOfferInfo.points
, it is implemented as stockInfo.points * preOfferInfo.points / preOfferInfo.amount
.
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/PreMarkets.sol#L671
This leads to a complete wrong calculation.
In the following test, Alice (maker) creates a ask offer. Bob (taker), creates a bid order against Alice's offer and buys all of the Alice's points. Later, Alice aborts her ask offer by calling abortAskOffer
. Then, Bob aborts his bid order by calling abortBidTaker
. It is expected that Bob would be able to take his deposited amount back. But due to the bug explained, the deposited amount would be calculated as stockInfo.points * preOfferInfo.points / preOfferInfo.amount = 1000 * 1000 / 1e18 = 0
. So, Bob cannot take his deposited amount back.
The output is:
The following test is similar to the previous test, the only difference is that the amount of points sold by the maker and bought by the taker is not 1000, it is 1000 * 1e18
. By doing so, the deposited amount would be calculated as stockInfo.points * preOfferInfo.points / preOfferInfo.amount = 1000e18 * 1000e18 / 1e18 = 1_000_000e18
. So, Bob can take 1M collateral token. This value is stored in the following code:
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/PreMarkets.sol#L687
This PoC also shows that an attacker can play the role of maker and taker to misuse the same vulnerability.
The output is:
Wrong calculation of deposited amount during aborting bid taker leads to critical issues based on the value of points:
The taker can not take his deposited amount if maker aborts.
The taker can set a huge number as MakerRefund
into his balance, and later can withdraw it leading to stealing from the protocol.
An attacker can drain the protocol without any honest maker or taker are involved.
It is recommended to have:
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/PreMarkets.sol#L671
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.