Skip to content

Commit

Permalink
crypto: use new poseidon377 API
Browse files Browse the repository at this point in the history
penumbra-zone/poseidon377#4 reworked the `poseidon377`
API to allow direct access to the permutation state, allowing the hash_n
functions to be moved into that crate.
  • Loading branch information
hdevalence committed Oct 20, 2021
1 parent 681c12f commit dfc677b
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 103 deletions.
7 changes: 4 additions & 3 deletions crypto/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ static VALUE_GENERATOR_DOMAIN_SEP: Lazy<Fq> = Lazy::new(|| {
impl Id {
/// Compute the value commitment generator for this asset.
pub fn value_generator(&self) -> decaf377::Element {
use crate::poseidon_hash::hash_1;
let hash = hash_1(&VALUE_GENERATOR_DOMAIN_SEP, self.0);
decaf377::Element::map_to_group_cdh(&hash)
decaf377::Element::map_to_group_cdh(&poseidon377::hash_1(
&VALUE_GENERATOR_DOMAIN_SEP,
self.0,
))
}
}

Expand Down
6 changes: 2 additions & 4 deletions crypto/src/keys/diversifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ impl Diversifier {

/// Generate the diversified basepoint.
pub fn diversified_generator(&self) -> decaf377::Element {
use crate::poseidon_hash::hash_1;
let hash = hash_1(
decaf377::Element::map_to_group_cdh(&poseidon377::hash_1(
&DIVERSIFY_GENERATOR_DOMAIN_SEP,
Fq::from_le_bytes_mod_order(&self.0[..]),
);
decaf377::Element::map_to_group_cdh(&hash)
))
}
}
2 changes: 0 additions & 2 deletions crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ pub mod proofs;
pub mod transaction;
pub mod value;

mod poseidon_hash;

pub use action::output::Output;
pub use action::spend::Spend;
pub use note::Note;
Expand Down
3 changes: 1 addition & 2 deletions crypto/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use incrementalmerkletree;
use once_cell::sync::Lazy;

use crate::note;
use crate::poseidon_hash::hash_2;

pub use incrementalmerkletree::{
bridgetree::{self, AuthFragment, BridgeTree},
Expand Down Expand Up @@ -46,6 +45,6 @@ impl Hashable for note::Commitment {
// extend to build domain sep
let level_fq: Fq = u8::from(level).into();
let level_domain_sep: Fq = *MERKLE_DOMAIN_SEP + level_fq;
note::Commitment(hash_2(&level_domain_sep, (a.0, b.0)))
note::Commitment(poseidon377::hash_2(&level_domain_sep, (a.0, b.0)))
}
}
4 changes: 2 additions & 2 deletions crypto/src/note.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ark_ff::PrimeField;
use once_cell::sync::Lazy;

use crate::{addresses::PaymentAddress, keys, poseidon_hash::hash_5, Fq, Value};
use crate::{addresses::PaymentAddress, keys, Fq, Value};

// TODO: Should have a `leadByte` as in Sapling and Orchard note plaintexts?
// Do we need that in addition to the tx version?
Expand Down Expand Up @@ -38,7 +38,7 @@ impl Note {
}

pub fn commit(&self) -> Commitment {
let commit = hash_5(
let commit = poseidon377::hash_5(
&NOTECOMMIT_DOMAIN_SEP,
(
self.note_blinding,
Expand Down
90 changes: 0 additions & 90 deletions crypto/src/poseidon_hash.rs

This file was deleted.

0 comments on commit dfc677b

Please sign in to comment.