Due to the incorrect use of collateralRate, users could steal funds from the protocol.
The collateralRate used by the user when depositing the collateral in listOffer comes from offerInfo which is stockInfo.preOffer.
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/PreMarkets.sol#L345-L353
However, when generating new offer data later, the _collateralRate in the parameters is used directly.
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/PreMarkets.sol#L369-L379
In Protected mode, it is not required that these two values are equal, it merely limits the minimum value of _collateralRate.
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/PreMarkets.sol#L304-L306
In closeOffer, the amount of refund is calculated based on the offer data generated in listOffer, which means that the offerInfo.collateralRate in closeOffer is the _collateralRate in listOffer, not the collateralRate used during deposit.
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/PreMarkets.sol#L441-L447
Therefore, since the collateralRate used when depositing and withdrawing collateral is different, if the rate is lower when depositing and higher when withdrawing, users could steal protocol funds.
For example:
Alice performs listOffer, where the _collateralRate parameter is 110%, and the amount is 100.
When depositing collateral, the offerInfo.collateralRate used is 100%, so Alice deposits 100 tokens as collateral.
In the newly generated offer from listOffer, the collateralRate is set to the _collateralRate of 110%.
Alice performs closeOffer to close the newly generated offer. In closeOffer, the offerInfo.collateralRate obtained is 110%, so the refund amount is 110.
Finally, Alice steals 110-100=10 tokens from the protocol through the two steps of listOffer + closeOffer.
Users could steal funds from the protocol.
vscode
Ensure that the collateralRate during deposit and the collateralRate when generating a new offer in listOffer are consistent.
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.