2

I want to create a contract function that will decrypt and return a value given a password (or key) - but only after a certain date.

e.g. outside the blockchain I encrypt the value "ABCDEF" and store the encrypted result "1fa329" in a contract on the blockchain:

storeEncryptedValue("1fa329')

After the year 2020 anyone can call a function providing they know the password (key) like this:

revealTheValue('my-password')

This function will throw if the date is not > 2020-01-01.

Does solidity have a decrypt function?

Obviously once somebody has called revealTheValue(...) function the password is visible to the world, but that is not a concern in this use case.

2

Ethereum can't keep secrets, as everything on the blockchain is public. You can store the encrypted value on the blockchain, but whoever has the decryption key will be able to decrypt it without waiting for the function on the blockchain to say that it should be decrypted.

One place where Ethereum may be useful here is in incentivizing the behaviour of whoever has the encryption key; You could make a contract that would pay them if they reveal the key after the time when it was supposed to be revealed, and/or withhold a bond that you get them to supply if anyone is able to send the contract the key or the plaintext before the time when it was supposed to be decrypted.

  • 1
    Thanks, I'll think about an ENS newBid() / unsealBid() solution with a salt and incorporate the date in the internal sha3() seal check. – mkaj Jun 6 '17 at 2:02
1

I'm working on a code where I'm facing a very similar challenge. My first pass solution is to use a third party service - Oraclize, with their decrypt "datasource".

  1. The client side encrypts the data using oraclize public key (they have a public API for that)
  2. Client sends encrypted data to contract
  3. Contract schedules an oraclize query callback to reveal: queryId = oraclize_query( timeInSeconds, "decrypt", encryptedData, gasLimitForCallback )
  4. Oraclize calls back contract's __callback(bytes32 queryId, string result) function with decrypted data

Oraclize's documentation is not perfect but devs on Oraclize's gitter channel are very helpful.

This first pass solution is not ideal for multiple reasons but we couldn't figure out a properly decentralised way yet.

A potential trustless alternative would be to use a process similar to the the ens bidding:

  1. client generates keypair
  2. client encrypts and sends the encrypted data to contract
  3. when it should be revealed client sends its private key to contract
  4. contract decrypts

With this method, there is no 3rd party trust required but the drawback that it requires user interaction to reveal the secret.

0

1-concerning the date you could use now and the timestamp of the target date 2020-01-01 in your case (there is many converters online to help you).

so to trigger something in the future you could use :

if(now<=1577750399) // 1577750399 is the timestamp for 31/12/2019
 throw;

now returns the timestamp of the block in which the transaction was included (kind of current time).

2-solidity can't decrypte your cyphertext.

  • But one can write a decrypting function which will decrypt the cypher text – Igor Barinov Jun 5 '17 at 23:55
  • so then why to decrypt if the decryption's function is public?? – Badr Bellaj Jun 5 '17 at 23:57
  • There is no secret on chain in this scheme. This process can be a part of a complex process with multiple smart contracts. Also it can be in Quorum like-environment with access levels and cryptographically enforced visibility – Igor Barinov Jun 6 '17 at 0:00
  • Sometimes people just say.. you can't do this, this is not possible and I think we shows elaborate more on possibilities:) – Igor Barinov Jun 6 '17 at 0:01
  • because you are in ethereum stackexchange then we suppose you are asking about ethereum not about a fork or a based project – Badr Bellaj Jun 6 '17 at 0:14

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.