say a user has an external public key (unrelated to ethereum address). they use the private key associated with this public key to sign sha3(message) via ECDSA. the message, public key and signature are submitted to a contract. is there a simple way to use solidity to verify the signature? ecrecover returns an address.

i've tried to look for an answer to this but it seems like prior applications have been verifying signatures of ethereum addresses with ecrecover.

EDIT: i suppose i could convert the public key to an address using the following steps (from Steve Waldman):

1.Start with the public key bytes (a bytestring of length 64)

2.Of that public key, take the Keccak-256 hash used ubiquitously by Ethereum (make sure you get that right, as the ultimately standardized SHA3-256 hash differs). You should now have a bytestring of length 32.

3.Drop the first 12 bytes. You should now have a bytestring of length 20, the Ethereum address associated with your public key.

would it be functional to convert the external public key to an ethereum address with solidity then check that address against the result of ecrecover() to determine if the signature is valid?

1 Answer 1


Since you mention it's an ECDSA key, I assume you're talking about using the same crypto that Ethereum uses for signatures. If you want to do this in Solidity, the simplest and most efficient thing will still be to use ecrecover.

As you say ecrecover returns an address, not a public key. But an Ethereum address is derived from the public key, so if you want to check the signed data was signed with a given public key inside the contract, you can recreate the address from the public key, then use ecrecover to get the address, and make sure they match. This answer tells you how you could derive an address from a public key in Solidity: https://ethereum.stackexchange.com/a/15190/774

However, addresses are shorter and easier to handle than public keys, so this derivation is more commonly done outside solidity, with a design that only requires the contracts to manage addresses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.