New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RTokenAsset
price estimation accounts for margin of error twice
#31
Comments
thereksfour marked the issue as primary issue |
Currently contemplating switching (or equivalently, using the |
@0xA5DF on further thought I'm not so sure this is a bug, or at least, I don't think one could do better. Consider the following:
As for the impact statements, there are a few things I'd point out:
|
I agree there's some sense to it, but:
My understanding was that
I agree the mechanism will work well for most of the time, but during busy and high gas price periods this might fail and this is when you need the minimum price to kick in. |
Good points. I was ignoring the fact that RTokens may hold other RTokens as assets. In the case of The point about the uncertainty being applied to the entire basket because of the use of For upwards pricing it feels like less of a concern to me, because It's worth noting though that all this discussion has been in the absence of any RSR stake. In practice all RTokens are overcollateralized by RSR. If the overcollateralization is at least 2%, and the avg oracleError for the collateral tokens is 1%, then ~no double counting occurs because Thoughts on ways this issue could be mitigated? I thought I had an idea but after I looked into it more I don't think it would work. |
tbrent marked the issue as sponsor acknowledged |
Maybe the most simple solution would be to calculate the total value of the assets that the protocol holds (capped to BU price), and then multiply by baskets needed and divide by I was thinking of modifying |
The issue with an approach like this is that it's agnostic of where we are in the collateralization process. Balances that are disjoint with the current basket are treated the same as balances that are overlapping. This really comes down to the question of when and where to apply |
We've discussed internally and where we're coming down is that we think this issue should be acknowledged but that it is a Medium and not a High. We want to acknowledge the issue because while we were aware of the double-counting of oracleError in the context of a single RToken pricing itself, we hadn't considered it in the context of a parent-child relationship, and in that case it is importantly different. However, it seems more like a Medium because the trading mechanisms are resilient to mild mispricing. The expected downside outcome would be a trade occuring via |
tbrent marked the issue as disagree with severity |
thereksfour changed the severity to 2 (Med Risk) |
thereksfour marked the issue as satisfactory |
thereksfour marked the issue as selected for report |
Lines of code
https://github.com/reserve-protocol/protocol/blob/9ee60f142f9f5c1fe8bc50eef915cf33124a534f/contracts/plugins/assets/RTokenAsset.sol#L53-L72
https://github.com/reserve-protocol/protocol/blob/9ee60f142f9f5c1fe8bc50eef915cf33124a534f/contracts/plugins/assets/RTokenAsset.sol#L100-L115
Vulnerability details
RTokenAsset
estimates the price by multiplying the BU (basket unit) price estimation by the estimation of baskets held (then dividing by total supply).The issue is that both BU and baskets held account for price margin of error, widening the range of the price more than necessary.
Impact
This would increase the high estimation of the price and decrease the lower estimation.
This would impact:
lotLow
falling below the min trade volume)Proof of Concept
tryPrice()
andlotPrice()
use this method of multiplying basket unit price by basket range then dividing by total supplyConsider the following scenario:
basketRange()
we're dividing the ETH'slow
price bybuPriceHigh
buPriceLow
(there's also some duplication within the
basketRange()
but that function isn't in scope, what is is scope is the additional margin of error when multiplying bybuPriceLow
).Recommended Mitigation Steps
I think the best way to mitigate this would be to use a dedicated function to estimate the price, I don't see an easy way to fix this while using the existing functions.
Assessed type
Other
The text was updated successfully, but these errors were encountered: