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

Add injection of prover files #7

Open
wants to merge 1 commit into
base: testnet3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions synthesizer/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ impl<N: Network> Process<N> {
Ok(process)
}

#[inline]
#[cfg(feature = "wasm")]
pub fn load_inclusion_proving_key() -> ProvingKey<N> {
return ProvingKey::<N>::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)]
Expand Down
35 changes: 35 additions & 0 deletions synthesizer/src/process/stack/inclusion/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,41 @@ impl<N: Network> Inclusion<N> {
}
}

pub fn prove_execution_web<A: circuit::Aleo<Network = N>, R: Rng + CryptoRng>(
&self,
execution: Execution<N>,
assignments: &[InclusionAssignment<N>],
global_state_root: N::StateRoot,
rng: &mut R,
inclusion_proving_key: Option<ProvingKey<N>>,
) -> Result<Execution<N>> {
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::<N>::new(N::inclusion_proving_key().clone()));

// Compute the inclusion batch proof.
let (global_state_root, inclusion_proof) = Self::prove_batch::<A, R>(&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<N>) -> Result<()> {
Expand Down