Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Improve CPU prover setup documentation #258

Merged
merged 46 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3e8342a
Add script to download setup data
jrchatruc Oct 18, 2023
69cf22a
Change permissions
jrchatruc Oct 18, 2023
9d862d2
Improve docs
jrchatruc Oct 18, 2023
8099dcc
zk fmt
jrchatruc Oct 18, 2023
4695d84
Check if the ZSKYNC_HOME environment variable is set instead of setti…
jrchatruc Oct 19, 2023
cba33da
Add comment explaining the script
jrchatruc Oct 19, 2023
1cb02ce
Modify toml config files instead of dev.env
jrchatruc Oct 19, 2023
19c1d2e
Remove unneeded prometheus push interval changes
jrchatruc Oct 19, 2023
be5ec8b
Restore cargo.lock file
jrchatruc Oct 19, 2023
8b283fe
Make sed run on mac and linux
Oct 20, 2023
8c2b103
Add pipeline to readme; Move steps
Oct 20, 2023
b82763a
Update README.md
igamigo Oct 20, 2023
a91dbd3
gpu prover docs
igamigo Oct 20, 2023
13db84e
Merge pull request #2 from lambdaclass/more-prover-docs-gpu
jrchatruc Oct 20, 2023
4babf13
Merge pull request #1 from lambdaclass/more-prover-docu
jrchatruc Oct 20, 2023
c8c5b7c
Add pipeline image
Oct 23, 2023
2f45cf9
Update README.md
Juan-M-V Oct 23, 2023
a0e66eb
Use svg instead
Oct 23, 2023
342cbbd
Solve merge conflict
Oct 23, 2023
9134fcd
Add flag to start all witness aggregators
Oct 23, 2023
4e1f9a9
Add .backup extension to removed files
Juan-M-V Oct 23, 2023
4a18e28
Add extension to rm
Juan-M-V Oct 24, 2023
0037abc
Shorten loop and comment to test
Oct 25, 2023
59611f2
Uncomment tracing info
Oct 25, 2023
fa34486
Merge branch 'improve-prover-setup' of github.com:lambdaclass/zksync-…
Oct 25, 2023
349d449
Add README step
Oct 25, 2023
ffef0ec
Remove as well
Oct 25, 2023
3435d1b
Unify and imporve scripts; Add comment
Nov 1, 2023
54b2c0e
Add README doc for script
Nov 1, 2023
a207df2
Add space to if
Nov 1, 2023
d353afa
Update README.md
Juan-M-V Nov 7, 2023
427968b
Remove pipeline image
Juan-M-V Nov 7, 2023
1c2f8a1
Merge branch 'main' into improve-prover-setup
IAvecilla Nov 7, 2023
42cdabd
Merge branch 'main' into improve-prover-setup
IAvecilla Nov 8, 2023
b1c642e
Remove hardcoding
Juan-M-V Nov 9, 2023
2b86bd7
Fix setup.sh script to download the correct files
jrchatruc Nov 12, 2023
99019a6
Fix prover compilation
jrchatruc Nov 17, 2023
08f05ff
Merge remote-tracking branch 'upstream/main' into improve-prover-setup
jrchatruc Nov 17, 2023
3364d3d
Merge branch 'main' into improve-prover-setup
jrchatruc Nov 17, 2023
8abe98c
Address nits
jrchatruc Nov 20, 2023
02e8d68
Lint
jrchatruc Nov 20, 2023
65b886d
zk fmt
jrchatruc Nov 20, 2023
11540ff
Fix incorrect feature flag on the prover setup script
jrchatruc Nov 20, 2023
b5dec10
CI test
jrchatruc Nov 21, 2023
2e7a87e
Merge branch 'main' into improve-prover-setup
jrchatruc Nov 27, 2023
ed070b3
Check out prover `Cargo.lock` file from main
jrchatruc Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion etc/env/base/fri_prover.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ specialized_group_id=100
witness_vector_generator_thread_count=5
queue_capacity=10
witness_vector_receiver_port=4000
shall_save_to_public_bucket=true
shall_save_to_public_bucket=true
173 changes: 127 additions & 46 deletions prover/prover_fri/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,92 +10,127 @@

## Proving a block using CPU prover locally

### Overview of the pipeline

These are the main components to this process:
- Sequencer
- Prover gateway
- Witness
- Prover
- Compressor

All of them will be sharing information through a SQL database.
The general idea is that the sequencer will produce blocks and the gateway will place them into the database to be proven. Then, the rest of the components will pull jobs from the database and do their part of the pipeline.

![Pipeline](block_proving_pipeline.svg)

### Prerequisites

Make sure these dependencies are installed and available on your machine: [Installing dependencies](./setup-dev.md)
Once that is done, before starting, make sure you go into the root of the repository, then run

```
export ZKSYNC_HOME=$(pwd)
mm-zk marked this conversation as resolved.
Show resolved Hide resolved
```

The whole setup below will NOT work if you don't have this environment variable properly set, as the entirety of the `zk`
CLI tool depends on it.

### Block proving with CPU
Below steps can be used to prove a block on local machine using CPU prover. This is useful for debugging and testing
Machine specs:

- CPU: At least 8 physical cores
- RAM: 60GB of RAM(if you have lower RAM machine enable swap)
- RAM: 60GB of RAM (if you have lower RAM machine enable swap)
- Disk: 400GB of free disk

1. Install the correct nightly version using command: `rustup install nightly-2023-07-21`
2. Generate the cpu setup data (no need to regenerate if it's already there). This will consume around 300Gb of disk.
Use these commands:
2. Initialize DB and run migrations. Go into the root of the repository, then run
```
zk init
```

```markdown
for i in {1..13}; do zk f cargo run --release --bin zksync_setup_data_generator_fri -- --numeric-circuit $i
--is_base_layer done
3. Generate the cpu setup data (no need to regenerate if it's already there). This will consume around 300Gb of disk.
For this, run

for i in {1..15}; do zk f cargo run --release --bin zksync_setup_data_generator_fri -- --numeric-circuit $i done
```
./prover/setup.sh
```

3. Initialize DB and run migrations: `zk init`
For the following steps, we recommend using `tmux` to run every command on a separate session, so you can attach to and
monitor logs for each one.

4. Override the following configuration in your `dev.env`:
4. Run the sequencer/operator. In the root of the repository:

```
ETH_SENDER_SENDER_PROOF_SENDING_MODE=OnlyRealProofs
ETH_SENDER_SENDER_PROOF_LOADING_MODE=FriProofFromGcs
OBJECT_STORE_FILE_BACKED_BASE_PATH=/path/to/server/artifacts
PROVER_OBJECT_STORE_FILE_BACKED_BASE_PATH=/path/to/prover/artifacts
FRI_PROVER_SETUP_DATA_PATH=/path/to/above-generated/cpu-setup-data
zk server --components=api,eth,tree,state_keeper,housekeeper,proof_data_handler
```

5. Run server `zk server --components=api,eth,tree,state_keeper,housekeeper,proof_data_handler` to produce blocks to be
proven
6. Run prover gateway to fetch blocks to be proven from server :
`zk f cargo run --release --bin zksync_prover_fri_gateway`
7. Run 4 witness generators to generate witness for each round:
to produce blocks to be proven

5. Run prover gateway to fetch blocks to be proven from server:

```
zk f cargo run --release --bin zksync_prover_fri_gateway
```

6. Run 4 witness generators to generate witness for each round:

```
API_PROMETHEUS_LISTENER_PORT=3116 zk f cargo run --release --bin zksync_witness_generator -- --round=basic_circuits
API_PROMETHEUS_LISTENER_PORT=3117 zk f cargo run --release --bin zksync_witness_generator -- --round=leaf_aggregation
API_PROMETHEUS_LISTENER_PORT=3118 zk f cargo run --release --bin zksync_witness_generator -- --round=node_aggregation
API_PROMETHEUS_LISTENER_PORT=3119 zk f cargo run --release --bin zksync_witness_generator -- --round=scheduler
```
These 4 steps can be reduced to a single command
```
API_PROMETHEUS_LISTENER_PORT=3116 zk f cargo run --release --bin zksync_witness_generator -- --all_rounds
```
Note that this will automatically open the three ports after the one specified in enviromental variable, in this case 3117, 3118 and 3119.

8. Run prover to perform actual proving: `zk f cargo run --release --bin zksync_prover_fri`
9. Finally, run proof compressor to compress the proof to be sent on L1:
`zk f cargo run --release --bin zksync_proof_fri_compressor`
7. Run prover to perform actual proving:
```
zk f cargo run --release --bin zksync_prover_fri
```
8. Finally, run proof compressor to compress the proof to be sent on L1:
```
zk f cargo run --release --bin zksync_proof_fri_compressor
```

## Proving a block using GPU prover locally

Below steps can be used to prove a block on local machine using GPU prover, It requires Cuda 12.0 installation as
pre-requisite. This is useful for debugging and testing Machine specs:
Below steps can be used to prove a block on local machine using GPU prover.
Running a GPU prover requires a Cuda 12.0 installation as a pre-requisite, alongside these machine specs:

- CPU: At least 8 physical cores
- RAM: 16GB of RAM(if you have lower RAM machine enable swap)
- Disk: 30GB of free disk
- GPU: 1x Nvidia L4/T4 with 16GB of GPU RAM

1. Install the correct nightly version using command: `rustup install nightly-2023-07-21`
2. Generate the gpu setup data (no need to regenerate if it's already there). This will consume around 300Gb of disk.
Use these commands:
2. Initialize DB and run migrations: `zk init`
3. Generate the GPU setup data (no need to regenerate if it's already there). This will consume around 300Gb of disk.
For this, run

```
./prover/setup_gpu.sh
```

```markdown
for i in {1..13}; do zk f cargo run --features "gpu" --release --bin zksync_setup_data_generator_fri --
--numeric-circuit $i --is_base_layer done
4. Run the sequencer/operator. In the root of the repository:

for i in {1..15}; do zk f cargo run --features "gpu" --release --bin zksync_setup_data_generator_fri --
--numeric-circuit $i done
```
zk server --components=api,eth,tree,state_keeper,housekeeper,proof_data_handler
```

3. Initialize DB and run migrations: `zk init`
to produce blocks to be proven

4. Override the following configuration in your `dev.env`:
5. Run prover gateway to fetch blocks to be proven from server:

```
ETH_SENDER_SENDER_PROOF_SENDING_MODE=OnlyRealProofs
ETH_SENDER_SENDER_PROOF_LOADING_MODE=FriProofFromGcs
OBJECT_STORE_FILE_BACKED_BASE_PATH=/path/to/server/artifacts
PROVER_OBJECT_STORE_FILE_BACKED_BASE_PATH=/path/to/prover/artifacts
FRI_PROVER_SETUP_DATA_PATH=/path/to/above-generated/gpu-setup-data
zk f cargo run --release --bin zksync_prover_fri_gateway
```

5. Run server `zk server --components=api,eth,tree,state_keeper,housekeeper,proof_data_handler` to produce blocks to be
proven
6. Run prover gateway to fetch blocks to be proven from server :
`zk f cargo run --release --bin zksync_prover_fri_gateway`
7. Run 4 witness generators to generate witness for each round:
6. Run 4 witness generators to generate witness for each round:

```
API_PROMETHEUS_LISTENER_PORT=3116 zk f cargo run --release --bin zksync_witness_generator -- --round=basic_circuits
Expand All @@ -104,8 +139,9 @@ pre-requisite. This is useful for debugging and testing Machine specs:
API_PROMETHEUS_LISTENER_PORT=3119 zk f cargo run --release --bin zksync_witness_generator -- --round=scheduler
```

8. Run prover to perform actual proving: `zk f cargo run --features "gpu" --release --bin zksync_prover_fri`
9. Run 5 witness vector generators to feed jobs to GPU prover:
7. Run prover to perform actual proving: `zk f cargo run --features "gpu" --release --bin zksync_prover_fri`

8. Run 5 witness vector generators to feed jobs to GPU prover:

```
FRI_WITNESS_VECTOR_GENERATOR_PROMETHEUS_LISTENER_PORT=3416 zk f cargo run --release --bin zksync_witness_vector_generator
Expand All @@ -115,9 +151,54 @@ pre-requisite. This is useful for debugging and testing Machine specs:
FRI_WITNESS_VECTOR_GENERATOR_PROMETHEUS_LISTENER_PORT=3420 zk f cargo run --release --bin zksync_witness_vector_generator
```

10. Finally, run proof compressor to compress the proof to be sent on L1:
9. Finally, run proof compressor to compress the proof to be sent on L1:
`zk f cargo run --release --bin zksync_proof_fri_compressor`


## Checking the status of the prover

Once everything is running (either with the CPU or GPU prover), the server should have at least three blocks, and you can see the first one by running

```
curl -X POST -H 'content-type: application/json' localhost:3050 -d '{"jsonrpc": "2.0", "id": 1, "method": "zks_getBlockDetails", "params": [0]}'
```

and then similarly for blocks number `1` and `2` by changing the parameters.

The prover gateway will then fetch block number 1 to prove and start the entire proving pipeline, which starts out by
generating the witness, then passing it to the prover, then to the compressor to wrap it inside a SNARK to send to L1.

You can follow the status of this pipeline by running

```
zk status prover
```

This might take a while (around an hour and a half on my machine using the CPU prover), you can check on it once in a while. A succesful flow
should output something like

```
==== FRI Prover status ====
State keeper: First batch: 0, recent batch: 1
L1 state: block verified: 1, block committed: 1
Verification key hash on contract is 0x4be443afd605a782b6e56d199df2460a025c81b3dea144e135bece83612563f2
Verification key in database is 0x4be443afd605a782b6e56d199df2460a025c81b3dea144e135bece83612563f2
Verifier hash matches.
Verifier params on contract are 0x5a3ef282b21e12fe1f4438e5bb158fc5060b160559c5158c6389d62d9fe3d080, 0x72167c43a46cf38875b267d67716edc4563861364a3c03ab7aee73498421e828, 0x0000000000000000000000000000000000000000000000000000000000000000
Verifcation params match.
Next block that should be verified is: 2
Checking status of the proofs...
Proof progress for 1 : 111 successful, 0 failed, 0 in progress, 0 queued. Compression job status: successful
```

The most important thing here is the following line

```
L1 state: block verified: 1, block committed: 1
```

which means the proof for the block was verified on L1.

## Performing circuit upgrade

Performing circuit upgrade requires crypto library to be updated and generating new setup data, verification key,
Expand Down
Loading
Loading