@@ -9,6 +9,7 @@ use rand::{CryptoRng, Rng};
99use curve25519_dalek:: ristretto:: RistrettoPoint ;
1010use curve25519_dalek:: scalar:: Scalar ;
1111
12+ use errors:: MPCError ;
1213use generators:: Generators ;
1314use inner_product_proof;
1415use proof_transcript:: ProofTranscript ;
@@ -28,12 +29,12 @@ impl Dealer {
2829 n : usize ,
2930 m : usize ,
3031 transcript : & ' a mut ProofTranscript ,
31- ) -> Result < DealerAwaitingValueCommitments < ' a , ' b > , & ' static str > {
32- if !n . is_power_of_two ( ) || n > 64 {
33- return Err ( "n is not valid: must be a power of 2, and less than or equal to 64" ) ;
32+ ) -> Result < DealerAwaitingValueCommitments < ' a , ' b > , MPCError > {
33+ if !( n == 8 || n == 16 || n == 32 || n == 64 ) {
34+ return Err ( MPCError :: InvalidBitsize ) ;
3435 }
3536 if !m. is_power_of_two ( ) {
36- return Err ( "m is not valid: must be a power of 2" ) ;
37+ return Err ( MPCError :: InvalidAggregation ) ;
3738 }
3839
3940 // At the end of the protocol, the dealer will attempt to
@@ -81,9 +82,9 @@ impl<'a, 'b> DealerAwaitingValueCommitments<'a, 'b> {
8182 pub fn receive_value_commitments (
8283 self ,
8384 value_commitments : Vec < ValueCommitment > ,
84- ) -> Result < ( DealerAwaitingPolyCommitments < ' a , ' b > , ValueChallenge ) , & ' static str > {
85+ ) -> Result < ( DealerAwaitingPolyCommitments < ' a , ' b > , ValueChallenge ) , MPCError > {
8586 if self . m != value_commitments. len ( ) {
86- return Err ( "Length of value commitments doesn't match expected length m" ) ;
87+ return Err ( MPCError :: WrongNumValueCommitments ) ;
8788 }
8889
8990 // Commit each V_j individually
@@ -137,9 +138,9 @@ impl<'a, 'b> DealerAwaitingPolyCommitments<'a, 'b> {
137138 pub fn receive_poly_commitments (
138139 self ,
139140 poly_commitments : Vec < PolyCommitment > ,
140- ) -> Result < ( DealerAwaitingProofShares < ' a , ' b > , PolyChallenge ) , & ' static str > {
141+ ) -> Result < ( DealerAwaitingProofShares < ' a , ' b > , PolyChallenge ) , MPCError > {
141142 if self . m != poly_commitments. len ( ) {
142- return Err ( "Length of poly commitments doesn't match expected length m" ) ;
143+ return Err ( MPCError :: WrongNumPolyCommitments ) ;
143144 }
144145
145146 // Commit sums of T_1_j's and T_2_j's
@@ -195,9 +196,9 @@ impl<'a, 'b> DealerAwaitingProofShares<'a, 'b> {
195196 /// Used as a helper function by `receive_trusted_shares` (which
196197 /// just hands back the result) and `receive_shares` (which
197198 /// validates the proof shares.
198- fn assemble_shares ( & mut self , proof_shares : & [ ProofShare ] ) -> Result < RangeProof , & ' static str > {
199+ fn assemble_shares ( & mut self , proof_shares : & [ ProofShare ] ) -> Result < RangeProof , MPCError > {
199200 if self . m != proof_shares. len ( ) {
200- return Err ( "Length of proof shares doesn't match expected length m" ) ;
201+ return Err ( MPCError :: WrongNumProofShares ) ;
201202 }
202203
203204 let t_x: Scalar = proof_shares. iter ( ) . map ( |ps| ps. t_x ) . sum ( ) ;
@@ -255,19 +256,17 @@ impl<'a, 'b> DealerAwaitingProofShares<'a, 'b> {
255256 mut self ,
256257 rng : & mut R ,
257258 proof_shares : & [ ProofShare ] ,
258- ) -> Result < RangeProof , & ' static str > {
259+ ) -> Result < RangeProof , MPCError > {
259260 let proof = self . assemble_shares ( proof_shares) ?;
260261
261262 let V : Vec < _ > = self . value_commitments . iter ( ) . map ( |vc| vc. V_j ) . collect ( ) ;
262263
263264 // See comment in `Dealer::new` for why we use `initial_transcript`
264- if proof
265- . verify ( & V , self . gens , & mut self . initial_transcript , rng, self . n )
266- . is_ok ( )
267- {
265+ let transcript = & mut self . initial_transcript ;
266+ if proof. verify ( & V , self . gens , transcript, rng, self . n ) . is_ok ( ) {
268267 Ok ( proof)
269268 } else {
270- // Create a list of bad shares
269+ // Proof verification failed. Now audit the parties:
271270 let mut bad_shares = Vec :: new ( ) ;
272271 for j in 0 ..self . m {
273272 match proof_shares[ j] . audit_share (
@@ -279,13 +278,10 @@ impl<'a, 'b> DealerAwaitingProofShares<'a, 'b> {
279278 & self . poly_challenge ,
280279 ) {
281280 Ok ( _) => { }
282- // XXX pass errors upwards
283281 Err ( _) => bad_shares. push ( j) ,
284282 }
285283 }
286- // XXX pass this upwards
287- println ! ( "bad shares: {:?}" , bad_shares) ;
288- Err ( "proof failed to verify" )
284+ Err ( MPCError :: MalformedProofShares { bad_shares } )
289285 }
290286 }
291287
@@ -305,7 +301,7 @@ impl<'a, 'b> DealerAwaitingProofShares<'a, 'b> {
305301 pub fn receive_trusted_shares (
306302 mut self ,
307303 proof_shares : & [ ProofShare ] ,
308- ) -> Result < RangeProof , & ' static str > {
304+ ) -> Result < RangeProof , MPCError > {
309305 self . assemble_shares ( proof_shares)
310306 }
311307}
0 commit comments