Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
This reverts commit d9431a1.
  • Loading branch information
frits-metalogix authored Nov 24, 2021
1 parent 8c9704e commit 2b6982b
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ fn map_ebpf_error(invoke_context: &dyn InvokeContext, e: EbpfError<BpfError>) ->
}

pub fn create_executor(
programdata_account_index: usize,
programdata_offset: usize,
program_account_index: usize,
program_data_offset: usize,
invoke_context: &mut dyn InvokeContext,
use_jit: bool,
) -> Result<Arc<BpfExecutor>, InstructionError> {
Expand All @@ -91,9 +91,11 @@ pub fn create_executor(
};
let mut executable = {
let keyed_accounts = invoke_context.get_keyed_accounts()?;
let programdata = keyed_account_at_index(keyed_accounts, programdata_account_index)?;
let program = keyed_account_at_index(keyed_accounts, program_account_index)?;
let account = program.try_account_ref()?;
let data = &account.data()[program_data_offset..];
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
&programdata.try_account_ref()?.data()[programdata_offset..],
data,
None,
config,
syscall_registry,
Expand Down Expand Up @@ -261,7 +263,7 @@ fn process_instruction_common(
Some(executor) => executor,
None => {
let executor = create_executor(
first_instruction_account,
next_first_instruction_account,
program_data_offset,
invoke_context,
use_jit,
Expand Down Expand Up @@ -347,7 +349,7 @@ fn process_loader_upgradeable_instruction(
return Err(InstructionError::InvalidAccountData);
}
write_program_data(
first_instruction_account,
1,
UpgradeableLoaderState::buffer_data_offset()? + offset as usize,
&bytes,
invoke_context,
Expand Down Expand Up @@ -470,12 +472,7 @@ fn process_loader_upgradeable_instruction(
)?;

// Load and verify the program bits
let executor = create_executor(
first_instruction_account + 3,
buffer_data_offset,
invoke_context,
use_jit,
)?;
let executor = create_executor(4, buffer_data_offset, invoke_context, use_jit)?;
invoke_context.add_executor(&new_program_id, executor);

let keyed_accounts = invoke_context.get_keyed_accounts()?;
Expand Down Expand Up @@ -614,12 +611,7 @@ fn process_loader_upgradeable_instruction(
}

// Load and verify the program bits
let executor = create_executor(
first_instruction_account + 2,
buffer_data_offset,
invoke_context,
use_jit,
)?;
let executor = create_executor(3, buffer_data_offset, invoke_context, use_jit)?;
invoke_context.add_executor(&new_program_id, executor);

let keyed_accounts = invoke_context.get_keyed_accounts()?;
Expand Down Expand Up @@ -886,20 +878,15 @@ fn process_loader_instruction(
ic_msg!(invoke_context, "Program account did not sign");
return Err(InstructionError::MissingRequiredSignature);
}
write_program_data(
first_instruction_account,
offset as usize,
&bytes,
invoke_context,
)?;
write_program_data(1, offset as usize, &bytes, invoke_context)?;
}
LoaderInstruction::Finalize => {
if program.signer_key().is_none() {
ic_msg!(invoke_context, "key[0] did not sign the transaction");
return Err(InstructionError::MissingRequiredSignature);
}

let executor = create_executor(first_instruction_account, 0, invoke_context, use_jit)?;
let executor = create_executor(1, 0, invoke_context, use_jit)?;
let keyed_accounts = invoke_context.get_keyed_accounts()?;
let program = keyed_account_at_index(keyed_accounts, first_instruction_account)?;
invoke_context.add_executor(program.unsigned_key(), executor);
Expand Down

0 comments on commit 2b6982b

Please sign in to comment.