Skip to content

Commit

Permalink
Remove SerdeObject and add read/write functions to hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
iquerejeta committed Jan 22, 2025
1 parent 087f684 commit e5256cf
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 62 deletions.
1 change: 0 additions & 1 deletion examples/vector-ops-unblinded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ where
Default + SerdeObject + Hashable<State> + CurveAffine<ScalarExt = E::Fr, CurveExt = E::G1>,
E::Fr: WithSmallOrderMulGroup<3>
+ FromUniformBytes<64>
+ SerdeObject
+ Sampleable<State>
+ Hashable<State>
+ Ord,
Expand Down
9 changes: 4 additions & 5 deletions src/plonk/lookup/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
};
use ff::{FromUniformBytes, PrimeField, WithSmallOrderMulGroup};
use group::ff::BatchInvert;
use halo2curves::serde::SerdeObject;
use rand_core::{CryptoRng, RngCore};
use std::{collections::BTreeMap, iter};

Expand Down Expand Up @@ -66,7 +65,7 @@ impl<F: WithSmallOrderMulGroup<3> + Ord> Argument<F> {
transcript: &mut T,
) -> Result<Permuted<F>, Error>
where
F: FromUniformBytes<64> + SerdeObject,
F: FromUniformBytes<64>,
CS::Commitment: Hashable<T::Hash>,
{
// Closure to get values of expressions and compress them
Expand Down Expand Up @@ -153,7 +152,7 @@ impl<F: WithSmallOrderMulGroup<3>> Permuted<F> {
transcript: &mut T,
) -> Result<Committed<F>, Error>
where
F: WithSmallOrderMulGroup<3> + FromUniformBytes<64> + SerdeObject,
F: WithSmallOrderMulGroup<3> + FromUniformBytes<64>,
CS::Commitment: Hashable<T::Hash>,
{
let blinding_factors = pk.vk.cs.blinding_factors();
Expand Down Expand Up @@ -286,7 +285,7 @@ impl<F: WithSmallOrderMulGroup<3>> Committed<F> {
transcript: &mut T,
) -> Result<Evaluated<F>, Error>
where
F: Hashable<T::Hash> + SerdeObject,
F: Hashable<T::Hash>,
{
let domain = &pk.vk.domain;
let x_inv = domain.rotate_omega(x, Rotation::prev());
Expand Down Expand Up @@ -368,7 +367,7 @@ fn permute_expression_pair<F, CS: PolynomialCommitmentScheme<F>, R: RngCore>(
table_expression: &Polynomial<F, LagrangeCoeff>,
) -> Result<ExpressionPair<F>, Error>
where
F: WithSmallOrderMulGroup<3> + Ord + FromUniformBytes<64> + SerdeObject,
F: WithSmallOrderMulGroup<3> + Ord + FromUniformBytes<64>,
{
let blinding_factors = pk.vk.cs.blinding_factors();
let usable_rows = pk.vk.n() as usize - (blinding_factors + 1);
Expand Down
5 changes: 2 additions & 3 deletions src/plonk/lookup/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
poly::{Rotation, VerifierQuery},
};
use ff::{PrimeField, WithSmallOrderMulGroup};
use halo2curves::serde::SerdeObject;

pub struct PermutationCommitments<F: PrimeField, CS: PolynomialCommitmentScheme<F>> {
permuted_input_commitment: CS::Commitment,
Expand Down Expand Up @@ -57,7 +56,7 @@ impl<F: PrimeField, CS: PolynomialCommitmentScheme<F>> PermutationCommitments<F,
transcript: &mut T,
) -> Result<Committed<F, CS>, Error>
where
CS::Commitment: Hashable<T::Hash> + SerdeObject,
CS::Commitment: Hashable<T::Hash>,
{
let product_commitment = transcript.read()?;

Expand All @@ -74,7 +73,7 @@ impl<F: PrimeField, CS: PolynomialCommitmentScheme<F>> Committed<F, CS> {
transcript: &mut T,
) -> Result<Evaluated<F, CS>, Error>
where
F: Hashable<T::Hash> + SerdeObject,
F: Hashable<T::Hash>,
{
let product_eval = transcript.read()?;
let product_next_eval = transcript.read()?;
Expand Down
3 changes: 1 addition & 2 deletions src/plonk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ const VERSION: u8 = 0x03;

impl<F, CS> VerifyingKey<F, CS>
where
F: WithSmallOrderMulGroup<3> + SerdeObject + FromUniformBytes<64>,
F: WithSmallOrderMulGroup<3> + FromUniformBytes<64>,
CS: PolynomialCommitmentScheme<F>,
CS::Commitment: SerdeObject,
{
/// Returns `n`
pub fn n(&self) -> u64 {
Expand Down
6 changes: 3 additions & 3 deletions src/plonk/permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<F: PrimeField, CS: PolynomialCommitmentScheme<F>> VerifyingKey<F, CS> {

pub(crate) fn write<W: io::Write>(&self, writer: &mut W, format: SerdeFormat) -> io::Result<()>
where
CS::Commitment: SerdeObject,
CS::Commitment: ProcessedSerdeObject,
{
for commitment in &self.commitments {
commitment.write(writer, format)?;
Expand All @@ -109,7 +109,7 @@ impl<F: PrimeField, CS: PolynomialCommitmentScheme<F>> VerifyingKey<F, CS> {
format: SerdeFormat,
) -> io::Result<Self>
where
CS::Commitment: SerdeObject,
CS::Commitment: ProcessedSerdeObject,
{
let commitments = (0..argument.columns.len())
.map(|_| CS::Commitment::read(reader, format))
Expand All @@ -119,7 +119,7 @@ impl<F: PrimeField, CS: PolynomialCommitmentScheme<F>> VerifyingKey<F, CS> {

pub(crate) fn bytes_length(&self, format: SerdeFormat) -> usize
where
CS::Commitment: SerdeObject,
CS::Commitment: ProcessedSerdeObject,
{
self.commitments.len() * byte_length::<CS::Commitment>(format)
}
Expand Down
5 changes: 2 additions & 3 deletions src/plonk/permutation/prover.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use ff::{PrimeField, WithSmallOrderMulGroup};
use group::ff::BatchInvert;
use halo2curves::serde::SerdeObject;
use rand_core::RngCore;
use std::iter::{self, ExactSizeIterator};

Expand Down Expand Up @@ -180,7 +179,7 @@ impl<F: PrimeField> super::ProvingKey<F> {
transcript: &mut T,
) -> Result<(), Error>
where
F: Hashable<T::Hash> + SerdeObject,
F: Hashable<T::Hash>,
{
// Hash permutation evals
for eval in self.polys.iter().map(|poly| eval_polynomial(poly, x)) {
Expand All @@ -199,7 +198,7 @@ impl<F: WithSmallOrderMulGroup<3>> Committed<F> {
transcript: &mut T,
) -> Result<Evaluated<F>, Error>
where
F: Hashable<T::Hash> + SerdeObject,
F: Hashable<T::Hash>,
{
let domain = &pk.vk.domain;
let blinding_factors = pk.vk.cs.blinding_factors();
Expand Down
9 changes: 4 additions & 5 deletions src/plonk/permutation/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ff::{PrimeField, WithSmallOrderMulGroup};
use halo2curves::serde::SerdeObject;
use std::iter;

use super::super::circuit::Any;
Expand Down Expand Up @@ -41,7 +40,7 @@ impl Argument {
transcript: &mut T,
) -> Result<Committed<F, CS>, Error>
where
CS::Commitment: Hashable<T::Hash> + SerdeObject,
CS::Commitment: Hashable<T::Hash>,
{
let chunk_len = vk.cs_degree - 2;

Expand All @@ -63,7 +62,7 @@ impl<F: PrimeField, CS: PolynomialCommitmentScheme<F>> VerifyingKey<F, CS> {
transcript: &mut T,
) -> Result<CommonEvaluated<F>, Error>
where
F: Hashable<T::Hash> + SerdeObject,
F: Hashable<T::Hash>,
{
let permutation_evals = self
.commitments
Expand All @@ -81,8 +80,8 @@ impl<F: PrimeField, CS: PolynomialCommitmentScheme<F>> Committed<F, CS> {
transcript: &mut T,
) -> Result<Evaluated<F, CS>, Error>
where
CS::Commitment: Hashable<T::Hash> + SerdeObject,
F: Hashable<T::Hash> + SerdeObject,
CS::Commitment: Hashable<T::Hash>,
F: Hashable<T::Hash>,
{
let mut sets = vec![];

Expand Down
4 changes: 1 addition & 3 deletions src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::poly::batch_invert_rational;
use crate::poly::commitment::PolynomialCommitmentScheme;
use crate::transcript::{Hashable, Sampleable, Transcript};
use crate::utils::rational::Rational;
use halo2curves::serde::SerdeObject;

/// This creates a proof for the provided `circuit` when given the public
/// parameters `params` and the proving key [`ProvingKey`] that was
Expand All @@ -45,11 +44,10 @@ pub fn create_proof<
transcript: &mut T,
) -> Result<(), Error>
where
CS::Commitment: Hashable<T::Hash> + SerdeObject,
CS::Commitment: Hashable<T::Hash>,
F: WithSmallOrderMulGroup<3>
+ Sampleable<T::Hash>
+ Hashable<T::Hash>
+ SerdeObject
+ Ord
+ FromUniformBytes<64>,
{
Expand Down
11 changes: 5 additions & 6 deletions src/plonk/vanishing/prover.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{collections::HashMap, iter};

use ff::{PrimeField, WithSmallOrderMulGroup};
use halo2curves::serde::SerdeObject;
use rand_chacha::ChaCha20Rng;
use rand_core::{RngCore, SeedableRng};

Expand Down Expand Up @@ -38,8 +37,8 @@ impl<F: WithSmallOrderMulGroup<3>, CS: PolynomialCommitmentScheme<F>> Argument<F
transcript: &mut T,
) -> Result<Committed<F>, Error>
where
CS::Commitment: Hashable<T::Hash> + SerdeObject,
F: Hashable<T::Hash> + SerdeObject,
CS::Commitment: Hashable<T::Hash>,
F: Hashable<T::Hash>,
{
// Sample a random polynomial of degree n - 1
let n = 1usize << domain.k() as usize;
Expand Down Expand Up @@ -88,8 +87,8 @@ impl<F: WithSmallOrderMulGroup<3>> Committed<F> {
transcript: &mut T,
) -> Result<Constructed<F>, Error>
where
CS::Commitment: Hashable<T::Hash> + SerdeObject,
F: Hashable<T::Hash> + SerdeObject,
CS::Commitment: Hashable<T::Hash>,
F: Hashable<T::Hash>,
{
// Divide by t(X) = X^{params.n} - 1.
let h_poly = domain.divide_by_vanishing_poly(h_poly);
Expand Down Expand Up @@ -129,7 +128,7 @@ impl<F: PrimeField> Constructed<F> {
transcript: &mut T,
) -> Result<Evaluated<F>, Error>
where
F: Hashable<T::Hash> + SerdeObject,
F: Hashable<T::Hash>,
{
self.h_pieces.iter().try_for_each(|p| {
let eval = eval_polynomial(p, x);
Expand Down
7 changes: 3 additions & 4 deletions src/plonk/vanishing/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::iter;

use ff::{PrimeField, WithSmallOrderMulGroup};
use halo2curves::serde::SerdeObject;

use crate::poly::commitment::PolynomialCommitmentScheme;
use crate::transcript::{read_n, Hashable, Transcript};
Expand Down Expand Up @@ -33,7 +32,7 @@ impl<F: PrimeField, CS: PolynomialCommitmentScheme<F>> Argument<F, CS> {
transcript: &mut T,
) -> Result<Committed<F, CS>, Error>
where
CS::Commitment: Hashable<T::Hash> + SerdeObject,
CS::Commitment: Hashable<T::Hash>,
{
let random_poly_commitment = transcript.read()?;

Expand All @@ -50,7 +49,7 @@ impl<F: WithSmallOrderMulGroup<3>, CS: PolynomialCommitmentScheme<F>> Committed<
transcript: &mut T,
) -> Result<Constructed<F, CS>, Error>
where
CS::Commitment: Hashable<T::Hash> + SerdeObject,
CS::Commitment: Hashable<T::Hash>,
{
// Obtain a commitment to h(X) in the form of multiple pieces of degree n - 1
let h_commitments = read_n(transcript, vk.domain.get_quotient_poly_degree())?;
Expand All @@ -69,7 +68,7 @@ impl<F: WithSmallOrderMulGroup<3>, CS: PolynomialCommitmentScheme<F>> Constructe
transcript: &mut T,
) -> Result<Evaluated<F, CS>, Error>
where
F: Hashable<T::Hash> + SerdeObject,
F: Hashable<T::Hash>,
{
let h_evals = read_n(transcript, vk.domain.get_quotient_poly_degree())?;
let random_eval = transcript.read()?;
Expand Down
4 changes: 1 addition & 3 deletions src/plonk/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ff::{FromUniformBytes, WithSmallOrderMulGroup};
use halo2curves::serde::SerdeObject;
use std::iter;

use super::{vanishing, Error, VerifyingKey};
Expand All @@ -18,10 +17,9 @@ where
F: WithSmallOrderMulGroup<3>
+ Hashable<T::Hash>
+ Sampleable<T::Hash>
+ SerdeObject
+ FromUniformBytes<64>
+ Ord,
CS::Commitment: Hashable<T::Hash> + SerdeObject,
CS::Commitment: Hashable<T::Hash>,
{
// Check that instances matches the expected number of instance columns
for instances in instances.iter() {
Expand Down
14 changes: 6 additions & 8 deletions src/poly/kzg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ use crate::utils::arithmetic::{truncate, truncated_powers};
use crate::poly::commitment::{Params, PolynomialCommitmentScheme};
use crate::poly::kzg::utils::construct_intermediate_sets;
use crate::transcript::{Hashable, Sampleable, Transcript};
use crate::utils::helpers::ProcessedSerdeObject;
use ff::Field;
use group::Group;
use halo2curves::msm::msm_best;
use halo2curves::pairing::MultiMillerLoop;
use halo2curves::serde::SerdeObject;
use halo2curves::CurveAffine;
use rand_core::OsRng;

Expand All @@ -48,8 +48,7 @@ pub struct KZGCommitmentScheme<E: Engine> {

impl<E: MultiMillerLoop> PolynomialCommitmentScheme<E::Fr> for KZGCommitmentScheme<E>
where
E::Fr: SerdeObject,
E::G1Affine: Default + SerdeObject + CurveAffine<ScalarExt = E::Fr, CurveExt = E::G1>,
E::G1Affine: Default + CurveAffine<ScalarExt = E::Fr, CurveExt = E::G1> + ProcessedSerdeObject,
{
type Parameters = ParamsKZG<E>;
type VerifierParameters = ParamsVerifierKZG<E>;
Expand Down Expand Up @@ -351,7 +350,7 @@ mod tests {
proof: &[u8],
should_fail: bool,
) where
E::Fr: SerdeObject + Hashable<T::Hash> + Sampleable<T::Hash> + Ord,
E::Fr: Hashable<T::Hash> + Sampleable<T::Hash> + Ord,
E::G1Affine: CurveAffine<ScalarExt = <E as Engine>::Fr, CurveExt = <E as Engine>::G1>
+ SerdeObject
+ Hashable<T::Hash>,
Expand Down Expand Up @@ -397,10 +396,9 @@ mod tests {

fn create_proof<E: MultiMillerLoop, T: Transcript>(kzg_params: &ParamsKZG<E>) -> Vec<u8>
where
E::Fr:
WithSmallOrderMulGroup<3> + SerdeObject + Hashable<T::Hash> + Sampleable<T::Hash> + Ord,
E::G1Affine: SerdeObject
+ Hashable<T::Hash>
E::Fr: WithSmallOrderMulGroup<3> + Hashable<T::Hash> + Sampleable<T::Hash> + Ord,
E::G1Affine: Hashable<T::Hash>
+ SerdeObject
+ Default
+ CurveAffine<ScalarExt = E::Fr, CurveExt = E::G1>,
{
Expand Down
5 changes: 2 additions & 3 deletions src/poly/kzg/msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use crate::poly::kzg::KZGCommitmentScheme;
use crate::poly::Error;
use crate::utils::arithmetic::parallelize;
use crate::utils::arithmetic::MSM;
use crate::utils::helpers::ProcessedSerdeObject;
use group::prime::PrimeCurveAffine;
use group::{Curve, Group};
use halo2curves::msm::msm_best;
use halo2curves::serde::SerdeObject;
use halo2curves::{
pairing::{Engine, MillerLoopResult, MultiMillerLoop},
CurveAffine,
Expand Down Expand Up @@ -111,8 +111,7 @@ where

impl<E: MultiMillerLoop> Guard<E::Fr, KZGCommitmentScheme<E>> for DualMSM<E>
where
E::Fr: SerdeObject,
E::G1Affine: Default + SerdeObject + CurveAffine<ScalarExt = E::Fr, CurveExt = E::G1>,
E::G1Affine: Default + CurveAffine<ScalarExt = E::Fr, CurveExt = E::G1> + ProcessedSerdeObject,
{
fn verify(
self,
Expand Down
Loading

0 comments on commit e5256cf

Please sign in to comment.