mirror of https://github.com/zcash/halo2.git
Compare commits
10 Commits
42a8bc7fbc
...
8cf1a3e9d4
Author | SHA1 | Date |
---|---|---|
Michał Papierski | 8cf1a3e9d4 | |
Daira-Emma Hopwood | 7df93fd855 | |
adria0 | daaa638966 | |
Daira-Emma Hopwood | 81729eca91 | |
Daira-Emma Hopwood | 4a8e640afd | |
Daira Emma Hopwood | ae52332c77 | |
Daira Emma Hopwood | 2e617ae1da | |
Daira Emma Hopwood | de1d237013 | |
Daira Emma Hopwood | 3eb4ec5c19 | |
Michał Papierski | 3646c592d8 |
|
@ -12,7 +12,7 @@ jobs:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: '1.76.0'
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
# - name: Setup mdBook
|
# - name: Setup mdBook
|
||||||
|
@ -26,7 +26,7 @@ jobs:
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: install
|
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
|
- name: Install mdbook-katex and mdbook-pdf
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
|
@ -40,6 +40,11 @@ jobs:
|
||||||
- name: Build halo2 book
|
- name: Build halo2 book
|
||||||
run: mdbook build book/
|
run: mdbook build book/
|
||||||
|
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: nightly-2023-10-05
|
||||||
|
override: true
|
||||||
|
|
||||||
- name: Build latest rustdocs
|
- name: Build latest rustdocs
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -4,5 +4,5 @@
|
||||||
**/.*.swp
|
**/.*.swp
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
.vscode
|
.vscode
|
||||||
**/*.html
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
/book/book
|
||||||
|
|
|
@ -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
|
## Minimum Supported Rust Version
|
||||||
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
.PHONY: all
|
|
||||||
all:
|
|
||||||
find src -type f -a -name '*.md' |sed 's/[.]md$$/.html/g' |xargs $(MAKE)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
find src -type f -a -name '*.html' -print0 |xargs -0 rm
|
|
||||||
|
|
||||||
%.html: %.md
|
|
||||||
pandoc --katex --from=markdown --to=html "$<" "--output=$@"
|
|
||||||
./edithtml.sh "$@" "$<"
|
|
|
@ -2,7 +2,7 @@
|
||||||
authors = [
|
authors = [
|
||||||
"Jack Grigg",
|
"Jack Grigg",
|
||||||
"Sean Bowe",
|
"Sean Bowe",
|
||||||
"Daira Hopwood",
|
"Daira Emma Hopwood",
|
||||||
"Ying Tong Lai",
|
"Ying Tong Lai",
|
||||||
]
|
]
|
||||||
language = "en"
|
language = "en"
|
||||||
|
@ -14,8 +14,6 @@ title = "The halo2 Book"
|
||||||
macros = "macros.txt"
|
macros = "macros.txt"
|
||||||
renderers = ["html"]
|
renderers = ["html"]
|
||||||
|
|
||||||
[output.katex]
|
|
||||||
|
|
||||||
[output.html]
|
[output.html]
|
||||||
|
|
||||||
[output.html.print]
|
[output.html.print]
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
cat - "$1" > "$1.prefix" <<EOF
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="generator" content="pandoc" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
|
|
||||||
<title>$2</title>
|
|
||||||
<style type="text/css">
|
|
||||||
code{white-space: pre-wrap;}
|
|
||||||
span.smallcaps{font-variant: small-caps;}
|
|
||||||
span.underline{text-decoration: underline;}
|
|
||||||
div.column{display: inline-block; vertical-align: top; width: 50%;}
|
|
||||||
</style>
|
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.2/dist/katex.min.css" integrity="sha384-yFRtMMDnQtDRO8rLpMIKrtPCD5jdktao2TV19YiZYWMDkUR5GQZR/NOVTdquEx1j" crossorigin="anonymous">
|
|
||||||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.2/dist/katex.min.js" integrity="sha384-9Nhn55MVVN0/4OFx7EE5kpFBPsEMZxKTCnA+4fqDmg12eCTqGi6+BB2LjY8brQxJ" crossorigin="anonymous"></script>
|
|
||||||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.2/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous"
|
|
||||||
onload="renderMathInElement(document.body);"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
EOF
|
|
||||||
cat "$1.prefix" - >"$1" <<EOF
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
EOF
|
|
||||||
rm -f "$1.prefix"
|
|
|
@ -4,7 +4,7 @@ version = "0.3.0"
|
||||||
authors = [
|
authors = [
|
||||||
"Sean Bowe <sean@electriccoin.co>",
|
"Sean Bowe <sean@electriccoin.co>",
|
||||||
"Jack Grigg <jack@electriccoin.co>",
|
"Jack Grigg <jack@electriccoin.co>",
|
||||||
"Daira Hopwood <daira@jacaranda.org>",
|
"Daira Emma Hopwood <daira@jacaranda.org>",
|
||||||
"Ying Tong Lai <yingtong@electriccoin.co>",
|
"Ying Tong Lai <yingtong@electriccoin.co>",
|
||||||
"Kris Nuttycombe <kris@electriccoin.co>",
|
"Kris Nuttycombe <kris@electriccoin.co>",
|
||||||
]
|
]
|
||||||
|
|
|
@ -4,7 +4,7 @@ version = "0.3.0"
|
||||||
authors = [
|
authors = [
|
||||||
"Sean Bowe <sean@electriccoin.co>",
|
"Sean Bowe <sean@electriccoin.co>",
|
||||||
"Ying Tong Lai <yingtong@electriccoin.co>",
|
"Ying Tong Lai <yingtong@electriccoin.co>",
|
||||||
"Daira Hopwood <daira@electriccoin.co>",
|
"Daira Emma Hopwood <daira@jacaranda.org>",
|
||||||
"Jack Grigg <jack@electriccoin.co>",
|
"Jack Grigg <jack@electriccoin.co>",
|
||||||
]
|
]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -77,6 +77,7 @@ getrandom = { version = "0.2", features = ["js"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["batch", "multicore"]
|
default = ["batch", "multicore"]
|
||||||
|
no_floating_points = []
|
||||||
multicore = ["maybe-rayon/threads"]
|
multicore = ["maybe-rayon/threads"]
|
||||||
dev-graph = ["plotters", "tabbycat"]
|
dev-graph = ["plotters", "tabbycat"]
|
||||||
test-dev-graph = [
|
test-dev-graph = [
|
||||||
|
|
|
@ -33,7 +33,8 @@ fn multiexp_serial<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C], acc: &mut
|
||||||
} else if bases.len() < 32 {
|
} else if bases.len() < 32 {
|
||||||
3
|
3
|
||||||
} else {
|
} else {
|
||||||
(f64::from(bases.len() as u32)).ln().ceil() as usize
|
let bases_len = bases.len();
|
||||||
|
ln_ceil(bases_len)
|
||||||
};
|
};
|
||||||
|
|
||||||
fn get_at<F: PrimeField>(segment: usize, c: usize, bytes: &F::Repr) -> usize {
|
fn get_at<F: PrimeField>(segment: usize, c: usize, bytes: &F::Repr) -> usize {
|
||||||
|
@ -115,6 +116,67 @@ fn multiexp_serial<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C], acc: &mut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "no_floating_points")]
|
||||||
|
const LN_CEIL_LOOKUP_TABLE: &[usize] = &[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
8,
|
||||||
|
21,
|
||||||
|
55,
|
||||||
|
149,
|
||||||
|
404,
|
||||||
|
1097,
|
||||||
|
2981,
|
||||||
|
8104,
|
||||||
|
22027,
|
||||||
|
59875,
|
||||||
|
162755,
|
||||||
|
442414,
|
||||||
|
1202605,
|
||||||
|
3269018,
|
||||||
|
8886111,
|
||||||
|
24154953,
|
||||||
|
65659970,
|
||||||
|
178482301,
|
||||||
|
485165196,
|
||||||
|
1318815735,
|
||||||
|
3584912847,
|
||||||
|
9744803447,
|
||||||
|
26489122130,
|
||||||
|
72004899338,
|
||||||
|
195729609429,
|
||||||
|
532048240602,
|
||||||
|
1446257064292,
|
||||||
|
3931334297145,
|
||||||
|
10686474581525,
|
||||||
|
29048849665248,
|
||||||
|
78962960182681,
|
||||||
|
214643579785917,
|
||||||
|
583461742527457,
|
||||||
|
1586013452313437,
|
||||||
|
4311231547115211,
|
||||||
|
11719142372802654,
|
||||||
|
31855931757113870,
|
||||||
|
86593400423994057,
|
||||||
|
235385266837020817,
|
||||||
|
639843493530057281,
|
||||||
|
1739274941520507264,
|
||||||
|
4727839468229363200,
|
||||||
|
12851600114359354369,
|
||||||
|
];
|
||||||
|
|
||||||
|
#[cfg(feature = "no_floating_points")]
|
||||||
|
fn ln_ceil(value: usize) -> usize {
|
||||||
|
let idx = LN_CEIL_LOOKUP_TABLE.partition_point(|val| *val <= value);
|
||||||
|
idx.saturating_sub(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_floating_points"))]
|
||||||
|
fn ln_ceil(input: usize) -> usize {
|
||||||
|
(input as f64).ln().ceil() as usize
|
||||||
|
}
|
||||||
|
|
||||||
/// Performs a small multi-exponentiation operation.
|
/// Performs a small multi-exponentiation operation.
|
||||||
/// Uses the double-and-add algorithm with doublings shared across points.
|
/// Uses the double-and-add algorithm with doublings shared across points.
|
||||||
pub fn small_multiexp<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C]) -> C::Curve {
|
pub fn small_multiexp<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C]) -> C::Curve {
|
||||||
|
@ -431,22 +493,52 @@ use rand_core::OsRng;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use crate::pasta::Fp;
|
use crate::pasta::Fp;
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_lagrange_interpolate() {
|
mod tests {
|
||||||
let rng = OsRng;
|
|
||||||
|
|
||||||
let points = (0..5).map(|_| Fp::random(rng)).collect::<Vec<_>>();
|
use super::*;
|
||||||
let evals = (0..5).map(|_| Fp::random(rng)).collect::<Vec<_>>();
|
|
||||||
|
|
||||||
for coeffs in 0..5 {
|
#[test]
|
||||||
let points = &points[0..coeffs];
|
fn test_lagrange_interpolate() {
|
||||||
let evals = &evals[0..coeffs];
|
let rng = OsRng;
|
||||||
|
|
||||||
let poly = lagrange_interpolate(points, evals);
|
let points = (0..5).map(|_| Fp::random(rng)).collect::<Vec<_>>();
|
||||||
assert_eq!(poly.len(), points.len());
|
let evals = (0..5).map(|_| Fp::random(rng)).collect::<Vec<_>>();
|
||||||
|
|
||||||
for (point, eval) in points.iter().zip(evals) {
|
for coeffs in 0..5 {
|
||||||
assert_eq!(eval_polynomial(&poly, *point), *eval);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "no_floating_points")]
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
#[cfg(feature = "no_floating_points")]
|
||||||
|
#[test]
|
||||||
|
fn verify_ln_ceil_lookup_table() {
|
||||||
|
assert_eq!(ln_ceil(LN_CEIL_LOOKUP_TABLE[0]) as usize, 0);
|
||||||
|
assert_eq!(ln_ceil(LN_CEIL_LOOKUP_TABLE[1]) as usize, 1);
|
||||||
|
|
||||||
|
for (exponent, argument) in LN_CEIL_LOOKUP_TABLE.iter().enumerate().skip(2) {
|
||||||
|
assert_eq!(ln_ceil(*argument) as usize, exponent);
|
||||||
|
assert_eq!(ln_ceil(*argument - 1) as usize, exponent - 1);
|
||||||
|
assert_eq!(ln_ceil(*argument + 1) as usize, exponent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "no_floating_points")]
|
||||||
|
proptest! {
|
||||||
|
#[test]
|
||||||
|
fn logarithm_lookup_table_is_correct(exp: usize) {
|
||||||
|
prop_assert_eq!(ln_ceil(exp), (exp as f64).ln().ceil() as usize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue