Thanks for taking a time to read this document. This document includes how to contribute to the project including testing and commits.
After the mainnet stage, you should not open up issues on Github to report bugs that can affect the network's security.
Mostly, it will be the case when you find some bugs in packages/contracts
or packages/circuits
.
In this case, please report the bug via [email protected] instead of opening a public issue on Github.
This project follows the conventional commit rule. To check the full specification, please see https://www.conventionalcommits.org/ Here is the sample commits.
-
Commit message with description and breaking change footer
feat: allow provided config object to extend other configs BREAKING CHANGE: `extends` key in config file is now used for extending other config files
-
Commit message with ! to draw attention to breaking change
refactor!: drop support for Node 6
-
Commit message with both ! and BREAKING CHANGE footer
refactor!: drop support for Node 6 BREAKING CHANGE: refactor to use JavaScript features not available in Node 6.
-
Commit message with no body
docs: correct spelling of CHANGELOG
-
Commit message with scope
feat(lang): add polish language
-
Commit message with multi-paragraph body and multiple footers
fix: correct minor typos in code see the issue for details on typos fixed. Reviewed-by: Z Refs #133
This uses airbnb eslint, and husky will automatically prettify using commit-hook.
-
You need docker & docker-compose for integration test
- Get docker
- Get docker-compose
-
Set your node version v12. It currently supports Node v12.
-
Get nvm here
-
Download node version 12 and set to use it.
nvm install 12 nvm use 12
If you want to make node 12 as the default option run && yarn build:keys
nvm alias default 12
-
-
Install yarn globally. You can skip this step if you already have yarn.
npm install -g yarn
-
Install & get initial setup for the project
yarn bootstrap
-
Build packages
yarn build
-
Run development env
yarn develop
This command will run the coordinator & cli wallet using docker and you can easily access to the running programs via web browser.
- coordinator: http://localhost:1234
- cli wallet: http://localhost:4321
Or you can setup the environment without docker-compose. Please check "Manually setup Run cli applications" section.
yarn test
If you have not enough cpu core, please use
yarn test:serial
Or you can test specific package by just going into the sub package and running yarn test
there.
-
Prepare three terminals
-
Run ganache and deploy contract using the following command.
docker-compose up --build testnet
-
Go to cli package and run coordinator with a pre-configured test account.
cd packages/cli && yarn dev:coordinator
This will give you a cli menu to operate coordinator locally.
-
Go to the cli package and run wallet with a pre-configured test account.
cd packages/cli && yarn dev:wallet
This will give you a cli menu to run wallet locally.
-
It stores the dev log in
packages/cli/WALLET_LOG
andpackages/cli/COORDINATOR_LOG
. You can beautify the logs using this command.npm install -g pino-pretty tail -f packages/cli/WALLET_LOG | pino-pretty tail -f packages/cli/COORDINATOR_LOG | pino-pretty
Currently, Zkopru is using prebuilt docker images for local testing to reduce the SNARK circuit building time consumption. Therefore, if you're trying to make any changes on smart contract or circuits you need to follow this steps.
- Go to
compose/docker-compose.yml
. - Modify the tag of the service what you want to make some modifications. Tag name convention is the branch name with issue number just like
feat-6
,refactor-913
. - And then run
yarn images build <service_name>
on the root directory. If you make changes on the 'circuit' image, this command will take about a day on common laptops. - After you built the image, run
yarn test
in the sub package directory or in the root directory.
-
Add a test circuit in the directory
packages/circuits/tester/
-
Write testcase in the directory
packages/circuits/tests
-
Run test command
lerna run test --scope=@zkopru/circuits
or
cd packages/circuits yarn test
-
After the testing, build a docker image to use the compiled circuit and keys
# root directory of the project yarn images build # Or you can build only the zkoprunet/circuits image with this command yarn images build circuits
- Add a test circuit in the directory
packages/circuits/tester/
- Build a docker image for testing the circuit
# root directory of the project
make circuit-testing-container
- Write testcase in the directory
packages/circuits/tests
- Run test command
lerna run test --scope=@zkopru/circuits
or
cd packages/circuits
yarn test
- After the testing, build a docker image to use the compiled circuit and keys
# root directory of the project
make circuit-container
This command will compile and setup circuits in the impls
directory.
-
Tag the docker image and push to the docker hub.
-
(Optional) Specify the docker image tag in the test cases.
This command will compile and setup circuits in the
impls
directory. -
(maintainer only) Update dockerifles/docker-compose.yml to modify tag and run following:
yarn images build docker-compose -f compose/docker-compose.yml push
- Because prisma currently not support multi source gracefully, we have to update the following scheme at once
packages/prisma/prisma/base.prisma
packages/prisma/prisma/postgres.prisma
packages/prisma/prisma/sqlite.prisma
packages/prisma/prisma/postgres-migrator.prisma
packages/prisma/prisma/sqlite-migrator.prisma
- Then run
yarn build:prisma
. This will update the prisma client typescript and the mockup sqlite db file. - To save the changes, run
yarn save:prisma
. - (optional) If you want to create a migration file for postgres manually, run
cd packages/prisma && yarn gen-migration:postgres
. You may have to run this command before running the integration test. - (optional) Migration may cause some problems, sometimes you need to clean up the
packages/prisma/prisma/migrations
directory. - (optional) To commit the change, clean up and squash the recent migrations into a single migration.
And then, force stage the migration using
git add packages/prisma/prisma/migrations --force
.
You can open the Prisma Studio to explore the database with following steps:
-
Create
packages/prisma/prisma/.env
-
Write up the database connection information.
-
for dev coordinator
# file packages/prisma/prisma/.env DATABASE_URL="file:../../cli/zkopru-coordinator.db"
-
for dev wallet
# file packages/prisma/prisma/.env DATABASE_URL="file:../../cli/zkopru-wallet.db"
-
-
Run
yarn studio
cd packages/prisma && yarn studio
-
Modify
packages/prisma/prisma/schema.prisma
-
Run the following command will update the typescript automatically.
yarn build:prisma
-
Update mockup database.
yarn save:prisma
yarn build:fresh
yarn build:ts
This command will re-build the whole packages by wiping away every artifacts.
yarn build:keys
This module contains HD Wallet that manages zk accounts which supports both the Babyjubjub EdDSA and Ethereum.
This modules contains basic crypto classes for the babyjubjub elliptic curve to integrate its third pary libraries into the zkopru project.
This library contains zk SNARK circuits written in Circom DSL.
Cli applications. Wallet and coordinator node.
This library contains the smart contract which runs the upstream layer 1 part of the system. This library is written in solidity.
This is an application package for the coordinator. It synchonizes, verifies, and generates blocks with its full-node feature.
The core layer2 blockchain system which supports both the full node and the light node. Using this package, you can develop a new application such as mobile wallets or payment solutions.
This module generates dataset for test cases. To avoid the recursive dependency graph, only the test cases refer this package using symbolic links.
This module is the integration test set to run the local testnet for development.
database layer.
This modules contains the transaction builder.
This package contains a light weight roll up tree for zkopru system. Especially the light sync mode allows running the system with a very tiny size of tree data (~30 MB).
This package contains miscellaneous tools for zkopru project.
It contains a zk-wizard which creates a zk-SNARK proof for raw transactions and zk-wallet that manages the accounts and UTXOs.