Grants Program: Faceless

This repository contains code and resources for the Faceless program.

All Steps to Build and Start the Faceless Substrate Node

Macos

# Install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew --version

brew update
brew install openssl
brew install cmake clang

# Install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
rustup default stable
rustup update
rustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup target add wasm32-unknown-unknown

# Build faceless substrate node
cd faceless-substrate-node
cargo build --release

# Run the node
./target/release/faceless-node --dev --ws-external

Crypto Implementation

Anonymous Identity-Based Encryption

An implementation of a variant of the following scheme:

  • Dan Boneh and Matthew K. Franklin. Identity-based encryption from the weil

pairing. SIAM J. Comput., 32(3):586–615, 2003.

Implemented here.

BN254 Curve (alt_bn128)

An implementation of the alt_bn128 curve that is almost the same as the zeropool-bn repository, but with some fixes to be applicable in our faceless protocol.

BulletProof

An implementation of the BulletProof zero-knowledge protocol based on BN254 curve.

Substrate Implementation

Build and Run Instruction

Environment setup

# Install Rust
curl --tlsv1.2 https://sh.rustup.rs -sSf | sh

Unit tests

# Test the anonymous identity-based encryption
cd aibe
cargo test test_bf_ibe -- --show-output

# Test the burn proof generation and verification 
cd aibe
cargo test test_zk_burn -- --show-output

# Test the transfer proof generation and verification
cargo test test_zk_transfer -- --show-output

Docker

If you prefer to run in a Docker environment, first install Docker before moving on.

Build docker image

docker build -t faceless .

Start a docker container

docker run -it faceless /bin/bash

Run tests

Inside the container, we can try the following tests:

# Test the anonymous identity-based encryption
cd aibe
cargo test test_bf_ibe -- --show-output

# Test the burn proof generation and verification 
cd aibe
cargo test test_zk_burn -- --show-output

# Test the transfer proof generation and verification
cargo test test_zk_transfer -- --show-output

NOTE: The pallet functions are intended for DApp usage. They require some global chain configuration and input construction which are difficult to carry out in unit tests. So we recommend to read the Tutorial section for usage.

Benchmark

We give a benchmark of the implemented identity-based encryption scheme below. Experiments are performed on a Macbook Pro with 2.5 GHz Dual-Core Intel Core i7. All tests are run in a single thread. We run the experiments for vectors of length 1, 5, 10, and 20.

AIBE Time
Keygen 6.35 ms
Extract 51.82 ms
Encrypt 236.25 ms
Decrypt 185.11 ms

We also give a benchmark of the 4 critical functions in Faceless, implemented in the faceless pallet.

Functionalities Time
Register 35 ms
Deposit 46 ms
Withdraw 52 ms
Transfer 55 ms

Tutorial

You can find usage of all public modules in tests/. We give further guides here.

Zero Knowledge Proof Generation and Verification

We provide generation of zero knowledge proof of burn and transfer operations. The burn and transfer proof generation can be found in aibe/src/bin/burn_example.rs and aibe/src/bin/transfer_example.rs.

Burn/Transfer Proof Generation

cd aibe
cargo run --bin burn_example

Suppose it outputs a burn proof and statement:

Burn proof:
fiLanOsnhXJJt3Fn72lDyG6IotTPBbs5b3S/W7g6zytpka1rHfao/xWZOA4YA2Y4UCJxbhehIaIG9SGe17NGCYctkayIkb4GXhW+CP3NkVea9BI2A8/izOggGVykl5IhLhhO1gNTgLfrruKol6OLTONymVWVUIwIO83zcjXmog8ggjF3j8yAJ4aJhrhn5B2kMnWP7W9MoG2F7ogk2qbaAw+CtiDIUD5mFIv7Lh0f+YnjlSWAfc5a5wTRwwTeWXIE8aoM+yXX0D/b/S1Bn95LtwHp31Ttmlbv6SBMIrTjxQJyYo6A9c8BzQ46kWw+QAwA9AhKH+29C0Fw1tbqmmVxCTB43/4Zk+3pNUqFxE/R0gii2rTzxUvg+kdlQ4YtZ8Eik6ZXrOwAQRVYIBhAgJE4tyvXakCKnUqCk3MM5rM1rRvr5KgM2pB2yHYaRFzuvjqBE8ndrmkPPVDJUmE6VHSILg==
Burn statement:
cMd+Y7scymUSNJ6aiJCwSxFEQq9yCOFq1XZId4jR7C+TYGaVVL93ylyK6xH7cCGYcX0ZA6HUrzDPvTI+U0ZJAkMP/EGzL175WTUf2iuo0jc2gw3jNwzliZWmytIQCDIZiyBAa8pS1E9N2SuBgwOUDXt+7eo+3DCvWI5hW+9jQQCZOjDmxJKuTZaoVo9eCMiXxihtQBOzElt3rQ35cO4pAe8SQKNaJRHfRv9xMXXgpDZ6vu3DjmCx2u2uhlvr3kcOjyagQ5w3fNoqsWxO8tpZkrF2Q2DO7rLOsZuSPunuqyjSa3I2Sb42WyLtG34laLGUmPb2rELNZmUaxYARXwKpG5Vgdx56guZ0EXec1RMEN98nMwQZ49sEOUJv4H816OsRNAHlCdNuiMil0i03wP4vPLfw5ytHIjw6+/5uCUlNSgJ57kjxM38ncsT15qosm3xJiQK1nZQlRZrLMfbzw19qHuq4g5Db+yCIr6WGyWmmHlNAguERoZ6S3yP0hbETOtIqVKatFiI60zlzySRuz0xvJ+1yCervsnZScvHDgeiK8xzswO8UhSuGZYVKsDJITijwfNDjN3Uq1oTC8+osaBqALQMQMP0f+TNoo9qovnng2toRh7SeksaFBQFdVI1HBLkjea9lS6Y2cqqbxzbaO7rKE4Szf90NCZ42e2RExmWm9hU=

