question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different output when using react-native-bignumber and bn.js

See original GitHub issue

I’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:open
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
Szymon20000commented, Dec 19, 2022

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.

4reactions
mrousavycommented, Dec 15, 2022

we’ll take a look

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found