libp2p / libp2p/py-libp2p

Interoperability of ed25519 keys

Open
#921 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
624
Forks
256
Avg merge
1d 34m
Merged PRs (30d)
47

Description

### Summary

I have not much experience in p2p networking or ed25519, but I think I'm experiencing interoperability issues between py-libp2p and some rust p2p code based on curve25519-dalek. What I'm seeing is that py-libp2p will happily create a keypair, of which the public key is already rejected by curve25519-dalek on object instantiation.

Specifically, the keys sometimes fail [the test done by curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek/blob/adb6a12b4a617659808c5c4de3ecb69d79d373a4/curve25519-dalek/src/edwards.rs#L234), apparently because they are 'not on the/a curve'.

Maybe this relates to [ZIP-0215](https://zips.z.cash/zip-0215) criteria. Interoperability issues seem to be [present for years](https://hdevalence.ca/blog/2020-10-04-its-25519am/).

I hacked together a validation test on the python end (mimicking the rust code), which does `seed[0]++` in a loop until [the generated key](https://github.com/libp2p/py-libp2p/blob/74f4aaf136a022b5a8786bd7e57974b8f6033e7f/libp2p/crypto/ed25519.py#L57) passes the test. This solves the issue.

But again, no experience or knowledge, so I might be missing something here, any feedback is welcome.

### Expected behavior

I expect py-libp2p to be able to inter-operate with other libp2p implementations and not generate keys that other implementations reject as invalid.

### Actual behavior

py-libp2p generates keypairs of which the public key cannot be loaded by rust code based on curve25519-dalek.

### Relevant log output

```shell

```

### Possible Solution

Implement key validation as part of generating random keypairs.

### Environment

```shell

```

### Would you like to work on fixing this bug ?

Yes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in libp2p/crypto/ed25519.py around line 57 and compare its generated public keys with the validation referenced in curve25519-dalek and ZIP-0215. Reproduce the reported rejection and determine the interoperability criteria; done means generated py-libp2p keys are accepted by the referenced Rust implementation without relying on ad hoc seed changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
networking, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.