Compute square of an Fq12 elements in normalized form (1 + c J) <- (1 + a J) x (1 + a J). Input a, and output c. In this form (1 + c J) <- 1 + {(2a)/(1 + a^2 J^2)} => c . (1 + a^2 J^2) =?= 2a a c are passed as input to the script and the above equation is validated to show that c is the correct output Assumes input a is valid i.e (1 + a^2 J ^2) != 0
(a: ark_bn254::Fq6)
| 287 | // a c are passed as input to the script and the above equation is validated to show that c is the correct output |
| 288 | // Assumes input a is valid i.e (1 + a^2 J ^2) != 0 |
| 289 | pub(crate) fn utils_fq12_square(a: ark_bn254::Fq6) -> (ark_bn254::Fq6, bool, Script, Vec<Hint>) { |
| 290 | let mut hints = vec![]; |
| 291 | |
| 292 | // compute ab in Script |
| 293 | let (asq_scr, ab_hints) = Fq6::hinted_square(a); |
| 294 | hints.extend_from_slice(&ab_hints); |
| 295 | |
| 296 | // calculate denom |
| 297 | let beta_sq = ark_bn254::Fq12Config::NONRESIDUE; |
| 298 | let denom = ark_bn254::Fq6::ONE + a * a * beta_sq; |
| 299 | |
| 300 | // is input valid ? output: mock_output |
| 301 | let (denom_mul_c_scr, c) = { |
| 302 | let c = (a + a) / denom; |
| 303 | let res = Fq6::hinted_mul(6, denom, 0, c); |
| 304 | hints.extend_from_slice(&res.1); |
| 305 | (res.0, c) |
| 306 | }; |
| 307 | |
| 308 | let mul_by_beta_sq_scr = script! { |
| 309 | {Fq6::mul_fq2_by_nonresidue()} |
| 310 | {Fq2::roll(4)} {Fq2::roll(4)} |
| 311 | }; |
| 312 | |
| 313 | let scr = script! { |
| 314 | // [hints a, c] [] |
| 315 | {Fq6::toaltstack()} |
| 316 | // [hints, a], [c] |
| 317 | {Fq6::copy(0)} |
| 318 | // [hints a, a] [c] |
| 319 | {asq_scr} |
| 320 | // [hints, a, asq] |
| 321 | {mul_by_beta_sq_scr} |
| 322 | // [hints, a, asq*beta_sq] |
| 323 | {Fq6::push(ark_bn254::Fq6::ONE)} |
| 324 | {Fq6::add(6, 0)} |
| 325 | // [hints, a, denom] [c] |
| 326 | {Fq6::fromaltstack()} |
| 327 | // [hints, a, denom, c] |
| 328 | {Fq6::copy(0)} |
| 329 | // [hints, a, denom, c, c] |
| 330 | {Fq6::roll(12)} {Fq6::roll(12)} |
| 331 | // [hints, a, c, denom, c] |
| 332 | {denom_mul_c_scr} |
| 333 | // [a, c, denom_c] |
| 334 | {Fq6::copy(12)} |
| 335 | // [a, c, denom_c, a] |
| 336 | {Fq6::double(0)} |
| 337 | // [a, c, denom_c, 2a] |
| 338 | {Fq6::equalverify()} |
| 339 | // [a,c] [] |
| 340 | {1} |
| 341 | // [a, c, 0/1] |
| 342 | }; |
| 343 | |
| 344 | let input_is_valid = denom != ark_bn254::Fq6::ZERO; |
| 345 | (c, input_is_valid, scr, hints) |
| 346 | } |
no outgoing calls