4
4
5
5
use crate :: {
6
6
error:: TokenError ,
7
- instruction:: { is_valid_signer_index, AuthorityType , TokenInstruction } ,
7
+ instruction:: { is_valid_signer_index, AuthorityType , TokenInstruction , MAX_SIGNERS } ,
8
8
option:: COption ,
9
9
pack:: { IsInitialized , Pack } ,
10
10
state:: { Account , AccountState , Mint , Multisig } ,
@@ -99,8 +99,8 @@ impl Processor {
99
99
Ok ( ( ) )
100
100
}
101
101
102
- /// Processes a [DangerInitializeMultisig ](enum.TokenInstruction.html) instruction.
103
- pub fn process_danger_initialize_multisig ( accounts : & [ AccountInfo ] , m : u8 ) -> ProgramResult {
102
+ /// Processes a [InitializeMultisig ](enum.TokenInstruction.html) instruction.
103
+ pub fn process_initialize_multisig ( accounts : & [ AccountInfo ] , m : u8 ) -> ProgramResult {
104
104
let account_info_iter = & mut accounts. iter ( ) ;
105
105
let multisig_info = next_account_info ( account_info_iter) ?;
106
106
let multisig_info_data_len = multisig_info. data_len ( ) ;
@@ -637,9 +637,9 @@ impl Processor {
637
637
info ! ( "Instruction: InitializeAccount" ) ;
638
638
Self :: process_initialize_account ( accounts)
639
639
}
640
- TokenInstruction :: DangerInitializeMultisig { m } => {
641
- info ! ( "Instruction: DangerInitializeMultisig " ) ;
642
- Self :: process_danger_initialize_multisig ( accounts, m)
640
+ TokenInstruction :: InitializeMultisig { m } => {
641
+ info ! ( "Instruction: InitializeMultisig " ) ;
642
+ Self :: process_initialize_multisig ( accounts, m)
643
643
}
644
644
TokenInstruction :: Transfer { amount } => {
645
645
info ! ( "Instruction: Transfer" ) ;
@@ -714,14 +714,18 @@ impl Processor {
714
714
{
715
715
let multisig = Multisig :: unpack ( & owner_account_info. data . borrow ( ) ) ?;
716
716
let mut num_signers = 0 ;
717
+ let mut matched = [ false ; MAX_SIGNERS ] ;
717
718
for signer in signers. iter ( ) {
718
- if multisig. signers [ 0 ..multisig. n as usize ] . contains ( signer. key ) {
719
+ for ( position, key) in multisig. signers [ 0 ..multisig. n as usize ] . iter ( ) . enumerate ( ) {
720
+ if key == signer. key && !matched[ position] {
719
721
if !signer. is_signer {
720
722
return Err ( ProgramError :: MissingRequiredSignature ) ;
721
723
}
724
+ matched[ position] = true ;
722
725
num_signers += 1 ;
723
726
}
724
727
}
728
+ }
725
729
if num_signers < multisig. m {
726
730
return Err ( ProgramError :: MissingRequiredSignature ) ;
727
731
}
@@ -3600,8 +3604,7 @@ mod tests {
3600
3604
assert_eq ! (
3601
3605
Err ( TokenError :: NotRentExempt . into( ) ) ,
3602
3606
do_process_instruction(
3603
- danger_initialize_multisig( & program_id, & multisig_key, & [ & signer_keys[ 0 ] ] , 1 )
3604
- . unwrap( ) ,
3607
+ initialize_multisig( & program_id, & multisig_key, & [ & signer_keys[ 0 ] ] , 1 ) . unwrap( ) ,
3605
3608
vec![
3606
3609
& mut multisig_account,
3607
3610
& mut rent_sysvar,
@@ -3615,7 +3618,7 @@ mod tests {
3615
3618
// single signer
3616
3619
let account_info_iter = & mut signer_accounts. iter_mut ( ) ;
3617
3620
do_process_instruction (
3618
- danger_initialize_multisig ( & program_id, & multisig_key, & [ & signer_keys[ 0 ] ] , 1 ) . unwrap ( ) ,
3621
+ initialize_multisig ( & program_id, & multisig_key, & [ & signer_keys[ 0 ] ] , 1 ) . unwrap ( ) ,
3619
3622
vec ! [
3620
3623
& mut multisig_account,
3621
3624
& mut rent_sysvar,
@@ -3627,7 +3630,7 @@ mod tests {
3627
3630
// multiple signer
3628
3631
let account_info_iter = & mut signer_accounts. iter_mut ( ) ;
3629
3632
do_process_instruction (
3630
- danger_initialize_multisig (
3633
+ initialize_multisig (
3631
3634
& program_id,
3632
3635
& multisig_delegate_key,
3633
3636
& signer_key_refs,
@@ -4087,7 +4090,7 @@ mod tests {
4087
4090
{
4088
4091
let mut multisig =
4089
4092
Multisig :: unpack_unchecked ( & owner_account_info. data . borrow ( ) ) . unwrap ( ) ;
4090
- multisig. m = 2 ; // TODO 11?
4093
+ multisig. m = 11 ;
4091
4094
multisig. n = 11 ;
4092
4095
Multisig :: pack ( multisig, & mut owner_account_info. data . borrow_mut ( ) ) . unwrap ( ) ;
4093
4096
}
@@ -4097,6 +4100,34 @@ mod tests {
4097
4100
Processor :: validate_owner( & program_id, & owner_key, & owner_account_info, & signers)
4098
4101
) ;
4099
4102
signers[ 5 ] . is_signer = true ;
4103
+
4104
+ // 11:11, single signer signs multiple times
4105
+ {
4106
+ let mut signer_lamports = 0 ;
4107
+ let mut signer_data = vec ! [ ] ;
4108
+ let signers = vec ! [
4109
+ AccountInfo :: new(
4110
+ & signer_keys[ 5 ] ,
4111
+ true ,
4112
+ false ,
4113
+ & mut signer_lamports,
4114
+ & mut signer_data,
4115
+ & program_id,
4116
+ false ,
4117
+ Epoch :: default ( ) ,
4118
+ ) ;
4119
+ MAX_SIGNERS + 1
4120
+ ] ;
4121
+ let mut multisig =
4122
+ Multisig :: unpack_unchecked ( & owner_account_info. data . borrow ( ) ) . unwrap ( ) ;
4123
+ multisig. m = 11 ;
4124
+ multisig. n = 11 ;
4125
+ Multisig :: pack ( multisig, & mut owner_account_info. data . borrow_mut ( ) ) . unwrap ( ) ;
4126
+ assert_eq ! (
4127
+ Err ( ProgramError :: MissingRequiredSignature ) ,
4128
+ Processor :: validate_owner( & program_id, & owner_key, & owner_account_info, & signers)
4129
+ ) ;
4130
+ }
4100
4131
}
4101
4132
4102
4133
#[ test]
0 commit comments