Skip to content

Commit

Permalink
ironfish round one wrapper for core frost (#4554)
Browse files Browse the repository at this point in the history
  • Loading branch information
jowparks authored Jan 18, 2024
1 parent fc8855d commit 76819fb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ testdbs
.env.production.local
*/**/yarn.lock
.idea
.vscode

# logs
npm-debug.log*
Expand Down
5 changes: 5 additions & 0 deletions ironfish-rust/src/frost_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
56 changes: 56 additions & 0 deletions ironfish-rust/src/frost_utils/round_one.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions ironfish-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 76819fb

Please sign in to comment.