Check out ZK Sync live demo.
ZK Sync is a scaling and privacy engine for Ethereum. Its current functionality scope includes low gas transfers of ETH and ERC20 tokens in the Ethereum network. This document is a description of the JS library that can be used to interact with ZK Sync.
ZK Sync is built on ZK Rollup architecture. ZK Rollup is an L2 scaling solution in which all funds are held by a smart contract on the mainchain, while computation and storage are performed off-chain. For every Rollup block, a state transition zero-knowledge proof (SNARK) is generated and verified by the mainchain contract. This SNARK includes the proof of the validity of every single transaction in the Rollup block. Additionally, the public data update for every block is published over the mainchain network in the cheap calldata.
This architecture provides the following guarantees:
- The Rollup validator(s) can never corrupt the state or steal funds (unlike Sidechains).
- Users can always retrieve the funds from the Rollup even if validator(s) stop cooperating because the data is available (unlike Plasma).
- Thanks to validity proofs, neither users nor a single other trusted party needs to be online to monitor Rollup blocks in order to prevent fraud.
In other words, ZK Rollup strictly inherits the security guarantees of the underlying L1.
To learn how to use ZK Sync, please refer to the ZK Sync SDK documentation.
Prepare dev environment prerequisites: see docs/setup-dev.md
Setup:
zksync init
To completely reset the dev environment:
- Stop services:
zksync dev-down
- Repeat the setup procedure above
zksync redeploy
Env config files are held in etc/env/
List configurations:
zksync env
Switch between configurations:
zksync env <ENV_NAME>
Run server:
zksync server
By default block chunk size set to 50
. For testing & development purposes you
can change it to the smaller value.
Note: Currently it's not recommended though. Lowering the block chunk size may break several tests, since some of them create big blocks.
If you have to change the block chunk size anyway, you should change the environment
variable BLOCK_SIZE_CHUNKS
value in ./etc/env/dev.env
.
After that you may need to invalidate cargo
cache by touching the files of models
:
touch core/models/**/*.rs
This is required, because models
take the environment variable value at the compile time, and
we have to recompile this module to set correct values.
If you use additional caching systems (like sccache
), you may have to remove their cache as well.
After that you must generate keys. This only needs to be done once:
./bin/gen-keys
zksync redeploy
Run prover:
zksync prover
Run client
zksync client
Client UI will be available at http://localhost:8080.
Make sure you have environment variables set right, you can check it by running:
zksync env
. You should see * dev
in output.
zksync dockerhub-push
zksync
uses pre-commit git hooks for basic code integrity checks. Hooks are set up automatically
within the workspace initialization process. These hooks will not allow to commit the code which does
not pass several checks.
Currently the following criteria are checked:
- Code should always be formatted via
cargo fmt
. - Dummy Prover should not be staged for commit (see below for the explanation).
-
cd core/storage
- Add diesel migration
- Rename
core/storage/schema.rs.generated
toschema.rs
- Run tests:
zksync db-tests
-
Running all the
rust
tests:f cargo test
-
Running the database tests:
zksync db-tests
-
Running the integration test:
zksync server # Has to be run in the 1st terminal zksync prover # Has to be run in the 2nd terminal zksync integration-simple # Has to be run in the 3rd terminal
-
Running the full integration tests (similar to
integration-simple
, but performs different full exits)zksync server # Has to be run in the 1st terminal zksync prover # Has to be run in the 2nd terminal zksync integration-full-exit # Has to be run in the 3rd terminal
-
Running the circuit tests:
zksync circuit-tests
-
Running the prover tests:
zksync prover-tests
-
Running the benchmarks:
f cargo bench
-
Running the loadtest:
zksync server # Has to be run in the 1st terminal zksync prover # Has to be run in the 2nd terminal zksync loadtest # Has to be run in the 3rd terminal
Using the real prover for the development can be not really handy, since it's pretty slow and resource consuming.
Instead, one may want to use the Dummy Prover: lightweight version of prover, which does not actually proves anything, but acts like it does.
To enable the dummy prover, run:
zksync dummy-prover enable
And after that you will be able to use the dummy prover instead of actual prover:
zksync dummy-prover # Instead of `zksync prover`
Warning: setup-dummy-prover
subcommand changes the Verifier.sol
contract, which is a part of git
repository.
Be sure not to commit these changes when using the dummy prover!
If one will need to switch back to the real prover, a following command is required:
zksync dummy-prover disable
This command will revert changes in the contract and redeploy it, so the actual prover will be usable again.
Also you can always check the current status of the dummy verifier:
$ zksync dummy-prover status
Dummy Verifier status: disabled
To generate a proving key, from server
dir run:
cargo run --release --bin read_write_keys
It will generate a *VerificationKey.sol
and *_pk.key
files for 'deposit', 'exit' and 'transfer' circuits in the root folder.
Move files to proper locations:
mv -f n*VerificationKey.sol ./contracts/contracts/
mv -f *_pk.key ./prover/keys/
If the pregenerated leaf format changes, replace the EMPTY_TREE_ROOT
constant in contracts/contracts/PlasmaStorage.sol
.
cd contracts; yarn build
IMPORTANT! Generated .abi
and .bin
files are fed to cargo to build module plasma::eth
.
So you need to rebuild the code on every change (to be automated).
zksync publish-source
ZK Sync is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE, LICENSE-MIT for details.