A Bug in the SteemJs Regarding the Incorrect Reputation

A Bug in the SteemJs Regarding the Incorrect Reputation

Current SteemJs Library has a bug in computing the reputation. I have raised this two years ago and proposed a fix

Specifically:

1
2
console.log(steem.formatter.reputation(10004392664120));
console.log(steem.formatter.reputation(10004392664120+100000000000));

As you will see this output:

1
2
70
61

Which is incorrect. The problem is at the code L166

Here, the developer probably didn’t know the Math.log10 function can be used to compute the Log10, instead, he/she uses a math trick Math.log(x)/Math.log(10) to compute the Math.log10 based on natural logarithm (base e ).

This will introduce rounding errors, and sometimes intermediate results will be amplified leading to much bigger errors.

1
2
console.log(Math.log10(1000))
console.log(Math.log(1000)/Math.log(10))

This will output

1
2
3
2.9999999999999996

In Line 168, it uses parseInt, therefore, the difference will be becoming ONE.

There are a few fixes:

  1. change parseInt to Math.round
  2. change entirely to use Math.log10
  3. or completely rewriting this function, as my PR (approved by @ety001 thanks!, but not merged yet due to this is a legacy PR which was created more than 2 years ago and the main branch has differed a lot).
    https://github.com/steemit/steem-js/pull/345/files

image.png

If you are happening to rely on this function, you probably need to do it yourself until this fix is merged.


Every little helps! I hope this helps!

Steem On!~

If you like my work, please consider voting for me, thanks!
https://steemit.com/~witnesses type in justyy and click VOTE



Alternatively, you could proxy to me if you are too lazy to vote!

Also: you can vote me at the tool I made: https://steemyy.com/witness-voting/?witness=justyy

Visit me at: https://steemyy.com


This page is synchronized from the post: ‘A Bug in the SteemJs Regarding the Incorrect Reputation’

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×