Use Hal's optimized secp256k1 verifier #2061

pull sipa wants to merge 9 commits into bitcoin:master from sipa:hal changing 9 files +313 −11
  1. sipa commented at 3:58 PM on December 2, 2012: member

    The first commit is a rebased version of Hal's feb 2011 patch. The second commit improves the code a bit (precalculate constants, and use BN_CTX_get for temporary values).

    This reduces reindexing time for the first 210k blocks (script checks enabled everywhere, 4 verification threads, -dbcache=900) from 1h14m to 1h1m on my system.

  2. gavinandresen commented at 12:34 AM on December 3, 2012: contributor

    I don't think the 20% speedup is worth the extra code complexity. I could be convinced if there are some EC crypto experts hanging around who will chime in and say "oh, yeah, that's an obvious optimization and implementation looks correct...."

    It seems to me that this type of low-level speedup would be better implemented in OpenSSL. I don't know if they would accept a patch to speed up one curve or not, but ideally I think that is where this code belongs.

  3. gmaxwell commented at 12:52 AM on December 3, 2012: contributor

    Hal claims that it can be increased to 40% with some other changes, but they weren't immediately clear to me. I think Pieter's plan was to get this in (as it has the structural changes) and then talk to an EC expert he may have access to about doing the rest. That might satisfy both your concerns.

    I would note that script checking all txn with Hal is similar in performance to script skipping before the checkpoint without Hal (if not faster). In terms of the uncertainty wrt security implications I'd prefer the former.

  4. gmaxwell commented at 4:30 AM on December 3, 2012: contributor

    I was a little over eager in my last claim there: syncing from start to 210000 the current parallel checking branch without hal is 23:58 while without checkpoints but with hal it's 37:10 for me (47:21 hal-less).

  5. laanwj commented at 7:26 AM on December 6, 2012: member

    If we decide to include low-level crypto code like this, we could just as well include all the ECDSA code (for the particular curve that we use) so that we can build with OpenSSL built without ECDSA.

  6. sipa commented at 3:37 PM on December 8, 2012: member

    @laanwj I believe there is quite some non-ECDSA-specific EC code left in OpenSSL that would need to be included in that case too...

  7. sipa commented at 6:37 PM on December 9, 2012: member

    Refactored the optimized algorithm into an almost exact copy of OpenSSL's own ecdsa_do_verify() function, but using an optimized version of EC_POINT_mul().

  8. sipa commented at 11:15 PM on December 10, 2012: member

    New commit: if compiled with -DVERIFY_OPTIMIZED_SECP256K1, checks will be compiled in that compare the generic OpenSSL code with the specialized one. It's not enabled by default, but I verified it for the entire current block chain & unit tests.

  9. Diapolo commented at 8:29 PM on December 12, 2012: none

    @sipa This pull can be tested independently from your other one with parallel verification or do they depend on eachother?

  10. sipa commented at 8:36 PM on December 12, 2012: member

    They're independent.

  11. sipa commented at 5:25 PM on December 15, 2012: member

    Added verification code for checking k == k1 + lambda_k2 and for checking p2 == lambda_p. Verified against unit tests and testnet.

    EDIT: and mainnet now as well.

  12. sipa commented at 6:30 PM on December 25, 2012: member

    New commit: implemented a small improvement suggested by Hal.

  13. sipa commented at 5:15 PM on January 24, 2013: member

    Added a commit to build the core .o files for tests separately, and add - DVERIFY_OPTIMIZED_SECP256K1 to them, so the unit tests now compare the internal values in ECDSA verification between optimized and non-optimized code.

  14. sipa commented at 4:52 AM on January 30, 2013: member

    Added a fuzzer that compares intermediate values during validation in optimized and non-optimized code, for message hashes with a random 1-bit difference for every real check.

  15. BitcoinPullTester commented at 5:23 AM on January 30, 2013: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/1f369d512b5b5c66e9623d2eaf9692eee9b11d36 for binaries and test log.

  16. SergioDemianLerner commented at 10:38 PM on February 1, 2013: contributor

    It would be good if someone checks this new implementation against timing attacks. Systems that automatically sign transactions (like exchanges) may be vulnerable to key recovery using timing attacks.

  17. sipa commented at 10:48 PM on February 1, 2013: member

    This code isn't used for signing.

  18. SergioDemianLerner commented at 12:14 AM on February 2, 2013: contributor

    Ok, I will check against specially crafted pubkeys/signatures in a few weeks. I've found bugs in other implementations.

  19. sipa commented at 1:25 AM on February 2, 2013: member
  20. sipa commented at 8:50 PM on February 24, 2013: member

    Rebased.

  21. sipa commented at 5:53 PM on March 4, 2013: member

    Added precomputation of G (doable as a separate pull if necessary), which improves verify performance by 2-3% (consistently), and turn off Hal's optimizations by default; -turbo turns them on.

  22. Add speedup for sig verification based on secp256k1. 5fa36553e1
  23. Some optimizations for Hal's secp256k1 verifier 3993c8f755
  24. Precalculate P, N and G*lambda in CSecp256k1Consts 0bed41e45e
  25. Refactor secp256k1 ECDSA verify code to mimic generic version 2acc872fd8
  26. Allow verification of optimized secp256k1 code dd94228091
  27. Implement Hal's suggestion for a faster G split 9a2d3f738a
  28. Build test objects separately b27c395501
  29. Precompute multiples of G 7ec8dcdba1
  30. Make optimized secp256k1 optional 92d1d41fab
  31. Diapolo commented at 8:49 PM on May 2, 2013: none

    How do these pulls get tagged updated, when I see no changes here? Rebase?

  32. sipa commented at 8:54 PM on May 2, 2013: member

    I don't intend to keep this updated, as I'm working on a separately library that implements ECDSA directly, with much more optimizations than this pullreq does. See http://github.com/sipa/secp256k1

  33. Diapolo commented at 9:00 PM on May 2, 2013: none

    You missunderstood my comment, this pull or issue was listed updated for me and I asked what made Github think it was updated. I think your work on this is great, but my intention was just to understand Github here.

  34. sipa commented at 9:02 PM on May 2, 2013: member

    @Diapolo Github hiccup, I guess.

  35. sipa closed this on May 2, 2013

  36. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 09:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me