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

prover: upgrade to v0.13.1 / v0.12.2, share params between versions. #1504

Closed
wants to merge 14 commits into from
17 changes: 13 additions & 4 deletions coordinator/internal/logic/verifier/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ func TestFFI(t *testing.T) {
as := assert.New(t)

cfg := &config.VerifierConfig{
MockMode: false,
ParamsPath: *paramsPath,
AssetsPathLo: *assetsPathLo,
AssetsPathHi: *assetsPathHi,
MockMode: false,
LowVersionCircuit: &config.CircuitConfig{
ParamsPath: *paramsPath,
AssetsPath: *assetsPathLo,
ForkName: "darwin",
MinProverVersion: "",
},
HighVersionCircuit: &config.CircuitConfig{
ParamsPath: *paramsPath,
AssetsPath: *assetsPathHi,
ForkName: "darwinV2",
MinProverVersion: "",
},
}

v, err := NewVerifier(cfg)
Expand Down
40 changes: 20 additions & 20 deletions prover/Cargo.lock

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

4 changes: 2 additions & 2 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "
ethers-providers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
snark-verifier-sdk = { git = "https://github.com/scroll-tech/snark-verifier", branch = "develop", default-features = false, features = ["loader_halo2", "loader_evm", "halo2-pse"] }
prover_darwin = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.12.0", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
prover_darwin_v2 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.13.0", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
prover_darwin = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.12.2", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
prover_darwin_v2 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.13.1", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
base64 = "0.13.1"
reqwest = { version = "0.12.4", features = ["gzip"] }
reqwest-middleware = "0.3"
Expand Down
13 changes: 11 additions & 2 deletions prover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,23 @@ fn start() -> Result<()> {
std::process::exit(-2);
}

let degrees: Vec<u32> = prover_darwin_v2::config::ZKEVM_DEGREES
.iter()
.copied()
.chain(prover_darwin_v2::config::AGG_DEGREES.iter().copied())
.collect();
let params_map = prover_darwin_v2::common::Prover::load_params_map(
&config.high_version_circuit.params_path,
&degrees,
);

let task_cache = Rc::new(TaskCache::new(&config.db_path)?);

let coordinator_listener = Box::new(ClearCacheCoordinatorListener {
task_cache: task_cache.clone(),
});

let prover = Prover::new(&config, coordinator_listener)?;
let prover = Prover::new(&config, &params_map, coordinator_listener)?;

log::info!(
"prover start successfully. name: {}, type: {:?}, publickey: {}, version: {}",
Expand All @@ -71,7 +81,6 @@ fn start() -> Result<()> {
);

let task_processor = TaskProcessor::new(&prover, task_cache);

task_processor.start();

Ok(())
Expand Down
24 changes: 17 additions & 7 deletions prover/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ use crate::{
utils::get_task_types,
zk_circuits_handler::{CircuitsHandler, CircuitsHandlerProvider},
};
use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};

use super::types::{ProofDetail, Task};

pub struct Prover<'a> {
config: &'a Config,
key_signer: Rc<KeySigner>,
circuits_handler_provider: RefCell<CircuitsHandlerProvider<'a>>,
circuits_handler_provider: RefCell<CircuitsHandlerProvider<'a, 'a>>,
coordinator_client: RefCell<CoordinatorClient<'a>>,
geth_client: Option<Rc<RefCell<GethClient>>>,
}

impl<'a> Prover<'a> {
pub fn new(config: &'a Config, coordinator_listener: Box<dyn Listener>) -> Result<Self> {
pub fn new(
config: &'a Config,
params_map: &'a std::collections::BTreeMap<u32, ParamsKZG<Bn256>>,
coordinator_listener: Box<dyn Listener>,
) -> Result<Self> {
let prover_type = config.prover_type;
let keystore_path = &config.keystore_path;
let keystore_password = &config.keystore_password;
Expand All @@ -41,10 +46,11 @@ impl<'a> Prover<'a> {
None
};

let provider = CircuitsHandlerProvider::new(prover_type, config, geth_client.clone())
.context("failed to create circuits handler provider")?;
let provider =
CircuitsHandlerProvider::new(prover_type, config, params_map, geth_client.clone())
.context("failed to create circuits handler provider")?;

let vks = provider.init_vks(prover_type, config, geth_client.clone());
let vks = provider.init_vks(prover_type, config);

let key_signer = Rc::new(KeySigner::new(keystore_path, keystore_password)?);
let coordinator_client =
Expand Down Expand Up @@ -97,15 +103,19 @@ impl<'a> Prover<'a> {

pub fn prove_task(&self, task: &Task) -> Result<ProofDetail> {
log::info!("[prover] start to prove_task, task id: {}", task.id);
let handler: Rc<Box<dyn CircuitsHandler>> = self
let handler: Rc<Box<dyn CircuitsHandler + 'a>> = self
.circuits_handler_provider
.borrow_mut()
.get_circuits_handler(&task.hard_fork_name)
.context("failed to get circuit handler")?;
self.do_prove(task, handler)
}

fn do_prove(&self, task: &Task, handler: Rc<Box<dyn CircuitsHandler>>) -> Result<ProofDetail> {
fn do_prove(
&self,
task: &Task,
handler: Rc<Box<dyn CircuitsHandler + 'a>>,
) -> Result<ProofDetail> {
let mut proof_detail = ProofDetail {
id: task.id.clone(),
proof_type: task.task_type,
Expand Down
10 changes: 5 additions & 5 deletions prover/src/task_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use super::{coordinator_client::ProofStatusNotOKError, prover::Prover, task_cach
use anyhow::{Context, Result};
use std::rc::Rc;

pub struct TaskProcessor<'a> {
prover: &'a Prover<'a>,
task_cache: Rc<TaskCache>,
pub struct TaskProcessor<'a, 'b> {
pub prover: &'a Prover<'b>,
pub task_cache: Rc<TaskCache>,
}

impl<'a> TaskProcessor<'a> {
pub fn new(prover: &'a Prover<'a>, task_cache: Rc<TaskCache>) -> Self {
impl<'a, 'b> TaskProcessor<'a, 'b> {
pub fn new(prover: &'a Prover<'b>, task_cache: Rc<TaskCache>) -> Self {
TaskProcessor { prover, task_cache }
}

Expand Down
Loading
Loading