Author

Topic: Need some clarification on usage of the nonce in version message (Read 291 times)

staff
Activity: 4284
Merit: 8808
Because it saves unnecessary code.
If you are worried about one line of code in exchange for doing something right you probably have no business creating a Bitcoin node. Smiley (in fact, the difference in practice should be zero lines of code-- it's just a question where the nonce for comparison is stored: globally or per-peer.).

In any case, using a consistent value would be bad for privacy allowing the correlation of a host across networks and time.
newbie
Activity: 24
Merit: 34
Quote
Perhaps then, you can explain to me why you think it shouldn't be done this way.

Because it saves unnecessary code.
staff
Activity: 3458
Merit: 6793
Just writing some code
No, it is a 64 bit integer which obsoletes your point concerning the birthday paradox entirely  Roll Eyes
Oops, forgot about that.

Regardless, my point still stands as the birthday paradox is largely unrelated to the point I was making:
While this is still fairly small, it is trivial to make this a non-issue by randomly generating a random value. Sure you can take a shortcut and no one would really care, but for the benefit of the network, we want to reduce these chances to as close to 0 as possible. We want the best possible and your idea is not the best possible.

That is the reason for doing this.



Perhaps then, you can explain to me why you think it shouldn't be done this way.
newbie
Activity: 24
Merit: 34


Ok in principle I get that. But to me that does not make terribly much sense because the probability that any two nodes create the same nonce AND try to connect to each other is exceedingly small.
I don't think it is as small as you think it is. The field is a 32 bit integer.

No, it is a 64 bit integer which obsoletes your point concerning the birthday paradox entirely  Roll Eyes
staff
Activity: 3458
Merit: 6793
Just writing some code
But in the version message I also have to specify my address (addr_from), so how do I do that if I don't know it?
It doesn't have to be correct. You can really set it to any IP address you want, the field is pretty much ignored. Many clients will set it to 127.0.0.1 if they don't know, and some set it to that even if they do know their external IP address.

Ok in principle I get that. But to me that does not make terribly much sense because the probability that any two nodes create the same nonce AND try to connect to each other is exceedingly small.
I don't think it is as small as you think it is. The field is a 32 bit integer. By the birthday paradox, you would only need 65536 nodes before it is likely that two of those nodes happen to generate the same nonce. While this is still fairly small, it is trivial to make this a non-issue by randomly generating a random value. Sure you can take a shortcut and no one would really care, but for the benefit of the network, we want to reduce these chances to as close to 0 as possible. We want the best possible and your idea is not the best possible.

So for that case I could just connect to another peer. Is that a fair statement?
Yes, you could just connect to another peer.
newbie
Activity: 24
Merit: 34
I need some clarification. First, why do I need a nonce to detect a connection to myself, do I not just see that from the IP address?
No, a node does not necessarily know his external IP address. Your computer typically does not know its external IP address unless someone tells you it. This is especially the case if your computer is behind a NAT (usually setup by a router), which it typically is.

But in the version message I also have to specify my address (addr_from), so how do I do that if I don't know it?

Second, why do I need to create a new nonce for EVERY version message? Can I not just always use the same nonce since this would still allow me to detect a connection to myself.
A random nonce allows you to avoid having the same nonce generated by someone else. If you happen to use the same nonce as someone else, you would not be able to connect to them as both nodes would think the connection was to themselves and drop it. Even with a randomly generated fixed nonce at the beginning of a session, the two nodes would never be able to connect with each other. With random nonces for every message, even if the nonces collide, the connection can be tried again and a new nonce will be used which is unlikely to collide.

Ok in principle I get that. But to me that does not make terribly much sense because the probability that any two nodes create the same nonce AND try to connect to each other is exceedingly small. So for that case I could just connect to another peer. Is that a fair statement?
staff
Activity: 3458
Merit: 6793
Just writing some code
I need some clarification. First, why do I need a nonce to detect a connection to myself, do I not just see that from the IP address?
No, a node does not necessarily know his external IP address. Your computer typically does not know its external IP address unless someone tells you it. This is especially the case if your computer is behind a NAT (usually setup by a router), which it typically is.

Second, why do I need to create a new nonce for EVERY version message? Can I not just always use the same nonce since this would still allow me to detect a connection to myself.
A random nonce allows you to avoid having the same nonce generated by someone else. If you happen to use the same nonce as someone else, you would not be able to connect to them as both nodes would think the connection was to themselves and drop it. Even with a randomly generated fixed nonce at the beginning of a session, the two nodes would never be able to connect with each other. With random nonces for every message, even if the nonces collide, the connection can be tried again and a new nonce will be used which is unlikely to collide.

@theymos:
My questions may not be the brightest from time to time, maybe just like the one above. But I do not think this is a reason to ban people just as you did with my prior account (schnuber2). You just banned me for no other reason than asking a legit question dude. I feel quite offended by this.

Please do not post meta topics in non-meta forums. Also note that if you were banned on one account, you cannot return with another account to post; that is considered ban evasion and is a bannable offense.
newbie
Activity: 24
Merit: 34
In https://en.bitcoin.it/wiki/Protocol_documentation#version it says about the nonce in the version message:

Quote
Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self.

I need some clarification. First, why do I need a nonce to detect a connection to myself, do I not just see that from the IP address? Second, why do I need to create a new nonce for EVERY version message? Can I not just always use the same nonce since this would still allow me to detect a connection to myself.
Jump to: