Author

Topic: Variable length integer - what the hell? (Read 3513 times)

legendary
Activity: 2128
Merit: 1074
July 29, 2011, 04:49:52 PM
#6
You missed the fact that Bitcoin uses little endian on the network. This is probably Bitcoin's biggest design mistake.
I wouldn't call it biggest, but probably one of the most difficult to rectify. The longer it stays this way the higher are the chances that people enshrine this mistake in the alternative clients. At present time the alternative block layout should be not too hard to implement. So long as it stays this way all the implementations will suffer problems related to those inconsistencies, e.g. ufsminer which was mining on the incorrect endianness.
legendary
Activity: 1596
Merit: 1012
Democracy is vulnerable to a 51% attack.
You missed the fact that Bitcoin uses little endian on the network. This is probably Bitcoin's biggest design mistake.
Here we see a master of the "praise with faint damn" technique. I bow to you, sir.
hero member
Activity: 588
Merit: 500
You missed the fact that Bitcoin uses little endian on the network. This is probably Bitcoin's biggest design mistake.
legendary
Activity: 1050
Merit: 1000
You are WRONG!
i hope you do read python:
Code:
if ord(bdata[0]) <= 0xfc:
    return ord(bdata[0]), bdata[1:]
    if ord(bdata[0]) == 0xfd:
        return struct.unpack("    if ord(bdata[0]) == 0xfe:
        return struct.unpack("    if ord(bdata[0]) == 0xff:
        return struct.unpack("
the first byte describes how long the integer is.
hero member
Activity: 504
Merit: 502
You're wrong I'm afraid.

The way the variable length integer works is:
  • Look at the first byte
  • If that first byte is less than 253, use the byte literally
  • If that first byte is 253, read the next two bytes as a little endian 16-bit number (total bytes read = 3)
  • If that first byte is 254, read the next four bytes as a little endian 32-bit number (total bytes read = 5)
  • If that first byte is 255, read the next eight bytes as a little endian 64-bit number (total bytes read = 9)
legendary
Activity: 2058
Merit: 1416
aka tonikt
Variable length integer, from the bitcoin protocol.

It states very clearly in the wiki:
Quote
<= 0xffff   3   0xfd + uint16_t
Here it makes sense.

But the problem is, when I do getblocks with hash_stop set to zero, I get back inv where the count field is "fd f4 01"
Now, if I parse it according to the spec, it give me value 753 (0xfd + 0x01f4). While in fact the proper value is 500 (0x01f4)

So which one is wrong; the spec or the value inside the message?
Or am I wrong somewhere?
Jump to: