Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add secp256r1 #541

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4f8a4a4
Create curve_point file
emmorais Jul 15, 2024
b0af9f5
Minimal use of CurveTrait in pilog.rs
emmorais Jul 15, 2024
e0fec6d
Cover all usage of generator in pilog
emmorais Jul 15, 2024
2d054f9
Using generator from trait in pisch.rs
emmorais Jul 16, 2024
cd3cb2c
Use CurveTrait in more places, not compiling yet
emmorais Jul 17, 2024
d50f9bd
Fix small issue
emmorais Jul 17, 2024
b2bff55
Compiling, but wrong implementation of deserialize
emmorais Jul 17, 2024
520798b
Testing passing after partial use of CurveTrait
emmorais Jul 17, 2024
9a63398
Remove commented code
emmorais Jul 17, 2024
897e388
Replace IDENTITY call in keyrefresh_commit.rs
emmorais Jul 17, 2024
ed642c9
Call identity() in keygen/output.rs
emmorais Jul 17, 2024
c5db00c
Replace IDENTITY by identity()
emmorais Jul 17, 2024
93f35b8
More use of CurveTrait, not compiling
emmorais Jul 18, 2024
ec97694
Associated type Point in CurveTrait
emmorais Jul 22, 2024
4162354
Continuation, Deserialization missing
emmorais Jul 23, 2024
c074c39
Small improvements
emmorais Jul 25, 2024
b1aae02
Propagate CurveTrait to all places
emmorais Jul 30, 2024
61071cf
Intermediate state of fixing errors
emmorais Aug 5, 2024
e58422d
Fixing more errors
emmorais Aug 5, 2024
2b3de7b
Fixing errors
emmorais Aug 5, 2024
8ed35d4
More error fixing
emmorais Aug 5, 2024
dc064e7
43 errors missing
emmorais Aug 5, 2024
1c1e236
37 errors
emmorais Aug 5, 2024
69666a8
3 errors
emmorais Aug 6, 2024
b1560f8
Undo "where C: 'a" in pilog and piaffg
emmorais Aug 6, 2024
35b25b0
Undo changes to src/zkp/pilog.rs
emmorais Aug 6, 2024
22c1c5e
Warnings
emmorais Aug 6, 2024
1918651
Replace curve order in pisch.rs
emmorais Aug 7, 2024
8d35c4c
Finish curve order replacement in pisch.rs
emmorais Aug 7, 2024
47d8a29
Replace order function in other places
emmorais Aug 7, 2024
273c11c
Finish replacement of order function
emmorais Aug 7, 2024
0bf3db4
Abstract bn_to_scalar in CurveTrait
emmorais Aug 7, 2024
5b7fbca
Remove unneeded code
emmorais Aug 7, 2024
f49fe20
Some adjustments
emmorais Aug 7, 2024
dd37240
Fixing errors
emmorais Aug 9, 2024
4a62bc8
Warnings
emmorais Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions examples/threaded_example/threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ use std::{
use tracing::{debug, info, instrument, span, trace, Level};
use tracing_subscriber::{self, EnvFilter};
use tss_ecdsa::{
auxinfo::AuxInfoParticipant,
keygen::{KeygenParticipant, Output},
messages::Message,
presign::{self, PresignParticipant},
sign::{self, SignParticipant},
Identifier, Participant, ParticipantConfig, ParticipantIdentifier, ProtocolParticipant,
auxinfo::AuxInfoParticipant, curve_point::CurvePoint, keygen::{KeygenParticipant, Output}, messages::Message, presign::{self, PresignParticipant}, sign::{self, SignParticipant}, Identifier, Participant, ParticipantConfig, ParticipantIdentifier, ProtocolParticipant
};
use utils::{MessageFromWorker, SubProtocol};
use uuid::Uuid;
Expand Down Expand Up @@ -326,7 +321,7 @@ struct Worker {
/// Outputs of successful presign.
presign_records: StoredOutput<PresignParticipant>,
/// Signatures generated from successful signing runs.
signatures: StoredOutput<SignParticipant>,
signatures: StoredOutput<SignParticipant<CurvePoint>>,
/// Channel for sending messages to the coordinator.
outgoing: Sender<MessageFromWorker>,
}
Expand Down Expand Up @@ -411,7 +406,7 @@ impl Worker {
fn new_auxinfo(&mut self, sid: SessionId, key_id: KeyId) -> anyhow::Result<()> {
// Note: Missing inputs to aux-info see issues
// #242 and #243.
let _output: &Output = self.key_gen_material.retrieve(&key_id);
let _output: &Output<tss_ecdsa::curve_point::CurvePoint> = self.key_gen_material.retrieve(&key_id);
self.new_sub_protocol::<AuxInfoParticipant>(sid, (), key_id)
}

Expand All @@ -428,7 +423,7 @@ impl Worker {
let record = self.presign_records.take(&key_id);

let inputs = sign::Input::new(b"hello world", record, key_shares.to_vec());
self.new_sub_protocol::<SignParticipant>(sid, inputs, key_id)
self.new_sub_protocol::<SignParticipant<CurvePoint>>(sid, inputs, key_id)
}
}

Expand Down Expand Up @@ -462,7 +457,7 @@ impl Worker {
}

fn process_sign(&mut self, sid: SessionId, incoming: Message) -> anyhow::Result<()> {
let (p, key_id) = self.participants.get_mut::<SignParticipant>(&sid);
let (p, key_id) = self.participants.get_mut::<SignParticipant<CurvePoint>>(&sid);
Self::process_message(p, key_id, incoming, &mut self.signatures, &self.outgoing)
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/auxinfo/auxinfo_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
// of this source tree.

use crate::{
auxinfo::{info::AuxInfoPublic, participant::AuxInfoParticipant},
errors::{InternalError, Result},
messages::{AuxinfoMessageType, Message, MessageType},
parameters::PRIME_BITS,
participant::{InnerProtocolParticipant, ProtocolParticipant},
protocol::{Identifier, ParticipantIdentifier},
auxinfo::{info::AuxInfoPublic, participant::AuxInfoParticipant}, errors::{InternalError, Result}, messages::{AuxinfoMessageType, Message, MessageType}, parameters::PRIME_BITS, participant::{InnerProtocolParticipant, ProtocolParticipant}, protocol::{Identifier, ParticipantIdentifier}
};
use libpaillier::unknown_order::BigNumber;
use merlin::Transcript;
Expand Down
9 changes: 2 additions & 7 deletions src/auxinfo/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
// of this source tree.

use crate::{
errors::{CallerError, InternalError, Result},
paillier::{DecryptionKey, EncryptionKey},
ring_pedersen::VerifiedRingPedersen,
utils::ParseBytes,
zkp::ProofContext,
ParticipantIdentifier,
errors::{CallerError, InternalError, Result}, paillier::{DecryptionKey, EncryptionKey}, ring_pedersen::VerifiedRingPedersen, utils::ParseBytes, zkp::ProofContext, ParticipantIdentifier
};
use k256::elliptic_curve::zeroize::ZeroizeOnDrop;
use libpaillier::unknown_order::BigNumber;
Expand Down Expand Up @@ -210,7 +205,7 @@ impl Debug for AuxInfoWitnesses {

#[cfg(test)]
mod tests {
use crate::{paillier::DecryptionKey, utils::testing::init_testing};
use crate::{paillier::DecryptionKey, curve_point::testing::init_testing};

use super::{AuxInfoPrivate, AUXINFO_TAG};

Expand Down
6 changes: 2 additions & 4 deletions src/auxinfo/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
use std::collections::HashSet;

use crate::{
auxinfo::info::{AuxInfoPrivate, AuxInfoPublic},
errors::{CallerError, InternalError, Result},
protocol::ParticipantIdentifier,
auxinfo::info::{AuxInfoPrivate, AuxInfoPublic}, errors::{CallerError, InternalError, Result}, protocol::ParticipantIdentifier
};
use tracing::error;

Expand Down Expand Up @@ -103,7 +101,7 @@ impl Output {
mod tests {
use super::*;
use crate::{
paillier::DecryptionKey, ring_pedersen::VerifiedRingPedersen, utils::testing::init_testing,
paillier::DecryptionKey, ring_pedersen::VerifiedRingPedersen, curve_point::testing::init_testing,
ParticipantConfig,
};

Expand Down
23 changes: 7 additions & 16 deletions src/auxinfo/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,9 @@ use crate::{
info::{AuxInfoPrivate, AuxInfoPublic, AuxInfoWitnesses},
proof::{AuxInfoProof, CommonInput},
Output,
},
broadcast::participant::{BroadcastOutput, BroadcastParticipant, BroadcastTag},
errors::{CallerError, InternalError, Result},
local_storage::LocalStorage,
messages::{AuxinfoMessageType, Message, MessageType},
paillier::DecryptionKey,
participant::{
}, broadcast::participant::{BroadcastOutput, BroadcastParticipant, BroadcastTag}, curve_point::CurvePoint, errors::{CallerError, InternalError, Result}, local_storage::LocalStorage, messages::{AuxinfoMessageType, Message, MessageType}, paillier::DecryptionKey, participant::{
Broadcast, InnerProtocolParticipant, ProcessOutcome, ProtocolParticipant, Status,
},
protocol::{Identifier, ParticipantIdentifier, ProtocolType, SharedContext},
ring_pedersen::VerifiedRingPedersen,
run_only_once,
}, protocol::{Identifier, ParticipantIdentifier, ProtocolType, SharedContext}, ring_pedersen::VerifiedRingPedersen, run_only_once
};
use rand::{CryptoRng, RngCore};
use tracing::{debug, error, info, instrument};
Expand Down Expand Up @@ -221,7 +212,7 @@ impl ProtocolParticipant for AuxInfoParticipant {
}

impl InnerProtocolParticipant for AuxInfoParticipant {
type Context = SharedContext;
type Context = SharedContext<CurvePoint>;

fn retrieve_context(&self) -> <Self as InnerProtocolParticipant>::Context {
SharedContext::collect(self)
Expand Down Expand Up @@ -506,7 +497,7 @@ impl AuxInfoParticipant {
// ... and use its setup parameters in the proof.
let common_input =
CommonInput::new(shared_context, sid, global_rid, self.id(), params, &product);
let proof = AuxInfoProof::prove(rng, &common_input, &witness.p, &witness.q)?;
let proof = AuxInfoProof::prove::<R, CurvePoint>(rng, &common_input, &witness.p, &witness.q)?;
Message::new(
MessageType::Auxinfo(AuxinfoMessageType::R3Proof),
sid,
Expand Down Expand Up @@ -561,7 +552,7 @@ impl AuxInfoParticipant {
);
// Verify the public parameters for the given participant. Note that
// this verification verifies _both_ the `𝚷[mod]` and `𝚷[fac]` proofs.
proof.verify(&common_input)?;
proof.verify::<CurvePoint>(&common_input)?;

self.local_storage
.store_once::<storage::Public>(message.from(), auxinfo_pub)?;
Expand Down Expand Up @@ -621,7 +612,7 @@ impl AuxInfoParticipant {
#[cfg(test)]
mod tests {
use super::*;
use crate::{utils::testing::init_testing, Identifier, ParticipantConfig};
use crate::{curve_point::{testing::init_testing, CurvePoint}, Identifier, ParticipantConfig};
use rand::{CryptoRng, Rng, RngCore};
use std::collections::HashMap;

Expand Down Expand Up @@ -761,7 +752,7 @@ mod tests {
assert_eq!(outputs.len(), QUORUM_SIZE);

let participant_ids = quorum[0].all_participants();
let context = SharedContext::fill_context(participant_ids, sid);
let context: SharedContext<CurvePoint> = SharedContext::fill_context(participant_ids, sid);
// Check returned outputs
//
// Every participant should have a public output from every other participant
Expand Down
45 changes: 20 additions & 25 deletions src/auxinfo/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
// of this source tree.

use crate::{
auxinfo::participant::AuxInfoParticipant,
errors::Result,
messages::{AuxinfoMessageType, Message, MessageType},
participant::InnerProtocolParticipant,
ring_pedersen::VerifiedRingPedersen,
Identifier, ParticipantIdentifier,
auxinfo::participant::AuxInfoParticipant, curve_point::{CurvePoint, CurveTrait}, errors::Result, messages::{AuxinfoMessageType, Message, MessageType}, participant::InnerProtocolParticipant, ring_pedersen::VerifiedRingPedersen, Identifier, ParticipantIdentifier
};

use crate::zkp::{pifac, pimod, Proof, ProofContext};
Expand Down Expand Up @@ -86,28 +81,28 @@ impl AuxInfoProof {
/// Note: The [`VerifiedRingPedersen`] argument **must be** provided by the
/// verifier!
#[allow(clippy::too_many_arguments)]
pub(crate) fn prove<R: RngCore + CryptoRng>(
pub(crate) fn prove<R: RngCore + CryptoRng, C: CurveTrait>(
rng: &mut R,
common_input: &CommonInput,
p: &BigNumber,
q: &BigNumber,
) -> Result<Self> {
let mut transcript = Self::new_transcript();
Self::append_pimod_transcript(
Self::append_pimod_transcript::<CurvePoint>(
&mut transcript,
common_input.shared_context,
common_input.sid,
common_input.rho,
common_input.pid,
)?;
let pimod = pimod::PiModProof::prove(
let pimod: pimod::PiModProof = pimod::PiModProof::prove(
pimod::CommonInput::new(common_input.modulus),
pimod::ProverSecret::new(p, q),
common_input.shared_context,
&mut transcript,
rng,
)?;
Self::append_pifac_transcript(
Self::append_pifac_transcript::<CurvePoint>(
&mut transcript,
common_input.shared_context,
common_input.sid,
Expand All @@ -131,9 +126,9 @@ impl AuxInfoProof {
///
/// Note: The [`VerifiedRingPedersen`] argument **must be** provided by the
/// verifier!
pub(crate) fn verify(self, common_input: &CommonInput) -> Result<()> {
pub(crate) fn verify<C: CurveTrait>(self, common_input: &CommonInput) -> Result<()> {
let mut transcript = Self::new_transcript();
Self::append_pimod_transcript(
Self::append_pimod_transcript::<CurvePoint>(
&mut transcript,
common_input.shared_context,
common_input.sid,
Expand All @@ -145,7 +140,7 @@ impl AuxInfoProof {
common_input.shared_context,
&mut transcript,
)?;
Self::append_pifac_transcript(
Self::append_pifac_transcript::<CurvePoint>(
&mut transcript,
common_input.shared_context,
common_input.sid,
Expand All @@ -162,7 +157,7 @@ impl AuxInfoProof {

/// Append info relevant to the `𝚷[mod]` proof to the provided
/// [`Transcript`].
fn append_pimod_transcript(
fn append_pimod_transcript<C: CurveTrait>(
transcript: &mut Transcript,
context: &<AuxInfoParticipant as InnerProtocolParticipant>::Context,
sid: Identifier,
Expand All @@ -179,7 +174,7 @@ impl AuxInfoProof {

/// Append info relevant to the `𝚷[fac]` proof to the provided
/// [`Transcript`].
fn append_pifac_transcript(
fn append_pifac_transcript<C: CurveTrait>(
transcript: &mut Transcript,
context: &<AuxInfoParticipant as InnerProtocolParticipant>::Context,
sid: Identifier,
Expand All @@ -198,7 +193,7 @@ impl AuxInfoProof {
#[cfg(test)]
mod tests {
use super::*;
use crate::{paillier::prime_gen, protocol::SharedContext, utils::testing::init_testing};
use crate::{curve_point::{testing::init_testing, CurvePoint}, paillier::prime_gen, protocol::SharedContext};
use rand::{rngs::StdRng, Rng, SeedableRng};

fn random_auxinfo_proof<R: RngCore + CryptoRng>(
Expand All @@ -214,7 +209,7 @@ mod tests {
let shared_context = SharedContext::random(rng);
let common_input =
CommonInput::new(&shared_context, sid, rho, pid, &setup_params, &modulus);
let proof = AuxInfoProof::prove(rng, &common_input, &p, &q).unwrap();
let proof = AuxInfoProof::prove::<R, CurvePoint>(rng, &common_input, &p, &q).unwrap();
test_code(common_input, proof)
}

Expand All @@ -230,8 +225,8 @@ mod tests {
let shared_context = SharedContext::random(&mut rng);
let common_input =
CommonInput::new(&shared_context, sid, rho, pid, &setup_params, &modulus);
let proof = AuxInfoProof::prove(&mut rng, &common_input, &p, &q)?;
assert!(proof.verify(&common_input).is_ok());
let proof = AuxInfoProof::prove::<StdRng, CurvePoint>(&mut rng, &common_input, &p, &q)?;
assert!(proof.verify::<CurvePoint>(&common_input).is_ok());
Ok(())
}

Expand All @@ -249,8 +244,8 @@ mod tests {
pifac: proof1.pifac,
pimod: proof.pimod,
};
assert!(mix_one.verify(&input).is_err());
assert!(mix_two.verify(&input1).is_err());
assert!(mix_one.verify::<CurvePoint>(&input).is_err());
assert!(mix_two.verify::<CurvePoint>(&input1).is_err());
Ok(())
};
random_auxinfo_proof(&mut rng2, f1)?;
Expand All @@ -272,8 +267,8 @@ mod tests {
let modulus = &p * &q;
let shared_context = &SharedContext::random(&mut rng);
let common_input = CommonInput::new(shared_context, sid, rho, pid, &setup_params, &modulus);
match AuxInfoProof::prove(&mut rng, &common_input, &p1, &q1) {
Ok(proof) => assert!(proof.verify(&common_input).is_err()),
match AuxInfoProof::prove::<StdRng, CurvePoint>(&mut rng, &common_input, &p1, &q1) {
Ok(proof) => assert!(proof.verify::<CurvePoint>(&common_input).is_err()),
Err(_) => return Ok(()),
}
Ok(())
Expand Down Expand Up @@ -306,8 +301,8 @@ mod tests {
setup_parameters: &setup_params,
modulus: &modulus,
};
match AuxInfoProof::prove(&mut rng, &common_input, &p, &q) {
Ok(proof) => assert!(proof.verify(&bad_common_input).is_err()),
match AuxInfoProof::prove::<StdRng, CurvePoint>(&mut rng, &common_input, &p, &q) {
Ok(proof) => assert!(proof.verify::<CurvePoint>(&bad_common_input).is_err()),
Err(_) => return Ok(()),
}
Ok(())
Expand Down
10 changes: 2 additions & 8 deletions src/broadcast/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
// of this source tree.

use crate::{
broadcast::data::BroadcastData,
errors::{CallerError, InternalError, Result},
local_storage::LocalStorage,
messages::{BroadcastMessageType, Message, MessageType},
participant::{InnerProtocolParticipant, ProcessOutcome, ProtocolParticipant},
protocol::{ParticipantIdentifier, ProtocolType, SharedContext},
run_only_once_per_tag, Identifier,
broadcast::data::BroadcastData, curve_point::CurvePoint, errors::{CallerError, InternalError, Result}, local_storage::LocalStorage, messages::{BroadcastMessageType, Message, MessageType}, participant::{InnerProtocolParticipant, ProcessOutcome, ProtocolParticipant}, protocol::{ParticipantIdentifier, ProtocolType, SharedContext}, run_only_once_per_tag, Identifier
};

use crate::participant::Status;
Expand Down Expand Up @@ -170,7 +164,7 @@ impl ProtocolParticipant for BroadcastParticipant {
}

impl InnerProtocolParticipant for BroadcastParticipant {
type Context = SharedContext;
type Context = SharedContext<CurvePoint>;

/// This method is never used.
fn retrieve_context(&self) -> <Self as InnerProtocolParticipant>::Context {
Expand Down
Loading