Skip to content

Commit 5942946

Browse files
authored
refactor: introduce new from trait for PoseidonDomain (filecoin-project#1703)
Add a new `From` conversion into the field element repr representation. This makes it also possible to hide the internal representation.
1 parent b3be3ec commit 5942946

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

filecoin-hashers/src/poseidon.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Hashable<PoseidonFunction> for PoseidonDomain {
5757
}
5858

5959
#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize)]
60-
pub struct PoseidonDomain(pub <Fr as PrimeField>::Repr);
60+
pub struct PoseidonDomain(<Fr as PrimeField>::Repr);
6161

6262
impl AsRef<PoseidonDomain> for PoseidonDomain {
6363
fn as_ref(&self) -> &PoseidonDomain {
@@ -365,6 +365,13 @@ impl From<[u8; 32]> for PoseidonDomain {
365365
}
366366
}
367367

368+
impl From<PoseidonDomain> for [u8; 32] {
369+
#[inline]
370+
fn from(val: PoseidonDomain) -> Self {
371+
val.0
372+
}
373+
}
374+
368375
impl From<PoseidonDomain> for Fr {
369376
#[inline]
370377
fn from(val: PoseidonDomain) -> Self {

storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,6 @@ mod tests {
754754
.read_at(final_labels.len() - 1)
755755
.expect("read_at");
756756
dbg!(&last_label);
757-
assert_eq!(expected_last_label.to_repr(), last_label.0);
757+
assert_eq!(expected_last_label.to_repr(), last_label.as_ref());
758758
}
759759
}

storage-proofs-porep/tests/stacked_vanilla.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,5 +577,5 @@ fn test_generate_labels_aux(
577577
let final_labels = labels.labels_for_last_layer().unwrap();
578578
let last_label = final_labels.read_at(nodes - 1).unwrap();
579579

580-
assert_eq!(expected_last_label.to_repr(), last_label.0);
580+
assert_eq!(expected_last_label.to_repr(), last_label.as_ref());
581581
}

0 commit comments

Comments
 (0)