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

upstream update #34

Open
wants to merge 24 commits into
base: zsa1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3eb4ec5
Change Daira Emma's name in `authors` fields.
daira Nov 21, 2023
de1d237
Revert "Add book/Makefile for local HTML generation."
daira Nov 21, 2023
2e617ae
Add `/book/book` to `.gitignore`.
daira Nov 21, 2023
ae52332
Merge pull request #802 from daira/book-remove-makefile
daira Dec 19, 2023
4a8e640
Remove references to the empty `halo2` crate from the README, and link
daira Feb 6, 2024
81729ec
Merge pull request #809 from daira/remove-empty-halo2-crate-from-readme
daira Feb 6, 2024
daaa638
fix(mdbook): fix generation
Feb 22, 2024
7df93fd
Merge pull request #814 from adria0/fix/mdbook
daira Feb 26, 2024
ef54bff
halo2_poseidon: Initial empty library crate
str4d Dec 13, 2024
94cf956
Merge pull request #830 from zcash/halo2_poseidon-empty-crate
str4d Dec 13, 2024
19a9f2e
Move Sinsemilla primitive impl into `sinsemilla` crate
str4d Dec 13, 2024
7a39f55
Merge pull request #829 from zcash/sinsemilla-primitive
str4d Dec 14, 2024
00b87a8
CI: Disable fail-fast for main test job
str4d Dec 16, 2024
b672cee
Bump pinned `aho-corasick` to 1.1.3
str4d Dec 16, 2024
0d1851b
Merge pull request #833 from zcash/fix-ci
str4d Dec 16, 2024
70d36ef
halo2_poseidon: Remove empty `lib.rs` file
str4d Dec 16, 2024
afa6713
Move Poseidon primitive into `halo2_poseidon`
str4d Dec 16, 2024
5893850
halo2_poseidon: Refactor code so it compiles in its new crate
str4d Dec 16, 2024
c91cc5c
Merge pull request #831 from zcash/poseidon-primitive
str4d Dec 16, 2024
e6897ef
halo2_poseidon: Add no-std support
str4d Dec 16, 2024
e374954
Merge pull request #834 from zcash/poseidon-no-std
str4d Dec 16, 2024
f066ace
halo2_poseidon 0.1.0
str4d Dec 16, 2024
3bb6f5c
halo2_gadgets 0.3.1
str4d Dec 16, 2024
fed6b00
Merge pull request #835 from zcash/halo2_poseidon-0.1.0
str4d Dec 16, 2024
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
9 changes: 7 additions & 2 deletions .github/workflows/book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jobs:
name: Test on ${{ matrix.os }}${{ matrix.name_suffix }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
stage: [stable, beta, nightly]
os: [ubuntu-latest, windows-latest, macOS-latest]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
**/.*.swp
**/*.rs.bk
.vscode
**/*.html
.DS_Store
/book/book
29 changes: 26 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
members = [
"halo2",
"halo2_gadgets",
"halo2_poseidon",
"halo2_proofs",
]
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 0 additions & 10 deletions book/Makefile

This file was deleted.

4 changes: 1 addition & 3 deletions book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = [
"Jack Grigg",
"Sean Bowe",
"Daira Hopwood",
"Daira Emma Hopwood",
"Ying Tong Lai",
]
language = "en"
Expand All @@ -14,8 +14,6 @@ title = "The halo2 Book"
macros = "macros.txt"
renderers = ["html"]

[output.katex]

[output.html]

[output.html.print]
Expand Down
28 changes: 0 additions & 28 deletions book/edithtml.sh

This file was deleted.

6 changes: 6 additions & 0 deletions halo2_gadgets/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to Rust's notion of

## [Unreleased]

## [0.3.1] - 2024-12-16
- `halo2_gadgets::poseidon::primitives` is now a re-export of the new `halo2_poseidon`
crate.
- `halo2_gadgets::sinsemilla::primitives` is now a re-export of the new `sinsemilla`
crate.

## [0.3.0] - 2023-03-21
### Added
- `halo2_gadgets::poseidon::primitives::{Mds, generate_constants}`
Expand Down
13 changes: 10 additions & 3 deletions halo2_gadgets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "halo2_gadgets"
version = "0.3.0"
version = "0.3.1"
authors = [
"Sean Bowe <[email protected]>",
"Jack Grigg <[email protected]>",
"Daira Hopwood <[email protected]>",
"Daira Emma Hopwood <[email protected]>",
"Ying Tong Lai <[email protected]>",
"Kris Nuttycombe <[email protected]>",
]
Expand All @@ -26,11 +26,13 @@ arrayvec = "0.7.0"
bitvec = "1"
ff = "0.13"
group = "0.13"
halo2_poseidon = { version = "0.1", path = "../halo2_poseidon", default-features = false }
halo2_proofs = { version = "0.3", path = "../halo2_proofs", default-features = false }
lazy_static = "1"
pasta_curves = "0.5"
proptest = { version = "1.0.0", optional = true }
rand = "0.8"
sinsemilla = "0.1"
subtle = "2.3"
uint = "0.9.2" # MSRV 1.56.1

Expand All @@ -39,7 +41,9 @@ plotters = { version = "0.3.0", default-features = false, optional = true }

[dev-dependencies]
criterion = "0.3"
halo2_poseidon = { version = "0.1", path = "../halo2_poseidon", default-features = false, features = ["test-dependencies"] }
proptest = "1.0.0"
sinsemilla = { version = "0.1", features = ["test-dependencies"] }

[target.'cfg(unix)'.dev-dependencies]
inferno = ">=0.11, <0.11.5" # MSRV 1.59
Expand All @@ -56,7 +60,10 @@ test-dev-graph = [
"plotters/bitmap_encoder",
"plotters/ttf",
]
test-dependencies = ["proptest"]
test-dependencies = [
"proptest",
"sinsemilla/test-dependencies",
]

# In-development features
# See https://zcash.github.io/halo2/dev/features.html
Expand Down
30 changes: 10 additions & 20 deletions halo2_gadgets/src/poseidon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! The Poseidon algebraic hash function.

use std::convert::TryInto;
use std::fmt;
use std::marker::PhantomData;

Expand All @@ -13,7 +12,7 @@
mod pow5;
pub use pow5::{Pow5Chip, Pow5Config, StateWord};

pub mod primitives;
pub use ::halo2_poseidon as primitives;
use primitives::{Absorbing, ConstantLength, Domain, Spec, SpongeMode, Squeezing, State};

/// A word from the padded input to a Poseidon sponge.
Expand Down Expand Up @@ -148,15 +147,9 @@
pub fn new(chip: PoseidonChip, mut layouter: impl Layouter<F>) -> Result<Self, Error> {
chip.initial_state(&mut layouter).map(|state| Sponge {
chip,
mode: Absorbing(
(0..RATE)
.map(|_| None)
.collect::<Vec<_>>()
.try_into()
.unwrap(),
),
mode: Absorbing::init_empty(),
state,
_marker: PhantomData::default(),

Check warning on line 152 in halo2_gadgets/src/poseidon.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

use of `default` to create a unit struct

warning: use of `default` to create a unit struct --> halo2_gadgets/src/poseidon.rs:152:33 | 152 | _marker: PhantomData::default(), | ^^^^^^^^^^^ help: remove this call to `default` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_constructed_unit_structs = note: `-W clippy::default-constructed-unit-structs` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::default_constructed_unit_structs)]`

Check warning on line 152 in halo2_gadgets/src/poseidon.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

use of `default` to create a unit struct

warning: use of `default` to create a unit struct --> halo2_gadgets/src/poseidon.rs:152:33 | 152 | _marker: PhantomData::default(), | ^^^^^^^^^^^ help: remove this call to `default` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_constructed_unit_structs = note: `-W clippy::default-constructed-unit-structs` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::default_constructed_unit_structs)]`
})
}

