-
Notifications
You must be signed in to change notification settings - Fork 154
Open
Labels
Description
Unfortunately I don’t have a smaller example, but raising this number (represented in base 36 for compactness) to the 4th power and then squaring it gives a mathematically incorrect result: https://gist.github.com/astiob/091b8dbadf0698affb7a469e93450a0b
x = new BN("...", 36)
x.sqr().sqr() // is correct
x.sqr().sqr().sqr() // is incorrect
x.pow(new BN(8)) // is incorrect (equivalent to previous line)
x.sqr().sqr().maskn(256).toString() // 9076919990156733995225002098329760000 (correct)
x.sqr().sqr().maskn(256).sqr().maskn(256).toString() // 82390476507706923968765337733501879292364638168635194987781701657600000000 (correct)
x.sqr().sqr().mul(x.sqr()).mul(x.sqr()).maskn(256).toString() // 82390476507706923968765337733501879292364638168635194987781701657600000000 (correct)
x.sqr().sqr().sqr().maskn(256).toString() // 308574507784727280410577156852044557420092381404603103173567945519950528512 (incorrect)
Tested using Git master in Firefox 48 on Mac OS X 10.6, Firefox 62 and 64 on Windows 7 and Chrome 71 on Windows Server 2016.
I should note that this number isn’t unique. I’m seeing this with plenty of numbers that I produce as a Kronecker substitution of some probability distribution convolutions, but all affected numbers that I’ve seen so far are similarly large or larger.
Reactions are currently unavailable