package octez-libs
A package that contains multiple base libraries used by the Octez suite
Install
Dune Dependency
Authors
Maintainers
Sources
tezos-octez-v20.1.tag.bz2
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65
doc/src/octez-libs.plonk/ecc_gates.ml.html
Source file ecc_gates.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
(*****************************************************************************) (* *) (* MIT License *) (* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) open Kzg.Bls open Identities module L = Plompiler.LibCircuit open Gates_common (* Weierstrass elliptic curve addition : checks that (a, ag) + (b, bg) = (c, cg) Non Arith degree : 4n nb identities : 2 advice selectors : None equations : with λ = (bg - ag) / (b - a), 1) q·[ (a + b + c)·(b - a)² - (bg - ag)² ] = 0 2) q·[ (ag + cg)·(b - a) - (a - c)·(bg - ag) ] = 0 /!\ q must be 0 or 1 *) module AddWeierstrass : Base_sig = struct let q_label = "qecc_ws_add" let identity = (q_label, 2) let index_com = None let nb_advs = 0 let nb_buffers = 3 let gx_composition = true let equations ~q ~wires ~wires_g ?precomputed_advice:_ () = if Scalar.is_zero q then Scalar.[zero; zero] else if not (Scalar.(is_one) q) then failwith "AddWeierstrass.equations : qecc_ws_add must be zero or one." else let a = wires.(0) in let b = wires.(1) in let c = wires.(2) in let ag = wires_g.(0) in let bg = wires_g.(1) in let cg = wires_g.(2) in let lambda = Scalar.(div_exn (sub bg ag) (sub b a)) in let x = Scalar.(sub (lambda * lambda) (a + b)) in let y = Scalar.(sub (lambda * sub a x) ag) in Scalar.[sub x c; sub y cg] let prover_identities ~prefix_common ~prefix ~public:_ ~domain : prover_identities = fun evaluations -> (* lambda: numerator = (bg - ag) ; denominator = (b - a) *) (* identity on new point's x coordinate: (c + b + a)·(b - a)^2 - (bg - ag)^2 = 0 *) let domain_size = Domain.length domain in let tmps, ids = get_buffers ~nb_buffers ~nb_ids:(snd identity) in let ({q; wires} : witness) = get_evaluations ~q_label ~prefix ~prefix_common evaluations in let a = wires.(0) in let b = wires.(1) in let c = wires.(2) in (* tmps.(2) <- (b - a) *) let b_minus_a = Evaluations.linear_c ~res:tmps.(2) ~evaluations:[b; a] ~linear_coeffs:[one; mone] () in (* tmps.(1) <- (b - a)^2 *) let b_minus_a_sqr = Evaluations.mul_c ~res:tmps.(1) ~evaluations:[b_minus_a] ~powers:[2] () in (* ids.(1) <- (a + b + c) *) let a_plus_b_plus_c = Evaluations.linear_c ~res:ids.(1) ~evaluations:[a; b; c] () in (* tmps.(0) <- (a + b + c)·(b - a)^2 *) let left_term = Evaluations.mul_c ~res:tmps.(0) ~evaluations:[a_plus_b_plus_c; b_minus_a_sqr] () in (* ids.(1) <- (a + b + c)·(b - a)^2 - (bg - ag)^2 *) let first_identity = Evaluations.linear_c ~res:ids.(1) ~evaluations:[left_term; b_minus_a_sqr] ~composition_gx:([0; 1], domain_size) ~linear_coeffs:[one; mone] () in let first_identity = Evaluations.mul_c ~res:ids.(0) ~evaluations:[q; first_identity] () in (* identity on new point's y coordinate: (cg + ag)·(b - a) - (bg - ag)·(a - c) = 0 *) (* ids.(1) <- (cg + ag) *) let cg_plus_ag = Evaluations.linear_c ~res:ids.(1) ~evaluations:[c; a] ~composition_gx:([1; 1], domain_size) () in (* tmps.(0) <- (cg + ag)·(b - a) *) let left_term_2 = Evaluations.mul_c ~res:tmps.(0) ~evaluations:[cg_plus_ag; b_minus_a] () in (* ids.(1) <- (a - c) *) let a_minus_c = Evaluations.linear_c ~res:ids.(1) ~evaluations:[a; c] ~linear_coeffs:[one; mone] () in (* tmps.(1) <- (bg - ag)·(a - c) *) let right_term_2 = Evaluations.mul_c ~res:tmps.(1) ~evaluations:[b_minus_a; a_minus_c] ~composition_gx:([1; 0], domain_size) () in (* tmps.(2) <- (cg + ag)·(b - a) - (bg - ag)·(a - c) *) let second_identity = Evaluations.linear_c ~res:tmps.(2) ~evaluations:[left_term_2; right_term_2] ~linear_coeffs:[one; mone] () in let second_identity = Evaluations.mul_c ~res:ids.(1) ~evaluations:[q; second_identity] () in SMap.of_list [ (prefix @@ q_label ^ ".0", first_identity); (prefix @@ q_label ^ ".1", second_identity); ] let verifier_identities ~prefix_common ~prefix ~public:_ ~generator:_ ~size_domain:_ : verifier_identities = fun _ answers -> let {q; wires; wires_g} = get_answers ~gx:true ~q_label ~prefix ~prefix_common answers in let a, b, c = (wires.(0), wires.(1), wires.(2)) in let ag, bg, cg = (wires_g.(0), wires_g.(1), wires_g.(2)) in let num_lambda = Scalar.(sub bg ag) in let den_lambda = Scalar.(sub b a) in (* identity on new point's x coordinate: (c + b + a)·(b - a)^2 - (bg - ag)^2 = 0 *) let first_identity = let num_lambda2 = Scalar.mul num_lambda num_lambda in let den_lambda2 = Scalar.mul den_lambda den_lambda in let id = Scalar.(sub ((c + b + a) * den_lambda2) num_lambda2) in Scalar.mul q id in (* identity on new point's y coordinate: (cg + ag)·(b - a) - (bg - ag)·(a - c) = 0 *) let second_identity = let id = Scalar.(sub ((cg + ag) * den_lambda) (num_lambda * sub a c)) in Scalar.mul q id in SMap.of_list [ (prefix @@ q_label ^ ".0", first_identity); (prefix @@ q_label ^ ".1", second_identity); ] let polynomials_degree = SMap.of_list [(wire_name 0, 4); (wire_name 1, 4); (wire_name 2, 4); (q_label, 4)] let cs ~q:qec ~wires ~wires_g ?precomputed_advice:_ () = let a = wires.(0) in let b = wires.(1) in let c = wires.(2) in let ag = wires_g.(0) in let bg = wires_g.(1) in let cg = wires_g.(2) in let open L in let open Num in let sub = add ~qr:mone in let* lambda_num = sub bg ag in let* lambda_denom = sub b a in let* lambda_num2 = mul lambda_num lambda_num in let* cba = add_list (to_list [c; b; a]) in let* fst_term = mul_list (to_list [cba; lambda_denom; lambda_denom]) in let* fst = sub fst_term lambda_num2 in let* fst = mul qec fst in let* cgag = add cg ag in let* ac = sub a c in let* fst_term = mul cgag lambda_denom in let* snd_term = mul lambda_num ac in let* snd = sub fst_term snd_term in let* snd = mul qec snd in ret [fst; snd] end (* Edwards elliptic curve addition : checks that P + Q = R Non Arith degree : 6n nb identities : 2 advice selectors : None equations : 1) q · [ r ·(1 + param_d · px · qx · py · qy) - (px · bg + qx · py) ] = 0 2) q · [ ry ·(1 - param_d · px · qx · py · qy) - (qy · py - param_a · qx · px) ] = 0 /!\ q must be 0 or 1 *) module AddEdwards : Base_sig = struct let q_label = "qecc_ed_add" let identity = (q_label, 2) let index_com = None let nb_advs = 0 let nb_buffers = 2 let gx_composition = true (* JubJub curve parameters *) let param_a = mone let param_d = Scalar.of_string "19257038036680949359750312669786877991949435402254120286184196891950884077233" let equations ~q ~wires ~wires_g ?precomputed_advice:_ () = if Scalar.is_zero q then Scalar.[zero; zero] else if not (Scalar.is_one q) then failwith "AddEdwards.equations : qecc_ed_add must be zero or one." else let px = wires.(0) in let py = wires_g.(0) in let qx = wires.(1) in let qy = wires_g.(1) in let rx = wires.(2) in let ry = wires_g.(2) in let pxqy = Scalar.(px * qy) in let qxpy = Scalar.(qx * py) in let pyqy = Scalar.(py * qy) in let pxqx = Scalar.(px * qx) in let rx' = Scalar.((pxqy + qxpy) / (one + (param_d * pxqy * qxpy))) in let ry' = Scalar.( (pyqy + (negate param_a * pxqx)) / (one + (negate param_d * pxqy * qxpy))) in Scalar.[rx' + negate rx; ry' + negate ry] let prover_identities ~prefix_common ~prefix ~public:_ ~domain : prover_identities = fun evaluations -> let domain_size = Domain.length domain in let tmps, ids = get_buffers ~nb_buffers ~nb_ids:(snd identity) in let ({q; wires} : witness) = get_evaluations ~q_label ~prefix ~prefix_common evaluations in let s = q in let p = wires.(0) in let q = wires.(1) in let r = wires.(2) in (* identity on new point's x coordinate: q · [r_x · (1 + Params_d · p_x · q_x · p_y · q_y) - (q_x · q_y + p_y · q_x)] = 0 *) (* tmps.(0) <- p_x · q_y *) let px_mul_qy = Evaluations.mul_c ~res:tmps.(0) ~evaluations:[p; q] ~composition_gx:([0; 1], domain_size) () in (* tmps.(1) <- p_y · q_x *) let py_mul_qx = Evaluations.mul_c ~res:tmps.(1) ~evaluations:[p; q] ~composition_gx:([1; 0], domain_size) () in (* ids.(0) <- px · py · qx · qy *) let px_mul_py_mul_qx_mul_qy = Evaluations.mul_c ~res:ids.(0) ~evaluations:[px_mul_qy; py_mul_qx] () in (* ids.(1) <- 1 + Params_d · px · py · qx · qy *) let one_plus_d_mul_px_mul_py_mul_qx_mul_qy = Evaluations.linear_c ~res:ids.(1) ~evaluations:[px_mul_py_mul_qx_mul_qy] ~linear_coeffs:[param_d] ~add_constant:one () in (* ids.(0) <- px · qy + py · qx *) let px_mul_qy_plus_py_mul_qx = Evaluations.linear_c ~res:ids.(0) ~evaluations:[px_mul_qy; py_mul_qx] () in (* tmps.(0) <- rx · (1 + Params_d · px · py · qx · qy) *) let rx_mul_one_plus_d_mul_px_mul_py_mul_qx_mul_qy = Evaluations.mul_c ~res:tmps.(0) ~evaluations:[one_plus_d_mul_px_mul_py_mul_qx_mul_qy; r] () in (* tmps.(1) <- rx · (1 + Params_d · px · py · qx · qy) - (px · qy + py · qx) *) let first_identity = Evaluations.linear_c ~res:tmps.(1) ~evaluations: [ rx_mul_one_plus_d_mul_px_mul_py_mul_qx_mul_qy; px_mul_qy_plus_py_mul_qx; ] ~linear_coeffs:[one; mone] () in let first_identity = Evaluations.mul_c ~res:ids.(0) ~evaluations:[s; first_identity] () in (* identity on new point's y coordinate: q * [ry * (1 - Params_d * p_x * q_x * p_y * q_y) - (p_y * q_y - Params_a * p_x * q_x)] = 0 *) (* tmps.(1) <- (1 - Params_d · px · py · qx · qy) *) let one_minus_d_mul_px_mul_py_mul_qx_mul_qy = Evaluations.linear_c ~res:tmps.(1) ~evaluations:[one_plus_d_mul_px_mul_py_mul_qx_mul_qy] ~linear_coeffs:[mone] ~add_constant:two () in (* tmps.(0) <- ry · (1 - Params_d · px · py · qx · qy) *) let ry_mul_one_minus_d_mul_px_mul_py_mul_qx_mul_qy = Evaluations.mul_c ~res:tmps.(0) ~evaluations:[one_minus_d_mul_px_mul_py_mul_qx_mul_qy; r] ~composition_gx:([0; 1], domain_size) () in (* ids.(1) <- px · qx *) let px_mul_qx = Evaluations.mul_c ~res:ids.(1) ~evaluations:[p; q] () in (* tmps.(1) <- ry · (1 - Params_d · px · py · qx · qy) - py · qy + Params_a · px · qx *) let second_identity = Evaluations.linear_c ~res:tmps.(1) ~evaluations: [ry_mul_one_minus_d_mul_px_mul_py_mul_qx_mul_qy; px_mul_qx; px_mul_qx] ~composition_gx:([0; 1; 0], domain_size) ~linear_coeffs:[one; mone; param_a] () in let second_identity = Evaluations.mul_c ~res:ids.(1) ~evaluations:[s; second_identity] () in SMap.of_list [ (prefix @@ q_label ^ ".0", first_identity); (prefix @@ q_label ^ ".1", second_identity); ] let verifier_identities ~prefix_common ~prefix ~public:_ ~generator:_ ~size_domain:_ : verifier_identities = fun _ answers -> let {q; wires; wires_g} = get_answers ~gx:true ~q_label ~prefix ~prefix_common answers in let px, py = (wires.(0), wires_g.(0)) in let qx, qy = (wires.(1), wires_g.(1)) in let rx, ry = (wires.(2), wires_g.(2)) in let pxqx = Scalar.mul px qx in let pyqy = Scalar.mul py qy in let den_common = Scalar.(param_d * pxqx * pyqy) in (* q·[x3·(1 + d·x1·x2·y1·y2) - (x1·y2 + y1·x2)] = 0 *) let first_identity = let num = Scalar.((px * qy) + (py * qx)) in let den = Scalar.(one + den_common) in let id = Scalar.(sub (rx * den) num) in Scalar.mul q id in (* q · [ry · (1 - d · px · qx · py · qy) - (py · qy - a · px · qx)] = 0 *) let second_identity = let num = Scalar.(sub pyqy (param_a * pxqx)) in let den = Scalar.(sub one den_common) in let id = Scalar.(sub (ry * den) num) in Scalar.mul q id in SMap.of_list [ (prefix @@ q_label ^ ".0", first_identity); (prefix @@ q_label ^ ".1", second_identity); ] let polynomials_degree = SMap.of_list [(wire_name 0, 6); (wire_name 1, 6); (wire_name 2, 6); (q_label, 6)] let cs ~q:qec ~wires ~wires_g ?precomputed_advice:_ () = let px = wires.(0) in let py = wires_g.(0) in let qx = wires.(1) in let qy = wires_g.(1) in let rx = wires.(2) in let ry = wires_g.(2) in let open L in let open Num in let sub = add ~qr:mone in let* pxqy = mul px qy in let* qxpy = mul qx py in (* 1 + d · p_x · q_x · p_y · q_y *) let* den = custom ~qc:Scalar.one ~qm:param_d pxqy qxpy in let* fst_term = mul rx den in let* snd_term = add pxqy qxpy in let* fst_id = sub fst_term snd_term in let* fst_id = mul qec fst_id in (* 1 - d · p_x · q_x · p_y · q_y *) let* den' = add_constant two ~ql:mone den in (* r_y · (1 - d · p_x · q_x · p_y · q_y) *) let* fst_term = mul ry den' in (* p_y · q_y - a · p_x · q_x *) let* snd_term = let* pyqy = mul py qy in let* apxqx = mul ~qm:param_a px qx in sub pyqy apxqx in let* snd_id = sub fst_term snd_term in let* snd_id = mul qec snd_id in ret [fst_id; snd_id] end (* Edwards elliptic curve conditional addition : checks that P(d, e) + a · Q = R Non Arith degree : 7n nb identities : 2 advice selectors : None equations : · q · [ rx · (1 + param_d · bit · qx · qy · px · py) - (px + bit · (px · qy + qx · py - px)) ] = 0 · q · [ ry · (1 - param_d · bit · qx · qy · px · py) - (py + bit · (py · qy - param_a · qx · px - py)) ] = 0 *) module ConditionalAddEdwards : Base_sig = struct let q_label = "qecc_ed_cond_add" let identity = (q_label, 2) let index_com = None let nb_advs = 0 let nb_buffers = 3 let gx_composition = true (* JubJub curve parameters *) let param_a = mone let param_d = Scalar.of_string "19257038036680949359750312669786877991949435402254120286184196891950884077233" (* Let P = (p_x; p_y), Q = (q_x; q_y), R = (r_x; r_y), b in {0,1}. This gate asserts that R = P + b * Q. b * Q = Q if b = 1 and (0, 1) if b = 0, so b * Q can be written as: (b * q_x; b * q_y + 1 - b) Let a et d the Edwards curve parameters. We thus have the following identities: r_x = (p_x * (b * q_y + 1 - b) + b * q_x * p_y) / (1 + d * p_x * b * q_x * p_y * (b * q_y + 1 - b)) r_y = (p_y * (b * q_y + 1 - b) - a * p_x * b * q_x) / (1 - d * p_x * b * q_x * p_y * (b * q_y + 1 - b)) We put in the wires a, b and c the point coordinates in this order: a b c d e wire #i: bit q_x q_y p_x p_y wire #i+1: r_x r_y Simplifying the equations, we get: r_x = (p_x * (b * q_y + 1 - b) + b * q_x * p_y) / (1 + b * d * p_x * q_x * p_y * q_y) r_y = (p_y * (b * q_y + 1 - b) - b * a * p_x * q_x) / (1 - b * d * p_x * q_x * p_y * q_y) *) let equations ~q ~wires ~wires_g ?precomputed_advice:_ () = if Scalar.is_zero q then Scalar.[zero; zero] else let bit = wires.(0) in let qx = wires.(1) in let qy = wires.(2) in let px = wires.(3) in let py = wires.(4) in let rx = wires_g.(3) in let ry = wires_g.(4) in let qx' = Scalar.(bit * qx) in let qy' = Scalar.((bit * qy) + sub one bit) in let pxqy' = Scalar.(px * qy') in let qx'py = Scalar.(qx' * py) in let pyqy' = Scalar.(py * qy') in let pxqx' = Scalar.(px * qx') in let rx' = Scalar.((pxqy' + qx'py) / (one + (param_d * pxqy' * qx'py))) in let ry' = Scalar.( (pyqy' + (negate param_a * pxqx')) / (one + (negate param_d * pxqy' * qx'py))) in Scalar.[rx' + negate rx; ry' + negate ry] let prover_identities ~prefix_common ~prefix ~public:_ ~domain evaluations = let domain_size = Domain.length domain in let tmps, ids = get_buffers ~nb_buffers ~nb_ids:(snd identity) in let ({q; wires} : witness) = get_evaluations ~q_label ~prefix ~prefix_common evaluations in let b = wires.(0) in let qx, qy = (wires.(1), wires.(2)) in let px, py = (wires.(3), wires.(4)) in (* (rx, ry) will be evaluated on GX *) let rx, ry = (px, py) in (* identity on new point's x coordinate: q · [r_x · (1 + d · b · p_x · q_x · p_y · q_y) - (b · p_x · q_y + p_x - b · p_x + b · q_x · p_y) = 0] *) (* tmps.(0) <- b · px · qy *) let b_mul_px_mul_qy = Evaluations.mul_c ~res:tmps.(0) ~evaluations:[b; px; qy] () in (* tmps.(1) <- py · qx *) let py_mul_qx = Evaluations.mul_c ~res:tmps.(1) ~evaluations:[py; qx] () in (* tmps.(2) <- b · px *) let b_mul_px = Evaluations.mul_c ~res:tmps.(2) ~evaluations:[b; px] () in (* ids.(0) <- b · px · py · qx · qy *) let b_mul_px_mul_py_mul_qx_mul_qy = Evaluations.mul_c ~res:ids.(0) ~evaluations:[b_mul_px_mul_qy; py_mul_qx] () in (* ids.(1) <- 1 + Params_d · b · px · py · qx · qy *) let den1 = Evaluations.linear_c ~res:ids.(1) ~evaluations:[b_mul_px_mul_py_mul_qx_mul_qy] ~linear_coeffs:[param_d] ~add_constant:one () in (* tmps.(1) <- b · py · qx *) let b_mul_py_mul_qx = Evaluations.mul_c ~res:tmps.(1) ~evaluations:[b; py; qx] () in (* ids.(0) <- px - b · px + b · px · qy + b · py · qx *) let rhs = Evaluations.linear_c ~res:ids.(0) ~evaluations:[px; b_mul_px; b_mul_px_mul_qy; b_mul_py_mul_qx] ~linear_coeffs:[one; mone; one; one] () in (* tmps.(0) <- rx · (1 + Params_d · b · px · py · qx · qy) *) let lhs = Evaluations.mul_c ~res:tmps.(0) ~evaluations:[den1; rx] ~composition_gx:([0; 1], domain_size) () in (* tmps.(1) <- rx · (1 + Params_d · b · px · py · qx · qy) - (px - b · px + b · px · qy + b · py · qx) *) let first_identity = Evaluations.linear_c ~res:tmps.(1) ~evaluations:[lhs; rhs] ~linear_coeffs:[one; mone] () in let first_identity = Evaluations.mul_c ~res:ids.(0) ~evaluations:[q; first_identity] () in (* identity on new point's y coordinate: q · [r_y · (1 - d · b · p_x · q_x · p_y · q_y) - (b · p_y · q_y + p_y - p_y · b - a · p_x · b · q_x)] = 0 *) (* tmps.(1) <- (1 - Params_d · b · px · py · qx · qy) *) let den2 = Evaluations.linear_c ~res:tmps.(1) ~evaluations:[den1] ~linear_coeffs:[mone] ~add_constant:two () in (* tmps.(0) <- ry · (1 - Params_d · px · py · qx · qy) *) let lhs = Evaluations.mul_c ~res:tmps.(0) ~evaluations:[den2; ry] ~composition_gx:([0; 1], domain_size) () in (* ids.(1) <- px · qx *) let px_mul_qx = Evaluations.mul_c ~res:ids.(1) ~evaluations:[px; qx] () in (* tmps.(1) <- py · qy *) let py_mul_qy = Evaluations.mul_c ~res:tmps.(1) ~evaluations:[py; qy] () in let minus_a_mul_px_mul_qx_plus_py_mul_qy_minus_py = Evaluations.linear_c ~res:tmps.(2) ~evaluations:[px_mul_qx; py_mul_qy; py] ~linear_coeffs:[Scalar.negate param_a; one; mone] () in let minus_b_times_a_mul_px_mul_qx_plus_py_mul_qy_minus_py = Evaluations.mul_c ~res:ids.(1) ~evaluations:[b; minus_a_mul_px_mul_qx_plus_py_mul_qy_minus_py] () in let rhs = Evaluations.linear_c ~res:tmps.(2) ~evaluations:[minus_b_times_a_mul_px_mul_qx_plus_py_mul_qy_minus_py; py] () in (* tmps.(1) <- ry · (1 - Params_d · px · py · qx · qy) - (b · py · qy + py - py · b - Params_a · px · b · qx) *) let second_identity = Evaluations.linear_c ~res:tmps.(1) ~evaluations:[lhs; rhs] ~linear_coeffs:[one; mone] () in let second_identity = Evaluations.mul_c ~res:ids.(1) ~evaluations:[q; second_identity] () in SMap.of_list [ (prefix @@ q_label ^ ".0", first_identity); (prefix @@ q_label ^ ".1", second_identity); ] let verifier_identities ~prefix_common ~prefix ~public:_ ~generator:_ ~size_domain:_ _ answers = let {q; wires; wires_g} = get_answers ~gx:true ~q_label ~prefix ~prefix_common answers in let b = wires.(0) in let qx, qy = (wires.(1), wires.(2)) in let px, py = (wires.(3), wires.(4)) in let rx, ry = (wires_g.(3), wires_g.(4)) in let bpxqy = Scalar.(b * px * qy) in let pyqx = Scalar.(py * qx) in let den_common = Scalar.(param_d * bpxqy * pyqx) in (* q · [rx · (1 + d · b · px · qx · py · qy) - (b · px · qy + px - b · px + b · qx · py) = 0] *) let first_identity = let num = Scalar.(sub px (b * px) + bpxqy + (b * pyqx)) in let den = Scalar.(one + den_common) in let id = Scalar.(sub (rx * den) num) in Scalar.mul q id in (* q · [ry · (1 - d · b · px · qx · py · qy) - (b · py · qy + py - py · b - a · px · b · qx)] = 0 *) let second_identity = let num = Scalar.(sub (b * py * qy) (param_a * px * b * qx) + sub py (py * b)) in let den = Scalar.(sub one den_common) in let id = Scalar.(sub (ry * den) num) in Scalar.mul q id in SMap.of_list [ (prefix @@ q_label ^ ".0", first_identity); (prefix @@ q_label ^ ".1", second_identity); ] let polynomials_degree = SMap.of_list [ (wire_name 0, 7); (wire_name 1, 7); (wire_name 2, 7); (wire_name 3, 7); (wire_name 4, 7); (q_label, 7); ] let cs ~q:qec ~wires ~wires_g ?precomputed_advice:_ () = let bit = wires.(0) in let qx = wires.(1) in let qy = wires.(2) in let px = wires.(3) in let py = wires.(4) in let rx = wires_g.(3) in let ry = wires_g.(4) in let open L in let sub x y = Num.add ~qr:mone x y in let* px_qy = Num.mul px qy in let* py_qx = Num.mul py qx in let* pqs = Num.mul px_qy py_qx in let* denom_first = Num.custom ~qm:param_d bit pqs ~qc:one in (* q · [rx · (1 + d · b · px · qx · py · qy) - (b · px · qy + b · py · qx - b · px + px)] = 0 *) let* first_identity = (* left = rx · (1 + d · b · px · qx · py · qy) *) let* left = Num.mul denom_first rx in (* right = b · (px · qy + py · qx - px) + px *) let* px_qy_plus_py_qx = Num.add px_qy py_qx in let* px_qy_plus_py_qx_minux_px = sub px_qy_plus_py_qx px in let* right_b = Num.mul bit px_qy_plus_py_qx_minux_px in let* right = Num.add px right_b in (* all = left - right = rx · (1 + d · b · px · qx · py · qy) - (b · px · qy + b · py · qx - b · px + px) *) let* all = sub left right in Num.mul qec all in (* q · [ry · (1 - d · b · px · qx · py · qy) - (b · py · qy - a · b · px · qx - b · py + py )] = 0 *) let* second_identity = (* left = ry · (1 - d · b · px · qx · py · qy) *) let* denom_second = Num.add_constant ~ql:mone two denom_first in let* left = Num.mul ry denom_second in (* right = b · (py · qy - a · px · qx - py) + py *) let* py_qy = Num.mul py qy in let* a_px_qx = Num.mul ~qm:param_a px qx in let* py_qy_plus_a_px_qx = sub py_qy a_px_qx in let* py_qy_plus_a_px_qx_minus_py = sub py_qy_plus_a_px_qx py in let* right_b = Num.mul bit py_qy_plus_a_px_qx_minus_py in let* right = Num.add right_b py in (* all = left - right = y · (1 - d · b · px · qx · py · qy) - (b · py · qy - a · b · px · qx - b · py + py ) *) let* all = sub left right in Num.mul qec all in ret [first_identity; second_identity] end
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>