Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
XuyangSong committed Jan 2, 2024
1 parent d99b6a5 commit 46fd8dd
Show file tree
Hide file tree
Showing 20 changed files with 163 additions and 141 deletions.
5 changes: 4 additions & 1 deletion halo2/src/accumulator/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ mod tests {
arithmetic::{CurveAffine, Field},
circuit::{AssignedCell, Chip, Layouter, SimpleFloorPlanner, Value},
dev::MockProver,
pasta::{group::ff::{PrimeFieldBits, PrimeField}, EpAffine, EqAffine},
pasta::{
group::ff::{PrimeField, PrimeFieldBits},
EpAffine, EqAffine,

Check warning on line 128 in halo2/src/accumulator/verifier.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused imports: `EpAffine`, `self`

warning: unused imports: `EpAffine`, `self` --> halo2/src/accumulator/verifier.rs:128:13 | 128 | EpAffine, EqAffine, | ^^^^^^^^ ... 135 | self, Blake2bRead, Blake2bWrite, Challenge255, EncodedChallenge, TranscriptRead, | ^^^^ | = note: `#[warn(unused_imports)]` on by default
},
plonk::{
create_proof, keygen_pk, keygen_vk, Circuit, ConstraintSystem, Error, VerifyingKey,
},
Expand Down
2 changes: 1 addition & 1 deletion halo2/src/transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use halo2_gadgets::{
use halo2_proofs::{
arithmetic::CurveAffine,
circuit::{AssignedCell, Layouter, Value},
plonk::Error,
pasta::group::ff::PrimeField,
plonk::Error,
};

pub trait DuplexInstructions<F: PrimeField> {
Expand Down
6 changes: 3 additions & 3 deletions halo2_gadgets/src/endoscale/chip.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{ecc::chip::NonIdentityEccPoint, utilities::decompose_running_sum::RunningSumConfig};

use super::EndoscaleInstructions;
use ff::{PrimeFieldBits, FromUniformBytes};
use ff::{FromUniformBytes, PrimeFieldBits};
use halo2_proofs::{
arithmetic::CurveAffine,
circuit::{AssignedCell, Layouter, Value},
Expand Down Expand Up @@ -185,7 +185,7 @@ mod tests {
use super::{EndoscaleConfig, EndoscaleInstructions};
use crate::ecc::chip::NonIdentityEccPoint;

use ff::{PrimeFieldBits, FromUniformBytes};
use ff::{FromUniformBytes, PrimeFieldBits};
use halo2_proofs::{
arithmetic::CurveAffine,
circuit::{Layouter, SimpleFloorPlanner, Value},
Expand Down Expand Up @@ -383,7 +383,7 @@ mod tests {
>()
where
BaseCurve::Base: PrimeFieldBits + FromUniformBytes<64>,
ScalarCurve::Base: PrimeFieldBits+ FromUniformBytes<64>,
ScalarCurve::Base: PrimeFieldBits + FromUniformBytes<64>,
{
use ff::Field;
use halo2_proofs::dev::MockProver;
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/endoscale/chip/alg_1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ff::{Field, PrimeFieldBits, WithSmallOrderMulGroup, FromUniformBytes};
use ff::{Field, FromUniformBytes, PrimeFieldBits, WithSmallOrderMulGroup};
use halo2_proofs::{
arithmetic::CurveAffine,
circuit::{Layouter, Region, Value},
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/endoscale/chip/alg_2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ff::{PrimeFieldBits, Field, WithSmallOrderMulGroup, FromUniformBytes};
use ff::{Field, FromUniformBytes, PrimeFieldBits, WithSmallOrderMulGroup};
use halo2_proofs::{
arithmetic::CurveAffine,
circuit::{AssignedCell, Layouter, Value},
Expand Down
12 changes: 9 additions & 3 deletions halo2_gadgets/src/endoscale/util.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Primitives used in endoscaling.

use ff::WithSmallOrderMulGroup;
use group::Group;
use pasta_curves::arithmetic::CurveAffine;
use ff::WithSmallOrderMulGroup;
use subtle::CtOption;

/// Maps a pair of bits to a multiple of a scalar using endoscaling.
Expand Down Expand Up @@ -37,7 +37,10 @@ pub(crate) fn compute_endoscalar<F: WithSmallOrderMulGroup<3>>(bits: &[bool]) ->
///
/// # Panics
/// Panics if there is an odd number of bits.
pub(crate) fn compute_endoscalar_with_acc<F: WithSmallOrderMulGroup<3>>(acc: Option<F>, bits: &[bool]) -> F {
pub(crate) fn compute_endoscalar_with_acc<F: WithSmallOrderMulGroup<3>>(
acc: Option<F>,
bits: &[bool],
) -> F {
assert_eq!(bits.len() % 2, 0);

let mut acc = acc.unwrap_or_else(|| (F::ZETA + F::ONE).double());
Expand Down Expand Up @@ -119,7 +122,10 @@ mod tests {
assert_eq!(base * endoscalar, endoscaled_base.to_curve());
}

fn shift_padded_endo<F: WithSmallOrderMulGroup<3>, const K: usize>(padded_endo: F, k_prime: usize) -> F {
fn shift_padded_endo<F: WithSmallOrderMulGroup<3>, const K: usize>(
padded_endo: F,
k_prime: usize,
) -> F {
// (1 - 2^{(K - K')/2}) * 2^{K'/2}
// = 2^{K'/2} - 2^{K/2}
let shift = F::from(1 << (k_prime / 2)) - F::from(1 << (K / 2));
Expand Down
20 changes: 10 additions & 10 deletions halo2_gadgets/src/poseidon/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,12 @@ impl<F: fmt::Debug, const RATE: usize> Absorbing<F, RATE> {

/// A Poseidon sponge.
#[derive(Debug)]
pub struct Sponge<
F: Field,
S: Spec<F, T, RATE>,
M: SpongeMode,
const T: usize,
const RATE: usize,
> {
pub struct Sponge<F: Field, S: Spec<F, T, RATE>, M: SpongeMode, const T: usize, const RATE: usize> {
mode: M,
///
pub state: State<F, T>,
///
pub mds_matrix: Mds<F, T>,
pub mds_matrix: Mds<F, T>,
///
pub round_constants: Vec<[F; T]>,
_marker: PhantomData<S>,
Expand Down Expand Up @@ -426,8 +420,8 @@ mod tests {

#[test]
fn test_poseidon_4_inputs() {
use pasta_curves::vesta::Base as Fq;
use crate::poseidon::primitives::P128Pow5T5;
use pasta_curves::vesta::Base as Fq;

let message = [Fq::from(1), Fq::from(12), Fq::from(121), Fq::from(1212)];

Expand All @@ -438,7 +432,13 @@ mod tests {

// The result should be equivalent to just directly applying the permutation and
// taking the first state element as the output.
let mut state = [message[0], message[1], message[2], message[3], Fq::from_u128(2 << 65)];
let mut state = [
message[0],
message[1],
message[2],
message[3],
Fq::from_u128(2 << 65),
];
permute::<_, P128Pow5T5, 5, 4>(&mut state, &mds, &round_constants);

assert_eq!(state[0], result);
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/poseidon/primitives/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3819,4 +3819,4 @@ pub(crate) const MDS_INV_T_5: [[pallas::Base; 5]; 5] = [
0x1c74_f2eb_8c95_4941,
]),
],
];
];
2 changes: 1 addition & 1 deletion halo2_gadgets/src/poseidon/primitives/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3818,4 +3818,4 @@ pub(crate) const MDS_INV_T_5: [[vesta::Base; 5]; 5] = [
0x23d9_42c4_ff7c_4a15,
]),
],
];
];
12 changes: 10 additions & 2 deletions halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ mod tests {
]),
];

permute::<Fp, P128Pow5T3Gen<Fp, 0>, 3, 2>(&mut input, &fp::MDS_T_3, &fp::ROUND_CONSTANTS_T_3);
permute::<Fp, P128Pow5T3Gen<Fp, 0>, 3, 2>(
&mut input,
&fp::MDS_T_3,
&fp::ROUND_CONSTANTS_T_3,
);
assert_eq!(input, expected_output);
}

Expand Down Expand Up @@ -247,7 +251,11 @@ mod tests {
]),
];

permute::<Fq, P128Pow5T3Gen<Fq, 0>, 3, 2>(&mut input, &fq::MDS_T_3, &fq::ROUND_CONSTANTS_T_3);
permute::<Fq, P128Pow5T3Gen<Fq, 0>, 3, 2>(
&mut input,
&fq::MDS_T_3,
&fq::ROUND_CONSTANTS_T_3,
);
assert_eq!(input, expected_output);
}
}
Expand Down
18 changes: 14 additions & 4 deletions halo2_gadgets/src/poseidon/primitives/p128pow5t5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ mod tests {
}
}

impl<F: FromUniformBytes<64> + Ord, const SECURE_MDS: usize> Spec<F, 5, 4> for P128Pow5T5Gen<F, SECURE_MDS> {
impl<F: FromUniformBytes<64> + Ord, const SECURE_MDS: usize> Spec<F, 5, 4>
for P128Pow5T5Gen<F, SECURE_MDS>
{
fn full_rounds() -> usize {
8
}
Expand All @@ -105,7 +107,7 @@ mod tests {
SECURE_MDS
}

fn constants() -> (Vec<[F; 5]>, Mds <F, 5>, Mds<F, 5>) {
fn constants() -> (Vec<[F; 5]>, Mds<F, 5>, Mds<F, 5>) {
generate_constants::<_, Self, 5, 4>()
}
}
Expand Down Expand Up @@ -217,7 +219,11 @@ mod tests {
]),
];

permute::<Fp, P128Pow5T5Gen<Fp, 0>, 5, 4>(&mut input, &fp::MDS_T_5, &fp::ROUND_CONSTANTS_T_5);
permute::<Fp, P128Pow5T5Gen<Fp, 0>, 5, 4>(
&mut input,
&fp::MDS_T_5,
&fp::ROUND_CONSTANTS_T_5,
);
assert_eq!(input, expected_output);
}

Expand Down Expand Up @@ -292,7 +298,11 @@ mod tests {
]),
];

permute::<Fq, P128Pow5T5Gen<Fq, 0>, 5, 4>(&mut input, &fq::MDS_T_5, &fq::ROUND_CONSTANTS_T_5);
permute::<Fq, P128Pow5T5Gen<Fq, 0>, 5, 4>(
&mut input,
&fq::MDS_T_5,
&fq::ROUND_CONSTANTS_T_5,
);
assert_eq!(input, expected_output);
}
}
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/utilities.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Utility gadgets.

