mirror of
https://github.com/logos-storage/circom-compat.git
synced 2026-01-06 06:53:09 +00:00
fix: negate negative witness elements
This commit is contained in:
parent
c32270a285
commit
de9af5b9e6
@ -75,11 +75,22 @@ impl<E: PairingEngine> CircomBuilder<E> {
|
|||||||
.wtns
|
.wtns
|
||||||
.calculate_witness(self.inputs, self.cfg.sanity_check)?;
|
.calculate_witness(self.inputs, self.cfg.sanity_check)?;
|
||||||
|
|
||||||
|
use ark_ff::{PrimeField, FpParameters};
|
||||||
|
let modulus = <<E::Fr as PrimeField>::Params as FpParameters>::MODULUS;
|
||||||
|
|
||||||
// convert it to field elements
|
// convert it to field elements
|
||||||
|
use num_traits::Signed;
|
||||||
let witness = witness
|
let witness = witness
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|w| E::Fr::from(w.to_biguint().unwrap()))
|
.map(|w| {
|
||||||
.collect::<Vec<_>>();
|
let w = if w.sign() == num_bigint::Sign::Minus {
|
||||||
|
// Need to negate the witness element if negative
|
||||||
|
modulus.into() - w.abs().to_biguint().unwrap()
|
||||||
|
} else {
|
||||||
|
w.to_biguint().unwrap()
|
||||||
|
};
|
||||||
|
E::Fr::from(w)
|
||||||
|
}).collect::<Vec<_>>();
|
||||||
circom.witness = Some(witness);
|
circom.witness = Some(witness);
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user