Skip to content

Commit

Permalink
Bumps solana_rbpf to v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed May 11, 2023
1 parent 2379e10 commit 11ca9fe
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 112 deletions.
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
12 changes: 8 additions & 4 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 @@ -2026,10 +2029,11 @@ fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::e
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
10 changes: 5 additions & 5 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 @@ -530,14 +530,14 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
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
44 changes: 15 additions & 29 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 Down Expand Up @@ -281,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 @@ -292,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 @@ -333,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 @@ -378,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 @@ -400,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 @@ -1522,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 @@ -1532,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 @@ -1566,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 @@ -1735,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 @@ -1801,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

0 comments on commit 11ca9fe

Please sign in to comment.