use ff::{Field, PrimeField, PrimeFieldBits, FromUniformBytes};
use ff::{Field, FromUniformBytes, PrimeField, PrimeFieldBits};
use halo2_proofs::{
circuit::{AssignedCell, Cell, Layouter, Value},
plonk::{Advice, Column, Error, Expression},
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/utilities/bitstring.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Bitstring gadget

use std::ops::Range;
use ff::Field;
use halo2_proofs::{
circuit::{AssignedCell, Layouter},
plonk::Error,
};
use std::ops::Range;

use super::RangeConstrained;

Expand Down
4 changes: 2 additions & 2 deletions halo2_gadgets/src/utilities/double_and_add.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Helper for single-row double-and-add.

use std::marker::PhantomData;
use ff::{PrimeField, Field};
use ff::{Field, PrimeField};
use halo2_proofs::{
arithmetic::CurveAffine,
circuit::{AssignedCell, Region, Value},
Expand All @@ -10,6 +9,7 @@ use halo2_proofs::{
},
poly::Rotation,
};
use std::marker::PhantomData;

/// A helper struct for implementing single-row double-and-add using incomplete addition.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Expand Down
16 changes: 6 additions & 10 deletions halo2_proofs/examples/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ use halo2_proofs::{
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Circuit, Column,
ConstraintSystem, Error, Fixed, Instance, ProvingKey, SingleVerifier,
},
poly::{
Rotation, commitment::Params,
},
transcript::{
Blake2bRead, Blake2bWrite, Challenge255,
},
poly::{commitment::Params, Rotation},
transcript::{Blake2bRead, Blake2bWrite, Challenge255},
};
use pasta_curves::{pallas, EqAffine, Fp};

