-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Sindri proof executor #82
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
Changes from all commits
582e3e1
f69eefd
db7140c
b66181a
e007679
d70f0ec
9662d46
6c21a17
e9f9d5f
6f739a5
5f1b941
5d8f23a
3d220a7
4686ef8
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,8 @@ | ||
| { | ||
| "$schema": "https://sindri.app/api/v1/sindri-manifest-schema.json", | ||
| "name": "pessimistic-proof", | ||
| "circuitType": "sp1", | ||
| "provingScheme": "plonk", | ||
| "sp1Version": "4.0.0", | ||
| "elfPath": "elf/riscv32im-succinct-zkvm-elf" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
|
|
||
| [primary-prover.sindri-prover] | ||
| proving-request-timeout = "5m" | ||
| proving-timeout = "10m" | ||
|
Author
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. As you are running tests, you may notice that the |
||
| project-name = "pessimistic-proof" | ||
| project-tag = "latest" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,10 @@ use std::{ | |
| }; | ||
|
|
||
| pub use error::Error; | ||
| use error::ProofVerificationError; | ||
| use futures::{Future, TryFutureExt}; | ||
| use prover_config::ProverType; | ||
| use sindri::{client::SindriClient, integrations::sp1_v4::SP1ProofInfo, JobStatus, ProofInput}; | ||
| use sp1_sdk::{ | ||
| network::{prover::NetworkProver, FulfillmentStrategy}, | ||
| CpuProver, Prover, ProverClient, SP1ProofWithPublicValues, SP1ProvingKey, SP1Stdin, | ||
|
|
@@ -137,6 +139,22 @@ impl Executor { | |
| ) | ||
| } | ||
| ProverType::GpuProver(_) => todo!(), | ||
| ProverType::SindriProver(sindri_prover_config) => { | ||
| debug!("Creating Sindri prover executor..."); | ||
| let mut sindri_client = SindriClient::default(); | ||
| sindri_client.polling_options.timeout = Some(sindri_prover_config.proving_timeout); | ||
| let verification_key = Self::get_vkey(program); | ||
| Self::build_network_service( | ||
| sindri_prover_config.get_proving_request_timeout(), | ||
| SindriExecutor { | ||
| prover: Arc::new(sindri_client), | ||
| verification_key, | ||
| timeout: sindri_prover_config.proving_timeout, | ||
| project_name: sindri_prover_config.project_name.clone(), | ||
| project_tag: sindri_prover_config.project_tag.clone(), | ||
| }, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -293,3 +311,83 @@ impl Service<Request> for NetworkExecutor { | |
| Box::pin(fut) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| struct SindriExecutor { | ||
| prover: Arc<SindriClient>, | ||
| verification_key: SP1VerifyingKey, | ||
| timeout: Duration, | ||
| project_name: String, | ||
| project_tag: String, | ||
| } | ||
|
|
||
| impl Service<Request> for SindriExecutor { | ||
| type Response = Response; | ||
|
|
||
| type Error = Error; | ||
|
|
||
| type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>; | ||
|
|
||
| fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
| Poll::Ready(Ok(())) | ||
| } | ||
|
|
||
| fn call(&mut self, req: Request) -> Self::Future { | ||
| let prover = self.prover.clone(); | ||
| let stdin = req.stdin; | ||
| let verification_key = self.verification_key.clone(); | ||
| let timeout = self.timeout; | ||
| let project_name = self.project_name.clone(); | ||
| let project_tag = self.project_tag.clone(); | ||
|
|
||
| debug!("Proving with network prover with timeout: {:?}", timeout); | ||
| let fut = async move { | ||
| debug!("Starting the proving of the requested MultiBatchHeader"); | ||
|
|
||
| // Convert Sp1Stdin type to the Sindri client's ProofInput type | ||
| let proof_input = ProofInput::try_from(stdin) | ||
| .map_err(|error| Error::ProverFailed(error.to_string()))?; | ||
|
|
||
| // Submit the proof request, and poll until the job is completed or a | ||
| // timeout occurs. The Sindri client was passed the timeout parameter | ||
| // upon creation | ||
| let proof_response = prover | ||
| .prove_circuit( | ||
| &format!("{}:{}", project_name, project_tag), | ||
| proof_input, | ||
| None, | ||
| None, | ||
| None, | ||
| ) | ||
| .await | ||
| .map_err(|error| Error::ProverFailed(error.to_string()))?; | ||
|
|
||
| // If the Sindri job completed with an error, retrieve the error message | ||
| if proof_response.status == JobStatus::Failed { | ||
| return Err(Error::ProverFailed( | ||
| proof_response.error.flatten().unwrap_or( | ||
| "Sindri job was marked as failed. No error message was provided." | ||
| .to_string(), | ||
| ), | ||
| )); | ||
| } | ||
|
Comment on lines
+366
to
+373
Author
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. While errors related to authorization or some other configuration issue are caught by the |
||
|
|
||
| // Convert the proof response to a SP1 proof with public values | ||
| let proof = proof_response | ||
| .to_sp1_proof_with_public() | ||
| .map_err(|error| Error::ProverFailed(error.to_string()))?; | ||
|
|
||
| debug!("Proving completed. Verifying the proof..."); | ||
| proof_response | ||
| .verify_sp1_proof_locally(&verification_key) | ||
| .map_err(|error| { | ||
| Error::ProofVerificationFailed(ProofVerificationError::Plonk(error.to_string())) | ||
| })?; | ||
|
|
||
| debug!("Proof verification completed successfully"); | ||
| Ok(Response { proof }) | ||
| }; | ||
|
|
||
| Box::pin(fut) | ||
| } | ||
| } | ||
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.
These three fields should be fixed while you pin to Sp1 v4.0.0, but the other fields (
nameandelfPath) are flexible. As mentioned in the PR descriptionnameis fully up to your team. TheelfPathprovides the relative path from this Sindri manifest to the compiled ELF.