Skip to content

Commit b01ef96

Browse files
authored
Merge pull request #215 from dalek-cryptography/circuit-notes-edit
some more circuit tweaks
2 parents 5389dca + 0615fe9 commit b01ef96

File tree

9 files changed

+59
-57
lines changed

9 files changed

+59
-57
lines changed

benches/r1cs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@ impl KShuffleGadget {
8484
}
8585

8686
// Make last x multiplier for i = k-1 and k-2
87-
let (_, _, last_mulx_out) = cs.add_intermediate_constraint(x[k - 1] - z, x[k - 2] - z);
87+
let (_, _, last_mulx_out) = cs.add_partial_constraint(x[k - 1] - z, x[k - 2] - z);
8888

8989
// Make multipliers for x from i == [0, k-3]
9090
let first_mulx_out = (0..k - 2).rev().fold(last_mulx_out, |prev_out, i| {
91-
let (_, _, o) = cs.add_intermediate_constraint(prev_out.into(), x[i] - z);
91+
let (_, _, o) = cs.add_partial_constraint(prev_out.into(), x[i] - z);
9292
o
9393
});
9494

9595
// Make last y multiplier for i = k-1 and k-2
96-
let (_, _, last_muly_out) = cs.add_intermediate_constraint(y[k - 1] - z, y[k - 2] - z);
96+
let (_, _, last_muly_out) = cs.add_partial_constraint(y[k - 1] - z, y[k - 2] - z);
9797

9898
// Make multipliers for y from i == [0, k-3]
9999
let first_muly_out = (0..k - 2).rev().fold(last_muly_out, |prev_out, i| {
100-
let (_, _, o) = cs.add_intermediate_constraint(prev_out.into(), y[i] - z);
100+
let (_, _, o) = cs.add_partial_constraint(prev_out.into(), y[i] - z);
101101
o
102102
});
103103

docs/aggregation-api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
The `aggregation` module contains the API for performing the aggregated multiparty computation protocol.
1+
The `range_proof_mpc` module contains the API for performing the aggregated multiparty computation protocol for joint range proof proving.
2+
23
Only the range proofs are supported, while aggregation of constraint system proofs is under development.
34

45
API for the aggregated multiparty computation protocol

