-
Notifications
You must be signed in to change notification settings - Fork 632
Optimization for prover (override #1774) #1783
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
base: develop
Are you sure you want to change the base?
Changes from all commits
bdf7826
9839bf7
d262a63
dc29c8c
af63bc0
5c2803c
5ae31bc
98be0a0
b244fa8
e852915
b833468
930a12a
3b174f8
74a3d7a
ede29c7
b270d96
79d79ed
d306b38
03b992f
492563f
6a57a2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| use async_trait::async_trait; | ||
| use libzkp::ProvingTaskExt; | ||
| use scroll_proving_sdk::prover::{ | ||
| proving_service::{ | ||
| GetVkRequest, GetVkResponse, ProveRequest, ProveResponse, QueryTaskRequest, | ||
| QueryTaskResponse, TaskStatus, | ||
| }, | ||
| ProvingService, | ||
| }; | ||
| use scroll_zkvm_types::ProvingTask; | ||
|
|
||
| #[derive(Default)] | ||
| pub struct Dumper { | ||
| #[allow(dead_code)] | ||
| pub target_path: String, | ||
| pub json_mode: bool, | ||
|
Comment on lines
+13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honor
🐛 Proposed fix fn dump(&self, input_string: &str) -> eyre::Result<()> {
let task: ProvingTaskExt = serde_json::from_str(input_string)?;
let task = ProvingTask::from(task);
+ let base_dir = if self.target_path.is_empty() {
+ std::path::Path::new(".")
+ } else {
+ std::path::Path::new(&self.target_path)
+ };
+ std::fs::create_dir_all(base_dir)?;
+
if self.json_mode {
- let file = std::fs::File::create("input_task.json")?;
+ let file = std::fs::File::create(base_dir.join("input_task.json"))?;
serde_json::to_writer(std::io::BufWriter::new(file), &task)?;
} else {
// stream-encode serialized_witness to input_task.bin using bincode 2.0
- let input_file = std::fs::File::create("input_task.bin")?;
+ let input_file = std::fs::File::create(base_dir.join("input_task.bin"))?;
let mut input_writer = std::io::BufWriter::new(input_file);
bincode::encode_into_std_write(
&task.serialized_witness,
&mut input_writer,
bincode::config::standard(),
)?;
// stream-encode aggregated_proofs to agg_proofs.bin using bincode 2.0
- let agg_file = std::fs::File::create("agg_proofs.bin")?;
+ let agg_file = std::fs::File::create(base_dir.join("agg_proofs.bin"))?;
let mut agg_writer = std::io::BufWriter::new(agg_file);
for proof in &task.aggregated_proofs {
let sz = bincode::serde::encode_into_std_write(
&proof.proofs,
&mut agg_writer,
bincode::config::standard(),
)?;
println!("written {sz} bytes for proof");
}
}Also applies to: 24-39 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| impl Dumper { | ||
| fn dump(&self, input_string: &str) -> eyre::Result<()> { | ||
| let task: ProvingTaskExt = serde_json::from_str(input_string)?; | ||
| let task = ProvingTask::from(task); | ||
|
|
||
| if self.json_mode { | ||
| let file = std::fs::File::create("input_task.json")?; | ||
| serde_json::to_writer(std::io::BufWriter::new(file), &task)?; | ||
| } else { | ||
| // stream-encode serialized_witness to input_task.bin using bincode 2.0 | ||
| let input_file = std::fs::File::create("input_task.bin")?; | ||
| let mut input_writer = std::io::BufWriter::new(input_file); | ||
| bincode::encode_into_std_write( | ||
| &task.serialized_witness, | ||
| &mut input_writer, | ||
| bincode::config::standard(), | ||
| )?; | ||
|
|
||
| // stream-encode aggregated_proofs to agg_proofs.bin using bincode 2.0 | ||
| let agg_file = std::fs::File::create("agg_proofs.bin")?; | ||
| let mut agg_writer = std::io::BufWriter::new(agg_file); | ||
| for proof in &task.aggregated_proofs { | ||
| let sz = bincode::serde::encode_into_std_write( | ||
| &proof.proofs, | ||
| &mut agg_writer, | ||
| bincode::config::standard(), | ||
| )?; | ||
| println!("written {sz} bytes for proof"); | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl ProvingService for Dumper { | ||
| fn is_local(&self) -> bool { | ||
| true | ||
| } | ||
| async fn get_vks(&self, _: GetVkRequest) -> GetVkResponse { | ||
| // get vk has been deprecated in new prover with dynamic asset loading scheme | ||
| GetVkResponse { | ||
| vks: vec![], | ||
| error: None, | ||
| } | ||
| } | ||
| async fn prove(&mut self, req: ProveRequest) -> ProveResponse { | ||
| let error = if let Err(e) = self.dump(&req.input) { | ||
| Some(format!("failed to dump: {}", e)) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| ProveResponse { | ||
| status: TaskStatus::Failed, | ||
| error, | ||
| ..Default::default() | ||
| } | ||
| } | ||
|
|
||
| async fn query_task(&mut self, req: QueryTaskRequest) -> QueryTaskResponse { | ||
| QueryTaskResponse { | ||
| task_id: req.task_id, | ||
| status: TaskStatus::Failed, | ||
| error: Some("dump file finished but need a fail return to exit".to_string()), | ||
| ..Default::default() | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,9 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mod dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mod prover; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mod types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mod zk_circuits_handler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use clap::{ArgAction, Parser, Subcommand}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use clap::{ArgAction, Parser, Subcommand, ValueEnum}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use prover::{LocalProver, LocalProverConfig}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use scroll_proving_sdk::{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prover::{types::ProofType, ProverBuilder}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -32,12 +33,35 @@ struct Args { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| command: Option<Commands>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[derive(Clone, Debug, PartialEq, Eq, ValueEnum)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enum TaskType { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Chunk, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Batch, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bundle, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| impl From<TaskType> for ProofType { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn from(value: TaskType) -> Self { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| match value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TaskType::Chunk => ProofType::Chunk, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TaskType::Batch => ProofType::Batch, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TaskType::Bundle => ProofType::Bundle, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[derive(Subcommand, Debug)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enum Commands { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Handle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// path to save the verifier's asset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task_path: String, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[arg(long = "json", default_value = "false")] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| json_mode: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+60
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's check the file at the specified lines
head -n 70 crates/prover-bin/src/main.rs | tail -n 20Repository: scroll-tech/scroll Length of output: 464 🏁 Script executed: # Let's also check the Cargo.toml to see which clap version is being used
cat crates/prover-bin/Cargo.toml | grep -A5 clapRepository: scroll-tech/scroll Length of output: 255 🏁 Script executed: # Let's look at more context around lines 60-61
sed -n '50,75p' crates/prover-bin/src/main.rsRepository: scroll-tech/scroll Length of output: 552 🏁 Script executed: # Let's check if there are other bool flags in the codebase and how they're defined
rg -B2 "bool," crates/prover-bin/src/main.rs | head -40Repository: scroll-tech/scroll Length of output: 258 🏁 Script executed: # Let's check if ArgAction is used elsewhere in the codebase
rg "ArgAction" crates/ --type rustRepository: scroll-tech/scroll Length of output: 228 🏁 Script executed: # Let's search for other #[arg] attributes to understand the pattern
rg "#\[arg\(" crates/prover-bin/src/main.rs -A1 -B1Repository: scroll-tech/scroll Length of output: 528 Use With 🔧 Suggested change- #[arg(long = "json", default_value = "false")]
+ #[arg(long = "json", action = ArgAction::SetTrue)]
json_mode: bool,📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task_type: TaskType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task_id: String, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[derive(Debug, serde::Deserialize)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -63,6 +87,26 @@ async fn main() -> eyre::Result<()> { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let local_prover = LocalProver::new(cfg.clone()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| match args.command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Some(Commands::Dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| json_mode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let prover = ProverBuilder::new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sdk_config, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dumper::Dumper { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| json_mode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ..Default::default() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .build() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .await | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map_err(|e| eyre::eyre!("build prover fail: {e}"))?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::sync::Arc::new(prover) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .one_shot(&[task_id], task_type.into()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .await; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+95
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's look at the specific file and lines mentioned
head -120 crates/prover-bin/src/main.rs | tail -40Repository: scroll-tech/scroll Length of output: 1372 🏁 Script executed: # Now let's find where one_shot is defined
rg "fn one_shot" --type rust -A 5Repository: scroll-tech/scroll Length of output: 44 🏁 Script executed: # Let's also search for the return type more broadly
rg "one_shot" crates/prover-bin/src/main.rs -B 2 -A 10Repository: scroll-tech/scroll Length of output: 1455 🏁 Script executed: # Search for one_shot method definition
fd "\.rs$" crates/ | xargs rg "fn one_shot" -B 2 -A 8Repository: scroll-tech/scroll Length of output: 46 🏁 Script executed: # Also search in the prover crate
find . -name "*.rs" -type f | xargs rg "fn one_shot" -B 2 -A 8 | head -50Repository: scroll-tech/scroll Length of output: 44 🏁 Script executed: # Try to find the type definition by looking for impl blocks or traits
rg "impl.*one_shot|trait.*Prover" -B 2 -A 10 | head -100Repository: scroll-tech/scroll Length of output: 44 🏁 Script executed: # Check what ProverBuilder builds to understand the prover type
rg "ProverBuilder" crates/prover-bin/src/main.rs -B 5 -A 15 | head -80Repository: scroll-tech/scroll Length of output: 2387 🏁 Script executed: # Let's look at the scroll_proving_sdk crate to find the one_shot definition
find . -path "*/scroll_proving_sdk/*" -name "*.rs" | head -20Repository: scroll-tech/scroll Length of output: 44 🏁 Script executed: # Check for prover definitions in the prover crate
find . -path "*/prover/*" -name "*.rs" -type f | head -30Repository: scroll-tech/scroll Length of output: 44 🏁 Script executed: # List the crates directory to understand the structure
ls -la crates/ | head -30Repository: scroll-tech/scroll Length of output: 402 🏁 Script executed: # Search for one_shot across all rust files more broadly
rg "fn one_shot" . --type rustRepository: scroll-tech/scroll Length of output: 44 🏁 Script executed: # Try to find where ProverBuilder is defined
rg "pub.*struct ProverBuilder|impl ProverBuilder" . --type rust -A 3Repository: scroll-tech/scroll Length of output: 44 🏁 Script executed: # Check the Cargo.toml in prover-bin to see where ProverBuilder comes from
cat crates/prover-bin/Cargo.tomlRepository: scroll-tech/scroll Length of output: 1152 🏁 Script executed: # Look at the entire repository structure to find scroll_proving_sdk
find . -name "*proving*" -o -name "*prover*" | grep -E "(\.rs$|\.toml$)" | head -30Repository: scroll-tech/scroll Length of output: 95 🏁 Script executed: # Search for scroll_proving_sdk in git ls-files
git ls-files | grep -E "scroll_proving_sdk|prover" | head -50Repository: scroll-tech/scroll Length of output: 2303 🏁 Script executed: # Let's check the prover.rs file in prover-bin to see how one_shot is used there
cat crates/prover-bin/src/prover.rsRepository: scroll-tech/scroll Length of output: 12441 🏁 Script executed: # Check imports and see if there are any type hints about one_shot
head -50 crates/prover-bin/src/main.rsRepository: scroll-tech/scroll Length of output: 1262 Handle The Dump command path ignores the return value of 🔧 Suggested change- std::sync::Arc::new(prover)
- .one_shot(&[task_id], task_type.into())
- .await;
+ let success = std::sync::Arc::new(prover)
+ .one_shot(&[task_id], task_type.into())
+ .await;
+ if !success {
+ eyre::bail!("dump failed for task_id={task_id}");
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Some(Commands::Handle { task_path }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let file = File::open(Path::new(&task_path))?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let reader = BufReader::new(file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: scroll-tech/scroll
Length of output: 1322
🏁 Script executed:
Repository: scroll-tech/scroll
Length of output: 451
🏁 Script executed:
Repository: scroll-tech/scroll
Length of output: 272
🏁 Script executed:
Repository: scroll-tech/scroll
Length of output: 6331
Update the OpenVM version comment from 1.4.2 to 1.4.3.
The Cargo.lock file shows OpenVM 1.4.3 is the actual dependency version, but the comment on line 20 references 1.4.2. Update the comment to reflect the correct version.
Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents