Skip to content
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

bitfield_bytes(bits) should return chunks #1787

Closed
booleanfunction opened this issue May 6, 2020 · 2 comments
Closed

bitfield_bytes(bits) should return chunks #1787

booleanfunction opened this issue May 6, 2020 · 2 comments
Labels
scope:SSZ Simple Serialize

Comments

@booleanfunction
Copy link
Contributor

The simple-serialise (Merkleisation section) reads:

bitfield_bytes(bits): return the bits of the bitlist or bitvector, packed in bytes, aligned to the start. Length-delimiting bit for bitlists is excluded.

However when this function is called for merkleisation of bitvectors or bitlists, the output expected from bitfield_bytes is BYTES_PER_CHUNK-byte chunks, as indicated by the specification of merkleize, generally,

merkleize(chunks, limit=None)

and then the specific definition for bitvectors or bitlists:

merkleize(bitfield_bytes(value), limit=chunk_count(type)) if value is a bitvector.
mix_in_length(merkleize(bitfield_bytes(value), limit=chunk_count(type)), len(value)) if value is a bitlist.

@hwwhww
Copy link
Contributor

hwwhww commented May 6, 2020

Thanks for the report!

I suppose the spec is misleading but the implementations are correct? (py-ssz is correct)
/cc @protolambda for checking remerkleable

Ideally, maybe rename bitfield_bytes to pack_bits would be more clear.

pack(value): given ordered objects of the same basic type, serialize them, pack them into BYTES_PER_CHUNK-byte chunks, right-pad the last chunk with zero bytes, and return the chunks.
pack_bits(bits): Given the bits of bitlist or bitvector, get bitfield_bytes by packing them in bytes and aligning to the start. Length-delimiting bit for bitlists is excluded. And them pack bitfield_bytes into BYTES_PER_CHUNK-byte chunks, right-pad the last chunk with zero bytes, and return the chunks.

merkleize(pack_bits(value), limit=chunk_count(type)) if value is a bitvector.
mix_in_length(merkleize(pack_bits(value), limit=chunk_count(type)), len(value)) if value is a bitlist.

@protolambda
Copy link
Contributor

Closing this, I think this is solved in #1806

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:SSZ Simple Serialize
Projects
None yet
Development

No branches or pull requests

3 participants