Skip to content

Commit

Permalink
Update to updated and audited dusk-poseidon v0.39
Browse files Browse the repository at this point in the history
Resolves #19
  • Loading branch information
moCello committed May 13, 2024
1 parent c22eb3f commit b4b9cca
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 43 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add `"zk"` feature [#21]

### Changed

- Update to new `dusk-poseidon` API, v0.39 [#19]

## [0.3.0] - 2024-04-24

### Changed
Expand Down Expand Up @@ -60,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- ISSUES -->
[#23]: https://github.com/dusk-network/jubjub-schnorr/issues/23
[#21]: https://github.com/dusk-network/jubjub-schnorr/issues/21
[#19]: https://github.com/dusk-network/jubjub-schnorr/issues/19
[#14]: https://github.com/dusk-network/jubjub-schnorr/issues/14
[#12]: https://github.com/dusk-network/jubjub-schnorr/issues/12
[#9]: https://github.com/dusk-network/jubjub-schnorr/issues/9
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ license = "MPL-2.0"
[dependencies]
rand_core = { version = "0.6", default-features = false }
dusk-bytes = "0.1"
dusk-poseidon = { version ="0.33", default-features = false }
dusk-poseidon = "0.39"
dusk-bls12_381 = { version = "0.13", default-features = false }
dusk-jubjub = { version = "0.14", default-features = false, features = ["zeroize"] }
ff = { version = "0.13", default-features = false }
Expand Down Expand Up @@ -59,7 +59,7 @@ var_generator = []
multisig = []
zk = [
"dusk-plonk",
"dusk-poseidon/alloc",
"dusk-poseidon/zk",
]
rkyv-impl = [
"dusk-jubjub/rkyv-impl",
Expand Down
5 changes: 3 additions & 2 deletions src/gadgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub use var_gen::verify_signature_var_gen;

use dusk_jubjub::GENERATOR_EXTENDED;
use dusk_plonk::prelude::*;
use dusk_poseidon::sponge;
use dusk_poseidon::{Domain, HashGadget};

/// Verifies a single-key Schnorr signature [`Signature`]within a Plonk circuit
/// without requiring the secret key as a witness.
Expand Down Expand Up @@ -65,7 +65,8 @@ pub fn verify_signature(
let pk_y = *pk.y();

let challenge = [r_x, r_y, pk_x, pk_y, msg];
let challenge_hash = sponge::truncated::gadget(composer, &challenge);
let challenge_hash =
HashGadget::digest_truncated(composer, Domain::Other, &challenge)[0];

let s_a = composer.component_mul_generator(u, GENERATOR_EXTENDED)?;
let s_b = composer.component_mul_point(challenge_hash, pk);
Expand Down
5 changes: 3 additions & 2 deletions src/gadgets/double.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use dusk_jubjub::{GENERATOR_EXTENDED, GENERATOR_NUMS_EXTENDED};
use dusk_plonk::prelude::*;
use dusk_poseidon::sponge;
use dusk_poseidon::{Domain, HashGadget};

/// Verifies a [`SignatureDouble`] within a Plonk circuit without requiring
/// the secret key as a witness.
Expand Down Expand Up @@ -55,7 +55,8 @@ pub fn verify_signature_double(
let pk_y = *pk.y();

let challenge = [r_x, r_y, r_p_x, r_p_y, pk_x, pk_y, msg];
let challenge_hash = sponge::truncated::gadget(composer, &challenge);
let challenge_hash =
HashGadget::digest_truncated(composer, Domain::Other, &challenge)[0];

let s_a = composer.component_mul_generator(u, GENERATOR_EXTENDED)?;
let s_b = composer.component_mul_point(challenge_hash, pk);
Expand Down
5 changes: 3 additions & 2 deletions src/gadgets/var_gen.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_plonk::prelude::*;
use dusk_poseidon::sponge;
use dusk_poseidon::{Domain, HashGadget};

/// Verifies a Schnorr signature with variable generator [`SignatureVarGen`]
/// within a Plonk circuit without requiring the secret key as a witness.
Expand Down Expand Up @@ -52,7 +52,8 @@ pub fn verify_signature_var_gen(
let pk_y = *pk.y();

let challenge = [r_x, r_y, pk_x, pk_y, msg];
let challenge_hash = sponge::truncated::gadget(composer, &challenge);
let challenge_hash =
HashGadget::digest_truncated(composer, Domain::Other, &challenge)[0];

// TODO: check whether we need to append the generator as a constant
let s_a = composer.component_mul_point(u, gen);
Expand Down
21 changes: 12 additions & 9 deletions src/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn multisig_common(
S_vec: &[JubJubExtended],
msg: &BlsScalar,
) -> (JubJubScalar, JubJubScalar, JubJubExtended) {
use dusk_poseidon::sponge::truncated::hash;
use dusk_poseidon::{Domain, Hash};

// Sum all the public keys pk = pk_1 + pk_2 + ... + pk_n for `n` signers
let mut pk = JubJubExtended::default();
Expand Down Expand Up @@ -231,7 +231,7 @@ fn multisig_common(
preimage.push(S_coordinates[1]);
}

let a = hash(&preimage);
let a = Hash::digest_truncated(Domain::Other, &preimage)[0];

// Compute RSa = R_1 + (S_1 * a) + R_2 + (S_2 * a) + ... + R_n + (S_n *
// a) for `n` signers
Expand All @@ -242,13 +242,16 @@ fn multisig_common(

// Compute challenge c = H(RSa || pk || m);
let RSa_coordinates = RSa.to_hash_inputs();
let c = hash(&[
RSa_coordinates[0],
RSa_coordinates[1],
pk_coordinates[0],
pk_coordinates[1],
*msg,
]);
let c = Hash::digest_truncated(
Domain::Other,
&[
RSa_coordinates[0],
RSa_coordinates[1],
pk_coordinates[0],
pk_coordinates[1],
*msg,
],
)[0];

(a, c, RSa)
}
19 changes: 11 additions & 8 deletions src/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) mod var_gen;
use dusk_bls12_381::BlsScalar;
use dusk_bytes::{DeserializableSlice, Error as BytesError, Serializable};
use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar};
use dusk_poseidon::sponge::truncated::hash;
use dusk_poseidon::{Domain, Hash};

use crate::PublicKey;

Expand Down Expand Up @@ -131,11 +131,14 @@ pub(crate) fn challenge_hash(
let R_coordinates = R.to_hash_inputs();
let pk_coordinates = pk.as_ref().to_hash_inputs();

hash(&[
R_coordinates[0],
R_coordinates[1],
pk_coordinates[0],
pk_coordinates[1],
message,
])
Hash::digest_truncated(
Domain::Other,
&[
R_coordinates[0],
R_coordinates[1],
pk_coordinates[0],
pk_coordinates[1],
message,
],
)[0]
}
23 changes: 13 additions & 10 deletions src/signatures/double.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use dusk_bls12_381::BlsScalar;
use dusk_bytes::{DeserializableSlice, Error as BytesError, Serializable};
use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar};
use dusk_poseidon::sponge::truncated::hash;
use dusk_poseidon::{Domain, Hash};

use crate::PublicKey;

Expand Down Expand Up @@ -152,13 +152,16 @@ pub(crate) fn challenge_hash(
let R_p_coordinates = R_prime.to_hash_inputs();
let pk_coordinates = pk.as_ref().to_hash_inputs();

hash(&[
R_coordinates[0],
R_coordinates[1],
R_p_coordinates[0],
R_p_coordinates[1],
pk_coordinates[0],
pk_coordinates[1],
message,
])
Hash::digest_truncated(
Domain::Other,
&[
R_coordinates[0],
R_coordinates[1],
R_p_coordinates[0],
R_p_coordinates[1],
pk_coordinates[0],
pk_coordinates[1],
message,
],
)[0]
}
19 changes: 11 additions & 8 deletions src/signatures/var_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use dusk_bls12_381::BlsScalar;
use dusk_bytes::{DeserializableSlice, Error as BytesError, Serializable};
use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar};
use dusk_poseidon::sponge::truncated::hash;
use dusk_poseidon::{Domain, Hash};

use crate::PublicKeyVarGen;

Expand Down Expand Up @@ -126,11 +126,14 @@ pub(crate) fn challenge_hash(
let R_coordinates = R.to_hash_inputs();
let pk_coordinates = pk.public_key().to_hash_inputs();

hash(&[
R_coordinates[0],
R_coordinates[1],
pk_coordinates[0],
pk_coordinates[1],
message,
])
Hash::digest_truncated(
Domain::Other,
&[
R_coordinates[0],
R_coordinates[1],
pk_coordinates[0],
pk_coordinates[1],
message,
],
)[0]
}

0 comments on commit b4b9cca

Please sign in to comment.