Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump solana_rbpf to v0.4.0 #31594

Merged
merged 3 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ signal-hook = "0.3.15"
smpl_jwt = "0.7.1"
socket2 = "0.4.9"
soketto = "0.7"
solana_rbpf = "=0.3.0"
solana_rbpf = "=0.4.0"
solana-account-decoder = { path = "account-decoder", version = "=1.16.0" }
solana-address-lookup-table-program = { path = "programs/address-lookup-table", version = "=1.16.0" }
solana-banks-client = { path = "banks-client", version = "=1.16.0" }
Expand Down
13 changes: 8 additions & 5 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use {
tpu_client::{TpuClient, TpuClientConfig},
},
solana_program_runtime::{compute_budget::ComputeBudget, invoke_context::InvokeContext},
solana_rbpf::{elf::Executable, verifier::RequisiteVerifier, vm::VerifiedExecutable},
solana_rbpf::{
elf::Executable,
verifier::{RequisiteVerifier, TautologyVerifier},
},
solana_remote_wallet::remote_wallet::RemoteWalletManager,
solana_rpc_client::rpc_client::RpcClient,
solana_rpc_client_api::{
Expand Down Expand Up @@ -2023,14 +2026,14 @@ fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::e
&FeatureSet::default(),
&ComputeBudget::default(),
true,
true,
false,
)
.unwrap();
let executable = Executable::<InvokeContext>::from_elf(&program_data, loader)
.map_err(|err| format!("ELF error: {err}"))?;
let executable =
Executable::<TautologyVerifier, InvokeContext>::from_elf(&program_data, loader)
.map_err(|err| format!("ELF error: {err}"))?;

let _ = VerifiedExecutable::<RequisiteVerifier, InvokeContext>::from_executable(executable)
let _ = Executable::<RequisiteVerifier, InvokeContext>::verified(executable)
.map_err(|err| format!("ELF error: {err}"))?;

Ok(program_data)
Expand Down
11 changes: 5 additions & 6 deletions ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use {
},
solana_rbpf::{
assembler::assemble, elf::Executable, static_analysis::Analysis,
verifier::RequisiteVerifier, vm::VerifiedExecutable,
verifier::RequisiteVerifier,
},
solana_runtime::{bank::Bank, runtime_config::RuntimeConfig},
solana_sdk::{
Expand Down Expand Up @@ -281,11 +281,11 @@ impl Debug for Output {
// https://github.com/rust-lang/rust/issues/74465
struct LazyAnalysis<'a, 'b> {
analysis: Option<Analysis<'a>>,
executable: &'a Executable<InvokeContext<'b>>,
executable: &'a Executable<RequisiteVerifier, InvokeContext<'b>>,
}

impl<'a, 'b> LazyAnalysis<'a, 'b> {
fn new(executable: &'a Executable<InvokeContext<'b>>) -> Self {
fn new(executable: &'a Executable<RequisiteVerifier, InvokeContext<'b>>) -> Self {
Self {
analysis: None,
executable,
Expand Down Expand Up @@ -525,20 +525,19 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
invoke_context.get_compute_budget(),
true,
true,
true,
)
.unwrap();
let executable =
assemble::<InvokeContext>(std::str::from_utf8(contents.as_slice()).unwrap(), loader)
.unwrap();
VerifiedExecutable::<RequisiteVerifier, InvokeContext>::from_executable(executable)
Executable::<RequisiteVerifier, InvokeContext>::verified(executable)
.map_err(|err| format!("Assembling executable failed: {err:?}"))
}
.unwrap();

#[cfg(all(not(target_os = "windows"), target_arch = "x86_64"))]
verified_executable.jit_compile().unwrap();
let mut analysis = LazyAnalysis::new(verified_executable.get_executable());
let mut analysis = LazyAnalysis::new(&verified_executable);

match action {
Action::Cfg => {
Expand Down
2 changes: 1 addition & 1 deletion program-runtime/src/builtin_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn create_builtin(
) -> Arc<LoadedProgram> {
let mut program = BuiltInProgram::default();
program
.register_function_by_name("entrypoint", process_instruction)
.register_function(b"entrypoint", process_instruction)
.unwrap();
Arc::new(LoadedProgram::new_builtin(name, 0, program))
}
Expand Down
18 changes: 7 additions & 11 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ use {
log::{debug, log_enabled, trace},
percentage::PercentageInteger,
solana_measure::measure::Measure,
solana_rbpf::{
elf::Executable,
verifier::RequisiteVerifier,
vm::{BuiltInProgram, VerifiedExecutable},
},
solana_rbpf::{elf::Executable, verifier::RequisiteVerifier, vm::BuiltInProgram},
solana_sdk::{
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, clock::Slot, loader_v4,
pubkey::Pubkey, saturating_add_assign,
Expand Down Expand Up @@ -67,9 +63,9 @@ pub enum LoadedProgramType {
DelayVisibility,
/// Successfully verified but not currently compiled, used to track usage statistics when a compiled program is evicted from memory.
Unloaded,
LegacyV0(VerifiedExecutable<RequisiteVerifier, InvokeContext<'static>>),
LegacyV1(VerifiedExecutable<RequisiteVerifier, InvokeContext<'static>>),
Typed(VerifiedExecutable<RequisiteVerifier, InvokeContext<'static>>),
LegacyV0(Executable<RequisiteVerifier, InvokeContext<'static>>),
LegacyV1(Executable<RequisiteVerifier, InvokeContext<'static>>),
Typed(Executable<RequisiteVerifier, InvokeContext<'static>>),
#[cfg(test)]
TestLoaded,
Builtin(String, BuiltInProgram<InvokeContext<'static>>),
Expand Down Expand Up @@ -225,11 +221,11 @@ impl LoadedProgram {
// Allowing mut here, since it may be needed for jit compile, which is under a config flag
#[allow(unused_mut)]
let mut program = if bpf_loader_deprecated::check_id(loader_key) {
LoadedProgramType::LegacyV0(VerifiedExecutable::from_executable(executable)?)
LoadedProgramType::LegacyV0(Executable::verified(executable)?)
} else if bpf_loader::check_id(loader_key) || bpf_loader_upgradeable::check_id(loader_key) {
LoadedProgramType::LegacyV1(VerifiedExecutable::from_executable(executable)?)
LoadedProgramType::LegacyV1(Executable::verified(executable)?)
} else if loader_v4::check_id(loader_key) {
LoadedProgramType::Typed(VerifiedExecutable::from_executable(executable)?)
LoadedProgramType::Typed(Executable::verified(executable)?)
} else {
panic!();
};
Expand Down
54 changes: 18 additions & 36 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use {
error::EbpfError,
memory_region::{AccessType, MemoryCowCallback, MemoryMapping, MemoryRegion},
verifier::RequisiteVerifier,
vm::{ContextObject, EbpfVm, ProgramResult, VerifiedExecutable},
vm::{ContextObject, EbpfVm, ProgramResult},
},
solana_sdk::{
account::WritableAccount,
Expand All @@ -35,10 +35,9 @@ use {
feature_set::{
bpf_account_data_direct_mapping, cap_accounts_data_allocations_per_transaction,
cap_bpf_program_instruction_accounts, delay_visibility_of_program_deployment,
disable_deploy_of_alloc_free_syscall, 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, FeatureSet,
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, FeatureSet,
},
instruction::{AccountMeta, InstructionError},
loader_instruction::LoaderInstruction,
Expand Down Expand Up @@ -77,13 +76,10 @@ pub fn load_program_from_bytes(
debugging_features: bool,
) -> Result<LoadedProgram, InstructionError> {
let mut register_syscalls_time = Measure::start("register_syscalls_time");
let disable_deploy_of_alloc_free_syscall = reject_deployment_of_broken_elfs
&& feature_set.is_active(&disable_deploy_of_alloc_free_syscall::id());
let loader = syscalls::create_loader(
feature_set,
compute_budget,
reject_deployment_of_broken_elfs,
disable_deploy_of_alloc_free_syscall,
debugging_features,
)
.map_err(|e| {
Expand Down Expand Up @@ -285,7 +281,7 @@ pub fn calculate_heap_cost(heap_size: u64, heap_cost: u64, enable_rounding_fix:

/// Only used in macro, do not use directly!
pub fn create_vm<'a, 'b>(
program: &'a VerifiedExecutable<RequisiteVerifier, InvokeContext<'b>>,
program: &'a Executable<RequisiteVerifier, InvokeContext<'b>>,
regions: Vec<MemoryRegion>,
orig_account_lengths: Vec<usize>,
invoke_context: &'a mut InvokeContext<'b>,
Expand All @@ -296,7 +292,7 @@ pub fn create_vm<'a, 'b>(
let heap_size = heap.len();
let accounts = Arc::clone(invoke_context.transaction_context.accounts());
let memory_mapping = create_memory_mapping(
program.get_executable(),
program,
stack,
heap,
regions,
Expand Down Expand Up @@ -337,7 +333,7 @@ pub fn create_vm<'a, 'b>(
macro_rules! create_vm {
($vm:ident, $program:expr, $regions:expr, $orig_account_lengths:expr, $invoke_context:expr $(,)?) => {
let invoke_context = &*$invoke_context;
let stack_size = $program.get_executable().get_config().stack_size();
let stack_size = $program.get_config().stack_size();
let heap_size = invoke_context
.get_compute_budget()
.heap_size
Expand Down Expand Up @@ -382,17 +378,14 @@ macro_rules! mock_create_vm {
solana_rbpf::vm::Config::default(),
));
let function_registry = solana_rbpf::vm::FunctionRegistry::default();
let executable = solana_rbpf::elf::Executable::<InvokeContext>::from_text_bytes(
&[0x95, 0, 0, 0, 0, 0, 0, 0],
loader,
function_registry,
)
.unwrap();
let verified_executable = solana_rbpf::vm::VerifiedExecutable::<
solana_rbpf::verifier::RequisiteVerifier,
let executable = solana_rbpf::elf::Executable::<
solana_rbpf::verifier::TautologyVerifier,
InvokeContext,
>::from_executable(executable)
>::from_text_bytes(
&[0x95, 0, 0, 0, 0, 0, 0, 0], loader, function_registry
)
.unwrap();
let verified_executable = solana_rbpf::elf::Executable::verified(executable).unwrap();
$crate::create_vm!(
$vm,
&verified_executable,
Expand All @@ -404,7 +397,7 @@ macro_rules! mock_create_vm {
}

fn create_memory_mapping<'a, 'b, C: ContextObject>(
executable: &'a Executable<C>,
executable: &'a Executable<RequisiteVerifier, C>,
stack: &'b mut AlignedMemory<{ HOST_ALIGN }>,
heap: &'b mut AlignedMemory<{ HOST_ALIGN }>,
additional_regions: Vec<MemoryRegion>,
Expand Down Expand Up @@ -1526,7 +1519,7 @@ fn process_loader_instruction(invoke_context: &mut InvokeContext) -> Result<(),
}

fn execute<'a, 'b: 'a>(
executable: &'a VerifiedExecutable<RequisiteVerifier, InvokeContext<'static>>,
executable: &'a Executable<RequisiteVerifier, InvokeContext<'static>>,
invoke_context: &'a mut InvokeContext<'b>,
) -> Result<(), Box<dyn std::error::Error>> {
let log_collector = invoke_context.get_log_collector();
Expand All @@ -1536,7 +1529,7 @@ fn execute<'a, 'b: 'a>(
#[cfg(any(target_os = "windows", not(target_arch = "x86_64")))]
let use_jit = false;
#[cfg(all(not(target_os = "windows"), target_arch = "x86_64"))]
let use_jit = executable.get_executable().get_compiled_program().is_some();
let use_jit = executable.get_compiled_program().is_some();
let bpf_account_data_direct_mapping = invoke_context
.feature_set
.is_active(&bpf_account_data_direct_mapping::id());
Expand Down Expand Up @@ -1570,7 +1563,7 @@ fn execute<'a, 'b: 'a>(
// We dropped the lifetime tracking in the Executor by setting it to 'static,
// thus we need to reintroduce the correct lifetime of InvokeContext here again.
unsafe {
mem::transmute::<_, &'a VerifiedExecutable<RequisiteVerifier, InvokeContext<'b>>>(
mem::transmute::<_, &'a Executable<RequisiteVerifier, InvokeContext<'b>>>(
executable,
)
},
Expand Down Expand Up @@ -1739,7 +1732,7 @@ mod tests {
invoke_context::mock_process_instruction, with_mock_invoke_context,
},
solana_rbpf::{
verifier::{Verifier, VerifierError},
verifier::Verifier,
vm::{Config, ContextObject, FunctionRegistry},
},
solana_sdk::{
Expand Down Expand Up @@ -1805,17 +1798,6 @@ mod tests {
program_account
}

struct TautologyVerifier {}
impl Verifier for TautologyVerifier {
fn verify(
_prog: &[u8],
_config: &Config,
_function_registry: &FunctionRegistry,
) -> std::result::Result<(), VerifierError> {
Ok(())
}
}

#[test]
#[should_panic(expected = "LDDWCannotBeLast")]
fn test_bpf_loader_check_load_dw() {
Expand Down
Loading