Skip to content

Commit 50bb5b7

Browse files
committed
fix: resolve Issue #5 Hardcoded Rent Calculation
- Replace hardcoded rent constants with Rent::minimum_balance(space) in manage_authority.rs - Use Rent sysvar in all AddAuthority logic (program + tests) - Update TEST_ISSUES.md
1 parent ed951be commit 50bb5b7

5 files changed

Lines changed: 21 additions & 5 deletions

File tree

program/src/processor/manage_authority.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -141,6 +142,10 @@ pub fn process_add_authority(
141142
) {
142143
return Err(ProgramError::IncorrectProgramId);
143144
}
145+
let rent_sysvar_info = account_info_iter
146+
.next()
147+
.ok_or(ProgramError::NotEnoughAccountKeys)?;
148+
let rent = Rent::from_account_info(rent_sysvar_info)?;
144149

145150
// Check removed here, moved to type-specific logic
146151
// if !admin_auth_pda.is_writable() {
@@ -210,10 +215,7 @@ pub fn process_add_authority(
210215
full_auth_data.len()
211216
};
212217
let space = header_size + variable_size;
213-
let rent = (space as u64)
214-
.checked_mul(6960)
215-
.and_then(|val| val.checked_add(897840))
216-
.ok_or(ProgramError::ArithmeticOverflow)?;
218+
let rent_lamports = rent.minimum_balance(space);
217219

218220
// Use secure transfer-allocate-assign pattern to prevent DoS (Issue #4)
219221
let bump_arr = [bump];
@@ -229,7 +231,7 @@ pub fn process_add_authority(
229231
new_auth_pda,
230232
system_program,
231233
space,
232-
rent,
234+
rent_lamports,
233235
program_id,
234236
&seeds,
235237
)?;

tests-e2e/TEST_ISSUES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
**Status**: ✅ Fixed
2323
**Fix**: Removed unused owner keypair from transaction signing to match instruction accounts.
2424

25+
### Issue #6 (DoS): System Program Create Account
26+
**Status**: ✅ Fixed
27+
**Fix**: Implemented Transfer-Allocate-Assign pattern in `utils.rs`. Verified by `dos_attack.rs`.
28+
29+
### Issue #7 (Rent Calc): Hardcoded Rent
30+
**Status**: ✅ Fixed
31+
**Fix**: Replaced hardcoded rent calculations with `Rent::minimum_balance(space)` in `create_wallet.rs` and `manage_authority.rs`. Verified by tests.
32+
2533
## Current Status
2634
All E2E scenarios are PASSING.
2735
- Happy Path

tests-e2e/src/scenarios/cross_wallet_attacks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ pub fn run(ctx: &mut TestContext) -> Result<()> {
130130
AccountMeta::new(owner_a_auth.to_address(), false), // Auth: Owner A (WRONG WALLET)
131131
AccountMeta::new(attacker_auth_b.to_address(), false),
132132
AccountMeta::new_readonly(solana_system_program::id().to_address(), false),
133+
AccountMeta::new_readonly(solana_sysvar::rent::ID.to_address(), false),
133134
AccountMeta::new_readonly(Signer::pubkey(&owner_a).to_address(), true), // Owner A signing
134135
],
135136
data: add_cross_data,

tests-e2e/src/scenarios/failures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ pub fn run(ctx: &mut TestContext) -> Result<()> {
160160
AccountMeta::new_readonly(owner_auth_pda.to_address(), false), // auth
161161
AccountMeta::new(spender_auth_pda.to_address(), false), // target
162162
AccountMeta::new_readonly(solana_system_program::id().to_address(), false),
163+
AccountMeta::new_readonly(solana_sysvar::rent::ID.to_address(), false),
163164
AccountMeta::new_readonly(Signer::pubkey(&owner_keypair).to_address(), true), // signer
164165
],
165166
data: add_spender_data,
@@ -201,6 +202,7 @@ pub fn run(ctx: &mut TestContext) -> Result<()> {
201202
AccountMeta::new_readonly(spender_auth_pda.to_address(), false), // Spender auth
202203
AccountMeta::new(bad_admin_pda.to_address(), false), // Target (Bad admin)
203204
AccountMeta::new_readonly(solana_system_program::id().to_address(), false),
205+
AccountMeta::new_readonly(solana_sysvar::rent::ID.to_address(), false),
204206
AccountMeta::new_readonly(Signer::pubkey(&spender_keypair).to_address(), true), // Signer
205207
],
206208
data: malicious_add,
@@ -318,6 +320,7 @@ pub fn run(ctx: &mut TestContext) -> Result<()> {
318320
AccountMeta::new_readonly(owner_auth_pda.to_address(), false), // auth
319321
AccountMeta::new(admin_auth_pda.to_address(), false), // target
320322
AccountMeta::new_readonly(solana_system_program::id().to_address(), false),
323+
AccountMeta::new_readonly(solana_sysvar::rent::ID.to_address(), false),
321324
AccountMeta::new_readonly(Signer::pubkey(&owner_keypair).to_address(), true), // signer
322325
],
323326
data: add_admin_data,

tests-e2e/src/scenarios/happy_path.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ pub fn run(ctx: &mut TestContext) -> Result<()> {
167167
AccountMeta::new_readonly(owner_auth_pda.to_address(), false),
168168
AccountMeta::new(secp_auth_pda.to_address(), false),
169169
AccountMeta::new_readonly(solana_system_program::id().to_address(), false),
170+
AccountMeta::new_readonly(solana_sysvar::rent::ID.to_address(), false),
170171
AccountMeta::new_readonly(Signer::pubkey(&owner_keypair).to_address(), true),
171172
],
172173
data: add_auth_data,
@@ -280,6 +281,7 @@ pub fn run(ctx: &mut TestContext) -> Result<()> {
280281
AccountMeta::new(owner_auth_pda.to_address(), false), // Current Owner
281282
AccountMeta::new(new_owner_pda.to_address(), false), // New Owner
282283
AccountMeta::new_readonly(solana_system_program::id().to_address(), false),
284+
AccountMeta::new_readonly(solana_sysvar::rent::ID.to_address(), false),
283285
AccountMeta::new_readonly(Signer::pubkey(&owner_keypair).to_address(), true),
284286
],
285287
data: transfer_own_data,

0 commit comments

Comments
 (0)