Open hats-bug-reporter[bot] opened 4 months ago
Thanks for the report. I agree that your finding is correct, however practically this won't introduce a risk/vulnerability. The fee is just an economic tool to ensure that we disincentivise abuse when the observed spot price is away from the expected historic price.
A +- of 1 wei in that spot price will be negligible in the fee outcome, perhaps +-1 bps at most. It doesn't have to be perfectly symmetric, as long as the economic tool is still effective (which it will be)
In saying that, yes it's still a low. Agree we can add a comment to explain this, and round in the same direction to bias for exits
100% agree on the super low impact. If there was an informational category, I would have labelled a that. Thanks for accepting though
Github username: @JacoboLansac Twitter username: jacolansac Submission hash (on-chain): 0x4cd8fb5219bf45add119fbd5a035bb9c7deee73803091c4edb69f641bbcf3d0b Severity: low
Description: The dynamic fees mechanism aims to impose a higher fee on users when they invest/exit at an unusually favorable rate. The
DynamicFees
library is in charge of calculating these fees, and it does so by querying the latest prices from the oracle: SPOT and HISTORIC. Then these prices are compared to calculate a_delta
, which is then used to increase the dynamic fees when the difference gives a favorable deal to the user. For context:The general principle can be summarized as:
For context, in the case of lovStEth, the oracle returns prices in [WETH/wstETH] units (how many WETH you get per 1 wstETH). A lower price means a higher value of wstETH, which would be reflected in a free market in relation to the lovStEth tokens. This, a user gets a favorable operation if:
The issue
When
DynamicFees::dynamicFeeBps()
queries the SPOT and HISTORIC prices, the SPOT is always queried withROUND_UP
and HISTORIC always withROUND_DOWN
. This rounding aims to round up the resulting_delta
between those prices, which would round up the resulting fees, to favor the protocol. However, this is only true whenSPOT > HISTORIC
. However, whenSPOT < HISTORIC
, the hardcoded rounding strategy will result in a downward rounding of_delta
, which will round down the protocol fees, going against the protocol.DynamicFees.sol
Impact: low
The hardcoded rounding mechanism when querying SPOT and HISTORIC prices will round down the protocol fees in the following situations:
_baseAsset == expectedBaseAsset
, (lovStEth, lovDsr strategies), fees are rounded down on deposits._quoteAsset == expectedBaseAsset
, (none for now), fees are rounded down on exits.Recommendation
A solution is not trivial. The fact that the appropriate rounding direction depends on the result of the query makes it necessary to make two queries to get the absolute perfect price, and this is a waste of gas for the overall impact of getting the exact rounding.
However, as the current implementation is biased towards exits, a solution that compromises the rounding between deposits and exits would be to round both prices in the same direction (up or down).
DynamicFees.sol