Skip to content

Commit c16f20c

Browse files
committed
Add mint as authority test
1 parent 8aef2d2 commit c16f20c

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

p-token/src/processor/withdraw_excess_lamports.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn process_withdraw_excess_lamports(accounts: &[AccountInfo]) -> ProgramResu
1818
return Err(ProgramError::NotEnoughAccountKeys);
1919
};
2020

21-
// SAFETY: single mutable borrow to `source_account_info` account data
21+
// SAFETY: single immutable borrow to `source_account_info` account data
2222
let source_data = unsafe { source_account_info.borrow_data_unchecked() };
2323

2424
match source_data.len() {
@@ -36,10 +36,25 @@ pub fn process_withdraw_excess_lamports(accounts: &[AccountInfo]) -> ProgramResu
3636
// SAFETY: `source_data` has the same length as `Mint`.
3737
let mint = unsafe { load::<Mint>(source_data)? };
3838

39-
if let Some(mint_authority) = mint.mint_authority() {
40-
validate_owner(mint_authority, authority_info, remaining)?;
41-
} else {
42-
return Err(TokenError::AuthorityTypeNotSupported.into());
39+
match mint.mint_authority() {
40+
Some(mint_authority) => {
41+
validate_owner(mint_authority, authority_info, remaining)?;
42+
}
43+
None if source_account_info == authority_info => {
44+
// Comparing whether the AccountInfo's "point" to the same account or
45+
// not - this is a faster comparison since it just checks the internal
46+
// raw pointer.
47+
//
48+
// This is a special case where there is no mint authority set but the mint
49+
// account is the same as the authority account and, therefore, needs to be
50+
// a signer.
51+
if !authority_info.is_signer() {
52+
return Err(ProgramError::MissingRequiredSignature);
53+
}
54+
}
55+
_ => {
56+
return Err(TokenError::AuthorityTypeNotSupported.into());
57+
}
4358
}
4459
}
4560
Multisig::LEN => {

0 commit comments

Comments
 (0)