Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: Use ed25519-consensus instead of ed25519-dalek (#1067) #1245

Merged

Conversation

hdevalence
Copy link
Collaborator

Backports this change to the new main (was #1067).

  • Use ed25519-consensus instead of ed25519-dalek

Closes #355 (see that issue for more context; ed25519-consensus is a fork of ed25519-zebra that's Zcash-independent).

This change ensures that tendermint-rs has the same signature verification as tendermint, which uses the validation criteria provided by the Go ed25519consensus library.

  • clippy fixes

Co-authored-by: Thane Thomson connect@thanethomson.com

  • Remove redundant dependency

Signed-off-by: Thane Thomson connect@thanethomson.com

  • cargo fmt

Signed-off-by: Thane Thomson connect@thanethomson.com

  • Add changelog entries

Signed-off-by: Thane Thomson connect@thanethomson.com

Co-authored-by: Henry de Valence hdevalence@penumbra.zone

@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2022

Codecov Report

Merging #1245 (726c637) into main (560c852) will decrease coverage by 0.0%.
The diff coverage is 67.8%.

@@           Coverage Diff           @@
##            main   #1245     +/-   ##
=======================================
- Coverage   64.4%   64.4%   -0.1%     
=======================================
  Files        245     245             
  Lines      21581   21547     -34     
=======================================
- Hits       13917   13889     -28     
+ Misses      7664    7658      -6     
Impacted Files Coverage Δ
p2p/src/error.rs 0.0% <ø> (ø)
p2p/src/secret_connection/amino_types.rs 0.0% <0.0%> (ø)
tendermint/src/error.rs 0.0% <0.0%> (ø)
tendermint/src/private_key.rs 28.7% <36.3%> (+4.9%) ⬆️
p2p/src/secret_connection/protocol.rs 59.8% <60.0%> (ø)
p2p/src/secret_connection.rs 86.6% <78.5%> (-0.2%) ⬇️
p2p/src/secret_connection/public_key.rs 80.6% <83.3%> (ø)
tendermint/src/public_key.rs 72.5% <85.7%> (-0.3%) ⬇️
config/src/node_key.rs 60.0% <100.0%> (ø)
tendermint/src/account.rs 91.0% <100.0%> (ø)
... and 11 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@mzabaluev mzabaluev left a comment

Choose a reason for hiding this comment

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

Generally looks good.

One thing which I find potentially problematic (though not a change I'm requesting now) is that ed25519-consensus does not integrate into the signature framework. Why is that?

@@ -40,7 +39,6 @@ define_error! {
| _ | { "public key missing" },

Signature
[ DisplayOnly<SignatureError> ]
Copy link
Contributor

Choose a reason for hiding this comment

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

This error is deliberately opaque, but we can't make the Display impl transparent in flex-error, so we have our own message. OK.

p2p/src/secret_connection.rs Show resolved Hide resolved
Comment on lines +74 to +84
// Tendermint uses a serialization format inherited from Go that includes a
// cached copy of the public key as the second half. This is somewhat
// dangerous, since there's no validation that the two parts are consistent
// with each other, so we ignore the second half and just check consistency
// with the re-derived data.
let signing_key = Ed25519::try_from(&keypair_bytes[0..32])
.map_err(|_| D::Error::custom("invalid signing key"))?;
let verification_key = VerificationKey::from(&signing_key);
if &keypair_bytes[32..64] != verification_key.as_bytes() {
return Err(D::Error::custom("keypair mismatch"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Great!

tendermint/src/public_key.rs Show resolved Hide resolved
flex-error = { version = "0.4.4", default-features = false }
flume = { version = "0.10", default-features = false }
rand_core = { version = "0.5", default-features = false, features = ["std"] }
rand_core = { version = "0.6", default-features = false, features = ["std"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, isis still has not updated their rand version? Another reason to switch.

@hdevalence
Copy link
Collaborator Author

hdevalence commented Dec 9, 2022

Generally looks good.

One thing which I find potentially problematic (though not a change I'm requesting now) is that ed25519-consensus does not integrate into the signature framework. Why is that?

There's no particular reason; there wasn't a need to do it when the crate was written, and it wasn't possible to implement for trivial reasons -- AFAIR, it was because the Signature trait requires AsRef<[u8]>, but internally the ed25519_consensus::Signature type has two [u8; 32] arrays because that was slightly more convenient as an internal representation.

We could probably add it if it's important. To be honest, the main reason we're interested in this is that the ed25519-consensus types have nicer Debug output, and that propagates into our logs when using tendermint-rs types.

@mzabaluev mzabaluev added enhancement New feature or request dependencies Pull requests that update a dependency file labels Dec 9, 2022
@mzabaluev
Copy link
Contributor

mzabaluev commented Dec 9, 2022

@hdevalence I think it's OK to not conform to the signature traits, as we're not going to make the Ed25519 implementation replaceable in the near term as per discussion on Slack (recap: it's not supported by Web Crypto, corner cases addressed differently by other implementations so we need the precise behavior). The API is also close enough to not require significant rework if we decide we need it.

So, I think this just needs a change to do the exhaustive match for proto's key type enum, and we can merge it.

@tony-iqlusion
Copy link
Collaborator

AFAIR, it was because the Signature trait requires AsRef<[u8]>, but internally the ed25519_consensus::Signature type has two [u8; 32] arrays because that was slightly more convenient as an internal representation.

@hdevalence that bound is removed in a forthcoming signature v2.0 release, FWIW:

https://docs.rs/signature/2.0.0-pre.2/signature/index.html

@hdevalence
Copy link
Collaborator Author

@hdevalence I think it's OK to not conform to the signature traits, as we're not going to make the Ed25519 implementation replaceable in the near term as per discussion on Slack (recap: it's not supported by Web Crypto, corner cases addressed differently by other implementations so we need the precise behavior). The API is also close enough to not require significant rework if we decide we need it.

So, I think this just needs a change to do the exhaustive match for proto's key type enum, and we can merge it.

Cool, I updated the exhaustive match. I'd be happy to try to support the signature traits in a later release of the crate if it becomes relevant.

Copy link
Contributor

@mzabaluev mzabaluev left a comment

Choose a reason for hiding this comment

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

Needs merging from main, but is otherwise good to go.

@hdevalence
Copy link
Collaborator Author

Rebased.

@thanethomson
Copy link
Member

Was the failing check here due to clippy errors from Rust v1.66? If so, #1253's been merged and that should fix things.

@thanethomson
Copy link
Member

@hdevalence please resolve the conflicts here and then we'll merge and cut a new release.

thanethomson and others added 5 commits January 9, 2023 17:13
…#1067)

* Use ed25519-consensus instead of ed25519-dalek

Closes informalsystems#355 (see that issue for more context; `ed25519-consensus` is a fork of
`ed25519-zebra` that's Zcash-independent).

This change ensures that `tendermint-rs` has the same signature verification as
`tendermint`, which uses the validation criteria provided by the Go
`ed25519consensus` library.

* clippy fixes

Co-authored-by: Thane Thomson <connect@thanethomson.com>

* Remove redundant dependency

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* cargo fmt

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add changelog entries

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Co-authored-by: Henry de Valence <hdevalence@penumbra.zone>
@hdevalence
Copy link
Collaborator Author

Rebased and did another round of clippy fixes.

Copy link
Contributor

@xla xla left a comment

Choose a reason for hiding this comment

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

(͠≖ ͜ʖ͠≖)👌

@mzabaluev mzabaluev merged commit 95e4505 into informalsystems:main Jan 10, 2023
@mzabaluev
Copy link
Contributor

Thank you @hdevalence and @xla!

@hdevalence
Copy link
Collaborator Author

hdevalence commented Jan 13, 2023

Thanks for merging this! Are there other changes in flight at the moment, or would it be possible to get it into a release soon? (We'll have to wait for it to propagate through our dep tree before we can pick it up).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking dependencies Pull requests that update a dependency file enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider ed25519-zebra crate?
6 participants