Skip to content

Commit

Permalink
fix: handle inputs that are >= mod in the same way as snarkjs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian1409 authored and dkales committed Oct 24, 2024
1 parent 3d7a37d commit 76f701b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion co-circom/co-circom/src/bin/co-circom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,15 @@ where
(false, s)
};
let positive_value = if let Some(stripped) = stripped.strip_prefix("0x") {
let big_int = BigUint::from_str_radix(stripped, 16)
let mut big_int = BigUint::from_str_radix(stripped, 16)
.map_err(|_| eyre!("could not parse field element: \"{}\"", val))
.context("while parsing field element")?;
let modulus = BigUint::try_from(F::MODULUS).expect("can convert mod to biguint");
if big_int >= modulus {
tracing::warn!("val {} >= mod", big_int);
// snarkjs also does this
big_int %= modulus;
}
let big_int: F::BigInt = big_int
.try_into()
.map_err(|_| eyre!("could not parse field element: \"{}\"", val))
Expand Down

0 comments on commit 76f701b

Please sign in to comment.