Skip to content

Commit

Permalink
chore: swap hash function for rustc hasher
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-camuto committed Aug 2, 2024
1 parent 8cfca22 commit ce4409b
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 34 deletions.
1 change: 1 addition & 0 deletions halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ rand_chacha = "0.3"
maybe-rayon = { version = "0.1.1"}
lazy_static = { version = "1", optional = true }
env_logger = "0.10.0"
rustc-hash = "2.0.0"

# GPU Icicle integration
icicle = { git = "https://github.com/ingonyama-zk/icicle.git", branch = "rust/large-bucket-factor-msm", optional = true }
Expand Down
3 changes: 2 additions & 1 deletion halo2_proofs/benches/commit_zk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use maybe_rayon::current_num_threads;
use rand_chacha::rand_core::RngCore;
use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;
use std::{collections::HashMap, iter};
use rustc_hash::FxHashMap as HashMap;
use std::iter;

fn rand_poly_serial(mut rng: ChaCha20Rng, domain: usize) -> Vec<Scalar> {
// Sample a random polynomial of degree n - 1
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/circuit/floor_planner/single_pass.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_hash::FxHashMap as HashMap;
use std::cmp;
use std::collections::HashMap;
use std::fmt;
use std::marker::PhantomData;

Expand Down
8 changes: 3 additions & 5 deletions halo2_proofs/src/circuit/floor_planner/v1/strategy.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::{
cmp,
collections::{BTreeSet, HashMap},
ops::Range,
};
use std::{cmp, collections::BTreeSet, ops::Range};

use rustc_hash::FxHashMap as HashMap;

use super::{RegionColumn, RegionShape};
use crate::{circuit::RegionStart, plonk::Any};
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/circuit/layouter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Implementations of common circuit layouters.

use rustc_hash::FxHashSet as HashSet;
use std::cmp;
use std::collections::HashSet;
use std::fmt;

use ff::Field;
Expand Down
7 changes: 3 additions & 4 deletions halo2_proofs/src/circuit/table_layouter.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Implementations of common table layouters.

use std::{
collections::HashMap,
fmt::{self, Debug},
};
use std::fmt::{self, Debug};

use rustc_hash::FxHashMap as HashMap;

use ff::Field;

Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/src/dev.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Tools for developing circuits.

use std::collections::HashMap;
use std::collections::HashSet;
use rustc_hash::FxHashMap as HashMap;
use rustc_hash::FxHashSet as HashSet;
use std::iter;
use std::ops::{Add, Mul, Neg, Range};

Expand Down
11 changes: 6 additions & 5 deletions halo2_proofs/src/dev/cost.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! Developer tools for investigating the cost of a circuit.

use std::{
cmp,
collections::{HashMap, HashSet},
iter,
cmp, iter,
marker::PhantomData,
ops::{Add, Mul},
};

use rustc_hash::FxHashMap as HashMap;
use rustc_hash::FxHashSet as HashSet;

use ff::{Field, PrimeField};
use group::prime::PrimeGroup;

Expand Down Expand Up @@ -288,7 +289,7 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
assert!((1 << k) >= cs.minimum_rows());

// Figure out how many point sets we have due to queried cells.
let mut column_queries: HashMap<Column<Any>, HashSet<i32>> = HashMap::new();
let mut column_queries: HashMap<Column<Any>, HashSet<i32>> = HashMap::default();
for (c, r) in iter::empty()
.chain(
cs.advice_queries
Expand All @@ -306,7 +307,7 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
{
column_queries.entry(c).or_default().insert(r.0);
}
let mut point_sets: HashSet<Vec<i32>> = HashSet::new();
let mut point_sets: HashSet<Vec<i32>> = HashSet::default();
for (_, r) in column_queries {
// Sort the query sets so we merge duplicates.
let mut query_set: Vec<_> = r.into_iter().collect();
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/dev/cost_model.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The cost estimator takes high-level parameters for a circuit design, and estimates the
//! verification cost, as well as resulting proof size.

use std::collections::HashSet;
use rustc_hash::FxHashSet as HashSet;
use std::{iter, num::ParseIntError, str::FromStr};

use crate::plonk::Circuit;
Expand Down
4 changes: 3 additions & 1 deletion halo2_proofs/src/dev/failure.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::collections::{BTreeMap, HashSet};
use std::collections::BTreeMap;
use std::fmt::{self, Debug};

use group::ff::Field;

use rustc_hash::FxHashSet as HashSet;

use super::metadata::{DebugColumn, DebugVirtualCell};
use super::MockProver;
use super::{
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/dev/graph/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use plotters::{
coord::Shift,
prelude::{DrawingArea, DrawingAreaErrorKind, DrawingBackend},
};
use std::collections::HashSet;
use rustc_hash::FxHashSet as HashSet;
use std::ops::Range;

use crate::{
Expand Down
7 changes: 3 additions & 4 deletions halo2_proofs/src/dev/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

use super::metadata::Column as ColumnMetadata;
use crate::plonk::{self, Any};
use std::{
collections::HashMap,
fmt::{self, Debug},
};
use std::fmt::{self, Debug};

use rustc_hash::FxHashMap as HashMap;
/// Metadata about a column within a circuit.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Column {
Expand Down
6 changes: 4 additions & 2 deletions halo2_proofs/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ use core::cmp::max;
use core::ops::{Add, Mul};
use ff::Field;
use sealed::SealedPhase;
use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;
use std::fmt::Debug;
use std::iter::{Product, Sum};
use std::{
convert::TryFrom,
ops::{Neg, Sub},
};

use rustc_hash::FxHashMap as HashMap;

#[cfg(not(feature = "mv-lookup"))]
use super::lookup;
#[cfg(feature = "mv-lookup")]
Expand Down Expand Up @@ -1701,7 +1703,7 @@ impl<F: Field> Default for ConstraintSystem<F> {
lookups_map: BTreeMap::default(),
lookups: Vec::new(),
shuffles: Vec::new(),
general_column_annotations: HashMap::new(),
general_column_annotations: HashMap::default(),
constants: vec![],
minimum_degree: None,
}
Expand Down
5 changes: 4 additions & 1 deletion halo2_proofs/src/plonk/permutation/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use crate::{
use maybe_rayon::prelude::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};

#[cfg(feature = "thread-safe-region")]
use std::collections::{BTreeSet, HashMap};
use std::collections::BTreeSet;

#[cfg(feature = "thread-safe-region")]
use rustc_hash::FxHashMap as HashMap;

#[cfg(not(feature = "thread-safe-region"))]
/// Struct that accumulates all the necessary data in order to construct the permutation argument.
Expand Down
11 changes: 8 additions & 3 deletions halo2_proofs/src/plonk/prover.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use ff::{Field, FromUniformBytes, WithSmallOrderMulGroup};
use group::Curve;
use rand_core::RngCore;
use std::collections::{BTreeSet, HashSet};
use rustc_hash::FxBuildHasher;
use rustc_hash::FxHashMap as HashMap;
use rustc_hash::FxHashSet as HashSet;
use std::collections::BTreeSet;
use std::iter;
use std::ops::RangeTo;
use std::{collections::HashMap, iter};

use super::{
circuit::{
Expand Down Expand Up @@ -311,7 +314,9 @@ where
};
instances.len()
];
let mut challenges = HashMap::<usize, Scheme::Scalar>::with_capacity(meta.num_challenges);
let s = FxBuildHasher::default();
let mut challenges =
HashMap::<usize, Scheme::Scalar>::with_capacity_and_hasher(meta.num_challenges, s);

let unusable_rows_start = params.n() as usize - (meta.blinding_factors() + 1);
for current_phase in pk.vk.cs.phases() {
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/src/plonk/vanishing/prover.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{collections::HashMap, iter};

use ff::Field;
use group::Curve;
use rand_chacha::ChaCha20Rng;
use rand_core::{RngCore, SeedableRng};
use rustc_hash::FxHashMap as HashMap;
use std::iter;

use super::Argument;
use crate::{
Expand Down

0 comments on commit ce4409b

Please sign in to comment.