1

I'm looking for a way to have private data in an Ethereum smart contract. I explored the ZK space, could work on some scenarios but not totally private. I wanted to ask if you know new tools, sdks etc to make Ethereum smart contracts have private data inside them. Thanks

3
  • 1
    By private data, do you mean (1) the smart contract code is hidden from public view, (2) private metadata whereby the contract is publicly visible, but parameters or attributes assigned in its code are private, or (3) a smart contract that hides its owner's public key (wallet address) and history/occurrence of transfers?
    – user610620
    Commented Dec 9, 2022 at 16:27
  • @user610620 Thanks, I mean private metadata. What I'm trying to achieve is a smart contract on Ethereum (or L2 Ethereum) that has hidden data and by a certain time/date reveals them (or send them to another party with a key)
    – m0j1
    Commented Dec 10, 2022 at 12:26
  • 1
    A recent community call has unveiled that Aztec Network will roll out their private smart contract platform called Aztec 3 in the next 4 weeks or more. Follow them on Twitter.
    – user610620
    Commented Dec 13, 2022 at 4:53

2 Answers 2

1

Zksync 2.0 is now highly compatible and Solidity-friendly in terms of porting smart contracts to zk roll-up applications, but I think a smart contract on the Layer-1 mainnet can never be made fully private unless its source code is made to appear encrypted and uncompile-able in the Etherscan "Contract" tab.

Perhaps zk roll-up privacy layers like Aztec Connect are home to projects that do enable private smart contracts within the Aztec network, not just private transactions, so Layer-2 only, most likely yes

4
  • Thanks very much, I think you're right. Aleo also seems promising but it's L1. But also Aztec doesn't seem to be very mature and I couldn't find good examples and sample codes on using Noir.
    – m0j1
    Commented Dec 9, 2022 at 16:12
  • 1
    Noir, as a programming language, was just born. But Aztec Connect and its zk.money shielding network has no direct competition of its stature and security, not even Aleo.
    – user610620
    Commented Dec 9, 2022 at 16:20
  • Thanks, So for writing private smart contract, I need Noir right?
    – m0j1
    Commented Dec 9, 2022 at 20:43
  • 1
    Please reply to the comment written below your original question up top.
    – user610620
    Commented Dec 10, 2022 at 0:16
1

I don't exactly know how do you want to store the private data. So I assume you want to do it in this way.

You have a an off-chain storage solution for the Ethereum network. The contract uses the SwarmAPI to store and retrieve private data in Swarm, The contract first hashes the data to be stored, and then uses the SwarmAPI to store the data. The contract then returns the data hash, which can be used to retrieve the data from Swarm at a later time.

here is the example code:

pragma solidity ^0.6.0;

import "https://github.com/ethereum/swarm/blob/develop/api/src/api.sol";

// The contract that stores private data
contract PrivateDataStorage {
    // The address of the Swarm API
    SwarmAPI api;

    // The function that stores private data in Swarm
    function storePrivateData(bytes memory data) public {
        // Hash the data to be stored
        bytes32 dataHash = keccak256(data);

        // Store the data in Swarm
        api.store(data);

        // Return the data hash
        return dataHash;
    }

    // The function that retrieves private data from Swarm
    function getPrivateData(bytes32 dataHash) public view returns (bytes memory) {
        // Retrieve the data from Swarm using the data hash
        return api.get(dataHash);
    }
}

This approach allows the contract to store private data off the blockchain, while only storing a hash of the data on the blockchain itself. This ensures that the data remains private, while still providing proof that it exists and has not been tampered with.

But, I don't if it's your want. Maybe you can show more code to have more discussion.

1
  • When you call storePrivateData(...), are you supposed to send the "private" data?
    – Mouradif
    Commented Mar 18, 2023 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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