Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dusk_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ jobs:
with:
token: ${{secrets.CODECOV_TOKEN}}

test_nightly_std:
name: Nightly tests std
test_stable_std:
name: Stable tests std
uses: dusk-network/.github/.github/workflows/run-tests.yml@main
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
name = "dusk-plonk"
version = "0.21.0"
categories =["algorithms", "cryptography", "science", "mathematics"]
edition = "2021"
edition = "2024"
rust-version = "1.85"
keywords = ["cryptography", "plonk", "zk-snarks", "zero-knowledge", "crypto"]
license = "MPL-2.0"
repository = "https://github.com/dusk-network/plonk"
Expand All @@ -15,6 +16,7 @@ exclude = [
]

[dependencies]
blake2b_simd = { version = "=1.0.3", default-features = false }
merlin = {version = "3.0", default-features = false}
rand_core = {version="0.6", default-features=false}
dusk-bytes = "0.1"
Expand All @@ -23,7 +25,7 @@ dusk-jubjub = {version = "0.15", default-features = false}
ff = {version = "0.13", default-features = false}
itertools = {version = "0.9", default-features = false}
hashbrown = {version = "0.9", default-features=false, features = ["ahash"]}
msgpacker = {version = "=0.4.3", default-features=false, features = ["alloc", "derive"], optional=true}
msgpacker = {version = "=0.4.8", default-features=false, features = ["alloc", "derive"], optional=true}
miniz_oxide = {version = "0.7", default-features=false, features = ["with-alloc"], optional = true}
rayon = {version = "1.3", optional = true}
sha2 = {version = "0.10", default-features = false, optional = true}
Expand Down
2 changes: 1 addition & 1 deletion benches/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#![allow(clippy::many_single_char_names)]

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{Criterion, black_box, criterion_group, criterion_main};
use dusk_plonk::prelude::*;

#[derive(Debug, Clone, Copy)]
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-10-17"
channel = "stable"
components = ["rustfmt", "cargo", "clippy"]
1 change: 0 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
max_width = 80
wrap_comments = true
2 changes: 1 addition & 1 deletion src/commitment_scheme/kzg10/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use dusk_bytes::{DeserializableSlice, Serializable};
use bytecheck::CheckBytes;
#[cfg(feature = "rkyv-impl")]
use rkyv::{
ser::{ScratchSpace, Serializer},
Archive, Deserialize, Serialize,
ser::{ScratchSpace, Serializer},
};

/// Holds a commitment to a polynomial in a form of a [`G1Affine`]-bls12_381
Expand Down
32 changes: 17 additions & 15 deletions src/commitment_scheme/kzg10/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
//! Key module contains the utilities and data structures
//! that support the generation and usage of Commit and
//! Opening keys.
use super::{proof::Proof, Commitment};
use super::{Commitment, proof::Proof};
use crate::{
error::Error, fft::Polynomial, transcript::TranscriptProtocol, util,
};
use alloc::vec::Vec;
use dusk_bls12_381::{
multiscalar_mul::msm_variable_base, BlsScalar, G1Affine, G1Projective,
G2Affine, G2Prepared,
BlsScalar, G1Affine, G1Projective, G2Affine, G2Prepared,
multiscalar_mul::msm_variable_base,
};
use dusk_bytes::{DeserializableSlice, Serializable};
use merlin::Transcript;
Expand All @@ -23,8 +23,8 @@ use merlin::Transcript;
use bytecheck::CheckBytes;
#[cfg(feature = "rkyv-impl")]
use rkyv::{
ser::{ScratchSpace, Serializer},
Archive, Deserialize, Serialize,
ser::{ScratchSpace, Serializer},
};

/// CommitKey is used to commit to a polynomial which is bounded by the
Expand Down Expand Up @@ -84,17 +84,19 @@ impl CommitKey {
/// happen, the inputed bytes must match the ones that were generated by
/// the encoding functions of this lib.
pub unsafe fn from_slice_unchecked(bytes: &[u8]) -> Self {
let mut len = [0u8; u64::SIZE];
len.copy_from_slice(&bytes[..u64::SIZE]);
let len = u64::from_le_bytes(len);

let powers_of_g = bytes[u64::SIZE..]
.chunks_exact(G1Affine::RAW_SIZE)
.zip(0..len)
.map(|(c, _)| G1Affine::from_slice_unchecked(c))
.collect();

Self { powers_of_g }
unsafe {
let mut len = [0u8; u64::SIZE];
len.copy_from_slice(&bytes[..u64::SIZE]);
let len = u64::from_le_bytes(len);

let powers_of_g = bytes[u64::SIZE..]
.chunks_exact(G1Affine::RAW_SIZE)
.zip(0..len)
.map(|(c, _)| G1Affine::from_slice_unchecked(c))
.collect();

Self { powers_of_g }
}
}

/// Serializes the [`CommitKey`] into a byte slice.
Expand Down
24 changes: 13 additions & 11 deletions src/commitment_scheme/kzg10/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use rand_core::{CryptoRng, RngCore};
use bytecheck::CheckBytes;
#[cfg(feature = "rkyv-impl")]
use rkyv::{
ser::{ScratchSpace, Serializer},
Archive, Deserialize, Serialize,
ser::{ScratchSpace, Serializer},
};

/// The Public Parameters can also be referred to as the Structured Reference
Expand Down Expand Up @@ -128,16 +128,18 @@ impl PublicParameters {
/// happen, the inputed bytes must match the ones that were generated by
/// the encoding functions of this lib.
pub unsafe fn from_slice_unchecked(bytes: &[u8]) -> Self {
let opening_key = &bytes[..OpeningKey::SIZE];
let opening_key = OpeningKey::from_slice(opening_key)
.expect("Error at OpeningKey deserialization");

let commit_key = &bytes[OpeningKey::SIZE..];
let commit_key = CommitKey::from_slice_unchecked(commit_key);

Self {
commit_key,
opening_key,
unsafe {
let opening_key = &bytes[..OpeningKey::SIZE];
let opening_key = OpeningKey::from_slice(opening_key)
.expect("Error at OpeningKey deserialization");

let commit_key = &bytes[OpeningKey::SIZE..];
let commit_key = CommitKey::from_slice_unchecked(commit_key);

Self {
commit_key,
opening_key,
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::commitment_scheme::{CommitKey, OpeningKey, PublicParameters};
use crate::error::Error;
use crate::fft::{EvaluationDomain, Evaluations, Polynomial};
use crate::proof_system::preprocess::Polynomials;
use crate::proof_system::{widget, ProverKey};
use crate::proof_system::{ProverKey, widget};

use crate::prelude::{Circuit, Composer};

Expand Down Expand Up @@ -161,8 +161,12 @@ impl Compiler {
Polynomial::from_coefficients_vec(q_variable_group_add_poly);

// 2. compute the sigma polynomials
let [s_sigma_1_poly, s_sigma_2_poly, s_sigma_3_poly, s_sigma_4_poly] =
perm.compute_sigma_polynomials(size, &domain);
let [
s_sigma_1_poly,
s_sigma_2_poly,
s_sigma_3_poly,
s_sigma_4_poly,
] = perm.compute_sigma_polynomials(size, &domain);

let q_m_comm = commit_key.commit(&q_m_poly).unwrap_or_default();
let q_l_comm = commit_key.commit(&q_l_poly).unwrap_or_default();
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::compiler::prover::linearization_poly::ProofEvaluations;
use crate::error::Error;
use crate::fft::{EvaluationDomain, Polynomial};
use crate::proof_system::{
linearization_poly, proof::Proof, quotient_poly, ProverKey, VerifierKey,
ProverKey, VerifierKey, linearization_poly, proof::Proof, quotient_poly,
};
use crate::transcript::TranscriptProtocol;

Expand Down
8 changes: 6 additions & 2 deletions src/composer/permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,12 @@ mod test {
assert_ne!(gamma, beta);

// 1. Compute the permutation polynomial using both methods
let [s_sigma_1_poly, s_sigma_2_poly, s_sigma_3_poly, s_sigma_4_poly] =
perm.compute_sigma_polynomials(n, domain);
let [
s_sigma_1_poly,
s_sigma_2_poly,
s_sigma_3_poly,
s_sigma_4_poly,
] = perm.compute_sigma_polynomials(n, domain);
let (z_vec, numerator_components, denominator_components) =
compute_slow_permutation_poly(
domain,
Expand Down
27 changes: 19 additions & 8 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ impl std::fmt::Display for Error {
write!(f, "circuit has already been preprocessed")
}
Self::InvalidCircuitSize(description_size, circuit_size) => {
write!(f, "circuit description has a different amount of gates than the circuit for the proof creation: description size = {description_size}, circuit size = {circuit_size}")
write!(
f,
"circuit description has a different amount of gates than the circuit for the proof creation: description size = {description_size}, circuit size = {circuit_size}"
)
}
Self::DegreeIsZero => {
write!(f, "cannot create PublicParameters with max degree 0")
Expand All @@ -152,19 +155,27 @@ impl std::fmt::Display for Error {
Self::NotEnoughBytes => write!(f, "not enough bytes left to read"),
Self::PointMalformed => write!(f, "BLS point bytes malformed"),
Self::BlsScalarMalformed => write!(f, "BLS scalar bytes malformed"),
Self::JubJubScalarMalformed => write!(f, "JubJub scalar bytes malformed"),
Self::JubJubScalarMalformed => {
write!(f, "JubJub scalar bytes malformed")
}
Self::BytesError(err) => write!(f, "{:?}", err),
Self::UnsupportedWNAF2k => write!(
f,
"WNAF2k cannot hold values not contained in `[-1..1]`"
),
Self::PublicInputNotFound {
Self::PublicInputNotFound { index } => write!(
f,
"The public input of index {} is defined in the circuit description, but wasn't declared in the prove instance",
index
} => write!(f, "The public input of index {} is defined in the circuit description, but wasn't declared in the prove instance", index),
Self::InconsistentPublicInputsLen {
expected, provided,
} => write!(f, "The provided public inputs set of length {} doesn't match the processed verifier: {}", provided, expected),
Self::InvalidCompressedCircuit => write!(f, "invalid compressed circuit"),
),
Self::InconsistentPublicInputsLen { expected, provided } => write!(
f,
"The provided public inputs set of length {} doesn't match the processed verifier: {}",
provided, expected
),
Self::InvalidCompressedCircuit => {
write!(f, "invalid compressed circuit")
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/fft/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use dusk_bytes::{DeserializableSlice, Serializable};
use bytecheck::CheckBytes;
#[cfg(feature = "rkyv-impl")]
use rkyv::{
ser::{ScratchSpace, Serializer},
Archive, Deserialize, Serialize,
ser::{ScratchSpace, Serializer},
};

/// Defines a domain over which finite field (I)FFTs can be performed. Works
Expand Down
8 changes: 4 additions & 4 deletions src/fft/evaluations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use dusk_bytes::{DeserializableSlice, Serializable};
use bytecheck::CheckBytes;
#[cfg(feature = "rkyv-impl")]
use rkyv::{
ser::{ScratchSpace, Serializer},
Archive, Deserialize, Serialize,
ser::{ScratchSpace, Serializer},
};

/// Stores a polynomial in evaluation form.
Expand Down Expand Up @@ -90,7 +90,7 @@ impl Index<usize> for Evaluations {
}
}

impl<'a, 'b> Mul<&'a Evaluations> for &'b Evaluations {
impl<'a> Mul<&'a Evaluations> for &Evaluations {
type Output = Evaluations;

#[inline]
Expand All @@ -112,7 +112,7 @@ impl<'a> MulAssign<&'a Evaluations> for Evaluations {
}
}

impl<'a, 'b> Add<&'a Evaluations> for &'b Evaluations {
impl<'a> Add<&'a Evaluations> for &Evaluations {
type Output = Evaluations;

#[inline]
Expand All @@ -134,7 +134,7 @@ impl<'a> AddAssign<&'a Evaluations> for Evaluations {
}
}

impl<'a, 'b> Sub<&'a Evaluations> for &'b Evaluations {
impl<'a> Sub<&'a Evaluations> for &Evaluations {
type Output = Evaluations;

#[inline]
Expand Down
30 changes: 14 additions & 16 deletions src/fft/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use dusk_bytes::{DeserializableSlice, Serializable};
use bytecheck::CheckBytes;
#[cfg(feature = "rkyv-impl")]
use rkyv::{
ser::{ScratchSpace, Serializer},
Archive, Deserialize, Serialize,
ser::{ScratchSpace, Serializer},
};

/// Represents a polynomial in coeffiient form.
Expand Down Expand Up @@ -82,10 +82,12 @@ impl Polynomial {
result.truncate_leading_zeros();
// Check that either the coefficients vec is empty or that the last
// coeff is non-zero.
assert!(result
.coeffs
.last()
.map_or(true, |coeff| coeff != &BlsScalar::zero()));
assert!(
result
.coeffs
.last()
.is_none_or(|coeff| coeff != &BlsScalar::zero())
);

result
}
Expand All @@ -109,11 +111,7 @@ impl Polynomial {
}

fn truncate_leading_zeros(&mut self) {
while self
.coeffs
.last()
.map_or(false, |c| c == &BlsScalar::zero())
{
while self.coeffs.last().is_some_and(|c| c == &BlsScalar::zero()) {
self.coeffs.pop();
}
}
Expand Down Expand Up @@ -185,7 +183,7 @@ impl Sum for Polynomial {
}
}

impl<'a, 'b> Add<&'a Polynomial> for &'b Polynomial {
impl<'a> Add<&'a Polynomial> for &Polynomial {
type Output = Polynomial;

fn add(self, other: &'a Polynomial) -> Polynomial {
Expand Down Expand Up @@ -269,7 +267,7 @@ impl Neg for Polynomial {
}
}

impl<'a, 'b> Sub<&'a Polynomial> for &'b Polynomial {
impl<'a> Sub<&'a Polynomial> for &Polynomial {
type Output = Polynomial;

#[inline]
Expand Down Expand Up @@ -370,7 +368,7 @@ impl Polynomial {
}

/// Performs O(nlogn) multiplication of polynomials if F is smooth.
impl<'a, 'b> Mul<&'a Polynomial> for &'b Polynomial {
impl<'a> Mul<&'a Polynomial> for &Polynomial {
type Output = Polynomial;

#[inline]
Expand All @@ -395,7 +393,7 @@ impl<'a, 'b> Mul<&'a Polynomial> for &'b Polynomial {
}
}

impl<'a, 'b> Mul<&'a BlsScalar> for &'b Polynomial {
impl<'a> Mul<&'a BlsScalar> for &Polynomial {
type Output = Polynomial;

#[inline]
Expand All @@ -409,7 +407,7 @@ impl<'a, 'b> Mul<&'a BlsScalar> for &'b Polynomial {
}
}

impl<'a, 'b> Add<&'a BlsScalar> for &'b Polynomial {
impl<'a> Add<&'a BlsScalar> for &Polynomial {
type Output = Polynomial;

#[inline]
Expand All @@ -427,7 +425,7 @@ impl<'a, 'b> Add<&'a BlsScalar> for &'b Polynomial {
}
}

impl<'a, 'b> Sub<&'a BlsScalar> for &'b Polynomial {
impl<'a> Sub<&'a BlsScalar> for &Polynomial {
type Output = Polynomial;

#[inline]
Expand Down
Loading