Skip to content

Commit

Permalink
Update node.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisPapac authored Oct 11, 2023
1 parent bf57c1b commit bb73bea
Showing 1 changed file with 239 additions and 4 deletions.
243 changes: 239 additions & 4 deletions src/modified_scrape/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
errors::PVSSError,
participant::Participant,
pvss::{PVSSCore, PVSSShareSecrets},
share::{PVSSAggregatedShare, PVSSShare},
share::{PVSSAggregatedShare, PVSSShare, SignedProof},
decomp::Decomp,
poly::{Polynomial as Poly}
},
Expand Down Expand Up @@ -45,7 +45,7 @@ where
SSIG: BatchVerifiableSignatureScheme<PublicKey = E::G1Affine, Secret = E::Fr>,
{

// Function for creating a new node in the PVSS sharing protocol.
// Function for initializing a new node in the PVSS sharing protocol.
pub fn new(
config: Config<E>,
scheme_sig: SSIG,
Expand Down Expand Up @@ -73,6 +73,7 @@ where
&mut self,
rng: &mut R,
) -> Result<(PVSSCore<E>, PVSSShareSecrets<E>), PVSSError<E>> {
// Retrieve scheme parameters
let t = self.aggregator.config.degree;
let n = self.aggregator.config.num_participants;

Expand Down Expand Up @@ -143,12 +144,16 @@ where
// Sign the decomposition proof using EdDSA
let signature_on_decomp = Signature::new(&digest, &self.dealer.private_key_ed);

let signed_proof = SignedProof::<E> {
decomp_proof,
signature_on_decomp,
};

// Create the PVSS share.
let share = PVSSShare {
participant_id: self.dealer.participant.id,
pvss_core,
decomp_proof,
signature_on_decomp,
signed_proof,
};

// Set dealer instance's state to DealerShared.
Expand Down Expand Up @@ -244,3 +249,233 @@ mod test {
node.share(rng).unwrap();
}
}
/*
#[test]
fn test_2_nodes_verify() {
const NODES: usize = 4;
let rng = &mut thread_rng();
let srs = SRS::<Bls12_381>::setup(rng).unwrap();
let bls_sig = BLSSignature::<BLSSignatureG1<Bls12_381>> {
srs: BLSSRS {
g_public_key: srs.h_g2,
g_signature: srs.g_g1,
},
};
let dkg_config = Config {
srs: srs.clone(),
u_1,
degree: 2,
};
let mut dealers = vec![];
for i in 0..NODES {
let dealer_keypair_sig = bls_sig.generate_keypair(rng).unwrap();
let participant = Participant {
pairing_type: PhantomData,
id: i,
public_key_sig: dealer_keypair_sig.1,
//state: ParticipantState::Dealer,
};
let dealer = Dealer {
private_key_sig: dealer_keypair_sig.0,
accumulated_secret: G2Projective::zero().into_affine(),
participant,
};
dealers.push(dealer);
}
let participants = dealers
.iter()
.map(|d| d.participant.clone())
.collect::<Vec<_>>();
let mut nodes = vec![];
for i in 0..NODES {
let degree = dkg_config.degree;
let num_participants = participants.len();
let node = Node {
aggregator: DKGAggregator {
config: dkg_config.clone(),
scheme_pok: bls_pok.clone(),
scheme_sig: bls_sig.clone(),
participants: participants.clone().into_iter().enumerate().collect(),
transcript: DKGTranscript::empty(degree, num_participants),
},
dealer: dealers[i].clone(),
};
nodes.push(node);
}
for i in 0..NODES {
let node = &mut nodes[i];
let share = node.share(rng).unwrap();
for j in 0..NODES {
nodes[j]
.receive_share_and_decrypt(rng, share.clone())
.unwrap();
}
}
}
#[test]
fn test_2_nodes_and_aggregator_bls() {
let rng = &mut thread_rng();
let srs = SRS::<Bls12_381>::setup(rng).unwrap();
let bls_sig = BLSSignature::<BLSSignatureG1<Bls12_381>> {
srs: BLSSRS {
g_public_key: srs.h_g2,
g_signature: srs.g_g1,
},
};
let bls_pok = BLSSignature::<BLSSignatureG2<Bls12_381>> {
srs: BLSSRS {
g_public_key: srs.g_g1,
g_signature: srs.h_g2,
},
};
test_2_nodes_and_aggregator_with_signature_scheme(srs, bls_pok, bls_sig);
}
#[test]
fn test_2_nodes_and_aggregator_schnorr() {
let rng = &mut thread_rng();
let srs = SRS::<Bls12_381>::setup(rng).unwrap();
let schnorr_sig = SchnorrSignature::<G2Affine> {
srs: SchnorrSRS {
g_public_key: srs.h_g2,
},
};
let schnorr_pok = SchnorrSignature::<G1Affine> {
srs: SchnorrSRS {
g_public_key: srs.g_g1,
},
};
test_2_nodes_and_aggregator_with_signature_scheme(srs, schnorr_pok, schnorr_sig);
}
fn test_2_nodes_and_aggregator_with_signature_scheme<
SPOK: BatchVerifiableSignatureScheme<PublicKey = G1Affine, Secret = Fr>,
SSIG: BatchVerifiableSignatureScheme<PublicKey = G2Affine, Secret = Fr>,
>(
srs: SRS<Bls12_381>,
spok: SPOK,
ssig: SSIG,
) {
const NODES: usize = 4;
let rng = &mut thread_rng();
let u_1 = G2Projective::rand(rng).into_affine();
let dkg_config = Config {
srs: srs.clone(),
u_1,
degree: 2,
};
let mut dealers = vec![];
for i in 0..NODES {
let dealer_keypair_sig = ssig.generate_keypair(rng).unwrap();
let participant = Participant {
pairing_type: PhantomData,
id: i,
public_key_sig: dealer_keypair_sig.1,
state: ParticipantState::Dealer,
};
let dealer = Dealer {
private_key_sig: dealer_keypair_sig.0,
accumulated_secret: G2Projective::zero().into_affine(),
participant,
};
dealers.push(dealer);
}
let participants = dealers
.iter()
.map(|d| d.participant.clone())
.collect::<Vec<_>>();
let num_participants = participants.len();
let mut aggregator = DKGAggregator {
config: dkg_config.clone(),
scheme_pok: spok.clone(),
scheme_sig: ssig.clone(),
participants: participants.clone().into_iter().enumerate().collect(),
transcript: DKGTranscript::empty(dkg_config.degree, num_participants),
};
let mut nodes = vec![];
for i in 0..NODES {
let degree = dkg_config.degree;
let node = Node {
aggregator: DKGAggregator {
config: dkg_config.clone(),
scheme_pok: spok.clone(),
scheme_sig: ssig.clone(),
participants: participants.clone().into_iter().enumerate().collect(),
transcript: DKGTranscript::empty(degree, num_participants),
},
dealer: dealers[i].clone(),
};
nodes.push(node);
}
// Make participant 0 have weight 2.
// Should ignore participant 1, since we modify its share to be bad.
for i in 0..NODES {
let node = &mut nodes[i];
let mut share = node.share(rng).unwrap();
for j in 0..NODES {
if i == 1 {
share.c_i = G1Projective::rand(rng).into_affine();
}
nodes[j]
.receive_share_and_decrypt(rng, share.clone())
.unwrap();
if i == 0 {
nodes[j]
.receive_share_and_decrypt(rng, share.clone())
.unwrap();
}
}
if i != 1 {
aggregator.receive_share(rng, &share.clone()).unwrap();
if i == 0 {
aggregator.receive_share(rng, &share.clone()).unwrap();
}
} else {
aggregator.receive_share(rng, &share.clone()).unwrap_err();
}
}
let transcript = aggregator.transcript;
for i in 0..NODES {
let degree = dkg_config.degree;
let mut node = Node {
aggregator: DKGAggregator {
config: dkg_config.clone(),
scheme_pok: spok.clone(),
scheme_sig: ssig.clone(),
participants: participants.clone().into_iter().enumerate().collect(),
transcript: DKGTranscript::empty(degree, num_participants),
},
dealer: dealers[i].clone(),
};
node.receive_transcript_and_decrypt(rng, transcript.clone())
.unwrap();
assert_eq!(
node.dealer.accumulated_secret,
nodes[i].dealer.accumulated_secret
);
if i == 0 {
assert_eq!(transcript.contributions[&i].weight, 2);
} else if i == 1 {
assert!(transcript.contributions.get(&i).is_none());
} else {
assert_eq!(transcript.contributions[&i].weight, 1);
}
}
}
}
*/

0 comments on commit bb73bea

Please sign in to comment.