MCPcopy Create free account
hub / github.com/BitVM/BitVM / hinted_inv

Method hinted_inv

bitvm/src/bn254/fq.rs:439–467  ·  view source on GitHub ↗
(a: ark_bn254::Fq)

Source from the content-addressed store, hash-verified

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
470pub fn bigint_to_u32_limbs(n: BigInt, n_bits: u32) -> Vec<u32> {

Callers

nothing calls this directly

Calls 2

FqClass · 0.85
pushMethod · 0.45

Tested by

no test coverage detected