Skip to content

Commit

Permalink
Debugging bridge circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
iquerejeta committed Nov 26, 2024
1 parent be92a55 commit b4604d4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 71 deletions.
6 changes: 5 additions & 1 deletion halo2_backend/src/plonk/vanishing/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ impl<C: CurveAffine> PartiallyEvaluated<C> {
y: ChallengeY<C>,
xn: C::Scalar,
) -> Evaluated<C, P::MSM> {
let expected_h_eval = expressions.fold(C::Scalar::ZERO, |h_eval, v| h_eval * *y + v);
let expected_h_eval = expressions.fold(C::Scalar::ZERO, |h_eval, v| {
dbg!(&v);
h_eval * *y + v
});
let expected_h_eval = expected_h_eval * ((xn - C::Scalar::ONE).invert().unwrap());

let h_commitment =
Expand Down Expand Up @@ -122,6 +125,7 @@ impl<C: CurveAffine, M: MSM<C>> Evaluated<C, M> {
&self,
x: ChallengeX<C>,
) -> impl Iterator<Item = VerifierQuery<C, M>> + Clone {
dbg!(&self.expected_h_eval);
iter::empty()
.chain(Some(VerifierQuery::new_msm(
&self.h_commitment,
Expand Down
84 changes: 42 additions & 42 deletions halo2_backend/src/plonk/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,17 @@ where
})
.collect::<Result<Vec<_>, _>>()?;

// [TRANSCRIPT-11]
let shuffles_committed = (0..num_proofs)
.map(|_| -> Result<Vec<_>, _> {
// Hash each shuffle product commitment
vk.cs
.shuffles
.iter()
.map(|_argument| shuffle_read_product_commitment(transcript))
.collect::<Result<Vec<_>, _>>()
})
.collect::<Result<Vec<_>, _>>()?;
// // [TRANSCRIPT-11]
// let shuffles_committed = (0..num_proofs)
// .map(|_| -> Result<Vec<_>, _> {
// // Hash each shuffle product commitment
// vk.cs
// .shuffles
// .iter()
// .map(|_argument| shuffle_read_product_commitment(transcript))
// .collect::<Result<Vec<_>, _>>()
// })
// .collect::<Result<Vec<_>, _>>()?;

// 8. Read vanishing argument (before y) ------------------------------------------------------
// [TRANSCRIPT-12]
Expand Down Expand Up @@ -344,16 +344,16 @@ where
})
.collect::<Result<Vec<_>, _>>()?;

// [TRANSCRIPT-23]
let shuffles_evaluated = shuffles_committed
.into_iter()
.map(|shuffles| -> Result<Vec<_>, _> {
shuffles
.into_iter()
.map(|shuffle| shuffle.evaluate(transcript))
.collect::<Result<Vec<_>, _>>()
})
.collect::<Result<Vec<_>, _>>()?;
// // [TRANSCRIPT-23]
// let shuffles_evaluated = shuffles_committed
// .into_iter()
// .map(|shuffles| -> Result<Vec<_>, _> {
// shuffles
// .into_iter()
// .map(|shuffle| shuffle.evaluate(transcript))
// .collect::<Result<Vec<_>, _>>()
// })
// .collect::<Result<Vec<_>, _>>()?;

// This check ensures the circuit is satisfied so long as the polynomial
// commitments open to the correct values.
Expand All @@ -378,9 +378,9 @@ where
.zip(instance_evals.iter())
.zip(permutations_evaluated.iter())
.zip(lookups_evaluated.iter())
.zip(shuffles_evaluated.iter())
// .zip(shuffles_evaluated.iter())
.flat_map(
|((((advice_evals, instance_evals), permutation), lookups), shuffles)| {
|(((advice_evals, instance_evals), permutation), lookups)| {
let challenges = &challenges;
let fixed_evals = &fixed_evals;
std::iter::empty()
Expand Down Expand Up @@ -432,22 +432,22 @@ where
)
},
))
.chain(shuffles.iter().zip(vk.cs.shuffles.iter()).flat_map(
move |(p, argument)| {
p.expressions(
l_0,
l_last,
l_blind,
argument,
theta,
gamma,
advice_evals,
fixed_evals,
instance_evals,
challenges,
)
},
))
// .chain(shuffles.iter().zip(vk.cs.shuffles.iter()).flat_map(
// move |(p, argument)| {
// p.expressions(
// l_0,
// l_last,
// l_blind,
// argument,
// theta,
// gamma,
// advice_evals,
// fixed_evals,
// instance_evals,
// challenges,
// )
// },
// ))
},
);

Expand All @@ -462,8 +462,8 @@ where
.zip(advice_evals.iter())
.zip(permutations_evaluated.iter())
.zip(lookups_evaluated.iter())
.zip(shuffles_evaluated.iter())
.flat_map(|((((((instance_commitments, instance_evals), advice_commitments),advice_evals),permutation),lookups),shuffles)| {
// .zip(shuffles_evaluated.iter())
.flat_map(|(((((instance_commitments, instance_evals), advice_commitments),advice_evals),permutation),lookups)| {
iter::empty()
.chain(
V::QUERY_INSTANCE
Expand All @@ -490,7 +490,7 @@ where
))
.chain(permutation.queries(vk, x))
.chain(lookups.iter().flat_map(move |p| p.queries(vk, x)))
.chain(shuffles.iter().flat_map(move |p| p.queries(vk, x)))
// .chain(shuffles.iter().flat_map(move |p| p.queries(vk, x)))
},
)
.chain(
Expand Down
29 changes: 1 addition & 28 deletions halo2_backend/src/poly/kzg/multiopen/gwc/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,33 +152,6 @@ where
.to_affine()
};

transcript.write_point(pi)?;

let final_poly_com = self.params.commit(engine, &final_poly, Blind::default());

let mut msm_accumulator = DualMSM::new();

// Scale commitment
let mut commitment = MSMKZG::<E>::new();
commitment.append_term(E::Fr::ONE, final_poly_com);

let mut pi_msm = MSMKZG::<E>::new();
pi_msm.append_term(E::Fr::ONE, pi.into());

// Scale zπ
let mut scaled_pi = MSMKZG::<E>::new();
scaled_pi.append_term(x3, pi.into());

// (π, C − vG + zπ)
msm_accumulator.left.add_msm(&pi_msm);

msm_accumulator.right.add_msm(&commitment); // C
let g0: E::G1 = self.params.g[0].into();
msm_accumulator.right.append_term(v, -g0); // -vG
msm_accumulator.right.add_msm(&scaled_pi); // zπ

// FIXME: In the previous implementation we ignore this? :thinking_face:
// Ok(GuardKZG { msm_accumulator })
Ok(())
transcript.write_point(pi)
}
}

0 comments on commit b4604d4

Please sign in to comment.