Skip to content

Commit

Permalink
feat: snark proof is already verified inside wrap_proof function (#1903)
Browse files Browse the repository at this point in the history
## What ❔

This PR avoids using useless era-zkevm-test-harness branch

## Why ❔

The only reason this dependency was used is verification of the wrapper
proof that was already verified inside `wrap_proof` function.

---------

Co-authored-by: Lech <88630083+Artemka374@users.noreply.github.com>
  • Loading branch information
olesHolem and Artemka374 authored Jul 5, 2024
1 parent 6153e99 commit 2c8cf35
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 189 deletions.
151 changes: 9 additions & 142 deletions prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ zksync_multivm = { path = "../core/lib/multivm", version = "0.1.0" }
zksync_vlog = { path = "../core/lib/vlog" }
zk_evm = { git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.4.1" }
zkevm_test_harness = { git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.5.0" }
zkevm_test_harness_1_3_3 = { git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.3.3", package = "zkevm_test_harness" }
zksync_basic_types = { path = "../core/lib/basic_types" }
zksync_config = { path = "../core/lib/config" }
zksync_dal = { path = "../core/lib/dal" }
Expand Down
1 change: 0 additions & 1 deletion prover/proof_fri_compressor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ zksync_queued_job_processor.workspace = true
vk_setup_data_generator_server_fri.workspace = true
zksync_vlog.workspace = true

zkevm_test_harness_1_3_3.workspace = true
circuit_sequencer_api.workspace = true
zkevm_test_harness.workspace = true

Expand Down
45 changes: 1 addition & 44 deletions prover/proof_fri_compressor/src/compressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ use wrapper_prover::{Bn256, GPUWrapperConfigs, WrapperProver, DEFAULT_WRAPPER_CO
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::plonk::better_better_cs::{
proof::Proof, setup::VerificationKey as SnarkVerificationKey,
},
witness::oracle::VmWitnessOracle,
};
use zksync_object_store::ObjectStore;
use zksync_prover_dal::{ConnectionPool, Prover, ProverDal};
use zksync_prover_fri_types::{
Expand All @@ -44,7 +33,6 @@ pub struct ProofCompressor {
blob_store: Arc<dyn ObjectStore>,
pool: ConnectionPool<Prover>,
compression_mode: u8,
verify_wrapper_proof: bool,
max_attempts: u32,
protocol_version: ProtocolSemanticVersion,
}
Expand All @@ -54,45 +42,21 @@ impl ProofCompressor {
blob_store: Arc<dyn ObjectStore>,
pool: ConnectionPool<Prover>,
compression_mode: u8,
verify_wrapper_proof: bool,
max_attempts: u32,
protocol_version: ProtocolSemanticVersion,
) -> Self {
Self {
blob_store,
pool,
compression_mode,
verify_wrapper_proof,
max_attempts,
protocol_version,
}
}

fn verify_proof(keystore: Keystore, serialized_proof: Vec<u8>) -> anyhow::Result<()> {
let proof: Proof<Bn256, ZkSyncCircuit<Bn256, VmWitnessOracle<Bn256>>> =
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<Bn256, ZkSyncCircuit<Bn256, VmWitnessOracle<Bn256>>>,
>(&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,
verify_wrapper_proof: bool,
) -> anyhow::Result<FinalProof> {
let keystore = Keystore::default();
let scheduler_vk = keystore
Expand Down Expand Up @@ -126,12 +90,6 @@ impl ProofCompressor {
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.
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.
// So `FinalProof` and `Proof<Bn256, ZkSyncCircuit<Bn256, VmWitnessOracle<Bn256>>>` are compatible on serialization bytecode level.
let final_proof: FinalProof =
Expand Down Expand Up @@ -213,11 +171,10 @@ impl JobProcessor for ProofCompressor {
_started_at: Instant,
) -> JoinHandle<anyhow::Result<Self::JobArtifacts>> {
let compression_mode = self.compression_mode;
let verify_wrapper_proof = self.verify_wrapper_proof;
let block_number = *job_id;
tokio::task::spawn_blocking(move || {
let _span = tracing::info_span!("compress", %block_number).entered();
Self::compress_proof(job, compression_mode, verify_wrapper_proof)
Self::compress_proof(job, compression_mode)
})
}

Expand Down
1 change: 0 additions & 1 deletion prover/proof_fri_compressor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ async fn main() -> anyhow::Result<()> {
blob_store,
pool,
config.compression_mode,
config.verify_wrapper_proof,
config.max_attempts,
protocol_version,
);
Expand Down

0 comments on commit 2c8cf35

Please sign in to comment.