Skip to content

Commit ea871af

Browse files
committed
Refactor code
1 parent 6edc47c commit ea871af

File tree

1 file changed

+60
-46
lines changed

1 file changed

+60
-46
lines changed

crates/task-sender/src/commands.rs

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -412,59 +412,27 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) {
412412
pub_path,
413413
} => {
414414
info!("Loading RISC Zero proof files");
415-
let Ok(proof) = std::fs::read(proof_path) else {
416-
error!("Could not read proof file: {}", proof_path);
417-
return;
418-
};
419-
let Ok(vm_program) = std::fs::read(bin_path) else {
420-
error!("Could not read bin file: {}", bin_path);
421-
return;
422-
};
423-
let pub_input = if let Some(pub_path) = pub_path {
424-
std::fs::read(pub_path).ok()
425-
} else {
426-
None
427-
};
428-
429-
// Create template verification data (without proof_generator_addr)
430-
vec![VerificationData {
431-
proving_system: ProvingSystemId::Risc0,
432-
proof,
433-
pub_input,
434-
verification_key: None,
435-
vm_program_code: Some(vm_program),
436-
proof_generator_addr: Address::zero(), // Will be set randomly in the loop
437-
}]
415+
match load_risc0_verification_data(proof_path, bin_path, pub_path) {
416+
Ok(data) => data,
417+
Err(err) => {
418+
error!("Failed to load RISC Zero files: {}", err);
419+
return;
420+
}
421+
}
438422
}
439423
InfiniteProofType::SP1 {
440424
proof_path,
441425
elf_path,
442426
pub_path,
443427
} => {
444428
info!("Loading SP1 proof files");
445-
let Ok(proof) = std::fs::read(proof_path) else {
446-
error!("Could not read proof file: {}", proof_path);
447-
return;
448-
};
449-
let Ok(vm_program) = std::fs::read(elf_path) else {
450-
error!("Could not read ELF file: {}", elf_path);
451-
return;
452-
};
453-
let pub_input = if let Some(pub_path) = pub_path {
454-
std::fs::read(pub_path).ok()
455-
} else {
456-
None
457-
};
458-
459-
// Create template verification data (without proof_generator_addr)
460-
vec![VerificationData {
461-
proving_system: ProvingSystemId::SP1,
462-
proof,
463-
pub_input,
464-
verification_key: None,
465-
vm_program_code: Some(vm_program),
466-
proof_generator_addr: Address::zero(), // Will be set randomly in the loop
467-
}]
429+
match load_sp1_verification_data(proof_path, elf_path, pub_path) {
430+
Ok(data) => data,
431+
Err(err) => {
432+
error!("Failed to load SP1 files: {}", err);
433+
return;
434+
}
435+
}
468436
}
469437
};
470438

@@ -590,3 +558,49 @@ fn get_verification_data_from_proofs_folder(
590558

591559
verifications_data
592560
}
561+
562+
fn load_risc0_verification_data(
563+
proof_path: &str,
564+
bin_path: &str,
565+
pub_path: &Option<String>,
566+
) -> Result<Vec<VerificationData>, std::io::Error> {
567+
let proof = std::fs::read(proof_path)?;
568+
let vm_program = std::fs::read(bin_path)?;
569+
let pub_input = if let Some(pub_path) = pub_path {
570+
std::fs::read(pub_path).ok()
571+
} else {
572+
None
573+
};
574+
575+
Ok(vec![VerificationData {
576+
proving_system: ProvingSystemId::Risc0,
577+
proof,
578+
pub_input,
579+
verification_key: None,
580+
vm_program_code: Some(vm_program),
581+
proof_generator_addr: Address::zero(),
582+
}])
583+
}
584+
585+
fn load_sp1_verification_data(
586+
proof_path: &str,
587+
elf_path: &str,
588+
pub_path: &Option<String>,
589+
) -> Result<Vec<VerificationData>, std::io::Error> {
590+
let proof = std::fs::read(proof_path)?;
591+
let vm_program = std::fs::read(elf_path)?;
592+
let pub_input = if let Some(pub_path) = pub_path {
593+
std::fs::read(pub_path).ok()
594+
} else {
595+
None
596+
};
597+
598+
Ok(vec![VerificationData {
599+
proving_system: ProvingSystemId::SP1,
600+
proof,
601+
pub_input,
602+
verification_key: None,
603+
vm_program_code: Some(vm_program),
604+
proof_generator_addr: Address::zero(),
605+
}])
606+
}

0 commit comments

Comments
 (0)