We forked Bacalhau and Lilypad to support off-chain privacy-preserving computation via Intel SGX enclaves.
We implemented off-chain privacy-preserving computation in a way that ultimately should be compatible with any blockchain with a custom smart contract oracle. This has wide implications for any Dapp, for example: - The smart contract can call off-chain code to perform some action off-chain (e.g. execute a trade with my secret API keys) - The smart contract can receive data from an oracle after computing on private data (e.g. determine credit-worthiness from private data)
We implemented off-chain privacy-preserving computation. This was completed by modifying Bacalhau and Lilypad. We then demo how this is used in an NFT generator Dapp.
We deployed our fork of Lilypad and the Dapp to hyperspace, which communicates with our custom Bacalhau node.
We implemented off-chain privacy-preserving computation in a way that ultimately should be compatible with any blockchain with a custom smart contract oracle. This has wide implications for any Dapp, for example: - The smart contract can call off-chain code to perform some action off-chain (e.g. execute a trade with my secret API keys) - The smart contract can receive data from an oracle after computing on private data (e.g. determine credit-worthiness from private data)
THE WHY
Privacy-preserving off-chain compute, especially when paired with a smart contract oracle, can be an incredibly flexible and powerful tool for developers. In this hackathon demo, we show one such application.
Digital generative artists today sell runs of their digital art. However, they must either do it on their own computer, or pay for centralized servers to run the art. Running their algorithms on public decentralized off-chain compute networks like Bacalhau don't work because the artists often want to keep their generative algorithms secret. Further, the artist may be integrating private data from the customer/user. Privacy-preserving off-chain compute can help artists securely offload the task of generating art and minting NFTs to a decentralized network.
In the future, privacy-preserving off-chain compute can serve a number of other use cases where developers and/or users may want to store and compute over secret data, including
Smart contracts trigger off-chain trades with centralized exchanges using secret API keys
Off-chain jobs run on secret user data (e.g. raw banking data) and store results on-chain (e.g. whether it is safe to lend to this user)
THE SOLUTION
This hackathon project comprises of 2 major components:
1. Privacy-preserving off-chain compute
We forked Bacalhau (https://github.com/bacalhau-project/bacalhau), an off-chain decentralized computation network, to support a new type of resource, trusted execution environments (TEE). We then added a new executor that will allow jobs to run inside an Intel SGX enclave for security and privacy. We also forked Lilypad (https://github.com/bacalhau-project/lilypad), a smart contract oracle, to be able to dispatch jobs and store results on-chain.
2. NFTrout Dapp
The NFTrout Dapp consists of a frontend UI/UX and a set of smart contracts that will mint new NFTs. The NFT minter dispatches an off-chain privacy-preserving compute job to generate the art and return an IPFS CID for the NFT.
We started with no prior code. The nfttrout monorepo and any modifications to Bacalhau and Lilypad were done during the hackathon week.
HOW IT WORKS
1. Privacy-preserving off-chain compute
We added a new type of rsource ("TEE") and a new executor to Bacalhau to run python scripts in an Intel SGX enclave wit the help of Gramine.
2. NFTrout Dapp user flow:
- The artist compiles, encrypts, and uploads their proprietary generative art algorithm into IPFS / Bacalhau.
- The user visits the website and mints a new NFT.
- This triggers a mint call on the smart contract.
- The smart contract uses the Lilypad oracle (https://github.com/bacalhau-project/lilypad) to dispatch a job to generate a new "run" of generative art.
- The resulting art is stored on IPFS and the CID is relayed back to the smart contract to store in the NFT metadata.
- The mint completes and is transferred to the user.