-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ironfish round one wrapper for core frost (#4554)
- Loading branch information
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ testdbs | |
.env.production.local | ||
*/**/yarn.lock | ||
.idea | ||
.vscode | ||
|
||
# logs | ||
npm-debug.log* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters