mul::complete.rs: Use ternary helper in complete addition part of variable-base scalar mul.

This commit is contained in:
therealyingtong 2021-11-30 12:55:20 -05:00
parent 9513efd6f3
commit 1a7a1255c8
2 changed files with 45 additions and 48 deletions

View File

@ -1,6 +1,6 @@
use super::super::{add, copy, CellValue, EccConfig, EccPoint, Var};
use super::{COMPLETE_RANGE, X, Y, Z};
use crate::circuit::gadget::utilities::bool_check;
use crate::circuit::gadget::utilities::{bool_check, ternary};
use halo2::{
circuit::Region,
@ -69,10 +69,7 @@ impl Config {
// k_i = 0 => y_p = -base_y
// k_i = 1 => y_p = base_y
let y_switch = {
let one_minus_k = Expression::Constant(pallas::Base::one()) - k.clone();
one_minus_k * (base_y.clone() + y_p.clone()) + k * (base_y - y_p)
};
let y_switch = ternary(k, base_y.clone() - y_p.clone(), base_y + y_p);
std::array::IntoIter::new([("bool_check", bool_check), ("y_switch", y_switch)])
.map(move |(name, poly)| (name, q_mul_decompose_var.clone() * poly))

View File

@ -7522,6 +7522,49 @@ PinnedVerificationKey {
),
),
Sum(
Product(
Sum(
Advice {
query_index: 10,
column_index: 9,
rotation: Rotation(
1,
),
},
Negated(
Product(
Constant(
0x0000000000000000000000000000000000000000000000000000000000000002,
),
Advice {
query_index: 11,
column_index: 9,
rotation: Rotation(
-1,
),
},
),
),
),
Sum(
Advice {
query_index: 9,
column_index: 9,
rotation: Rotation(
0,
),
},
Negated(
Advice {
query_index: 21,
column_index: 1,
rotation: Rotation(
-1,
),
},
),
),
),
Product(
Sum(
Constant(
@ -7570,49 +7613,6 @@ PinnedVerificationKey {
},
),
),
Product(
Sum(
Advice {
query_index: 10,
column_index: 9,
rotation: Rotation(
1,
),
},
Negated(
Product(
Constant(
0x0000000000000000000000000000000000000000000000000000000000000002,
),
Advice {
query_index: 11,
column_index: 9,
rotation: Rotation(
-1,
),
},
),
),
),
Sum(
Advice {
query_index: 9,
column_index: 9,
rotation: Rotation(
0,
),
},
Negated(
Advice {
query_index: 21,
column_index: 1,
rotation: Rotation(
-1,
),
},
),
),
),
),
),
Product(