Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blinding scalars #651

Merged
merged 6 commits into from
Mar 7, 2022
Merged

Add blinding scalars #651

merged 6 commits into from
Mar 7, 2022

Conversation

moCello
Copy link
Member

@moCello moCello commented Dec 14, 2021

Add blinding scalars in round 1, 2 and 3 of the proof

@moCello moCello added the team:Core Low Level Core Development Team (Rust) label Dec 14, 2021
@moCello moCello added this to In progress in PlonkUp Paper via automation Dec 14, 2021
@moCello moCello linked an issue Dec 14, 2021 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Dec 14, 2021

Codecov Report

Merging #651 (576fdfd) into master (3125d13) will increase coverage by 0.14%.
The diff coverage is 97.12%.

❗ Current head 576fdfd differs from pull request most recent head 6b5e281. Consider uploading reports for the commit 6b5e281 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #651      +/-   ##
==========================================
+ Coverage   80.62%   80.76%   +0.14%     
==========================================
  Files          54       54              
  Lines        4479     4482       +3     
==========================================
+ Hits         3611     3620       +9     
+ Misses        868      862       -6     
Impacted Files Coverage Δ
src/proof_system/widget.rs 94.45% <71.42%> (ø)
src/permutation.rs 90.00% <77.77%> (-0.44%) ⬇️
src/circuit.rs 73.33% <100.00%> (+0.73%) ⬆️
src/constraint_system/composer.rs 63.23% <100.00%> (+0.34%) ⬆️
src/constraint_system/helper.rs 87.50% <100.00%> (ø)
src/proof_system/preprocess.rs 95.85% <100.00%> (ø)
src/proof_system/prover.rs 88.60% <100.00%> (+3.06%) ⬆️
src/proof_system/quotient_poly.rs 98.87% <100.00%> (-0.24%) ⬇️
src/proof_system/widget/permutation/proverkey.rs 97.05% <100.00%> (ø)
tests/circuit.rs 80.00% <100.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3125d13...6b5e281. Read the comment docs.

@xevisalle xevisalle added the fix:vulnerability Issues related to fix vulnerabilities of the architecture or software label Mar 5, 2022
@xevisalle xevisalle marked this pull request as ready for review March 5, 2022 20:28
@xevisalle xevisalle moved this from In progress to Review in progress in PlonkUp Paper Mar 5, 2022
src/circuit.rs Outdated Show resolved Hide resolved
&self,
domain: &EvaluationDomain,
wires: [&[BlsScalar]; 4],
beta: &BlsScalar,
gamma: &BlsScalar,
sigma_polys: [&Polynomial; 4],
) -> Polynomial {
) -> Vec<dusk_bls12_381::BlsScalar> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Vec<BlsScalar> and don't have to mention the dusk_bls12_381 module path since it is imported on the top of the file already.

More generally though, why do you not use Polynomial here? We have to convert the evals to to their polynomial form at some point, so why do not do it here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with @moCello

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function domain.ifft(w_vec) requires a vector, we could compute it into the function but then in the prover, we need to treat each vector to be blinded in a different way. I think is more clear and clean to put the IFFT into the blind_poly(), and treat all inputs in the same way.

@@ -308,7 +308,7 @@ impl Permutation {
h_2: &[BlsScalar],
delta: &BlsScalar,
epsilon: &BlsScalar,
) -> Polynomial {
) -> Vec<dusk_bls12_381::BlsScalar> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

/// if hiding degree = 2: (b3*X^(n+2) + b2*X(n+1) + b1*X^n - b3*X^2 - b2*X
/// - b1) + w_vec
pub(crate) fn blind_poly<R: RngCore + CryptoRng>(
w_vec: &Vec<dusk_bls12_381::BlsScalar>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above dusk_bls12_381::BlsScalar is already imported, so you can simply use &Vec<BlsScalar> here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! :)

domain: &EvaluationDomain,
mut rng: &mut R,
) -> Polynomial {
let mut w_vec_i = domain.ifft(w_vec);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the names w_vec and w_vec_i not so descriptive. Isn't w_vec_i just w_poly and w_vec the poly in evaluation form? What about calling them w_poly and w_poly_evals?

Copy link
Member

@xevisalle xevisalle Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just followed the same naming used in the whole code, we should rename the whole code if we want to change it here... And I used w_vec_i where i comes from inverse. I used this name to distinguish the value we get before calling Polynomial::from_coefficients_vec()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh i see, then please call it w_vec_inverse. At first sight I thought that you used the i because you want to loop through the coefficients later on

Copy link
Member Author

@moCello moCello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments

Copy link
Contributor

@vlopes11 vlopes11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few nits/questions

src/circuit.rs Outdated
) -> Result<Proof, Error> {
let (ck, _) = pub_params.trim(self.padded_gates())?;
let (ck, _) = pub_params.trim(self.padded_gates() + 6)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @moCello mentioned, we should avoid magic numbers. Since its used in different parts, consider creating a documented constant

src/circuit.rs Outdated
@@ -306,7 +308,7 @@ where

// Add ProverKey to Prover
prover.prover_key = Some(prover_key.clone());
prover.prove(&ck)
prover.prove(&ck, &mut rng)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We take rng as mut rng: &mut R. Mutable references are copy, even if the referred value isn't copy (they are just pointers).

Suggested change
prover.prove(&ck, &mut rng)
prover.prove(&ck, rng)

The current code works because &mut R is virtually congruent to &mut &mut R, but I believe this is a nit. We shouldn't take the reference as mutable, since we don't change the reference itself, but the data it points to (RNG).

src/circuit.rs Outdated Show resolved Hide resolved
&self,
domain: &EvaluationDomain,
wires: [&[BlsScalar]; 4],
beta: &BlsScalar,
gamma: &BlsScalar,
sigma_polys: [&Polynomial; 4],
) -> Polynomial {
) -> Vec<dusk_bls12_381::BlsScalar> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with @moCello

src/proof_system/preprocess.rs Show resolved Hide resolved
src/proof_system/prover.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@vlopes11 vlopes11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small non-blocking question; waiting for the comments of @moCello to be addressed in order to approve

src/proof_system/preprocess.rs Show resolved Hide resolved
Copy link
Member Author

@moCello moCello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Find the last approach better than this one. I think the decision we need to make is, if we want to perform the ifft before calling blind and have blind in part of the Polynomial or if we perform the ifft in blind and have blind part of the Prover as you had before. Your call :)

/// Adds the blinding scalars to a given vector. Always the same elements
/// of 'w_vec' are modified at the beginning of it, and appended at the end:
/// if hiding degree = 1: (b2*X(n+1) + b1*X^n - b2*X - b1) + w_vec
/// if hiding degree = 2: (b3*X^(n+2) + b2*X(n+1) + b1*X^n - b3*X^2 - b2*X
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing the ^ before the (n+1) in both lines

Copy link
Contributor

@vlopes11 vlopes11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This is an important security fix and we might consider including this in testnet. cc @autholykos

@xevisalle xevisalle merged commit 37e17f6 into master Mar 7, 2022
PlonkUp Paper automation moved this from Review in progress to Done Mar 7, 2022
@xevisalle xevisalle deleted the blinding branch March 7, 2022 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix:vulnerability Issues related to fix vulnerabilities of the architecture or software team:Core Low Level Core Development Team (Rust)
Projects
Development

Successfully merging this pull request may close these issues.

Add blinding scalars
3 participants