fuel-crypto
fuel-crypto copied to clipboard
Use native verify
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(())
}
From bench results, verify
will be ~10% faster if we opt for native approach