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

Update from arkworks 3 --> 4 #10

Closed
wants to merge 9 commits into from
Closed
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk

.idea
.idea

.vscode
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ark-ff = { version = "^0.3.0", default-features = false }
ark-std = { version = "^0.3.0", default-features = false }
ark-r1cs-std = { version = "^0.3.0", default-features = false}
ark-sponge = { version = "^0.3.0", default-features = false }
ark-poly = { version = "0.3.0", default-features = false }
ark-relations = { version = "^0.3.0", default-features = false, optional = true}
ark-crypto-primitives = { version="^0.4.0", features = ["sponge"] }
ark-ff = { version = "^0.4.2", default-features = false }
ark-std = { version = "^0.4.0", default-features = false }
ark-r1cs-std = { version = "^0.4.0", default-features = false}
ark-poly = { version = "0.4.2" }
ark-relations = { version = "^0.4.0", default-features = false, optional = true}
tracing = { version = "0.1", default-features = false, features = [ "attributes" ], optional = true}

[dev-dependencies]
ark-test-curves = { version = "^0.3.0", default-features = false, features = ["bls12_381_scalar_field", "mnt4_753_scalar_field"] }
ark-test-curves = { version = "^0.4.2", default-features = false, features = ["bls12_381_scalar_field", "mnt4_753_scalar_field"] }

