Open hats-bug-reporter[bot] opened 1 year ago
Sorry, here ABDKMathQuad.ln(timeRatio).div(ABDKMathQuad.ln(ABDKMathQuad.fromUInt(totalOutToken / 10 ** 18)))
will become greater than -1.
Instead of greater
, it should be lower
.
By greater
, I mean unsigned greater.
Hello, Thanks a lot for your attention.
This is a nice catch.
In fact with the function is : f(t) = (ln(t/T) / ln(N))+1
As we know, ln(x) with x ]0;1] is defined on ]-infinite; 0]
Here is a representation of the function https://www.desmos.com/calculator/epedwlev4z?lang=fr
On this representation, we can see that :
This time the curve stays under 0 is the time where the bond is not available. The only risks is that the function will revert. Users will not be able to deposit in the bond during the first S seconds of the bonds. So no funds will be lost or blocked.
As the impact is verry small ( example on the desmos link => 10s of outage at the begining of the bond )
We cannot afford an high severity for it but more a Low.
The fix we found is that, if we find a negative result we'll pass 0 now.
@walk-on-me The fix sounds good to me. But for the label, I should mention that:
After discussion with @0xmahdirostami
We agree that for a more general usage of this contract, this outage at the beginning of the bond can be more problematic
( ex of 10 ETH on 1 day )
This issue passes so to medium
Github username: @0xmahdirostami Submission hash (on-chain): 0x7c402da62ea6108b6870add5bbba4ee087008c31a0397daa5ac077b560fe55be Severity: high
Description: Description\ The computeRoi function uses computeCvgExpected. In the computeCvgExpected function, If
composedFunction
is 1, it usesln
:also as :
0 < timeRatio < 1
we have-∞ < ln(timeRatio) <0
, so we doln(timeRatio) / ln(totalOutToken / 10 ** 18)
to have-1<ABDKMathQuad.ln(timeRatio).div(ABDKMathQuad.ln(ABDKMathQuad.fromUInt(totalOutToken / 10 ** 18))) < 0
,but if
ln(totalOutToken / 10 ** 18)
is less thanln(timeRatio)
soABDKMathQuad.ln(timeRatio).div(ABDKMathQuad.ln(ABDKMathQuad.fromUInt(totalOutToken / 10 ** 18)))
will become greater than -1 andcvgExpected
becomes negative, so it causes revert incomputeRoi
.Impact\ Revert in
computeRoi
may cause a lot of problems ascomputeRoi
is used in_depositRoi
(is used ingetBondView
) and_computeCvgBondUsdPrice
( is used indeposit
andgetBondView
)deposit
revert untillln(totalOutToken / 10 ** 18)
becomes bigger thanunsigned ln(timeRatio)
.Attachments
In Bond Calculator tests:
VESTING_TIME is: 43200
, solog(1/43200) = -15.3987436919
, so ifln(totalOutToken / 10 ** 18) < 15.3987436919
, it will be reverted.ln(43200) = 15.3987436919
so iftotalOutToken / 10 ** 18 < 43200
, it will be reverted.test:
Output:
test:
Output:
Recommendation, Make sure that
ln(totalOutToken / 10 ** 18)
is bigger thanunsigned ln(timeRatio)
.For example:
ln(totalOutToken / 10 ** 18) must be bigger than unsigned ln(1/43200) => 15.3987436919
ln(totalOutToken / 10 ** 18) must be bigger than unsigned ln(1/432000) => 18.7206717868