plonkup/constraint_system/ecc/curve_addition/
fixed_base_gate.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4//
5// Copyright (c) DUSK NETWORK. All rights reserved.
6
7use crate::constraint_system::{TurboComposer, Witness};
8use dusk_bls12_381::BlsScalar;
9
10#[derive(Debug, Clone, Copy)]
11/// Contains all of the components needed to verify that a bit scalar
12/// multiplication was computed correctly
13pub(crate) struct WnafRound<T: Into<Witness>> {
14    /// This is the accumulated x coordinate point that we wish to add (so
15    /// far.. depends on where you are in the scalar mul) it is linked to
16    /// the wnaf entry, so must not be revealed
17    pub acc_x: T,
18    /// This is the accumulated y coordinate
19    pub acc_y: T,
20
21    /// This is the wnaf accumulated entry
22    /// For all intents and purposes, you can think of this as the secret bit
23    pub accumulated_bit: T,
24
25    /// This is the multiplication of x_\alpha * y_\alpha
26    /// we need this as a distinct wire, so that the degree of the polynomial
27    /// does not go over 4
28    pub xy_alpha: T,
29    /// This is the possible x co-ordinate of the wnaf point we are going to
30    /// add Actual x-co-ordinate = b_i * x_\beta
31    pub x_beta: BlsScalar,
32    /// This is the possible y co-ordinate of the wnaf point we are going to
33    /// add Actual y coordinate = (b_i)^2 [y_\beta -1] + 1
34    pub y_beta: BlsScalar,
35    /// This is the multiplication of x_\beta * y_\beta
36    pub xy_beta: BlsScalar,
37}
38
39impl TurboComposer {
40    /// Fixed group addition of a jubjub point
41    pub(crate) fn fixed_group_add<T: Into<Witness> + Copy>(
42        &mut self,
43        wnaf_round: WnafRound<T>,
44    ) {
45        self.a_w.push(wnaf_round.acc_x.into());
46        self.b_w.push(wnaf_round.acc_y.into());
47        self.c_w.push(wnaf_round.xy_alpha.into());
48        self.d_w.push(wnaf_round.accumulated_bit.into());
49
50        self.q_l.push(wnaf_round.x_beta);
51        self.q_r.push(wnaf_round.y_beta);
52
53        self.q_c.push(wnaf_round.xy_beta);
54        self.q_o.push(BlsScalar::zero());
55        self.q_fixed_group_add.push(BlsScalar::one());
56        self.q_variable_group_add.push(BlsScalar::zero());
57
58        self.q_m.push(BlsScalar::zero());
59        self.q_4.push(BlsScalar::zero());
60        self.q_arith.push(BlsScalar::zero());
61        self.q_range.push(BlsScalar::zero());
62        self.q_logic.push(BlsScalar::zero());
63        self.q_k.push(BlsScalar::zero());
64
65        self.perm.add_witnesses_to_map(
66            wnaf_round.acc_x,
67            wnaf_round.acc_y,
68            wnaf_round.xy_alpha,
69            wnaf_round.accumulated_bit,
70            self.n,
71        );
72
73        self.n += 1;
74    }
75}