Expand All @@ -166,12 +159,10 @@
mut layouter: impl Layouter<F>,
value: PaddedWord<F>,
) -> Result<(), Error> {
for entry in self.mode.0.iter_mut() {
if entry.is_none() {
*entry = Some(value);
return Ok(());
}
}
let value = match self.mode.absorb(value) {
Ok(()) => return Ok(()),
Err(value) => value,
};

// We've already absorbed as many elements as we can
let _ = poseidon_sponge(
Expand All @@ -180,7 +171,8 @@
&mut self.state,
Some(&self.mode),
)?;
self.mode = Absorbing::init_with(value);
self.mode = Absorbing::init_empty();
self.mode.absorb(value).expect("state is not full");

Ok(())
}
Expand All @@ -203,7 +195,7 @@
chip: self.chip,
mode,
state: self.state,
_marker: PhantomData::default(),

Check warning on line 198 in halo2_gadgets/src/poseidon.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

use of `default` to create a unit struct

warning: use of `default` to create a unit struct --> halo2_gadgets/src/poseidon.rs:198:33 | 198 | _marker: PhantomData::default(), | ^^^^^^^^^^^ help: remove this call to `default` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_constructed_unit_structs
})
}
}
Expand All @@ -220,10 +212,8 @@
/// Squeezes an element from the sponge.
pub fn squeeze(&mut self, mut layouter: impl Layouter<F>) -> Result<AssignedCell<F, F>, Error> {
loop {
for entry in self.mode.0.iter_mut() {
if let Some(inner) = entry.take() {
return Ok(inner.into());
}
if let Some(value) = self.mode.squeeze() {
return Ok(value.into());
}

// We've already squeezed out all available elements
Expand Down
28 changes: 14 additions & 14 deletions halo2_gadgets/src/poseidon/pow5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,31 +238,31 @@
// Load the initial state into this region.
let state = Pow5State::load(&mut region, config, initial_state)?;

let state = (0..config.half_full_rounds).fold(Ok(state), |res, r| {
res.and_then(|state| state.full_round(&mut region, config, r, r))
})?;

Check warning on line 243 in halo2_gadgets/src/poseidon/pow5.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

usage of `Iterator::fold` on a type that implements `Try`

warning: usage of `Iterator::fold` on a type that implements `Try` --> halo2_gadgets/src/poseidon/pow5.rs:241:58 | 241 | let state = (0..config.half_full_rounds).fold(Ok(state), |res, r| { | __________________________________________________________^ 242 | | res.and_then(|state| state.full_round(&mut region, config, r, r)) 243 | | })?; | |__________________^ help: use `try_fold` instead: `try_fold(state, |res, r| ...)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold = note: `-W clippy::manual-try-fold` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::manual_try_fold)]`

let state = (0..config.half_partial_rounds).fold(Ok(state), |res, r| {
res.and_then(|state| {
state.partial_round(
&mut region,
config,
config.half_full_rounds + 2 * r,
config.half_full_rounds + r,
)
})
})?;

Check warning on line 254 in halo2_gadgets/src/poseidon/pow5.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

usage of `Iterator::fold` on a type that implements `Try`

warning: usage of `Iterator::fold` on a type that implements `Try` --> halo2_gadgets/src/poseidon/pow5.rs:245:61 | 245 | let state = (0..config.half_partial_rounds).fold(Ok(state), |res, r| { | _____________________________________________________________^ 246 | | res.and_then(|state| { 247 | | state.partial_round( 248 | | &mut region, ... | 253 | | }) 254 | | })?; | |__________________^ help: use `try_fold` instead: `try_fold(state, |res, r| ...)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold

Check warning on line 254 in halo2_gadgets/src/poseidon/pow5.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

usage of `Iterator::fold` on a type that implements `Try`

warning: usage of `Iterator::fold` on a type that implements `Try` --> halo2_gadgets/src/poseidon/pow5.rs:245:61 | 245 | let state = (0..config.half_partial_rounds).fold(Ok(state), |res, r| { | _____________________________________________________________^ 246 | | res.and_then(|state| { 247 | | state.partial_round( 248 | | &mut region, ... | 253 | | }) 254 | | })?; | |__________________^ help: use `try_fold` instead: `try_fold(state, |res, r| ...)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold

let state = (0..config.half_full_rounds).fold(Ok(state), |res, r| {
res.and_then(|state| {
state.full_round(
&mut region,
config,
config.half_full_rounds + 2 * config.half_partial_rounds + r,
config.half_full_rounds + config.half_partial_rounds + r,
)
})
})?;

Check warning on line 265 in halo2_gadgets/src/poseidon/pow5.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

usage of `Iterator::fold` on a type that implements `Try`

warning: usage of `Iterator::fold` on a type that implements `Try` --> halo2_gadgets/src/poseidon/pow5.rs:256:58 | 256 | let state = (0..config.half_full_rounds).fold(Ok(state), |res, r| { | __________________________________________________________^ 257 | | res.and_then(|state| { 258 | | state.full_round( 259 | | &mut region, ... | 264 | | }) 265 | | })?; | |__________________^ help: use `try_fold` instead: `try_fold(state, |res, r| ...)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold

Check warning on line 265 in halo2_gadgets/src/poseidon/pow5.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

usage of `Iterator::fold` on a type that implements `Try`

warning: usage of `Iterator::fold` on a type that implements `Try` --> halo2_gadgets/src/poseidon/pow5.rs:256:58 | 256 | let state = (0..config.half_full_rounds).fold(Ok(state), |res, r| { | __________________________________________________________^ 257 | | res.and_then(|state| { 258 | | state.full_round( 259 | | &mut region, ... | 264 | | }) 265 | | })?; | |__________________^ help: use `try_fold` instead: `try_fold(state, |res, r| ...)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold

Ok(state.0)
},
Expand Down Expand Up @@ -340,19 +340,20 @@
let initial_state = initial_state?;

// Load the input into this region.
let load_input_word = |i: usize| {
let (cell, value) = match input.0[i].clone() {
let load_input_word = |(i, input_word): (usize, &Option<PaddedWord<F>>)| {
let (cell, value) = match input_word {
Some(PaddedWord::Message(word)) => (word.cell(), word.value().copied()),
Some(PaddedWord::Padding(padding_value)) => {
let value = Value::known(*padding_value);
let cell = region
.assign_fixed(
|| format!("load pad_{}", i),
config.rc_b[i],
1,
|| Value::known(padding_value),
|| value,
)?
.cell();
(cell, Value::known(padding_value))
(cell, value)
}
_ => panic!("Input is not padded"),
};
Expand All @@ -366,7 +367,12 @@

Ok(StateWord(var))
};
let input: Result<Vec<_>, Error> = (0..RATE).map(load_input_word).collect();
let input: Result<Vec<_>, Error> = input
.expose_inner()
.iter()
.enumerate()
.map(load_input_word)
.collect();
let input = input?;

// Constrain the output.
Expand Down Expand Up @@ -394,14 +400,8 @@
}

fn get_output(state: &State<Self::Word, WIDTH>) -> Squeezing<Self::Word, RATE> {
Squeezing(
state[..RATE]
.iter()
.map(|word| Some(word.clone()))
.collect::<Vec<_>>()
.try_into()
.unwrap(),
)
let vals = state[..RATE].to_vec();
Squeezing::init_full(vals.try_into().expect("correct length"))
}
}

Expand Down Expand Up @@ -448,7 +448,7 @@
.value()
.map(|v| *v + config.round_constants[round][idx])
});
let r: Value<Vec<F>> = q.map(|q| q.map(|q| q.pow(&config.alpha))).collect();

Check warning on line 451 in halo2_gadgets/src/poseidon/pow5.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> halo2_gadgets/src/poseidon/pow5.rs:451:62 | 451 | let r: Value<Vec<F>> = q.map(|q| q.map(|q| q.pow(&config.alpha))).collect(); | ^^^^^^^^^^^^^ help: change this to: `config.alpha` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 451 in halo2_gadgets/src/poseidon/pow5.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> halo2_gadgets/src/poseidon/pow5.rs:451:62 | 451 | let r: Value<Vec<F>> = q.map(|q| q.map(|q| q.pow(&config.alpha))).collect(); | ^^^^^^^^^^^^^ help: change this to: `config.alpha` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
let m = &config.m_reg;
let state = m.iter().map(|m_i| {
r.as_ref().map(|r| {
Expand All @@ -474,7 +474,7 @@
let p: Value<Vec<_>> = self.0.iter().map(|word| word.0.value().cloned()).collect();

let r: Value<Vec<_>> = p.map(|p| {
let r_0 = (p[0] + config.round_constants[round][0]).pow(&config.alpha);

Check warning on line 477 in halo2_gadgets/src/poseidon/pow5.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> halo2_gadgets/src/poseidon/pow5.rs:477:73 | 477 | let r_0 = (p[0] + config.round_constants[round][0]).pow(&config.alpha); | ^^^^^^^^^^^^^ help: change this to: `config.alpha` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 477 in halo2_gadgets/src/poseidon/pow5.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> halo2_gadgets/src/poseidon/pow5.rs:477:73 | 477 | let r_0 = (p[0] + config.round_constants[round][0]).pow(&config.alpha); | ^^^^^^^^^^^^^ help: change this to: `config.alpha` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
let r_i = p[1..]
.iter()
.enumerate()
Expand Down Expand Up @@ -514,7 +514,7 @@
}

let r_mid: Value<Vec<_>> = p_mid.map(|p| {
let r_0 = (p[0] + config.round_constants[round + 1][0]).pow(&config.alpha);

Check warning on line 517 in halo2_gadgets/src/poseidon/pow5.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> halo2_gadgets/src/poseidon/pow5.rs:517:77 | 517 | let r_0 = (p[0] + config.round_constants[round + 1][0]).pow(&config.alpha); | ^^^^^^^^^^^^^ help: change this to: `config.alpha` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 517 in halo2_gadgets/src/poseidon/pow5.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> halo2_gadgets/src/poseidon/pow5.rs:517:77 | 517 | let r_0 = (p[0] + config.round_constants[round + 1][0]).pow(&config.alpha); | ^^^^^^^^^^^^^ help: change this to: `config.alpha` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
let r_i = p[1..]
.iter()
.enumerate()
Expand Down Expand Up @@ -687,7 +687,7 @@
.try_into()
.unwrap();
let (round_constants, mds, _) = S::constants();
poseidon::permute::<_, S, WIDTH, RATE>(
poseidon::test_only_permute::<_, S, WIDTH, RATE>(
&mut expected_final_state,
&mds,
&round_constants,
Expand Down
Loading
Loading