๐ Webb's Solidity Smart Contract Implementation ๐
Table of Contents
For additional information, please refer to the Webb protocol-solidity implementation docs and the official Webb docs site ๐. Have feedback on how to improve protocol-solidity? Or have a specific question to ask? Checkout the Anchor System Feedback Discussion ๐ฌ.
Your development environment will need to include nodejs, and Rust setups. If you need to generate fixtures you will also require Circom 2.0 and snarkjs installations. You can find installation instructions below.
This repository makes use of node.js, yarn, Rust, and requires version 16. To install node.js binaries, installers, and source tarballs, please visit https://nodejs.org/en/download/. Once node.js is installed you may proceed to install yarn
:
npm install --global yarn
Great! Now your Node environment is ready! ๐๐
You must also have Rust installed. This guide uses https://rustup.rs installer and the rustup
tool to manage the Rust toolchain.
First install and configure rustup
:
# Install
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Configure
source ~/.cargo/env
Configure the Rust toolchain to default to the latest nightly version, and add the nightly wasm target:
rustup default nightly
rustup update
rustup update nightly
rustup target add wasm32-unknown-unknown
Great! Now your Rust environment is ready! ๐๐
Lastly, install
- DVC is used for fetching large ZK files and managing them alongside git
- substrate.io may require additional dependencies
๐๐ Your environment is complete! ๐๐
NOTE: This is only required for testing / dev purposes and not required to compile or interact with smart contracts.
To generate fixtures you will need Circom 2.0 and snarkjs installed. To install from source, clone the circom repository:
git clone https://github.com/iden3/circom.git
Enter the circom directory and use the cargo build to compile:
cargo build --release
The installation takes around 3 minutes to be completed. When the command successfully finishes, it generates the circom binary in the directory target/release
. You can install this binary as follows:
cargo install --path circom
The previous command will install the circom binary in the directory $HOME/.cargo/bin
.
snarkjs is a npm package that contains code to generate and validate ZK proofs from the artifacts produced by circom.
You can install snarkjs with the following command:
npm install -g snarkjs
Install dependencies:
yarn install
Update submodules:
git submodule update --init --recursive
Populate fixtures from the submodules:
yarn fetch:fixtures
To compile contracts and build typescript interfaces
yarn build
The above command will build the Solidity system, performing the following build steps:
-
Compile the smart contracts and generate appropriate typescript bindings in a folder
typechain
at the root directory. -
Compile the hashers. These hashers are provided to the merkle tree upon deployment.
Note: If you need to generate fixtures you should run:
yarn build
The above command will compile
the contracts but also compile the circom circuits, and generate ptau. The ptau is needed for setup of zero knowledge proofs. This ptau is for test and development purposes only!
Note: If you push new fixtures to remote storage
cd solidity-fixtures
dvc add solidity-fixtures
dvc push --remote aws
To run the test suite, update the submodules:
git submodule update --init --recursive
Fetch the fixtures:
yarn fetch:fixtures
Install the dependencies:
yarn install
Compile the contracts:
yarn compile
Run test suite:
yarn test
It is also possible to output a gas report of the contracts by running:
yarn test:gas-reporter
To fix the formatting, please run:
yarn format
To run TypeScript checks:
yarn ts-check
This repository contains a variety of scripts to deploy and interact with the smart contracts in the scripts
folder. To use these scripts, one will need to setup an .env
file in the root directory:
# Setup an endpoint
ENDPOINT=https://rinkeby.infura.io/v3/fff68ca474dd4764a8d54dd14fa5519e
# Add private key
PRIVATE_KEY=XXX-XXX-XXX
Interested in contributing to the Webb Relayer Network? Thank you so much for your interest! We are always appreciative for contributions from the open-source community!
If you have a contribution in mind, please check out our Contribution Guide for information on how to do so. We are excited for your first contribution!
Licensed under Apache 2.0 license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache 2.0 license, shall be licensed as above, without any additional terms or conditions.