Skip to content

Commit b1703b6

Browse files
noel2004lightsing
andauthored
feat: cloud prover many fixs and feats (#77)
Co-authored-by: Akase Haruka <lightsing@users.noreply.github.com> Co-authored-by: lightsing <light.tsing@gmail.com>
1 parent 4c36ab2 commit b1703b6

21 files changed

Lines changed: 1725 additions & 2030 deletions

Cargo.lock

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

Cargo.toml

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
11
[package]
22
name = "scroll-proving-sdk"
3-
version = "0.1.0"
4-
edition = "2021"
3+
version = "0.2.0"
4+
edition = "2024"
5+
6+
[[bin]]
7+
name = "scroll-pover-db-tool"
8+
path = "src/bin/pover_db_tool.rs"
59

610
[dependencies]
7-
anyhow = "1.0"
8-
log = "0.4"
11+
eyre = "0.6"
12+
color-eyre = "0.6"
913
serde = { version = "1", features = ["derive"] }
1014
serde_json = "1.0"
1115
ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
12-
ethers-providers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
13-
reqwest = { version = "0.12.4", features = ["gzip"] }
14-
reqwest-middleware = "0.3"
15-
reqwest-retry = "0.5"
16-
hex = "0.4.3"
17-
tiny-keccak = { version = "2.0.0", features = ["sha3", "keccak"] }
18-
rand = "0.8.5"
19-
rlp = "0.5.2"
20-
tokio = { version = "1.37.0", features = ["full"] }
16+
futures = "0.3"
17+
reqwest = { version = "0.12", features = ["gzip", "json"] }
18+
reqwest-middleware = "0.4"
19+
reqwest-retry = "0.7"
20+
hex = "0.4"
21+
tiny-keccak = { version = "2.0", features = ["sha3", "keccak"] }
22+
rand = "0.9"
23+
alloy-rlp = { version = "0.3", features = ["derive"] }
24+
tokio = { version = "1.48", features = ["net", "sync"] }
2125
async-trait = "0.1"
22-
http = "1.1.0"
26+
http = "1.4"
2327
clap = { version = "4.5", features = ["derive"] }
24-
tracing = "0.1.40"
25-
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
26-
axum = "0.6.0"
27-
dotenv = "0.15"
28-
rocksdb = "0.23.0"
29-
url = "2.5.4"
28+
tracing = "0.1"
29+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
30+
axum = { version = "0.8", default-features = false, features = ["tokio", "http1"] }
31+
dotenvy = "0.15"
32+
rocksdb = "0.24"
33+
strum = { version = "0.27", features = ["derive"] }
34+
serde_repr = "0.1"
3035

36+
# ref: https://docs.rs/color-eyre/0.6.5/color_eyre/#improving-perf-on-debug-builds
37+
[profile.dev.package.backtrace]
38+
opt-level = 3

build.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::env;
2+
3+
const DEFAULT_COMMIT: &str = "unknown";
4+
const DEFAULT_ZK_VERSION: &str = "000000-000000";
5+
const DEFAULT_TAG: &str = "v0.0.0";
6+
7+
fn main() {
8+
println!(
9+
"cargo:rustc-env=GIT_REV={}",
10+
env::var("GIT_REV").unwrap_or_else(|_| DEFAULT_COMMIT.to_string()),
11+
);
12+
println!(
13+
"cargo:rustc-env=GO_TAG={}",
14+
env::var("GO_TAG").unwrap_or_else(|_| DEFAULT_TAG.to_string()),
15+
);
16+
println!(
17+
"cargo:rustc-env=ZK_VERSION={}",
18+
env::var("ZK_VERSION").unwrap_or_else(|_| DEFAULT_ZK_VERSION.to_string()),
19+
);
20+
}

conf/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
2,
1818
3
1919
],
20-
"circuit_version": "v0.13.1"
20+
"circuit_version": "v0.13.1",
21+
"suppress_empty_task_error": true
2122
},
2223
"db_path": "db"
2324
}

