Open hats-bug-reporter[bot] opened 5 months ago
Thanks for submitting, we are taking a look at the issue.
This issue carries a good understanding of the protocol, congrats for that.
Though I think this is a low. Likelihood that the oracle is stale is very low + users will get a DOS for a very short period of time, where they will be able to sell it quickly after regardless.
So stale rate + user wanting to sell exactly when the rate is stale + them being able to sell shortly after, imo is a low.
Now, we know that we said we were not going to reward lows, I will await for the team to confirm the decision, but we will reward this one as it is on the edge and it was helpful.
Hi! We are going to reward you with 150 USDC as a token of appreciation
Github username: @bauchibred Twitter username: bauchibred Submission hash (on-chain): 0x878ab44dc233f89a7e96c4298f9f4126d3e8745fcea5d3e71d7dc726aa3d08e6 Severity: medium
Description: Description
Take a look at https://github.com/hats-finance/Tapioca--Lending-Engine--0x5bee198f5b060eecd86b299fdbea6b0c07c728dd/blob/8920782db6044643fd0c682f58ef37f7e59f99b1/contracts/markets/bigBang/BBLeverage.sol#L133-L170
This function is used by an integrator in order to sell their collateral so as to repay their debt.
Now there was a previous finding from the sherlock contest about the
solvent()
modifier does not enforce that the exchange rate is always up to date, which is why protocol changed the implementation to the below https://github.com/hats-finance/Tapioca--Lending-Engine--0x5bee198f5b060eecd86b299fdbea6b0c07c728dd/blob/8920782db6044643fd0c682f58ef37f7e59f99b1/contracts/markets/Market.sol#L167-L175https://github.com/hats-finance/Tapioca--Lending-Engine--0x5bee198f5b060eecd86b299fdbea6b0c07c728dd/blob/8920782db6044643fd0c682f58ef37f7e59f99b1/contracts/markets/Market.sol#L384-L393
Issue however is that, now if there is any issue with getting the exchange rate the whole execution fails, now where as this is logical when someone is trying to enter into the market or so as not game protocol (since leverage buying, borrow and collateral removal can increase riskiness of a position),, that's to say when a user is trying to
borrow()
orbuyCollateral
, this should revert to ensure protocol is safe and they are not being gamed, however in the case of users selling their collateral to repay their debt, this does not increase the risk of a position, so, there should be a check to see that even if updating the exchange rate fails, if the users accept the rate then they should be able to repay their debt, otherwise they could accrue more debt.This window was also acknowledged in the linked finding, were the auditor hinted that all other instances of using stale rates are acceptable asides the below:
Attack Scenario
Recommendation Consider reimplementing the way the
solvent()
modifier exists and how it's being integrated, in the case where it's a function likesellCollateral()
there mustn't be an enforcal in updating the exchange rate, so consider passing in aisUpdateRequired()
param to thesolvent()
modifier and in the case where it's a functionality likesellCollateral
that doesn't increase the risk to a position theisUpdateRequired()
which would then allow users to be able to access this function and even repay their debts or what not. AttachmentsN/A
N/A