Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev43 committed Sep 18, 2022
1 parent 6eb4a5d commit addfaa9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 21 deletions.
63 changes: 45 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
# Harpocrates
# 🤐 Harpocrates 🙊

![Harpocrates](harpocrates.jpg)

> Harpocrates (Ancient Greek: Ἁρποκράτης) was the god of silence, secrets and confidentiality in the Hellenistic religion developed in Ptolemaic Alexandria (and also an embodiment of hope, according to Plutarch).
## Description

Harpocrates is a proof of concept of using a Fully Homomorphic Encryption scheme in a decentralized way.
Harpocrates is a POC providing a Permanent Fully Homomorphic Encryption (FHE) smart contract on Arweave.

This is done using Nucypher's/[SunscreenTech](https://github.com/Sunscreen-tech/Sunscreen) sunscreen compiler, an easy to use FHE compiler that currently only uses the BFV scheme.
The backend is the permanent data storage [Arweave](https://arweave.org).
This is done using [Nucypher](https://github.com/nucypher/)'s/[SunscreenTech](https://github.com/Sunscreen-tech/Sunscreen) sunscreen compiler, an easy to use FHE compiler that currently only uses the [BFV scheme](https://inferati.com/blog/fhe-schemes-bfv) (Brakerski-Fan-Vercauteren).
The backend is the permanent decentralized data storage open to all [Arweave](https://arweave.org).
The ZK circuits are built using [Circom](https://github.com/iden3/circom) and compiled using [`snarkjs`](https://github.com/iden3/snarkjs).
And the connection to a private key store is done using [WalletConnect](https://github.com/WalletConnect)

## Warning
## Why should I care?

Fully Homomorphic Encryption allows you to keep your data private, which was never possible before. To be able to get analytics on your data, you would usually be required to decrypt it from you database, send it to a third party so they can crunch the numbers and get it back to you. This means that to gain insight into your own data, you have to give it **all** away. With FHE, you don't have to, these same insights can be gotten while never ever revealing the inputs (and even the output!).

This allows you to do multi-party computation, identity management, private database lookups, games with full privacy and more!

By mixing the FHE and decentralized open systems, we have a system that can't be stopped AND cannot be snooped on!

## ☢️☢️☢️⛔ ⛔ ⛔ ⚠️⚠️⚠️Warning⚠️⚠️⚠️⛔ ⛔ ⛔ ☢️☢️☢️

This repo is a POC, not meant to be in production. Use at your own risks.

## Motivation

Privacy is a human right.
**Privacy is a human right.**

Technology can be a double edge sword. It has made us extremely productive and inventive. It connects us like nothing else before. But this convenience and power can be used nefariously. We tend to forget that not so long ago, it was easy to be private. You would pay in cash, GPS didn't exist, cellphones less so. All these technologies degrade our option to be private. It's time to harness technology to swing the pendulum the other way.
Technology can be a double edge sword. It has made us extremely productive and inventive. It connects us like nothing else before. But this convenience and power can be used nefariously. We tend to forget that not so long ago, it was easy to be private. You would pay in cash, GPS didn't exist, cellphones even less so. All these technologies degrade our **option** to be private. You don't have to be private all the time, but you should have the option to at anytime. It's time to harness technology to swing the pendulum back the other way.

I strongly identify with statement from Eric Hughes:

Expand All @@ -39,13 +47,15 @@ Make sure you have [`snarkjs`](https://github.com/iden3/snarkjs) installed.

To run this, first run `make` in the root of the project. This download the necessary dependencies and also set you up to be able to create and verify Zkproofs :).

Now, if you want this to be deployed to Arweave, you will need to have an arweave-keyfile with some AR on it. You can get a pre-funded one [here](https://faucet.arweave.net/). Make sure to have the keyfile in the `fhe_contract` repository with the name `arweave-keyfile.json`.
Now, if you want this to be deployed to Arweave, you will need to have an arweave keyfile with some AR on it. You can get a pre-funded one [here](https://faucet.arweave.net/). Make sure to have the keyfile in the `fhe_contract` repository with the name `arweave-keyfile.json`.

Now all you have to do is go into the fhe_contract repository `fhe_contract` and run `cargo run -- run-all`. From there, just follow the necessary prompts!

More info can be found by running `cargo run -- --help`

```bash
POC providing a Permanent Fully Homomorphic Encryption smart contract on Arweave.

USAGE:
fhe_contract [SUBCOMMAND]

Expand All @@ -54,16 +64,16 @@ OPTIONS:
-V, --version Print version information

SUBCOMMANDS:
compute-latest
create-new-user
deploy
fetch-latest
fetch-zk
compute-latest computes the result of all the FHE transactions
create-new-user creates the keys for a new user
deploy deploys the FHE contract to Arweave
fetch-latest fetches the latest transactions and saves them in the cache
fetch-zk fetches the latest zk params and saves it in the cache
help Print this message or the help of the given subcommand(s)
init-state
init-zk-proof
run-all
vote
init-state initializes the state of our contract
init-zk-proof deploys all the information needed for ZKsnark to arweave
run-all runs all the interactions in the correct order, also is interactive
vote create and deploys a vote on the user's preferred proposition
```
## TODO
Expand All @@ -87,6 +97,23 @@ SUBCOMMANDS:
### Stretch

- [x] Integrate WalletConnect
- [ ] Integrate Pinata

### Limitations

Here are the limitations encountered in the project

1. FHE is still very new. There aren't a lot of production grade libraries out there, and if they are they are extremely complex and easy to make a mistake. Thanks efforts like Nucypher's Sunscreen, it makes it easier for developers to use.

2. The current FHE scheme involved here cannot do (yet) an infinite amount of computation (at least using this library). The more computations happen, the more noise gets introduced into the ciphertext. When the noise gets too much, it is impossible to decrypt. There are techniques to go around this, but for now you are limited in the number of computations possible. Also, the current scheme doesn't allow for comparisons, which reduces the scope of possible actions.
3. In its current form in our application, the admin (the creator) of the vote can decrypt all of the votes. This is less than ideal, and could even be dangerous. One can kind of go around this by combining 2 or more (n) people's votes together and then deploying the txn to Arweave. There would have to be proofs that the n votes are valid.

4. The current way this project is done, the "voter apathy" problem is still not solved. This can be solved with Multi-key Fully Homomorphic Encryption (MKFHE) as we will discuss later.

5. The current scheme does not give a guarantee that what was passed as input to create the Zkproof is the same as what was encrypted. There is research that show a possibility for those proofs to [exists](https://eprint.iacr.org/2019/057.pdf) (in the BFV scheme and others!)

### Future possibilities

The advent of [Multi-key Fully Homomorphic Encryption](https://eprint.iacr.org/2021/1131.pdf) (MKFHE) can be a game changer. In MKFHE, every participant can encrypt their data using their key and then do calculations on this encrypted data that was created with different keys. There would then need to be a decryption phase of the result at the end, without ever needing to divulge the input to anyone else. This would remove the voter apathy, and not allow any of the users to know who voted for who.

The possibility of having proofs about the validity of the encrypted data as in [here](https://eprint.iacr.org/2019/057.pdf) will also be a game changer, as now one can be sure that the others are playing by the same rules.
20 changes: 18 additions & 2 deletions fhe_contract/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,49 @@ use std::io::prelude::*;
use std::os::unix::prelude::PermissionsExt;
/// Search for a pattern in a file and display the lines that contain it.
#[derive(Parser, Debug)]
#[clap(author="Dev43",name="harpocrates", version="0.0.1", about = Some("Tool to vote using FHE and ZKSnarks"), long_about = None)]
#[clap(author="Dev43",name="harpocrates", version="0.0.1", about = Some("POC providing a Permanent Fully Homomorphic Encryption smart contract on Arweave."), long_about = None)]
struct Cli {
#[clap(subcommand)]
command: Option<Commands>,
}

#[derive(Subcommand, Debug)]
enum Commands {
#[clap(about = "creates the keys for a new user")]
CreateNewUser {},
#[clap(about = "deploys the FHE contract to Arweave")]
Deploy {},
#[clap(about = "deploys all the information needed for ZKsnark to arweave")]
InitZkProof {
#[clap(value_parser)]
contract_id: String,
},
#[clap(about = "initializes the state of our contract")]
InitState {
#[clap(value_parser)]
contract_id: String,
},
#[clap(about = "fetches the latest transactions and saves them in the cache")]
FetchLatest {
#[clap(value_parser)]
contract_id: String,
},
#[clap(about = "fetches the latest zk params and saves it in the cache")]
FetchZk {
#[clap(value_parser)]
contract_id: String,
},
#[clap(about = "computes the result of all the FHE transactions")]
ComputeLatest {},
#[clap(about = "create and deploys a vote on the user's preferred proposition")]
Vote {
#[clap(value_parser)]
contract_id: String,

#[clap(value_parser)]
number: usize,
},
#[clap(about = "runs all the interactions in the correct order, also is interactive")]
RunAll {},
}

Expand Down Expand Up @@ -428,8 +437,15 @@ async fn vote(id: &String, index: &usize) -> Result<(), Box<dyn std::error::Erro

pub async fn run() -> Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();

println!();
println!();
println!();
println!();
println!("{}", ascii::HARPOCRATES);
println!();
println!();
println!();
println!();

let _ = match &cli.command {
Some(Commands::CreateNewUser {}) => create_new_user(),
Expand Down
2 changes: 1 addition & 1 deletion fhe_contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mod tests {
&counter_pk,
)?;

let c: [Signed; 10] = runtime.decrypt(&first_result[0], &counter_sk)?;
// let c: [Signed; 10] = runtime.decrypt(&first_result[0], &counter_sk)?;
// intermediate result

// now bob votes
Expand Down

0 comments on commit addfaa9

Please sign in to comment.