boltlabs-inc / tss-ecdsa

An implementation of a threshold ECDSA signature scheme
Other
11 stars 5 forks source link

Implement `Serialize` and `Deserialize` traits for "Output" types? #525

Open gatoWololo opened 4 months ago

gatoWololo commented 4 months ago

We currently have some "output" types which are the outputs of running our sub-protocols, e.g. keygen::Output and auxinfo::Output. These types do no currently implement the Serialize and Deserialize traits. It is still possible to serialize/deserialize these types.

For example:

/// Output type from key generation, including all parties' public key shares,
/// this party's private key share, and a bit of global randomness.
#[derive(Debug, Clone)]
pub struct Output {
    public_key_shares: Vec<KeySharePublic>,
    private_key_share: KeySharePrivate,
    rid: [u8; 32],
}

This keygen::Output type does not implement Serialize, but the sub-type KeySharePublic does. Meanwhile KeySharePrivate can be serialized by calling the into_bytes method.

While this works, it is quite painful to work with these types. It would be a lot more convenient to implement serialize/deserialize for these types.

It seems not implementing serialize/deserialize was done on purpose for this type. I believe the argument is: Developers should explicitly call the serialize method (into_bytes) as a type of misuse resistance. I don't believe this buys us much though...

gatoWololo commented 4 months ago

@krs85 Since you asked here is an example of a type AuxinfoPrivate which does not implement serialize. Instead there are method into_bytes and try_from_bytes

krs85 commented 4 months ago

Thank you for pointing me to this example. I agree that just implementing serialize is the right way to do it, having these "workarounds" is more confusing than helpful.