Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature gate is_builtin when checking for account executable #298

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions programs/system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ serde = { workspace = true }
serde_derive = { workspace = true }
solana-program-runtime = { workspace = true }
solana-sdk = { workspace = true }
test-case = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
Expand Down
87 changes: 87 additions & 0 deletions programs/system/src/system_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ mod tests {
#[allow(deprecated)]
use solana_sdk::{
account::{self, Account, AccountSharedData, ReadableAccount},
feature_set::{self, FeatureSet},
fee_calculator::FeeCalculator,
hash::{hash, Hash},
instruction::{AccountMeta, Instruction, InstructionError},
Expand All @@ -564,6 +565,8 @@ mod tests {
solana_program_runtime::{
invoke_context::mock_process_instruction, with_mock_invoke_context,
},
std::sync::Arc,
test_case::test_case,
};

impl From<Pubkey> for Address {
Expand All @@ -575,6 +578,33 @@ mod tests {
}
}

fn process_instruction_toggle_feature(
instruction_data: &[u8],
transaction_accounts: Vec<(Pubkey, AccountSharedData)>,
instruction_accounts: Vec<AccountMeta>,
expected_result: Result<(), InstructionError>,
feature_id: &Pubkey,
enable: bool,
) -> Vec<AccountSharedData> {
mock_process_instruction(
&system_program::id(),
Vec::new(),
instruction_data,
transaction_accounts,
instruction_accounts,
expected_result,
Entrypoint::vm,
|invoke_context| {
if !enable {
let mut features = FeatureSet::all_enabled();
features.deactivate(feature_id);
invoke_context.feature_set = Arc::new(features);
}
},
|_invoke_context| {},
)
}

fn process_instruction(
instruction_data: &[u8],
transaction_accounts: Vec<(Pubkey, AccountSharedData)>,
Expand Down Expand Up @@ -2065,4 +2095,61 @@ mod tests {
upgraded_nonce_account
);
}

#[test_case(true; "enable_deprecate_executable_meta_update_in_bpf_loader")]
#[test_case(false; "disable_deprecate_executable_meta_update_in_bpf_loader")]
fn test_assign_native_loader(enable: bool) {
let pubkey = Pubkey::new_unique();
let account = AccountSharedData::new(100, 10, &system_program::id());
let accounts = process_instruction(
&bincode::serialize(&SystemInstruction::Assign {
owner: solana_sdk::native_loader::id(),
})
.unwrap(),
vec![(pubkey, account.clone())],
vec![AccountMeta {
pubkey,
is_signer: true,
is_writable: true,
}],
Ok(()),
);
assert_eq!(accounts[0].owner(), &solana_sdk::native_loader::id());
assert_eq!(accounts[0].lamports(), 100);

let pubkey2 = Pubkey::new_unique();
let expected = if enable {
Err(InstructionError::ExecutableLamportChange)
} else {
Ok(())
};
let accounts = process_instruction_toggle_feature(
&bincode::serialize(&SystemInstruction::Transfer { lamports: 50 }).unwrap(),
vec![
(
pubkey2,
AccountSharedData::new(100, 0, &system_program::id()),
),
(pubkey, accounts[0].clone()),
],
vec![
AccountMeta {
pubkey: pubkey2,
is_signer: true,
is_writable: true,
},
AccountMeta {
pubkey,
is_signer: false,
is_writable: true,
},
],
expected,
&feature_set::deprecate_executable_meta_update_in_bpf_loader::id(),
enable,
);
assert_eq!(accounts[1].owner(), &solana_sdk::native_loader::id());
let expected_lamports = if enable { 100 } else { 150 };
assert_eq!(accounts[1].lamports(), expected_lamports);
}
}
8 changes: 6 additions & 2 deletions sdk/src/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use {
use {
crate::{
account::{is_builtin, is_executable, AccountSharedData, ReadableAccount},
feature_set::FeatureSet,
feature_set::{deprecate_executable_meta_update_in_bpf_loader, FeatureSet},
instruction::InstructionError,
pubkey::Pubkey,
},
Expand Down Expand Up @@ -1041,7 +1041,11 @@ impl<'a> BorrowedAccount<'a> {
/// Returns whether this account is executable (transaction wide)
#[inline]
pub fn is_executable(&self, feature_set: &FeatureSet) -> bool {
is_builtin(&*self.account) || is_executable(&*self.account, feature_set)
if !feature_set.is_active(&deprecate_executable_meta_update_in_bpf_loader::id()) {
is_executable(&*self.account, feature_set)
} else {
is_builtin(&*self.account) || is_executable(&*self.account, feature_set)
}
}

/// Configures whether this account is executable (transaction wide)
Expand Down
Loading