@@ -276,7 +276,12 @@ pub struct StmSig<D: Clone + Digest + FixedOutput> {
276276impl < D : Clone + Digest + FixedOutput > StmSig < D > {
277277 /// Verify an stm signature by checking that the lottery was won, the merkle path is correct,
278278 /// the index is in the desired range and the underlying msp signature validates.
279- pub fn verify ( & self , params : & StmParameters , avk : & StmAggrVerificationKey < D > , msg : & [ u8 ] ) -> Result < ( ) , VerificationFailure < D > > {
279+ pub fn verify (
280+ & self ,
281+ params : & StmParameters ,
282+ avk : & StmAggrVerificationKey < D > ,
283+ msg : & [ u8 ] ,
284+ ) -> Result < ( ) , VerificationFailure < D > > {
280285 let msgp = avk. mt_commitment . concat_with_msg ( msg) ;
281286
282287 if self . index > params. m {
@@ -344,7 +349,7 @@ impl<D: Clone + Digest + FixedOutput> StmSig<D> {
344349#[ derive( Debug , Clone , Serialize , Deserialize ) ]
345350pub struct StmAggrVerificationKey < D >
346351where
347- D : Clone + Digest + FixedOutput
352+ D : Clone + Digest + FixedOutput ,
348353{
349354 mt_commitment : MerkleTreeCommitment < D > ,
350355 total_stake : Stake ,
@@ -357,7 +362,7 @@ where
357362 fn from ( reg : & ClosedKeyReg < D > ) -> Self {
358363 Self {
359364 mt_commitment : reg. merkle_tree . to_commitment ( ) ,
360- total_stake : reg. total_stake
365+ total_stake : reg. total_stake ,
361366 }
362367 }
363368}
@@ -419,13 +424,29 @@ impl<D: Clone + Digest + FixedOutput> StmAggrSig<D> {
419424 }
420425
421426 // Check that merkle paths are valid
422- if avk. mt_commitment . check ( & MTLeaf ( sig. pk , sig. stake ) , & sig. path ) . is_err ( ) {
427+ if avk
428+ . mt_commitment
429+ . check ( & MTLeaf ( sig. pk , sig. stake ) , & sig. path )
430+ . is_err ( )
431+ {
423432 return Err ( MithrilWitnessError :: PathInvalid ( sig. path . clone ( ) ) ) ;
424433 }
425434 }
426435
427- let aggregate_signature: Signature = self . signatures . iter ( ) . map ( |sig| sig. sigma ) . collect :: < Vec < Signature > > ( ) . iter ( ) . sum ( ) ;
428- let aggregate_mpk: StmVerificationKey = self . signatures . iter ( ) . map ( |sig| sig. pk ) . collect :: < Vec < StmVerificationKey > > ( ) . iter ( ) . sum ( ) ;
436+ let aggregate_signature: Signature = self
437+ . signatures
438+ . iter ( )
439+ . map ( |sig| sig. sigma )
440+ . collect :: < Vec < Signature > > ( )
441+ . iter ( )
442+ . sum ( ) ;
443+ let aggregate_mpk: StmVerificationKey = self
444+ . signatures
445+ . iter ( )
446+ . map ( |sig| sig. pk )
447+ . collect :: < Vec < StmVerificationKey > > ( )
448+ . iter ( )
449+ . sum ( ) ;
429450
430451 aggregate_signature. verify ( & avk. mt_commitment . concat_with_msg ( msg) , & aggregate_mpk) ?;
431452 Ok ( ( ) )
@@ -633,10 +654,19 @@ where
633654 // sigma <- MSP.Sig(msk, msg')
634655 // ev <- MSP.Eval(msg', index, sigma)
635656 // return 1 if ev < phi(stake) else return 0
636- let msgp = self . closed_reg . merkle_tree . to_commitment ( ) . concat_with_msg ( msg) ;
657+ let msgp = self
658+ . closed_reg
659+ . merkle_tree
660+ . to_commitment ( )
661+ . concat_with_msg ( msg) ;
637662 let sigma = self . sk . sign ( & msgp) ;
638663 let ev = sigma. eval ( & msgp, index) ;
639- ev_lt_phi ( self . params . phi_f , ev, self . stake , self . closed_reg . total_stake )
664+ ev_lt_phi (
665+ self . params . phi_f ,
666+ ev,
667+ self . stake ,
668+ self . closed_reg . total_stake ,
669+ )
640670 }
641671
642672 /// If lottery is won for this message/index, signs it.
@@ -648,9 +678,16 @@ where
648678 // p_i is the users path inside the merkle tree AVK
649679 // reg_i is (mvk_i, stake_i)
650680 // return pi
651- let msgp = self . closed_reg . merkle_tree . to_commitment ( ) . concat_with_msg ( msg) ;
681+ let msgp = self
682+ . closed_reg
683+ . merkle_tree
684+ . to_commitment ( )
685+ . concat_with_msg ( msg) ;
652686 let sigma = self . sk . sign ( & msgp) ;
653- let path = self . closed_reg . merkle_tree . get_path ( self . mt_index . try_into ( ) . unwrap ( ) ) ;
687+ let path = self
688+ . closed_reg
689+ . merkle_tree
690+ . get_path ( self . mt_index . try_into ( ) . unwrap ( ) ) ;
654691 Some ( StmSig {
655692 sigma,
656693 pk : self . vk ,
@@ -881,10 +918,7 @@ where
881918 /// Create a new `Clerk` from a closed registration instance.
882919 /// todo: why does it consume the closed reg?
883920 pub fn from_registration ( params : StmParameters , closed_reg : ClosedKeyReg < D > ) -> Self {
884- Self {
885- params,
886- closed_reg
887- }
921+ Self { params, closed_reg }
888922 }
889923
890924 /// Creates a Clerk from a Signer.
@@ -927,8 +961,12 @@ where
927961 msig : & StmAggrSig < D > ,
928962 msg : & [ u8 ] ,
929963 ) -> Result < ( ) , MithrilWitnessError < D > > {
930- StmVerifier :: new ( self . closed_reg . merkle_tree . to_commitment ( ) , self . params , self . closed_reg . total_stake )
931- . verify_msig ( msg, msig)
964+ StmVerifier :: new (
965+ self . closed_reg . merkle_tree . to_commitment ( ) ,
966+ self . params ,
967+ self . closed_reg . total_stake ,
968+ )
969+ . verify_msig ( msg, msig)
932970 }
933971
934972 /// Given a slice of `indices` and one of `sigs`, this functions selects a single valid signature
@@ -1096,11 +1134,11 @@ where
10961134 params : StmParameters ,
10971135 total_stake : Stake ,
10981136 ) -> Self {
1099- let avk = StmAggrVerificationKey { mt_commitment , total_stake } ;
1100- Self {
1101- avk ,
1102- params ,
1103- }
1137+ let avk = StmAggrVerificationKey {
1138+ mt_commitment ,
1139+ total_stake ,
1140+ } ;
1141+ Self { avk , params }
11041142 }
11051143
11061144 /// Verify an aggregated signature
0 commit comments