0

Assume a scenario where we want to send digital signatures to a smart contract.

  1. A user will sign a message with his/her private key and use the signature as input when triggering a smart contract.

  2. A function in the smart contract will then use the sender's public key to decrypt the digital signature and compare it a stored value. (For simplicity, assume we are not concerned with replay attacks.)

Is there any way to do this using Solidity? Are there any known libraries that can be used?

There is an ecrecover function which returns the signing address of a signed message. However, this does not return the message itself. The only use of this function is to make sure all the message sent are signed by the same sender. This is discussed nicely here: ecrecover from Geth and web3.eth.sign

1
  • 3
    You could theoretically do this, but I'm not sure I understand the point. Why not just send the (unencrypted) message along with a signature? Then check the signature with ecrecover.
    – user19510
    Jun 5, 2018 at 18:50

1 Answer 1

1

There is no decryption of that nature on a smart contract. You can essentially make encryption and/or decryption methods on the smart contract "if you really desired to", but then you'd end up with a smart contract that can basically decrypt encryption itself publically.

As for the signature, it was actually important, security-wise, that the message itself could not be recovered but the signature conversion verified the sender's public address.

Your Answer

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

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