-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Varint description #2340
Comments
This varint encoding is the same as the one used in protocol buffers (https://developers.google.com/protocol-buffers/docs/encoding#varints). The integers are stored in little-endian order, but by blocks of 7 bits (instead of 8). In each byte, bits 0 to 6 are bits from the integer, and bit 8 indicates if there are more bits to come (in the next byte) or not. In the case of 0xff = 11111111 So the encoding of 0xff is "ff01". Note: the varint encoding used by the portable binary archive serialization is different from this one |
Ok, I see. So the description in varint.h is misleading. |
+resolved |
@glv2 can you explain the varint encoding used by the portable binary archive serialization please? |
The portable binary archive serialization stores integers in little-endian order in a series of 1, 2, 4 or 8 bytes. /* Constants used */
BYTE = 0
WORD = 1
DOUBLE_WORD = 2
QUAD_WORD = 3
/* Serialization rules */
if (n <= 64)
return (uint8le) ((n << 2) | BYTE)
else if (n <= 16383)
return (uint16le) ((n << 2) | WORD)
else if (n <= 1073741823)
return (uint32le) ((n << 2) | DOUBLE_WORD)
else if (n <= 4611686018427387903)
return (uint64le) ((n << 2) | QUAD_WORD)
else
error "Too big to be serialized" |
@glv2 thanks for posting this. We are looking at how the serialisation of a tx prefix is done. If we examine the start of one of these prefixes: Json: Hex of the serialised result (ie serialised prefix not json): Broken up hex: So I have a few questions:
If I examine a different prefix with a higher amount I see this: 01 version Amount=10000 as hex is 2710 which isn't present as hex. If i do n << 2 | 1, I then get 9c41 in hex, which isn't present in the string either. Could you help shed some light on this? Many thanks for your help. |
If I remember correctly, the serialization of transactions uses the protocol buffer varint encoding, not the portable binary archive one. For the format of transactions, check https://monero.stackexchange.com/questions/3958/what-is-the-format-of-a-block-in-the-monero-blockchain or https://monero.stackexchange.com/questions/5664/size-requirements-for-different-pieces-of-a-monero-transaction. |
We figured this out and wrote a doc on it: |
Could you please check if the description of varint is correct?
https://github.com/monero-project/monero/blob/master/src/common/varint.h#L38
It doesn't make sense to me.
What happens when you want to encode 0x01ff01 to varint?
The text was updated successfully, but these errors were encountered: