Browse Source

Fix the incorrect `NonNativeAffineVar::inputize` implementation (#89)

* Fix the incorrect `NonNativeAffineVar::inputize` implementation

* Fmt and clippy
main
winderica 8 months ago
committed by GitHub
parent
commit
d23e6d1886
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 15 deletions
  1. +4
    -11
      folding-schemes/src/folding/circuits/nonnative/affine.rs
  2. +3
    -4
      folding-schemes/src/folding/circuits/nonnative/uint.rs

+ 4
- 11
folding-schemes/src/folding/circuits/nonnative/affine.rs

@ -1,5 +1,4 @@
use ark_ec::{AffineRepr, CurveGroup};
use ark_ff::PrimeField;
use ark_r1cs_std::{
alloc::{AllocVar, AllocationMode},
fields::fp::FpVar,
@ -95,20 +94,14 @@ where
pub fn inputize(p: C) -> Result<(Vec<C::ScalarField>, Vec<C::ScalarField>), SynthesisError> {
let affine = p.into_affine();
if affine.is_zero() {
let x = NonNativeUintVar::inputize(
&(C::ScalarField::zero()).into(),
C::ScalarField::MODULUS_BIT_SIZE as usize,
);
let y = NonNativeUintVar::inputize(
&(C::ScalarField::zero()).into(),
C::ScalarField::MODULUS_BIT_SIZE as usize,
);
let x = NonNativeUintVar::inputize(C::BaseField::zero());
let y = NonNativeUintVar::inputize(C::BaseField::zero());
return Ok((x, y));
}
let (x, y) = affine.xy().unwrap();
let x = NonNativeUintVar::inputize(&(*x).into(), C::ScalarField::MODULUS_BIT_SIZE as usize);
let y = NonNativeUintVar::inputize(&(*y).into(), C::ScalarField::MODULUS_BIT_SIZE as usize);
let x = NonNativeUintVar::inputize(*x);
let y = NonNativeUintVar::inputize(*y);
Ok((x, y))
}
}

+ 3
- 4
folding-schemes/src/folding/circuits/nonnative/uint.rs

@ -256,10 +256,9 @@ impl AllocVar for NonNativeUintVar {
}
impl<F: PrimeField> NonNativeUintVar<F> {
pub fn inputize(x: &BigUint, l: usize) -> Vec<F> {
(0..l)
.map(|i| x.bit(i as u64))
.collect::<Vec<_>>()
pub fn inputize<T: PrimeField>(x: T) -> Vec<F> {
x.into_bigint()
.to_bits_le()
.chunks(Self::bits_per_limb())
.map(|chunk| F::from_bigint(F::BigInt::from_bits_le(chunk)).unwrap())
.collect()

Loading…
Cancel
Save