diff --git a/CHANGELOG.md b/CHANGELOG.md index 82d0c9703af..76d1232a773 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#4783](https://github.com/osmosis-labs/osmosis/pull/4783) Update wasmd to 0.31.0 * [#4830](https://github.com/osmosis-labs/osmosis/pull/4830) Add gas cost when we AddToGaugeRewards, linearly increase with coins to add * [#4886](https://github.com/osmosis-labs/osmosis/pull/4886) Implement MsgSplitRouteSwapExactAmountIn and MsgSplitRouteSwapExactAmountOut that supports route splitting. + * [#5000](https://github.com/osmosis-labs/osmosis/pull/5000) osmomath.Power panics for base < 1 to temporarily restrict broken logic for such base. ### Misc Improvements diff --git a/go.mod b/go.mod index d740acbe7bf..c9e9aa3acff 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/mattn/go-sqlite3 v1.14.16 github.com/ory/dockertest/v3 v3.10.0 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 - github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230328024000-175ec88e4304 + github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230425121701-4d427b673864 github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230411200859-ae3065d0ca05 github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230331072320-5d6f6cfa2627 diff --git a/go.sum b/go.sum index 75ab3faba61..c24db52527c 100644 --- a/go.sum +++ b/go.sum @@ -936,6 +936,8 @@ github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:Ylmch github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI= github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230328024000-175ec88e4304 h1:iSSlHl+SoewNpP/2N8JaUEHhOQRmJAnS8zaJ11yWslY= github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230328024000-175ec88e4304/go.mod h1:/h3CZIo25kMrM4Ojm7qBgMxKofTVwOycVWSa4rhEsaM= +github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230425121701-4d427b673864 h1:UhkJ67kx4NP7FEEQ+ybpDLIiS0Rl8vX8G55FKZux98I= +github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230425121701-4d427b673864/go.mod h1:Hu4OHAvKtnCaqA4GlodNf89JZ+2TFtH7IDNxNi6Vue8= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230411200859-ae3065d0ca05 h1:fqVGxZPgUWuYWxVcMxHz5vrDV/aoxGJ7Kt0J4Vu/bsY= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230411200859-ae3065d0ca05/go.mod h1:zyBrzl2rsZWGbOU+/1hzA+xoQlCshzZuHe/5mzdb/zo= github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 h1:RIrWLzIiZN5Xd2JOfSOtGZaf6V3qEQYg6EaDTAkMnCo= diff --git a/osmomath/decimal.go b/osmomath/decimal.go index cf921f494b1..03b6fea77bf 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -1019,6 +1019,9 @@ func (d BigDec) PowerIntegerMut(power uint64) BigDec { // If a greater exponent is given, the function panics. // The error is not bounded but expected to be around 10^-18, use with care. // See the underlying Exp2, LogBase2 and Mul for the details of their bounds. +// WARNING: This function is broken for base < 1. The reason is that logarithm function is +// negative between zero and 1, and the Exp2(k) is undefined for negative k. +// As a result, this function panics if called for d < 1. func (d BigDec) Power(power BigDec) BigDec { if d.IsNegative() { panic(fmt.Sprintf("negative base is not supported for Power(), base was (%s)", d)) @@ -1038,6 +1041,9 @@ func (d BigDec) Power(power BigDec) BigDec { if d.IsZero() { return ZeroDec() } + if d.LT(OneDec()) { + panic(fmt.Sprintf("Power() is not supported for base < 1, base was (%s)", d)) + } if d.Equal(twoBigDec) { return Exp2(power) } diff --git a/osmomath/decimal_test.go b/osmomath/decimal_test.go index 7961637dbbe..b0152e0a4f4 100644 --- a/osmomath/decimal_test.go +++ b/osmomath/decimal_test.go @@ -1416,6 +1416,12 @@ func (s *decimalTestSuite) TestPower() { base: osmomath.NewBigDec(1), exponent: osmomath.MustNewDecFromStr("-4"), + expectPanic: true, + }, + "base < 1 - panic (see godoc)": { + base: osmomath.NewBigDec(1).Sub(osmomath.SmallestDec()), + exponent: osmomath.OneDec(), + expectPanic: true, }, } diff --git a/x/concentrated-liquidity/math/tick.go b/x/concentrated-liquidity/math/tick.go index 4858782ea2c..bf0204ac87e 100644 --- a/x/concentrated-liquidity/math/tick.go +++ b/x/concentrated-liquidity/math/tick.go @@ -133,9 +133,9 @@ func PowTenInternal(exponent sdk.Int) sdk.Dec { func powTenBigDec(exponent sdk.Int) osmomath.BigDec { if exponent.GTE(sdk.ZeroInt()) { - return osmomath.NewBigDec(10).Power(osmomath.NewBigDec(exponent.Int64())) + return osmomath.NewBigDec(10).PowerInteger(exponent.Uint64()) } - return osmomath.OneDec().Quo(osmomath.NewBigDec(10).Power(osmomath.NewBigDec(exponent.Abs().Int64()))) + return osmomath.OneDec().Quo(osmomath.NewBigDec(10).PowerInteger(exponent.Abs().Uint64())) } // CalculatePriceToTick takes in a price and returns the corresponding tick index.