diff --git a/.gitignore b/.gitignore index c8126cc6c5..0a5751c5b2 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ testdbs .env.production.local */**/yarn.lock .idea +.vscode # logs npm-debug.log* diff --git a/ironfish-rust/src/frost_utils/mod.rs b/ironfish-rust/src/frost_utils/mod.rs new file mode 100644 index 0000000000..25bb98d3e2 --- /dev/null +++ b/ironfish-rust/src/frost_utils/mod.rs @@ -0,0 +1,5 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +pub mod round_one; diff --git a/ironfish-rust/src/frost_utils/round_one.rs b/ironfish-rust/src/frost_utils/round_one.rs new file mode 100644 index 0000000000..3b6c4177d1 --- /dev/null +++ b/ironfish-rust/src/frost_utils/round_one.rs @@ -0,0 +1,56 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use ironfish_frost::frost::{ + self, + keys::KeyPackage, + round1::{SigningCommitments, SigningNonces}, +}; +use rand::{rngs::StdRng, SeedableRng}; + +// Small wrapper around frost::round1::commit that provides a seedable rng +pub fn round_one(key_package: &KeyPackage, seed: u64) -> (SigningNonces, SigningCommitments) { + let mut rng = StdRng::seed_from_u64(seed); + frost::round1::commit(key_package.signing_share(), &mut rng) +} + +#[cfg(test)] +mod test { + + use ff::Field; + use ironfish_frost::frost::keys::IdentifierList; + use jubjub::Fr; + use rand::rngs::ThreadRng; + + use crate::transaction::{split_secret, SecretShareConfig}; + + #[test] + pub fn test_seed_provides_same_result() { + let seed = 100; + let key = Fr::random(&mut rand::thread_rng()); + + let mut rng = ThreadRng::default(); + let key_packages = split_secret( + &SecretShareConfig { + max_signers: 3, + min_signers: 2, + secret: key.to_bytes().to_vec(), + }, + IdentifierList::Default, + &mut rng, + ) + .expect("key shares to be created"); + let key_package = key_packages + .0 + .into_iter() + .next() + .expect("key package to be created") + .1; + let (nonces, commitments) = super::round_one(&key_package, seed); + let (nonces2, commitments2) = super::round_one(&key_package, seed); + assert_eq!(nonces.hiding().serialize(), nonces2.hiding().serialize()); + assert_eq!(nonces.binding().serialize(), nonces2.binding().serialize()); + assert_eq!(commitments, commitments2); + } +} diff --git a/ironfish-rust/src/lib.rs b/ironfish-rust/src/lib.rs index ac99da0682..f20dfeb45b 100644 --- a/ironfish-rust/src/lib.rs +++ b/ironfish-rust/src/lib.rs @@ -6,6 +6,7 @@ use blstrs::Bls12; pub mod assets; pub mod errors; +pub mod frost_utils; pub mod keys; pub mod merkle_note; pub mod merkle_note_hash;