src/errors.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ pub enum R1CSError {
9999
/// Occurs when there are insufficient generators for the proof.
100100
#[fail(display = "Invalid generators size, too few generators for proof")]
101101
InvalidGeneratorsLength,
102-
/// Occurs when trying to use a missing variable assignment, for
103-
/// instance if
104-
/// [`Assignment::Missing`](::r1cs::Assignment::Missing) is passed
105-
/// to a [`ProverCS`](::r1cs::ProverCS).
106-
#[fail(display = "Variable does not have a value assignment.")]
107-
MissingAssignment,
108102
/// Occurs when verification of an
109103
/// [`R1CSProof`](::r1cs::R1CSProof) fails.
110104
#[fail(display = "R1CSProof did not verify correctly.")]

src/r1cs/constraint_system.rs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use curve25519_dalek::scalar::Scalar;
66
/// The interface for a constraint system, abstracting over the prover
77
/// and verifier's roles.
88
///
9-
/// Statements to be proved by an [`R1CSProof`] are specified by
9+
/// Statements to be proved by an [`R1CSProof`](::r1cs::R1CSProof) are specified by
1010
/// programmatically constructing constraints. These constraints need
1111
/// to be identical between the prover and verifier, since the prover
1212
/// and verifier need to construct the same statement.
@@ -16,35 +16,43 @@ use curve25519_dalek::scalar::Scalar;
1616
/// using the `ConstraintSystem` trait, so that the prover and
1717
/// verifier share the logic for specifying constraints.
1818
pub trait ConstraintSystem {
19-
/// Constrain `left`, `right`, and `out` linear combinations such that:
20-
/// `left` = `l_var` (by adding a constraint)
21-
/// `right` = `r_var` (by adding a constraint)
22-
/// `out` = `o_var` (by adding a constraint)
23-
/// `l_var` * `r_var` = `o_var` (by allocating multiplier variables)
24-
/// Where:
25-
/// `l_var` is either `left.eval()` (prover) or `Missing` (verifier)
26-
/// `r_var` is either `right.eval()` (prover) or `Missing` (verifier)
27-
/// `o_var` is either `out.eval()` (prover) or `Missing` (verifier)
28-
/// This is used when all three gates of a multiplication gate should be
29-
/// constrained by linear constraints.
19+
/// Allocate variables `left`, `right`, and `out`
20+
/// with the implicit constraint that
21+
/// ```text
22+
/// left * right = out
23+
/// ```
24+
/// and the explicit constraints that
25+
/// ```text
26+
/// left = left_constraint
27+
/// right = right_constraint
28+
/// out = out_constraint
29+
/// ```
30+
/// This is used when all three multiplier variables can be constrained up-front.
31+
///
32+
/// Returns `(left, right, out)` for use in further constraints.
3033
fn add_constraint(
3134
&mut self,
32-
left: LinearCombination,
33-
right: LinearCombination,
34-
out: LinearCombination,
35+
left_constraint: LinearCombination,
36+
right_constraint: LinearCombination,
37+
out_constraint: LinearCombination,
3538
) -> (Variable, Variable, Variable);
3639

37-
/// Constrain `left` and `right` linear combinations such that:
38-
/// `left` = `l_var` (by adding a constraint)
39-
/// `right` = `r_var` (by adding a constraint)
40-
/// `l_var` * `r_var` = `o_var` (by allocating multiplier variables)
41-
/// Where:
42-
/// `l_var` is either `left.eval()` (prover) or `Missing` (verifier)
43-
/// `r_var` is either `right.eval()` (prover) or `Missing` (verifier)
44-
/// `o_var` is either `left.eval() * right.eval()` (prover) or `Missing` (verifier)
45-
/// This is used when only the left and right inputs of a multiplication gate
46-
/// should be constrained by linear constraints.
47-
fn add_intermediate_constraint(
40+
/// Allocate variables `left`, `right`, and `out`
41+
/// with the implicit constraint that
42+
/// ```text
43+
/// left * right = out
44+
/// ```
45+
/// and the explicit constraints that
46+
/// ```text
47+
/// left = left_constraint
48+
/// right = right_constraint
49+
/// ```
50+
/// This is used when the output variable cannot be immediately
51+
/// constrained (for instance, because it should be constrained to
52+
/// match a variable that has not yet been allocated).
53+
///
54+
/// Returns `(left, right, out)` for use in further constraints.
55+
fn add_partial_constraint(
4856
&mut self,
4957
left: LinearCombination,
5058
right: LinearCombination,

src/r1cs/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@
8484
//! }
8585
//!
8686
//! // Make last x multiplier for i = k-1 and k-2
87-
//! let (_, _, last_mulx_out) = cs.add_intermediate_constraint(x[k - 1] - z, x[k - 2] - z);
87+
//! let (_, _, last_mulx_out) = cs.add_partial_constraint(x[k - 1] - z, x[k - 2] - z);
8888
//!
8989
//! // Make multipliers for x from i == [0, k-3]
9090
//! let first_mulx_out = (0..k - 2).rev().fold(last_mulx_out, |prev_out, i| {
91-
//! let (_, _, o) = cs.add_intermediate_constraint(prev_out.into(), x[i] - z);
91+
//! let (_, _, o) = cs.add_partial_constraint(prev_out.into(), x[i] - z);
9292
//! o
9393
//! });
9494
//!
9595
//! // Make last y multiplier for i = k-1 and k-2
96-
//! let (_, _, last_muly_out) = cs.add_intermediate_constraint(y[k - 1] - z, y[k - 2] - z);
96+
//! let (_, _, last_muly_out) = cs.add_partial_constraint(y[k - 1] - z, y[k - 2] - z);
9797
//!
9898
//! // Make multipliers for y from i == [0, k-3]
9999
//! let first_muly_out = (0..k - 2).rev().fold(last_muly_out, |prev_out, i| {
100-
//! let (_, _, o) = cs.add_intermediate_constraint(prev_out.into(), y[i] - z);
100+
//! let (_, _, o) = cs.add_partial_constraint(prev_out.into(), y[i] - z);
101101
//! o
102102
//! });
103103
//!

src/r1cs/proof.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use inner_product_proof::InnerProductProof;
1010
///
1111
/// Statements are specified by writing gadget functions which add
1212
/// constraints to a [`ConstraintSystem`](::r1cs::ConstraintSystem)
13-
/// implementation. To construct an `R1CSProof`, a prover constructs
13+
/// implementation. To construct an [`R1CSProof`], a prover constructs
1414
/// a [`ProverCS`](::r1cs::ProverCS), then passes it to gadget
1515
/// functions to build the constraint system, then consumes the
1616
/// constraint system using
1717
/// [`ProverCS::prove`](::r1cs::ProverCS::prove) to produce an
18-
/// `R1CSProof`. To verify an `R1CSProof`, a verifier constructs a
18+
/// [`R1CSProof`]. To verify an [`R1CSProof`], a verifier constructs a
1919
/// [`VerifierCS`](::r1cs::VerifierCS), then passes it to the same
2020
/// gadget functions to (re)build the constraint system, then consumes
2121
/// the constraint system using

src/r1cs/prover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'b> ConstraintSystem for ProverCS<'a, 'b> {
100100
(l_var, r_var, o_var)
101101
}
102102

103-
fn add_intermediate_constraint(
103+
fn add_partial_constraint(
104104
&mut self,
105105
mut left: LinearCombination,
106106
mut right: LinearCombination,

src/r1cs/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,20 @@ impl KShuffleGadget {
174174
}
175175

176176
// Make last x multiplier for i = k-1 and k-2
177-
let (_, _, last_mulx_out) = cs.add_intermediate_constraint(x[k - 1] - z, x[k - 2] - z);
177+
let (_, _, last_mulx_out) = cs.add_partial_constraint(x[k - 1] - z, x[k - 2] - z);
178178

179179
// Make multipliers for x from i == [0, k-3]
180180
let first_mulx_out = (0..k - 2).rev().fold(last_mulx_out, |prev_out, i| {
181-
let (_, _, o) = cs.add_intermediate_constraint(prev_out.into(), x[i] - z);
181+
let (_, _, o) = cs.add_partial_constraint(prev_out.into(), x[i] - z);
182182
o
183183
});
184184

185185
// Make last y multiplier for i = k-1 and k-2
186-
let (_, _, last_muly_out) = cs.add_intermediate_constraint(y[k - 1] - z, y[k - 2] - z);
186+
let (_, _, last_muly_out) = cs.add_partial_constraint(y[k - 1] - z, y[k - 2] - z);
187187

188188
// Make multipliers for y from i == [0, k-3]
189189
let first_muly_out = (0..k - 2).rev().fold(last_muly_out, |prev_out, i| {
190-
let (_, _, o) = cs.add_intermediate_constraint(prev_out.into(), y[i] - z);
190+
let (_, _, o) = cs.add_partial_constraint(prev_out.into(), y[i] - z);
191191
o
192192
});
193193

src/r1cs/verifier.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ use transcript::TranscriptProtocol;
1313

1414
/// A [`ConstraintSystem`] implementation for use by the verifier.
1515
///
16-
/// The lifecycle of a `VerifierCS` is as follows. The verification
16+
/// The lifecycle of a [`VerifierCS`] is as follows. The verification
1717
/// code assembles the commitments to the external inputs to the
1818
/// constraint system, then passes them, along with generators and a
1919
/// transcript, to [`VerifierCS::new`]. This initializes the
20-
/// `VerifierCS` and returns [`Variable`]s corresponding to the
20+
/// [`VerifierCS`] and returns [`Variable`]s corresponding to the
2121
/// inputs.
2222
///
23-
/// The verifier can then pass the `VerifierCS` and the external
24-
/// variables to the same gadget code as the prover, using
25-
/// `Assignment::Missing` for witness variables, to build an identical
26-
/// constraint system to the one the prover built. Finally, they pass
27-
/// the prover's [`R1CSProof`] to [`VerifierCS::verify`], which
28-
/// consumes the `VerifierCS` and verifies the proof.
23+
/// The verifier can then pass the [`VerifierCS`] and the external
24+
/// variables to the same gadget code as the prover, constructing an
25+
/// identical constraint system to the one the prover built. Finally,
26+
/// they pass the prover's [`R1CSProof`] to [`VerifierCS::verify`],
27+
/// which consumes the [`VerifierCS`] and verifies the proof.
2928
pub struct VerifierCS<'a, 'b> {
3029
bp_gens: &'b BulletproofGens,
3130
pc_gens: &'b PedersenGens,
@@ -68,7 +67,7 @@ impl<'a, 'b> ConstraintSystem for VerifierCS<'a, 'b> {
6867
(l_var, r_var, o_var)
6968
}
7069

71-
fn add_intermediate_constraint(
70+
fn add_partial_constraint(
7271
&mut self,
7372
mut left: LinearCombination,
7473
mut right: LinearCombination,

0 commit comments

Comments
 (0)