Different output when using react-native-bignumber and bn.js
See original GitHub issueI’m trying to use this package in a project which uses elliptic
and one of the functions produce different output when using react-native-bignumber and bn.js. I managed to identify piece of code that returns different output. I tested it in the example app of react-native-bignumber. The code looks pretty much like this.
import bn_elliptic from 'bn_elliptic';
import elliptic from 'elliptic';
const secp256k1 = new elliptic.ec('secp256k1');
const bn_secp256k1 = new bn_elliptic.ec('secp256k1');
const kI =
'9dc74cbfd383980fb4ae5d2680acddac9dac956dca65a28c80ac9c847c2374e4';
const n = secp256k1.curve.n;
const G = secp256k1.curve.g;
const Q = G.mul(kI);
const n_BN = bn_secp256k1.curve.n;
const G_BN = bn_secp256k1.curve.g;
const Q_BN = G_BN.mul(kI);
console.log(Q.x.umod(n));
// output: e696d0036454d7b7890bd425947329f68d9c7c0e2de44958e5700a30ca98b02c
console.log(Q_BN.x.umod(n_BN));
// output: 54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed
It looks like there are some differences in umod
implementation but I might be wrong.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
indutny/bn.js: BigNum in pure javascript - GitHub
Convert inputs to reducted ones; Operate on them in reduction context; Convert outputs back from the reduction context. Here is how one may...
Read more >How to avoid duplication of module "bn.js" in webpack ...
I used webpack 4 for my app. Somehow, bn. js package takes up a lot in production build. The image shows that it...
Read more >bn.js - npm
Start using bn.js in your project by running `npm i bn.js`. There are 3950 other projects in the npm registry using bn.js.
Read more >A comparison of BigNumber libraries in JavaScript
A comparison of the most popular libraries for performing arbitrary-precision arithmetic in JavaScript. Tagged with javascript, math, ...
Read more >chai-bn - Chai Assertion Library
This is a key difference with chai-bignumber, which automatically converts JavaScript numbers to BigNumber instances for both actual and expected values. Only ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey! I started working on the issue. Seems like problem with umod indeed. However, I need to take a closer looks as Q.x looks to be a red number. I’m not sure what umod in a field would mean to be honest 😄 Will do my best to resolve it this week.
we’ll take a look