ethereum / eth-keys

A common API for Ethereum key operations.
MIT License
159 stars 64 forks source link

Signature.verify_msg requires both return value checking and error handling. #59

Open pipermerriam opened 5 years ago

pipermerriam commented 5 years ago

What was wrong?

https://github.com/ethereum/trinity/pull/586/files#r287599483

Code that wants to verify signatures is required to both do error handling and return value checking when calling Signature.verify_msg due to the function returning a boolean and potentially raising a BadSignature in the event of a corrupt signature.

How can it be fixed?

The naive thing to do is have that method convert BadSignature to a False return but I think that is wrong since it conflates a corrupt signature with a signature that doesn't validate.

This probably needs to be split into a two part check so that the two concepts remain distinct, allowing the user to check if the signature itself is valid in isolation and then to check if it is a valid signature for a message.