Skip to content

Commit

Permalink
Fix benches and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratyush committed Dec 28, 2023
1 parent 074ee54 commit 33e53a2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std = [ "ark-ff/std", "ark-relations/std", "ark-std/std", "num-bigint/std" ]
parallel = [ "std", "ark-ff/parallel", "ark-std/parallel"]

[[bench]]
name = "nonnative-bench"
name = "emulated-bench"
path = "benches/bench.rs"
harness = false

Expand Down
22 changes: 11 additions & 11 deletions src/fields/emulated_fp/allocated_field_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<TargetF: PrimeField, BaseF: PrimeField> AllocatedEmulatedFpVar<TargetF, Bas
result
}

/// Obtain the value of a nonnative field element
/// Obtain the value of a emulated field element
pub fn value(&self) -> R1CSResult<TargetF> {
let mut limbs = Vec::new();
for limb in self.limbs.iter() {
Expand All @@ -91,7 +91,7 @@ impl<TargetF: PrimeField, BaseF: PrimeField> AllocatedEmulatedFpVar<TargetF, Bas
Ok(Self::limbs_to_value(limbs, self.get_optimization_type()))
}

/// Obtain the nonnative field element of a constant value
/// Obtain the emulated field element of a constant value
pub fn constant(cs: ConstraintSystemRef<BaseF>, value: TargetF) -> R1CSResult<Self> {
let optimization_type = match cs.optimization_goal() {
OptimizationGoal::None => OptimizationType::Constraints,
Expand All @@ -116,17 +116,17 @@ impl<TargetF: PrimeField, BaseF: PrimeField> AllocatedEmulatedFpVar<TargetF, Bas
})
}

/// Obtain the nonnative field element of one
/// Obtain the emulated field element of one
pub fn one(cs: ConstraintSystemRef<BaseF>) -> R1CSResult<Self> {
Self::constant(cs, TargetF::one())
}

/// Obtain the nonnative field element of zero
/// Obtain the emulated field element of zero
pub fn zero(cs: ConstraintSystemRef<BaseF>) -> R1CSResult<Self> {
Self::constant(cs, TargetF::zero())
}

/// Add a nonnative field element
/// Add a emulated field element
#[tracing::instrument(target = "r1cs")]
pub fn add(&self, other: &Self) -> R1CSResult<Self> {
assert_eq!(self.get_optimization_type(), other.get_optimization_type());
Expand Down Expand Up @@ -176,7 +176,7 @@ impl<TargetF: PrimeField, BaseF: PrimeField> AllocatedEmulatedFpVar<TargetF, Bas
Ok(res)
}

/// Subtract a nonnative field element, without the final reduction step
/// Subtract a emulated field element, without the final reduction step
#[tracing::instrument(target = "r1cs")]
pub fn sub_without_reduce(&self, other: &Self) -> R1CSResult<Self> {
assert_eq!(self.get_optimization_type(), other.get_optimization_type());
Expand Down Expand Up @@ -251,7 +251,7 @@ impl<TargetF: PrimeField, BaseF: PrimeField> AllocatedEmulatedFpVar<TargetF, Bas
Ok(result)
}

/// Subtract a nonnative field element
/// Subtract a emulated field element
#[tracing::instrument(target = "r1cs")]
pub fn sub(&self, other: &Self) -> R1CSResult<Self> {
assert_eq!(self.get_optimization_type(), other.get_optimization_type());
Expand All @@ -267,7 +267,7 @@ impl<TargetF: PrimeField, BaseF: PrimeField> AllocatedEmulatedFpVar<TargetF, Bas
self.sub(&Self::constant(self.cs(), *other)?)
}

/// Multiply a nonnative field element
/// Multiply a emulated field element
#[tracing::instrument(target = "r1cs")]
pub fn mul(&self, other: &Self) -> R1CSResult<Self> {
assert_eq!(self.get_optimization_type(), other.get_optimization_type());
Expand All @@ -280,13 +280,13 @@ impl<TargetF: PrimeField, BaseF: PrimeField> AllocatedEmulatedFpVar<TargetF, Bas
self.mul(&Self::constant(self.cs(), *other)?)
}

/// Compute the negate of a nonnative field element
/// Compute the negate of a emulated field element
#[tracing::instrument(target = "r1cs")]
pub fn negate(&self) -> R1CSResult<Self> {
Self::zero(self.cs())?.sub(self)
}

/// Compute the inverse of a nonnative field element
/// Compute the inverse of a emulated field element
#[tracing::instrument(target = "r1cs")]
pub fn inverse(&self) -> R1CSResult<Self> {
let inverse = Self::new_witness(self.cs(), || {
Expand Down Expand Up @@ -867,7 +867,7 @@ impl<TargetF: PrimeField, BaseF: PrimeField> ToConstraintFieldGadget<BaseF>
for AllocatedEmulatedFpVar<TargetF, BaseF>
{
fn to_constraint_field(&self) -> R1CSResult<Vec<FpVar<BaseF>>> {
// provide a unique representation of the nonnative variable
// provide a unique representation of the emulated variable
// step 1: convert it into a bit sequence
let bits = self.to_bits_le()?;

Expand Down
6 changes: 3 additions & 3 deletions src/fields/emulated_fp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//! # use ark_std::UniformRand;
//! # use ark_relations::{ns, r1cs::ConstraintSystem};
//! # use ark_r1cs_std::prelude::*;
//! use ark_r1cs_std::fields::nonnative::EmulatedFpVar;
//! use ark_r1cs_std::fields::emulated::EmulatedFpVar;
//! use ark_bls12_377::{Fr, Fq};
//!
//! # let mut rng = ark_std::test_rng();
Expand Down Expand Up @@ -122,8 +122,8 @@
//!
//! \[OWWB20\]: A. Ozdemir, R. S. Wahby, B. Whitehat, and D. Boneh. "Scaling verifiable computation using efficient set accumulators," in *Proceedings of the 29th USENIX Security Symposium*, ser. Security ’20, 2020.
//!
//! [`EmulatedFpVar`]: crate::fields::nonnative::EmulatedFpVar
//! [`MulResultVar`]: crate::fields::nonnative::MulResultVar
//! [`EmulatedFpVar`]: crate::fields::emulated::EmulatedFpVar
//! [`MulResultVar`]: crate::fields::emulated::MulResultVar
//! [`FpVar`]: crate::fields::fp::FpVar

#![allow(
Expand Down
2 changes: 1 addition & 1 deletion src/fields/emulated_fp/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum OptimizationType {
Weight,
}

/// A function to search for parameters for nonnative field gadgets
/// A function to search for parameters for emulated field gadgets
pub const fn find_parameters(
base_field_prime_length: usize,
target_field_prime_bit_length: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod quadratic_extension;
/// That is, it implements the R1CS equivalent of `ark_ff::Fp*`.
pub mod fp;

/// This module contains a generic implementation of "nonnative" prime field
/// This module contains a generic implementation of "emulated" prime field
/// variables. It emulates `Fp` arithmetic using `Fq` operations, where `p != q`.
pub mod emulated_fp;

Expand Down

0 comments on commit 33e53a2

Please sign in to comment.