Skip to content

Commit 14e277b

Browse files
authored
Merge pull request #24 from leanEthereum/make-stuff-public
make some stuff public
2 parents df408bf + 0ccadec commit 14e277b

File tree

8 files changed

+44
-10
lines changed

8 files changed

+44
-10
lines changed

src/inc_encoding/target_sum.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub enum TargetSumError {
2424
/// const MAX_CHUNK_VALUE: usize = MH::BASE - 1
2525
/// const EXPECTED_SUM: usize = MH::DIMENSION * MAX_CHUNK_VALUE / 2
2626
/// ```
27+
#[derive(Clone)]
2728
pub struct TargetSumEncoding<MH: MessageHash, const TARGET_SUM: usize> {
2829
_marker_mh: std::marker::PhantomData<MH>,
2930
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(crate) mod inc_encoding;
2020
pub mod serialization;
2121
pub mod signature;
2222
pub(crate) mod simd_utils;
23-
pub(crate) mod symmetric;
23+
pub mod symmetric;
2424

2525
// Cached Poseidon2 permutations.
2626
//

src/signature/generalized_xmss.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,28 @@ pub struct GeneralizedXMSSSignatureScheme<
4040

4141
/// Signature for GeneralizedXMSSSignatureScheme
4242
/// It contains a Merkle authentication path, encoding randomness, and a list of hashes
43-
#[derive(Serialize, Deserialize)]
43+
#[derive(Serialize, Deserialize, Clone)]
4444
#[serde(bound = "")]
4545
pub struct GeneralizedXMSSSignature<IE: IncomparableEncoding, TH: TweakableHash> {
4646
path: HashTreeOpening<TH>,
4747
rho: IE::Randomness,
4848
hashes: Vec<TH::Domain>,
4949
}
5050

51+
impl<IE: IncomparableEncoding, TH: TweakableHash> GeneralizedXMSSSignature<IE, TH> {
52+
pub const fn path(&self) -> &HashTreeOpening<TH> {
53+
&self.path
54+
}
55+
56+
pub const fn rho(&self) -> &IE::Randomness {
57+
&self.rho
58+
}
59+
60+
pub const fn hashes(&self) -> &Vec<TH::Domain> {
61+
&self.hashes
62+
}
63+
}
64+
5165
impl<IE: IncomparableEncoding, TH: TweakableHash> Encode for GeneralizedXMSSSignature<IE, TH> {
5266
fn is_ssz_fixed_len() -> bool {
5367
false
@@ -174,12 +188,22 @@ impl<IE: IncomparableEncoding, TH: TweakableHash> Decode for GeneralizedXMSSSign
174188

175189
/// Public key for GeneralizedXMSSSignatureScheme
176190
/// It contains a Merkle root and a parameter for the tweakable hash
177-
#[derive(Serialize, Deserialize)]
191+
#[derive(Serialize, Deserialize, Clone)]
178192
pub struct GeneralizedXMSSPublicKey<TH: TweakableHash> {
179193
root: TH::Domain,
180194
parameter: TH::Parameter,
181195
}
182196

197+
impl<TH: TweakableHash> GeneralizedXMSSPublicKey<TH> {
198+
pub const fn root(&self) -> &TH::Domain {
199+
&self.root
200+
}
201+
202+
pub const fn parameter(&self) -> &TH::Parameter {
203+
&self.parameter
204+
}
205+
}
206+
183207
/// Secret key for GeneralizedXMSSSignatureScheme
184208
/// It contains a PRF key and a Merkle tree.
185209
///

src/signature/generalized_xmss/instantiations_poseidon_top_level.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ pub mod lifetime_2_to_the_32 {
8686

8787
use crate::{
8888
inc_encoding::target_sum::TargetSumEncoding,
89-
signature::generalized_xmss::GeneralizedXMSSSignatureScheme,
89+
signature::generalized_xmss::{
90+
GeneralizedXMSSPublicKey, GeneralizedXMSSSignature, GeneralizedXMSSSignatureScheme,
91+
},
9092
symmetric::{
9193
message_hash::top_level_poseidon::TopLevelPoseidonMessageHash,
9294
prf::shake_to_field::ShakePRFtoF, tweak_hash::poseidon::PoseidonTweakHash,
@@ -101,18 +103,18 @@ pub mod lifetime_2_to_the_32 {
101103
const TARGET_SUM: usize = 375;
102104

103105
const PARAMETER_LEN: usize = 5;
104-
const TWEAK_LEN_FE: usize = 2;
106+
pub const TWEAK_LEN_FE: usize = 2;
105107
const MSG_LEN_FE: usize = 9;
106-
const RAND_LEN_FE: usize = 7;
107-
const HASH_LEN_FE: usize = 8;
108+
pub const RAND_LEN_FE: usize = 7;
109+
pub const HASH_LEN_FE: usize = 8;
108110

109111
const CAPACITY: usize = 9;
110112

111113
const POS_OUTPUT_LEN_PER_INV_FE: usize = 15;
112114
const POS_INVOCATIONS: usize = 1;
113115
const POS_OUTPUT_LEN_FE: usize = POS_OUTPUT_LEN_PER_INV_FE * POS_INVOCATIONS;
114116

115-
type MH = TopLevelPoseidonMessageHash<
117+
pub type MH = TopLevelPoseidonMessageHash<
116118
POS_OUTPUT_LEN_PER_INV_FE,
117119
POS_INVOCATIONS,
118120
POS_OUTPUT_LEN_FE,
@@ -130,6 +132,8 @@ pub mod lifetime_2_to_the_32 {
130132

131133
pub type SIGTopLevelTargetSumLifetime32Dim64Base8 =
132134
GeneralizedXMSSSignatureScheme<PRF, IE, TH, LOG_LIFETIME>;
135+
pub type PubKeyTopLevelTargetSumLifetime32Dim64Base8 = GeneralizedXMSSPublicKey<TH>;
136+
pub type SigTopLevelTargetSumLifetime32Dim64Base8 = GeneralizedXMSSSignature<IE, TH>;
133137

134138
#[cfg(test)]
135139
mod test {

src/symmetric/message_hash/top_level_poseidon.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ fn map_into_hypercube_part<
7878
/// - `POS_INVOCATIONS` must be at most 2^8.
7979
/// - `POS_OUTPUT_LEN_FE` must be equal to `POS_INVOCATIONS * POS_OUTPUT_LEN_PER_INV_FE`.
8080
/// - `BASE` must be at most 2^8.
81+
#[derive(Clone)]
8182
pub struct TopLevelPoseidonMessageHash<
8283
const POS_OUTPUT_LEN_PER_INV_FE: usize,
8384
const POS_INVOCATIONS: usize,

src/symmetric/tweak_hash.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub trait TweakableHash {
7575
/// We start walking the chain at position `start_pos_in_chain` with `start`,
7676
/// and then walk the chain for `steps` many steps. For example, walking two steps
7777
/// with `start = A` would mean we walk A -> B -> C, and then return C.
78+
#[allow(clippy::too_long_first_doc_paragraph)]
7879
pub fn chain<TH: TweakableHash>(
7980
parameter: &TH::Parameter,
8081
epoch: u32,

src/symmetric/tweak_hash/poseidon.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const CHAIN_COMPRESSION_WIDTH: usize = 16;
2323
const MERGE_COMPRESSION_WIDTH: usize = 24;
2424

2525
/// Enum to implement tweaks.
26+
#[derive(Debug)]
2627
pub enum PoseidonTweak {
2728
TreeTweak {
2829
level: u8,
@@ -36,7 +37,7 @@ pub enum PoseidonTweak {
3637
}
3738

3839
impl PoseidonTweak {
39-
fn to_field_elements<const TWEAK_LEN: usize>(&self) -> [F; TWEAK_LEN] {
40+
pub fn to_field_elements<const TWEAK_LEN: usize>(&self) -> [F; TWEAK_LEN] {
4041
// We first represent the entire tweak as one big integer
4142
let mut acc = match self {
4243
Self::TreeTweak {
@@ -248,6 +249,7 @@ where
248249
///
249250
/// Note: HASH_LEN, TWEAK_LEN, CAPACITY, and PARAMETER_LEN must
250251
/// be given in the unit "number of field elements".
252+
#[derive(Clone)]
251253
pub struct PoseidonTweakHash<
252254
const PARAMETER_LEN: usize,
253255
const HASH_LEN: usize,

src/symmetric/tweak_hash_tree.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<TH: TweakableHash> Decode for HashSubTree<TH> {
251251
}
252252

253253
/// Opening in a hash-tree: a co-path, without the leaf
254-
#[derive(Serialize, Deserialize)]
254+
#[derive(Serialize, Deserialize, Clone)]
255255
#[serde(bound = "")]
256256
pub struct HashTreeOpening<TH: TweakableHash> {
257257
/// The co-path needed to verify
@@ -562,6 +562,7 @@ where
562562

563563
/// Function to compute a Merkle authentication path from a tree that is
564564
/// splitted into top tree and bottom trees.
565+
#[must_use]
565566
pub fn combined_path<TH: TweakableHash>(
566567
top_tree: &HashSubTree<TH>,
567568
bottom_tree: &HashSubTree<TH>,

0 commit comments

Comments
 (0)