22
33use crate :: { error:: BBSPlusError , threshold:: base_ot_phase:: BaseOTPhaseOutput } ;
44use ark_ff:: PrimeField ;
5+ use ark_serialize:: { CanonicalDeserialize , CanonicalSerialize } ;
56use ark_std:: {
67 collections:: { BTreeMap , BTreeSet } ,
78 rand:: RngCore ,
@@ -20,25 +21,35 @@ use oblivious_transfer_protocols::{
2021} ;
2122
2223/// The participant will acts as
23- /// - a receiver in OT extension where its id is less than other participant
24- /// - a sender in OT extension where its id is greater than other participant
25- #[ derive( Clone ) ]
24+ /// - a receiver in OT extension, also called Party2 in multiplication protocol, and its id is less than other participant
25+ /// - a sender in OT extension, also called Party1 in multiplication protocol, and its id is greater than other participant
26+ #[ derive( Clone , CanonicalSerialize , CanonicalDeserialize ) ]
2627pub struct Phase2 < F : PrimeField , const KAPPA : u16 , const STATISTICAL_SECURITY_PARAMETER : u16 > {
2728 pub id : ParticipantId ,
2829 /// Number of threshold signatures being generated in a single batch.
2930 pub batch_size : usize ,
3031 /// Transcripts to record protocol interactions with each participant and later used to generate random challenges
3132 pub transcripts : BTreeMap < ParticipantId , Merlin > ,
3233 pub ote_params : MultiplicationOTEParams < KAPPA , STATISTICAL_SECURITY_PARAMETER > ,
34+ /// Map where this participant plays the role of sender, i.e Party1
3335 pub multiplication_party1 :
3436 BTreeMap < ParticipantId , Party1 < F , KAPPA , STATISTICAL_SECURITY_PARAMETER > > ,
37+ /// Map where this participant plays the role of receiver, i.e Party2
3538 pub multiplication_party2 :
3639 BTreeMap < ParticipantId , Party2 < F , KAPPA , STATISTICAL_SECURITY_PARAMETER > > ,
3740 pub z_A : BTreeMap < ParticipantId , ( Vec < F > , Vec < F > ) > ,
3841 pub z_B : BTreeMap < ParticipantId , ( Vec < F > , Vec < F > ) > ,
3942}
4043
41- #[ derive( Clone , Debug , PartialEq ) ]
44+ /// Message sent from Party2 to Party1 of multiplication protocol
45+ #[ derive( Clone , Debug , PartialEq , CanonicalSerialize , CanonicalDeserialize ) ]
46+ pub struct Message1 < F : PrimeField > ( BitMatrix , KOSRLC , MaskedInputs < F > ) ;
47+
48+ /// Message sent from Party1 to Party2 of multiplication protocol. This message is created after Part1 processes `Message1`
49+ #[ derive( Clone , Debug , PartialEq , CanonicalSerialize , CanonicalDeserialize ) ]
50+ pub struct Message2 < F : PrimeField > ( CorrelationTag < F > , RLC < F > , MaskedInputs < F > ) ;
51+
52+ #[ derive( Clone , Debug , PartialEq , CanonicalSerialize , CanonicalDeserialize ) ]
4253pub struct Phase2Output < F : PrimeField > {
4354 pub z_A : BTreeMap < ParticipantId , ( Vec < F > , Vec < F > ) > ,
4455 pub z_B : BTreeMap < ParticipantId , ( Vec < F > , Vec < F > ) > ,
@@ -56,13 +67,7 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
5667 others : BTreeSet < ParticipantId > ,
5768 ote_params : MultiplicationOTEParams < KAPPA , STATISTICAL_SECURITY_PARAMETER > ,
5869 gadget_vector : & GadgetVector < F , KAPPA , STATISTICAL_SECURITY_PARAMETER > ,
59- ) -> Result <
60- (
61- Self ,
62- BTreeMap < ParticipantId , ( BitMatrix , KOSRLC , MaskedInputs < F > ) > ,
63- ) ,
64- BBSPlusError ,
65- > {
70+ ) -> Result < ( Self , BTreeMap < ParticipantId , Message1 < F > > ) , BBSPlusError > {
6671 assert_eq ! ( masked_signing_key_share. len( ) , masked_r. len( ) ) ;
6772 let batch_size = masked_signing_key_share. len ( ) ;
6873
@@ -108,7 +113,7 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
108113 & gadget_vector,
109114 ) ?;
110115 multiplication_party2. insert ( other, party2) ;
111- Us . insert ( other, ( U , rlc, gamma) ) ;
116+ Us . insert ( other, Message1 ( U , rlc, gamma) ) ;
112117 } else {
113118 return Err ( BBSPlusError :: MissingOTSenderFor ( other) ) ;
114119 }
@@ -130,20 +135,20 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
130135 ) )
131136 }
132137
133- pub fn receive_u < D : Default + DynDigest + Clone > (
138+ /// Process received message from Party2 of multiplication protocol
139+ pub fn receive_message1 < D : Default + DynDigest + Clone > (
134140 & mut self ,
135141 sender_id : ParticipantId ,
136- U : BitMatrix ,
137- rlc : KOSRLC ,
138- gamma : MaskedInputs < F > ,
142+ message : Message1 < F > ,
139143 gadget_vector : & GadgetVector < F , KAPPA , STATISTICAL_SECURITY_PARAMETER > ,
140- ) -> Result < ( CorrelationTag < F > , RLC < F > , MaskedInputs < F > ) , BBSPlusError > {
144+ ) -> Result < Message2 < F > , BBSPlusError > {
141145 if self . multiplication_party2 . contains_key ( & sender_id) {
142146 return Err ( BBSPlusError :: NotAMultiplicationParty2 ( sender_id) ) ;
143147 }
144148 if !self . multiplication_party1 . contains_key ( & sender_id) {
145149 return Err ( BBSPlusError :: NotAMultiplicationParty1 ( sender_id) ) ;
146150 }
151+ let Message1 ( U , rlc, gamma) = message;
147152 let party1 = self . multiplication_party1 . remove ( & sender_id) . unwrap ( ) ;
148153 let trans = self . transcripts . get_mut ( & sender_id) . unwrap ( ) ;
149154
@@ -160,15 +165,14 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
160165 }
161166 }
162167 self . z_A . insert ( sender_id, ( z_A_0, z_A_1) ) ;
163- Ok ( ( tau, r, gamma_a) )
168+ Ok ( Message2 ( tau, r, gamma_a) )
164169 }
165170
166- pub fn receive_tau < D : Default + DynDigest + Clone > (
171+ /// Process received message from Party1 of multiplication protocol
172+ pub fn receive_message2 < D : Default + DynDigest + Clone > (
167173 & mut self ,
168174 sender_id : ParticipantId ,
169- tau : CorrelationTag < F > ,
170- rlc : RLC < F > ,
171- gamma : MaskedInputs < F > ,
175+ message : Message2 < F > ,
172176 gadget_vector : & GadgetVector < F , KAPPA , STATISTICAL_SECURITY_PARAMETER > ,
173177 ) -> Result < ( ) , BBSPlusError > {
174178 if self . multiplication_party1 . contains_key ( & sender_id) {
@@ -177,7 +181,7 @@ impl<F: PrimeField, const KAPPA: u16, const STATISTICAL_SECURITY_PARAMETER: u16>
177181 if !self . multiplication_party2 . contains_key ( & sender_id) {
178182 return Err ( BBSPlusError :: NotAMultiplicationParty2 ( sender_id) ) ;
179183 }
180-
184+ let Message2 ( tau , rlc , gamma ) = message ;
181185 let party2 = self . multiplication_party2 . remove ( & sender_id) . unwrap ( ) ;
182186 let trans = self . transcripts . get_mut ( & sender_id) . unwrap ( ) ;
183187 let shares = party2. receive :: < D > ( tau, rlc, gamma, trans, & gadget_vector) ?;
0 commit comments