diff --git a/synthesizer/src/process/mod.rs b/synthesizer/src/process/mod.rs index b6d6a15853..81a6b1d407 100644 --- a/synthesizer/src/process/mod.rs +++ b/synthesizer/src/process/mod.rs @@ -177,6 +177,13 @@ impl Process { Ok(process) } + #[inline] + #[cfg(feature = "wasm")] + pub fn load_inclusion_proving_key() -> ProvingKey { + return ProvingKey::::new(N::inclusion_proving_key().clone()); + } + + /// Initializes a new process with a cache of previously used keys. This version is suitable for tests /// (which often use nested loops that keep reusing those), as their deserialization is slow. #[cfg(test)] diff --git a/synthesizer/src/process/stack/inclusion/execute.rs b/synthesizer/src/process/stack/inclusion/execute.rs index b27c57fdc7..ce834c3721 100644 --- a/synthesizer/src/process/stack/inclusion/execute.rs +++ b/synthesizer/src/process/stack/inclusion/execute.rs @@ -164,6 +164,41 @@ impl Inclusion { } } + pub fn prove_execution_web, R: Rng + CryptoRng>( + &self, + execution: Execution, + assignments: &[InclusionAssignment], + global_state_root: N::StateRoot, + rng: &mut R, + inclusion_proving_key: Option>, + ) -> Result> { + match assignments.is_empty() { + true => { + // Ensure the global state root is not zero. + if *global_state_root == Field::zero() { + bail!("Inclusion expected the global state root in the execution to *not* be zero") + } + + // Ensure the inclusion proof in the execution is 'None'. + if execution.inclusion_proof().is_some() { + bail!("Inclusion expected the inclusion proof in the execution to be 'None'") + } + // Return the execution. + Execution::from(execution.into_transitions(), global_state_root, None) + } + false => { + // Fetch the inclusion proving key. + let proving_key = inclusion_proving_key + .unwrap_or_else(|| ProvingKey::::new(N::inclusion_proving_key().clone())); + + // Compute the inclusion batch proof. + let (global_state_root, inclusion_proof) = Self::prove_batch::(&proving_key, assignments, rng)?; + // Return the execution. + Execution::from(execution.into_transitions(), global_state_root, Some(inclusion_proof)) + } + } + } + /// Checks the inclusion proof for the execution. /// Note: This does *not* check that the global state root exists in the ledger. pub fn verify_execution(execution: &Execution) -> Result<()> {