|
1 | 1 | use {
|
2 |
| - crate::entrypoint::inner_process_instruction, |
| 2 | + crate::{entrypoint::inner_process_instruction, processor::check_account_owner}, |
3 | 3 | pinocchio::{account_info::AccountInfo, program_error::ProgramError, ProgramResult},
|
4 | 4 | pinocchio_token_interface::error::TokenError,
|
5 | 5 | };
|
@@ -46,6 +46,54 @@ pub fn process_batch(mut accounts: &[AccountInfo], mut instruction_data: &[u8])
|
46 | 46 | )
|
47 | 47 | };
|
48 | 48 |
|
| 49 | + // Few Instructions require specific account ownership checks when executed |
| 50 | + // in a batch since ownership is only enforced by the runtime at the end of |
| 51 | + // the batch processing. |
| 52 | + // |
| 53 | + // Instructions that do not appear in the list below do not require |
| 54 | + // ownership checks since they either do not modify accounts or the ownership |
| 55 | + // is already checked explicitly. |
| 56 | + if let Some(&discriminator) = ix_data.first() { |
| 57 | + match discriminator { |
| 58 | + // 3 - Transfer |
| 59 | + // 7 - MintTo |
| 60 | + // 8 - Burn |
| 61 | + // 14 - MintToChecked |
| 62 | + // 15 - BurnChecked |
| 63 | + 3 | 7 | 8 | 14 | 15 => { |
| 64 | + let [a0, a1, ..] = ix_accounts else { |
| 65 | + return Err(ProgramError::NotEnoughAccountKeys); |
| 66 | + }; |
| 67 | + check_account_owner(a0)?; |
| 68 | + check_account_owner(a1)?; |
| 69 | + } |
| 70 | + // 12 - TransferChecked |
| 71 | + 12 => { |
| 72 | + let [a0, _, a2, ..] = ix_accounts else { |
| 73 | + return Err(ProgramError::NotEnoughAccountKeys); |
| 74 | + }; |
| 75 | + check_account_owner(a0)?; |
| 76 | + check_account_owner(a2)?; |
| 77 | + } |
| 78 | + // 4 - Approve |
| 79 | + // 5 - Revoke |
| 80 | + // 6 - SetAuthority |
| 81 | + // 9 - CloseAccount |
| 82 | + // 10 - FreezeAccount |
| 83 | + // 11 - ThawAccount |
| 84 | + // 13 - ApproveChecked |
| 85 | + // 22 - InitializeImmutableOwner |
| 86 | + // 38 - WithdrawExcessLamports |
| 87 | + 4..=13 | 22 | 38 => { |
| 88 | + let [a0, ..] = ix_accounts else { |
| 89 | + return Err(ProgramError::NotEnoughAccountKeys); |
| 90 | + }; |
| 91 | + check_account_owner(a0)?; |
| 92 | + } |
| 93 | + _ => {} |
| 94 | + } |
| 95 | + } |
| 96 | + |
49 | 97 | inner_process_instruction(ix_accounts, ix_data)?;
|
50 | 98 |
|
51 | 99 | if data_offset == instruction_data.len() {
|
|
0 commit comments