-
Notifications
You must be signed in to change notification settings - Fork 5
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
aslanbek - Actual funding can be lower than intended due to precision loss in utilization
#60
Comments
utilization
utilization
Escalate Valid Medium
|
You've created a valid escalation! To remove the escalation from consideration: Delete your comment. You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final. |
@aslanbekaibimov could you make a scenario showcasing how the utilisation can be so low? |
Let's say we have ETH/USDT pair, 1 ETH = 2000 USDT
E.g. LP Alice provides 101e18 ETH and 202_000e6 USDT via Trader Bob base_interest = interest.base = position.interest_tagged.base = interest = virtual_tokens * leverage = quote_to_base(2000 USDT to ETH) = 1e18 |
Result: |
Escalations have been resolved successfully! Escalation status:
|
aslanbek
Medium
Actual funding can be lower than intended due to precision loss in
utilization
Summary
Because
params#utilization
is not multiplied by a precision factor, computed utilization can be up to 100% lower than the actual one (i.e. 0 instead of ~1), which in turn would make funding fees up to 100% lower than intended.Root Cause
Absense of precision factor in
params#utilization
(and absence of division by the same factor inparams#scale
).Impact
Shorts/longs receive up to 100% less funding fees from longs/shorts than they should.
PoC
base_reserves = 101e18
base_interest = 1e18
utilization = 1e18 / (101e18 / 100) = 1e18 / 1.01e18 = 0
Mitigation
utilization
should be multiplied by 1e18 (or another suitable precision factor).scale
should be divided by the same value.Duplicate of #72
The text was updated successfully, but these errors were encountered: