Bitcoin Forum
September 27, 2018, 10:41:28 PM *
News: ♦♦ New info! Bitcoin Core users absolutely must upgrade to previously-announced 0.16.3 [Torrent]. All Bitcoin users should temporarily trust confirmations slightly less. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Byte order in serialisation  (Read 552 times)
domob
Legendary
*
Offline Offline

Activity: 1004
Merit: 1007


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

Posts: 1538088088

View Profile Personal Message (Offline)

Ignore
1538088088
Reply with quote  #2

1538088088
Report to moderator
1538088088
Hero Member
*
Offline Offline

Posts: 1538088088

View Profile Personal Message (Offline)

Ignore
1538088088
Reply with quote  #2

1538088088
Report to moderator
Make a difference with your Ether.
Donate Ether for the greater good.
SPRING.WETRUST.IO
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1538088088
Hero Member
*
Offline Offline

Posts: 1538088088

View Profile Personal Message (Offline)

Ignore
1538088088
Reply with quote  #2

1538088088
Report to moderator
1538088088
Hero Member
*
Offline Offline

Posts: 1538088088

View Profile Personal Message (Offline)

Ignore
1538088088
Reply with quote  #2

1538088088
Report to moderator
TierNolan
Legendary
*
Offline Offline

Activity: 1190
Merit: 1001


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: 1001


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
Legendary
*
Offline Offline

Activity: 1004
Merit: 1007


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: 1001


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
Legendary
*
Offline Offline

Activity: 1004
Merit: 1007


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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!