Bitcoin Forum
June 14, 2024, 07:43:33 PM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Byte order in serialisation  (Read 621 times)
domob (OP)
Legendary
*
Offline Offline

Activity: 1135
Merit: 1166


View Profile WWW
April 15, 2014, 12:16:30 PM
 #1

Looking at Bitcoin's serialize.h and in particular the WRITEDATA / READDATA macros, I wonder how this handles byte order / endian-ness issues correctly.  Seemingly, primitive data types (for instance, (unsigned) integers) are serialised just as they appear in memory.  The same seems to be true for the individual "words" (uint32_t each) of uint256.  I can not find anything that handles converting to a unified byte order.  Aren't these routines also used to compute the hashes and to transmit data over the network?  At least for these uses, shouldn't the byte order be "normalised" somehow?

I'm probably just missing something obvious, since I've only started looking at these pieces of the code.  What is it? Smiley

Use your Namecoin identity as OpenID: https://nameid.org/
Donations: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS | GPG 0xA7330737
TierNolan
Legendary
*
Offline Offline

Activity: 1232
Merit: 1084


View Profile
April 15, 2014, 01:21:52 PM
 #2

Pretty much all numbers in the protocol are little endian.

Implementations on big endian machines would have to convert.

IP addresses and ports are big endian though (in the addr message).  DER format is big endian too and it is used for keys.

1LxbG5cKXzTwZg9mjL3gaRE835uNQEteWF
maaku
Legendary
*
expert
Offline Offline

Activity: 905
Merit: 1011


View Profile
April 15, 2014, 06:49:54 PM
 #3

How the compiled binaries behave on supported platforms (just x86, currently) is the standard behavior. It would have been better if Satoshi followed typical conventions with regard to bit- and byte-order, but that ship has long since sailed.

I'm an independent developer working on bitcoin-core, making my living off community donations.
If you like my work, please consider donating yourself: 13snZ4ZyCzaL7358SmgvHGC9AxskqumNxP
domob (OP)
Legendary
*
Offline Offline

Activity: 1135
Merit: 1166


View Profile WWW
April 16, 2014, 06:01:31 AM
 #4

Ok thanks.  So this means that the reference client can't be compiled for big endian platforms?  Have those become so rare in the last years?  I didn't expect that.  But anyway, this answers my question!

Use your Namecoin identity as OpenID: https://nameid.org/
Donations: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS | GPG 0xA7330737
maaku
Legendary
*
expert
Offline Offline

Activity: 905
Merit: 1011


View Profile
April 16, 2014, 08:04:32 AM
 #5

It does not currently work on big-endian systems, no. But it could in principle be modified to work, by adding the appropriate conditional byteswaps.

I'm an independent developer working on bitcoin-core, making my living off community donations.
If you like my work, please consider donating yourself: 13snZ4ZyCzaL7358SmgvHGC9AxskqumNxP
domob (OP)
Legendary
*
Offline Offline

Activity: 1135
Merit: 1166


View Profile WWW
April 16, 2014, 11:11:29 AM
 #6

It does not currently work on big-endian systems, no. But it could in principle be modified to work, by adding the appropriate conditional byteswaps.

Yes of course.  I was looking for those in the first place.  But if the code is not (yet) meant for big endian systems, everything is fine.

Use your Namecoin identity as OpenID: https://nameid.org/
Donations: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS | GPG 0xA7330737
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!