How to simply create Ethereum private contracts that remains enforceable on-chain
Disclaimer: The code below is not safe. It’s a simple proof of concept. Do not use it in production.
The basic principle behind this is relatively simple. It’s the same that is used for payment/state channels:
2 participants lock funds into a contract that incentivize cooperation, but instead of signing proof-messages to exchange funds, participants sign a contract bytecode that they keep private.
If participants cooperate the contract is never revealed to any other party. Otherwise the contract must be revealed to be settled.
The contract where the funds are locked just need to be capable of deploying a contract signed by both participants and transfer his own balance to it.
Let’s take a very simple scenario where Alice and Bob want to bet on the price of Ethereum at a later date, but don’t want the world to know what they are betting on.
The terms of this bet are the following: If the price of Ethereum is over $1200 at the specified date Alice will pay Bob 10 ethers, if not Bob will pay Alice 10 ethers.
This terms will be represented by the following smart contract:
Both Alice and Bob will compile this smart contract, sign the resulting bytecode and share it with each other.
Once this is done one of them will deploy a PrivateContractEnforcer.
This PrivateContractEnforcer incentivize cooperation between participants by refunding a portion of his bet to the looser when he voluntary release the funds.
Private contract enforcer aka Privacy judge
This is a very simple implementation of this concept using the OpenZeppelin lib:
Both of participants will need to verify the deployed code before sending money to it.
Once the result of the bet is clear the looser can willingly pay the winner and get is collateral back or force the winner to reveal the contract to collect his winnings and the looser collateral as punishment for not cooperating.
Building on that concept
This same concept can be used in combination with payment/state channels to allow multiple private contracts to be independently settled between the 2 participants.
I like to thanks, Jorge from the Aragon team for his great article that got me thinking about this concept and insights he provided on dynamic contract deployment https://blog.aragon.one/advanced-solidity-code-deployment-techniques-dc032665f434