Skip to content

Commit

Permalink
Revert "Dont call precompiled programs (solana-labs#19930)"
Browse files Browse the repository at this point in the history
This reverts commit b578765.
  • Loading branch information
frits-metalogix authored Nov 24, 2021
1 parent fec5908 commit 9968635
Show file tree
Hide file tree
Showing 27 changed files with 386 additions and 604 deletions.
25 changes: 23 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ members = [
"programs/bpf_loader",
"programs/compute-budget",
"programs/config",
"programs/ed25519",
"programs/failure",
"programs/noop",
"programs/ownable",
"programs/secp256k1",
"programs/stake",
"programs/vote",
"rbpf-cli",
Expand Down
19 changes: 6 additions & 13 deletions program-runtime/src/instruction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,12 @@ impl InstructionProcessor {
/// Add a static entrypoint to intercept instructions before the dynamic loader.
pub fn add_program(
&mut self,
program_id: &Pubkey,
program_id: Pubkey,
process_instruction: ProcessInstructionWithContext,
) {
match self.programs.iter_mut().find(|(key, _)| program_id == key) {
match self.programs.iter_mut().find(|(key, _)| program_id == *key) {
Some((_, processor)) => *processor = process_instruction,
None => self.programs.push((*program_id, process_instruction)),
}
}

/// Remove a program
pub fn remove_program(&mut self, program_id: &Pubkey) {
if let Some(position) = self.programs.iter().position(|(key, _)| program_id == key) {
self.programs.remove(position);
None => self.programs.push((program_id, process_instruction)),
}
}

Expand Down Expand Up @@ -615,7 +608,7 @@ impl InstructionProcessor {

let mut instruction_processor = InstructionProcessor::default();
for (program_id, process_instruction) in invoke_context.get_programs().iter() {
instruction_processor.add_program(program_id, *process_instruction);
instruction_processor.add_program(*program_id, *process_instruction);
}

let mut result = instruction_processor.process_instruction(
Expand Down Expand Up @@ -1097,8 +1090,8 @@ mod tests {
Ok(())
}
let program_id = solana_sdk::pubkey::new_rand();
instruction_processor.add_program(&program_id, mock_process_instruction);
instruction_processor.add_program(&program_id, mock_ix_processor);
instruction_processor.add_program(program_id, mock_process_instruction);
instruction_processor.add_program(program_id, mock_ix_processor);

assert!(!format!("{:?}", instruction_processor).is_empty());
}
Expand Down
4 changes: 2 additions & 2 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ impl ProgramTest {
// Add loaders
macro_rules! add_builtin {
($b:expr) => {
bank.add_builtin(&$b.0, &$b.1, $b.2)
bank.add_builtin(&$b.0, $b.1, $b.2)
};
}
add_builtin!(solana_bpf_loader_deprecated_program!());
Expand All @@ -795,7 +795,7 @@ impl ProgramTest {
for builtin in self.builtins.iter() {
bank.add_builtin(
&builtin.name,
&builtin.id,
builtin.id,
builtin.process_instruction_with_context,
);
}
Expand Down
16 changes: 16 additions & 0 deletions programs/bpf/Cargo.lock

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

2 changes: 1 addition & 1 deletion programs/bpf/benches/bpf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn bench_program_execute_noop(bencher: &mut Bencher) {
} = create_genesis_config(50);
let mut bank = Bank::new_for_benches(&genesis_config);
let (name, id, entrypoint) = solana_bpf_loader_program!();
bank.add_builtin(&name, &id, entrypoint);
bank.add_builtin(&name, id, entrypoint);
let bank = Arc::new(bank);
let bank_client = BankClient::new_shared(&bank);

Expand Down
19 changes: 3 additions & 16 deletions programs/bpf/c/src/invoke/invoke.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ static const uint8_t TEST_PRIVILEGE_DEESCALATION_ESCALATION_WRITABLE = 13;
static const uint8_t TEST_WRITABLE_DEESCALATION_WRITABLE = 14;
static const uint8_t TEST_NESTED_INVOKE_TOO_DEEP = 15;
static const uint8_t TEST_EXECUTABLE_LAMPORTS = 16;
static const uint8_t TEST_CALL_PRECOMPILE = 17;
static const uint8_t ADD_LAMPORTS = 18;
static const uint8_t TEST_RETURN_DATA_TOO_LARGE = 19;
static const uint8_t ADD_LAMPORTS = 17;
static const uint8_t TEST_RETURN_DATA_TOO_LARGE = 18;

static const int MINT_INDEX = 0;
static const int ARGUMENT_INDEX = 1;
Expand All @@ -41,8 +40,6 @@ static const int DERIVED_KEY2_INDEX = 7;
static const int DERIVED_KEY3_INDEX = 8;
static const int SYSTEM_PROGRAM_INDEX = 9;
static const int FROM_INDEX = 10;
static const int ED25519_PROGRAM_INDEX = 11;
static const int INVOKE_PROGRAM_INDEX = 12;

uint64_t do_nested_invokes(uint64_t num_nested_invokes,
SolAccountInfo *accounts, uint64_t num_accounts) {
Expand Down Expand Up @@ -76,7 +73,7 @@ uint64_t do_nested_invokes(uint64_t num_nested_invokes,
extern uint64_t entrypoint(const uint8_t *input) {
sol_log("Invoke C program");

SolAccountInfo accounts[13];
SolAccountInfo accounts[12];
SolParameters params = (SolParameters){.ka = accounts};

if (!sol_deserialize(input, &params, SOL_ARRAY_SIZE(accounts))) {
Expand Down Expand Up @@ -591,16 +588,6 @@ extern uint64_t entrypoint(const uint8_t *input) {
*accounts[ARGUMENT_INDEX].lamports += 1;
break;
}
case TEST_CALL_PRECOMPILE: {
sol_log("Test calling precompile from cpi");
SolAccountMeta arguments[] = {};
uint8_t data[] = {};
const SolInstruction instruction = {accounts[ED25519_PROGRAM_INDEX].key,
arguments, SOL_ARRAY_SIZE(arguments),
data, SOL_ARRAY_SIZE(data)};
sol_invoke(&instruction, accounts, SOL_ARRAY_SIZE(accounts));
break;
}
case ADD_LAMPORTS: {
*accounts[0].lamports += 1;
break;
Expand Down
12 changes: 1 addition & 11 deletions programs/bpf/rust/invoke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use solana_program::{
account_info::AccountInfo,
entrypoint,
entrypoint::{ProgramResult, MAX_PERMITTED_DATA_INCREASE},
instruction::Instruction,
msg,
program::{get_return_data, invoke, invoke_signed, set_return_data},
program_error::ProgramError,
Expand All @@ -33,8 +32,7 @@ const TEST_PRIVILEGE_DEESCALATION_ESCALATION_WRITABLE: u8 = 13;
const TEST_WRITABLE_DEESCALATION_WRITABLE: u8 = 14;
const TEST_NESTED_INVOKE_TOO_DEEP: u8 = 15;
const TEST_EXECUTABLE_LAMPORTS: u8 = 16;
const TEST_CALL_PRECOMPILE: u8 = 17;
const ADD_LAMPORTS: u8 = 18;
const ADD_LAMPORTS: u8 = 17;

// const MINT_INDEX: usize = 0; // unused placeholder
const ARGUMENT_INDEX: usize = 1;
Expand All @@ -47,8 +45,6 @@ const DERIVED_KEY2_INDEX: usize = 7;
const DERIVED_KEY3_INDEX: usize = 8;
const SYSTEM_PROGRAM_INDEX: usize = 9;
const FROM_INDEX: usize = 10;
const ED25519_PROGRAM_INDEX: usize = 11;
// const INVOKE_PROGRAM_INDEX: usize = 12; unused placeholder

fn do_nested_invokes(num_nested_invokes: u64, accounts: &[AccountInfo]) -> ProgramResult {
assert!(accounts[ARGUMENT_INDEX].is_signer);
Expand Down Expand Up @@ -667,12 +663,6 @@ fn process_instruction(
// reset executable account
**(*accounts[ARGUMENT_INDEX].lamports).borrow_mut() += 1;
}
TEST_CALL_PRECOMPILE => {
msg!("Test calling precompiled program from cpi");
let instruction =
Instruction::new_with_bytes(*accounts[ED25519_PROGRAM_INDEX].key, &[], vec![]);
invoke(&instruction, accounts)?;
}
ADD_LAMPORTS => {
// make sure the total balance is fine
**accounts[0].lamports.borrow_mut() += 1;
Expand Down
Loading

0 comments on commit 9968635

Please sign in to comment.