Skip to content

Commit 938a8cd

Browse files
committed
Move account validation
1 parent 2f37967 commit 938a8cd

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

p-token/src/processor/revoke.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use {
99

1010
#[inline(always)]
1111
pub fn process_revoke(accounts: &[AccountInfo]) -> ProgramResult {
12-
let [source_account_info, owner_info, remaining @ ..] = accounts else {
12+
let [source_account_info, remaining @ ..] = accounts else {
1313
return Err(ProgramError::NotEnoughAccountKeys);
1414
};
1515

@@ -18,6 +18,12 @@ pub fn process_revoke(accounts: &[AccountInfo]) -> ProgramResult {
1818
let source_account =
1919
unsafe { load_mut::<Account>(source_account_info.borrow_mut_data_unchecked())? };
2020

21+
// Unpacking the remaining accounts to get the owner account at this point
22+
// to maintain the same order as SPL Token.
23+
let [owner_info, remaining @ ..] = remaining else {
24+
return Err(ProgramError::NotEnoughAccountKeys);
25+
};
26+
2127
if source_account.is_frozen()? {
2228
return Err(TokenError::AccountFrozen.into());
2329
}

p-token/src/processor/shared/burn.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ pub fn process_burn(
2121
// `load_mut` validates that the account is initialized.
2222
let source_account =
2323
unsafe { load_mut::<Account>(source_account_info.borrow_mut_data_unchecked())? };
24+
// SAFETY: single mutable borrow to `mint_info` account data and
25+
// `load_mut` validates that the mint is initialized; additionally, an
26+
// account cannot be both a token account and a mint, so if duplicates are
27+
// passed in, one of them will fail the `load_mut` check.
28+
let mint = unsafe { load_mut::<Mint>(mint_info.borrow_mut_data_unchecked())? };
2429

2530
if source_account.is_frozen()? {
2631
return Err(TokenError::AccountFrozen.into());
@@ -36,12 +41,6 @@ pub fn process_burn(
3641
.checked_sub(amount)
3742
.ok_or(TokenError::InsufficientFunds)?;
3843

39-
// SAFETY: single mutable borrow to `mint_info` account data and
40-
// `load_mut` validates that the mint is initialized; additionally, an
41-
// account cannot be both a token account and a mint, so if duplicates are
42-
// passed in, one of them will fail the `load_mut` check.
43-
let mint = unsafe { load_mut::<Mint>(mint_info.borrow_mut_data_unchecked())? };
44-
4544
if mint_info.key() != &source_account.mint {
4645
return Err(TokenError::MintMismatch.into());
4746
}

0 commit comments

Comments
 (0)