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

update halo2curves to 0.6.0 #242

Merged
merged 9 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- feature_set: basic
features: batch,dev-graph,gadget-traces
- feature_set: all
features: batch,dev-graph,gadget-traces,multicore,test-dev-graph,thread-safe-region,sanity-checks,circuit-params
features: batch,dev-graph,gadget-traces,test-dev-graph,thread-safe-region,sanity-checks,circuit-params

steps:
- uses: actions/checkout@v3
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ minor version bump.

## Controlling parallelism

`halo2` currently uses [rayon](https://github.com/rayon-rs/rayon) for parallel computation.
The `RAYON_NUM_THREADS` environment variable can be used to set the number of threads.
`halo2` currently uses [rayon](https://github.com/rayon-rs/rayon) for parallel computation. The `RAYON_NUM_THREADS` environment variable can be used to set the number of threads.

You can disable `rayon` by disabling the `"multicore"` feature.
Warning! Halo2 will lose access to parallelism if you disable the `"multicore"` feature.
This will significantly degrade performance.
When compiling to WASM-targets, notice that since version `1.7`, `rayon` will fallback automatically (with no need to handle features) to require `getrandom` in order to be able to work. For more info related to WASM-compilation.

See: [Rayon: Usage with WebAssembly](https://github.com/rayon-rs/rayon#usage-with-webassembly) for more

## License

Expand Down
2 changes: 1 addition & 1 deletion halo2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "katex-header.html"]

[dependencies]
halo2_proofs = { version = "0.2", path = "../halo2_proofs", default-features = false }
halo2_proofs = { version = "0.3", path = "../halo2_proofs", default-features = false }

[lib]
bench = false
10 changes: 5 additions & 5 deletions halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "halo2_proofs"
version = "0.2.0"
version = "0.3.0"
authors = [
"Sean Bowe <sean@electriccoin.co>",
"Ying Tong Lai <yingtong@electriccoin.co>",
Expand Down Expand Up @@ -51,15 +51,15 @@ harness = false
backtrace = { version = "0.3", optional = true }
ff = "0.13"
group = "0.13"
halo2curves = { version = "0.1.0" }
halo2curves = { version = "0.6.0", default-features = false }
rand_core = { version = "0.6", default-features = false }
tracing = "0.1"
blake2b_simd = "1" # MSRV 1.66.0
sha3 = "0.9.1"
rand_chacha = "0.3"
maybe-rayon = { version = "0.1.0", default-features = false }
serde = { version = "1", optional = true, features = ["derive"] }
serde_derive = { version = "1", optional = true}
rayon = "1.8"

# Developer tooling dependencies
plotters = { version = "0.3.0", default-features = false, optional = true }
Expand All @@ -80,15 +80,15 @@ serde_json = "1"
getrandom = { version = "0.2", features = ["js"] }

[features]
default = ["batch", "multicore"]
multicore = ["maybe-rayon/threads"]
default = ["batch", "bits"]
dev-graph = ["plotters", "tabbycat"]
test-dev-graph = [
"dev-graph",
"plotters/bitmap_backend",
"plotters/bitmap_encoder",
"plotters/ttf",
]
bits = ["halo2curves/bits"]
gadget-traces = ["backtrace"]
thread-safe-region = []
sanity-checks = []
Expand Down
6 changes: 3 additions & 3 deletions halo2_proofs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ minor version bump.
computation. The `RAYON_NUM_THREADS` environment variable can be used to set the number of
threads.

You can disable `rayon` by disabling the `"multicore"` feature.
Warning! Halo2 will lose access to parallelism if you disable the `"multicore"` feature.
This will significantly degrade performance.
When compiling to WASM-targets, notice that since version `1.7`, `rayon` will fallback automatically (with no need to handle features) to require `getrandom` in order to be able to work. For more info related to WASM-compilation.

See: [Rayon: Usage with WebAssembly](https://github.com/rayon-rs/rayon#usage-with-webassembly) for more

## License

Expand Down
9 changes: 1 addition & 8 deletions halo2_proofs/benches/commit_zk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@ use halo2curves::pasta::pallas::Scalar;
use rand_chacha::rand_core::RngCore;
use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;
use rayon::current_num_threads;
use std::{collections::HashMap, iter};

#[cfg(feature = "multicore")]
use maybe_rayon::current_num_threads;

#[cfg(not(feature = "multicore"))]
fn current_num_threads() -> usize {
1
}

fn rand_poly_serial(mut rng: ChaCha20Rng, domain: usize) -> Vec<Scalar> {
// Sample a random polynomial of degree n - 1
let mut random_poly = vec![Scalar::zero(); 1 << domain];
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/benches/dev_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|mut table| {
for row in 0u64..(1 << 8) {
table.assign_cell(
|| format!("row {}", row),
|| format!("row {row}"),
config.table,
row as usize,
|| Value::known(F::from(row + 1)),
Expand All @@ -79,7 +79,7 @@ fn criterion_benchmark(c: &mut Criterion) {
for offset in 0u64..(1 << 10) {
config.selector.enable(&mut region, offset as usize)?;
region.assign_advice(
|| format!("offset {}", offset),
|| format!("offset {offset}"),
config.advice,
offset as usize,
|| Value::known(F::from((offset % 256) + 1)),
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/examples/circuit-layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl<F: Field> Circuit<F> for MyCircuit<F> {

for i in 0..10 {
layouter.assign_region(
|| format!("region_{}", i),
|| format!("region_{i}"),
|mut region| {
let a: Value<Assigned<_>> = self.a.into();
let mut a_squared = Value::unknown();
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/examples/proof-size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Circuit<Fp> for TestCircuit {
|mut table| {
for row in 0u64..(1 << 8) {
table.assign_cell(
|| format!("row {}", row),
|| format!("row {row}"),
config.table,
row as usize,
|| Value::known(Fp::from(row + 1)),
Expand All @@ -70,7 +70,7 @@ impl Circuit<Fp> for TestCircuit {
for offset in 0u64..(1 << 10) {
config.selector.enable(&mut region, offset as usize)?;
region.assign_advice(
|| format!("offset {}", offset),
|| format!("offset {offset}"),
config.advice,
offset as usize,
|| Value::known(Fp::from((offset % 256) + 1)),
Expand Down
11 changes: 3 additions & 8 deletions halo2_proofs/examples/shuffle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<F: Field, const W: usize, const H: usize> Circuit<F> for MyCircuit<F, W, H>
{
for (offset, &value) in values.transpose_array().iter().enumerate() {
region.assign_advice(
|| format!("original[{}][{}]", idx, offset),
|| format!("original[{idx}][{offset}]"),
column,
offset,
|| value,
Expand All @@ -183,7 +183,7 @@ impl<F: Field, const W: usize, const H: usize> Circuit<F> for MyCircuit<F, W, H>
{
for (offset, &value) in values.transpose_array().iter().enumerate() {
region.assign_advice(
|| format!("shuffled[{}][{}]", idx, offset),
|| format!("shuffled[{idx}][{offset}]"),
column,
offset,
|| value,
Expand Down Expand Up @@ -233,12 +233,7 @@ impl<F: Field, const W: usize, const H: usize> Circuit<F> for MyCircuit<F, W, H>
},
);
for (offset, value) in z.transpose_vec(H + 1).into_iter().enumerate() {
region.assign_advice(
|| format!("z[{}]", offset),
config.z,
offset,
|| value,
)?;
region.assign_advice(|| format!("z[{offset}]"), config.z, offset, || value)?;
}

Ok(())
Expand Down
34 changes: 0 additions & 34 deletions halo2_proofs/examples/vector-mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,40 +178,6 @@ impl<F: Field> NumericInstructions<F> for FieldChip<F> {
let config = self.config();
assert_eq!(a.len(), b.len());

#[cfg(feature = "thread-safe-region")]
{
use maybe_rayon::prelude::{
IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator,
};
layouter.assign_region(
|| "mul",
|region: Region<'_, F>| {
let thread_safe_region = std::sync::Mutex::new(region);
a.par_iter()
.zip(b.par_iter())
.enumerate()
.map(|(i, (a, b))| {
let mut region = thread_safe_region.lock().unwrap();

config.s_mul.enable(&mut region, i)?;

a.0.copy_advice(|| "lhs", &mut region, config.advice[0], i)?;
b.0.copy_advice(|| "rhs", &mut region, config.advice[1], i)?;

let value = a.0.value().copied() * b.0.value();

// Finally, we do the assignment to the output, returning a
// variable to be used in another part of the circuit.
region
.assign_advice(|| "lhs * rhs", config.advice[2], i, || value)
.map(Number)
})
.collect()
},
)
}

#[cfg(not(feature = "thread-safe-region"))]
layouter.assign_region(
|| "mul",
|mut region: Region<'_, F>| {
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ impl<'a, F: Field, L: Layouter<F> + 'a> Drop for NamespacedLayouter<'a, F, L> {
if is_second_frame {
// Resolve this instruction pointer to a symbol name.
backtrace::resolve_frame(frame, |symbol| {
gadget_name = symbol.name().map(|name| format!("{:#}", name));
gadget_name = symbol.name().map(|name| format!("{name:#}"));
});

// We are done!
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/circuit/table_layouter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'r, 'a, F: Field, CS: Assignment<F> + 'a> TableLayouter<F>
return Err(Error::TableError(TableError::OverwriteDefault(
column,
format!("{:?}", entry.0.unwrap()),
format!("{:?}", value),
format!("{value:?}"),
)))
}
_ => (),
Expand Down
Loading
Loading