Open sherlock-admin opened 1 year ago
Confirmed ✅
Escalate
This should be medium not high. While it is true that the calculation will be wrong for scaling factors other than 1, it heavily depends on the configuration of auction settings as to whether this sells assets at a bad price and causes a loss to the set token.
Escalate
This should be medium not high. While it is true that the calculation will be wrong for scaling factors other than 1, it heavily depends on the configuration of auction settings as to whether this sells assets at a bad price and causes a loss to the set token.
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.
Escalate
This should be medium not high. While it is true that the calculation will be wrong for scaling factors other than 1, it heavily depends on the configuration of auction settings as to whether this sells assets at a bad price and causes a loss to the set token.
Agree here this should be a medium not a high
1) manager's are expected to preview full auction price curves ahead of a startRebalance
call by calling the pure function getPrice
with input _timeElapsed
in the range [0, _duration]
2) the difference is not catastrophic, it is a shift that stays constant throughout the auction https://colab.research.google.com/drive/1ZkXs2MuTJFaWUU611KolNXQ52zh9k3VM?usp=sharing
manager's are expected to preview full auction price curves ahead of a startRebalance call by calling the pure function getPrice with input _timeElapsed in the range [0, _duration]
getPrice only takes in one _timeElapsed (not array), so managers can't view full curve. Also, the curve is directly affected by timeBucket
, rather than _timeElapsed
. Different _timeElapsed
could give the same price depending on bucketSize. There's hardly a simulation or plotting tool for solidity, so it might be done in other languages like we're doing right now.
the difference is not catastrophic
It could be very catastrophic mainly because it affects priceChange (which would then be added or subtracted from price). WE DON'T KNOW WHAT INITIAL PRICE IS. It could be 10,000
, it could 20
, it could be 0.1
, it could be 1e-12
.
1
and increasing to 1.05
.1e-12
because of decimals 1e6/1e18
(1e6 in WAD)2
, the priceChange at t0
would be 02
, the priceChange at t0
would 1
(1e18 in WAD) instead of 0
1e-12
DAI. That's less than a penny.My bad, I agree with Med cause the catastrophe is bounded by min and max value.
My bad, I agree with Med cause the catastrophe is bounded by min and max value.
I think we all agree this should be de-escalated to a Medium
Result: Medium Has duplicates Considering this a valid medium based on the above comments.
The remediation for this issue is open for review here https://github.com/IndexCoop/index-protocol/pull/25
The fix to the formula is here: https://github.com/IndexCoop/index-protocol/blob/839a6c699cc9217c8ee9f3b67418c64e80f0e10d/contracts/protocol/integration/auction-price/BoundedStepwiseExponentialPriceAdapter.sol#L73
Fix looks good. scalingFactor
is now applied via wadMul
which fixes this order of operation issue.
0x007
high
price is calculated wrongly in BoundedStepwiseExponentialPriceAdapter
Summary
The BoundedStepwiseExponentialPriceAdapter contract is trying to implement price change as
scalingFactor * (e^x - 1)
but the code implementsscalingFactor * e^x - 1
. Since there are no brackets, multiplication would be executed before subtraction. And this has been confirmed with one of the team members.Vulnerability Detail
The getPrice code has been simplified as the following when boundary/edge cases are ignored
When timeBucket is 0, we want priceChange to be 0, so that the returned price would be the initial price. Since
e^0 = 1
, we need to subtract 1 (in WAD) from theexpExpression
.However, with the incorrect implementation, the returned price would be different than real price by a value equal to
scalingFactor - 1
. The image below shows the difference between the right and wrong formula when initialPrice is 100 and scalingFactor is 11. The right formula starts at 100 while the wrong one starts at 110=100+11-1Impact
Incorrect price is returned from BoundedStepwiseExponentialPriceAdapter and that will have devastating effects on rebalance.
Code Snippet
https://github.com/sherlock-audit/2023-06-Index/blob/main/index-protocol/contracts/protocol/integration/auction-price/BoundedStepwiseExponentialPriceAdapter.sol#L73
Tool used
Manual Review
Recommendation
Change the following line