Skip to content

Commit

Permalink
Merge branch 'main' into improve-backward-compatability-without-zsa
Browse files Browse the repository at this point in the history
  • Loading branch information
ConstanceBeguier committed Jan 27, 2025
2 parents 7ed444a + fed6b00 commit ed043bd
Show file tree
Hide file tree
Showing 30 changed files with 272 additions and 14,844 deletions.
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
25 changes: 24 additions & 1 deletion 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 @@ use halo2_proofs::{
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,13 +147,7 @@ impl<
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)]`
})
Expand All @@ -166,12 +159,10 @@ impl<
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 @@ impl<
&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 Down Expand Up @@ -220,10 +212,8 @@ impl<
/// 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 @@ -340,19 +340,20 @@ impl<
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 @@ impl<

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 @@ impl<
}

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 @@ -687,7 +687,7 @@ mod tests {
.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
3 changes: 2 additions & 1 deletion halo2_gadgets/src/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use std::fmt::Debug;
pub mod chip;
pub mod merkle;
mod message;
pub mod primitives;

pub use ::sinsemilla as primitives;

/// The set of circuit instructions required to use the [`Sinsemilla`](https://zcash.github.io/halo2/design/gadgets/sinsemilla.html) gadget.
/// This trait is bounded on two constant parameters: `K`, the number of bits
Expand Down
Loading

0 comments on commit ed043bd

Please sign in to comment.