diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 97323bf0f62ecb..f32e769f0170e7 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -241,7 +241,6 @@ impl Accounts { let rent_for_sysvars = feature_set.is_active(&feature_set::rent_for_sysvars::id()); let demote_program_write_locks = feature_set.is_active(&feature_set::demote_program_write_locks::id()); - let is_upgradeable_loader_present = is_upgradeable_loader_present(message); for (i, key) in message.account_keys_iter().enumerate() { let account = if !message.is_non_loader_key(i) { @@ -280,7 +279,7 @@ impl Accounts { if bpf_loader_upgradeable::check_id(account.owner()) { if demote_program_write_locks && message.is_writable(i, demote_program_write_locks) - && !is_upgradeable_loader_present + && !message.is_upgradeable_loader_present() { error_counters.invalid_writable_account += 1; return Err(TransactionError::InvalidWritableAccount); @@ -1133,12 +1132,6 @@ pub fn prepare_if_nonce_account( false } -fn is_upgradeable_loader_present(message: &SanitizedMessage) -> bool { - message - .account_keys_iter() - .any(|&key| key == bpf_loader_upgradeable::id()) -} - pub fn create_test_accounts( accounts: &Accounts, pubkeys: &mut Vec, diff --git a/sdk/program/src/message/legacy.rs b/sdk/program/src/message/legacy.rs index 21742b837da0f3..456ea95808661d 100644 --- a/sdk/program/src/message/legacy.rs +++ b/sdk/program/src/message/legacy.rs @@ -503,6 +503,13 @@ impl Message { } false } + + /// Returns true if any account is the bpf upgradeable loader + pub fn is_upgradeable_loader_present(&self) -> bool { + self.account_keys + .iter() + .any(|&key| key == bpf_loader_upgradeable::id()) + } } #[cfg(test)] diff --git a/sdk/program/src/message/mapped.rs b/sdk/program/src/message/mapped.rs index 0f30e35238db07..3d8bec3885b63a 100644 --- a/sdk/program/src/message/mapped.rs +++ b/sdk/program/src/message/mapped.rs @@ -1,5 +1,6 @@ use { crate::{ + bpf_loader_upgradeable, message::{legacy::BUILTIN_PROGRAMS_KEYS, v0}, pubkey::Pubkey, sysvar, @@ -116,6 +117,12 @@ impl MappedMessage { false } } + + /// Returns true if any account is the bpf upgradeable loader + pub fn is_upgradeable_loader_present(&self) -> bool { + self.account_keys_iter() + .any(|&key| key == bpf_loader_upgradeable::id()) + } } #[cfg(test)] diff --git a/sdk/program/src/message/sanitized.rs b/sdk/program/src/message/sanitized.rs index 3b8d3d79755c99..d771f2ca082336 100644 --- a/sdk/program/src/message/sanitized.rs +++ b/sdk/program/src/message/sanitized.rs @@ -308,6 +308,14 @@ impl SanitizedMessage { .saturating_add(num_secp256k1_signatures), ) } + + /// Inspect all message keys for the bpf upgradeable loader + pub fn is_upgradeable_loader_present(&self) -> bool { + match self { + Self::Legacy(message) => message.is_upgradeable_loader_present(), + Self::V0(message) => message.is_upgradeable_loader_present(), + } + } } #[cfg(test)]