Skip to content

Commit

Permalink
Backport - feature disable_bpf_loader_instructions to v1.17 (#35093)
Browse files Browse the repository at this point in the history
* Adds the feature disable_bpf_loader_instructions.

* Deactivates the feature in the tests and benches.
  • Loading branch information
Lichtso authored Feb 6, 2024
1 parent a4621d8 commit fad585e
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 41 deletions.
35 changes: 30 additions & 5 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ use {
feature_set::{
bpf_account_data_direct_mapping, cap_accounts_data_allocations_per_transaction,
cap_bpf_program_instruction_accounts, delay_visibility_of_program_deployment,
enable_bpf_loader_extend_program_ix, enable_bpf_loader_set_authority_checked_ix,
enable_program_redeployment_cooldown, limit_max_instruction_trace_length,
native_programs_consume_cu, remove_bpf_loader_incorrect_program_id,
disable_bpf_loader_instructions, enable_bpf_loader_extend_program_ix,
enable_bpf_loader_set_authority_checked_ix, enable_program_redeployment_cooldown,
limit_max_instruction_trace_length, native_programs_consume_cu,
remove_bpf_loader_incorrect_program_id,
},
instruction::{AccountMeta, InstructionError},
loader_instruction::LoaderInstruction,
Expand Down Expand Up @@ -509,7 +510,20 @@ pub fn process_instruction_inner(
if native_programs_consume_cu {
invoke_context.consume_checked(DEFAULT_LOADER_COMPUTE_UNITS)?;
}
process_loader_instruction(invoke_context)
// Return `UnsupportedProgramId` error for bpf_loader when
// `disable_bpf_loader_instruction` feature is activated.
if invoke_context
.feature_set
.is_active(&disable_bpf_loader_instructions::id())
{
ic_logger_msg!(
log_collector,
"BPF loader management instructions are no longer supported"
);
Err(InstructionError::UnsupportedProgramId)
} else {
process_loader_instruction(invoke_context)
}
} else if bpf_loader_deprecated::check_id(program_id) {
if native_programs_consume_cu {
invoke_context.consume_checked(DEPRECATED_LOADER_COMPUTE_UNITS)?;
Expand Down Expand Up @@ -1773,6 +1787,7 @@ mod tests {
},
account_utils::StateMut,
clock::Clock,
feature_set::FeatureSet,
instruction::{AccountMeta, InstructionError},
pubkey::Pubkey,
rent::Rent,
Expand Down Expand Up @@ -1811,6 +1826,9 @@ mod tests {
expected_result,
Entrypoint::vm,
|invoke_context| {
let mut features = FeatureSet::all_enabled();
features.deactivate(&disable_bpf_loader_instructions::id());
invoke_context.feature_set = Arc::new(features);
test_utils::load_all_invoked_programs(invoke_context);
},
|_invoke_context| {},
Expand Down Expand Up @@ -2030,6 +2048,9 @@ mod tests {
Err(InstructionError::ProgramFailedToComplete),
Entrypoint::vm,
|invoke_context| {
let mut features = FeatureSet::all_enabled();
features.deactivate(&disable_bpf_loader_instructions::id());
invoke_context.feature_set = Arc::new(features);
invoke_context.mock_set_remaining(0);
test_utils::load_all_invoked_programs(invoke_context);
},
Expand Down Expand Up @@ -2575,7 +2596,11 @@ mod tests {
instruction_accounts,
expected_result,
Entrypoint::vm,
|_invoke_context| {},
|invoke_context| {
let mut features = FeatureSet::all_enabled();
features.deactivate(&disable_bpf_loader_instructions::id());
invoke_context.feature_set = Arc::new(features);
},
|_invoke_context| {},
)
}
Expand Down
11 changes: 9 additions & 2 deletions programs/sbf/benches/bpf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use {
bpf_loader,
client::SyncClient,
entrypoint::SUCCESS,
feature_set::FeatureSet,
feature_set::{self, FeatureSet},
instruction::{AccountMeta, Instruction},
message::Message,
native_loader,
Expand Down Expand Up @@ -183,10 +183,17 @@ fn bench_program_alu(bencher: &mut Bencher) {
#[bench]
fn bench_program_execute_noop(bencher: &mut Bencher) {
let GenesisConfigInfo {
genesis_config,
mut genesis_config,
mint_keypair,
..
} = create_genesis_config(50);

// deactivate `disable_bpf_loader_instructions` feature so that the program
// can be loaded, finalized and benched.
genesis_config
.accounts
.remove(&feature_set::disable_bpf_loader_instructions::id());

let bank = Bank::new_for_benches(&genesis_config);
let bank = Arc::new(bank);
let mut bank_client = BankClient::new_shared(bank.clone());
Expand Down
Loading

0 comments on commit fad585e

Please sign in to comment.