Conversation
🤖 Kimi Code ReviewSecurity & Correctness IssuesLine 465-467: The
Line 468: Hardcoded IPv4 assumption - this will crash on IPv6-only networks. Suggested FixReplace the parsing logic with proper error handling: let ip = record.pairs
.iter()
.find(|(key, _)| key.as_ref() == b"ip")
.and_then(|(_, bytes)| {
// Try IPv4 first, then IPv6
Ipv4Addr::decode(bytes.as_ref())
.map(IpAddr::from)
.or_else(|_| Ipv6Addr::decode(bytes.as_ref()).map(IpAddr::from))
})
.unwrap_or_else(|| {
// Log warning and skip this ENR instead of panicking
warn!("Skipping ENR without valid IP: {}", enr);
return None;
})?;Also, the function should return Minor Issues
Automated review by Kimi (Moonshot AI) · custom prompt |
🤖 Codex Code ReviewFocused review of the diff in Findings (ordered by severity)
Security implications
Performance
Rust best practices
Suggested direction
If you want, I can draft a small refactor to handle Suggested next steps:
Automated review by OpenAI Codex · custom prompt |
🤖 Claude Code ReviewBased on my review of the PR, here's my analysis: PR Review: Fix bootnode IP address parsingSummaryThe PR correctly fixes the hardcoded Findings
|
Greptile OverviewGreptile Summary
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| crates/net/p2p/src/lib.rs | Parses bootnode IP from ENR record instead of hardcoding 127.0.0.1, but the new code only supports the ENR ip (IPv4) key and will panic for valid ENRs that use ip6/non-IPv4 encodings. |
Sequence Diagram
sequenceDiagram
participant Cfg as Config (bootnodes ENRs)
participant P2P as p2p::start_p2p
participant Parser as parse_enrs
participant ENR as NodeRecord
participant Swarm as libp2p::Swarm
Cfg->>P2P: bootnodes: Vec<String>
P2P->>Parser: parse_enrs(enrs)
loop each enr_str
Parser->>ENR: base64 decode + RLP decode
Parser->>ENR: find "quic" + "secp256k1"
Parser->>ENR: find "ip" (new)
Parser-->>Parser: decode IPv4 bytes => IpAddr
Parser-->>P2P: Bootnode { ip, quic_port, public_key }
end
P2P->>Swarm: dial /ip{ip}/udp/{quic_port}/quic-v1/p2p/{peer_id}
Swarm-->>P2P: ConnectionEstablished / ConnectionClosed events
| .unwrap(); | ||
|
|
||
| let quic_port = u16::decode(quic_port_bytes.as_ref()).unwrap(); | ||
| let (_, ip_bytes) = record |
There was a problem hiding this comment.
Bootnode IP parsing too strict
parse_enrs now requires an ENR pair with key "ip" and decodes it as Ipv4Addr. That will panic for valid bootnode ENRs that advertise only IPv6 ("ip6") or otherwise omit "ip" (common on dual-stack/IPv6-only deployments). This reintroduces “works locally but not remotely” failures for IPv6 environments. Consider supporting both ip and ip6 (and decoding to IpAddr accordingly), or falling back to SocketAddr resolution if the ENR omits an IP field.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/net/p2p/src/lib.rs
Line: 458:461
Comment:
**Bootnode IP parsing too strict**
`parse_enrs` now requires an ENR pair with key `"ip"` and decodes it as `Ipv4Addr`. That will panic for valid bootnode ENRs that advertise only IPv6 (`"ip6"`) or otherwise omit `"ip"` (common on dual-stack/IPv6-only deployments). This reintroduces “works locally but not remotely” failures for IPv6 environments. Consider supporting both `ip` and `ip6` (and decoding to `IpAddr` accordingly), or falling back to `SocketAddr` resolution if the ENR omits an IP field.
How can I resolve this? If you propose a fix, please make it concise.
We had a hardcoded value of 127.0.0.1 for bootnode IPs. This worked for local devnets but not for remote deployments.
This PR adds parsing from the config file to populate this value.