Skip to content

Commit

Permalink
Small adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
emmorais committed Jan 28, 2025
1 parent b0811ae commit f7f9160
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
19 changes: 13 additions & 6 deletions benches/e2e_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rand::{prelude::IteratorRandom, rngs::OsRng, CryptoRng, Rng, RngCore};
use std::collections::HashMap;
use tss_ecdsa::{
auxinfo::AuxInfoParticipant,
curve::TestCurve as C,
curve::TestCurve,
errors::Result,
keygen::KeygenParticipant,
messages::Message,
Expand Down Expand Up @@ -107,26 +107,30 @@ fn run_benchmarks_for_given_size(c: &mut Criterion, num_players: usize) {
let keygen_sid = Identifier::random(&mut rng);
let keygen_inputs = std::iter::repeat(()).take(num_players).collect::<Vec<_>>();
c.bench_function(&format!("Keygen with {num_players} nodes"), |b| {
b.iter(|| run_subprotocol::<KeygenParticipant<C>>(keygen_sid, keygen_inputs.clone()))
b.iter(|| {
run_subprotocol::<KeygenParticipant<TestCurve>>(keygen_sid, keygen_inputs.clone())
})
});

// Benchmark auxinfo
let auxinfo_sid = Identifier::random(&mut rng);
let auxinfo_inputs = std::iter::repeat(()).take(num_players).collect::<Vec<_>>();
c.bench_function(&format!("Auxinfo with {num_players} nodes"), |b| {
b.iter(|| run_subprotocol::<AuxInfoParticipant<C>>(auxinfo_sid, auxinfo_inputs.clone()))
b.iter(|| {
run_subprotocol::<AuxInfoParticipant<TestCurve>>(auxinfo_sid, auxinfo_inputs.clone())
})
});

// Prepare to benchmark presign:
// 1. Run keygen and get outputs
let keygen_inputs = std::iter::repeat(()).take(num_players).collect();
let keygen_outputs =
run_subprotocol::<KeygenParticipant<C>>(keygen_sid, keygen_inputs).unwrap();
run_subprotocol::<KeygenParticipant<TestCurve>>(keygen_sid, keygen_inputs).unwrap();

// 2. Run auxinfo and get outputs
let auxinfo_inputs = std::iter::repeat(()).take(num_players).collect();
let auxinfo_outputs =
run_subprotocol::<AuxInfoParticipant<C>>(auxinfo_sid, auxinfo_inputs).unwrap();
run_subprotocol::<AuxInfoParticipant<TestCurve>>(auxinfo_sid, auxinfo_inputs).unwrap();

// 3. Assemble presign input from keygen and auxinfo.
let presign_inputs = auxinfo_outputs
Expand All @@ -141,7 +145,10 @@ fn run_benchmarks_for_given_size(c: &mut Criterion, num_players: usize) {
let presign_identifier = Identifier::random(&mut rng);
c.bench_function(&format!("Presign with {num_players} nodes"), |b| {
b.iter(|| {
run_subprotocol::<PresignParticipant<C>>(presign_identifier, presign_inputs.clone())
run_subprotocol::<PresignParticipant<TestCurve>>(
presign_identifier,
presign_inputs.clone(),
)
})
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ impl ScalarTrait for K256_Scalar {

/// Default curve type.
pub type TestCurve = K256;
//pub type TestCT = P256;
//pub type TestCurve = P256;

/// Default scalar type.
pub type TestScalar = K256_Scalar;
//pub type TestST = P256_Scalar;
//pub type TestScalar = P256_Scalar;

/// Default signature type.
pub type TestSignature = k256::ecdsa::Signature;
Expand Down
4 changes: 2 additions & 2 deletions src/presign/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ mod tests {
_rng: &mut (impl CryptoRng + RngCore),
) -> Vec<Self> {
// Note: using slightly-biased generation for faster tests
//let mask_shares = std::iter::repeat_with(|| <TestCT as
// CT>::Scalar::generate_biased(rng)).take(keygen_outputs.len())
//let mask_shares = std::iter::repeat_with(|| <TestCurve as
// CurveTrait>::Scalar::generate_biased(rng)).take(keygen_outputs.len())
// .collect::<Vec<_>>();
// TODO: use generate_biased when generalized
let mask_shares = std::iter::repeat_with(<TestCurve as CurveTrait>::Scalar::random)
Expand Down
2 changes: 1 addition & 1 deletion src/sign/non_interactive_sign/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ mod test {
// Re-derive the public key from the recoverable ID and ensure it matches the
// original public key.
let recovered_pk = <TestCT as CT>::VK::recover_from_digest(
let recovered_pk = <TestCurve as CurveTrait>::VK::recover_from_digest(
digest,
distributed_sig,
RecoveryId::from_byte(recovery_id).expect("Invalid recovery ID"),
Expand Down
12 changes: 6 additions & 6 deletions src/slip0010/ckd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ public: 0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2 */

#[test]
fn test_derive_master_key() {
use crate::curve::TestCurve as C;
use crate::curve::TestCurve;

let seed = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
0x0f,
];
let mk_input = MasterKeyInput::new(&seed, CURVE_NAME.into()).unwrap();
let master_key_output = MasterKeyInput::derive_master_key::<C>(&mk_input);
let master_key_output = MasterKeyInput::derive_master_key::<TestCurve>(&mk_input);
assert_eq!(
master_key_output.private_key.to_bytes(),
[
Expand Down Expand Up @@ -238,7 +238,7 @@ fn test_derive_child_key() {
let master_key_output = MasterKeyInput::derive_master_key::<TestCurve>(&mk_input);

// derive the child key
//let pk = TestCT::GENERATOR.mul(&master_key_output.private_key);
//let pk = TestCurve::GENERATOR.mul(&master_key_output.private_key);
//let private_key = master_key_output.private_key;
//let public_key_bytes: Vec<u8> = pk.to_bytes().to_vec();

Expand Down Expand Up @@ -275,9 +275,9 @@ fn test_derive_child_key() {
0x5b, 0xd6, 0xac, 0xe4, 0xa7
]
);
let public_key = TestCT::try_from_bytes(&public_key_bytes).unwrap();
let public_key = TestCurve::try_from_bytes(&public_key_bytes).unwrap();
let ckd_input: CKDInput<TestCT> = CKDInput::new(
let ckd_input: CKDInput<TestCurve> = CKDInput::new(
Some(private_key),
public_key,
master_key_output.chain_code,
Expand All @@ -295,7 +295,7 @@ fn test_derive_child_key() {
]
);*/
// assert the private key (TODO: it only works for K256)
/*let private_key: <TestCT as CT>::Scalar = child_key_output.private_key;
/*let private_key: <TestCurve as CurveTrait>::Scalar = child_key_output.private_key;
assert_eq!(
private_key.to_bytes().as_slice(),
[
Expand Down
3 changes: 0 additions & 3 deletions src/tshare/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,9 +1003,6 @@ pub(crate) mod tests {
use std::{collections::HashMap, iter::zip};
use tracing::debug;

//type Output = super::Output<TestCT>;
//type TshareParticipant = super::TshareParticipant<TestCT>;

/// Test utility to convert the tshares to t-out-of-t shares of all
/// participants.
#[cfg(test)]
Expand Down

0 comments on commit f7f9160

Please sign in to comment.