-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Summary
PeerRecord uses incompatible domain and payload type with Go/JS implementations, breaking cross-implementation interoperability
Expected behavior
Rust libp2p should be able to verify signed peer records created by Go and JavaScript implementations, and vice versa. All implementations should use the same domain string and payload type as defined in the libp2p specifications.
Expected constants (matching Go/JS):
- Domain: "libp2p-peer-record"
- Payload Type: [0x03, 0x01] (multicodec identifier)
References:
- Go: https://github.com/libp2p/go-libp2p/blob/master/core/peer/record.go#L21-L24
- JS: https://github.com/libp2p/js-libp2p/blob/main/packages/peer-record/src/peer-record/consts.ts#L7
- Multicodec table: https://github.com/multiformats/multicodec/blob/master/table.csv
Actual behavior
Rust libp2p uses different constants:
- Domain: "libp2p-routing-state"
- Payload Type: "/libp2p/routing-state-record"
This causes signed peer records from JS/Go to fail verification in Rust with:
BadPayload(UnexpectedPayloadType { expected: [47, 108, 105, 98, 112, 50, 112, 47, 114, 111, 117, 116, 105, 110, 103, 45, 115, 116, 97, 116, 101, 45, 114, 101, 99, 111, 114, 100], got: [3, 1] })
The expected bytes decode to "/libp2p/routing-state-record" (wrong).
The received bytes [3, 1] are the correct multicodec identifier.
Relevant log output
Running tests with signed peer records from JS and Go:
---- tests::verify_js_signed_peer_record stdout ----
thread 'tests::verify_js_signed_peer_record' panicked at core/tests/peer_record_interop.rs:18:56:
Failed to verify JS peer record: BadPayload(UnexpectedPayloadType { expected: [47, 108, 105, 98, 112, 50, 112, 47, 114, 111, 117, 116, 105, 110, 103, 45, 115, 116, 97, 116, 101, 45, 114, 101, 99, 111, 114, 100], got: [3, 1] })
---- tests::verify_go_signed_peer_record stdout ----
thread 'tests::verify_go_signed_peer_record' panicked at core/tests/peer_record_interop.rs:25:56:
Failed to verify Go peer record: BadPayload(UnexpectedPayloadType { expected: [47, 108, 105, 98, 112, 50, 112, 47, 114, 111, 117, 116, 105, 110, 103, 45, 115, 116, 97, 116, 101, 45, 114, 101, 99, 111, 114, 100], got: [3, 1] })Possible Solution
// core/src/peer_record.rs
// Change from:
const PAYLOAD_TYPE: &str = "/libp2p/routing-state-record";
const DOMAIN_SEP: &str = "libp2p-routing-state";
// To:
const PAYLOAD_TYPE: &[u8] = &[0x03, 0x01];
const DOMAIN_SEP: &str = "libp2p-peer-record";
Version
0.43.1
Would you like to work on fixing this bug?
Yes