From 535567e231b20572bc099e6321c8fcf95d282760 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 23 Oct 2023 13:45:21 +0000 Subject: [PATCH] fix: RelativePow now returns 1 when 0^0 (backport #18211) (#18216) Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com> Co-authored-by: marbar3778 --- math/CHANGELOG.md | 1 + math/uint.go | 4 ++-- math/uint_test.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/math/CHANGELOG.md b/math/CHANGELOG.md index b337d786d4..10dbe4a437 100644 --- a/math/CHANGELOG.md +++ b/math/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j ### Bug Fixes * [#16266](https://github.com/cosmos/cosmos-sdk/pull/16266) fix: legacy dec power mut zero exponent precision. +* [#18211](https://github.com/cosmos/cosmos-sdk/pull/18211) RelativePow now returns 1 when 0^0, before it was returning the scale factor. ## [math/v1.0.1](https://github.com/cosmos/cosmos-sdk/releases/tag/math/v1.0.1) - 2023-05-15 diff --git a/math/uint.go b/math/uint.go index 406d9418ce..0a61646ae1 100644 --- a/math/uint.go +++ b/math/uint.go @@ -243,8 +243,8 @@ func checkNewUint(i *big.Int) (Uint, error) { func RelativePow(x, n, b Uint) (z Uint) { if x.IsZero() { if n.IsZero() { - z = b // 0^0 = 1 - return + z = OneUint() // 0^0 = 1 + return z } z = ZeroUint() // otherwise 0^a = 0 return diff --git a/math/uint_test.go b/math/uint_test.go index 7d4a5a731f..0c464433a0 100644 --- a/math/uint_test.go +++ b/math/uint_test.go @@ -271,7 +271,7 @@ func (s *uintTestSuite) TestRelativePow() { want sdkmath.Uint }{ {[]sdkmath.Uint{sdkmath.ZeroUint(), sdkmath.ZeroUint(), sdkmath.OneUint()}, sdkmath.OneUint()}, - {[]sdkmath.Uint{sdkmath.ZeroUint(), sdkmath.ZeroUint(), sdkmath.NewUint(10)}, sdkmath.NewUint(10)}, + {[]sdkmath.Uint{sdkmath.ZeroUint(), sdkmath.ZeroUint(), sdkmath.NewUint(10)}, sdkmath.NewUint(1)}, {[]sdkmath.Uint{sdkmath.ZeroUint(), sdkmath.OneUint(), sdkmath.NewUint(10)}, sdkmath.ZeroUint()}, {[]sdkmath.Uint{sdkmath.NewUint(10), sdkmath.NewUint(2), sdkmath.OneUint()}, sdkmath.NewUint(100)}, {[]sdkmath.Uint{sdkmath.NewUint(210), sdkmath.NewUint(2), sdkmath.NewUint(100)}, sdkmath.NewUint(441)},