Cosmos-sdk: ApproxRoot Infinite Looping

Created on 13 Aug 2020  Â·  8Comments  Â·  Source: cosmos/cosmos-sdk

Summary of Bug

Infinite loop when supplying small values to the Dec.ApproxRoot() function, most likely because the SmallestDec boundary is never satisfied. Example input: ApproxRoot(NewDecWithPrec(10000000000, 18), 3)

Version

Commit: 6a7cf4442e340b1878b28552778e42d3c6285624 (master as of writing)

Steps to Reproduce

Add the following test case to TestApproxRoot function in types/decimal_test.go:

  • {NewDecWithPrec(10000000000, 18), 3, MustNewDecFromStr("0")},

For Admin Use

  • [ ] Not duplicate issue
  • [ ] Appropriate labels applied
  • [ ] Appropriate contributors tagged
  • [ ] Contributor assigned/self-assigned
bug types

All 8 comments

/cc @sunnya97 :(

I'd propose to remove the feature in master and reintroduce it when we have a fix.
For what concerns the Launchpad Release Series, we must communicate this ASAP (and maybe even remove it)

Fine by me -- feel free to remove entirely.

@karzak Are you using this function?

No - this doesn't have an impact on Kava.

I understand why it would be removed, but is there the possibility of restricting it to a known range of valid inputs or a larger error tolerance rather than removing it completely? Or maybe an alternative approach can be found? It is currently used by the bonds module. In any case, I'm happy to see the bug get squished.

As discussed with @migueldingli1997, he'll take a stab at this

I'm thinking that with any implementation with no hard limit, there might always be the possibility that we get an infinite loop. So in my opinion the simplest solution without messing too much with the current code is to add an extra 'maximum number of iterations' argument which puts a hard limit on the looping. From my experimentation, it seems typically the number of iterations required is in the 10's, so maybe a hard limit that could be used would be 100. Will open a PR with this solution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mossid picture mossid  Â·  3Comments

rigelrozanski picture rigelrozanski  Â·  3Comments

cwgoes picture cwgoes  Â·  3Comments

kevlubkcm picture kevlubkcm  Â·  3Comments

fedekunze picture fedekunze  Â·  3Comments