Skip to content

Commit

Permalink
feat(zk_toolbox): Update reamde for toolbox (#2531)
Browse files Browse the repository at this point in the history
## What ❔

Description for all commands in readme 



## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.

---------

Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo authored Jul 31, 2024
1 parent 6b94ff5 commit d5ba7d8
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 62 deletions.
249 changes: 188 additions & 61 deletions zk_toolbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,167 +4,294 @@ Toolkit for creating and managing ZK Stack chains.

## ZK Inception

ZK Inception facilitates the creation and management of ZK Stacks. All commands are interactive, but you can also pass
all necessary arguments via the command line.
`ZK Inception` facilitates the creation and management of ZK Stacks. Commands are interactive but can also accept
arguments via the command line.

### Dependencies

Ensure you have followed
[these instructions](https://github.com/matter-labs/zksync-era/blob/main/docs/guides/setup-dev.md) to set up
dependencies on your machine (don't worry about the Environment section for now).
Follow [these instructions](https://github.com/matter-labs/zksync-era/blob/main/docs/guides/setup-dev.md) to set up
dependencies on your machine. Ignore the Environment section for now.

### Installation

Install zk_inception from git:
Install `zk_inception` from Git:

```bash
cargo install --git https://github.com/matter-labs/zksync-era/ --locked zk_inception --force
cargo install --git https://github.com/matter-labs/zksync-era/ --locked zk_inception zk_supervisor --force
```

Manually building from a local copy of the [ZkSync](https://github.com/matter-labs/zksync-era/) repository:
Or manually build from a local copy of the [ZkSync](https://github.com/matter-labs/zksync-era/) repository:

```bash
cd zk_toolbox
cargo install --path ./crates/zk_inception --force --locked
./bin/zkt
```

This command installs `zk_inception` and `zk_supervisor` from the current repository.

### Foundry Integration

Foundry is utilized for deploying smart contracts. For commands related to deployment, you can pass flags for Foundry
integration.
Foundry is used for deploying smart contracts. Pass flags for Foundry integration with the `-a` option, e.g.,
`-a --gas-estimate-multiplier=500`.

### Ecosystem

ZK Stack allows you to either create a new ecosystem or connect to an existing one. An ecosystem includes the components
that connects all ZK chains, like the BridgeHub, the shared bridges, and state transition managers.
ZK Stack allows you to create a new ecosystem or connect to an existing one. An ecosystem includes components like the
BridgeHub, shared bridges, and state transition managers.
[Learn more](https://docs.zksync.io/zk-stack/components/shared-bridges.html).

To create a ZK Stack project, you must first create an ecosystem:
#### Global Config

- `--verbose`: Show all output from all commands.
- `--chain`: Use a specific chain for ecosystem operations.
- `--ignore-prerequisites`: Do not verify prerequisites. !!!WARNING!!! This option won't show errors if required tools
for network deployment and operation are missing.

#### Create

To create a ZK Stack project, start by creating an ecosystem:

```bash
zk_inception ecosystem create
```

If you chose to not start database & L1 containers after creating the ecosystem, you can later run
`zk_inception containers`
If you choose not to start database & L1 containers after creating the ecosystem, you can later run:

```bash
zk_inception containers
```

All subsequent commands should be executed from within the ecosystem folder you created:
Execute subsequent commands from within the created ecosystem folder:

```bash
cd `path/to/ecosystem/name`
cd path/to/ecosystem/name
```

If the ecosystem has never been deployed before, initialization is required:
#### Init

If the ecosystem has never been deployed before, initialize it:

```bash
zk_inception ecosystem init
```

This command also initializes the first ZK chain. Note that the very first chain becomes the default one, but you can
override it with another by using the `--chain <name>` flag.
This initializes the first ZK chain, which becomes the default. Override with `--chain <name>` if needed. For default
params, use:

```bash
zk_inception ecosystem init --dev
```

If the process gets stuck, resume it with `--resume`. This flag keeps track of already sent transactions and sends new
ones with provided params.

#### Verifying Contracts

To verify contracts, use the `--verify` flag.

- `--verifier name`: Verification provider. Options: etherscan, sourcify, blockscout (default: etherscan). Note: Add "
/api?" to the end of the Blockscout homepage explorer URL.
- `--verifier-url` url: Optional verifier URL for submitting the verification request.
- `--verifier-api-key`: Verifier API key.

To change the default ZK chain, use:
#### Changing Default Chain

To change the default ZK chain:

```bash
zk_inception ecosystem change-default-chain
```

IMPORTANT: It is not yet possible to use an existing ecosystem and register a chain to it. this feature will be added in
the future.
IMPORTANT: Currently, you cannot use an existing ecosystem to register a new chain. This feature will be added in the
future.

### ZK Chain

Upon ecosystem creation, the first ZK chain is automatically generated. However, you can create additional chains and
switch between them:
#### Create

The first ZK chain is generated upon ecosystem creation. Create additional chains and switch between them:

```bash
zk_inception chain create
```

Once created, contracts for the ZK chain must be deployed:
#### Init

Deploy contracts and initialize Zk Chain:

```bash
zk_inception chain init
```

Initialization utilizes the ecosystem's governance to register it in the BridgeHub.
This registers the chain in the BridgeHub and deploys all necessary contracts. Manual initialization steps:

If contracts were deployed by a third party (e.g., MatterLabs), you may need to run the genesis process locally:
`init`: Register in BridgeHub, deploy L2 contracts, and create genesis (preferred method). `deploy-l2-contracts`: Deploy
L2 bridge and Default Upgrade Contracts. `initialize-bridges`: Deploy L2 bridge. `upgrader`: Deploy Default Upgrade
Contract. `deploy-paymaster`: Deploy paymaster. `genesis`: Run genesis after deploying contracts (preferred if deployed
by a third party).

```bash
zk_inception chain genesis
```
### ZK Server

This ensures proper initialization of the server.

### Zk Server

For running the chain:
To run the chain:

```bash
zk_inception server
```

You can specify the chain you are running by providing `--chain <chain_name>` argument
You can specify the component you want to run using `--components` flag

Specify the chain with `--chain <chain_name>`.

### Prover

#### Requirements

Make sure you have installed the following requirements:
Ensure you have installed:

- [gcloud](https://cloud.google.com/sdk/docs/install)
- [wget](https://www.gnu.org/software/wget/)
- [cmake](https://apt.kitware.com/)
- [nvcc (CUDA toolkit)](https://developer.nvidia.com/cuda-downloads)

Checkout [prover docs](https://github.com/matter-labs/zksync-era/blob/main/prover/docs/02_setup.md) for more info.
Refer to the [prover docs](https://github.com/matter-labs/zksync-era/blob/main/prover/docs/02_setup.md) for more
information.

#### Running the prover
#### Running the Prover

To run the prover, follow these steps:

First, initialize the prover:
Initialize the prover:

```bash
zk_inception prover init # initializes object store settings, downloads setup keys and initializes bellman-cuda
zk_inception prover init
```

You can generate the setup keys with:
Generate setup keys:

```bash
zk_inception prover generate-sk
```

Finally, run the prover:
Run the prover:

```bash
zk_inception prover run
```

You can specify the prover component to run by providing `--component <component>` argument. Possible components are:
`gateway, witness-generator, witness-vector-generator, prover, compressor`

If you are running `witness-generator` you can specify the round by providing `--round <round>` argument. Possible
rounds are: `all-rounds, basic-circuits, leaf-aggregation, node-aggregation, recursion-tip, scheduler`
Specify the prover component with `--component <component>`. Components:
`gateway, witness-generator, witness-vector-generator, prover, compressor`.

For `witness-vector-generator`, specify the number of WVG jobs with `--threads <threads>`.

### Contract verifier
For `witness-generator`, specify the round with `--round <round>`. Rounds:
`all-rounds, basic-circuits, leaf-aggregation, node-aggregation, recursion-tip, scheduler`.

Running the contract verifier:
### Contract Verifier

First, download the required `solc`, `zksolc`, `vyper` and `zkvyper` binaries with:
Download required binaries (`solc`, `zksolc`, `vyper`, `zkvyper`):

```bash
zk_inception contract-verifier init`
zk_inception contract-verifier init
```

Select the minimum version of each compiler, and the tool will download any missing binaries. These binaries are
necessary to compile contracts, as each contract may require a different compiler version.

Then, run the contract verifier with:
Run the contract verifier:

```bash
zk_inception contract-verifier run
```

### External Node

Commands for running an external node:

#### Configs

Prepare configs:

```bash
zk_inception en configs
```

This ensures no port conflicts with the main node.

#### Init

Prepare the databases:

```bash
zk_inception en init
```

#### Run

Run the external node:

```bash
zk_inception en run
```

### Update

To update your node:

```bash
zk_inception update
```

This command pulls the latest changes, syncs the general config for all chains, and raises a warning if L1 upgrades are
needed.

## ZK Supervisor

Tools for developing zkSync.

### Database

Commands for database manipulation:

```bash
zk_supervisor db
```

Possible commands:

- `check-sqlx-data`: Check if sqlx-data.json is up to date.
- `drop`: Drop databases.
- `migrate`: Migrate databases.
- `new-migration`: Create a new migration.
- `prepare`: Prepare sqlx-data.json.
- `reset`: Reset databases.
- `setup`: Set up databases.

### Clean

Clean artifacts:

```bash
zk_supervisor clean
```

Possible commands:

- `all`: Remove containers and contracts cache.
- `containers`: Remove containers and Docker volumes.
- `contracts-cache`: Remove contracts cache.

### Tests

Run zkSync tests:

```bash
zk_supervisor test
```

Possible commands:

- `integration`: Run integration tests.
- `revert`: Run revert tests.
- `recovery`: Run recovery tests.

### Snapshot Commands

Create a snapshot of the current chain:

```bash
zks snapshot create
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ mod run;

#[derive(Debug, Serialize, Deserialize, Parser)]
pub enum ExternalNodeCommands {
/// Prepare configs for EN
Configs(PrepareConfigArgs),
/// Init databases
Init,
/// Run external node
Run(RunExternalNodeArgs),
}

Expand Down
2 changes: 1 addition & 1 deletion zk_toolbox/crates/zk_inception/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum InceptionSubcommands {
Prover(ProverCommands),
/// Run server
Server(RunServerArgs),
// Run External Node
/// External Node related commands
#[command(subcommand, alias = "en")]
ExternalNode(ExternalNodeCommands),
/// Run containers for local development
Expand Down
3 changes: 3 additions & 0 deletions zk_toolbox/crates/zk_supervisor/src/commands/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ use crate::messages::{

#[derive(Subcommand, Debug)]
pub enum CleanCommands {
/// Remove containers and contracts cache
All,
/// Remove containers and docker volumes
Containers,
/// Remove contracts caches
ContractsCache,
}

Expand Down

0 comments on commit d5ba7d8

Please sign in to comment.