| 437 | } |
| 438 | |
| 439 | pub fn hinted_inv(a: ark_bn254::Fq) -> (Script, Vec<Hint>) { |
| 440 | let mut hints = Vec::new(); |
| 441 | let x = &BigInt::from_str(&a.to_string()).unwrap(); |
| 442 | let modulus = &Fq::modulus_as_bigint(); |
| 443 | let y = &x.modinv(modulus).unwrap(); |
| 444 | let q = (x * y) / modulus; |
| 445 | let script = script! { |
| 446 | for _ in 0..Self::N_LIMBS { |
| 447 | OP_DEPTH OP_1SUB OP_ROLL // hints |
| 448 | } |
| 449 | for _ in 0..Self::N_LIMBS { |
| 450 | OP_DEPTH OP_1SUB OP_ROLL // hints |
| 451 | } |
| 452 | // { Fq::push(ark_bn254::Fq::from_str(&y.to_string()).unwrap()) } |
| 453 | // { Fq::push(ark_bn254::Fq::from_str(&q.to_string()).unwrap()) } |
| 454 | // x, y, q |
| 455 | { Fq::roll(2) } |
| 456 | { Fq::copy(2) } |
| 457 | // y, q, x, y |
| 458 | { Fq::tmul() } |
| 459 | // y, 1 |
| 460 | { Fq::push_one() } |
| 461 | { Fq::equalverify(1, 0) } |
| 462 | }; |
| 463 | hints.push(Hint::Fq(ark_bn254::Fq::from_str(&y.to_string()).unwrap())); |
| 464 | hints.push(Hint::BigIntegerTmulLC1(q)); |
| 465 | |
| 466 | (script, hints) |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | pub fn bigint_to_u32_limbs(n: BigInt, n_bits: u32) -> Vec<u32> { |