Skip to content
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

feat: SDK refactor #1855

Draft
wants to merge 55 commits into
base: dev
Choose a base branch
from
Draft

feat: SDK refactor #1855

wants to merge 55 commits into from

Conversation

mattstam
Copy link
Contributor

@mattstam mattstam commented Dec 10, 2024

API:

    // Local

    // Generate the proof.
    let client = ProverClient::builder()
        .local()
        .build();

    // Generate the proving key and verifying key for the given program.
    let pk = client.setup(&elf).await;

    // Generate the proof.
    let proof_result = client
        .prove(&pk, stdin)
        .compressed()
        .await;
        
    // Network

    // Generate the proof, using the specified network configuration.
    let client = ProverClient::builder()
        .network()
        .rpc_url(rpc_url)
        .private_key(private_key)
        .build();

    // Generate the proving key and verifying key for the given program.
    let pk = client.setup(Arc::from(&ELF[..])).await;

    // Generate the proof.
    let proof_result = client
        .prove(&pk, stdin)
        .compressed()
        .timeout(100)
        .cycle_limit(20_000)
        .await;

    // Old env var behavior
    
    let client = ProverClient::builder()
        .from_env();

crates/sdk/src/builder.rs Outdated Show resolved Hide resolved
@mattstam mattstam force-pushed the mattstam/sdk-refactor-proposal branch from 017d5de to 051545c Compare December 10, 2024 22:08
crates/sdk/src/local.rs Outdated Show resolved Hide resolved
crates/sdk/src/network.rs Outdated Show resolved Hide resolved
crates/sdk/src/request.rs Outdated Show resolved Hide resolved
crates/sdk/src/prover.rs Outdated Show resolved Hide resolved
crates/sdk/src/client.rs Outdated Show resolved Hide resolved
crates/sdk/src/request.rs Outdated Show resolved Hide resolved
crates/sdk/src/prover.rs Outdated Show resolved Hide resolved
crates/sdk/src/prover.rs Outdated Show resolved Hide resolved
crates/sdk/src/network.rs Outdated Show resolved Hide resolved
crates/sdk/src/local.rs Outdated Show resolved Hide resolved
@mattstam mattstam force-pushed the mattstam/sdk-refactor-proposal branch from 7dca438 to 6ceb9dd Compare December 11, 2024 00:45
/// Verify that an SP1 proof is valid given its vkey and metadata.
/// For Plonk proofs, verifies that the public inputs of the PlonkBn254 proof match
/// the hash of the VK and the committed public values of the SP1ProofWithPublicValues.
pub fn verify(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on putting this on a seperate func? I guess this was the reason we previously had a CpuProver wrapper over SP1Prover<DefaultProverComponents> so we could attach this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I think we need to expose verify somehow but lets revisit towards the end

crates/sdk/src/mode.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@nhtyy nhtyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okie looking good,

Some issues with async stuff though, lets remove ProofRequest traits, so users dont need to import it to use it, and make sure any method called run is not async.

So LocalProofRequest run just calls prove on the underlying sp1_prover, and its IntoFuture will just do a tokio::task::spawn_blocking

Now for Network its run either needs to use the blocking methods on the client if they exist or create a new runtime and block on that.

And finally for DynProofRequest its run method calls prover.prove_with_options_sync and its into future method will call prove_with_options

Self::create_from_env()
}

fn create_from_env() -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think that the DynBuilder should also expose default_{cycle_limt, timeout}?

I think that we should remove this method "create_from_env" and make the method like "build_with_env" that than overrides stuff at the end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean as methods? Currently I have:

/// The default timeout seconds for a proof request to be generated (4 hours).
pub const DEFAULT_TIMEOUT: u64 = 14400;

/// The default cycle limit for a proof request.
pub const DEFAULT_CYCLE_LIMIT: u64 = 100_000_000;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yaa I think since these are common defaults we can optionally let the user set them at builder level wdyt? Otherwise default to these

crates/sdk/src/client.rs Outdated Show resolved Hide resolved
crates/sdk/src/client.rs Outdated Show resolved Hide resolved
crates/sdk/src/local.rs Outdated Show resolved Hide resolved
crates/sdk/src/local.rs Outdated Show resolved Hide resolved
crates/sdk/src/prover.rs Show resolved Hide resolved
crates/sdk/src/prover.rs Outdated Show resolved Hide resolved
crates/sdk/src/request.rs Outdated Show resolved Hide resolved
/// Verify that an SP1 proof is valid given its vkey and metadata.
/// For Plonk proofs, verifies that the public inputs of the PlonkBn254 proof match
/// the hash of the VK and the committed public values of the SP1ProofWithPublicValues.
pub fn verify(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I think we need to expose verify somehow but lets revisit towards the end

crates/sdk/src/local.rs Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Dec 12, 2024

SP1 Performance Test Results

Branch: mattstam/sdk-refactor-proposal
Commit: 95e2a13
Author: mattstam

program cycles execute (mHz) core (kHZ) compress (KHz) time success
fibonacci 11291 0.18 2.75 0.46 25s
ssz-withdrawals 2757356 16.49 126.37 34.58 1m20s
tendermint 12593597 6.71 265.90 98.11 2m10s

@nhtyy nhtyy force-pushed the mattstam/sdk-refactor-proposal branch from 217abfa to 2873a73 Compare December 12, 2024 02:18
@mattstam mattstam changed the title design: SDK refactor feat: SDK refactor Dec 12, 2024
use std::sync::Arc;

/// The ELF we want to execute inside the zkVM.
const ELF: &[u8] = include_elf!("fibonacci-program");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: we will update this macro to return an Arc so its easy

@@ -1,142 +0,0 @@
use std::{borrow::Cow, str::FromStr};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I am nuking v1 and I will convert network-v2 to just network (after review because otherwise diff would be nightmarish)

@nhtyy nhtyy force-pushed the mattstam/sdk-refactor-proposal branch from 7f559a2 to 4e4e8c4 Compare December 12, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants