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

Support ark-bls12-381 #16

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix not padding witness vars
  • Loading branch information
piotr-roslaniec committed Jan 4, 2025
commit 9cf2892b58f1481889e7e21b853c874e24752995
7 changes: 3 additions & 4 deletions examples/less_than.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ fn num_to_bits_le_bounded<F: PrimeField>(
// TODO: Why do I need namespaces here?
// TODO: Namespace can't use string ids, only const ids
// let namespaced_cs = Namespace::from(cs.clone());
// TODO: Is it a "new_input" or a different type of a variable?
AllocatedBool::<F>::new_input(cs.clone(), || b.ok_or(SynthesisError::AssignmentMissing))
AllocatedBool::<F>::new_witness(cs.clone(), || b.ok_or(SynthesisError::AssignmentMissing))
})
.collect::<Result<Vec<AllocatedBool<F>>, SynthesisError>>()?;

Expand Down Expand Up @@ -100,7 +99,7 @@ impl<F: PrimeField> ConstraintSynthesizer<F> for LessThanCircuitUnsafe<F> {
assert!(F::MODULUS_BIT_SIZE > self.num_bits as u32 + 1);

let input_ns = ns!(cs.clone(), "input");
let input = AllocatedFp::<F>::new_input(input_ns, || Ok(self.input))?;
let input = AllocatedFp::<F>::new_witness(input_ns, || Ok(self.input))?;

let shifted_ns = ns!(cs.clone(), "shifted_diff");
let shifted_diff = AllocatedFp::<F>::new_witness(shifted_ns, || {
Expand Down Expand Up @@ -158,7 +157,7 @@ impl<F: PrimeField> ConstraintSynthesizer<F> for LessThanCircuitSafe<F> {
fn generate_constraints(self, cs: ConstraintSystemRef<F>) -> Result<(), SynthesisError> {
// TODO: Do we need to use a namespace here?
let input_ns = Namespace::from(cs.clone());
let input = AllocatedFp::<F>::new_input(input_ns, || Ok(self.input))?;
let input = AllocatedFp::<F>::new_witness(input_ns, || Ok(self.input))?;

// Perform the input bit decomposition check
num_to_bits_le_bounded::<F>(cs.clone(), input, self.num_bits)?;
Expand Down
15 changes: 7 additions & 8 deletions src/spartan/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
};
use ark_ff::{AdditiveGroup, Field};
use ark_relations::lc;
use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystem, ConstraintSystemRef};
use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystem};
use once_cell::sync::OnceCell;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -120,7 +120,7 @@ impl<G: Group, EE: EvaluationEngineTrait<G>> RelaxedR1CSSNARKTrait<G> for Relaxe

let num_vars = cs.num_witness_variables();
(num_vars..num_vars.next_power_of_two()).for_each(|i| {
cs.enforce_constraint(lc!(), lc!(), lc!())
cs.new_witness_variable(|| Ok(G::Scalar::ZERO))
.expect(&format!("Failed to enforce padding variable {i}"));
});

Expand All @@ -146,18 +146,17 @@ impl<G: Group, EE: EvaluationEngineTrait<G>> RelaxedR1CSSNARKTrait<G> for Relaxe
pk: &Self::ProverKey,
circuit: C,
) -> Result<Self, SpartanError> {
let cs = ConstraintSystem::<G::Scalar>::new();
let cs_ref = ConstraintSystemRef::new(cs.clone());
let cs_ref = ConstraintSystem::new_ref();
circuit
.generate_constraints(cs_ref.clone())
.expect("TODO: Handle error");

// Padding the variables
let num_vars = cs_ref.num_instance_variables();
// Padding the witness variables
let num_vars = cs_ref.num_witness_variables();
(num_vars..num_vars.next_power_of_two()).for_each(|i| {
cs_ref
.enforce_constraint(lc!(), lc!(), lc!())
.expect(&format!("Failed to enforce padding constraint {i}"));
.new_witness_variable(|| Ok(G::Scalar::ZERO))
.expect(&format!("Failed to enforce padding variable {i}"));
});

let cs = cs_ref.borrow().unwrap();
Expand Down
Loading