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

Update dependencies #139

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Derive `Debug` trait for keys [#136]

## Changed

- Update dusk-bls12_381 -> 0.13
- Update dusk-jubjub -> 0.14
- Update dusk-poseidon -> 0.32
- Update bls12_381-sign -> 0.6
- Update dusk-schnorr -> 0.17

## [0.22.0] - 2023-11-22

### Added
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ exclude = [".github/workflows/ci.yml", ".gitignore"]
[dependencies]
rand_core = { version = "0.6", default-features = false }
dusk-bytes = "0.1"
dusk-bls12_381 = { version = "0.12", default-features = false }
dusk-bls12_381-sign = { version = "0.5", default-features = false }
dusk-jubjub = { version = "0.13", default-features = false }
dusk-poseidon = { version = "0.31", default-features = false }
dusk-schnorr = { version = "0.15.0", default-features = false }
dusk-bls12_381 = { version = "0.13", default-features = false }
dusk-bls12_381-sign = { version = "0.6", default-features = false }
dusk-jubjub = { version = "0.14", default-features = false }
dusk-poseidon = { version = "0.32", default-features = false }
dusk-schnorr = { version = "0.17", default-features = false }
subtle = { version = "^2.2.1", default-features = false }
rkyv = { version = "0.7", optional = true, default-features = false }
bytecheck = { version = "0.6", optional = true, default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use dusk_bls12_381::BlsScalar;
use dusk_bytes::{DeserializableSlice, Error as BytesError, Serializable};
use dusk_jubjub::JubJubScalar;
use dusk_poseidon::sponge::hash;
use ff::Field;
use rand_core::{CryptoRng, RngCore};

#[cfg(feature = "rkyv-impl")]
Expand Down Expand Up @@ -52,7 +53,7 @@ impl Fee {
gas_price: u64,
psk: &PublicKey,
) -> Self {
let r = JubJubScalar::random(rng);
let r = JubJubScalar::random(&mut *rng);

Self::deterministic(gas_limit, gas_price, &r, psk)
}
Expand Down
7 changes: 4 additions & 3 deletions src/keys/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

use crate::{permutation, StealthAddress};
use dusk_jubjub::JubJubScalar;
use dusk_schnorr::NoteSecretKey;
use dusk_schnorr::SecretKey as NoteSecretKey;
use ff::Field;

#[cfg(feature = "rkyv-impl")]
use rkyv::{Archive, Deserialize, Serialize};
Expand Down Expand Up @@ -47,8 +48,8 @@ impl SecretKey {
/// Deterministically create a new [`SecretKey`] from a random number
/// generator
pub fn random<R: RngCore + CryptoRng>(rng: &mut R) -> Self {
let a = JubJubScalar::random(rng);
let b = JubJubScalar::random(rng);
let a = JubJubScalar::random(&mut *rng);
let b = JubJubScalar::random(&mut *rng);

SecretKey::new(a, b)
}
Expand Down
2 changes: 1 addition & 1 deletion src/keys/stealth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_jubjub::{JubJubAffine, JubJubExtended};
use dusk_schnorr::NotePublicKey;
use dusk_schnorr::PublicKey as NotePublicKey;

use dusk_bytes::{DeserializableSlice, Error, Serializable};

Expand Down
2 changes: 1 addition & 1 deletion src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Note {
value: u64,
blinding_factor: JubJubScalar,
) -> Self {
let r = JubJubScalar::random(rng);
let r = JubJubScalar::random(&mut *rng);
let nonce = BlsScalar::random(&mut *rng);

Self::deterministic(note_type, &r, nonce, psk, value, blinding_factor)
Expand Down
25 changes: 13 additions & 12 deletions tests/crossover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@
use core::convert::TryInto;

use dusk_jubjub::JubJubScalar;
use ff::Field;
use phoenix_core::{Error, Message, Note, PublicKey, SecretKey};
use rand_core::OsRng;

#[test]
fn crossover_hash() -> Result<(), Error> {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let psk = PublicKey::from(ssk);

let value = 25;
let blinding_factor = JubJubScalar::random(rng);
let note = Note::obfuscated(rng, &psk, value, blinding_factor);
let blinding_factor = JubJubScalar::random(&mut rng);
let note = Note::obfuscated(&mut rng, &psk, value, blinding_factor);

let value = 25;
let blinding_factor = JubJubScalar::random(rng);
let note_p = Note::obfuscated(rng, &psk, value, blinding_factor);
let blinding_factor = JubJubScalar::random(&mut rng);
let note_p = Note::obfuscated(&mut rng, &psk, value, blinding_factor);

let (_, crossover) = note.try_into()?;
let (_, crossover_p) = note_p.try_into()?;
Expand All @@ -38,17 +39,17 @@ fn crossover_hash() -> Result<(), Error> {

#[test]
fn message_hash() -> Result<(), Error> {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let psk = PublicKey::from(ssk);
let value = 25;

let r = JubJubScalar::random(rng);
let message = Message::new(rng, &r, &psk, value);
let r = JubJubScalar::random(&mut rng);
let message = Message::new(&mut rng, &r, &psk, value);

let r_p = JubJubScalar::random(rng);
let message_p = Message::new(rng, &r_p, &psk, value);
let r_p = JubJubScalar::random(&mut rng);
let message_p = Message::new(&mut rng, &r_p, &psk, value);

let hash = message.hash();
let hash_p = message_p.hash();
Expand Down
1 change: 1 addition & 0 deletions tests/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_bytes::{DeserializableSlice, Serializable};
use ff::Field;
use phoenix_core::{PublicKey, SecretKey, ViewKey};
use rand_core::OsRng;

Expand Down
21 changes: 11 additions & 10 deletions tests/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
use dusk_bytes::Serializable;
use dusk_jubjub::JubJubScalar;
use dusk_jubjub::{GENERATOR_EXTENDED, GENERATOR_NUMS_EXTENDED};
use ff::Field;
use phoenix_core::{Message, PublicKey, SecretKey};
use rand_core::OsRng;

#[test]
fn message_consistency() {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let psk = PublicKey::from(ssk);
let psk_wrong = PublicKey::from(SecretKey::random(rng));
let psk_wrong = PublicKey::from(SecretKey::random(&mut rng));

let r = JubJubScalar::random(rng);
let r_wrong = JubJubScalar::random(rng);
let r = JubJubScalar::random(&mut rng);
let r_wrong = JubJubScalar::random(&mut rng);
let value = 105;

let message = Message::new(rng, &r, &psk, value);
let message = Message::new(&mut rng, &r, &psk, value);
let value_commitment = message.value_commitment();
let (value_p, blinding_factor) = message.decrypt(&r, &psk).unwrap();
assert!(message.decrypt(&r_wrong, &psk).is_err());
Expand All @@ -38,15 +39,15 @@ fn message_consistency() {

#[test]
fn message_bytes() {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let psk = PublicKey::from(ssk);

let r = JubJubScalar::random(rng);
let r = JubJubScalar::random(&mut rng);
let value = 106;

let m = Message::new(rng, &r, &psk, value);
let m = Message::new(&mut rng, &r, &psk, value);
let m_p = m.to_bytes();
let m_p = Message::from_bytes(&m_p).unwrap();

Expand Down
68 changes: 34 additions & 34 deletions tests/note_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use rand_core::OsRng;

#[test]
fn transparent_note() -> Result<(), Error> {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let psk = PublicKey::from(ssk);
let value = 25;

let note = Note::transparent(rng, &psk, value);
let note = Note::transparent(&mut rng, &psk, value);

assert_eq!(note.note(), NoteType::Transparent);
assert_eq!(value, note.value(None)?);
Expand Down Expand Up @@ -54,15 +54,15 @@ fn transparent_stealth_note() -> Result<(), Error> {

#[test]
fn obfuscated_note() -> Result<(), Error> {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let psk = PublicKey::from(ssk);
let vk = ViewKey::from(ssk);
let value = 25;

let blinding_factor = JubJubScalar::random(rng);
let note = Note::obfuscated(rng, &psk, value, blinding_factor);
let blinding_factor = JubJubScalar::random(&mut rng);
let note = Note::obfuscated(&mut rng, &psk, value, blinding_factor);

assert_eq!(note.note(), NoteType::Obfuscated);
assert_eq!(value, note.value(Some(&vk))?);
Expand Down Expand Up @@ -100,14 +100,14 @@ fn obfuscated_deterministic_note() -> Result<(), Error> {

#[test]
fn value_commitment_transparent() {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let vk = ViewKey::from(ssk);
let psk = PublicKey::from(ssk);
let value = 25;

let note = Note::transparent(rng, &psk, value);
let note = Note::transparent(&mut rng, &psk, value);

let value = note
.value(Some(&vk))
Expand All @@ -127,15 +127,15 @@ fn value_commitment_transparent() {

#[test]
fn value_commitment_obfuscated() {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let vk = ViewKey::from(ssk);
let psk = PublicKey::from(ssk);
let value = 25;

let blinding_factor = JubJubScalar::random(rng);
let note = Note::obfuscated(rng, &psk, value, blinding_factor);
let blinding_factor = JubJubScalar::random(&mut rng);
let note = Note::obfuscated(&mut rng, &psk, value, blinding_factor);

let value = note
.value(Some(&vk))
Expand All @@ -155,41 +155,41 @@ fn value_commitment_obfuscated() {

#[test]
fn note_keys_consistency() {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let psk = PublicKey::from(ssk);
let vk = ViewKey::from(ssk);
let value = 25;

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

assert_ne!(ssk, wrong_ssk);
assert_ne!(vk, wrong_vk);

let blinding_factor = JubJubScalar::random(rng);
let note = Note::obfuscated(rng, &psk, value, blinding_factor);
let blinding_factor = JubJubScalar::random(&mut rng);
let note = Note::obfuscated(&mut rng, &psk, value, blinding_factor);

assert!(!wrong_vk.owns(&note));
assert!(vk.owns(&note));
}

#[test]
fn fee_and_crossover_generation() -> Result<(), Error> {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let psk = PublicKey::from(ssk);
let vk = ViewKey::from(ssk);
let value = 25;

let blinding_factor = JubJubScalar::random(rng);
let note = Note::obfuscated(rng, &psk, value, blinding_factor);
let blinding_factor = JubJubScalar::random(&mut rng);
let note = Note::obfuscated(&mut rng, &psk, value, blinding_factor);
let (fee, crossover): (Fee, Crossover) = note.try_into()?;

let ssk_fee = SecretKey::random(rng);
let wrong_fee = Fee::new(rng, 0, 0, &ssk_fee.into());
let ssk_fee = SecretKey::random(&mut rng);
let wrong_fee = Fee::new(&mut rng, 0, 0, &ssk_fee.into());
let wrong_note: Note = (wrong_fee, crossover).into();

assert_ne!(note, wrong_note);
Expand All @@ -207,13 +207,13 @@ fn fee_and_crossover_generation() -> Result<(), Error> {

#[test]
fn fail_fee_and_crossover_from_transparent() {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let psk = PublicKey::from(ssk);
let value = 25;

let note = Note::transparent(rng, &psk, value);
let note = Note::transparent(&mut rng, &psk, value);
let result: Result<(Fee, Crossover), Error> = note.try_into();

assert!(
Expand All @@ -224,17 +224,17 @@ fn fail_fee_and_crossover_from_transparent() {

#[test]
fn transparent_from_fee_remainder() -> Result<(), Error> {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let psk = PublicKey::from(ssk);
let vk = ViewKey::from(ssk);

let gas_consumed = 3;
let gas_limit = 10;
let gas_price = 2;

let fee = Fee::new(rng, gas_limit, gas_price, &psk);
let fee = Fee::new(&mut rng, gas_limit, gas_price, &psk);
let remainder = fee.gen_remainder(gas_consumed);
let note = Note::from(remainder);

Expand All @@ -249,17 +249,17 @@ fn transparent_from_fee_remainder() -> Result<(), Error> {

#[test]
fn transparent_from_fee_remainder_with_invalid_consumed() -> Result<(), Error> {
let rng = &mut OsRng;
let mut rng = OsRng;

let ssk = SecretKey::random(rng);
let ssk = SecretKey::random(&mut rng);
let psk = PublicKey::from(ssk);
let vk = ViewKey::from(ssk);

let gas_consumed = 30;
let gas_limit = 10;
let gas_price = 2;

let fee = Fee::new(rng, gas_limit, gas_price, &psk);
let fee = Fee::new(&mut rng, gas_limit, gas_price, &psk);
let remainder = fee.gen_remainder(gas_consumed);
let note = Note::from(remainder);

Expand Down