@@ -5,6 +5,7 @@ use pinocchio::{
55 instruction:: Seed ,
66 program_error:: ProgramError ,
77 pubkey:: { find_program_address, Pubkey } ,
8+ sysvars:: rent:: Rent ,
89 ProgramResult ,
910} ;
1011
@@ -68,6 +69,7 @@ impl CreateWalletArgs {
6869/// 3. `[writable]` Vault PDA: Derived from `["vault", wallet_pubkey]`.
6970/// 4. `[writable]` Authority PDA: Derived from `["authority", wallet_pubkey, id_seed]`.
7071/// 5. `[]` System Program.
72+ /// 6. `[]` Rent Sysvar.
7173pub fn process (
7274 program_id : & Pubkey ,
7375 accounts : & [ AccountInfo ] ,
@@ -108,6 +110,12 @@ pub fn process(
108110 let system_program = account_info_iter
109111 . next ( )
110112 . ok_or ( ProgramError :: NotEnoughAccountKeys ) ?;
113+ let rent_sysvar = account_info_iter
114+ . next ( )
115+ . ok_or ( ProgramError :: NotEnoughAccountKeys ) ?;
116+
117+ // Get rent from sysvar (fixes audit issue #5 - hardcoded rent calculations)
118+ let rent = Rent :: from_account_info ( rent_sysvar) ?;
111119
112120 let ( wallet_key, wallet_bump) = find_program_address ( & [ b"wallet" , & args. user_seed ] , program_id) ;
113121 if !sol_assert_bytes_eq ( wallet_pda. key ( ) . as_ref ( ) , wallet_key. as_ref ( ) , 32 ) {
@@ -131,13 +139,7 @@ pub fn process(
131139 // --- 1. Initialize Wallet Account ---
132140 // Calculate rent-exempt balance for fixed 8-byte wallet account layout.
133141 let wallet_space = 8 ;
134- // 897840 + (space * 6960)
135- let rent_base = 897840u64 ;
136- let rent_per_byte = 6960u64 ;
137- let wallet_rent = ( wallet_space as u64 )
138- . checked_mul ( rent_per_byte)
139- . and_then ( |val| val. checked_add ( rent_base) )
140- . ok_or ( ProgramError :: ArithmeticOverflow ) ?;
142+ let wallet_rent = rent. minimum_balance ( wallet_space) ;
141143
142144 // Use secure transfer-allocate-assign pattern to prevent DoS (Issue #4)
143145 let wallet_bump_arr = [ wallet_bump] ;
@@ -182,12 +184,7 @@ pub fn process(
182184 } ;
183185
184186 let auth_space = header_size + variable_size;
185-
186- // Rent calculation: 897840 + (space * 6960)
187- let auth_rent = ( auth_space as u64 )
188- . checked_mul ( 6960 )
189- . and_then ( |val| val. checked_add ( 897840 ) )
190- . ok_or ( ProgramError :: ArithmeticOverflow ) ?;
187+ let auth_rent = rent. minimum_balance ( auth_space) ;
191188
192189 // Use secure transfer-allocate-assign pattern to prevent DoS (Issue #4)
193190 let auth_bump_arr = [ auth_bump] ;
0 commit comments