privacy-scaling-explorations / sonobe

Experimental folding schemes library
https://privacy-scaling-explorations.github.io/sonobe-docs/
MIT License
205 stars 54 forks source link

Add serde capabilites to `Nova` #107

Closed dmpierre closed 5 months ago

dmpierre commented 6 months ago

This PR aims to add serialization and deserialization capabilities to Nova.

For serialization, we derive the CanonicalSerialize trait for most of the fields of struct Nova. Two notable exceptions are:

  1. For KZG::ProverKey, where we implement the trait without deriving it. This is required since powers_of_g consists in a type which is does not support arkworks serialization by default.
  2. PoseidonParams, since we can not implement an external trait to an external struct (both PoseidonParams and PoseidonParams are imported from arkworks).

For deserialization, we could not implement the CanonicalDeserialize trait on Nova. CanonicalDeserialize requires types to be deserialized to satisfy the Valid trait, itself requiring types to satisfy Sync + Sized. Since, CurveVar does not implement Sync, we had to resort to not implement CanonicalDeserialize.

We eventually include all of struct Nova fields at serialization time. When deserializing, users do not have to worry about providing back all of the correct auxiliary configs (r1cs, pcs, hash function, ...).