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

Rename nonnative to emulated, as in r1cs-std #137

Merged
merged 5 commits into from
Jan 9, 2024
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
20 changes: 10 additions & 10 deletions poly-commit/src/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use ark_crypto_primitives::sponge::CryptographicSponge;
use ark_ff::PrimeField;
use ark_poly::Polynomial;
use ark_r1cs_std::fields::nonnative::NonNativeFieldVar;
use ark_r1cs_std::fields::emulated_fp::EmulatedFpVar;
use ark_r1cs_std::{fields::fp::FpVar, prelude::*};
use ark_relations::r1cs::{ConstraintSystemRef, Namespace, Result as R1CSResult, SynthesisError};
use ark_std::{borrow::Borrow, cmp::Eq, cmp::PartialEq, hash::Hash, marker::Sized};
Expand All @@ -24,8 +24,8 @@ pub enum LinearCombinationCoeffVar<TargetField: PrimeField, BaseField: PrimeFiel
One,
/// Coefficient -1.
MinusOne,
/// Other coefficient, represented as a nonnative field element.
Var(NonNativeFieldVar<TargetField, BaseField>),
/// Other coefficient, represented as a "emulated" field element.
Var(EmulatedFpVar<TargetField, BaseField>),
}

/// An allocated version of `LinearCombination`.
Expand Down Expand Up @@ -60,7 +60,7 @@ impl<TargetField: PrimeField, BaseField: PrimeField>
let (f, lc_term) = term;

let fg =
NonNativeFieldVar::new_variable(ark_relations::ns!(cs, "term"), || Ok(f), mode)
EmulatedFpVar::new_variable(ark_relations::ns!(cs, "term"), || Ok(f), mode)
.unwrap();

(LinearCombinationCoeffVar::Var(fg), lc_term.clone())
Expand All @@ -79,12 +79,12 @@ impl<TargetField: PrimeField, BaseField: PrimeField>
pub struct PCCheckRandomDataVar<TargetField: PrimeField, BaseField: PrimeField> {
/// Opening challenges.
/// The prover and the verifier MUST use the same opening challenges.
pub opening_challenges: Vec<NonNativeFieldVar<TargetField, BaseField>>,
pub opening_challenges: Vec<EmulatedFpVar<TargetField, BaseField>>,
/// Bit representations of the opening challenges.
pub opening_challenges_bits: Vec<Vec<Boolean<BaseField>>>,
/// Batching random numbers.
/// The verifier can choose these numbers freely, as long as they are random.
pub batching_rands: Vec<NonNativeFieldVar<TargetField, BaseField>>,
pub batching_rands: Vec<EmulatedFpVar<TargetField, BaseField>>,
/// Bit representations of the batching random numbers.
pub batching_rands_bits: Vec<Vec<Boolean<BaseField>>>,
}
Expand Down Expand Up @@ -172,7 +172,7 @@ pub struct LabeledPointVar<TargetField: PrimeField, BaseField: PrimeField> {
/// MUST be a unique identifier in a query set.
pub name: String,
/// The point value.
pub value: NonNativeFieldVar<TargetField, BaseField>,
pub value: EmulatedFpVar<TargetField, BaseField>,
}

/// An allocated version of `QuerySet`.
Expand All @@ -184,16 +184,16 @@ pub struct QuerySetVar<TargetField: PrimeField, BaseField: PrimeField>(
/// An allocated version of `Evaluations`.
#[derive(Clone)]
pub struct EvaluationsVar<TargetField: PrimeField, BaseField: PrimeField>(
pub HashMap<LabeledPointVar<TargetField, BaseField>, NonNativeFieldVar<TargetField, BaseField>>,
pub HashMap<LabeledPointVar<TargetField, BaseField>, EmulatedFpVar<TargetField, BaseField>>,
);

impl<TargetField: PrimeField, BaseField: PrimeField> EvaluationsVar<TargetField, BaseField> {
/// find the evaluation result
pub fn get_lc_eval(
&self,
lc_string: &str,
point: &NonNativeFieldVar<TargetField, BaseField>,
) -> Result<NonNativeFieldVar<TargetField, BaseField>, SynthesisError> {
point: &EmulatedFpVar<TargetField, BaseField>,
) -> Result<EmulatedFpVar<TargetField, BaseField>, SynthesisError> {
let key = LabeledPointVar::<TargetField, BaseField> {
name: String::from(lc_string),
value: point.clone(),
Expand Down
9 changes: 4 additions & 5 deletions poly-commit/src/streaming_kzg/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ where

/// Stream implementation of foleded polynomial.
#[derive(Clone, Copy)]
pub struct FoldedPolynomialStream<'a, F, S>(FoldedPolynomialTree<'a, F, S>, usize);
pub struct FoldedPolynomialStream<'a, F, S>(FoldedPolynomialTree<'a, F, S>);
Pratyush marked this conversation as resolved.
Show resolved Hide resolved
/// Iterator implementation of foleded polynomial.
pub struct FoldedPolynomialStreamIter<'a, F, I> {
challenges: &'a [F],
Expand All @@ -157,8 +157,7 @@ where
/// Initialize a new folded polynomial stream.
pub fn new(coefficients: &'a S, challenges: &'a [F]) -> Self {
let tree = FoldedPolynomialTree::new(coefficients, challenges);
let len = challenges.len();
Self(tree, len)
Self(tree)
}
}

Expand Down Expand Up @@ -240,7 +239,7 @@ fn test_folded_polynomial() {
let challenges = vec![F::one(), two];
let coefficients_stream = coefficients.as_slice();
let foldstream = FoldedPolynomialTree::new(&coefficients_stream, challenges.as_slice());
let fold_stream = FoldedPolynomialStream(foldstream, 2);
let fold_stream = FoldedPolynomialStream(foldstream);
assert_eq!(fold_stream.len(), 1);
assert_eq!(
fold_stream.iter().next(),
Expand All @@ -252,7 +251,7 @@ fn test_folded_polynomial() {
let challenges = vec![F::one(); 4];
let coefficients_stream = coefficients.as_slice();
let foldstream = FoldedPolynomialTree::new(&coefficients_stream, challenges.as_slice());
let fold_stream = FoldedPolynomialStream(foldstream, 4).iter();
let fold_stream = FoldedPolynomialStream(foldstream).iter();
assert_eq!(fold_stream.last(), Some(coefficients.iter().sum()));
}

Expand Down
Loading