diff --git a/common/libzkp/impl/src/batch.rs b/common/libzkp/impl/src/batch.rs index 2dd6a401a7..e5fb061b1f 100644 --- a/common/libzkp/impl/src/batch.rs +++ b/common/libzkp/impl/src/batch.rs @@ -6,20 +6,20 @@ use crate::{ }, }; use libc::c_char; -use prover_v3::BatchProof as BatchProofV3; +use prover_v3::BatchProof as BatchProofLoVersion; use prover_v4::{ - aggregator::{Prover, Verifier as VerifierV4}, + aggregator::{Prover, Verifier as VerifierHiVersion}, check_chunk_hashes, consts::BATCH_VK_FILENAME, utils::{chunk_trace_to_witness_block, init_env_and_log}, - BatchHeader, BatchProof as BatchProofV4, BatchProvingTask, BlockTrace, BundleProof, + BatchHeader, BatchProof as BatchProofHiVersion, BatchProvingTask, BlockTrace, BundleProof, BundleProvingTask, ChunkInfo, ChunkProof, MAX_AGG_SNARKS, }; use snark_verifier_sdk::verify_evm_calldata; use std::{cell::OnceCell, env, ptr::null}; static mut PROVER: OnceCell = OnceCell::new(); -static mut VERIFIER_V4: OnceCell = OnceCell::new(); +static mut VERIFIER: OnceCell = OnceCell::new(); /// # Safety #[no_mangle] @@ -52,9 +52,9 @@ pub unsafe extern "C" fn init_batch_verifier(params_dir: *const c_char, assets_d // TODO: add a settings in scroll-prover. env::set_var("SCROLL_PROVER_ASSETS_DIR", assets_dir); - let verifier_v4 = VerifierV4::from_dirs(params_dir, assets_dir); + let verifier_hi = VerifierHiVersion::from_dirs(params_dir, assets_dir); - VERIFIER_V4.set(verifier_v4).unwrap(); + VERIFIER.set(verifier_hi).unwrap(); } /// # Safety @@ -189,7 +189,7 @@ pub unsafe extern "C" fn verify_batch_proof( let verified = panic_catch(|| { if fork_id == 3 { // As of upgrade #3 (Curie), we verify batch proofs on-chain (EVM). - let proof = serde_json::from_slice::(proof.as_slice()).unwrap(); + let proof = serde_json::from_slice::(proof.as_slice()).unwrap(); verify_evm_calldata( include_bytes!("plonk_verifier_0.11.4.bin").to_vec(), proof.calldata(), @@ -197,8 +197,8 @@ pub unsafe extern "C" fn verify_batch_proof( } else { // Post upgrade #4 (Darwin), batch proofs are not EVM-verifiable. Instead they are // halo2 proofs meant to be bundled recursively. - let proof = serde_json::from_slice::(proof.as_slice()).unwrap(); - VERIFIER_V4.get().unwrap().verify_batch_proof(&proof) + let proof = serde_json::from_slice::(proof.as_slice()).unwrap(); + VERIFIER.get().unwrap().verify_batch_proof(&proof) } }); verified.unwrap_or(false) as c_char @@ -209,7 +209,7 @@ pub unsafe extern "C" fn verify_batch_proof( pub unsafe extern "C" fn gen_bundle_proof(batch_proofs: *const c_char) -> *const c_char { let proof_result: Result, String> = panic_catch(|| { let batch_proofs = c_char_to_vec(batch_proofs); - let batch_proofs = serde_json::from_slice::>(&batch_proofs) + let batch_proofs = serde_json::from_slice::>(&batch_proofs) .map_err(|e| format!("failed to deserialize batch proofs: {e:?}"))?; let bundle = BundleProvingTask { batch_proofs }; @@ -243,7 +243,7 @@ pub unsafe extern "C" fn gen_bundle_proof(batch_proofs: *const c_char) -> *const pub unsafe extern "C" fn verify_bundle_proof(proof: *const c_char) -> c_char { let proof = c_char_to_vec(proof); let proof = serde_json::from_slice::(proof.as_slice()).unwrap(); - let verified = panic_catch(|| VERIFIER_V4.get().unwrap().verify_bundle_proof(proof)); + let verified = panic_catch(|| VERIFIER.get().unwrap().verify_bundle_proof(proof)); verified.unwrap_or(false) as c_char } diff --git a/common/libzkp/impl/src/chunk.rs b/common/libzkp/impl/src/chunk.rs index 3d06f34755..dd8d455751 100644 --- a/common/libzkp/impl/src/chunk.rs +++ b/common/libzkp/impl/src/chunk.rs @@ -6,18 +6,18 @@ use crate::{ }, }; use libc::c_char; -use prover_v3::{zkevm::Verifier as VerifierV3, ChunkProof as ChunkProofV3}; +use prover_v3::{zkevm::Verifier as VerifierLoVersion, ChunkProof as ChunkProofLoVersion}; use prover_v4::{ consts::CHUNK_VK_FILENAME, utils::init_env_and_log, - zkevm::{Prover, Verifier as VerifierV4}, - BlockTrace, ChunkProof as ChunkProofV4, ChunkProvingTask, + zkevm::{Prover, Verifier as VerifierHiVersion}, + BlockTrace, ChunkProof as ChunkProofHiVersion, ChunkProvingTask, }; use std::{cell::OnceCell, env, ptr::null}; static mut PROVER: OnceCell = OnceCell::new(); -static mut VERIFIER_V3: OnceCell = OnceCell::new(); -static mut VERIFIER_V4: OnceCell = OnceCell::new(); +static mut VERIFIER_LO_VERSION: OnceCell = OnceCell::new(); +static mut VERIFIER_HI_VERSION: OnceCell = OnceCell::new(); /// # Safety #[no_mangle] @@ -42,19 +42,25 @@ pub unsafe extern "C" fn init_chunk_prover(params_dir: *const c_char, assets_dir /// # Safety #[no_mangle] -pub unsafe extern "C" fn init_chunk_verifier(params_dir: *const c_char, assets_dir: *const c_char) { +pub unsafe extern "C" fn init_chunk_verifier( + params_dir: *const c_char, + v3_assets_dir: *const c_char, + v4_assets_dir: *const c_char, +) { init_env_and_log("ffi_chunk_verify"); let params_dir = c_char_to_str(params_dir); - let assets_dir = c_char_to_str(assets_dir); + let v3_assets_dir = c_char_to_str(v3_assets_dir); + let v4_assets_dir = c_char_to_str(v4_assets_dir); // TODO: add a settings in scroll-prover. - env::set_var("SCROLL_PROVER_ASSETS_DIR", assets_dir); - let verifier_v3 = VerifierV3::from_dirs(params_dir, assets_dir); - let verifier_v4 = VerifierV4::from_dirs(params_dir, assets_dir); + env::set_var("SCROLL_PROVER_ASSETS_DIR", v3_assets_dir); + let verifier_lo = VerifierLoVersion::from_dirs(params_dir, v3_assets_dir); + env::set_var("SCROLL_PROVER_ASSETS_DIR", v4_assets_dir); + let verifier_hi = VerifierHiVersion::from_dirs(params_dir, v4_assets_dir); - VERIFIER_V3.set(verifier_v3).unwrap(); - VERIFIER_V4.set(verifier_v4).unwrap(); + VERIFIER_LO_VERSION.set(verifier_lo).unwrap(); + VERIFIER_HI_VERSION.set(verifier_hi).unwrap(); } /// # Safety @@ -120,11 +126,11 @@ pub unsafe extern "C" fn verify_chunk_proof( }; let verified = panic_catch(|| { if fork_id == 3 { - let proof = serde_json::from_slice::(proof.as_slice()).unwrap(); - VERIFIER_V3.get().unwrap().verify_chunk_proof(proof) + let proof = serde_json::from_slice::(proof.as_slice()).unwrap(); + VERIFIER_LO_VERSION.get().unwrap().verify_chunk_proof(proof) } else { - let proof = serde_json::from_slice::(proof.as_slice()).unwrap(); - VERIFIER_V4.get().unwrap().verify_chunk_proof(proof) + let proof = serde_json::from_slice::(proof.as_slice()).unwrap(); + VERIFIER_HI_VERSION.get().unwrap().verify_chunk_proof(proof) } }); verified.unwrap_or(false) as c_char diff --git a/common/libzkp/interface/libzkp.h b/common/libzkp/interface/libzkp.h index 99cb8f3a3a..1c661a7509 100644 --- a/common/libzkp/interface/libzkp.h +++ b/common/libzkp/interface/libzkp.h @@ -17,7 +17,7 @@ char* gen_bundle_proof(char* batch_proofs); char verify_bundle_proof(char* proof); void init_chunk_prover(char* params_dir, char* assets_dir); -void init_chunk_verifier(char* params_dir, char* assets_dir); +void init_chunk_verifier(char* params_dir, char* v3_assets_dir, char* v4_assets_dir); char* get_chunk_vk(); char* gen_chunk_proof(char* block_traces); char verify_chunk_proof(char* proof, char* fork_name); diff --git a/coordinator/conf/config.json b/coordinator/conf/config.json index 2e2ca9d383..15ae708f8d 100644 --- a/coordinator/conf/config.json +++ b/coordinator/conf/config.json @@ -9,7 +9,8 @@ "fork_name": "bernoulli", "mock_mode": true, "params_path": "", - "assets_path": "" + "assets_path_lo": "", + "assets_path_hi": "" }, "max_verifier_workers": 4, "min_prover_version": "v1.0.0" diff --git a/coordinator/internal/config/config.go b/coordinator/internal/config/config.go index 78c85f5887..cbe9ca02d8 100644 --- a/coordinator/internal/config/config.go +++ b/coordinator/internal/config/config.go @@ -52,10 +52,11 @@ type Config struct { // VerifierConfig load zk verifier config. type VerifierConfig struct { - ForkName string `json:"fork_name"` - MockMode bool `json:"mock_mode"` - ParamsPath string `json:"params_path"` - AssetsPath string `json:"assets_path"` + ForkName string `json:"fork_name"` + MockMode bool `json:"mock_mode"` + ParamsPath string `json:"params_path"` + AssetsPathLo string `json:"assets_path_lo"` // lower version Verifier + AssetsPathHi string `json:"assets_path_hi"` // higher version Verifier } // NewConfig returns a new instance of Config. diff --git a/coordinator/internal/logic/verifier/verifier.go b/coordinator/internal/logic/verifier/verifier.go index baecfc965d..b394bfba92 100644 --- a/coordinator/internal/logic/verifier/verifier.go +++ b/coordinator/internal/logic/verifier/verifier.go @@ -36,14 +36,16 @@ func NewVerifier(cfg *config.VerifierConfig) (*Verifier, error) { return &Verifier{cfg: cfg, ChunkVKMap: chunkVKMap, BatchVKMap: batchVKMap, BundleVkMap: bundleVKMap}, nil } paramsPathStr := C.CString(cfg.ParamsPath) - assetsPathStr := C.CString(cfg.AssetsPath) + assetsPathLoStr := C.CString(cfg.AssetsPathLo) + assetsPathHiStr := C.CString(cfg.AssetsPathHi) defer func() { C.free(unsafe.Pointer(paramsPathStr)) - C.free(unsafe.Pointer(assetsPathStr)) + C.free(unsafe.Pointer(assetsPathLoStr)) + C.free(unsafe.Pointer(assetsPathHiStr)) }() - C.init_batch_verifier(paramsPathStr, assetsPathStr) - C.init_chunk_verifier(paramsPathStr, assetsPathStr) + C.init_batch_verifier(paramsPathStr, assetsPathHiStr) + C.init_chunk_verifier(paramsPathStr, assetsPathLoStr, assetsPathHiStr) v := &Verifier{ cfg: cfg, @@ -52,15 +54,15 @@ func NewVerifier(cfg *config.VerifierConfig) (*Verifier, error) { BundleVkMap: make(map[string]string), } - bundleVK, err := v.readVK(path.Join(cfg.AssetsPath, "vk_bundle.vkey")) + bundleVK, err := v.readVK(path.Join(cfg.AssetsPathHi, "vk_bundle.vkey")) if err != nil { return nil, err } - batchVK, err := v.readVK(path.Join(cfg.AssetsPath, "vk_batch.vkey")) + batchVK, err := v.readVK(path.Join(cfg.AssetsPathHi, "vk_batch.vkey")) if err != nil { return nil, err } - chunkVK, err := v.readVK(path.Join(cfg.AssetsPath, "vk_chunk.vkey")) + chunkVK, err := v.readVK(path.Join(cfg.AssetsPathHi, "vk_chunk.vkey")) if err != nil { return nil, err } diff --git a/coordinator/internal/logic/verifier/verifier_test.go b/coordinator/internal/logic/verifier/verifier_test.go index 0e79b9c4b9..4b0be9fcb4 100644 --- a/coordinator/internal/logic/verifier/verifier_test.go +++ b/coordinator/internal/logic/verifier/verifier_test.go @@ -18,7 +18,8 @@ import ( var ( paramsPath = flag.String("params", "/assets/test_params", "params dir") - assetsPath = flag.String("assets", "/assets/test_assets", "assets dir") + assetsPathLo = flag.String("assets", "/assets/test_assets_lo", "assets dir") + assetsPathHi = flag.String("assets", "/assets/test_assets_hi", "assets dir") batchProofPath = flag.String("batch_proof", "/assets/proof_data/batch_proof", "batch proof file path") chunkProofPath1 = flag.String("chunk_proof1", "/assets/proof_data/chunk_proof1", "chunk proof file path 1") chunkProofPath2 = flag.String("chunk_proof2", "/assets/proof_data/chunk_proof2", "chunk proof file path 2") @@ -28,9 +29,10 @@ func TestFFI(t *testing.T) { as := assert.New(t) cfg := &config.VerifierConfig{ - MockMode: false, - ParamsPath: *paramsPath, - AssetsPath: *assetsPath, + MockMode: false, + ParamsPath: *paramsPath, + AssetsPathLo: *assetsPathLo, + AssetsPathHi: *assetsPathHi, } v, err := NewVerifier(cfg)