arkworks-rs / r1cs-std

R1CS constraints for bits, fields, and elliptic curves
https://www.arkworks.rs
Apache License 2.0
133 stars 58 forks source link

Short Weierstrass `G1Var::new_input` behaves differently from `G1::to_field_elements` #106

Open nulltea opened 1 year ago

nulltea commented 1 year ago

Summary of Bug

There's a discrepancy between input variable allocation and constraint field conversion for the Short Weierstrass curve group, specifically, how the infinity marker's value field is used.

For the curve group, it's either zero or one depending on the value of the infinity marker. Please see the following trace:

  1. https://github.com/arkworks-rs/algebra/blob/master/ec/src/models/short_weierstrass/group.rs#L624
  2. https://github.com/arkworks-rs/algebra/blob/master/ec/src/models/short_weierstrass/affine.rs#L390
  3. https://github.com/arkworks-rs/algebra/blob/master/ff/src/to_field_vec.rs#L14

However, in the r1cs variant it's always F::one, see: https://github.com/arkworks-rs/r1cs-std/blob/master/src/groups/curves/short_weierstrass/mod.rs#L219

For the algebra repo, the behavior seems correct. I see that for r1cs there is conversion after allocation here, but since the FpVar was already allocated as FpVar::one, I get a conflict during proof verification.

Version

Reproduces in v0.3.0 and the latest master.

Steps to Reproduce

  1. Allocate short_weierstrass::G1Var with non-infinity value
  2. Generate proof
  3. Get public input
  4. Verify proof