Skip to content

Commit c15aae4

Browse files
committed
remove halo2 dependency and refactor types to better accomodate openvm
1 parent 2ad1e33 commit c15aae4

13 files changed

+4990
-2921
lines changed

Cargo.lock

Lines changed: 4676 additions & 2750 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,13 @@ name = "scroll-proving-sdk"
33
version = "0.1.0"
44
edition = "2021"
55

6-
[patch.crates-io]
7-
ethers-signers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
8-
halo2curves = { git = "https://github.com/scroll-tech/halo2curves", branch = "v0.1.0" }
9-
[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
10-
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
11-
[patch."https://github.com/privacy-scaling-explorations/poseidon.git"]
12-
poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "main" }
13-
[patch."https://github.com/privacy-scaling-explorations/bls12_381"]
14-
bls12_381 = { git = "https://github.com/scroll-tech/bls12_381", branch = "feat/impl_scalar_field" }
15-
166
[dependencies]
177
anyhow = "1.0"
188
log = "0.4"
199
serde = { version = "1.0.198", features = ["derive"] }
2010
serde_json = "1.0.116"
2111
ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
2212
ethers-providers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
23-
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"] }
2413
reqwest = { version = "0.12.4", features = ["gzip"] }
2514
reqwest-middleware = "0.3"
2615
reqwest-retry = "0.5"
@@ -37,3 +26,22 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
3726
axum = "0.6.0"
3827
dotenv = "0.15"
3928
rocksdb = "0.23.0"
29+
sbv-utils = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "omerfirmak-patch-1", features = [
30+
"scroll",
31+
], optional = true }
32+
sbv-primitives = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "omerfirmak-patch-1", features = [
33+
"scroll",
34+
], optional = true }
35+
url = "2.5.4"
36+
37+
[features]
38+
openvm = ["dep:sbv-utils", "dep:sbv-primitives"]
39+
40+
[patch.crates-io]
41+
# patched add rkyv support & MSRV 1.77
42+
ruint = { git = "https://github.com/scroll-tech/uint.git", branch = "v1.12.3" }
43+
alloy-primitives = { git = "https://github.com/scroll-tech/alloy-core", branch = "v0.8.18" }
44+
revm = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
45+
revm-interpreter = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
46+
revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
47+
revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }

