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

halo2_poseidon: Add no-std support #834

Merged
merged 1 commit into from
Dec 16, 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
4 changes: 2 additions & 2 deletions halo2_poseidon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ readme = "README.md"
categories = ["cryptography"]

[dependencies]
bitvec = "1"
ff = "0.13"
bitvec = { version = "1", default-features = false }
ff = { version = "0.13", default-features = false }
group = "0.13"
pasta_curves = "0.5"

Expand Down
2 changes: 1 addition & 1 deletion halo2_poseidon/src/grain.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The Grain LFSR in self-shrinking mode, as used by Poseidon.

use std::marker::PhantomData;
use core::marker::PhantomData;

use bitvec::prelude::*;
use group::ff::{Field, FromUniformBytes, PrimeField};
Expand Down Expand Up @@ -69,7 +69,7 @@
let mut grain = Grain {
state,
next_bit: STATE,
_field: PhantomData::default(),

Check warning on line 72 in halo2_poseidon/src/grain.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_poseidon/src/grain.rs:72:32 | 72 | _field: 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 72 in halo2_poseidon/src/grain.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_poseidon/src/grain.rs:72:32 | 72 | _field: 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)]`
};

// Discard the first 160 bits.
Expand Down
15 changes: 11 additions & 4 deletions halo2_poseidon/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
//! The Poseidon algebraic hash function.

use std::convert::TryInto;
use std::fmt;
use std::iter;
use std::marker::PhantomData;
#![no_std]

#[macro_use]
extern crate alloc;

use alloc::string::String;
use alloc::vec::Vec;
use core::convert::TryInto;
use core::fmt;
use core::iter;
use core::marker::PhantomData;

use group::ff::{Field, FromUniformBytes, PrimeField};

Expand Down Expand Up @@ -295,7 +302,7 @@
state,
mds_matrix,
round_constants,
_marker: PhantomData::default(),

Check warning on line 305 in halo2_poseidon/src/lib.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_poseidon/src/lib.rs:305:33 | 305 | _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

Check warning on line 305 in halo2_poseidon/src/lib.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_poseidon/src/lib.rs:305:33 | 305 | _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 Down Expand Up @@ -332,7 +339,7 @@
state: self.state,
mds_matrix: self.mds_matrix,
round_constants: self.round_constants,
_marker: PhantomData::default(),

Check warning on line 342 in halo2_poseidon/src/lib.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_poseidon/src/lib.rs:342:33 | 342 | _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

Check warning on line 342 in halo2_poseidon/src/lib.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_poseidon/src/lib.rs:342:33 | 342 | _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 Down Expand Up @@ -438,7 +445,7 @@
pub fn init() -> Self {
Hash {
sponge: Sponge::new(D::initial_capacity_element()),
_domain: PhantomData::default(),

Check warning on line 448 in halo2_poseidon/src/lib.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_poseidon/src/lib.rs:448:33 | 448 | _domain: 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

Check warning on line 448 in halo2_poseidon/src/lib.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_poseidon/src/lib.rs:448:33 | 448 | _domain: 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 Down
2 changes: 2 additions & 0 deletions halo2_poseidon/src/mds.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::vec::Vec;

use ff::FromUniformBytes;

use super::{grain::Grain, Mds};
Expand Down
6 changes: 5 additions & 1 deletion halo2_poseidon/src/p128pow5t3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::vec::Vec;

use ff::Field;
use pasta_curves::{pallas::Base as Fp, vesta::Base as Fq};

Expand Down Expand Up @@ -66,8 +68,10 @@

#[cfg(test)]
mod tests {
use alloc::vec::Vec;
use core::marker::PhantomData;

use ff::{Field, FromUniformBytes, PrimeField};
use std::marker::PhantomData;

use super::{
super::{fp, fq},
Expand All @@ -83,7 +87,7 @@
impl<F: Field, const SECURE_MDS: usize> P128Pow5T3Gen<F, SECURE_MDS> {
#![allow(dead_code)]
pub fn new() -> Self {
P128Pow5T3Gen(PhantomData::default())

Check warning on line 90 in halo2_poseidon/src/p128pow5t3.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_poseidon/src/p128pow5t3.rs:90:38 | 90 | P128Pow5T3Gen(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 Down
2 changes: 2 additions & 0 deletions halo2_poseidon/src/test_vectors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Test vectors for [`OrchardNullifier`].

Check warning on line 1 in halo2_poseidon/src/test_vectors.rs

View workflow job for this annotation

GitHub Actions / Intra-doc links

unresolved link to `OrchardNullifier`

Check warning on line 1 in halo2_poseidon/src/test_vectors.rs

View workflow job for this annotation

GitHub Actions / Intra-doc links

unresolved link to `OrchardNullifier`

use alloc::vec::Vec;

pub struct PermuteTestVector {
pub initial_state: [[u8; 32]; 3],
pub final_state: [[u8; 32]; 3],
Expand Down
Loading