Fix Ed25519 key generation interoperability#1134
Conversation
Signed-off-by: Gautam Manchandani <gautammanch@Gautams-MacBook-Air.local>
|
@seetadev its ready for review! |
|
@GautamBytes : Thanks a lot, Gautam — this is a solid and very well-documented fix 👏 The root cause explanation around probabilistic generation of invalid Ed25519 points and the resulting Python ↔ Rust interoperability failures is very clear, and the approach you’ve taken makes sense: Using crypto_core_ed25519_is_valid_point to enforce strict curve validity aligns well with ZIP-215–style validation. The retry loop for random key generation is a pragmatic solution that preserves ergonomics while guaranteeing correctness. Explicitly failing on invalid seeded keys is the right tradeoff. I also appreciate the conscious decision not to modify from_bytes to avoid breaking existing nodes — that backward-compatibility note is important and well thought through. The comprehensive tests covering both random and seeded generation are a big plus 👍 I’ll invite @acul71 and @pacrob for additional review as well, given the crypto + interoperability implications. One small request before merge: Once that’s in and we get the remaining reviews, we should be in a good position to move this forward. Great work on this — thanks for tackling a subtle but impactful issue! 🚀 |
Signed-off-by: Gautam Manchandani <gautammanch@Gautams-MacBook-Air.local>
|
@seetadev added the newsfragments |
|
@seetadev @GautamBytes Why
|
acul71
left a comment
There was a problem hiding this comment.
Great. I don't like 100 hard coded instead of a constant config var, but it's ok. Thank you!
What was wrong?
Issue #921
Previously,
Ed25519PrivateKey.new()could probabilistically generate keys that were not valid points on the Ed25519 curve. Whilepy-libp2paccepted these keys, strict implementations (such as Rust'scurve25519-dalek, used in Zcash and other networks) rejected them. This caused persistent interoperability failures where valid-looking Python nodes could not connect to Rust nodes.How was it fixed?
The fix ensures that all new keys generated by this library are valid curve points, complying with strict validation rules (like ZIP-215).
Updated
Ed25519PrivateKey.newinlibp2p/crypto/ed25519.py:crypto_core_ed25519_is_valid_pointfromnacl.bindings.ValueErrorif the provided seed results in an invalid curve point.Added Tests:
tests/core/crypto/test_ed25519_comprehensive.pywith specific test cases to verify that both randomly generated and seeded keys are always valid curve points.Note: This change specifically targets new key generation. It intentionally does not modify
from_bytes(loading keys) to ensure backward compatibility for existing nodes that may possess technically invalid but previously functioning keys.