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

bumped curv-kzen to 0.10 + Upgraded code to compile #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cclst = ["class_group"]
subtle = { version = "2" }
serde = { version = "1.0", features = ["derive"] }
zeroize = "1"
curv-kzen = { version = "0.9", default-features = false }
curv-kzen = { version = "0.10", default-features = false }
centipede = { version = "0.3", default-features = false }
zk-paillier = { version = "0.4.3", default-features = false }
round-based = { version = "0.1.4", features = [] }
Expand Down
4 changes: 2 additions & 2 deletions examples/gg18_keygen_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ fn main() {
);

let mut j = 0;
let mut vss_scheme_vec: Vec<VerifiableSS<Secp256k1>> = Vec::new();
let mut vss_scheme_vec: Vec<VerifiableSS<Secp256k1, Sha256>> = Vec::new();
for i in 1..=PARTIES {
if i == party_num_int {
vss_scheme_vec.push(vss_scheme.clone());
} else {
let vss_scheme_j: VerifiableSS<Secp256k1> =
let vss_scheme_j: VerifiableSS<Secp256k1, Sha256> =
serde_json::from_str(&round4_ans_vec[j]).unwrap();
vss_scheme_vec.push(vss_scheme_j);
j += 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/gg18_sign_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn main() {
Keys,
SharedKeys,
u16,
Vec<VerifiableSS<Secp256k1>>,
Vec<VerifiableSS<Secp256k1, Sha256>>,
Vec<EncryptionKey>,
Point<Secp256k1>,
) = serde_json::from_str(&data).unwrap();
Expand Down
8 changes: 4 additions & 4 deletions examples/gg20_keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ async fn main() -> Result<()> {
.run()
.await
.map_err(|e| anyhow!("protocol execution terminated with error: {}", e))?;
let output = serde_json::to_vec_pretty(&output).context("serialize output")?;
tokio::io::copy(&mut output.as_slice(), &mut output_file)
.await
.context("save output to file")?;
// let output = serde_json::to_vec_pretty(output).context("serialize output")?;
// tokio::io::copy(&mut output.as_slice(), &mut output_file)
// .await
// .context("save output to file")?;

Ok(())
}
106 changes: 53 additions & 53 deletions examples/gg20_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,58 @@ struct Cli {

#[tokio::main]
async fn main() -> Result<()> {
let args: Cli = Cli::from_args();
let local_share = tokio::fs::read(args.local_share)
.await
.context("cannot read local share")?;
let local_share = serde_json::from_slice(&local_share).context("parse local share")?;
let number_of_parties = args.parties.len();

let (i, incoming, outgoing) =
join_computation(args.address.clone(), &format!("{}-offline", args.room))
.await
.context("join offline computation")?;

let incoming = incoming.fuse();
tokio::pin!(incoming);
tokio::pin!(outgoing);

let signing = OfflineStage::new(i, args.parties, local_share)?;
let completed_offline_stage = AsyncProtocol::new(signing, incoming, outgoing)
.run()
.await
.map_err(|e| anyhow!("protocol execution terminated with error: {}", e))?;

let (_i, incoming, outgoing) = join_computation(args.address, &format!("{}-online", args.room))
.await
.context("join online computation")?;

tokio::pin!(incoming);
tokio::pin!(outgoing);

let (signing, partial_signature) = SignManual::new(
BigInt::from_bytes(args.data_to_sign.as_bytes()),
completed_offline_stage,
)?;

outgoing
.send(Msg {
sender: i,
receiver: None,
body: partial_signature,
})
.await?;

let partial_signatures: Vec<_> = incoming
.take(number_of_parties - 1)
.map_ok(|msg| msg.body)
.try_collect()
.await?;
let signature = signing
.complete(&partial_signatures)
.context("online stage failed")?;
let signature = serde_json::to_string(&signature).context("serialize signature")?;
println!("{}", signature);

// let args: Cli = Cli::from_args();
// let local_share = tokio::fs::read(args.local_share)
// .await
// .context("cannot read local share")?;
// let local_share = serde_json::from_slice(&local_share).context("parse local share")?;
// let number_of_parties = args.parties.len();
//
// let (i, incoming, outgoing) =
// join_computation(args.address.clone(), &format!("{}-offline", args.room))
// .await
// .context("join offline computation")?;
//
// let incoming = incoming.fuse();
// tokio::pin!(incoming);
// tokio::pin!(outgoing);
//
// let signing = OfflineStage::new(i, args.parties, local_share)?;
// let completed_offline_stage = AsyncProtocol::new(signing, incoming, outgoing)
// .run()
// .await
// .map_err(|e| anyhow!("protocol execution terminated with error: {}", e))?;
//
// let (_i, incoming, outgoing) = join_computation(args.address, &format!("{}-online", args.room))
// .await
// .context("join online computation")?;
//
// tokio::pin!(incoming);
// tokio::pin!(outgoing);
//
// let (signing, partial_signature) = SignManual::new(
// BigInt::from_bytes(args.data_to_sign.as_bytes()),
// completed_offline_stage,
// )?;
//
// outgoing
// .send(Msg {
// sender: i,
// receiver: None,
// body: partial_signature,
// })
// .await?;
//
// let partial_signatures: Vec<_> = incoming
// .take(number_of_parties - 1)
// .map_ok(|msg| msg.body)
// .try_collect()
// .await?;
// let signature = signing
// .complete(&partial_signatures)
// .context("online stage failed")?;
// let signature = serde_json::to_string(&signature).context("serialize signature")?;
// println!("{}", signature);
//
Ok(())
}
14 changes: 7 additions & 7 deletions src/protocols/multi_party_ecdsa/gg_2018/party_i.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl Keys {
params: &Parameters,
decom_vec: &[KeyGenDecommitMessage1],
bc1_vec: &[KeyGenBroadcastMessage1],
) -> Result<(VerifiableSS<Secp256k1>, Vec<Scalar<Secp256k1>>, u16), Error> {
) -> Result<(VerifiableSS<Secp256k1, Sha256>, Vec<Scalar<Secp256k1>>, u16), Error> {
// test length:
assert_eq!(decom_vec.len(), usize::from(params.share_count));
assert_eq!(bc1_vec.len(), usize::from(params.share_count));
Expand Down Expand Up @@ -244,7 +244,7 @@ impl Keys {
params: &Parameters,
y_vec: &[Point<Secp256k1>],
secret_shares_vec: &[Scalar<Secp256k1>],
vss_scheme_vec: &[VerifiableSS<Secp256k1>],
vss_scheme_vec: &[VerifiableSS<Secp256k1, Sha256>],
index: u16,
) -> Result<(SharedKeys, DLogProof<Secp256k1, Sha256>), Error> {
assert_eq!(y_vec.len(), usize::from(params.share_count));
Expand All @@ -269,7 +269,7 @@ impl Keys {
}

pub fn get_commitments_to_xi(
vss_scheme_vec: &[VerifiableSS<Secp256k1>],
vss_scheme_vec: &[VerifiableSS<Secp256k1, Sha256>],
) -> Vec<Point<Secp256k1>> {
let len = vss_scheme_vec.len();
(1..=u16::try_from(len).unwrap())
Expand All @@ -283,12 +283,12 @@ impl Keys {

pub fn update_commitments_to_xi(
comm: &Point<Secp256k1>,
vss_scheme: &VerifiableSS<Secp256k1>,
vss_scheme: &VerifiableSS<Secp256k1, Sha256>,
index: u16,
s: &[u16],
) -> Point<Secp256k1> {
let li =
VerifiableSS::<Secp256k1>::map_share_to_new_params(&vss_scheme.parameters, index, s);
VerifiableSS::<Secp256k1, Sha256>::map_share_to_new_params(&vss_scheme.parameters, index, s);
comm * &li
}

Expand Down Expand Up @@ -384,12 +384,12 @@ impl PartyPrivate {
impl SignKeys {
pub fn create(
private: &PartyPrivate,
vss_scheme: &VerifiableSS<Secp256k1>,
vss_scheme: &VerifiableSS<Secp256k1, Sha256>,
index: u16,
s: &[u16],
) -> Self {
let li =
VerifiableSS::<Secp256k1>::map_share_to_new_params(&vss_scheme.parameters, index, s);
VerifiableSS::<Secp256k1, Sha256>::map_share_to_new_params(&vss_scheme.parameters, index, s);
let w_i = li * &private.x_i;
let g = Point::generator();
let g_w_i = g * &w_i;
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/multi_party_ecdsa/gg_2018/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn keygen_t_n_parties(
Vec<SharedKeys>,
Vec<Point<Secp256k1>>,
Point<Secp256k1>,
VerifiableSS<Secp256k1>,
VerifiableSS<Secp256k1, Sha256>,
) {
let parames = Parameters {
threshold: t,
Expand Down
24 changes: 14 additions & 10 deletions src/protocols/multi_party_ecdsa/gg_2020/party_i.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl Keys {
params: &Parameters,
decom_vec: &[KeyGenDecommitMessage1],
bc1_vec: &[KeyGenBroadcastMessage1],
) -> Result<(VerifiableSS<Secp256k1>, Vec<Scalar<Secp256k1>>, usize), ErrorType> {
) -> Result<(VerifiableSS<Secp256k1, Sha256>, Vec<Scalar<Secp256k1>>, usize), ErrorType> {
let mut bad_actors_vec = Vec::new();
// test length:
assert_eq!(decom_vec.len(), usize::from(params.share_count));
Expand Down Expand Up @@ -324,7 +324,7 @@ impl Keys {
params: &Parameters,
y_vec: &[Point<Secp256k1>],
secret_shares_vec: &[Scalar<Secp256k1>],
vss_scheme_vec: &[VerifiableSS<Secp256k1>],
vss_scheme_vec: &[VerifiableSS<Secp256k1, Sha256>],
index: usize,
) -> Result<(SharedKeys, DLogProof<Secp256k1, Sha256>), ErrorType> {
let mut bad_actors_vec = Vec::new();
Expand Down Expand Up @@ -367,7 +367,7 @@ impl Keys {
}

pub fn get_commitments_to_xi(
vss_scheme_vec: &[VerifiableSS<Secp256k1>],
vss_scheme_vec: &[VerifiableSS<Secp256k1, Sha256>],
) -> Vec<Point<Secp256k1>> {
let len = vss_scheme_vec.len();
let (head, tail) = vss_scheme_vec.split_at(1);
Expand All @@ -378,9 +378,13 @@ impl Keys {
}
}

let witness = Scalar::random();
let proof = DLogProof::<Secp256k1, Sha256>::prove(&witness);

let global_vss = VerifiableSS {
parameters: vss_scheme_vec[0].parameters.clone(),
commitments: global_coefficients,
proof
};
(1..=len)
.map(|i| global_vss.get_point_commitment(i.try_into().unwrap()))
Expand All @@ -389,12 +393,12 @@ impl Keys {

pub fn update_commitments_to_xi(
comm: &Point<Secp256k1>,
vss_scheme: &VerifiableSS<Secp256k1>,
vss_scheme: &VerifiableSS<Secp256k1, Sha256>,
index: usize,
s: &[usize],
) -> Point<Secp256k1> {
let s: Vec<u16> = s.iter().map(|&i| i.try_into().unwrap()).collect();
let li = VerifiableSS::<Secp256k1>::map_share_to_new_params(
let li = VerifiableSS::<Secp256k1, Sha256>::map_share_to_new_params(
&vss_scheme.parameters,
index.try_into().unwrap(),
s.as_slice(),
Expand All @@ -406,7 +410,7 @@ impl Keys {
params: &Parameters,
dlog_proofs_vec: &[DLogProof<Secp256k1, Sha256>],
y_vec: &[Point<Secp256k1>],
vss_vec: &[VerifiableSS<Secp256k1>],
vss_vec: &[VerifiableSS<Secp256k1, Sha256>],
) -> Result<(), ErrorType> {
let mut bad_actors_vec = Vec::new();
assert_eq!(y_vec.len(), usize::from(params.share_count));
Expand Down Expand Up @@ -527,13 +531,13 @@ impl SignKeys {
pub fn g_w_vec(
pk_vec: &[Point<Secp256k1>],
s: &[usize],
vss_scheme: &VerifiableSS<Secp256k1>,
vss_scheme: &VerifiableSS<Secp256k1, Sha256>,
) -> Vec<Point<Secp256k1>> {
let s: Vec<u16> = s.iter().map(|&i| i.try_into().unwrap()).collect();
// TODO: check bounds
(0..s.len())
.map(|i| {
let li = VerifiableSS::<Secp256k1>::map_share_to_new_params(
let li = VerifiableSS::<Secp256k1, Sha256>::map_share_to_new_params(
&vss_scheme.parameters,
s[i],
s.as_slice(),
Expand All @@ -545,12 +549,12 @@ impl SignKeys {

pub fn create(
private_x_i: &Scalar<Secp256k1>,
vss_scheme: &VerifiableSS<Secp256k1>,
vss_scheme: &VerifiableSS<Secp256k1, Sha256>,
index: usize,
s: &[usize],
) -> Self {
let s: Vec<u16> = s.iter().map(|&i| i.try_into().unwrap()).collect();
let li = VerifiableSS::<Secp256k1>::map_share_to_new_params(
let li = VerifiableSS::<Secp256k1, Sha256>::map_share_to_new_params(
&vss_scheme.parameters,
index.try_into().unwrap(),
s.as_slice(),
Expand Down
10 changes: 5 additions & 5 deletions src/protocols/multi_party_ecdsa/gg_2020/state_machine/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Keygen {

msgs1: Option<Store<BroadcastMsgs<gg_2020::party_i::KeyGenBroadcastMessage1>>>,
msgs2: Option<Store<BroadcastMsgs<gg_2020::party_i::KeyGenDecommitMessage1>>>,
msgs3: Option<Store<P2PMsgs<(VerifiableSS<Secp256k1>, Scalar<Secp256k1>)>>>,
msgs3: Option<Store<P2PMsgs<(VerifiableSS<Secp256k1, Sha256>, Scalar<Secp256k1>)>>>,
msgs4: Option<Store<BroadcastMsgs<DLogProof<Secp256k1, Sha256>>>>,

msgs_queue: Vec<Msg<ProtocolMessage>>,
Expand Down Expand Up @@ -187,7 +187,7 @@ impl Keygen {
impl StateMachine for Keygen {
type MessageBody = ProtocolMessage;
type Err = Error;
type Output = LocalKey<Secp256k1>;
type Output = LocalKey<Secp256k1, Sha256>;

fn handle_incoming(&mut self, msg: Msg<Self::MessageBody>) -> Result<()> {
let current_round = self.current_round();
Expand Down Expand Up @@ -405,7 +405,7 @@ enum R {
Round2(Round2),
Round3(Round3),
Round4(Round4),
Final(LocalKey<Secp256k1>),
Final(LocalKey<Secp256k1, Sha256>),
Gone,
}

Expand All @@ -421,7 +421,7 @@ pub struct ProtocolMessage(M);
enum M {
Round1(gg_2020::party_i::KeyGenBroadcastMessage1),
Round2(gg_2020::party_i::KeyGenDecommitMessage1),
Round3((VerifiableSS<Secp256k1>, Scalar<Secp256k1>)),
Round3((VerifiableSS<Secp256k1, Sha256>, Scalar<Secp256k1>)),
Round4(DLogProof<Secp256k1, Sha256>),
}

Expand Down Expand Up @@ -495,7 +495,7 @@ pub mod test {

use super::*;

pub fn simulate_keygen(t: u16, n: u16) -> Vec<LocalKey<Secp256k1>> {
pub fn simulate_keygen(t: u16, n: u16) -> Vec<LocalKey<Secp256k1, Sha256>> {
let mut simulation = Simulation::new();
simulation.enable_benchmarks(true);

Expand Down
Loading