For the transfer proof, run:

cargo run --bin transfer_example

This would output a transfer proof and statement like:

Transfer proof:
TlMcjubogCNj0dfdzJYhqBdHB9+jfs5DsW0i3sqPQCygoq1hIofwRx2rFzu8QBMyqwRohzTMhKBKoabxhApeKNlCggZUrZqiOMBocSkk4SSevZoiGdEHdq+7P2M+eCAnqY8p9i2RxB9RhkpCUi/UarLvbqvHuSdpwbWL/+Dd7y+872YWHkpyjrLn+deUypvdZ987GOly0TSjy+h1E8SjKZlT0FVE/oiF9VylYt735OzYlIwDEoZhgBzkhpgnDugakzoQ0sBqIA4WPSId/a6GG6ybinU7KoCLyGT3fbVqJw2gwimVxMS5bT8g2sZWQ41plaviQ15ncQ85MuthrVfDCWlMQTIDeYO14ujVOk0hY2ToJROv1qduE92ZcA2ak5oGHZxYbZUo0lH89XX84zvUnBgZr1lqK1Yml7B+bLyylibOL6uTzfJwyEwCWzL4SaRIEVvks5pp+kmBj7F1VgpaCL1ks/tTnsxaid9LYUcVPu2kNV6pi3PIiWbFPGa9afQA0yqazgAdFARWjM54q2MtACUXK0D0xbG6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fsi62/sKvWw0I/xk7PI2zf1lj7cbYgzzs0dfy80U60ANyC+gYOM3qmzvfFXa7TjMoK+caU00ONLBlJjmqHwv65uGebpAS/8MBjjBZnfHbLRgaVXzPZgJl0svCC6ROgYPRMl6+BK7neRdMM//9+F+X8Q9+NEoC50qPLOwwvW7oIHjCR20+q3zre9KeVlm5ohepfkV4UamdNsmgRn1XcqkkApLV2lWwSg39lXI0gB04ngf6UNq78IxtNeybwens9U6MkbMM4sn38k/or4GEeFXZZq/Gg0xMQk/y9hCc7gMbLBeBYH5Fvsy5jB9/QXR6HtzhqKF5FNRcK7RmcZ5p20ntnlGw48YGtlzaPP5ymCo6zNXzDkJlYntYAspzrUpJfgxDIExhS2ZwX7P65j4C/OQ7YggADxXP53FMZ5HHMJ9puLmCkYyLvq0zK5tkU+NBtZ/5I+4r/axspOpwjcrvmyO/OgFOP9YqsespLu0zj6b6tBXLc84Dp0+nhgJXMjIT4UQbsRKXYzKx5O5HUDrg4ANw9l4J2bkjH3kJKTNCp14KO8RyJX3Zq4i+1Ge9k4ZBpRmNdoAaW8t49qNhWaayrAqYH4Ew==

Use Substrate to Verify ZK Proof

After generating the ZK proof, we can use a substrate pallet to verify it. To setup the environment, run:

# Build and run a substrate node
cd faceless-substrate-node
cargo build --release
./target/release/faceless-node --dev

# Open another terminal, annd run
cd faceless-front-end
yarn install
yarn start

This should open a web page in the browser: http://localhost:8000

On the web page, we select "Pallet Interator --> Extrinsic --> faceless --> verifyBurn", then copy the above burn statement and proof to the corresponding input boxes, like the following image, and then click "Signed":

alt

We should see corresponding events that say the burn proof verification is successful.

Faceless DApp Test

For the 4 core pallet fucntions (register, deposit, withdraw, transfer), we deliver a Faceless DApp to interact with them, which is also the biggest contribution in Stage 2 of this project. Here is the detailed guide for the interaction.

Step 1: Run a local faceless substrate node

Because the Faceless DApp requires a running faceless substrate node, we show here how to construct a local testing node. For the moment, this node must be running on the same machine where you open the browser to use the DApp.

If you have a full fledged Substrate development environment, then you can run the following commands your terminal:

cd faceless-substrate-node
cargo build --release
./target/release/faceless-node --dev

Otherwise, you can use our dockerfile to create a container environment:

docker build -t faceless .
docker run -it --network host faceless /bin/bash
# NOW we are inside the container
cd faceless-substrate-node
cargo build --release
./target/release/faceless-node --dev

Step 2: Play with the Faceless DApp

We have already deployed the DApp website here. The source code of this DApp frontend is located in Faceless DApp.

Normally, if you can access the Internet, you don't need to build the DApp. Just use our depolyed website. In case you want to build it, run the following:

cd Faceless_frontend/
wasm-pack build faceless-wasm-wrapper --target web
yarn
yarn dev

Register

img

Deposit

Withdraw

Transfer

Documentation

Run the following to generate documentation for the anonymous identity-based encryption in aibe/target/doc/aibe/:

cd aibe
cargo doc --no-deps

About Faceless APIs (Newly Added Features)

As discussed above, there are 4 critical functionalities, implemented in both the substrate pallet and in the DApp. Here is a brief introduction about them:

  • Register: To add an account on chain. It is bound to a wallet address and a platform ID.

  • Deposit: Deposit some fund to an account on chain. The fund is encrypted with IBE encryption.

  • Withdraw: Withdraw some fund from chain to a wallet address.

  • Transfer: Transfer fund between two accounts on chain.

Security Warnings

As of now, this project serves mainly proof-of-concepts, benchmarking and evaluation purpose and not for production use. Also implementation have not been fully-reviewed.