Skip to content

Update libsecp256k1, Go wrapper and tests#1853

Merged
obscuren merged 2 commits intoethereum:developfrom
Gustav-Simonsson:libsecp256k1_update
Oct 15, 2015
Merged

Update libsecp256k1, Go wrapper and tests#1853
obscuren merged 2 commits intoethereum:developfrom
Gustav-Simonsson:libsecp256k1_update

Conversation

@Gustav-Simonsson
Copy link
Copy Markdown

NOTE: RecoverPubkey is on the consensus-critical code path. Please review carefully.

Go wrapper update is in it's own commit, files changed:

crypto/secp256k1/secp256.go
crypto/secp256k1/secp256_test.go
benchmark                                  old ns/op     new ns/op     delta
BenchmarkSignRandomInputEachRound-2        148648        149994        +0.91%
BenchmarkRecoverRandomInputEachRound-2     207831        203833        -1.92%

We'll probably see a more significant speedup when we can improve internal conversions (as in remove where possible) of signatures and pubkeys - currently we need two extra calls to the lib for each recovery - one to serialise signature and one to serialise the returned pubkey.

If we can avoid those calls + other internal conversions we could probably gain a few % more on recovery.

  • Update libsecp256k1
  • Update Go wrapper to new libsecp256k1 API
  • Refactor Go wrapper tests to have meaningful names, clearer validations and a few more edge cases.
  • Add benchmarks of Sign and RecoverPubkey

@robotally
Copy link
Copy Markdown

Vote Count Reviewers
👍 2 @fjl @obscuren
👎 0

Updated: Fri Oct 9 13:02:59 UTC 2015

@fjl
Copy link
Copy Markdown
Contributor

fjl commented Oct 1, 2015

Did you add zeroing of intermediate buffers yet?

@Gustav-Simonsson
Copy link
Copy Markdown
Author

@fjl not yet. added to Sign

@obscuren
Copy link
Copy Markdown
Contributor

obscuren commented Oct 8, 2015

LGTM 👍

@Gustav-Simonsson
Copy link
Copy Markdown
Author

@obscuren removed unneeded return matchings. SECP256K1_EC_COMPRESSED is from the name of the macro in the lib

@codecov-io
Copy link
Copy Markdown

Current coverage is 47.77%

Merging #1853 into develop will increase coverage by +0.14% as of 97d4d77

Powered by Codecov. Updated on successful CI builds.

Comment thread crypto/secp256k1/secp256_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's usually better to use the same input data for all iterations.
package testing runs benchmarks several times to make the
result more stable, so StartTimer/StopTimer is not required.
This also applies to BenchmarkSign.

_, seckey := GenerateKeyPair()
msg := randentropy.GetEntropyCSPRNG(32)
sig, _ := Sign(msg, seckey)
for i := 0; i < b.N; i++ {
    if _, err := RecoverPubkey(msg, sig); err != nil {
        b.Fatal(err)
    }
} 

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually in this benchmark it's intended to use a new key for every recovery to avoid potential caching affecting the benchmark. I'll add another benchmark where the same key is used though, that will be interesting to see if caching affects the result. In that one starting and stopping of the timer can indeed be skipped.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of caching? libsecp256k1 shouldn't cache anything.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, but it takes much less time if using the same key. See new commit - pushed a separate benchmark for using the same key.

@fjl
Copy link
Copy Markdown
Contributor

fjl commented Oct 9, 2015

👍 and please squash one more time.

obscuren added a commit that referenced this pull request Oct 15, 2015
Update libsecp256k1, Go wrapper and tests
@obscuren obscuren merged commit f466243 into ethereum:develop Oct 15, 2015
@obscuren obscuren removed the review label Oct 15, 2015
@obscuren obscuren modified the milestones: 2.0.0, 1.3.0 Oct 29, 2015
sduchesneau pushed a commit to streamingfast/go-ethereum that referenced this pull request Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants