From d23e6d188637f0890a59d0ffc76db9589656afa6 Mon Sep 17 00:00:00 2001 From: winderica Date: Wed, 17 Apr 2024 09:32:34 +0100 Subject: [PATCH] Fix the incorrect `NonNativeAffineVar::inputize` implementation (#89) * Fix the incorrect `NonNativeAffineVar::inputize` implementation * Fmt and clippy --- .../src/folding/circuits/nonnative/affine.rs | 15 ++++----------- .../src/folding/circuits/nonnative/uint.rs | 7 +++---- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/folding-schemes/src/folding/circuits/nonnative/affine.rs b/folding-schemes/src/folding/circuits/nonnative/affine.rs index a5e2af9..33df868 100644 --- a/folding-schemes/src/folding/circuits/nonnative/affine.rs +++ b/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, Vec), 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)) } } diff --git a/folding-schemes/src/folding/circuits/nonnative/uint.rs b/folding-schemes/src/folding/circuits/nonnative/uint.rs index 49f5fe0..bb627e5 100644 --- a/folding-schemes/src/folding/circuits/nonnative/uint.rs +++ b/folding-schemes/src/folding/circuits/nonnative/uint.rs @@ -256,10 +256,9 @@ impl AllocVar for NonNativeUintVar { } impl NonNativeUintVar { - pub fn inputize(x: &BigUint, l: usize) -> Vec { - (0..l) - .map(|i| x.bit(i as u64)) - .collect::>() + pub fn inputize(x: T) -> Vec { + x.into_bigint() + .to_bits_le() .chunks(Self::bits_per_limb()) .map(|chunk| F::from_bigint(F::BigInt::from_bits_le(chunk)).unwrap()) .collect()