zkcrypto / bls12_381

Implementation of the BLS12-381 pairing-friendly elliptic curve group
Other
304 stars 178 forks source link

Implement gate-featured serde for exported structures #38

Closed CPerezz closed 4 years ago

CPerezz commented 4 years ago

A few weeks ago, I needed serde implementations for the types that this library exports, so I coded them on our fork: https://github.com/dusk-network/bls12_381

Then I saw the suggestion raised in #35 by @hdevalence and thought that it would be nice to convert our impl to a feature-gated behind a serde feature.

So I modified our impl according to the gate-feature suggestion and made the PR.

Adds serde impl for:

All the implementations will make the deserialization fail if any of the items is not canonically-encoded.

Appart from that, I think that implement Write and Read for these types would be also nice, since sometimes, you just want to move the point structures as bytes but without doing any compresions/decompressions, having them "serialized" as bytes (which would be much more performant). See: https://github.com/dusk-network/plonk/issues/190 where a Proof takes a considerable amount of time to be deserialized just because we call decompression for each point we store on it computing the security checks.

I added the serde feature to the default features group, but feel free to remove it from there since Idk if everyone will want the feature enabled by default.

narodnik commented 4 years ago

You should add Scalar serialization as well