Skip to content

Commit

Permalink
update frost-secp256-tr code to changes from 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zebra-lucky committed Feb 24, 2024
1 parent 0ed163f commit c63a3ca
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
10 changes: 5 additions & 5 deletions frost-secp256k1-tr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ edition = "2021"
# When releasing to crates.io:
# - Update CHANGELOG.md
# - Create git tag.
version = "1.0.0-rc.0"
version = "1.0.0"
authors = [
"Deirdre Connolly <[email protected]>",
"Chelsea Komlo <[email protected]>",
Expand All @@ -23,16 +23,16 @@ rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
document-features = "0.2.7"
frost-core = { path = "../frost-core", version = "1.0.0-rc.0" }
frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0-rc.0" }
frost-core = { path = "../frost-core", version = "1.0.0" }
frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0" }
k256 = { version = "0.13.0", features = ["arithmetic", "expose-field", "hash2curve"] }
rand_core = "0.6"
sha2 = "0.10.2"

[dev-dependencies]
criterion = "0.5"
frost-core = { path = "../frost-core", version = "1.0.0-rc.0", features = ["test-impl"] }
frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0-rc.0", features = ["test-impl"] }
frost-core = { path = "../frost-core", version = "1.0.0", features = ["test-impl"] }
frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0", features = ["test-impl"] }
insta = { version = "1.31.0", features = ["yaml"] }
hex = "0.4.3"
lazy_static = "1.4"
Expand Down
4 changes: 4 additions & 0 deletions frost-secp256k1-tr/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// Required since each integration test is compiled as a separated crate,
// and each one uses only part of the module.
#![allow(dead_code)]

pub mod samples;
14 changes: 12 additions & 2 deletions frost-secp256k1-tr/tests/helpers/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
use std::collections::BTreeMap;

use frost_core::{Ciphersuite, Element, Group, Scalar};
use frost_core::{round1::Nonce, Ciphersuite, Element, Group, Scalar};
use frost_secp256k1_tr::{
keys::{
dkg::{round1, round2},
KeyPackage, PublicKeyPackage, SecretShare, SigningShare, VerifiableSecretSharingCommitment,
VerifyingShare,
},
round1::{NonceCommitment, SigningCommitments},
round1::{NonceCommitment, SigningCommitments, SigningNonces},
round2::SignatureShare,
Field, Signature, SigningPackage, VerifyingKey,
};
Expand All @@ -32,6 +32,16 @@ fn scalar1() -> Scalar<C> {
.expect("nonzero elements have inverses")
}

/// Generate a sample SigningCommitments.
pub fn signing_nonces() -> SigningNonces {
let serialized_scalar1 = <<C as Ciphersuite>::Group as Group>::Field::serialize(&scalar1());
let serialized_scalar2 = <<C as Ciphersuite>::Group as Group>::Field::serialize(&scalar1());
let hiding_nonce = Nonce::deserialize(serialized_scalar1).unwrap();
let binding_nonce = Nonce::deserialize(serialized_scalar2).unwrap();

SigningNonces::from_nonces(hiding_nonce, binding_nonce)
}

/// Generate a sample SigningCommitments.
pub fn signing_commitments() -> SigningCommitments {
let serialized_element1 = <C as Ciphersuite>::Group::serialize(&element1());
Expand Down
12 changes: 11 additions & 1 deletion frost-secp256k1-tr/tests/recreation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use frost_secp256k1_tr::{
dkg::{round1, round2},
KeyPackage, PublicKeyPackage, SecretShare,
},
round1::SigningCommitments,
round1::{SigningCommitments, SigningNonces},
round2::SignatureShare,
SigningPackage,
};
Expand All @@ -15,6 +15,16 @@ mod helpers;

use helpers::samples;

/// Check if SigningNonces can be recreated.
#[test]
fn check_signing_nonces_recreation() {
let nonces = samples::signing_nonces();
let hiding = nonces.hiding();
let binding = nonces.binding();
let new_nonces = SigningNonces::from_nonces(*hiding, *binding);
assert!(nonces == new_nonces);
}

/// Check if SigningCommitments can be recreated.
#[test]
fn check_signing_commitments_recreation() {
Expand Down
10 changes: 9 additions & 1 deletion frost-secp256k1-tr/tests/serialization_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ use frost_secp256k1_tr::{
dkg::{round1, round2},
KeyPackage, PublicKeyPackage, SecretShare,
},
round1::SigningCommitments,
round1::{SigningCommitments, SigningNonces},
round2::SignatureShare,
SigningPackage,
};

use helpers::samples;
use insta::assert_snapshot;

#[test]
fn check_signing_nonces_postcard_serialization() {
let nonces = samples::signing_nonces();
let bytes: Vec<_> = nonces.serialize().unwrap();
assert_snapshot!(hex::encode(&bytes));
assert_eq!(nonces, SigningNonces::deserialize(&bytes).unwrap());
}

#[test]
fn check_signing_commitments_postcard_serialization() {
let commitments = samples::signing_commitments();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: frost-secp256k1/tests/serialization_tests.rs
expression: "hex::encode(&bytes)"
---
00230f8ab3aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9d1c9e899ca306ad27fe1945de0242b81aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9d1c9e899ca306ad27fe1945de0242b8100230f8ab3034c7ff4f2ba8603998339c8e42675ceac23ef2e9623fdb260b24b1c944a2ea1a9034c7ff4f2ba8603998339c8e42675ceac23ef2e9623fdb260b24b1c944a2ea1a9

0 comments on commit c63a3ca

Please sign in to comment.