@@ -21,6 +21,14 @@ use serde::Serialize;
2121use sui_crypto:: SignatureError ;
2222use sui_sdk_types:: Address ;
2323
24+ /// Default MPC threshold in basis points. Mirrors `DEFAULT_THRESHOLD_IN_BASIS_POINTS` in
25+ /// `mpc_config.move`.
26+ pub const DEFAULT_MPC_THRESHOLD_IN_BASIS_POINTS : u16 = 3334 ;
27+
28+ /// Default allowed delta for weight reduction. Mirrors `DEFAULT_WEIGHT_REDUCTION_ALLOWED_DELTA` in
29+ /// `mpc_config.move`.
30+ pub const DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA : u16 = 800 ;
31+
2432// TODO: Read threshold from on-chain config once it is made configurable.
2533const THRESHOLD_NUMERATOR : u64 = 2 ;
2634const THRESHOLD_DENOMINATOR : u64 = 3 ;
@@ -85,6 +93,8 @@ pub struct Committee {
8593 members : Vec < CommitteeMember > ,
8694 address_to_index : HashMap < Address , usize > ,
8795 total_weight : u64 ,
96+ mpc_threshold_in_basis_points : u16 ,
97+ mpc_weight_reduction_allowed_delta : u16 ,
8898}
8999
90100#[ derive( Clone , PartialEq ) ]
@@ -147,7 +157,12 @@ impl MemberSignature {
147157}
148158
149159impl Committee {
150- pub fn new ( members : Vec < CommitteeMember > , epoch : u64 ) -> Self {
160+ pub fn new (
161+ members : Vec < CommitteeMember > ,
162+ epoch : u64 ,
163+ mpc_threshold_in_basis_points : u16 ,
164+ mpc_weight_reduction_allowed_delta : u16 ,
165+ ) -> Self {
151166 let total_weight = members. iter ( ) . map ( |member| member. weight ) . sum ( ) ;
152167 let address_to_index = members
153168 . iter ( )
@@ -159,6 +174,8 @@ impl Committee {
159174 members,
160175 address_to_index,
161176 total_weight,
177+ mpc_threshold_in_basis_points,
178+ mpc_weight_reduction_allowed_delta,
162179 }
163180 }
164181
@@ -175,6 +192,14 @@ impl Committee {
175192 self . total_weight
176193 }
177194
195+ pub fn mpc_threshold_in_basis_points ( & self ) -> u16 {
196+ self . mpc_threshold_in_basis_points
197+ }
198+
199+ pub fn mpc_weight_reduction_allowed_delta ( & self ) -> u16 {
200+ self . mpc_weight_reduction_allowed_delta
201+ }
202+
178203 fn member ( & self , address : & Address ) -> Result < & CommitteeMember , SignatureError > {
179204 let index = self
180205 . address_to_index
@@ -662,6 +687,9 @@ mod test {
662687 use fastcrypto:: groups:: FiatShamirChallenge ;
663688 use fastcrypto:: groups:: bls12381:: Scalar ;
664689 use fastcrypto:: serde_helpers:: ToFromByteArray ;
690+
691+ const TEST_THRESHOLD_IN_BASIS_POINTS : u16 = 3333 ;
692+ const TEST_WEIGHT_REDUCTION_ALLOWED_DELTA : u16 = 0 ;
665693 use test_strategy:: proptest;
666694
667695 impl proptest:: arbitrary:: Arbitrary for Bls12381PrivateKey {
@@ -719,7 +747,12 @@ mod test {
719747 weight : 1 ,
720748 } )
721749 . collect ( ) ;
722- let committee = Committee :: new ( members, epoch) ;
750+ let committee = Committee :: new (
751+ members,
752+ epoch,
753+ TEST_THRESHOLD_IN_BASIS_POINTS ,
754+ TEST_WEIGHT_REDUCTION_ALLOWED_DELTA ,
755+ ) ;
723756
724757 let mut aggregator = BlsSignatureAggregator :: new ( & committee, message. clone ( ) ) ;
725758
@@ -816,7 +849,12 @@ mod test {
816849 weight : 1 ,
817850 } )
818851 . collect ( ) ;
819- let committee = Committee :: new ( members, epoch) ;
852+ let committee = Committee :: new (
853+ members,
854+ epoch,
855+ TEST_THRESHOLD_IN_BASIS_POINTS ,
856+ TEST_WEIGHT_REDUCTION_ALLOWED_DELTA ,
857+ ) ;
820858
821859 let mut aggregator = BlsSignatureAggregator :: new ( & committee, message. clone ( ) ) ;
822860
@@ -858,6 +896,8 @@ mod test {
858896 } )
859897 . collect ( ) ,
860898 999 , // Different epoch
899+ TEST_THRESHOLD_IN_BASIS_POINTS ,
900+ TEST_WEIGHT_REDUCTION_ALLOWED_DELTA ,
861901 ) ;
862902 assert ! (
863903 certificate
@@ -887,7 +927,12 @@ mod test {
887927 weight : 2500 , // committee weight
888928 } )
889929 . collect ( ) ;
890- let committee = Committee :: new ( members, epoch) ;
930+ let committee = Committee :: new (
931+ members,
932+ epoch,
933+ TEST_THRESHOLD_IN_BASIS_POINTS ,
934+ TEST_WEIGHT_REDUCTION_ALLOWED_DELTA ,
935+ ) ;
891936
892937 // Reduced weights: different from committee weights
893938 let reduced_weights: HashMap < Address , u16 > =
@@ -970,7 +1015,12 @@ mod test {
9701015 weight : 1 ,
9711016 } )
9721017 . collect ( ) ;
973- let committee = Committee :: new ( members, epoch) ;
1018+ let committee = Committee :: new (
1019+ members,
1020+ epoch,
1021+ TEST_THRESHOLD_IN_BASIS_POINTS ,
1022+ TEST_WEIGHT_REDUCTION_ALLOWED_DELTA ,
1023+ ) ;
9741024
9751025 // Create a certificate via aggregator
9761026 let mut aggregator = BlsSignatureAggregator :: new ( & committee, message. clone ( ) ) ;
0 commit comments