[patch.crates-io]
ark-sponge = {git = "https://github.com/arkworks-rs/sponge"}
ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives" }
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std" }
z-tech marked this conversation as resolved.
Show resolved Hide resolved
ark-ec = { git = "https://github.com/arkworks-rs/algebra" }
ark-ff = { git = "https://github.com/arkworks-rs/algebra" }
ark-ff = { git = "https://github.com/arkworks-rs/algebra/" }
ark-poly = { git = "https://github.com/arkworks-rs/algebra" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra" }
ark-std = { git = "https://github.com/arkworks-rs/std" }
Expand Down Expand Up @@ -55,6 +55,6 @@ debug = true

[features]
default = ["std"]
std = ["ark-ff/std", "ark-std/std", "ark-relations/std", "ark-r1cs-std/std", "ark-sponge/std", "ark-poly/std"]
r1cs = ["ark-sponge/r1cs", "tracing", "ark-relations"]
std = ["ark-ff/std", "ark-std/std", "ark-relations/std", "ark-r1cs-std/std", "ark-crypto-primitives/std", "ark-poly/std"]
r1cs = ["ark-crypto-primitives/r1cs", "tracing", "ark-relations"]

5 changes: 2 additions & 3 deletions src/direct/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ark_ff::PrimeField;
use ark_poly::univariate::DensePolynomial;
use ark_poly::Polynomial;
use ark_std::marker::PhantomData;
use ark_std::vec::Vec;
use ark_std::vec::*;
/// Direct LDT by interpolating evaluations and truncating coefficients to low degree.
/// /// This requires communication linear in the degree bound; use FRI for better communication complexity.
pub struct DirectLDT<F: PrimeField> {
Expand Down Expand Up @@ -56,8 +56,7 @@ impl<F: PrimeField> DirectLDT<F> {
mod tests {
use crate::direct::{DirectLDT, Radix2CosetDomain};
use ark_ff::UniformRand;
use ark_poly::univariate::DensePolynomial;
use ark_poly::DenseUVPolynomial;
use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
use ark_std::test_rng;
use ark_test_curves::bls12_381::Fr;

Expand Down
11 changes: 8 additions & 3 deletions src/domain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ use ark_poly::polynomial::univariate::DensePolynomial;
use ark_poly::{
DenseUVPolynomial, EvaluationDomain, Evaluations, Polynomial, Radix2EvaluationDomain,
};

#[cfg(feature = "r1cs")]
use ark_r1cs_std::bits::boolean::Boolean;
use ark_r1cs_std::boolean::Boolean;
#[cfg(feature = "r1cs")]
use ark_r1cs_std::fields::fp::FpVar;
#[cfg(feature = "r1cs")]
use ark_r1cs_std::fields::FieldVar;
#[cfg(feature = "r1cs")]
use ark_relations::r1cs::SynthesisError;
use ark_std::vec::Vec;
use ark_std::vec::*;

/// Given domain as `<g>`, `CosetOfDomain` represents `h<g>`
///
Expand Down Expand Up @@ -178,6 +179,9 @@ mod tests {
use ark_std::{test_rng, UniformRand};
use ark_test_curves::bls12_381::Fr;

#[cfg(feature = "r1cs")]
use ark_r1cs_std::convert::ToBitsGadget;

use crate::domain::Radix2CosetDomain;

#[cfg(feature = "r1cs")]
Expand Down Expand Up @@ -297,7 +301,8 @@ mod tests {
let index = 11;
let index_var = UInt64::new_witness(ns!(cs, "index"), || Ok(index))
.unwrap()
.to_bits_le();
.to_bits_le()
.unwrap();

let expected = domain_coset.element(index as usize);
let actual = domain_coset
Expand Down
23 changes: 15 additions & 8 deletions src/fri/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
use crate::direct::constraints::DirectLDTGadget;
use crate::domain::Radix2CosetDomain;
use crate::fri::FRIParameters;
use ark_crypto_primitives::sponge::constraints::CryptographicSpongeVar;
use ark_crypto_primitives::sponge::FieldBasedCryptographicSponge;
use ark_ff::PrimeField;
use ark_r1cs_std::bits::boolean::Boolean;
use ark_r1cs_std::boolean::*;
use ark_r1cs_std::eq::EqGadget;
use ark_r1cs_std::fields::fp::FpVar;
use ark_r1cs_std::fields::FieldVar;
Expand All @@ -12,10 +14,8 @@ use ark_r1cs_std::poly::evaluations::univariate::EvaluationsVar;
use ark_r1cs_std::poly::polynomial::univariate::dense::DensePolynomialVar;
use ark_r1cs_std::prelude::CondSelectGadget;
use ark_relations::r1cs::SynthesisError;
use ark_sponge::constraints::CryptographicSpongeVar;
use ark_sponge::FieldBasedCryptographicSponge;
use ark_std::marker::PhantomData;
use ark_std::vec::Vec;
use ark_std::vec::*;

/// Constraints for FRI verifier.
pub struct FRIVerifierGadget<F: PrimeField> {
Expand Down Expand Up @@ -165,7 +165,11 @@ impl<F: PrimeField> FRIVerifierGadget<F> {
&queried_evaluations[i + 1],
)?;

check_result = check_result.and(&expected_next_round_eval.is_eq(&actual)?)?;
check_result = Boolean::<F>::kary_and(&[
check_result,
expected_next_round_eval.is_eq(&actual)?,
])
.unwrap();
}
}

Expand Down Expand Up @@ -197,9 +201,10 @@ mod tests {
use ark_poly::polynomial::univariate::DensePolynomial;
use ark_poly::DenseUVPolynomial;
use ark_r1cs_std::alloc::AllocVar;
use ark_r1cs_std::bits::uint64::UInt64;
use ark_r1cs_std::convert::ToBitsGadget;
use ark_r1cs_std::fields::fp::FpVar;
use ark_r1cs_std::poly::polynomial::univariate::dense::DensePolynomialVar;
use ark_r1cs_std::uint64::UInt64;
use ark_r1cs_std::R1CSVar;
use ark_relations::r1cs::ConstraintSystem;
use ark_relations::*;
Expand All @@ -219,7 +224,8 @@ mod tests {
let rand_coset_index_var =
UInt64::new_witness(ns!(cs, "rand_coset_index"), || Ok(rand_coset_index as u64))
.unwrap();
let rand_coset_index_var_arr = rand_coset_index_var.to_bits_le()[..(1 << 6)].to_vec();
let rand_coset_index_var_arr =
rand_coset_index_var.to_bits_le().unwrap()[..(1 << 6)].to_vec();

let rand_coset_index = 31;
let (query_cosets, query_indices, domain_final) =
Expand Down Expand Up @@ -286,7 +292,8 @@ mod tests {
.to_bits_le();

let (query_cosets, query_indices, domain_final) =
FRIVerifierGadget::prepare_query(rand_coset_index_var, &fri_parameters).unwrap();
FRIVerifierGadget::prepare_query(rand_coset_index_var.unwrap(), &fri_parameters)
.unwrap();
let (_, query_indices_native, _) =
FRIVerifier::prepare_query(rand_coset_index as usize, &fri_parameters);

Expand Down
2 changes: 1 addition & 1 deletion src/fri/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::domain::Radix2CosetDomain;
use ark_ff::PrimeField;
use ark_std::marker::PhantomData;
use ark_std::vec::Vec;
use ark_std::vec::*;
/// R1CS constraints for FRI Verifier.
#[cfg(feature = "r1cs")]
pub mod constraints;
Expand Down
5 changes: 2 additions & 3 deletions src/fri/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::domain::Radix2CosetDomain;
use ark_ff::{batch_inversion_and_mul, PrimeField};
use ark_r1cs_std::poly::evaluations::univariate::lagrange_interpolator::LagrangeInterpolator;
use ark_std::marker::PhantomData;
use ark_std::vec::Vec;
use ark_std::vec::*;
/// FRI Prover
pub struct FRIProver<F: PrimeField> {
_prover: PhantomData<F>,
Expand Down Expand Up @@ -172,8 +172,7 @@ pub mod tests {
use crate::direct::DirectLDT;
use crate::domain::Radix2CosetDomain;
use crate::fri::prover::FRIProver;
use ark_poly::univariate::DensePolynomial;
use ark_poly::DenseUVPolynomial;
use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
use ark_std::{test_rng, UniformRand};
use ark_test_curves::bls12_381::Fr;

Expand Down
4 changes: 2 additions & 2 deletions src/fri/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use ark_std::marker::PhantomData;
use crate::direct::DirectLDT;
use crate::domain::Radix2CosetDomain;
use crate::fri::FRIParameters;
use ark_crypto_primitives::sponge::FieldBasedCryptographicSponge;
use ark_ff::PrimeField;
use ark_poly::polynomial::univariate::DensePolynomial;
use ark_poly::Polynomial;
use ark_sponge::FieldBasedCryptographicSponge;
use ark_std::vec::Vec;
use ark_std::vec::*;

/// Implements FRI verifier.
pub struct FRIVerifier<F: PrimeField> {
Expand Down
Loading