Skip to content
Merged
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
71 changes: 39 additions & 32 deletions expander_compiler/src/zkcuda/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{circuit::config::Config, utils::pool::Pool};
use super::{
kernel::{shape_prepend, Kernel, Shape},
proof::{ComputationGraph, ProofTemplate},
proving_system::{Commitment, ExpanderGKRProvingSystem, ProvingSystem},
proving_system::{ExpanderGKRProvingSystem, ProvingSystem},
vec_shaped::{flatten_shaped, unflatten_shaped, VecShaped},
};

Expand Down Expand Up @@ -50,7 +50,7 @@ pub struct Context<
}

pub struct CombinedProof<C: Config, P: ProvingSystem<C> = ExpanderGKRProvingSystem<C>> {
pub commitments: Vec<P::Commitment>,
pub commitments: Vec<Vec<P::Commitment>>, // a vector of commitments for each kernel
pub proofs: Vec<P::Proof>,
}

Expand All @@ -61,7 +61,7 @@ impl<C: Config, P: ProvingSystem<C>> ExpSerde for CombinedProof<C, P> {
self.proofs.serialize_into(&mut writer)
}
fn deserialize_from<R: std::io::Read>(mut reader: R) -> serdes::SerdeResult<Self> {
let commitments = Vec::<P::Commitment>::deserialize_from(&mut reader)?;
let commitments = Vec::<Vec<P::Commitment>>::deserialize_from(&mut reader)?;
let proofs = Vec::<P::Proof>::deserialize_from(&mut reader)?;
Ok(CombinedProof {
commitments,
Expand Down Expand Up @@ -575,27 +575,35 @@ impl<C: Config, P: ProvingSystem<C>, H: HintCaller<C::CircuitField>> Context<C,

pub fn to_proof(self, prover_setup: &P::ProverSetup) -> CombinedProof<C, P> {
let commitments = self
.device_memories
.proof_templates
.iter()
.map(|x| P::commit(prover_setup, &x.values))
.map(|template| {
template
.commitment_indices
.iter()
.zip(template.is_broadcast.iter())
.map(|(x, is_broadcast)| {
P::commit(
prover_setup,
&self.device_memories[*x].values,
next_power_of_two(template.parallel_count),
*is_broadcast,
)
})
.unzip::<_, _, Vec<_>, Vec<_>>()
})
.collect::<Vec<_>>();
let proofs = self

let proofs: Vec<P::Proof> = self
.proof_templates
.iter()
.map(|template| {
.zip(commitments.iter())
.map(|(template, commitments_kernel)| {
P::prove(
prover_setup,
self.kernels.get(template.kernel_id),
&template
.commitment_indices
.iter()
.map(|x| &commitments[*x].0)
.collect::<Vec<_>>(),
&template
.commitment_indices
.iter()
.map(|x| &commitments[*x].1)
.collect::<Vec<_>>(),
&commitments_kernel.0,
&commitments_kernel.1,
&template
.commitment_indices
.iter()
Expand All @@ -606,6 +614,7 @@ impl<C: Config, P: ProvingSystem<C>, H: HintCaller<C::CircuitField>> Context<C,
)
})
.collect::<Vec<_>>();

CombinedProof {
commitments: commitments.into_iter().map(|x| x.0).collect(),
proofs,
Expand All @@ -619,29 +628,27 @@ impl<C: Config> ComputationGraph<C> {
combined_proof: &CombinedProof<C, P>,
verifier_setup: &P::VerifierSetup,
) -> bool {
for (commitment, len) in combined_proof
.commitments
.iter()
.zip(self.commitments_lens.iter())
{
if commitment.vals_len() != *len {
return false;
}
}
for (proof, template) in combined_proof
// TODO: Add a proper check
// for (commitment, len) in combined_proof
// .commitments
// .iter()
// .zip(self.commitments_lens.iter())
// {
// if commitment.vals_len() != *len {
// return false;
// }
// }
for ((proof, template), commitments_kernel) in combined_proof
.proofs
.iter()
.zip(self.proof_templates.iter())
.zip(combined_proof.commitments.iter())
{
if !P::verify(
verifier_setup,
&self.kernels[template.kernel_id],
proof,
&template
.commitment_indices
.iter()
.map(|&x| &combined_proof.commitments[x])
.collect::<Vec<_>>(),
commitments_kernel,
next_power_of_two(template.parallel_count),
&template.is_broadcast,
) {
Expand Down
11 changes: 6 additions & 5 deletions expander_compiler/src/zkcuda/proving_system/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ impl<C: Config> ProvingSystem<C> for DummyProvingSystem<C> {

fn commit(
_prover_setup: &Self::ProverSetup,
vals: &Vec<<C as Config>::DefaultSimdField>,
vals: &[<C as Config>::DefaultSimdField],
_parallel_count: usize,
_is_broadcast: bool,
) -> (Self::Commitment, Self::CommitmentExtraInfo) {
println!("Real Commit to {} values", vals.len());
assert!(vals.len() & (vals.len() - 1) == 0);
(
DummyCommitment {
Expand All @@ -91,8 +92,8 @@ impl<C: Config> ProvingSystem<C> for DummyProvingSystem<C> {
fn prove(
_prover_setup: &Self::ProverSetup,
kernel: &Kernel<C>,
_commitments: &[&Self::Commitment],
_commitments_extra_info: &[&Self::CommitmentExtraInfo],
_commitments: &[Self::Commitment],
_commitments_extra_info: &[Self::CommitmentExtraInfo],
commitments_values: &[&[C::DefaultSimdField]],
parallel_count: usize,
is_broadcast: &[bool],
Expand All @@ -117,7 +118,7 @@ impl<C: Config> ProvingSystem<C> for DummyProvingSystem<C> {
_verifier_setup: &Self::VerifierSetup,
kernel: &Kernel<C>,
proof: &Self::Proof,
commitments: &[&Self::Commitment],
commitments: &[Self::Commitment],
parallel_count: usize,
is_broadcast: &[bool],
) -> bool {
Expand Down
Loading