File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -1815,6 +1815,27 @@ pub struct MultiKeySignature {
1815
1815
1816
1816
impl VerifyInput for MultiKeySignature {
1817
1817
fn verify ( & self ) -> anyhow:: Result < ( ) > {
1818
+ if self . public_keys . is_empty ( ) {
1819
+ bail ! ( "MultiKey signature has no public keys" )
1820
+ } else if self . signatures . is_empty ( ) {
1821
+ bail ! ( "MultiKey signature has no signatures" )
1822
+ } else if self . public_keys . len ( ) > MAX_NUM_OF_KEYS {
1823
+ bail ! (
1824
+ "MultiKey signature has over the maximum number of public keys {}" ,
1825
+ MAX_NUM_OF_KEYS
1826
+ )
1827
+ } else if self . signatures . len ( ) > MAX_NUM_OF_SIGS {
1828
+ bail ! (
1829
+ "MultiKey signature has over the maximum number of signatures {}" ,
1830
+ MAX_NUM_OF_SIGS
1831
+ )
1832
+ } else if self . signatures . len ( ) != self . signatures_required as usize {
1833
+ bail ! ( "MultiKey signature does not the number of signatures required" )
1834
+ } else if self . signatures_required == 0 {
1835
+ bail ! ( "MultiKey signature threshold must be greater than 0" )
1836
+ } else if self . signatures_required > MAX_NUM_OF_SIGS as u8 {
1837
+ bail ! ( "MultiKey signature threshold is greater than the maximum number of signatures" )
1838
+ }
1818
1839
let _: AccountAuthenticator = self . try_into ( ) ?;
1819
1840
Ok ( ( ) )
1820
1841
}
Original file line number Diff line number Diff line change @@ -1047,6 +1047,12 @@ impl MultiKey {
1047
1047
"The number of required signatures is 0."
1048
1048
) ;
1049
1049
1050
+ ensure ! (
1051
+ public_keys. len( ) <= MAX_NUM_OF_SIGS , // This max number of signatures is also the max number of public keys.
1052
+ "The number of public keys is greater than {}." ,
1053
+ MAX_NUM_OF_SIGS
1054
+ ) ;
1055
+
1050
1056
ensure ! (
1051
1057
public_keys. len( ) >= signatures_required as usize ,
1052
1058
"The number of public keys is smaller than the number of required signatures, {} < {}" ,
@@ -2089,4 +2095,21 @@ mod tests {
2089
2095
2090
2096
assert ! ( signed_txn. verify_signature( ) . is_err( ) ) ;
2091
2097
}
2098
+
2099
+ #[ test]
2100
+ fn test_multi_key_with_33_keys_fails ( ) {
2101
+ let mut keys = Vec :: new ( ) ;
2102
+ for _ in 0 ..33 {
2103
+ let private_key = Ed25519PrivateKey :: generate ( & mut rand:: thread_rng ( ) ) ;
2104
+ let public_key = private_key. public_key ( ) ;
2105
+ keys. push ( AnyPublicKey :: ed25519 ( public_key) ) ;
2106
+ }
2107
+
2108
+ let result = MultiKey :: new ( keys, 3 ) ;
2109
+ assert ! ( result. is_err( ) ) ;
2110
+ assert_eq ! (
2111
+ result. unwrap_err( ) . to_string( ) ,
2112
+ "The number of public keys is greater than 32."
2113
+ ) ;
2114
+ }
2092
2115
}
You can’t perform that action at this time.
0 commit comments