Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit de693dc

Browse files
authored
stake-pool: Fail initializing if mint has a freeze authority (#1949)
1 parent 5b34f25 commit de693dc

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

stake-pool/program/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ pub enum StakePoolError {
9696
/// The provided withdraw stake account is not the preferred deposit vote account
9797
#[error("IncorrectWithdrawVoteAddress")]
9898
IncorrectWithdrawVoteAddress,
99+
/// The mint has an invalid freeze authority
100+
#[error("InvalidMintFreezeAuthority")]
101+
InvalidMintFreezeAuthority,
99102
}
100103
impl From<StakePoolError> for ProgramError {
101104
fn from(e: StakePoolError) -> Self {

stake-pool/program/src/processor.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ impl Processor {
488488
return Err(StakePoolError::WrongMintingAuthority.into());
489489
}
490490

491+
if pool_mint.freeze_authority.is_some() {
492+
return Err(StakePoolError::InvalidMintFreezeAuthority.into());
493+
}
494+
491495
if *reserve_stake_info.owner != stake_program::id() {
492496
msg!("Reserve stake account not owned by stake program");
493497
return Err(ProgramError::IncorrectProgramId);
@@ -2099,6 +2103,7 @@ impl PrintProgramError for StakePoolError {
20992103
StakePoolError::StakeLamportsNotEqualToMinimum => msg!("Error: The lamports in the validator stake account is not equal to the minimum"),
21002104
StakePoolError::IncorrectDepositVoteAddress => msg!("Error: The provided deposit stake account is not delegated to the preferred deposit vote account"),
21012105
StakePoolError::IncorrectWithdrawVoteAddress => msg!("Error: The provided withdraw stake account is not the preferred deposit vote account"),
2106+
StakePoolError::InvalidMintFreezeAuthority => msg!("Error: The mint has an invalid freeze authority"),
21022107
}
21032108
}
21042109
}

stake-pool/program/tests/initialize.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,89 @@ async fn fail_with_wrong_mint_authority() {
313313
}
314314
}
315315

316+
#[tokio::test]
317+
async fn fail_with_freeze_authority() {
318+
let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
319+
let stake_pool_accounts = StakePoolAccounts::new();
320+
321+
create_required_accounts(
322+
&mut banks_client,
323+
&payer,
324+
&recent_blockhash,
325+
&stake_pool_accounts,
326+
)
327+
.await;
328+
329+
// create mint with freeze authority
330+
let wrong_mint = Keypair::new();
331+
let rent = banks_client.get_rent().await.unwrap();
332+
let mint_rent = rent.minimum_balance(spl_token::state::Mint::LEN);
333+
334+
let transaction = Transaction::new_signed_with_payer(
335+
&[
336+
system_instruction::create_account(
337+
&payer.pubkey(),
338+
&wrong_mint.pubkey(),
339+
mint_rent,
340+
spl_token::state::Mint::LEN as u64,
341+
&spl_token::id(),
342+
),
343+
spl_token::instruction::initialize_mint(
344+
&spl_token::id(),
345+
&wrong_mint.pubkey(),
346+
&stake_pool_accounts.withdraw_authority,
347+
Some(&stake_pool_accounts.withdraw_authority),
348+
0,
349+
)
350+
.unwrap(),
351+
],
352+
Some(&payer.pubkey()),
353+
&[&payer, &wrong_mint],
354+
recent_blockhash,
355+
);
356+
banks_client.process_transaction(transaction).await.unwrap();
357+
358+
let pool_fee_account = Keypair::new();
359+
create_token_account(
360+
&mut banks_client,
361+
&payer,
362+
&recent_blockhash,
363+
&pool_fee_account,
364+
&wrong_mint.pubkey(),
365+
&stake_pool_accounts.manager.pubkey(),
366+
)
367+
.await
368+
.unwrap();
369+
370+
let error = create_stake_pool(
371+
&mut banks_client,
372+
&payer,
373+
&recent_blockhash,
374+
&stake_pool_accounts.stake_pool,
375+
&stake_pool_accounts.validator_list,
376+
&stake_pool_accounts.reserve_stake.pubkey(),
377+
&wrong_mint.pubkey(),
378+
&pool_fee_account.pubkey(),
379+
&stake_pool_accounts.manager,
380+
&stake_pool_accounts.staker.pubkey(),
381+
&None,
382+
&stake_pool_accounts.fee,
383+
stake_pool_accounts.max_validators,
384+
)
385+
.await
386+
.err()
387+
.unwrap()
388+
.unwrap();
389+
390+
assert_eq!(
391+
error,
392+
TransactionError::InstructionError(
393+
2,
394+
InstructionError::Custom(error::StakePoolError::InvalidMintFreezeAuthority as u32),
395+
)
396+
);
397+
}
398+
316399
#[tokio::test]
317400
async fn fail_with_wrong_token_program_id() {
318401
let (mut banks_client, payer, recent_blockhash) = program_test().start().await;

0 commit comments

Comments
 (0)