Browse Source

Move account validation

febo 5 months ago
parent
commit
938a8cd624
2 changed files with 12 additions and 7 deletions
  1. 7 1
      p-token/src/processor/revoke.rs
  2. 5 6
      p-token/src/processor/shared/burn.rs

+ 7 - 1
p-token/src/processor/revoke.rs

@@ -9,7 +9,7 @@ use {
 
 #[inline(always)]
 pub fn process_revoke(accounts: &[AccountInfo]) -> ProgramResult {
-    let [source_account_info, owner_info, remaining @ ..] = accounts else {
+    let [source_account_info, remaining @ ..] = accounts else {
         return Err(ProgramError::NotEnoughAccountKeys);
     };
 
@@ -18,6 +18,12 @@ pub fn process_revoke(accounts: &[AccountInfo]) -> ProgramResult {
     let source_account =
         unsafe { load_mut::<Account>(source_account_info.borrow_mut_data_unchecked())? };
 
+    // Unpacking the remaining accounts to get the owner account at this point
+    // to maintain the same order as SPL Token.
+    let [owner_info, remaining @ ..] = remaining else {
+        return Err(ProgramError::NotEnoughAccountKeys);
+    };
+
     if source_account.is_frozen()? {
         return Err(TokenError::AccountFrozen.into());
     }

+ 5 - 6
p-token/src/processor/shared/burn.rs

@@ -21,6 +21,11 @@ pub fn process_burn(
     // `load_mut` validates that the account is initialized.
     let source_account =
         unsafe { load_mut::<Account>(source_account_info.borrow_mut_data_unchecked())? };
+    // SAFETY: single mutable borrow to `mint_info` account data and
+    // `load_mut` validates that the mint is initialized; additionally, an
+    // account cannot be both a token account and a mint, so if duplicates are
+    // passed in, one of them will fail the `load_mut` check.
+    let mint = unsafe { load_mut::<Mint>(mint_info.borrow_mut_data_unchecked())? };
 
     if source_account.is_frozen()? {
         return Err(TokenError::AccountFrozen.into());
@@ -36,12 +41,6 @@ pub fn process_burn(
         .checked_sub(amount)
         .ok_or(TokenError::InsufficientFunds)?;
 
-    // SAFETY: single mutable borrow to `mint_info` account data and
-    // `load_mut` validates that the mint is initialized; additionally, an
-    // account cannot be both a token account and a mint, so if duplicates are
-    // passed in, one of them will fail the `load_mut` check.
-    let mint = unsafe { load_mut::<Mint>(mint_info.borrow_mut_data_unchecked())? };
-
     if mint_info.key() != &source_account.mint {
         return Err(TokenError::MintMismatch.into());
     }