philsippl / circom-witness-rs

MIT License
60 stars 13 forks source link

Missing ops #8

Open NikZak opened 9 months ago

NikZak commented 9 months ago

My circuit requires: Fr_element2str Fr_neg Fr_div Fr_band Fr_shr

I am happy to help implementing those if you could provide a bit of guidance. Thank you!

NikZak commented 9 months ago

and Fr_pow

biscuitdey commented 7 months ago

@NikZak

A. To extend the eval functions, we can do the following using ruint library:

  1. Fr_neg --> Neg => (M - a) assuming M is the field's order. This has been used to calculate Sub
  2. Fr_div --> Div => a.mul_mod (b.inv_mod(M), M) use inv_mod from ruint::algorithms as this uses Extended Euclidean Algorithm to calculate the inverse.
  3. Fr_pow --> Pow => a.pow_mod(b, M)

B. To extend the eval_fr functions, we can do the following: The Prime Field Fr = Fp256<MontBackend<FrConfig, 4>> elements are implemented using the ark_ff library, which provides functions for calculating negative, division, etc. Adding the following code to the graph.rs file, under the impl Operation -> eval_fr might work :

Neg => a.neg_in_place(),
FromString => Fr::from_str("testString"),
Div => a / b

Source:

  1. Ark prime fields library : ark_ff
  2. Ark BN254 curve example (similar to ark_bn254 curve used) : curve
  3. Arkworks-rs guide
  4. Arkworks-rs github