examples/cloud.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ impl ProvingService for CloudProver {
8383
async fn get_vks(&self, req: GetVkRequest) -> GetVkResponse {
8484
todo!()
8585
}
86-
async fn prove(&self, req: ProveRequest) -> ProveResponse {
86+
async fn prove(&mut self, req: ProveRequest) -> ProveResponse {
8787
todo!()
8888
}
89-
async fn query_task(&self, req: QueryTaskRequest) -> QueryTaskResponse {
89+
async fn query_task(&mut self, req: QueryTaskRequest) -> QueryTaskResponse {
9090
todo!()
9191
}
9292
}
@@ -109,10 +109,7 @@ async fn main() -> anyhow::Result<()> {
109109
let cfg = CloudProverConfig::from_file_and_env(args.config_file)?;
110110
let sdk_config = cfg.sdk_config.clone();
111111
let cloud_prover = CloudProver::new(cfg);
112-
let prover = ProverBuilder::new(sdk_config)
113-
.with_proving_service(Box::new(cloud_prover))
114-
.build()
115-
.await?;
112+
let prover = ProverBuilder::new(sdk_config, cloud_prover).build().await?;
116113

117114
prover.run().await;
118115

examples/local.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ impl ProvingService for LocalProver {
5959
async fn get_vks(&self, req: GetVkRequest) -> GetVkResponse {
6060
todo!()
6161
}
62-
async fn prove(&self, req: ProveRequest) -> ProveResponse {
62+
async fn prove(&mut self, req: ProveRequest) -> ProveResponse {
6363
todo!()
6464
}
65-
async fn query_task(&self, req: QueryTaskRequest) -> QueryTaskResponse {
65+
async fn query_task(&mut self, req: QueryTaskRequest) -> QueryTaskResponse {
6666
todo!()
6767
}
6868
}
@@ -81,10 +81,7 @@ async fn main() -> anyhow::Result<()> {
8181
let cfg = LocalProverConfig::from_file_and_env(args.config_file)?;
8282
let sdk_config = cfg.sdk_config.clone();
8383
let local_prover = LocalProver::new(cfg);
84-
let prover = ProverBuilder::new(sdk_config)
85-
.with_proving_service(Box::new(local_prover))
86-
.build()
87-
.await?;
84+
let prover = ProverBuilder::new(sdk_config, local_prover).build().await?;
8885

8986
prover.run().await;
9087

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "nightly-2023-12-03"
2+
channel = "nightly-2024-12-06"

src/config.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::prover::CircuitType;
1+
use crate::{
2+
coordinator_handler::ProverType,
3+
prover::{CircuitType, ProofType},
4+
};
25
use anyhow::{anyhow, Result};
36
use dotenv::dotenv;
47
use serde::{Deserialize, Serialize};
@@ -32,7 +35,8 @@ pub struct L2GethConfig {
3235

3336
#[derive(Debug, Serialize, Deserialize, Clone)]
3437
pub struct ProverConfig {
35-
pub circuit_types: Vec<CircuitType>,
38+
pub circuit_type: CircuitType,
39+
pub supported_proof_types: Vec<ProofType>,
3640
pub circuit_version: String,
3741
#[serde(default = "default_n_workers")]
3842
pub n_workers: usize,
@@ -94,22 +98,23 @@ impl Config {
9498
l2geth.endpoint = val;
9599
}
96100
}
97-
if let Some(val) = Self::get_env_var("CIRCUIT_TYPES")? {
101+
102+
if let Some(val) = Self::get_env_var("PROOF_TYPES")? {
98103
let values_vec: Vec<&str> = val
99104
.trim_matches(|c| c == '[' || c == ']')
100105
.split(',')
101106
.map(|s| s.trim())
102107
.collect();
103108

104-
self.prover.circuit_types = values_vec
109+
self.prover.supported_proof_types = values_vec
105110
.iter()
106111
.map(|value| match value.parse::<u8>() {
107-
Ok(num) => CircuitType::from_u8(num),
112+
Ok(num) => ProofType::from_u8(num),
108113
Err(e) => {
109114
panic!("Failed to parse circuit type: {}", e);
110115
}
111116
})
112-
.collect::<Vec<CircuitType>>();
117+
.collect::<Vec<ProofType>>();
113118
}
114119

115120
if let Some(val) = Self::get_env_var("N_WORKERS")? {
@@ -122,4 +127,30 @@ impl Config {
122127

123128
Ok(())
124129
}
130+
131+
pub fn coordinator_prover_type(&self) -> Vec<ProverType> {
132+
if self.prover.circuit_type == CircuitType::OpenVM {
133+
vec![ProverType::OpenVM]
134+
} else {
135+
let mut prover_types = vec![];
136+
if self
137+
.prover
138+
.supported_proof_types
139+
.iter()
140+
.any(|t| *t == ProofType::Bundle || *t == ProofType::Batch)
141+
{
142+
prover_types.push(ProverType::Batch)
143+
}
144+
145+
if self
146+
.prover
147+
.supported_proof_types
148+
.contains(&ProofType::Chunk)
149+
{
150+
prover_types.push(ProverType::Chunk)
151+
}
152+
153+
prover_types
154+
}
155+
}
125156
}

src/coordinator_handler/coordinator_client.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
use super::{
22
api::Api, error::ErrorCode, GetTaskRequest, GetTaskResponseData, KeySigner, LoginMessage,
3-
LoginRequest, Response, SubmitProofRequest, SubmitProofResponseData,
4-
};
5-
use crate::{
6-
config::CoordinatorConfig,
7-
prover::{CircuitType, ProverProviderType},
8-
utils::get_version,
3+
LoginRequest, ProverType, Response, SubmitProofRequest, SubmitProofResponseData,
94
};
5+
use crate::{config::CoordinatorConfig, prover::ProverProviderType, utils::get_version};
106
use tokio::sync::{Mutex, MutexGuard};
117

128
pub struct CoordinatorClient {
13-
circuit_types: Vec<CircuitType>,
9+
prover_types: Vec<ProverType>,
1410
vks: Vec<String>,
1511
pub prover_name: String,
1612
pub prover_provider_type: ProverProviderType,
@@ -22,15 +18,15 @@ pub struct CoordinatorClient {
2218
impl CoordinatorClient {
2319
pub fn new(
2420
cfg: CoordinatorConfig,
25-
circuit_types: Vec<CircuitType>,
21+
prover_types: Vec<ProverType>,
2622
vks: Vec<String>,
2723
prover_name: String,
2824
prover_provider_type: ProverProviderType,
2925
key_signer: KeySigner,
3026
) -> anyhow::Result<Self> {
3127
let api = Api::new(cfg)?;
3228
let client = Self {
33-
circuit_types,
29+
prover_types,
3430
vks,
3531
prover_name,
3632
prover_provider_type,
@@ -111,22 +107,12 @@ impl CoordinatorClient {
111107
.as_ref()
112108
.ok_or_else(|| anyhow::anyhow!("Missing challenge token"))?;
113109

114-
let mut prover_types = vec![];
115-
if self.circuit_types.contains(&CircuitType::Bundle)
116-
|| self.circuit_types.contains(&CircuitType::Batch)
117-
{
118-
prover_types.push(CircuitType::Batch)
119-
}
120-
if self.circuit_types.contains(&CircuitType::Chunk) {
121-
prover_types.push(CircuitType::Chunk)
122-
}
123-
124110
let login_message = LoginMessage {
125111
challenge: login_response_data.token.clone(),
126112
prover_version: get_version().to_string(),
127113
prover_name: self.prover_name.clone(),
128114
prover_provider_type: self.prover_provider_type,
129-
prover_types,
115+
prover_types: self.prover_types.clone(),
130116
vks: self.vks.clone(),
131117
};
132118

src/coordinator_handler/types.rs

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::error::ErrorCode;
22
use crate::{
3-
prover::{CircuitType, ProverProviderType},
3+
prover::{ProofType, ProverProviderType},
44
tracing_handler::CommonHash,
55
};
66
use rlp::{Encodable, RlpStream};
@@ -13,13 +13,60 @@ pub struct Response<T> {
1313
pub data: Option<T>,
1414
}
1515

16+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
17+
pub enum ProverType {
18+
Undefined,
19+
Chunk,
20+
Batch,
21+
OpenVM,
22+
}
23+
24+
impl ProverType {
25+
pub fn from_u8(v: u8) -> Self {
26+
match v {
27+
1 => ProverType::Chunk,
28+
2 => ProverType::Batch,
29+
3 => ProverType::OpenVM,
30+
_ => ProverType::Undefined,
31+
}
32+
}
33+
34+
pub fn to_u8(&self) -> u8 {
35+
match self {
36+
ProverType::Undefined => 0,
37+
ProverType::Chunk => 1,
38+
ProverType::Batch => 2,
39+
ProverType::OpenVM => 3,
40+
}
41+
}
42+
}
43+
44+
impl Serialize for ProverType {
45+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
46+
where
47+
S: Serializer,
48+
{
49+
serializer.serialize_u8(self.to_u8())
50+
}
51+
}
52+
53+
impl<'de> Deserialize<'de> for ProverType {
54+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
55+
where
56+
D: Deserializer<'de>,
57+
{
58+
let v: u8 = u8::deserialize(deserializer)?;
59+
Ok(ProverType::from_u8(v))
60+
}
61+
}
62+
1663
#[derive(Serialize, Deserialize)]
1764
pub struct LoginMessage {
1865
pub challenge: String,
1966
pub prover_version: String,
2067
pub prover_name: String,
2168
pub prover_provider_type: ProverProviderType,
22-
pub prover_types: Vec<CircuitType>,
69+
pub prover_types: Vec<ProverType>,
2370
pub vks: Vec<String>,
2471
}
2572

@@ -36,7 +83,7 @@ impl Encodable for LoginMessage {
3683
let prover_types = self
3784
.prover_types
3885
.iter()
39-
.map(|prover_type: &CircuitType| prover_type.to_u8())
86+
.map(|prover_type| prover_type.to_u8())
4087
.collect::<Vec<u8>>();
4188
s.append(&prover_types);
4289
s.begin_list(self.vks.len());
@@ -63,15 +110,15 @@ pub type ChallengeResponseData = LoginResponseData;
63110

64111
#[derive(Default, Serialize, Deserialize)]
65112
pub struct GetTaskRequest {
66-
pub task_types: Vec<CircuitType>,
113+
pub task_types: Vec<ProofType>,
67114
pub prover_height: Option<u64>,
68115
}
69116

70117
#[derive(Serialize, Deserialize, Clone)]
71118
pub struct GetTaskResponseData {
72119
pub uuid: String,
73120
pub task_id: String,
74-
pub task_type: CircuitType,
121+
pub task_type: ProofType,
75122
pub task_data: String,
76123
pub hard_fork_name: String,
77124
}
@@ -85,7 +132,7 @@ pub struct ChunkTaskDetail {
85132
pub struct SubmitProofRequest {
86133
pub uuid: String,
87134
pub task_id: String,
88-
pub task_type: CircuitType,
135+
pub task_type: ProofType,
89136
pub status: ProofStatus,
90137
pub proof: String,
91138
pub failure_type: Option<ProofFailureType>,
@@ -203,7 +250,7 @@ mod tests {
203250
prover_version: "v4.4.45-37af5ef5-38a68e2-1c5093c".to_string(),
204251
prover_name: "test".to_string(),
205252
prover_provider_type: ProverProviderType::Internal,
206-
prover_types: vec![CircuitType::Chunk],
253+
prover_types: vec![ProverType::Chunk],
207254
vks: vec!["mock_vk".to_string()],
208255
};
209256

0 commit comments

Comments
 (0)