Skip to content

Commit 6adc633

Browse files
committed
fix previous commit
1 parent 233dbc6 commit 6adc633

File tree

13 files changed

+91
-92
lines changed

13 files changed

+91
-92
lines changed

Cargo.lock

Lines changed: 21 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

halo2_proofs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ blake2b_simd = "1"
5555
sha3 = "0.9.1"
5656
subtle = "2.3"
5757
cfg-if = "0.1"
58-
poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "scroll-dev-0220" }
58+
poseidon = { git = "https://github.com/privacy-scaling-explorations/poseidon.git", tag = "v2023_04_20" }
5959
num-integer = "0.1"
6060
num-bigint = { version = "0.4", features = ["rand"] }
6161

halo2_proofs/src/arithmetic.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn serial_split_fft<Scalar: Field, G: FftGroup<Scalar>>(
263263

264264
let mut k = 0;
265265
while k < n {
266-
let mut w = G::Scalar::ONE;
266+
let mut w = Scalar::ONE;
267267
for j in 0..m {
268268
let mut t = a[(k + j + m) as usize];
269269
t *= &w;
@@ -293,10 +293,15 @@ fn split_radix_fft<Scalar: Field, G: FftGroup<Scalar>>(
293293

294294
// we use out-place bitreverse here, split_m <= num_threads, so the buffer spase is small
295295
// and it's is good for data locality
296-
let mut t1 = vec![G::Scalar::ZERO; split_m];
296+
// COPY `a` to init temp buffer,
297+
// it's a workaround for G: FftGroup,
298+
// used to be: vec![G::identity; split_m];
299+
// let mut t1 = a.clone();
297300
// if unsafe code is allowed, a 10% performance improvement can be achieved
298-
// let mut t1: Vec<G> = Vec::with_capacity(split_m as usize);
299-
// unsafe{ t1.set_len(split_m as usize); }
301+
let mut t1: Vec<G> = Vec::with_capacity(split_m as usize);
302+
unsafe {
303+
t1.set_len(split_m as usize);
304+
}
300305
for i in 0..split_m {
301306
t1[bitreverse(i, log_split)] = a[(i * sub_n + sub_fft_offset)];
302307
}
@@ -310,7 +315,7 @@ fn split_radix_fft<Scalar: Field, G: FftGroup<Scalar>>(
310315
if high_idx > 0 {
311316
omega = omega * twiddle_lut[(1 << sparse_degree) + high_idx];
312317
}
313-
let mut w_m = G::Scalar::ONE;
318+
let mut w_m = Scalar::ONE;
314319
for i in 0..split_m {
315320
t1[i] *= &w_m;
316321
tmp[i] = t1[i];
@@ -329,7 +334,7 @@ pub fn generate_twiddle_lookup_table<F: Field>(
329334

330335
// dense
331336
if is_lut_len_large {
332-
let mut twiddle_lut = vec![F::zero(); (1 << log_n) as usize];
337+
let mut twiddle_lut = vec![F::ZERO; (1 << log_n) as usize];
333338
parallelize(&mut twiddle_lut, |twiddle_lut, start| {
334339
let mut w_n = omega.pow_vartime([start as u64, 0, 0, 0]);
335340
for twiddle_lut in twiddle_lut.iter_mut() {
@@ -343,7 +348,7 @@ pub fn generate_twiddle_lookup_table<F: Field>(
343348
// sparse
344349
let low_degree_lut_len = 1 << sparse_degree;
345350
let high_degree_lut_len = 1 << (log_n - sparse_degree - without_last_level as u32);
346-
let mut twiddle_lut = vec![F::zero(); (low_degree_lut_len + high_degree_lut_len) as usize];
351+
let mut twiddle_lut = vec![F::ZERO; (low_degree_lut_len + high_degree_lut_len) as usize];
347352
parallelize(
348353
&mut twiddle_lut[..low_degree_lut_len],
349354
|twiddle_lut, start| {
@@ -378,10 +383,15 @@ pub fn parallel_fft<Scalar: Field, G: FftGroup<Scalar>>(a: &mut [G], omega: Scal
378383
let twiddle_lut = generate_twiddle_lookup_table(omega, log_n, SPARSE_TWIDDLE_DEGREE, true);
379384

380385
// split fft
381-
let mut tmp = vec![G::Scalar::ZERO; n];
386+
// COPY `a` to init temp buffer,
387+
// it's a workaround for G: FftGroup,
388+
// used to be: vec![G::identity; n];
389+
// let mut tmp = a.clone();
382390
// if unsafe code is allowed, a 10% performance improvement can be achieved
383-
// let mut tmp: Vec<G> = Vec::with_capacity(n);
384-
// unsafe{ tmp.set_len(n); }
391+
let mut tmp: Vec<G> = Vec::with_capacity(n);
392+
unsafe {
393+
tmp.set_len(n);
394+
}
385395
multicore::scope(|scope| {
386396
let a = &*a;
387397
let twiddle_lut = &*twiddle_lut;

halo2_proofs/src/dev.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Region {
9797
}
9898

9999
/// The value of a particular cell within the circuit.
100-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
100+
#[derive(Clone, Copy, Debug, Eq)]
101101
pub enum CellValue<F: Field> {
102102
/// An unassigned cell.
103103
Unassigned,
@@ -110,7 +110,7 @@ pub enum CellValue<F: Field> {
110110
Poison(usize),
111111
}
112112

113-
impl<F: Group + Field> PartialEq for CellValue<F> {
113+
impl<F: Field> PartialEq for CellValue<F> {
114114
fn eq(&self, other: &Self) -> bool {
115115
match (self, other) {
116116
(Self::Unassigned, Self::Unassigned) => true,

halo2_proofs/src/dev/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub(super) fn load<'a, F: Field, T: ColumnType, Q: Into<AnyQuery> + Copy>(
8686
}
8787
*/
8888

89-
pub(super) fn load_slice<'a, F: FieldExt, T: ColumnType, Q: Into<AnyQuery> + Copy>(
89+
pub(super) fn load_slice<'a, F: Field, T: ColumnType, Q: Into<AnyQuery> + Copy>(
9090
n: i32,
9191
row: i32,
9292
queries: &'a [(Column<T>, Rotation)],

halo2_proofs/src/helpers.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::plonk::{Any, Column};
22
use crate::poly::Polynomial;
3-
use ff::Field;
4-
use ff::PrimeField;
5-
use halo2curves::FieldExt;
3+
use ff::{Field, FromUniformBytes, PrimeField};
64
use halo2curves::{pairing::Engine, serde::SerdeObject, CurveAffine};
75
use num_bigint::BigUint;
86
use std::io;
@@ -42,24 +40,30 @@ pub(crate) trait CurveRead: CurveAffine {
4240
}
4341
impl<C: CurveAffine> CurveRead for C {}
4442

45-
pub fn field_to_bn<F: FieldExt>(f: &F) -> BigUint {
43+
pub fn field_to_bn<F: PrimeField>(f: &F) -> BigUint {
4644
BigUint::from_bytes_le(f.to_repr().as_ref())
4745
}
4846

4947
/// Input a big integer `bn`, compute a field element `f`
5048
/// such that `f == bn % F::MODULUS`.
51-
pub fn bn_to_field<F: FieldExt>(bn: &BigUint) -> F {
49+
pub fn bn_to_field<F: PrimeField>(bn: &BigUint) -> F
50+
where
51+
F: FromUniformBytes<64>,
52+
{
5253
let mut buf = bn.to_bytes_le();
5354
buf.resize(64, 0u8);
5455

5556
let mut buf_array = [0u8; 64];
5657
buf_array.copy_from_slice(buf.as_ref());
57-
F::from_bytes_wide(&buf_array)
58+
F::from_uniform_bytes(&buf_array)
5859
}
5960

6061
/// Input a base field element `b`, output a scalar field
6162
/// element `s` s.t. `s == b % ScalarField::MODULUS`
62-
pub(crate) fn base_to_scalar<C: CurveAffine>(base: &C::Base) -> C::Scalar {
63+
pub(crate) fn base_to_scalar<C: CurveAffine>(base: &C::Base) -> C::Scalar
64+
where
65+
C::Scalar: FromUniformBytes<64>,
66+
{
6367
let bn = field_to_bn(base);
6468
// bn_to_field will perform a mod reduction
6569
bn_to_field(&bn)
@@ -103,6 +107,7 @@ mod test {
103107
}
104108
}
105109
}
110+
106111
pub trait SerdeCurveAffine: CurveAffine + SerdeObject {
107112
/// Reads an element from the buffer and parses it according to the `format`:
108113
/// - `Processed`: Reads a compressed curve element and decompress it

halo2_proofs/src/plonk/keygen.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ where
424424
C: CurveAffine,
425425
P: Params<'params, C>,
426426
ConcreteCircuit: Circuit<C::Scalar>,
427+
<C as CurveAffine>::ScalarExt: FromUniformBytes<64>,
427428
{
428429
keygen_pk_impl(params, None, circuit)
429430
}
@@ -438,6 +439,7 @@ where
438439
C: CurveAffine,
439440
P: Params<'params, C>,
440441
ConcreteCircuit: Circuit<C::Scalar>,
442+
<C as CurveAffine>::ScalarExt: FromUniformBytes<64>,
441443
{
442444
keygen_pk_impl(params, Some(vk), circuit)
443445
}
@@ -452,6 +454,7 @@ where
452454
C: CurveAffine,
453455
P: Params<'params, C>,
454456
ConcreteCircuit: Circuit<C::Scalar>,
457+
<C as CurveAffine>::ScalarExt: FromUniformBytes<64>,
455458
{
456459
let (domain, cs, config) = create_domain::<C, ConcreteCircuit>(params.k());
457460

halo2_proofs/src/plonk/prover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ where
466466
//*cell = C::Scalar::one();
467467
//}
468468
let idx = advice_values.len() - 1;
469-
advice_values[idx] = Scheme::Scalar::one();
469+
advice_values[idx] = Scheme::Scalar::ONE;
470470
}
471471

472472
// Compute commitments to advice column polynomials

halo2_proofs/src/plonk/vanishing/prover.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ impl<C: CurveAffine> Argument<C> {
5050
transcript: &mut T,
5151
) -> Result<Committed<C>, Error> {
5252
// Sample a random polynomial of degree n - 1
53-
let random_poly = domain.constant_lagrange(C::Scalar::one());
53+
let random_poly = domain.constant_lagrange(C::Scalar::ONE);
5454
let random_poly = domain.lagrange_to_coeff(random_poly);
5555
// Sample a random blinding factor
56-
let random_blind = Blind(C::Scalar::zero());
56+
let random_blind = Blind(C::Scalar::ZERO);
5757
let c = params.commit(&random_poly, random_blind).to_affine();
5858
// We write the identity point to the transcript which
5959
// is the commitment of the zero polynomial.

halo2_proofs/src/poly/domain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl<F: WithSmallOrderMulGroup<3>> EvaluationDomain<F> {
458458
parallelize(a, |a, index| {
459459
let mut c_power = c.pow_vartime(&[index as u64, 0, 0, 0]);
460460
for a in a {
461-
a = a * (&c_power);
461+
*a = *a * (&c_power);
462462
c_power = c_power * c;
463463
}
464464
});
@@ -654,7 +654,7 @@ fn test_l_i() {
654654
points.push(domain.omega.pow(&[i, 0, 0, 0]));
655655
}
656656
for i in 0..8 {
657-
let mut l_i = vec![Scalar::zero(); 8];
657+
let mut l_i = vec![Scalar::ZERO; 8];
658658
l_i[i] = Scalar::ONE;
659659
let l_i = lagrange_interpolate(&points[..], &l_i[..]);
660660
l.push(l_i);

0 commit comments

Comments
 (0)