Skip to content

Commit

Permalink
poseidon-permutation: rewrite for embedded environments
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Apr 1, 2024
1 parent a7810be commit f45ba1a
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 121 deletions.
4 changes: 4 additions & 0 deletions poseidon-parameters/src/arc_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ impl<const N_ROWS: usize, const N_COLS: usize, const N_ELEMENTS: usize>
pub fn transpose(&self) -> ArcMatrix<N_COLS, N_ROWS, N_ELEMENTS> {
ArcMatrix(self.0.transpose())
}

pub fn inner_elements(&self) -> [Fq; N_ELEMENTS] {
self.0.elements
}
}

impl<const N_ROWS: usize, const N_COLS: usize, const N_ELEMENTS: usize> MatrixOperations
Expand Down
1 change: 0 additions & 1 deletion poseidon-parameters/src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ impl<const N_ROWS: usize, const N_COLS: usize, const N_ELEMENTS: usize> MatrixOp
}
}

#[allow(dead_code)]
/// Multiply two `Matrix`
pub fn mat_mul<
const LHS_N_ROWS: usize,
Expand Down
17 changes: 10 additions & 7 deletions poseidon-parameters/src/v1.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
pub use crate::alpha::Alpha;
pub use crate::round_numbers::RoundNumbers;

pub use crate::{matrix::Matrix, matrix::SquareMatrix};

// pub use crate::matrix_ops::mat_mul;

pub use crate::matrix::{mat_mul, square_mat_mul, Matrix, SquareMatrix};
pub use crate::{
arc_matrix::ArcMatrix, arc_matrix::OptimizedArcMatrix, matrix_ops::MatrixOperations,
matrix_ops::SquareMatrixOperations, mds_matrix::MdsMatrix, mds_matrix::OptimizedMdsMatrices,
Expand Down Expand Up @@ -48,7 +45,13 @@ pub struct PoseidonParameters<

/// Optimized round constants.
pub optimized_arc: OptimizedArcMatrix<NUM_ROUND_ROWS, NUM_ROUND_COLS, NUM_ROUND_ELEMENTS>,
// TODO:
// /// Optimized MDS matrices.
//pub optimized_mds: OptimizedMdsMatrices,

/// Optimized MDS matrices.
pub optimized_mds: OptimizedMdsMatrices<
NUM_ROUND_ROWS,
STATE_SIZE,
STATE_SIZE_MINUS_1,
NUM_MDS_ELEMENTS,
NUM_STATE_SIZE_MINUS_1_ELEMENTS,
>,
}
6 changes: 2 additions & 4 deletions poseidon-paramgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "poseidon-paramgen"
version = "0.4.0"
edition = "2018"
authors = ["Penumbra <[email protected]>", "redshiftzero <[email protected]>"]
description = "A crate for generating Poseidon parameters"
description = "A crate for generating Poseidon parameters for decaf377"
license = "MIT OR Apache-2.0"
repository = "https://github.com/penumbra-zone/poseidon377"

Expand All @@ -20,9 +20,7 @@ rand_core = { version = "0.6.3", default-features = false, features = ["getrando
poseidon-parameters = { path = "../poseidon-parameters", default-features = false, version = "1.0" }

[dev-dependencies]
ark-bn254 = "0.4"
ark-ed-on-bls12-377 = "0.4"
ark-ed-on-bls12-381 = "0.4"
decaf377 = "0.8"

[features]
default = ["std"]
Expand Down
1 change: 0 additions & 1 deletion poseidon-paramgen/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub fn generate<F: PrimeField>(

PoseidonParameters::<F> {
M: input.M,
t: input.t,
alpha,
rounds,
mds,
Expand Down
2 changes: 0 additions & 2 deletions poseidon-paramgen/src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub fn generate<F: PrimeField>(
if t < 4 {
PoseidonParameters::<F> {
M: input.M,
t: input.t,
alpha,
rounds,
arc,
Expand All @@ -44,7 +43,6 @@ pub fn generate<F: PrimeField>(
let m_e = external::generate(t);
PoseidonParameters::<F> {
M: input.M,
t: input.t,
alpha,
rounds,
arc,
Expand Down
2 changes: 1 addition & 1 deletion poseidon-paramgen/src/v2/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn generate<F: PrimeField>(t: usize) -> SquareMatrix<F> {

#[cfg(test)]
mod tests {
use ark_ed_on_bls12_377::Fq;
use decaf377::Fq;

use super::*;

Expand Down
9 changes: 5 additions & 4 deletions poseidon-permutation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ name = "poseidon-permutation"
version = "1.0.0"
edition = "2018"
authors = ["Penumbra <[email protected]>", "redshiftzero <[email protected]>"]
description = "An instantiation of the Poseidon permutation"
description = "An instantiation of the Poseidon permutation for decaf377"
license = "MIT OR Apache-2.0"
repository = "https://github.com/penumbra-zone/poseidon377"

[dependencies]
ark-ff = { version = "0.4", default-features = false }
ark-std = { version = "^0.4.0", default-features = false }
decaf377 = { version="0.8", default-features = false }
ark-ff = { version = "0.4", default-features = false, optional=true }
ark-std = { version = "^0.4.0", default-features = false, optional=true }
ark-r1cs-std = {version = "0.4", default-features = false, optional=true }
ark-relations = { version="0.4", default-features = false, optional=true }

poseidon-parameters = { path = "../poseidon-parameters", default-features = false, version = "1.0" }

[features]
default = ["std"]
r1cs = ["ark-r1cs-std", "ark-relations"]
r1cs = ["std", "ark-ff/std", "ark-r1cs-std", "ark-relations", "decaf377/r1cs"]
std = [
"ark-ff/std",
"ark-std/std",
Expand Down
Loading

0 comments on commit f45ba1a

Please sign in to comment.