5

I have a public smart contract where I am able to make a secret and hash it within the contract. I then share the "secret" with N number of my friends and with the secret they can create a new hash (secret + private key) to prove to the contract that they in fact know the secret and have access to send funds.

The contract would only know the secret internal hash + the new sent hash + the msg.sender public key. Would this be enough to prove to the contract that the msg.sender know the secret and is allowed access to the contract functions?

Can't this be done? It sounds like a zero-knowledge proof algorithm, but I am not an expert in cryptography so not sure if it's a viable solution.

  • What is your goal? Allowing only specific addresses to access the contract? – ivicaa Feb 27 '18 at 19:45
  • This question has been asked before (hopefully someone else can find it to mark as duplicate to aid others in finding it); there were some good answers by some of the "usual suspects" so hopefully they can dig it up from their history :) In the meantime, only tangentially related, but perhaps this might be useful: ethereum.stackexchange.com/questions/35692/… – lungj Feb 27 '18 at 19:56
  • 2
    Nothing is private when passing "secrets" around and having the smart contract do the encrypting/decrypting on a public ledger. Every node will have access to what your parameters are passed in as they have to process those transactions to verify the results. – MSwezey Feb 27 '18 at 20:08
  • Also partially related: ethereum.stackexchange.com/questions/13681/… (that also is a duplicate but I think it has more relevant information than the original). Also, more theoretical, but more official: blog.ethereum.org/2016/01/15/privacy-on-the-blockchain – Lauri Peltonen Feb 27 '18 at 21:05
  • I want to be able to restrict access to the contract to people i sent a specific secret or private hash in a forum or other medium. I don´t know before hand how many people could read the forum. Could be 10 could be 100. Keeping track of the addresses is not a good option. The private/public key idea from flygoing sounds like a better option. The secret is not critical that is known/unknown is just a second layer to make the access more selective to people that know of the contract, meaning that to interact with the contract and participate (send ether) you need that "private/secret" invite – demolina Feb 27 '18 at 23:47
4

Since nothing stored in a contract is actually private (any node can access the storage, even "private" variables aren't actually private), this isn't at all secure. A secure way to do this would be to just generate a private key as the "secret" and give that to your friends. You'd then generate the address for the private key and store it on the contract saying it's authenticated. You and your friends can then sign messages with this private key and send them to the contract, and the contract can verify that the message was signed with the private key that relates to the address that it knows.

  • I like this idea, i see that solidity soports ecrecover. I would need to do the exact same thing but only that the private key is not an ethereum private key. Is there anyway to do that? It would be a precreated keypair that the manager of the contract adds to the contract and shares with a specific group of friends. – demolina Feb 27 '18 at 23:49
  • why could you not use an ethereum private key for it? you can register the address to the contract and share the private key. the private key wouldn't be used for anything besides authenticating these calls to the contract – flygoing Feb 27 '18 at 23:50
  • OK, so it would not be the same private key you used for your own accounts or deploying the contract, It should be a brand new one only for that purpose? – demolina Feb 27 '18 at 23:53
  • Oh, of course! Yeah, don't hand out your private key :P Just generate a private key specifically for this. Don't use it to store funds or anything. – flygoing Feb 27 '18 at 23:54
  • 1
    No problem! You can see a similar example me and a colleague wrote here github.com/yarrumretep/PortCoin/blob/master/contracts/…. This contract lets the owner store an address for an event. The owner then signs "tickets" with the private key of the event's address, which we hand out to attendees of the event. We wrote it as a kind of reward for attending our meetups, but it should be a good starting point for your system. The difference would be that you give the private key to your friends to sign their own messages as well. – flygoing Feb 27 '18 at 23:59

Your Answer

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

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