Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
- Update `dusk-bls12_381` to `0.12`
- Update `dusk-bls12_381-sign` to `0.5`
- Update `dusk-jubjub` to `0.13`
- Update `dusk-poseidon` to `0.31`
- Update `dusk-pki` to `0.13`
- Add `ff` dependency
  • Loading branch information
moCello committed Oct 12, 2023
1 parent 7727c8c commit 1a56806
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Update `dusk-bls12_381` to `0.12`
- Update `dusk-bls12_381-sign` to `0.5`
- Update `dusk-jubjub` to `0.13`
- Update `dusk-poseidon` to `0.31`
- Update `dusk-pki` to `0.13`

### Added

- Add `ff` dependency

### Changed

- Update to `[email protected]`
- Update to `[email protected]`

Expand Down
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ exclude = [".github/workflows/ci.yml", ".gitignore"]
[dependencies]
rand_core = { version = "0.6", default-features = false }
dusk-bytes = "0.1"
dusk-bls12_381 = { version = "0.11", default-features = false }
dusk-bls12_381-sign = { version = "0.4", default-features = false }
dusk-jubjub = { version = "0.12", default-features = false }
dusk-poseidon = { version = "0.30", default-features = false }
dusk-pki = { version = "0.12", default-features = false }
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-pki = { version = "0.13", default-features = false }
rkyv = { version = "0.7", optional = true, default-features = false }
bytecheck = { version = "0.6", optional = true, default-features = false }
ff = { version = "0.13", default-features = false }

[dev-dependencies]
assert_matches = "1.3"
Expand Down
10 changes: 7 additions & 3 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use dusk_jubjub::{dhke, JubJubAffine};
use dusk_pki::PublicSpendKey;
use dusk_poseidon::cipher::PoseidonCipher;
use dusk_poseidon::sponge;
use ff::Field;
use rand_core::{CryptoRng, RngCore};

/// Message structure with value commitment
Expand All @@ -39,7 +40,7 @@ impl Message {
psk: &PublicSpendKey,
value: u64,
) -> Self {
let nonce = BlsScalar::random(rng);
let nonce = BlsScalar::random(&mut *rng);
let blinding_factor = JubJubScalar::random(rng);

let note = Note::deterministic(
Expand Down Expand Up @@ -124,8 +125,11 @@ impl Message {
let value = value.0[0];

// Converts the BLS Scalar into a JubJub Scalar.
let blinding_factor = JubJubScalar::from_bytes(&data[1].to_bytes())
.map_err(|_| Error::InvalidBlindingFactor)?;
let blinding_factor =
match JubJubScalar::from_bytes(&data[1].to_bytes()).into() {
Some(scalar) => scalar,
None => return Err(Error::InvalidBlindingFactor),
};

Ok((value, blinding_factor))
}
Expand Down
9 changes: 7 additions & 2 deletions src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use dusk_pki::{
};
use dusk_poseidon::cipher::PoseidonCipher;
use dusk_poseidon::sponge::hash;
use ff::Field;
use rand_core::{CryptoRng, RngCore};

#[cfg(feature = "rkyv-impl")]
Expand Down Expand Up @@ -91,7 +92,7 @@ impl Note {
blinding_factor: JubJubScalar,
) -> Self {
let r = JubJubScalar::random(rng);
let nonce = BlsScalar::random(rng);
let nonce = BlsScalar::random(&mut *rng);

Self::deterministic(note_type, &r, nonce, psk, value, blinding_factor)
}
Expand Down Expand Up @@ -225,7 +226,11 @@ impl Note {
// Converts the BLS Scalar into a JubJub Scalar.
// If the `vk` is wrong it might fails since the resulting BLS Scalar
// might not fit into a JubJub Scalar.
let blinding_factor = JubJubScalar::from_bytes(&data[1].to_bytes())?;
let blinding_factor =
match JubJubScalar::from_bytes(&data[1].to_bytes()).into() {
Some(scalar) => scalar,
None => return Err(BytesError::InvalidData),
};

Ok((value, blinding_factor))
}
Expand Down
19 changes: 10 additions & 9 deletions tests/note_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use core::convert::TryInto;
use dusk_bls12_381::BlsScalar;
use dusk_jubjub::{JubJubScalar, GENERATOR_EXTENDED, GENERATOR_NUMS_EXTENDED};
use dusk_pki::{Ownable, SecretSpendKey};
use ff::Field;
use phoenix_core::{Crossover, Error, Fee, Note, NoteType};
use rand_core::OsRng;

Expand All @@ -29,15 +30,15 @@ fn transparent_note() -> Result<(), Error> {

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

let ssk = SecretSpendKey::random(rng);
let ssk = SecretSpendKey::random(&mut rng);
let psk = ssk.public_spend_key();

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

let sa = psk.gen_stealth_address(&r);
let nonce = BlsScalar::random(rng);
let nonce = BlsScalar::random(&mut rng);
let value = 25;

let note = Note::transparent_stealth(sa, value, nonce);
Expand Down Expand Up @@ -69,16 +70,16 @@ fn obfuscated_note() -> Result<(), Error> {

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

let ssk = SecretSpendKey::random(rng);
let ssk = SecretSpendKey::random(&mut rng);
let psk = ssk.public_spend_key();
let vk = ssk.view_key();
let value = 25;

let r = JubJubScalar::random(rng);
let nonce = BlsScalar::random(rng);
let blinding_factor = JubJubScalar::random(rng);
let r = JubJubScalar::random(&mut rng);
let nonce = BlsScalar::random(&mut rng);
let blinding_factor = JubJubScalar::random(&mut rng);

let note = Note::deterministic(
NoteType::Obfuscated,
Expand Down

0 comments on commit 1a56806

Please sign in to comment.