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

Fix #47 #160

Merged
merged 11 commits into from
Dec 30, 2020
Merged

Fix #47 #160

merged 11 commits into from
Dec 30, 2020

Conversation

Pratyush
Copy link
Member

@Pratyush Pratyush commented Dec 30, 2020

Description

closes: #47


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (main)
  • Linked to Github issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

@Pratyush Pratyush marked this pull request as ready for review December 30, 2020 10:56
@Pratyush Pratyush changed the title Work Fix #47 Dec 30, 2020
ff/src/fields/macros.rs Outdated Show resolved Hide resolved
ff/src/fields/macros.rs Outdated Show resolved Hide resolved
serialize/src/flags.rs Outdated Show resolved Hide resolved
@Pratyush
Copy link
Member Author

Upstream tests pass for ark-pallas and ark-vesta!

CHANGELOG.md Outdated Show resolved Hide resolved
serialize/src/flags.rs Show resolved Hide resolved
serialize/src/flags.rs Show resolved Hide resolved
serialize/src/flags.rs Show resolved Hide resolved
serialize/src/flags.rs Show resolved Hide resolved
@ValarDragon
Copy link
Member

I'm generally confused as to why ConstantSerializedSize was removed, that seems like a really useful trait to me.

For this new class of curves, presumably the serialization with flags is still constant sized, its just one byte longer than the serialization without flags?

@Pratyush
Copy link
Member Author

It was removed because the size depends dynamically on the flag used (and we can't do generics in constants yet). For example, if I'm serializing with EdwardsFlags, a 255-bit field will still fit into 32 bytes. However, if I'm serializing with SWFlags, a 255-bit field will fit only into 33 bytes.

@ValarDragon
Copy link
Member

ValarDragon commented Dec 30, 2020

It was removed because the size depends dynamically on the flag used (and we can't do generics in constants yet). For example, if I'm serializing with EdwardsFlags, a 255-bit field will still fit into 32 bytes. However, if I'm serializing with SWFlags, a 255-bit field will fit only into 33 bytes.

I'm a bit confused about the structure of this. Currently it sounds like the field has a method serialize_with_flags, but why is that done versus the following:

  1. Have a method/trait to serialize a field element, and state the exact number of bits used in the serialization. (Basically add serialized_size_bits to CanonicalSerialize)
  2. Have a method that generically takes a Flags object, and a b bit serialized blob, and append the flag bits to it. (Named append_flags or append_metadata)

I'm not seeing why we would want to specialize the appending of flags to fields. Is there an efficiency gain in the current form?

@Pratyush
Copy link
Member Author

Not all objects care about Flags; in fact, only Fields care about them. So it doesn't make sense to add these methods to the CanonicalSerialize trait, which is why we have the CanonicalSerializeWithFlags trait

@ValarDragon
Copy link
Member

The only method that would be added to CanonicalSerialize would be serialized_size_bits (which could even have an auto-impl to just be 8 * serialized_size).

The concept of flags is essentially taking two serializable objects, and concatenating their serializations at the bit-level instead of the byte level. I don't currently understand why we'd prefer the flag trait versus making a serialization method / deserialization method that concatenates object serializations at the bit-boundary, instead of the byte boundary. Maybe we should put this into an issue, and revisit later? A more general method would also enable saving space in serializing many 257 bit field elements

@Pratyush
Copy link
Member Author

Hmm that is interesting, but out of scope for this PR =P

I've filed an issue about it, so that we can revisit it in the future (it might be that the space saving would be blown out by the implementation complexity)

@Pratyush
Copy link
Member Author

@ValarDragon is there anything else you'd like to see changed here?

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for adding more documentation around all of these changes as well

@Pratyush Pratyush merged commit 6292e0c into master Dec 30, 2020
@Pratyush Pratyush deleted the fix-serialize-field-packing branch December 30, 2020 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Correctly handle serialization of curves where BaseField::MODULUS_SIZE = m * 64 - 1
2 participants