[Ethereum] Decryption in a smart contract

contract-developmentcryptographyencryption

I have a key pair:

The data is encrypted off-chain:

and it is saved into the following smart contract:

contract Foo {
    string data;
}

Can I decrypt stored data on-chain, assuming I provide a corresponding private key?

function decryptData(string privKey){
    ...
}

Best Answer

I don't think this is possible in the present arrangement.

SK1 would have to be transmitted to the contract, therefore revealed to all verifiers, which is everyone. In any case, that's the hurdle. In summary, if the contract can decode it, then everyone can decode it.

This is the sort of thing that might be possible with a ZKSnarks implementation, as I understand it.

This might be of assistance: Can smart contracts compute on encrypted data?

Hope it helps.

Related Topic