Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiAddress.String representation question #230

Closed
0xTylerHolmes opened this issue Jan 23, 2024 · 8 comments
Closed

MultiAddress.String representation question #230

0xTylerHolmes opened this issue Jan 23, 2024 · 8 comments

Comments

@0xTylerHolmes
Copy link
Contributor

I'm trying to understand some of the caveats of the different NewMultiaddr functions. Is the string representation of a multiaddress supposed to be compatible with the string constructor? e.g.

// m is a previously constructed MultiAddr
m2, err := ma.NewMultiaddr(m.String())

Should NewMultiaddr ever fail? My understanding is that m2 should always succeed and that m.Equal(m2) should always be true.

@Jorropo
Copy link
Contributor

Jorropo commented Jan 24, 2024

This is correct.

@Jorropo
Copy link
Contributor

Jorropo commented Jan 24, 2024

I think there are edge cases like base64 where you can add extra padding which is trimmed off if you do the round trip.

@Jorropo
Copy link
Contributor

Jorropo commented Jan 24, 2024

Actually no, I was completely wrong, there are plenty of counter examples where we canonicalize old encodings:

--- FAIL: FuzzNewMultiaddrString (0.01s)
    --- FAIL: FuzzNewMultiaddrString/seed#23 (0.00s)
        multiaddr_test.go:543: before and after don't match "/garlic32/566niximlxdzpanmn4qouucvua3k7neniwss47li5r6ugoertzuqzwassw" "/garlic32/566niximlxdzpanmn4qouucvua3k7neniwss47li5r6ugoertzuqzwassu"
    --- FAIL: FuzzNewMultiaddrString/seed#35 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC" "/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"
    --- FAIL: FuzzNewMultiaddrString/seed#36 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7" "/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"
    --- FAIL: FuzzNewMultiaddrString/seed#38 (0.00s)
        multiaddr_test.go:543: before and after don't match "/p2p/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7" "/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"
    --- FAIL: FuzzNewMultiaddrString/seed#39 (0.00s)
        multiaddr_test.go:543: before and after don't match "/p2p/bafzbeigvf25ytwc3akrijfecaotc74udrhcxzh2cx3we5qqnw5vgrei4bm" "/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"
    --- FAIL: FuzzNewMultiaddrString/seed#41 (0.00s)
        multiaddr_test.go:543: before and after don't match "/p2p/k51qzi5uqu5dhb6l8spkdx7yxafegfkee5by8h7lmjh2ehc2sgg34z7c15vzqs" "/p2p/12D3KooWCryG7Mon9orvQxcS1rYZjotPgpwoJNHHKcLLfE4Hf5mV"
    --- FAIL: FuzzNewMultiaddrString/seed#42 (0.00s)
        multiaddr_test.go:543: before and after don't match "/p2p/bafzaajaiaejcalj543iwv2d7pkjt7ykvefrkfu7qjfi6sduakhso4lay6abn2d5u" "/p2p/12D3KooWCryG7Mon9orvQxcS1rYZjotPgpwoJNHHKcLLfE4Hf5mV"
    --- FAIL: FuzzNewMultiaddrString/seed#49 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234" "/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234"
    --- FAIL: FuzzNewMultiaddrString/seed#50 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7/tcp/1234" "/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234"
    --- FAIL: FuzzNewMultiaddrString/seed#52 (0.00s)
        multiaddr_test.go:543: before and after don't match "/p2p/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7/tcp/1234" "/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234"
    --- FAIL: FuzzNewMultiaddrString/seed#56 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/tcp/1234/" "/ip4/127.0.0.1/tcp/1234"
    --- FAIL: FuzzNewMultiaddrString/seed#60 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmpy" "/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/u1QEQOFj2IjCsPJFfMAxmQxLGPw"
    --- FAIL: FuzzNewMultiaddrString/seed#61 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmpy/certhash/zQmbWTwYGcmdyK9CYfNBcfs9nhZs17a6FQ4Y8oea278xx41" "/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/u1QEQOFj2IjCsPJFfMAxmQxLGPw/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g"
    --- FAIL: FuzzNewMultiaddrString/seed#62 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC" "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"
    --- FAIL: FuzzNewMultiaddrString/seed#63 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234" "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234"
    --- FAIL: FuzzNewMultiaddrString/seed#64 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7" "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"
    --- FAIL: FuzzNewMultiaddrString/seed#65 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7/tcp/1234" "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234"
    --- FAIL: FuzzNewMultiaddrString/seed#68 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/p2p/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7" "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"
    --- FAIL: FuzzNewMultiaddrString/seed#69 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/p2p/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7/tcp/1234" "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234"
    --- FAIL: FuzzNewMultiaddrString/seed#73 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234/unix/stdio" "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234/unix/stdio"
    --- FAIL: FuzzNewMultiaddrString/seed#74 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7/tcp/1234/unix/stdio" "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234/unix/stdio"
    --- FAIL: FuzzNewMultiaddrString/seed#76 (0.00s)
        multiaddr_test.go:543: before and after don't match "/ip4/127.0.0.1/p2p/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7/tcp/1234/unix/stdio" "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234/unix/stdio"
    --- FAIL: FuzzNewMultiaddrString/63891c9534054d61 (0.00s)
        multiaddr_test.go:543: before and after don't match "/p2p/BAfZA2jA222222222222222222222222222222222222222222222222222222222" "/p2p/2wkP41SiPzyR6TaGRLzjiywpQVC1HgGK2Ea3tSUeWtobGyZAivsT"
    --- FAIL: FuzzNewMultiaddrString/95a479f85dc92117 (0.00s)
        multiaddr_test.go:543: before and after don't match "/p2p/BAfZBAjA222222222222222222222222222222222222222222222222222222222" "/p2p/3PVGmVXQvTiq21ca5aBR7WEH9nnxnw5VWZSSZoWvzL4j7y9nD8HF"

Generally they have the same semantics, m2.Equal(m) should always be true however.

@0xTylerHolmes
Copy link
Contributor Author

In general though m2 should always succeed correct?

@Jorropo
Copy link
Contributor

Jorropo commented Jan 24, 2024

should is doing heavy work here.
I doubt this actually happens, a counter example probably exists somewhere.

Some weird edge case invalid thing can slip through the cracks.

@0xTylerHolmes
Copy link
Contributor Author

0xTylerHolmes commented Jan 24, 2024

Thanks for clarity, there are several edge cases here generally around different encoding types. It does seem a bit troubling that the str representation isn't valid. (e.g. I have several cases where we error on m2 creation or if we do succeed !m.Equal(m2)), but I don't see a valid use case where someone would want to do this in production.

As long as this doesn't sound alarming I'm satisfied with my current understanding and I'll close this issue.

@Jorropo
Copy link
Contributor

Jorropo commented Feb 9, 2024

Hey I improved fuzzing and @sukunrt fixed a bunch of edge cases in 77f3edf.
Could you retry your:

I have several cases where we error on m2 creation or if we do succeed !m.Equal(m2)

cases with v0.12.2 they should be consistent now.

Again I don't think it's critical to have complete consistency but it's still nice.

@sukunrt
Copy link
Member

sukunrt commented Mar 4, 2024

Fixed by #232

@sukunrt sukunrt closed this as completed Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants