diff --git a/.dockerignore b/.dockerignore index 603386e55e3b..88f241c5275e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -24,6 +24,7 @@ keys/setup !Cargo.toml !contracts/ !setup_2\^26.key +!setup_2\^24.key # It's required to remove .git from contracts, # otherwise yarn tries to use .git parent directory that # doesn't exist. diff --git a/.github/workflows/build-contract-verifier-template.yml b/.github/workflows/build-contract-verifier-template.yml index fab6a6f18a58..7042484160f3 100644 --- a/.github/workflows/build-contract-verifier-template.yml +++ b/.github/workflows/build-contract-verifier-template.yml @@ -31,11 +31,11 @@ jobs: runs-on: ${{ fromJSON('["matterlabs-ci-runner", "matterlabs-ci-runner-arm"]')[contains(matrix.platforms, 'arm')] }} strategy: matrix: - components: - - contract-verifier - - verified-sources-fetcher - platforms: - - linux/amd64 + components: + - contract-verifier + - verified-sources-fetcher + platforms: + - linux/amd64 steps: - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 diff --git a/.github/workflows/build-core-template.yml b/.github/workflows/build-core-template.yml index 29b66d991f01..855d37665822 100644 --- a/.github/workflows/build-core-template.yml +++ b/.github/workflows/build-core-template.yml @@ -36,15 +36,15 @@ jobs: runs-on: ${{ fromJSON('["matterlabs-ci-runner", "matterlabs-ci-runner-arm"]')[contains(matrix.platforms, 'arm')] }} strategy: matrix: - components: - - server-v2 - - external-node - - snapshots-creator - platforms: - - linux/amd64 - include: - - components: external-node - platforms: linux/arm64 + components: + - server-v2 + - external-node + - snapshots-creator + platforms: + - linux/amd64 + include: + - components: external-node + platforms: linux/arm64 steps: - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 diff --git a/.github/workflows/build-prover-template.yml b/.github/workflows/build-prover-template.yml index 4da79fccb40a..401c6dbc94fb 100644 --- a/.github/workflows/build-prover-template.yml +++ b/.github/workflows/build-prover-template.yml @@ -41,7 +41,7 @@ jobs: RUNNER_COMPOSE_FILE: "docker-compose-runner-nightly.yml" ERA_BELLMAN_CUDA_RELEASE: ${{ inputs.ERA_BELLMAN_CUDA_RELEASE }} CUDA_ARCH: ${{ inputs.CUDA_ARCH }} - runs-on: [matterlabs-ci-runner] + runs-on: [ matterlabs-ci-runner ] strategy: matrix: component: @@ -51,6 +51,7 @@ jobs: - witness-vector-generator - prover-fri-gateway - proof-fri-compressor + - proof-fri-gpu-compressor steps: - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 with: @@ -80,11 +81,17 @@ jobs: ci_run zk # We need the CRS only for the fri compressor. - - name: download CRS + - name: download CRS for CPU compressor if: matrix.component == 'proof-fri-compressor' run: | ci_run curl --retry 5 -LO https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2\^26.key + - name: download CRS for GPU compressor + if: matrix.component == 'proof-fri-gpu-compressor' + run: | + ci_run curl --retry 5 -LO https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2\^24.key + + - name: login to Docker registries if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) run: | @@ -138,7 +145,7 @@ jobs: env: DOCKER_ACTION: ${{ inputs.action }} COMPONENT: ${{ matrix.component }} - run: | + run: | PASSED_ENV_VARS="ERA_BELLMAN_CUDA_RELEASE,CUDA_ARCH" \ ci_run zk docker $DOCKER_ACTION $COMPONENT diff --git a/Cargo.lock b/Cargo.lock index 3fdbc90f710e..8a65af10c6e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2596,9 +2596,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.13.2" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +checksum = "33ff8ae62cd3a9102e5637afc8452c55acf3844001bd5374e0b0bd7b6616c038" dependencies = [ "ahash 0.8.7", ] @@ -3598,13 +3598,13 @@ dependencies = [ [[package]] name = "metrics-util" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "111cb375987443c3de8d503580b536f77dc8416d32db62d9456db5d93bd7ac47" +checksum = "4de2ed6e491ed114b40b732e4d1659a9d53992ebd87490c44a6ffe23739d973e" dependencies = [ "crossbeam-epoch 0.9.15", "crossbeam-utils 0.8.16", - "hashbrown 0.13.2", + "hashbrown 0.13.1", "metrics", "num_cpus", "quanta 0.11.1", diff --git a/checks-config/era.dic b/checks-config/era.dic index 34610e8e8099..2b9b8ce7239a 100644 --- a/checks-config/era.dic +++ b/checks-config/era.dic @@ -961,3 +961,6 @@ vec zksync_merkle_tree TreeMetadata delegator +Bbellman +Sbellman +DCMAKE diff --git a/core/lib/config/src/configs/fri_proof_compressor.rs b/core/lib/config/src/configs/fri_proof_compressor.rs index 4b4e062dee28..0fceac509aca 100644 --- a/core/lib/config/src/configs/fri_proof_compressor.rs +++ b/core/lib/config/src/configs/fri_proof_compressor.rs @@ -20,7 +20,7 @@ pub struct FriProofCompressorConfig { /// Path to universal setup key file pub universal_setup_path: String, - /// https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2\^26.key + /// https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2\^24.key pub universal_setup_download_url: String, // Whether to verify wrapper proof or not. diff --git a/docker/proof-fri-gpu-compressor/Dockerfile b/docker/proof-fri-gpu-compressor/Dockerfile new file mode 100644 index 000000000000..ead48f6af6bb --- /dev/null +++ b/docker/proof-fri-gpu-compressor/Dockerfile @@ -0,0 +1,48 @@ +# Will work locally only after prior universal setup key download +FROM nvidia/cuda:12.2.0-devel-ubuntu22.04 as builder + +ARG DEBIAN_FRONTEND=noninteractive + +ARG CUDA_ARCH=89 +ENV CUDAARCHS=${CUDA_ARCH} + +RUN apt-get update && apt-get install -y curl clang openssl libssl-dev gcc g++ git \ + pkg-config build-essential libclang-dev && \ + rm -rf /var/lib/apt/lists/* + +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH + +RUN curl https://sh.rustup.rs -sSf | bash -s -- -y && \ + rustup install nightly-2023-08-21 && \ + rustup default nightly-2023-08-21 + +RUN curl -Lo cmake-3.24.2-linux-x86_64.sh https://github.com/Kitware/CMake/releases/download/v3.24.2/cmake-3.24.2-linux-x86_64.sh && \ + chmod +x cmake-3.24.2-linux-x86_64.sh && \ + ./cmake-3.24.2-linux-x86_64.sh --skip-license --prefix=/usr/local + +WORKDIR /usr/src/zksync +COPY . . + +RUN cd prover && \ + git clone https://github.com/matter-labs/era-bellman-cuda.git --branch main bellman-cuda && \ + cmake -Bbellman-cuda/build -Sbellman-cuda/ -DCMAKE_BUILD_TYPE=Release && \ + cmake --build bellman-cuda/build/ + +RUN cd prover && BELLMAN_CUDA_DIR=$PWD/bellman-cuda cargo build --features "gpu" --release --bin zksync_proof_fri_compressor + +FROM nvidia/cuda:12.2.0-runtime-ubuntu22.04 + +RUN apt-get update && apt-get install -y curl libpq5 ca-certificates && rm -rf /var/lib/apt/lists/* + +# copy VK required for proof wrapping +COPY prover/vk_setup_data_generator_server_fri/data/ /prover/vk_setup_data_generator_server_fri/data/ + +COPY setup_2\^24.key /setup_2\^24.key + +ENV CRS_FILE=/setup_2\^24.key + +COPY --from=builder /usr/src/zksync/prover/target/release/zksync_proof_fri_compressor /usr/bin/ + +ENTRYPOINT ["zksync_proof_fri_compressor"] diff --git a/etc/env/base/fri_proof_compressor.toml b/etc/env/base/fri_proof_compressor.toml index bda943391f06..9d26fe876896 100644 --- a/etc/env/base/fri_proof_compressor.toml +++ b/etc/env/base/fri_proof_compressor.toml @@ -1,10 +1,10 @@ [fri_proof_compressor] -compression_mode=1 -prometheus_listener_port=3321 -prometheus_pushgateway_url="http://127.0.0.1:9091" -prometheus_push_interval_ms=100 -generation_timeout_in_secs=3600 -max_attempts=5 -universal_setup_path="../keys/setup/setup_2^26.key" -universal_setup_download_url="https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2^26.key" -verify_wrapper_proof=true +compression_mode = 1 +prometheus_listener_port = 3321 +prometheus_pushgateway_url = "http://127.0.0.1:9091" +prometheus_push_interval_ms = 100 +generation_timeout_in_secs = 3600 +max_attempts = 5 +universal_setup_path = "../keys/setup/setup_2^24.key" +universal_setup_download_url = "https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2^24.key" +verify_wrapper_proof = true diff --git a/etc/env/file_based/general.yaml b/etc/env/file_based/general.yaml index d31e694594de..9a557bde7a48 100644 --- a/etc/env/file_based/general.yaml +++ b/etc/env/file_based/general.yaml @@ -200,8 +200,8 @@ proof_compressor: prometheus_push_interval_ms: 100 generation_timeout_in_secs: 3600 max_attempts: 5 - universal_setup_path: keys/setup/setup_2^26.key - universal_setup_download_url: https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2^26.key + universal_setup_path: keys/setup/setup_2^24.key + universal_setup_download_url: https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2^24.key verify_wrapper_proof: true prover_group: group_0: diff --git a/infrastructure/zk/src/docker.ts b/infrastructure/zk/src/docker.ts index fc98e8ad02a3..6d0edf1f4cdf 100644 --- a/infrastructure/zk/src/docker.ts +++ b/infrastructure/zk/src/docker.ts @@ -15,6 +15,7 @@ const IMAGES = [ 'witness-vector-generator', 'prover-fri-gateway', 'proof-fri-compressor', + 'proof-fri-gpu-compressor', 'snapshots-creator', 'verified-sources-fetcher' ]; @@ -79,6 +80,7 @@ function defaultTagList(image: string, imageTagSha: string, imageTagShaTS: strin 'witness-vector-generator', 'prover-fri-gateway', 'proof-fri-compressor', + 'proof-fri-gpu-compressor', 'snapshots-creator' ].includes(image) ? ['latest', 'latest2.0', `2.0-${imageTagSha}`, `${imageTagSha}`, `2.0-${imageTagShaTS}`, `${imageTagShaTS}`] diff --git a/prover/Cargo.lock b/prover/Cargo.lock index c13e06fd3021..09e30fd4517b 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -444,6 +444,29 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.59.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "clap 2.34.0", + "env_logger 0.9.3", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2 1.0.78", + "quote 1.0.35", + "regex", + "rustc-hash", + "shlex", + "which", +] + [[package]] name = "bindgen" version = "0.65.1" @@ -855,6 +878,20 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "circuit_definitions" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-zkevm_test_harness?branch=gpu-wrapper#ea0d54f6d5d7d3302a4a6594150a2ca809e6677b" +dependencies = [ + "crossbeam 0.8.4", + "derivative", + "seq-macro", + "serde", + "snark_wrapper", + "zk_evm 1.4.0", + "zkevm_circuits 1.4.0 (git+https://github.com/matter-labs/era-zkevm_circuits.git?branch=main)", +] + [[package]] name = "circuit_definitions" version = "1.5.0" @@ -878,7 +915,7 @@ dependencies = [ "derivative", "serde", "zk_evm 1.4.0", - "zkevm_circuits 1.4.0", + "zkevm_circuits 1.4.0 (git+https://github.com/matter-labs/era-zkevm_circuits.git?branch=v1.4.0)", ] [[package]] @@ -2250,6 +2287,17 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-locks" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45ec6fe3675af967e67c5536c0b9d44e34e6c52f86bedc4ea49c5317b8e94d06" +dependencies = [ + "futures-channel", + "futures-task", + "tokio", +] + [[package]] name = "futures-macro" version = "0.3.30" @@ -2455,6 +2503,35 @@ dependencies = [ "async-trait", ] +[[package]] +name = "gpu-ffi" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-heavy-ops-service.git?rev=3d33e06#3d33e069d9d263f3a9626d235ac6dc6c49179965" +dependencies = [ + "bindgen 0.59.2", + "crossbeam 0.7.3", + "derivative", + "futures 0.3.30", + "futures-locks", + "num_cpus", +] + +[[package]] +name = "gpu-prover" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-heavy-ops-service.git?rev=3d33e06#3d33e069d9d263f3a9626d235ac6dc6c49179965" +dependencies = [ + "bit-vec", + "cfg-if 1.0.0", + "crossbeam 0.7.3", + "franklin-crypto 0.0.5 (git+https://github.com/matter-labs/franklin-crypto?branch=snark_wrapper)", + "gpu-ffi", + "itertools 0.10.5", + "num_cpus", + "rand 0.4.6", + "serde", +] + [[package]] name = "group" version = "0.12.1" @@ -4556,7 +4633,7 @@ version = "0.1.0" dependencies = [ "anyhow", "bincode", - "circuit_definitions", + "circuit_definitions 1.5.0", "clap 4.4.6", "colored", "dialoguer", @@ -5680,7 +5757,7 @@ dependencies = [ "blake2 0.10.6 (registry+https://github.com/rust-lang/crates.io-index)", "boojum", "boojum-cuda", - "circuit_definitions", + "circuit_definitions 1.5.0", "cudart", "cudart-sys", "derivative", @@ -6991,7 +7068,7 @@ version = "0.1.0" dependencies = [ "anyhow", "bincode", - "circuit_definitions", + "circuit_definitions 1.5.0", "clap 4.4.6", "hex", "itertools 0.10.5", @@ -7372,6 +7449,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "wrapper-prover" +version = "0.1.0" +source = "git+https://github.com/matter-labs/era-heavy-ops-service.git?rev=3d33e06#3d33e069d9d263f3a9626d235ac6dc6c49179965" +dependencies = [ + "circuit_definitions 0.1.0", + "gpu-prover", + "zkevm_test_harness 1.4.0", +] + [[package]] name = "wyz" version = "0.5.1" @@ -7586,6 +7673,27 @@ dependencies = [ "zkevm_opcode_defs 1.5.0", ] +[[package]] +name = "zkevm_circuits" +version = "1.4.0" +source = "git+https://github.com/matter-labs/era-zkevm_circuits.git?branch=main#fb3e2574b5c890342518fc930c145443f039a105" +dependencies = [ + "arrayvec 0.7.4", + "bincode", + "boojum", + "cs_derive 0.1.0 (git+https://github.com/matter-labs/era-boojum?branch=main)", + "derivative", + "hex", + "itertools 0.10.5", + "rand 0.4.6", + "rand 0.8.5", + "seq-macro", + "serde", + "serde_json", + "smallvec", + "zkevm_opcode_defs 1.3.2", +] + [[package]] name = "zkevm_circuits" version = "1.4.0" @@ -7730,13 +7838,36 @@ dependencies = [ "zkevm-assembly 1.3.2", ] +[[package]] +name = "zkevm_test_harness" +version = "1.4.0" +source = "git+https://github.com/matter-labs/era-zkevm_test_harness?branch=gpu-wrapper#ea0d54f6d5d7d3302a4a6594150a2ca809e6677b" +dependencies = [ + "bincode", + "circuit_definitions 0.1.0", + "codegen", + "crossbeam 0.8.4", + "derivative", + "env_logger 0.9.3", + "hex", + "rand 0.4.6", + "rayon", + "serde", + "serde_json", + "smallvec", + "structopt", + "test-log", + "tracing", + "zkevm-assembly 1.3.2", +] + [[package]] name = "zkevm_test_harness" version = "1.5.0" source = "git+https://github.com/matter-labs/era-zkevm_test_harness.git?branch=v1.5.0#ecb08797ced36fcc7d3696ffd2ec6a2d534b9395" dependencies = [ "bincode", - "circuit_definitions", + "circuit_definitions 1.5.0", "circuit_sequencer_api 0.1.50", "codegen", "crossbeam 0.8.4", @@ -8069,6 +8200,7 @@ dependencies = [ "vise", "vk_setup_data_generator_server_fri", "vlog", + "wrapper-prover", "zkevm_test_harness 1.3.3", "zkevm_test_harness 1.5.0", "zksync_config", @@ -8123,7 +8255,7 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "circuit_definitions", + "circuit_definitions 1.5.0", "ctrlc", "futures 0.3.30", "local-ip-address", @@ -8178,7 +8310,7 @@ dependencies = [ name = "zksync_prover_fri_types" version = "0.1.0" dependencies = [ - "circuit_definitions", + "circuit_definitions 1.5.0", "serde", "zksync_object_store", "zksync_types", @@ -8355,7 +8487,7 @@ dependencies = [ "anyhow", "async-trait", "bincode", - "circuit_definitions", + "circuit_definitions 1.5.0", "const-decoder", "ctrlc", "futures 0.3.30", diff --git a/prover/Cargo.toml b/prover/Cargo.toml index 3a958aad30fd..ca1f97d75b83 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -4,7 +4,6 @@ members = [ "prover_fri_utils", "prover_fri_types", "prover_dal", - # binaries "witness_generator", "vk_setup_data_generator_server_fri", @@ -90,6 +89,9 @@ zksync_utils = { path = "../core/lib/utils" } zksync_eth_client = { path = "../core/lib/eth_client" } zksync_contracts = { path = "../core/lib/contracts" } +wrapper_prover = { package = "wrapper-prover", git = "https://github.com/matter-labs/era-heavy-ops-service.git", rev = "3d33e06" } + + # for `perf` profiling [profile.perf] inherits = "release" diff --git a/prover/proof_fri_compressor/Cargo.toml b/prover/proof_fri_compressor/Cargo.toml index 7e602d754c18..dd1aad902da3 100644 --- a/prover/proof_fri_compressor/Cargo.toml +++ b/prover/proof_fri_compressor/Cargo.toml @@ -39,3 +39,8 @@ bincode.workspace = true reqwest = { workspace = true, features = ["blocking"] } serde_json.workspace = true serde = { workspace = true, features = ["derive"] } +wrapper_prover = { workspace = true, optional = true } + +[features] +gpu = ["wrapper_prover"] + diff --git a/prover/proof_fri_compressor/src/compressor.rs b/prover/proof_fri_compressor/src/compressor.rs index 6f933aaf4a2c..c85162ccdfe0 100644 --- a/prover/proof_fri_compressor/src/compressor.rs +++ b/prover/proof_fri_compressor/src/compressor.rs @@ -5,14 +5,20 @@ use async_trait::async_trait; use circuit_sequencer_api::proof::FinalProof; use prover_dal::{ConnectionPool, Prover, ProverDal}; use tokio::task::JoinHandle; -use zkevm_test_harness::proof_wrapper_utils::{wrap_proof, WrapperConfig}; +#[cfg(feature = "gpu")] +use wrapper_prover::{Bn256, GPUWrapperConfigs, WrapperProver, DEFAULT_WRAPPER_CONFIG}; +#[cfg(not(feature = "gpu"))] +use zkevm_test_harness::proof_wrapper_utils::WrapperConfig; +#[allow(unused_imports)] +use zkevm_test_harness::proof_wrapper_utils::{get_trusted_setup, wrap_proof}; +#[cfg(not(feature = "gpu"))] +use zkevm_test_harness_1_3_3::bellman::bn256::Bn256; use zkevm_test_harness_1_3_3::{ abstract_zksync_circuit::concrete_circuits::{ ZkSyncCircuit, ZkSyncProof, ZkSyncVerificationKey, }, - bellman::{ - bn256::Bn256, - plonk::better_better_cs::{proof::Proof, setup::VerificationKey as SnarkVerificationKey}, + bellman::plonk::better_better_cs::{ + proof::Proof, setup::VerificationKey as SnarkVerificationKey, }, witness::oracle::VmWitnessOracle, }; @@ -62,9 +68,30 @@ impl ProofCompressor { } } + fn verify_proof(keystore: Keystore, serialized_proof: Vec) -> anyhow::Result<()> { + let proof: Proof>> = + bincode::deserialize(&serialized_proof) + .expect("Failed to deserialize proof with ZkSyncCircuit"); + // We're fetching the key as String and deserializing it here + // as we don't want to include the old version of prover in the main libraries. + let existing_vk_serialized = keystore + .load_snark_verification_key() + .context("get_snark_vk()")?; + let existing_vk = serde_json::from_str::< + SnarkVerificationKey>>, + >(&existing_vk_serialized)?; + + let vk = ZkSyncVerificationKey::from_verification_key_and_numeric_type(0, existing_vk); + let scheduler_proof = ZkSyncProof::from_proof_and_numeric_type(0, proof.clone()); + match vk.verify_proof(&scheduler_proof) { + true => tracing::info!("Compressed proof verified successfully"), + false => anyhow::bail!("Compressed proof verification failed "), + } + Ok(()) + } pub fn compress_proof( proof: ZkSyncRecursionLayerProof, - compression_mode: u8, + _compression_mode: u8, verify_wrapper_proof: bool, ) -> anyhow::Result { let keystore = Keystore::default(); @@ -73,35 +100,36 @@ impl ProofCompressor { ZkSyncRecursionLayerStorageType::SchedulerCircuit as u8, ) .context("get_recursiver_layer_vk_for_circuit_type()")?; - let config = WrapperConfig::new(compression_mode); - let (wrapper_proof, _) = wrap_proof(proof, scheduler_vk, config); - let inner = wrapper_proof.into_inner(); + #[cfg(feature = "gpu")] + let wrapper_proof = { + let crs = get_trusted_setup(); + let wrapper_config = DEFAULT_WRAPPER_CONFIG; + let mut prover = WrapperProver::::new(&crs, wrapper_config).unwrap(); + + prover + .generate_setup_data(scheduler_vk.into_inner()) + .unwrap(); + prover.generate_proofs(proof.into_inner()).unwrap(); + + prover.get_wrapper_proof().unwrap() + }; + #[cfg(not(feature = "gpu"))] + let wrapper_proof = { + let config = WrapperConfig::new(_compression_mode); + + let (wrapper_proof, _) = wrap_proof(proof, scheduler_vk, config); + wrapper_proof.into_inner() + }; + // (Re)serialization should always succeed. - let serialized = bincode::serialize(&inner) + let serialized = bincode::serialize(&wrapper_proof) .expect("Failed to serialize proof with ZkSyncSnarkWrapperCircuit"); if verify_wrapper_proof { // If we want to verify the proof, we have to deserialize it, with proper type. // So that we can pass it into `from_proof_and_numeric_type` method below. - let proof: Proof>> = - bincode::deserialize(&serialized) - .expect("Failed to deserialize proof with ZkSyncCircuit"); - // We're fetching the key as String and deserializing it here - // as we don't want to include the old version of prover in the main libraries. - let existing_vk_serialized = keystore - .load_snark_verification_key() - .context("get_snark_vk()")?; - let existing_vk = serde_json::from_str::< - SnarkVerificationKey>>, - >(&existing_vk_serialized)?; - - let vk = ZkSyncVerificationKey::from_verification_key_and_numeric_type(0, existing_vk); - let scheduler_proof = ZkSyncProof::from_proof_and_numeric_type(0, proof.clone()); - match vk.verify_proof(&scheduler_proof) { - true => tracing::info!("Compressed proof verified successfully"), - false => anyhow::bail!("Compressed proof verification failed "), - } + Self::verify_proof(keystore, serialized.clone())?; } // For sending to L1, we can use the `FinalProof` type, that has a generic circuit inside, that is not used for serialization. diff --git a/prover/proof_fri_compressor/src/main.rs b/prover/proof_fri_compressor/src/main.rs index d303c62804b2..1d261cd6b352 100644 --- a/prover/proof_fri_compressor/src/main.rs +++ b/prover/proof_fri_compressor/src/main.rs @@ -1,3 +1,5 @@ +#![feature(generic_const_exprs)] + use std::{env, time::Duration}; use anyhow::Context as _; diff --git a/prover/prover_fri/README.md b/prover/prover_fri/README.md index 9ec6cb870c75..5f0a26cfdd49 100644 --- a/prover/prover_fri/README.md +++ b/prover/prover_fri/README.md @@ -16,9 +16,9 @@ will pull jobs from the database and do their part of the pipeline, loading inte ```mermaid flowchart LR - A["Operator"] --> |Produces block| F[Prover Gateway] - F --> |Inserts into DB| B["Postgres DB"] - B --> |Retrieves proven block \nafter compression| F + A["Operator"] -->|Produces block| F[Prover Gateway] + F -->|Inserts into DB| B["Postgres DB"] + B -->|Retrieves proven block \nafter compression| F B --> C["Witness"] C --- C1["Basic Circuits"] C --- C2["Leaf Aggregation"] @@ -27,9 +27,9 @@ flowchart LR C --- C5["Scheduler"] C --> B B --> D["Vector Generator/Prover"] - D --> |Proven Block| B + D -->|Proven Block| B B --> G["Compressor"] - G --> |Compressed block| B + G -->|Compressed block| B ``` ## Prerequisites @@ -60,9 +60,10 @@ installation as a pre-requisite, alongside these machine specs: Note that it will produce a first l1 batch that can be proven (should be batch 0). -3. Generate the GPU setup data (no need to regenerate if it's already there). This will consume around 20GB of disk. You - need to be in the `prover/` directory (for all commands from here onwards, you need to be in the `prover/` directory) - and run: +3. Generate the GPU setup data (no need to regenerate if it's already there). If you want to use this with the GPU + compressors, you need to change the key in the file from `setup_2^26.key` to `setup_2^24.key`. This will consume + around 20GB of disk. You need to be in the `prover/` directory (for all commands from here onwards, you need to be in + the `prover/` directory) and run: ```console ./setup.sh gpu @@ -167,6 +168,43 @@ Machine specs: zk f cargo run --release --bin zksync_proof_fri_compressor ``` +## Running GPU compressors + +There is an option to run compressors with the GPU, which will significantly improve the performance. + +1. The hardware setup should be the same as for GPU prover +2. Install and compile `era-bellman-cuda` library + + ```console + git clone https://github.com/matter-labs/bellman-cuda.git --branch dev bellman-cuda + cmake -Bbellman-cuda/build -Sbellman-cuda/ -DCMAKE_BUILD_TYPE=Release + cmake --build bellman-cuda/build/ + ``` + +3. Set path of library as environmental variable + + ```console + export BELLMAN_CUDA_DIR=$PWD/bellman-cuda + ``` + +4. GPU compressor uses `setup_2^24.key`. Download it by using: + + ```console + wget https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2^24.key + ``` + +5. Set the env variable with it's path: + + ```console + export CRS_FILE=$PWD/setup_2^24.key + ``` + +6. Run the compressor using: + + ```console + zk f cargo run ---features "gpu" --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