-
Notifications
You must be signed in to change notification settings - Fork 242
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
Correctly handle serialization of curves where BaseField::MODULUS_SIZE = m * 64 - 1
#47
Comments
If I understand correctly, the reason for first change is that you want to make the size dependent on the flags? But yes, I think this is a reasonable way to deal with this additional dependency. 👍 |
In general it sounds like a good idea to me! How about the following? |
Yes, the proposed method would mean you cannot use it in constant contexts anymore.
This would probably work as well. Even a bit more complicated calculations could be made as long as they rely on |
We can make this work if we change the trait to be A correct impl for prime fields would be: impl<P: $params, F: Flags> ark_serialize::ConstantSerializedSize<F> for $field<P> {
const SERIALIZED_SIZE: usize = ark_serialize::buffer_byte_size(
P::MODULUS_BITS as usize + F::BIT_SIZE,
);
const UNCOMPRESSED_SIZE: usize = Self::SERIALIZED_SIZE;
} A correct impl for curves would be impl<P: Parameters, F: Flags> ConstantSerializedSize<F> for GroupAffine<P> {
const SERIALIZED_SIZE: usize = <P::BaseField as ConstantSerializedSize<F>>::SERIALIZED_SIZE;
const UNCOMPRESSED_SIZE: usize = <P::BaseField as ConstantSerializedSize>::SERIALIZED_SIZE
+ <P::BaseField as ConstantSerializedSize<EmptyFlags>>::SERIALIZED_SIZE;
} |
You're right, thanks for the correction! |
Hm so changing trait ConstantSerializedSize<F: Flags = EmptyFlags> {
const SERIALIZED_SIZE: usize;
const UNCOMPRESSED_SIZE: usize;
} This is because adding the type parameter (even a defaulted one) makes the trait unusable in trait bounds: either we just keep it the trait bound to be I think we're stuck with using the |
I think we've used it in a constant case, but I'll check and let you know. EDIT: I've checked my uses, and while they could be const, they are used in non-const contexts. So no objection from me at this point. |
Ok thanks! I'll go ahead and implement the non-const version. |
Handle this as follows:
ConstantSerializedSize
trait to use methods instead of constants:ConstantSerializedSize
for all fields to additionally useF::len()
when calculating the number of required bytes, and similarly for elliptic curvescc @therealyingtong; I believe this is the reason why your tests are failing in arkworks-rs/curves#8
also cc @paberr @kobigurk since y'all were involved in the original serialization code; does this strategy seems reasonable?
The text was updated successfully, but these errors were encountered: