Skip to content

Commit

Permalink
Merge pull request #225 from dusk-network/mocello/owns
Browse files Browse the repository at this point in the history
core: Change `owns` to take a `StealthAddress`
  • Loading branch information
moCello authored Jun 27, 2024
2 parents 92c3229 + 04a1c83 commit b462dd3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Let `owns` take a `StealthAddress` instead of a `Note`
- Rename `tx_max_fee` to `max_fee` [#214]
- Add `sender_enc` field to the `Note` [#214]
- Add `sender_blinder` parameter for `Note` contructors [#214]
Expand Down
10 changes: 4 additions & 6 deletions core/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::{keys::hash, Note, StealthAddress};
use crate::{keys::hash, StealthAddress};

use dusk_jubjub::{JubJubScalar, GENERATOR_EXTENDED};
use ff::Field;
Expand Down Expand Up @@ -88,16 +88,14 @@ impl SecretKey {
}

/// Checks if `note_pk ?= (H(R · a) + b) · G`
pub fn owns(&self, note: &Note) -> bool {
let stealth = note.stealth_address();

let aR = stealth.R() * self.a();
pub fn owns(&self, stealth_address: &StealthAddress) -> bool {
let aR = stealth_address.R() * self.a();
let hash_aR = hash(&aR);
let note_sk = hash_aR + self.b();

let note_pk = GENERATOR_EXTENDED * note_sk;

stealth.note_pk().as_ref() == &note_pk
stealth_address.note_pk().as_ref() == &note_pk
}
}

Expand Down
10 changes: 4 additions & 6 deletions core/src/keys/view.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::{keys::hash, Note, SecretKey};
use crate::{keys::hash, SecretKey, StealthAddress};

use dusk_bytes::{DeserializableSlice, Error, Serializable};
use dusk_jubjub::{
Expand Down Expand Up @@ -63,15 +63,13 @@ impl ViewKey {
}

/// Checks `note_pk = H(R · a) · G + B`
pub fn owns(&self, note: &Note) -> bool {
let stealth = note.stealth_address();

let aR = stealth.R() * self.a();
pub fn owns(&self, stealth_address: &StealthAddress) -> bool {
let aR = stealth_address.R() * self.a();
let hash_aR = hash(&aR);
let hash_aR_G = GENERATOR_EXTENDED * hash_aR;
let note_pk = hash_aR_G + self.B();

stealth.note_pk().as_ref() == &note_pk
stealth_address.note_pk().as_ref() == &note_pk
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/tests/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ fn keys_consistency() {
sender_blinder,
);

assert!(receiver_vk.owns(&note));
assert!(receiver_sk.owns(&note));
assert!(receiver_vk.owns(note.stealth_address()));
assert!(receiver_sk.owns(note.stealth_address()));

let wrong_sk = SecretKey::random(&mut rng);
let wrong_vk = ViewKey::from(&wrong_sk);

assert_ne!(receiver_sk, wrong_sk);
assert_ne!(receiver_vk, wrong_vk);

assert!(!wrong_vk.owns(&note));
assert!(!wrong_sk.owns(&note));
assert!(!wrong_vk.owns(note.stealth_address()));
assert!(!wrong_sk.owns(note.stealth_address()));

let sa = receiver_pk.gen_stealth_address(&r);

Expand Down

0 comments on commit b462dd3

Please sign in to comment.