@@ -4,7 +4,7 @@ use pinocchio::{
44 account_info:: AccountInfo ,
55 instruction:: Seed ,
66 program_error:: ProgramError ,
7- pubkey:: { find_program_address, Pubkey } ,
7+ pubkey:: { create_program_address , find_program_address, Pubkey } ,
88 sysvars:: rent:: Rent ,
99 ProgramResult ,
1010} ;
@@ -117,6 +117,15 @@ pub fn process(
117117 // Get rent from sysvar (fixes audit issue #5 - hardcoded rent calculations)
118118 let rent = Rent :: from_account_info ( rent_sysvar) ?;
119119
120+ // Validate system_program is the correct System Program (audit N2)
121+ if !sol_assert_bytes_eq (
122+ system_program. key ( ) . as_ref ( ) ,
123+ & crate :: utils:: SYSTEM_PROGRAM_ID ,
124+ 32 ,
125+ ) {
126+ return Err ( ProgramError :: IncorrectProgramId ) ;
127+ }
128+
120129 let ( wallet_key, wallet_bump) = find_program_address ( & [ b"wallet" , & args. user_seed ] , program_id) ;
121130 if !sol_assert_bytes_eq ( wallet_pda. key ( ) . as_ref ( ) , wallet_key. as_ref ( ) , 32 ) {
122131 return Err ( ProgramError :: InvalidSeeds ) ;
@@ -129,8 +138,13 @@ pub fn process(
129138 return Err ( ProgramError :: InvalidSeeds ) ;
130139 }
131140
132- let ( auth_key, auth_bump) =
133- find_program_address ( & [ b"authority" , wallet_key. as_ref ( ) , id_seed] , program_id) ;
141+ // Use client-provided auth_bump for efficiency (audit N1)
142+ let auth_bump_arr = [ args. auth_bump ] ;
143+ let auth_key = create_program_address (
144+ & [ b"authority" , wallet_key. as_ref ( ) , id_seed, & auth_bump_arr] ,
145+ program_id,
146+ )
147+ . map_err ( |_| ProgramError :: InvalidSeeds ) ?;
134148 if !sol_assert_bytes_eq ( auth_pda. key ( ) . as_ref ( ) , auth_key. as_ref ( ) , 32 ) {
135149 return Err ( ProgramError :: InvalidSeeds ) ;
136150 }
@@ -187,7 +201,7 @@ pub fn process(
187201 let auth_rent = rent. minimum_balance ( auth_space) ;
188202
189203 // Use secure transfer-allocate-assign pattern to prevent DoS (Issue #4)
190- let auth_bump_arr = [ auth_bump] ;
204+ let auth_bump_arr = [ args . auth_bump ] ;
191205 let auth_seeds = [
192206 Seed :: from ( b"authority" ) ,
193207 Seed :: from ( wallet_key. as_ref ( ) ) ,
@@ -211,7 +225,7 @@ pub fn process(
211225 discriminator : AccountDiscriminator :: Authority as u8 ,
212226 authority_type : args. authority_type ,
213227 role : 0 ,
214- bump : auth_bump,
228+ bump : args . auth_bump ,
215229 version : crate :: state:: CURRENT_ACCOUNT_VERSION ,
216230 _padding : [ 0 ; 3 ] ,
217231 counter : 0 ,
0 commit comments