Skip to content
Open
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
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2023-06-01
1 change: 0 additions & 1 deletion src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! with the intention of construction of parameters and are not used in the
//! actual permutation process.


use halo2_proofs::arithmetic::FieldExt;

#[derive(PartialEq, Debug, Clone)]
Expand Down
15 changes: 13 additions & 2 deletions src/poseidon.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
use crate::{Spec, State};
use halo2_proofs::arithmetic::FieldExt;
use std::sync::Arc;

/// Poseidon hasher that maintains state and inputs and yields single element
/// output when desired
#[derive(Debug, Clone)]
pub struct Poseidon<F: FieldExt, const T: usize, const RATE: usize> {
state: State<F, T>,
spec: Spec<F, T, RATE>,
spec: Arc<Spec<F, T, RATE>>,
absorbing: Vec<F>,
}

impl<F: FieldExt, const T: usize, const RATE: usize> Poseidon<F, T, RATE> {
/// Constructs a clear state poseidon instance
pub fn new(r_f: usize, r_p: usize) -> Self {
Self {
spec: Spec::new(r_f, r_p),
spec: Arc::new(Spec::new(r_f, r_p)),
state: State::default(),
absorbing: Vec::new(),
}
Expand All @@ -26,6 +27,16 @@ impl<F: FieldExt, const T: usize, const RATE: usize> Poseidon<F, T, RATE> {
self.absorbing = Vec::new();
}

/// return share spec
pub fn get_spec(&self) -> Arc<Spec<F, T, RATE>> {
self.spec.clone()
}

/// get the internal state spec
pub fn get_state(&self) -> [F; T] {
self.state.0.clone()
}

/// Update n = RATE elements
/// This assumes the current absorbing list is empty
pub fn update_exact(&mut self, elements: &[F; RATE]) -> F {
Expand Down
4 changes: 2 additions & 2 deletions src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ impl<F: FieldExt, const T: usize, const RATE: usize> Spec<F, T, RATE> {

#[cfg(test)]
pub(super) mod tests {
use halo2_proofs::arithmetic::FieldExt;

use halo2_proofs::arithmetic::FieldExt;

use super::MDSMatrix;
use crate::grain::Grain;
Expand Down