bitcoinjs / bip38

BIP38 is a standard process to encrypt Bitcoin and crypto currency private keys that is less susceptible to brute force attacks thus protecting the user.
http://cryptocoinjs.com/modules/currency/bip38/
MIT License
206 stars 100 forks source link

Poor performance when decrypting 2+ keys #40

Closed Rufus-L closed 6 years ago

Rufus-L commented 6 years ago

Hey, I'd like to know why it takes about 2-3s to decrypt one key, but then it gets a lot worse for subsequent keys (12-15s). Is it possible to improve that?

That happens either running with Node or Web browser.

var bip38 = require("bip38");
var keyList = ["6PnQYMjJ7ZXpX8rbh8b6PfzK38WG5KL9mGqscB2RXFGb4ZKwXBaP5gMmhC", "6PnPNwvsTy3jeogyENrV23F15om4ecbEmFZcYrjrTsPgvKEwfnubVEAEEc"];
var password = "123";

for (var key of keyList) {
  var t0 = new Date().getTime();
  bip38.decrypt(key, password);
  console.log((new Date().getTime() - t0) + " ms");
}
dcousens commented 6 years ago

A sample of 2 keys is probably not a great example, but, I'd be happy to look into this. It is likely this is a hot-spotting issue from the VM mis-optimizing the code.

Are you experiencing this consistently?

Rufus-L commented 6 years ago

I used a sample of 2 to make the code simpler. The result is always the same: first one is quick, all the others take about 5x the time.

That happens everytime. Even if the 1st and 2nd keys are the same.

dcousens commented 6 years ago

Reproduced. 5x. Will investigate...

dcousens commented 6 years ago

Closing in favour of https://github.com/cryptocoinjs/scryptsy/issues/8