Cleanup - feature gate of `remove_bpf_loader_incorrect_program_id` (#34843)
Cleanup feature gate of remove_bpf_loader_incorrect_program_id.
This commit is contained in:
parent
b5b829111c
commit
9d132441fd
|
@ -36,8 +36,7 @@ use {
|
||||||
feature_set::{
|
feature_set::{
|
||||||
bpf_account_data_direct_mapping, deprecate_executable_meta_update_in_bpf_loader,
|
bpf_account_data_direct_mapping, deprecate_executable_meta_update_in_bpf_loader,
|
||||||
disable_bpf_loader_instructions, enable_bpf_loader_extend_program_ix,
|
disable_bpf_loader_instructions, enable_bpf_loader_extend_program_ix,
|
||||||
enable_bpf_loader_set_authority_checked_ix, remove_bpf_loader_incorrect_program_id,
|
enable_bpf_loader_set_authority_checked_ix, FeatureSet,
|
||||||
FeatureSet,
|
|
||||||
},
|
},
|
||||||
instruction::{AccountMeta, InstructionError},
|
instruction::{AccountMeta, InstructionError},
|
||||||
loader_instruction::LoaderInstruction,
|
loader_instruction::LoaderInstruction,
|
||||||
|
@ -47,9 +46,7 @@ use {
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
saturating_add_assign,
|
saturating_add_assign,
|
||||||
system_instruction::{self, MAX_PERMITTED_DATA_LENGTH},
|
system_instruction::{self, MAX_PERMITTED_DATA_LENGTH},
|
||||||
transaction_context::{
|
transaction_context::{IndexOfAccount, InstructionContext, TransactionContext},
|
||||||
BorrowedAccount, IndexOfAccount, InstructionContext, TransactionContext,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
std::{
|
std::{
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
|
@ -378,99 +375,6 @@ pub fn process_instruction_inner(
|
||||||
let log_collector = invoke_context.get_log_collector();
|
let log_collector = invoke_context.get_log_collector();
|
||||||
let transaction_context = &invoke_context.transaction_context;
|
let transaction_context = &invoke_context.transaction_context;
|
||||||
let instruction_context = transaction_context.get_current_instruction_context()?;
|
let instruction_context = transaction_context.get_current_instruction_context()?;
|
||||||
|
|
||||||
if !invoke_context
|
|
||||||
.feature_set
|
|
||||||
.is_active(&remove_bpf_loader_incorrect_program_id::id())
|
|
||||||
{
|
|
||||||
fn get_index_in_transaction(
|
|
||||||
instruction_context: &InstructionContext,
|
|
||||||
index_in_instruction: IndexOfAccount,
|
|
||||||
) -> Result<IndexOfAccount, InstructionError> {
|
|
||||||
if index_in_instruction < instruction_context.get_number_of_program_accounts() {
|
|
||||||
instruction_context
|
|
||||||
.get_index_of_program_account_in_transaction(index_in_instruction)
|
|
||||||
} else {
|
|
||||||
instruction_context.get_index_of_instruction_account_in_transaction(
|
|
||||||
index_in_instruction
|
|
||||||
.saturating_sub(instruction_context.get_number_of_program_accounts()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_borrow_account<'a>(
|
|
||||||
transaction_context: &'a TransactionContext,
|
|
||||||
instruction_context: &'a InstructionContext,
|
|
||||||
index_in_instruction: IndexOfAccount,
|
|
||||||
) -> Result<BorrowedAccount<'a>, InstructionError> {
|
|
||||||
if index_in_instruction < instruction_context.get_number_of_program_accounts() {
|
|
||||||
instruction_context
|
|
||||||
.try_borrow_program_account(transaction_context, index_in_instruction)
|
|
||||||
} else {
|
|
||||||
instruction_context.try_borrow_instruction_account(
|
|
||||||
transaction_context,
|
|
||||||
index_in_instruction
|
|
||||||
.saturating_sub(instruction_context.get_number_of_program_accounts()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let first_instruction_account = {
|
|
||||||
let borrowed_root_account =
|
|
||||||
instruction_context.try_borrow_program_account(transaction_context, 0)?;
|
|
||||||
let owner_id = borrowed_root_account.get_owner();
|
|
||||||
if native_loader::check_id(owner_id) {
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let first_account_key = transaction_context.get_key_of_account_at_index(
|
|
||||||
get_index_in_transaction(instruction_context, first_instruction_account)?,
|
|
||||||
)?;
|
|
||||||
let second_account_key = get_index_in_transaction(
|
|
||||||
instruction_context,
|
|
||||||
first_instruction_account.saturating_add(1),
|
|
||||||
)
|
|
||||||
.and_then(|index_in_transaction| {
|
|
||||||
transaction_context.get_key_of_account_at_index(index_in_transaction)
|
|
||||||
});
|
|
||||||
let program_id = instruction_context.get_last_program_key(transaction_context)?;
|
|
||||||
let program_account_index = if first_account_key == program_id {
|
|
||||||
first_instruction_account
|
|
||||||
} else if second_account_key
|
|
||||||
.map(|key| key == program_id)
|
|
||||||
.unwrap_or(false)
|
|
||||||
{
|
|
||||||
first_instruction_account.saturating_add(1)
|
|
||||||
} else {
|
|
||||||
let first_account = try_borrow_account(
|
|
||||||
transaction_context,
|
|
||||||
instruction_context,
|
|
||||||
first_instruction_account,
|
|
||||||
)?;
|
|
||||||
if first_account.is_executable(&invoke_context.feature_set) {
|
|
||||||
ic_logger_msg!(log_collector, "BPF loader is executable");
|
|
||||||
return Err(Box::new(InstructionError::IncorrectProgramId));
|
|
||||||
}
|
|
||||||
first_instruction_account
|
|
||||||
};
|
|
||||||
let program = try_borrow_account(
|
|
||||||
transaction_context,
|
|
||||||
instruction_context,
|
|
||||||
program_account_index,
|
|
||||||
)?;
|
|
||||||
if program.is_executable(&invoke_context.feature_set)
|
|
||||||
&& !check_loader_id(program.get_owner())
|
|
||||||
{
|
|
||||||
ic_logger_msg!(
|
|
||||||
log_collector,
|
|
||||||
"Executable account not owned by the BPF loader"
|
|
||||||
);
|
|
||||||
return Err(Box::new(InstructionError::IncorrectProgramId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let program_account =
|
let program_account =
|
||||||
instruction_context.try_borrow_last_program_account(transaction_context)?;
|
instruction_context.try_borrow_last_program_account(transaction_context)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue