Skip to content

Commit

Permalink
use PROGRAM_OWNER to check executable on account
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoranYi committed Nov 21, 2023
1 parent ab49dc7 commit 0985839
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions runtime/src/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use {
loaded_programs::LoadedProgramsForTxBatch,
},
solana_sdk::{
account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
account::{Account, AccountSharedData, ReadableAccount, WritableAccount, PROGRAM_OWNERS},
account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
feature_set::{
Expand Down Expand Up @@ -151,6 +151,9 @@ fn load_transaction_accounts(
) -> Result<LoadedTransaction> {
let in_reward_interval = reward_interval == RewardInterval::InsideInterval;

let is_executable =
|account: &AccountSharedData| PROGRAM_OWNERS.iter().any(|v| account.owner() == v);

// NOTE: this check will never fail because `tx` is sanitized
if tx.signatures().is_empty() && fee != 0 {
return Err(TransactionError::MissingSignatureForFee);
Expand Down Expand Up @@ -288,7 +291,7 @@ fn load_transaction_accounts(
return Err(TransactionError::InvalidWritableAccount);
}

if account.executable() {
if is_executable(&account) {
// The upgradeable loader requires the derived ProgramData account
if let Ok(UpgradeableLoaderState::Program {
programdata_address,
Expand All @@ -306,7 +309,7 @@ fn load_transaction_accounts(
return Err(TransactionError::InvalidProgramForExecution);
}
}
} else if account.executable() && message.is_writable(i) {
} else if is_executable(&account) && message.is_writable(i) {
error_counters.invalid_writable_account += 1;
return Err(TransactionError::InvalidWritableAccount);
}
Expand Down Expand Up @@ -363,7 +366,7 @@ fn load_transaction_accounts(
error_counters.account_not_found += 1;
return Err(TransactionError::ProgramAccountNotFound);
}
if !program_account.executable() {
if !is_executable(program_account) {
error_counters.invalid_program_for_execution += 1;
return Err(TransactionError::InvalidProgramForExecution);
}
Expand All @@ -385,7 +388,7 @@ fn load_transaction_accounts(
accounts_db.load_with_fixed_root(ancestors, owner_id)
{
if !native_loader::check_id(owner_account.owner())
|| !owner_account.executable()
|| !is_executable(&owner_account)
{
error_counters.invalid_program_for_execution += 1;
return Err(TransactionError::InvalidProgramForExecution);
Expand Down

0 comments on commit 0985839

Please sign in to comment.