Bitcoin Forum
May 05, 2024, 09:34:52 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Need some clarification on usage of the nonce in version message  (Read 263 times)
BusinessChain (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 34


View Profile
June 02, 2018, 04:38:35 PM
Last edit: June 04, 2018, 12:10:32 PM by BusinessChain
 #1

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.
1714901692
Hero Member
*
Offline Offline

Posts: 1714901692

View Profile Personal Message (Offline)

Ignore
1714901692
Reply with quote  #2

1714901692
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714901692
Hero Member
*
Offline Offline

Posts: 1714901692

View Profile Personal Message (Offline)

Ignore
1714901692
Reply with quote  #2

1714901692
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
June 03, 2018, 05:30:39 AM
Merited by Foxpup (2), ABCbits (1)
 #2

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.

BusinessChain (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 34


View Profile
June 03, 2018, 02:11:53 PM
 #3

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?

Quote
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?
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
June 05, 2018, 04:27:51 AM
 #4

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.

BusinessChain (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 34


View Profile
June 06, 2018, 02:15:03 PM
 #5



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
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
June 08, 2018, 07:09:12 AM
 #6

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.

BusinessChain (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 34


View Profile
July 26, 2018, 09:01:01 AM
 #7

Quote
Perhaps then, you can explain to me why you think it shouldn't be done this way.

Because it saves unnecessary code.
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4158
Merit: 8382



View Profile WWW
July 26, 2018, 03:11:43 PM
Merited by Foxpup (2)
 #8

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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!