| 372 | } |
| 373 | |
| 374 | pub(crate) fn chunk_final_verify( |
| 375 | f: ark_bn254::Fq6, |
| 376 | fixed_p1q1: ark_bn254::Fq6, |
| 377 | |
| 378 | t4: ark_bn254::G2Affine, |
| 379 | q4: ark_bn254::G2Affine, |
| 380 | ) -> (bool, Script, Vec<Hint>) { |
| 381 | let (qq, precomp_q_scr, hints) = hinted_mul_by_char_on_phi_sq_q(q4); |
| 382 | |
| 383 | let t4_is_in_subgroup = t4 == -qq; |
| 384 | let fp12_is_unity = f + fixed_p1q1 == ark_bn254::Fq6::ZERO; |
| 385 | let is_valid = t4_is_in_subgroup && fp12_is_unity; |
| 386 | |
| 387 | let fp12_is_unity_scr = script!( |
| 388 | // [f] |
| 389 | {Fq6::push(fixed_p1q1)} |
| 390 | {Fq6::add(6, 0)} |
| 391 | for _ in 0..6 { |
| 392 | {Fq::push(ark_bn254::Fq::ZERO)} |
| 393 | {Fq::equal(1, 0)} |
| 394 | OP_TOALTSTACK |
| 395 | } |
| 396 | {1} |
| 397 | for _ in 0..6 { |
| 398 | OP_FROMALTSTACK |
| 399 | OP_BOOLAND |
| 400 | } |
| 401 | // [0/1] |
| 402 | ); |
| 403 | |
| 404 | let ops_scr = script! { |
| 405 | // [f, {t4, ht4_le}] [in_t4hash, in_fhash, q4] |
| 406 | |
| 407 | // Validity checks: f is Fq6, t4 is G2Affine, ht4_le is a hash and q4 is G2Affine |
| 408 | { G2Affine::fromaltstack() } |
| 409 | { Fq2::toaltstack() } { Fq2::toaltstack() } // q4 doesn't need a validity check |
| 410 | { Fq::toaltstack() } //ht4_le |
| 411 | { Fq2::check_validity() } { Fq2::check_validity() } //t4 |
| 412 | { Fq6::check_validity() } { Fq6::fromaltstack() } //f, moved back to the top of the stack |
| 413 | |
| 414 | // [f] [in_t4hash, in_fhash, q4, ht4le, t4] |
| 415 | {Fq6::copy(0)} |
| 416 | {fp12_is_unity_scr} |
| 417 | // [f, fp12_is_unity] [in_t4hash, in_fhash, q4, ht4le, t4] |
| 418 | {G2Affine::fromaltstack()} |
| 419 | {Fq::fromaltstack()} |
| 420 | // [f, fp12_is_unity, {t4, ht4le}] [in_t4hash, in_fhash, q4] |
| 421 | {G2Affine::fromaltstack()} |
| 422 | // [f, fp12_is_unity, {t4, ht4le}, q4] [in_t4hash, in_fhash] |
| 423 | {precomp_q_scr} |
| 424 | // [f, fp12_is_unity, {t4, ht4le}, q4_dash] [in_t4hash, in_fhash] |
| 425 | {Fq::toaltstack()} |
| 426 | {Fq::neg(0)} |
| 427 | {Fq::fromaltstack()} |
| 428 | {Fq::neg(0)} |
| 429 | // [f, fp12_is_unity, {t4, ht4le}, -q4_dash] [in_t4hash, in_fhash] |
| 430 | for _ in 0..4 { |
| 431 | {Fq::copy(8)} |