From 1a5680660873e63888446fd1045524f478eea021 Mon Sep 17 00:00:00 2001 From: moana Date: Thu, 12 Oct 2023 17:52:14 +0200 Subject: [PATCH] Update dependencies - 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 --- CHANGELOG.md | 12 ++++++++++++ Cargo.toml | 11 ++++++----- src/message.rs | 10 +++++++--- src/note.rs | 9 +++++++-- tests/note_test.rs | 19 ++++++++++--------- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1e9a93..8961d28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `dusk-poseidon@0.30` - Update to `dusk-pki@0.12` diff --git a/Cargo.toml b/Cargo.toml index 5c564dc..7bcc047 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/message.rs b/src/message.rs index b11bb92..efb63f4 100644 --- a/src/message.rs +++ b/src/message.rs @@ -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 @@ -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( @@ -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)) } diff --git a/src/note.rs b/src/note.rs index 606e40d..fe0976f 100644 --- a/src/note.rs +++ b/src/note.rs @@ -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")] @@ -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) } @@ -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)) } diff --git a/tests/note_test.rs b/tests/note_test.rs index adaf265..125c79c 100644 --- a/tests/note_test.rs +++ b/tests/note_test.rs @@ -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; @@ -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); @@ -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,