Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Jan 11, 2025
1 parent 8f8eb34 commit a505a1d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
31 changes: 22 additions & 9 deletions crates/core/executor/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,31 @@ pub struct SP1Context<'a> {
/// The maximum number of cpu cycles to use for execution.
pub max_cycles: Option<u64>,

/// Skip deferred proof verification.
pub skip_deferred_proof_verification: bool,
/// Deferred proof verification.
pub deferred_proof_verification: bool,
}

/// A builder for [`SP1Context`].
#[derive(Clone, Default)]
#[derive(Clone)]
pub struct SP1ContextBuilder<'a> {
no_default_hooks: bool,
hook_registry_entries: Vec<(u32, BoxedHook<'a>)>,
subproof_verifier: Option<&'a dyn SubproofVerifier>,
max_cycles: Option<u64>,
skip_deferred_proof_verification: bool,
deferred_proof_verification: bool,
}

impl<'a> Default for SP1ContextBuilder<'a> {
fn default() -> Self {
Self {
no_default_hooks: false,
hook_registry_entries: Vec::new(),
subproof_verifier: None,
max_cycles: None,
// Always verify deferred proofs by default.
deferred_proof_verification: true,
}
}
}

impl<'a> SP1Context<'a> {
Expand Down Expand Up @@ -86,12 +99,12 @@ impl<'a> SP1ContextBuilder<'a> {

let subproof_verifier = take(&mut self.subproof_verifier);
let cycle_limit = take(&mut self.max_cycles);
let skip_deferred_proof_verification = take(&mut self.skip_deferred_proof_verification);
let deferred_proof_verification = take(&mut self.deferred_proof_verification);
SP1Context {
hook_registry,
subproof_verifier,
max_cycles: cycle_limit,
skip_deferred_proof_verification,
deferred_proof_verification,
}
}

Expand Down Expand Up @@ -137,9 +150,9 @@ impl<'a> SP1ContextBuilder<'a> {
self
}

/// Set the skip deferred proof verification flag.
pub fn set_skip_deferred_proof_verification(&mut self, skip: bool) -> &mut Self {
self.skip_deferred_proof_verification = skip;
/// Set the deferred proof verification flag.
pub fn set_deferred_proof_verification(&mut self, value: bool) -> &mut Self {
self.deferred_proof_verification = value;
self
}
}
Expand Down
16 changes: 11 additions & 5 deletions crates/core/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ pub enum DeferredProofVerification {
Disabled,
}

impl From<bool> for DeferredProofVerification {
fn from(value: bool) -> Self {
if value {
DeferredProofVerification::Enabled
} else {
DeferredProofVerification::Disabled
}
}
}

/// An executor for the SP1 RISC-V zkVM.
///
/// The exeuctor is responsible for executing a user program and tracing important events which
Expand Down Expand Up @@ -330,11 +340,7 @@ impl<'a> Executor<'a> {
hook_registry,
opts,
max_cycles: context.max_cycles,
deferred_proof_verification: if context.skip_deferred_proof_verification {
DeferredProofVerification::Disabled
} else {
DeferredProofVerification::Enabled
},
deferred_proof_verification: context.deferred_proof_verification.into(),
memory_checkpoint: Memory::default(),
uninitialized_memory_checkpoint: Memory::default(),
local_memory_access: HashMap::new(),
Expand Down
13 changes: 7 additions & 6 deletions crates/sdk/src/cpu/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ impl<'a> CpuExecuteBuilder<'a> {
self
}

/// Whether to skip deferred proof verification in the executor.
/// Whether to enable deferred proof verification in the executor.
///
/// # Arguments
/// * `value` - Whether to skip deferred proof verification.
/// * `value` - Whether to enable deferred proof verification.
///
/// # Details
/// If set to `true`, the executor will skip the deferred proof verification step. This is useful
/// for reducing the execution time of the program and optimistically assuming that the
/// deferred proofs are correct.
/// Default: `true`. If set to `false`, the executor will skip deferred proof verification.
/// This is useful for reducing the execution time of the program and optimistically assuming
/// that the deferred proofs are correct. Can also be used for mock proof setups that require
/// verifying mock compressed proofs.
///
/// # Example
/// ```rust,no_run
Expand All @@ -108,7 +109,7 @@ impl<'a> CpuExecuteBuilder<'a> {
/// ```
#[must_use]
pub fn deferred_proof_verification(mut self, value: bool) -> Self {
self.context_builder.set_skip_deferred_proof_verification(!value);
self.context_builder.set_deferred_proof_verification(value);
self
}

Expand Down
6 changes: 3 additions & 3 deletions crates/sdk/src/cpu/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ impl<'a> CpuProveBuilder<'a> {
self
}

/// Set the skip deferred proof verification flag.
/// Set the deferred proof verification flag.
///
/// # Details
/// If set to `true`, the prover will skip the deferred proof verification step in the executor.
/// If set to `false`, the prover will skip deferred proof verification in the executor.
/// This is useful for reducing the amount of time it takes to execute the program.
///
/// # Example
Expand All @@ -253,7 +253,7 @@ impl<'a> CpuProveBuilder<'a> {
/// ```
#[must_use]
pub fn deferred_proof_verification(mut self, value: bool) -> Self {
self.context_builder.set_skip_deferred_proof_verification(value);
self.context_builder.set_deferred_proof_verification(value);
self
}

Expand Down

0 comments on commit a505a1d

Please sign in to comment.