Cleanup old features (#15391)

This commit is contained in:
Jack May
2021-02-18 09:56:11 -08:00
committed by GitHub
parent 82850781c9
commit 02432a548f
9 changed files with 57 additions and 215 deletions

View File

@ -27,7 +27,7 @@ use solana_sdk::{
client::SyncClient,
clock::{DEFAULT_SLOTS_PER_EPOCH, MAX_PROCESSING_AGE},
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
feature_set::try_find_program_address_syscall_enabled,
feature_set::ristretto_mul_syscall_enabled,
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
keyed_account::KeyedAccount,
message::Message,
@ -1216,7 +1216,7 @@ fn assert_instruction_count() {
("noop", 57),
("relative_call", 10),
("sanity", 176),
("sanity++", 176),
("sanity++", 177),
("struct_pass", 8),
("struct_ret", 22),
]);
@ -2195,7 +2195,7 @@ fn test_program_bpf_syscall_feature_activation() {
..
} = create_genesis_config(50);
let mut bank = Bank::new(&genesis_config);
bank.deactivate_feature(&try_find_program_address_syscall_enabled::id());
bank.deactivate_feature(&ristretto_mul_syscall_enabled::id());
let (name, id, entrypoint) = solana_bpf_loader_program!();
bank.add_builtin(&name, id, entrypoint);
let bank = Arc::new(bank);
@ -2212,7 +2212,7 @@ fn test_program_bpf_syscall_feature_activation() {
assert!(result.is_ok());
let mut bank = Bank::new_from_parent(&bank, &Pubkey::default(), 1);
bank.activate_feature(&try_find_program_address_syscall_enabled::id());
bank.activate_feature(&ristretto_mul_syscall_enabled::id());
let bank = Arc::new(bank);
let bank_client = BankClient::new_shared(&bank);

View File

@ -58,11 +58,11 @@ fn adj_insn_ptr(insn_ptr: usize) -> usize {
insn_ptr + ebpf::ELF_INSN_DUMP_OFFSET
}
fn check_prog_len(prog: &[u8], is_program_size_cap: bool) -> Result<(), BPFError> {
fn check_prog_len(prog: &[u8]) -> Result<(), BPFError> {
if prog.len() % ebpf::INSN_SIZE != 0 {
return Err(VerifierError::ProgramLengthNotMultiple.into());
}
if is_program_size_cap && prog.len() > ebpf::PROG_MAX_SIZE {
if prog.len() > ebpf::PROG_MAX_SIZE {
return Err(VerifierError::ProgramTooLarge(prog.len() / ebpf::INSN_SIZE).into());
}
@ -149,8 +149,8 @@ fn check_imm_register(insn: &ebpf::Insn, insn_ptr: usize) -> Result<(), Verifier
}
#[rustfmt::skip]
pub fn check(prog: &[u8], is_program_size_cap: bool) -> Result<(), BPFError> {
check_prog_len(prog, is_program_size_cap)?;
pub fn check(prog: &[u8]) -> Result<(), BPFError> {
check_prog_len(prog)?;
let mut insn_ptr: usize = 0;
while insn_ptr * ebpf::INSN_SIZE < prog.len() {

View File

@ -27,10 +27,7 @@ use solana_sdk::{
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::Clock,
entrypoint::SUCCESS,
feature_set::{
bpf_compute_budget_balancing, matching_buffer_upgrade_authorities,
prevent_upgrade_and_invoke,
},
feature_set::matching_buffer_upgrade_authorities,
ic_logger_msg, ic_msg,
instruction::InstructionError,
keyed_account::{from_keyed_account, next_keyed_account, KeyedAccount},
@ -90,11 +87,8 @@ pub fn create_and_cache_executor(
let (_, elf_bytes) = program
.get_text_bytes()
.map_err(|e| map_ebpf_error(invoke_context, e))?;
bpf_verifier::check(
elf_bytes,
!invoke_context.is_feature_active(&bpf_compute_budget_balancing::id()),
)
.map_err(|e| map_ebpf_error(invoke_context, EbpfError::UserError(e)))?;
bpf_verifier::check(elf_bytes)
.map_err(|e| map_ebpf_error(invoke_context, EbpfError::UserError(e)))?;
let syscall_registry = syscalls::register_syscalls(invoke_context).map_err(|e| {
ic_msg!(invoke_context, "Failed to register syscalls: {}", e);
InstructionError::ProgramEnvironmentSetupFailure
@ -491,9 +485,7 @@ fn process_loader_upgradeable_instruction(
ic_logger_msg!(logger, "Program account not executable");
return Err(InstructionError::AccountNotExecutable);
}
if !program.is_writable()
&& invoke_context.is_feature_active(&prevent_upgrade_and_invoke::id())
{
if !program.is_writable() {
ic_logger_msg!(logger, "Program account not writeable");
return Err(InstructionError::InvalidArgument);
}
@ -911,7 +903,7 @@ mod tests {
let prog = &[
0x18, 0x00, 0x00, 0x00, 0x88, 0x77, 0x66, 0x55, // first half of lddw
];
bpf_verifier::check(prog, true).unwrap();
bpf_verifier::check(prog).unwrap();
}
#[test]

View File

@ -16,25 +16,18 @@ use solana_sdk::{
bpf_loader, bpf_loader_deprecated,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
feature_set::{
abort_on_all_cpi_failures, limit_cpi_loader_invoke, per_byte_logging_cost,
pubkey_log_syscall_enabled, ristretto_mul_syscall_enabled, sha256_syscall_enabled,
sol_log_compute_units_syscall, try_find_program_address_syscall_enabled,
use_loaded_executables, use_loaded_program_accounts,
},
feature_set::{per_byte_logging_cost, ristretto_mul_syscall_enabled, use_loaded_executables},
hash::{Hasher, HASH_BYTES},
ic_msg,
instruction::{AccountMeta, Instruction, InstructionError},
keyed_account::KeyedAccount,
native_loader,
process_instruction::{stable_log, ComputeMeter, InvokeContext, Logger},
program_error::ProgramError,
pubkey::{Pubkey, PubkeyError, MAX_SEEDS},
};
use std::{
alloc::Layout,
cell::{Ref, RefCell, RefMut},
convert::TryFrom,
mem::{align_of, size_of},
rc::Rc,
slice::from_raw_parts_mut,
@ -110,18 +103,12 @@ pub fn register_syscalls(
syscall_registry.register_syscall_by_name(b"sol_log_", SyscallLog::call)?;
syscall_registry.register_syscall_by_name(b"sol_log_64_", SyscallLogU64::call)?;
if invoke_context.is_feature_active(&sol_log_compute_units_syscall::id()) {
syscall_registry
.register_syscall_by_name(b"sol_log_compute_units_", SyscallLogBpfComputeUnits::call)?;
}
syscall_registry
.register_syscall_by_name(b"sol_log_compute_units_", SyscallLogBpfComputeUnits::call)?;
if invoke_context.is_feature_active(&pubkey_log_syscall_enabled::id()) {
syscall_registry.register_syscall_by_name(b"sol_log_pubkey", SyscallLogPubkey::call)?;
}
syscall_registry.register_syscall_by_name(b"sol_log_pubkey", SyscallLogPubkey::call)?;
if invoke_context.is_feature_active(&sha256_syscall_enabled::id()) {
syscall_registry.register_syscall_by_name(b"sol_sha256", SyscallSha256::call)?;
}
syscall_registry.register_syscall_by_name(b"sol_sha256", SyscallSha256::call)?;
if invoke_context.is_feature_active(&ristretto_mul_syscall_enabled::id()) {
syscall_registry
@ -132,12 +119,10 @@ pub fn register_syscalls(
b"sol_create_program_address",
SyscallCreateProgramAddress::call,
)?;
if invoke_context.is_feature_active(&try_find_program_address_syscall_enabled::id()) {
syscall_registry.register_syscall_by_name(
b"sol_try_find_program_address",
SyscallTryFindProgramAddress::call,
)?;
}
syscall_registry.register_syscall_by_name(
b"sol_try_find_program_address",
SyscallTryFindProgramAddress::call,
)?;
syscall_registry
.register_syscall_by_name(b"sol_invoke_signed_c", SyscallInvokeSignedC::call)?;
syscall_registry
@ -202,40 +187,34 @@ pub fn bind_syscall_context_objects<'a>(
None,
)?;
bind_feature_gated_syscall_context_object!(
vm,
invoke_context,
&sol_log_compute_units_syscall::id(),
vm.bind_syscall_context_object(
Box::new(SyscallLogBpfComputeUnits {
cost: 0,
compute_meter: invoke_context.get_compute_meter(),
logger: invoke_context.get_logger(),
}),
);
None,
)?;
bind_feature_gated_syscall_context_object!(
vm,
invoke_context,
&pubkey_log_syscall_enabled::id(),
vm.bind_syscall_context_object(
Box::new(SyscallLogPubkey {
cost: bpf_compute_budget.log_pubkey_units,
compute_meter: invoke_context.get_compute_meter(),
logger: invoke_context.get_logger(),
loader_id,
}),
);
None,
)?;
bind_feature_gated_syscall_context_object!(
vm,
invoke_context,
&sha256_syscall_enabled::id(),
vm.bind_syscall_context_object(
Box::new(SyscallSha256 {
sha256_base_cost: bpf_compute_budget.sha256_base_cost,
sha256_byte_cost: bpf_compute_budget.sha256_byte_cost,
compute_meter: invoke_context.get_compute_meter(),
loader_id,
}),
);
None,
)?;
bind_feature_gated_syscall_context_object!(
vm,
@ -257,16 +236,14 @@ pub fn bind_syscall_context_objects<'a>(
None,
)?;
bind_feature_gated_syscall_context_object!(
vm,
invoke_context,
&try_find_program_address_syscall_enabled::id(),
vm.bind_syscall_context_object(
Box::new(SyscallTryFindProgramAddress {
cost: bpf_compute_budget.create_program_address_units,
compute_meter: invoke_context.get_compute_meter(),
loader_id,
}),
);
None,
)?;
// Cross-program invocation syscalls
@ -1450,8 +1427,7 @@ where
SyscallError::InstructionError(InstructionError::MissingAccount)
})?;
if (invoke_context.is_feature_active(&use_loaded_program_accounts::id())
&& i == program_account_index)
if i == program_account_index
|| (invoke_context.is_feature_active(&use_loaded_executables::id())
&& account.borrow().executable)
{
@ -1511,7 +1487,6 @@ fn check_account_infos(
> invoke_context
.get_bpf_compute_budget()
.max_cpi_instruction_size
&& invoke_context.is_feature_active(&use_loaded_program_accounts::id())
{
// Cap the number of account_infos a caller can pass to approximate
// maximum that accounts that could be passed in an instruction
@ -1580,14 +1555,7 @@ fn call<'a>(
signers_seeds_len: u64,
memory_mapping: &MemoryMapping,
) -> Result<u64, EbpfError<BPFError>> {
let (
message,
executables,
accounts,
account_refs,
caller_privileges,
abort_on_all_cpi_failures,
) = {
let (message, executables, accounts, account_refs, caller_privileges) = {
let invoke_context = syscall.get_context()?;
invoke_context
@ -1633,9 +1601,7 @@ fn call<'a>(
}
})
.collect::<Vec<bool>>();
if invoke_context.is_feature_active(&limit_cpi_loader_invoke::id()) {
check_authorized_program(&callee_program_id, &instruction.data)?;
}
check_authorized_program(&callee_program_id, &instruction.data)?;
let (accounts, account_refs) = syscall.translate_accounts(
&message.account_keys,
callee_program_id_index,
@ -1668,7 +1634,6 @@ fn call<'a>(
accounts,
account_refs,
caller_privileges,
invoke_context.is_feature_active(&abort_on_all_cpi_failures::id()),
)
};
@ -1684,14 +1649,7 @@ fn call<'a>(
) {
Ok(()) => (),
Err(err) => {
if abort_on_all_cpi_failures {
return Err(SyscallError::InstructionError(err).into());
} else {
match ProgramError::try_from(err) {
Ok(err) => return Ok(err.into()),
Err(err) => return Err(SyscallError::InstructionError(err).into()),
}
}
return Err(SyscallError::InstructionError(err).into());
}
}