Compare commits

...

7 Commits

Author SHA1 Message Date
ashWhiteHat e0a178fd8b
Merge 647d61cab7 into 7df93fd855 2024-02-29 16:45:13 +05:30
Daira-Emma Hopwood 7df93fd855
Merge pull request #814 from adria0/fix/mdbook
Fix MD book generation
2024-02-26 23:50:17 +00:00
adria0 daaa638966 fix(mdbook): fix generation 2024-02-22 22:28:36 +01:00
Daira-Emma Hopwood 81729eca91
Merge pull request #809 from daira/remove-empty-halo2-crate-from-readme
Remove references to the empty `halo2` crate from the README
2024-02-06 15:25:48 +00:00
Daira-Emma Hopwood 4a8e640afd Remove references to the empty `halo2` crate from the README, and link
to the `halo2_proofs` and `halo2_gadgets` READMEs.

Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
2024-02-06 12:54:21 +00:00
NoCtrlZ 647d61cab7 Apply @str4d and @therealyingtong's review suggestion 2022-06-01 00:56:46 +09:00
NoCtrlZ 8544f1467f add poly arithmetic bench and test 2022-04-26 19:57:16 +09:00
7 changed files with 113 additions and 21 deletions

View File

@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: '1.76.0'
override: true
# - name: Setup mdBook
@ -26,7 +26,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: install
args: mdbook --git https://github.com/HollowMan6/mdBook.git --rev 62e01b34c23b957579c04ee1b24b57814ed8a4d5
args: mdbook --git https://github.com/HollowMan6/mdBook.git --rev 5830c9555a4dc051675d17f1fcb04dd0920543e8
- name: Install mdbook-katex and mdbook-pdf
uses: actions-rs/cargo@v1
@ -40,6 +40,11 @@ jobs:
- name: Build halo2 book
run: mdbook build book/
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-10-05
override: true
- name: Build latest rustdocs
uses: actions-rs/cargo@v1
with:

View File

@ -4,3 +4,7 @@ members = [
"halo2_gadgets",
"halo2_proofs",
]
[profile.bench]
lto = "thin"
codegen-units = 1

View File

@ -1,6 +1,9 @@
# halo2 [![Crates.io](https://img.shields.io/crates/v/halo2.svg)](https://crates.io/crates/halo2) #
# halo2
## [Documentation](https://docs.rs/halo2)
## Usage
This repository contains the [halo2_proofs](halo2_proofs/README.md) and
[halo2_gadgets](halo2_gadgets/README.md) crates, which should be used directly.
## Minimum Supported Rust Version

View File

@ -14,8 +14,6 @@ title = "The halo2 Book"
macros = "macros.txt"
renderers = ["html"]
[output.katex]
[output.html]
[output.html.print]

View File

@ -35,6 +35,10 @@ harness = false
name = "plonk"
harness = false
[[bench]]
name = "poly"
harness = false
[[bench]]
name = "dev_lookup"
harness = false

View File

@ -0,0 +1,35 @@
#[macro_use]
extern crate criterion;
use crate::arithmetic::{compute_inner_product, eval_polynomial};
use crate::pasta::Fp;
use group::ff::Field;
use halo2_proofs::*;
use criterion::{BenchmarkId, Criterion};
use rand_core::OsRng;
fn criterion_benchmark(c: &mut Criterion) {
let mut eval_polynomial_group = c.benchmark_group("poly-eval");
for k in 3..19 {
eval_polynomial_group.bench_function(BenchmarkId::new("k", k), |b| {
let poly = (0..(1 << k)).map(|_| Fp::random(OsRng)).collect::<Vec<_>>();
let point = Fp::random(OsRng);
b.iter(|| eval_polynomial(&poly, point));
});
}
eval_polynomial_group.finish();
let mut compute_inner_product_group = c.benchmark_group("poly-inner-product");
for k in 3..19 {
compute_inner_product_group.bench_function(BenchmarkId::new("k", k), |b| {
let a = (0..(1 << k)).map(|_| Fp::random(OsRng)).collect::<Vec<_>>();
let other = (0..(1 << k)).map(|_| Fp::random(OsRng)).collect::<Vec<_>>();
b.iter(|| compute_inner_product(&a, &other));
});
}
compute_inner_product_group.finish();
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

View File

@ -426,27 +426,70 @@ pub fn lagrange_interpolate<F: Field>(points: &[F], evals: &[F]) -> Vec<F> {
}
#[cfg(test)]
use rand_core::OsRng;
mod tests {
use super::{compute_inner_product, eval_polynomial, lagrange_interpolate, Field};
use crate::pasta::{arithmetic::FieldExt, Fp};
use proptest::{collection::vec, prelude::*};
use rand_core::OsRng;
use std::{convert::TryFrom, env::consts::OS};
#[cfg(test)]
use crate::pasta::Fp;
prop_compose! {
fn arb_point()(
bytes in vec(any::<u8>(), 64)
) -> Fp {
Fp::from_bytes_wide(&<[u8; 64]>::try_from(bytes).unwrap())
}
}
#[test]
fn test_lagrange_interpolate() {
let rng = OsRng;
fn arb_poly(k: usize, rng: OsRng) -> Vec<Fp> {
(0..(1 << k)).map(|_| Fp::random(rng)).collect::<Vec<_>>()
}
let points = (0..5).map(|_| Fp::random(rng)).collect::<Vec<_>>();
let evals = (0..5).map(|_| Fp::random(rng)).collect::<Vec<_>>();
proptest! {
#![proptest_config(ProptestConfig::with_cases(100))]
#[test]
fn test_eval_polynomial(point in arb_point(), k in 3_usize..10) {
let mut eval = Fp::zero();
let mut exp = Fp::one();
let poly = arb_poly(k, OsRng);
poly.iter().for_each(|a| {
eval += a * exp;
exp *= point;
});
assert_eq!(eval_polynomial(&poly, point), eval);
}
}
for coeffs in 0..5 {
let points = &points[0..coeffs];
let evals = &evals[0..coeffs];
proptest! {
#![proptest_config(ProptestConfig::with_cases(100))]
#[test]
fn test_compute_inner_product(k in 3_usize..10) {
let mut product = Fp::zero();
let a = arb_poly(k, OsRng);
let b = arb_poly(k, OsRng);
a.iter().zip(b.iter()).for_each(|(a, b)| product += a * b);
assert_eq!(compute_inner_product(&a, &b), product);
}
}
let poly = lagrange_interpolate(points, evals);
assert_eq!(poly.len(), points.len());
#[test]
fn test_lagrange_interpolate() {
let k = 5;
let rng = OsRng;
for (point, eval) in points.iter().zip(evals) {
assert_eq!(eval_polynomial(&poly, *point), *eval);
let points = arb_poly(k, rng);
let evals = arb_poly(k, rng);
for coeffs in 0..k {
let points = &points[0..coeffs];
let evals = &evals[0..coeffs];
let poly = lagrange_interpolate(points, evals);
assert_eq!(poly.len(), points.len());
for (point, eval) in points.iter().zip(evals) {
assert_eq!(eval_polynomial(&poly, *point), *eval);
}
}
}
}