6

This question already has an answer here:

I know about the general open / trustless protocol of storing transactions. How would I approach a scenario here where I want to store some data in a contract on deployment, to later be retrieved by someone unknown at the time of deployment?

The main problem here is that the receiver of the secret data is not known in advance / when providing the secret data. Therefore simply encrypting the data with buyers public key is not a valid approach

E.g. I have a contract which stores secret number and other users can interact with the Dapp and bid on these numbers, only the highest bidder shall receive the true secret number in the end.

marked as duplicate by niksmac, Waqar Lim Mar 31 '17 at 13:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    EDIT: Different but related question ethereum.stackexchange.com/questions/2624/… – eth Mar 29 '17 at 10:10
  • It is partially answered by the linked question, although the linked question assumes that you know the receiver beforehand, which is not the case in this scenario. Shall I clarify and reopen, or add a comment to the other question? – floAr Mar 29 '17 at 10:22
  • I think with the clarification this is a sufficiently different question. – Tjaden Hess Mar 29 '17 at 18:47
  • Also, does the contract have to do this all on its own, or can the deployer just encrypt the number with the bidder's public key after the bidding is over? – Tjaden Hess Mar 29 '17 at 18:53
  • This is of course a possible solution, but I would love to have everything as autonomous as possible. If the dev encrypts the value afterwards the buyer needs to trust the dev. Having the contract holding the data from the beginning would allow the whole thing to be trustless, basically removing the possibility of the dev taking all the ether and not giving out the data – floAr Mar 30 '17 at 9:01
2

There is no complete way of doing this. One approach you could look at is:

You could commit to the secret in advance (by having the contract hold a hash of the secret). When you know the recipient you could send them the secret encrypted with their public key, which they can then decrypt and check matches the earlier committed hash. Nothing forces you to do this, but at least you can't change your mind on what the secret was after the fact. NB - nothing forces you to actually reveal the secret though.

You could come up with a variation on the above involving one or both parties putting up stakes that are only refunded on a successful outcome / conclusion, but this wouldn't solve the underlying problem entirely.

There are some research / development efforts going on in this area (including homomorphic encryption) and Hawk) but nothing that seems even close to being ready for primetime.

My view is that these types of functionality will be part of web 4.0 ;-)

Hope this helps!

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