Skip to content

Comments

Replace OpenSSL With rbsecp25k1#43

Closed
etscrivner wants to merge 4 commits intose3000:developfrom
etscrivner:use-rbsecp256k1
Closed

Replace OpenSSL With rbsecp25k1#43
etscrivner wants to merge 4 commits intose3000:developfrom
etscrivner:use-rbsecp256k1

Conversation

@etscrivner
Copy link
Contributor

@etscrivner etscrivner commented Sep 28, 2019

Overview

This change replaces the current OpenSSL secp256k1 ECDSA with rbsecp256k1, a native extension gem binding to libsecp256k1. It replaces all key generation, signing, and key recovery methods with their rbsecp256k1 equivalents.

Directly using libsecp256k1 will provide performance and security benefits over the current hand-rolled OpenSSL version.

  • Replacing OpenSSL
    • Replace OpenSSL usage with rbsecp256k1.
    • Remove OpenSSL dependency and Secp256k1 module.
  • Clean up and refactoring
    • Factor out recoverable signature functionality into a single interface.

This change replaces the current OpenSSL secp256k1 ECDSA with rbsecp256k1, a
binding to libsecp256k1. It replaces all key generation, signing, and key
recovery methods with their rbsecp256k1 equivalents.
Remove the OpenSSL and Secp256k1 modules as they are replaced by rbsecp256k1.
We also no longer need to check that signatures are in lower-s form as this is
done by libsecp256k1.
Factor the recoverable signature functionality out into two separate classes.
`PersonalMessage` which represents a message to be recoverably signed,
typically to prove key ownership. `RecoverableSignature` which represents a
recoverable signature and provides methods for easily recovering the public key
from it.
Remove TODO around libsecp256k1 signing from the README as this is now
supported.
@etscrivner etscrivner changed the title [WIP] Replace OpenSSL With rbsecp25k1 Replace OpenSSL With rbsecp25k1 Sep 30, 2019
@etscrivner etscrivner requested a review from se3000 January 29, 2020 21:52
def personal_sign(message, chain_id = nil)
signature =
if chain_id
PersonalMessage.new(message).sign(private_key, nil)
Copy link
Owner

Choose a reason for hiding this comment

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

I thought that personal_sign did not take chain ID into account? As far as I can see in this PR, this chain_id parameter is is always nil for PersonalMessage#sign. Could we cut it? Is there a scenario for it I'm missing?

# @raise [RuntimeError] if v value derived from signature is invalid.
def initialize(signature, chain_id = nil)
# Move the last byte containing the v value to the front.
rotated_signature = Utils.hex_to_bin(signature).bytes.rotate(-1)
Copy link
Owner

Choose a reason for hiding this comment

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

Isn't it possible that v is larger than a single byte?

@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'digest-sha3-patched', '~> 1.1'
spec.add_dependency 'ffi', '~> 1.0'
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
spec.add_dependency 'ffi', '~> 1.0'

I think we can get rid of the FFI dependency now that we aren't using OpenSSL.

@akodkod
Copy link

akodkod commented Mar 15, 2020

@etscrivner unfortunately, your solution still doesn't work for me. When I'm trying to run rails console I get this error and nothing else:

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

Any ideas?

@andremedeiros
Copy link

@se3000 do you need someone to take over this PR? I'm getting an issue with OpenSSL on Mac (it pretends to be OpenSSL but it's really LibreSSL) and this PR could make my life a lot easier.

@keo
Copy link

keo commented Oct 31, 2020

would love to have this working!

@q9f
Copy link
Collaborator

q9f commented Oct 27, 2021

If anyone wants to take over this work and rebase it on the latest version of ruby-eth, I would be happy to review and integrate it.

@q9f
Copy link
Collaborator

q9f commented Dec 22, 2021

I implemented this in q9f/eth.rb#4 and q9f/eth.rb#24 and plan to release it as 0.5.0 soon. Thanks for your pioneering work @etscrivner 🎉

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.

6 participants