When a user create a taker for an offer he can then use the stock newly created to list an offer. After that he can abort the offer by calling aboardAskOffer if the offer is the ask type. This function will the credit the sender if there is an amount that have not been used. However this function will overestimate the claimable balance of the sender if when he listed the offer he user a collateral rate hire than the original offer.
When the user list the offer he can use a different collateral rate than the original offer if the settled type is not turbo as we can see here in the listOffer function (L-335) in the PreMarkets contract:
if the settle type of the maker is Protected he can use whatever collateral rate if it's above 10_000 and he will then send
the amount with collateral rate of the previous offer as we can see in this line(346)
If the offer is an Ask he can now call aboardAskOffer(L-536) in the PreMarkets contract.
this function will refund the sender by the unused amount of the offer based on the amount the points and the usedPoints.
The problem occure when calculating the transferAmount here(L-595) :
The function calculated the amount that the sender originally send when he created the offer, however the function do a miscalculation because it calculat the transferAmount withe the collateral Rate of the current offer not the previous one. resulting in a miscalculation of the transferAmount if the settle type is protected.
As we can see in the getDepositAmount function(L-27) in the OfferLibraries library :
This function will return the remainig amount with muldiv with collateral rate and the scaler but this is not the correct amount if the collateral rate used in the listOffer function is different from the one used in the original offer.
We can the imagine a scenario where the user use this vulnerability to drain the protocol :
Before running the POC you must fix the bug with the allowance that I mentionned in a previous submittion
add this if statement in the _transfer function in the token Manager before the _safe_transfer_from to ensure that the token Manager have enougth allowance :
You can copy paste this test in the PreMarkets.t.sol
The user can use this to drain all the protocol and any use that aboard an ask type in protected mode can overestimate his balance
Echidna
I thing that the protocol in protected mode should use the _collateral that the sender used when he listed the offer as it is specified in the documentation:
Valid high severity, because the collateral rate utilized when creating an offer is stale and retrieved from a previously set collateral rate, it allows possible manipilation of refund amounts using an inflated collateral rate to drain funds from the CapitalPool contract
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.