Let's say that I want to generate a key such that a user can use it and at the same time save the hashed key on the blockchain. My idea was to use a smart contract that could implement the Diffie-Hellman encryption. In this way the recipient would have the original key and the smart contract could calculate the hash of the key and store it. Is this a viable solution? What are other ways to achieve this?

  • What is the application of such a scheme? Sending private messages over the blockchain? Why does the smart contract need to store the hash of the key, how is it gonna be used? – medvedev1088 Feb 8 '18 at 17:17
  • @medvedev1088 The key can be considered as a ticket to a music concert that the user buys. Then when the user tries to access the concert it will provide the key and a smart contract will compared it with the stored hash to verify if the key is legit. – David Feb 8 '18 at 17:27
  • beware of the fact that everything on the chain is publicly visible and frontrunning is an issue: I see you submitting a valid ticket but inject your payload into a tx coming from me. Direct analogy: I take a screenshot of your ticket, jump in the queue to the concert ahead of you, get in and you stay out. – Validity Labs - Sebastian Feb 9 '18 at 8:27
  • @ValidityLabs-Sebastian let's say that the key of the user is on the blockchain encrypted with the user's public key. On the chain there is also the hash of the key. This guarantees that only the user can access its key. Now to check if a key is valid the user calls a smart contract which input is the key in plain text. The smart contract calculates the hash and compares it with the one saved. Are you saying that when I call the smart contract someone could steal my key, generate a new tx to get it validated and then this user could jump in front of me if its tx is validated before mine? – David Feb 9 '18 at 13:40
  • Yes precisely that. There are more advanced ways of going about it by doing a two-step approach: first commit a hash of secret and sender address (hashing happens off-chain!), then you reveal the secret (the sender cannot be spoofed), on-chain calculated hash of secret and sender has to match. This would be a secure way to reveal a secret on chain but it takes two transactions. – Validity Labs - Sebastian Feb 9 '18 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.