Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Blake for stealth addresses #147

Merged
merged 5 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Update bls12_381-bls -> 0.2
- Update jubjub-schnorr -> 0.2
- Use Blake for computing the stealth addresses, instead of Poseidon.

## [0.25.0] - 2024-01-24

Expand Down
8 changes: 8 additions & 0 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar};

pub mod public;
pub mod secret;
pub mod stealth;
pub mod view;

/// Hashes a JubJub's ExtendedPoint into a JubJub's Scalar using the JubJub's
/// hash to scalar function
pub fn hash(p: &JubJubExtended) -> JubJubScalar {
JubJubScalar::hash_to_scalar(&JubJubAffine::from(p).to_bytes())
}
4 changes: 2 additions & 2 deletions src/keys/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::{permutation, SecretKey, StealthAddress, ViewKey};
use crate::{keys::hash, SecretKey, StealthAddress, ViewKey};

use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar};

Expand Down Expand Up @@ -50,7 +50,7 @@ impl PublicKey {
let R = G * r;

let rA = self.A * r;
let rA = permutation::hash(&rA);
let rA = hash(&rA);
let rA = G * rA;

let pk_r = rA + self.B;
Expand Down
4 changes: 2 additions & 2 deletions src/keys/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::{permutation, StealthAddress};
use crate::{keys::hash, StealthAddress};
use dusk_jubjub::JubJubScalar;
use ff::Field;
use jubjub_schnorr::SecretKey as NoteSecretKey;
Expand Down Expand Up @@ -58,7 +58,7 @@ impl SecretKey {
/// With the formula: `sk_r = H(a · R) + b`
pub fn sk_r(&self, sa: &StealthAddress) -> NoteSecretKey {
let aR = sa.R() * self.a;
let aR = permutation::hash(&aR);
let aR = hash(&aR);

(aR + self.b).into()
}
Expand Down
4 changes: 2 additions & 2 deletions src/keys/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use crate::keys::stealth;

use crate::{permutation, SecretKey};
use crate::{keys::hash, SecretKey};

use dusk_bytes::{DeserializableSlice, Error, Serializable};
use dusk_jubjub::{
Expand Down Expand Up @@ -69,7 +69,7 @@ impl ViewKey {
let sa = owner.stealth_address();

let aR = sa.R() * self.a();
let aR = permutation::hash(&aR);
let aR = hash(&aR);
let aR = GENERATOR_EXTENDED * aR;
let pk_r = aR + self.B();

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ pub mod note;
/// Phoenix Core Keys & Addresses
mod keys;

xevisalle marked this conversation as resolved.
Show resolved Hide resolved
mod permutation;

/// Public (Spend) Key
pub use keys::public::PublicKey;
/// Secret (Spend) Key
Expand Down
14 changes: 0 additions & 14 deletions src/permutation.rs

This file was deleted.