From 475297406dc387222a40fd7aa803db1466f59081 Mon Sep 17 00:00:00 2001 From: Sinka Date: Tue, 7 May 2024 15:03:11 +0800 Subject: [PATCH 1/5] add get_state api --- src/matrix.rs | 1 - src/poseidon.rs | 5 +++++ src/spec.rs | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/matrix.rs b/src/matrix.rs index 9207835..e3593ae 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -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)] diff --git a/src/poseidon.rs b/src/poseidon.rs index 163c1fe..cc0f90b 100644 --- a/src/poseidon.rs +++ b/src/poseidon.rs @@ -26,6 +26,11 @@ impl Poseidon { self.absorbing = Vec::new(); } + /// get the internal state spec + pub fn get_state(&self) -> State { + self.state.clone() + } + /// Update n = RATE elements /// This assumes the current absorbing list is empty pub fn update_exact(&mut self, elements: &[F; RATE]) -> F { diff --git a/src/spec.rs b/src/spec.rs index 01a91e8..e78a9d7 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -397,8 +397,8 @@ impl Spec { #[cfg(test)] pub(super) mod tests { - -use halo2_proofs::arithmetic::FieldExt; + + use halo2_proofs::arithmetic::FieldExt; use super::MDSMatrix; use crate::grain::Grain; From 162fc28c2c1fa361d0851a1f50c3e9c2c65c0042 Mon Sep 17 00:00:00 2001 From: Sinka Date: Tue, 7 May 2024 15:39:42 +0800 Subject: [PATCH 2/5] expose the internal data of spec state --- src/poseidon.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/poseidon.rs b/src/poseidon.rs index cc0f90b..8195bab 100644 --- a/src/poseidon.rs +++ b/src/poseidon.rs @@ -27,8 +27,8 @@ impl Poseidon { } /// get the internal state spec - pub fn get_state(&self) -> State { - self.state.clone() + pub fn get_state(&self) -> [F; T] { + self.state.0.clone() } /// Update n = RATE elements From 2753c0837c14c89af43e823b1bc992ab01174ce4 Mon Sep 17 00:00:00 2001 From: mooreland Date: Mon, 2 Sep 2024 09:25:05 +0800 Subject: [PATCH 3/5] add rc to spec --- src/poseidon.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/poseidon.rs b/src/poseidon.rs index 8195bab..fb30f18 100644 --- a/src/poseidon.rs +++ b/src/poseidon.rs @@ -1,12 +1,13 @@ use crate::{Spec, State}; use halo2_proofs::arithmetic::FieldExt; +use std::rc::Rc; /// Poseidon hasher that maintains state and inputs and yields single element /// output when desired #[derive(Debug, Clone)] pub struct Poseidon { state: State, - spec: Spec, + spec: Rc>, absorbing: Vec, } @@ -14,7 +15,7 @@ impl Poseidon { /// 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: Rc::new(Spec::new(r_f, r_p)), state: State::default(), absorbing: Vec::new(), } @@ -26,6 +27,11 @@ impl Poseidon { self.absorbing = Vec::new(); } + /// return share spec + pub fn get_spec(&self) -> Rc> { + self.spec.clone() + } + /// get the internal state spec pub fn get_state(&self) -> [F; T] { self.state.0.clone() From 5fc311dbade3758bb76b7afddd445bb89c918cc3 Mon Sep 17 00:00:00 2001 From: mooreland Date: Mon, 2 Sep 2024 10:44:14 +0800 Subject: [PATCH 4/5] add toolchain --- rust-toolchain | 1 + 1 file changed, 1 insertion(+) create mode 100644 rust-toolchain diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..d309aeb --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly-2023-06-01 \ No newline at end of file From 03fa2101409dee9f2b7a70c2295a9c5f19a025d5 Mon Sep 17 00:00:00 2001 From: mooreland Date: Tue, 3 Sep 2024 10:22:23 +0800 Subject: [PATCH 5/5] replace rc to arc --- src/poseidon.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/poseidon.rs b/src/poseidon.rs index fb30f18..99aed04 100644 --- a/src/poseidon.rs +++ b/src/poseidon.rs @@ -1,13 +1,13 @@ use crate::{Spec, State}; use halo2_proofs::arithmetic::FieldExt; -use std::rc::Rc; +use std::sync::Arc; /// Poseidon hasher that maintains state and inputs and yields single element /// output when desired #[derive(Debug, Clone)] pub struct Poseidon { state: State, - spec: Rc>, + spec: Arc>, absorbing: Vec, } @@ -15,7 +15,7 @@ impl Poseidon { /// Constructs a clear state poseidon instance pub fn new(r_f: usize, r_p: usize) -> Self { Self { - spec: Rc::new(Spec::new(r_f, r_p)), + spec: Arc::new(Spec::new(r_f, r_p)), state: State::default(), absorbing: Vec::new(), } @@ -28,7 +28,7 @@ impl Poseidon { } /// return share spec - pub fn get_spec(&self) -> Rc> { + pub fn get_spec(&self) -> Arc> { self.spec.clone() }