zcash / pasta_curves

Rust implementation for zcash/pasta
Other
80 stars 49 forks source link

Consider implementing (de)serialization for base types (Fp, Fq) #77

Open bazzilic opened 1 year ago

bazzilic commented 1 year ago

It is quite typical, at least in my experience, for code using pasta_curves crate to have the necessity to persist or transfer structs with fields of types Fp and Fq, which requires (de)serialization.

As Rust doesn't allow implementing traits for imported structs, we have to manually write (de)serializers for every struct that contains Fp or Fq fields instead of being able to just do a simple #[derive].

Would you consider adding serialization impl's to these types? At least for some popular serialization libraries such as serde and borsh. The implementations could be behind a feature flag. The change, I believe, would be as much as adding a #[derive(Serialize,Deserialize,BorshSerialize,BorshDeserialize)] to the struct declaration.

I can do a PR, if you prefer.

bazzilic commented 1 year ago

I don't know why it took me so long to realize that pasta_curves actually does have a serde feature. Is there a reason why you implement ser/de functions manually instead of deriving them? And do you think it would be possible to also add impl's for borsh? It seems to gain quite a popularity in crypto space.