-
Notifications
You must be signed in to change notification settings - Fork 369
somthing wrong in bitvec codec #5886
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
Comments
Do you mind explaining what exactly is wrong with this implementation? |
The current implementation of the BitVec class contains a discrepancy in how the length is encoded. According to the class comment, the length prefix should indicate the number of bits encoded, not the number of bytes.
The method responsible for calculating the encoded length currently returns:
The length should be encoded correctly as the number of bits. Therefore, the correct implementation should be:
decode section
|
@mrtnetwork based on my understanding and research the current implementation is correct: public override get encodedLength (): number {
return this.length + compactToU8a(this.#decodedLength).length;
} Why it's correct: The SCALE
Using Example: A
If the prefix used Hope this concisely clarifies it. |
Amazing analysis @rajk93 |
But in this code, |
Yes, @mrtnetwork — It looks like there's an issue in the decodeBitVec function, which is used in the constructor to set Currently, the length calculation appears to be: return [u8a.length / 8, u8a]; However, this should be: return [u8a.length * 8, u8a]; to correctly represent the length in bits, not bytes. |
In the BitVec codec, I see the following comment:
However, in the decoding section, we have:
Can you please double-check the encoding and decoding logic for BitVec? Thanks!
The text was updated successfully, but these errors were encountered: