mintlayer / core

Mintlayer Core
https://www.mintlayer.org/
MIT License
14 stars 4 forks source link

Witness signature should be versioned with the signature algorithm #131

Open TheQuantumPhysicist opened 2 years ago

TheQuantumPhysicist commented 2 years ago

Looking at this code from utxo/lib.src:

        pub fn sign(
            mut self,
            utxos: &[TransactionOutput<AccountId>],
            index: usize,
            pk: &sr25519::Public,
        ) -> Option<Self> {
            let msg = crate::sign::TransactionSigMsg::construct(
                Default::default(),
                &self,
                utxos,
                index as u64,
                u32::MAX,
            );
            self.inputs[index].witness =
                crypto::sr25519_sign(SR25519, pk, &msg.encode())?.0.to_vec();
            Some(self)
        }

And given that we may use a different signature algorithm in the future, it may be wise to use a serialization mechanism that can detect the signature algorithm. A simple way of doing this is: Instead of using Vec as type for the witness, we use an enum that has SR25519 as one arm with Vec as underlying type, and we just support adding more in the future. Scalecodec can take care of the serialization.

PS: Whether we're gonna remove the witness from inputs is a different discussion.

iljakuklic commented 2 years ago

Either this or spare ourselves an extra byte by allocating a new Destination enum arm to new signature schemes. E.g. rename Destination::Pubkey to Destination::PubkeySchnorr, eventually add Destination::PubkeyBLS, etc. Signatures inside scripts already have sig type tags as proposed here (at expense of a 1-byte overhead).