libp2p / libp2p/go-libp2p

core: can't decode an encoded peer.ID, for certain peer ID values

Open
#1,694 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
6.9k
Forks
1.3k
Avg merge
13d 21h
Merged PRs (30d)
1

Description

Minimal example:

```go
package main

import (
"log"

"github.com/libp2p/go-libp2p-core/peer"
)

func main() {
data := []byte{
0x00, 0x01, 0x72, 0x94, 0xe4, 0xc5, 0x30, 0x1b, 0x30, 0x30, 0x30, 0x0e, 0x30, 0xbd, 0xef,
0x30, 0x30, 0x30, 0x22, 0x77, 0xff, 0x22, 0x30, 0xef, 0x30, 0x30, 0x30, 0xbd, 0x30, 0x30, 0x30,
0x30, 0xbd, 0x30, 0x30,
}
var id peer.ID
if err := id.UnmarshalText(data); err != nil {
log.Fatal("unmarshal failed")
}
encoded := peer.Encode(id)
id2, err := peer.Decode(encoded)
if err != nil {
log.Fatal(err)
}
if id != id2 {
log.Fatal("expected ids to match")
}
}
```

The `peer.Decode(encoded)` step here fails: `failed to parse peer ID: expected 1 as the cid version number, got: 3261359138256`.

As far as I can tell, the reason for the failure is that `Encode` always uses base58 encoding: https://github.com/libp2p/go-libp2p-core/blob/83ac1d370dfe3f04aee38a904f73e49070be4863/peer/peer.go#L144-L146
Encoding uses the CID code to decode, if the encoded value doesn't start with "1" or "Qm": https://github.com/libp2p/go-libp2p-core/blob/83ac1d370dfe3f04aee38a904f73e49070be4863/peer/peer.go#L172-L187

I'm not sure what to do here. Can someone with more IPLD experience help me out here? @rvagg, @warpfork?

Contributor guide

No contributing guide indexed for this repository

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 with peer/peer.go at the Encode and Decode implementations referenced in the issue, then run the minimal Go example to reproduce the round-trip failure. Trace how the encoded peer ID is interpreted when it does not begin with "1" or "Qm". Done means the example decodes successfully and the original and decoded peer.ID values match.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
networking
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.