Check warning on line 16 in halo2_proofs/examples/serialization.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused import: `pallas`

warning: unused import: `pallas` --> halo2_proofs/examples/serialization.rs:16:20 | 16 | use pasta_curves::{pallas, EqAffine, Fp}; | ^^^^^^ | = note: `#[warn(unused_imports)]` on by default
use rand_core::OsRng;
use pasta_curves::{pallas, Fp, EqAffine};

#[derive(Clone, Copy)]
struct StandardPlonkConfig {
Expand Down Expand Up @@ -46,8 +42,8 @@ impl StandardPlonkConfig {
"q_a·a + q_b·b + q_c·c + q_ab·a·b + constant + instance = 0",
|meta| {
let [a, b, c] = [a, b, c].map(|column| meta.query_advice(column, Rotation::cur()));
let [q_a, q_b, q_c, q_ab, constant] = [q_a, q_b, q_c, q_ab, constant]
.map(|column| meta.query_fixed(column));
let [q_a, q_b, q_c, q_ab, constant] =
[q_a, q_b, q_c, q_ab, constant].map(|column| meta.query_fixed(column));
let instance = meta.query_instance(instance, Rotation::cur());
Some(
q_a * a.clone()
Expand Down Expand Up @@ -162,4 +158,4 @@ fn main() {
&mut transcript
)
.is_ok());
}
}
4 changes: 2 additions & 2 deletions halo2_proofs/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::poly::Polynomial;
use crate::arithmetic::CurveAffine;
use crate::poly::Polynomial;
use ff::PrimeField;
use std::io;

Expand Down Expand Up @@ -84,4 +84,4 @@ pub(crate) fn write_polynomial_slice<W: io::Write, F: PrimeField, B>(
pub(crate) fn polynomial_slice_byte_length<F: PrimeField, B>(slice: &[Polynomial<F, B>]) -> usize {
let field_len = F::default().to_repr().as_ref().len();
4 + slice.len() * (4 + field_len * slice.get(0).map(|poly| poly.len()).unwrap_or(0))

Check warning on line 86 in halo2_proofs/src/helpers.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

accessing first element with `slice.get(0)`

warning: accessing first element with `slice.get(0)` --> halo2_proofs/src/helpers.rs:86:40 | 86 | 4 + slice.len() * (4 + field_len * slice.get(0).map(|poly| poly.len()).unwrap_or(0)) | ^^^^^^^^^^^^ help: try: `slice.first()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#get_first

Check warning on line 86 in halo2_proofs/src/helpers.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

accessing first element with `slice.get(0)`

warning: accessing first element with `slice.get(0)` --> halo2_proofs/src/helpers.rs:86:40 | 86 | 4 + slice.len() * (4 + field_len * slice.get(0).map(|poly| poly.len()).unwrap_or(0)) | ^^^^^^^^^^^^ help: try: `slice.first()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#get_first
}
}
Loading

0 comments on commit 46fd8dd

Please sign in to comment.