3

This question already has an answer here:

I am trying to make a contract that receives an encrypted signed transaction and stores it for later use. This transaction can only be decrypted if the specified wallet sends a transaction to this contract telling it to forward this signed transaction to its destination.

marked as duplicate by carver, Badr Bellaj Aug 29 '17 at 23:50

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

In short, no.

A smart contract cannot safely hold a private key. Since every contract's code and storage is publically viewable, an attacker can simply read the key.

Any decryption must happen off-chain.

  • I get that but what if one user sends an encrypted signed transaction to the contract and the second user sends the decryption code and the contract matches the two, just like myetherwallet with the JSON files. The contract does not need to know the decryption code. – Mbando Aug 29 '17 at 4:25
  • Yes, that's possible, although it might be gas expensive. There may also be simpler ways of doing that. – Matthew Schmidt Aug 29 '17 at 16:02
  • What do you have in mind? – Mbando Aug 29 '17 at 18:26
  • It would be much easier to simply have the contract record the encrypted transaction, and have the second user read it off the blockchain, decrypt it himself, and then broadcast it himself. You'll save a ton of gas. (Note: contracts cannot send signed transactions as if they came from the signing account, anyway.) – Matthew Schmidt Aug 29 '17 at 22:16
  • So a contract wouldnt be able to trade on etherdelta by forwarding transactions from a wallet to the etherdelta contract? – Mbando Aug 29 '17 at 23:34

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