examples/cloud.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
use anyhow::{anyhow, Result};
1+
#![allow(dead_code)]
22
use async_trait::async_trait;
33
use clap::Parser;
4+
use eyre::{Result, eyre};
45
use reqwest::Url;
56
use std::fs::File;
67

78
use scroll_proving_sdk::{
89
config::Config as SdkConfig,
910
prover::{
11+
ProverBuilder, ProvingService,
1012
proving_service::{
1113
GetVkRequest, GetVkResponse, ProveRequest, ProveResponse, QueryTaskRequest,
1214
QueryTaskResponse,
1315
},
14-
ProverBuilder, ProvingService,
1516
},
1617
utils::init_tracing,
1718
};
@@ -37,7 +38,7 @@ impl CloudProverConfig {
3738
where
3839
R: std::io::Read,
3940
{
40-
serde_json::from_reader(reader).map_err(|e| anyhow!(e))
41+
serde_json::from_reader(reader).map_err(|e| eyre!(e))
4142
}
4243

4344
pub fn from_file(file_name: String) -> Result<Self> {
@@ -49,7 +50,7 @@ impl CloudProverConfig {
4950
std::env::var_os(key)
5051
.map(|val| {
5152
val.to_str()
52-
.ok_or_else(|| anyhow!("{key} env var is not valid UTF-8"))
53+
.ok_or_else(|| eyre!("{key} env var is not valid UTF-8"))
5354
.map(String::from)
5455
})
5556
.transpose()
@@ -80,13 +81,13 @@ impl ProvingService for CloudProver {
8081
fn is_local(&self) -> bool {
8182
false
8283
}
83-
async fn get_vks(&self, req: GetVkRequest) -> GetVkResponse {
84+
async fn get_vks(&self, _req: GetVkRequest) -> GetVkResponse {
8485
todo!()
8586
}
86-
async fn prove(&mut self, req: ProveRequest) -> ProveResponse {
87+
async fn prove(&mut self, _req: ProveRequest) -> ProveResponse {
8788
todo!()
8889
}
89-
async fn query_task(&mut self, req: QueryTaskRequest) -> QueryTaskResponse {
90+
async fn query_task(&mut self, _req: QueryTaskRequest) -> QueryTaskResponse {
9091
todo!()
9192
}
9293
}
@@ -101,8 +102,8 @@ impl CloudProver {
101102
}
102103
}
103104

104-
#[tokio::main]
105-
async fn main() -> anyhow::Result<()> {
105+
#[tokio::main(flavor = "current_thread")]
106+
async fn main() -> Result<()> {
106107
init_tracing();
107108

108109
let args = Args::parse();

examples/local.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use anyhow::{anyhow, Result};
21
use async_trait::async_trait;
32
use clap::Parser;
3+
use eyre::{Result, eyre};
44
use scroll_proving_sdk::{
55
config::Config as SdkConfig,
66
prover::{
7+
ProverBuilder, ProvingService,
78
proving_service::{
89
GetVkRequest, GetVkResponse, ProveRequest, ProveResponse, QueryTaskRequest,
910
QueryTaskResponse,
1011
},
11-
ProverBuilder, ProvingService,
1212
},
1313
utils::init_tracing,
1414
};
@@ -35,7 +35,7 @@ impl LocalProverConfig {
3535
where
3636
R: std::io::Read,
3737
{
38-
serde_json::from_reader(reader).map_err(|e| anyhow!(e))
38+
serde_json::from_reader(reader).map_err(|e| eyre!(e))
3939
}
4040

4141
pub fn from_file(file_name: String) -> Result<Self> {
@@ -56,25 +56,25 @@ impl ProvingService for LocalProver {
5656
fn is_local(&self) -> bool {
5757
true
5858
}
59-
async fn get_vks(&self, req: GetVkRequest) -> GetVkResponse {
59+
async fn get_vks(&self, _req: GetVkRequest) -> GetVkResponse {
6060
todo!()
6161
}
62-
async fn prove(&mut self, req: ProveRequest) -> ProveResponse {
62+
async fn prove(&mut self, _req: ProveRequest) -> ProveResponse {
6363
todo!()
6464
}
65-
async fn query_task(&mut self, req: QueryTaskRequest) -> QueryTaskResponse {
65+
async fn query_task(&mut self, _req: QueryTaskRequest) -> QueryTaskResponse {
6666
todo!()
6767
}
6868
}
6969

7070
impl LocalProver {
71-
pub fn new(cfg: LocalProverConfig) -> Self {
71+
pub fn new(_cfg: LocalProverConfig) -> Self {
7272
Self {}
7373
}
7474
}
7575

76-
#[tokio::main]
77-
async fn main() -> anyhow::Result<()> {
76+
#[tokio::main(flavor = "current_thread")]
77+
async fn main() -> Result<()> {
7878
init_tracing();
7979

8080
let args = Args::parse();

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-2025-02-14"
2+
channel = "nightly-2025-08-18"

src/bin/pover_db_tool.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use clap::{Parser, Subcommand};
2+
use eyre::WrapErr;
3+
use scroll_proving_sdk::db::{Db, PROVING_TASK_ID_KEY_PREFIX};
4+
use scroll_proving_sdk::utils::init_color_eyre_hook;
5+
use std::collections::HashMap;
6+
use std::path::PathBuf;
7+
8+
/// Tool to interact with the prover database.
9+
#[derive(Parser)]
10+
struct Cli {
11+
/// Path to the database
12+
#[clap(long, default_value = ".work/db")]
13+
db: PathBuf,
14+
15+
#[command(subcommand)]
16+
commands: Commands,
17+
}
18+
19+
#[derive(Subcommand)]
20+
enum Commands {
21+
/// List all coordinator and prover task ID pairs
22+
List,
23+
/// Get the corresponding task ID
24+
Get {
25+
#[command(subcommand)]
26+
commands: GetCommands,
27+
},
28+
}
29+
30+
#[derive(Subcommand)]
31+
enum GetCommands {
32+
/// Get coordinator task ID by prover task ID
33+
Coordinator { task_id: String },
34+
/// Get prover task ID by coordinator task ID
35+
Prover { task_id: String },
36+
}
37+
38+
fn main() -> eyre::Result<()> {
39+
init_color_eyre_hook();
40+
41+
let cli = Cli::parse();
42+
let db = Db::new(&cli.db).context("open database")?;
43+
44+
let mut c2p = HashMap::new();
45+
let mut p2c = HashMap::new();
46+
47+
for result in db.inner().prefix_iterator(PROVING_TASK_ID_KEY_PREFIX) {
48+
let (proving_task_key_bytes, _) = result.context("iter entry")?;
49+
let public_key =
50+
std::str::from_utf8(&proving_task_key_bytes[PROVING_TASK_ID_KEY_PREFIX.len()..])?;
51+
52+
let Some((coordinator_task, prover_task_id)) = db.get_task(public_key) else {
53+
continue;
54+
};
55+
56+
c2p.insert(coordinator_task.task_id.clone(), prover_task_id.clone());
57+
p2c.insert(prover_task_id, coordinator_task.task_id);
58+
}
59+
60+
match cli.commands {
61+
Commands::List => {
62+
for (c_task_id, p_task_id) in c2p.iter() {
63+
println!("{}\t{}", c_task_id, p_task_id);
64+
}
65+
}
66+
Commands::Get { commands } => match commands {
67+
GetCommands::Coordinator { task_id } => {
68+
if let Some(coordinator_task_id) = p2c.get(&task_id) {
69+
println!("{coordinator_task_id}");
70+
}
71+
}
72+
GetCommands::Prover { task_id } => {
73+
if let Some(prover_task_id) = c2p.get(&task_id) {
74+
println!("{prover_task_id}");
75+
}
76+
}
77+
},
78+
}
79+
80+
Ok(())
81+
}

0 commit comments

Comments
 (0)