fuel-crypto icon indicating copy to clipboard operation
fuel-crypto copied to clipboard

Use native verify

Open vlopes11 opened this issue 3 years ago • 1 comments

To simplify the initial implementation, we are using a plain recover for the verify operation.

However, recover is more expensive than verify. After https://github.com/FuelLabs/fuel-crypto/issues/3 , we should compare the performance gain of using native verify instead of recover, pk == pk_p

The pseudocode for the native verify with secp256k1 backend is:

        pub fn verify(mut self, pk: &PublicKey, message: &Message) -> Result<(), Error> {
            self.truncate_recovery_id();

            let signature = Secp256k1Signature::from_compact(self.as_ref())?;

            let message = message.to_secp();
            let pk = pk.to_secp()?;

            Secp256k1::verification_only().verify(&message, &signature, &pk)?;

            Ok(())
        }

vlopes11 avatar Feb 04 '22 17:02 vlopes11

From bench results, verify will be ~10% faster if we opt for native approach

vlopes11 avatar Apr 07 '22 22:04 vlopes11