6

I'm trying to debug an app that at some point needs to create a password protected account. When I reach that point in my code using pycharm's debugger it takes forever to generate an account protected by a four character password.

The code is:

new_account = accounts.Account.new(password, priv_key, path)

where all fields are not None. Is there a way to debug faster?

4
  • Have you tried other clients? geth, parity?
    – q9f
    Commented Jun 14, 2016 at 13:16
  • 2
    I'm limited to using pyethapp because at the moment it is the only client supporting programmable hooks (I need to make a syscall once a transaction has been confirmed)
    – Sebi
    Commented Jun 14, 2016 at 13:22
  • @Sebi: What platform/OS are you running on?
    – jimkberry
    Commented Jun 16, 2016 at 14:10
  • @jimkberry Debian 8.3, Jessie, x64
    – Sebi
    Commented Jun 16, 2016 at 19:25

1 Answer 1

3

Account generation is slow by design.

Part of the account generation process involves scrypt or pbkdf2, password hashing algorithms that are designed to be slow in order to mitigate brute force attacks on your private keys.

If you look here in the pyethereum source you can see the parameters that are used for each of these hash functions. Both use a work factor/iteration count of 262114 or 2**18 which should translate to something between 1-3 seconds of hashing depending on how old your hardware is.

7
  • In python it's more like 3 or 4 minutes, perhaps even more. Even so, once an attacker has your account only strong (60+ random & non-ASCII character) passwords will keep it safe, regardless of the hashing algorithms involved (at least in practical scenarios). This approach is uselessly slow, at least in my opinion.
    – Sebi
    Commented Jun 16, 2016 at 21:06
  • Have you profiled the code and why it's so slow. I suspect that the slowness of the hashing algorithms isn't what your seeing but rather something different. Possibly your IDE is doing something that's adding significant overhead to the process? Commented Jun 16, 2016 at 21:14
  • Yes, too many rounds of hmac-sha256. I've run it both inside the IDE (pycharm) and also, separately, from bash. The latter is faster but not by much (at least 2 or 3 minutes per account generation).
    – Sebi
    Commented Jun 16, 2016 at 21:26
  • can you try this code and see how long it takes? from ethereum import keys; keys.make_keystore_json(keys.sha3('cow'), 'abcd'). I'm seeing 22 second generation times. Commented Jun 16, 2016 at 22:52
  • It take ~4 minutes per run. I have rebuild pyethereum and decreased the constant 1000 times.
    – Sebi
    Commented Jun 17, 2016 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.