Skip to content

Commit

Permalink
Bump solana_rbpf to v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Jun 28, 2023
1 parent 5e830d2 commit 86521cf
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 111 deletions.
3 changes: 1 addition & 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 @@ -292,7 +292,7 @@ siphasher = "0.3.10"
smpl_jwt = "0.7.1"
socket2 = "0.4.9"
soketto = "0.7"
solana_rbpf = "=0.5.0"
solana_rbpf = { git = "https://github.com/solana-labs/rbpf.git" }
solana-account-decoder = { path = "account-decoder", version = "=1.17.0" }
solana-address-lookup-table-program = { path = "programs/address-lookup-table", version = "=1.17.0" }
solana-banks-client = { path = "banks-client", version = "=1.17.0" }
Expand Down
6 changes: 3 additions & 3 deletions ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,17 +579,17 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
if matches.value_of("mode").unwrap() == "debugger" {
vm.debug_port = Some(matches.value_of("port").unwrap().parse::<u16>().unwrap());
}
let (instruction_count, result) = vm.execute_program(interpreted);
let (instruction_count, result) = vm.execute_program(&verified_executable, interpreted);
let duration = Instant::now() - start_time;
if matches.occurrences_of("trace") > 0 {
// top level trace is stored in syscall_context
if let Some(Some(syscall_context)) = vm.env.context_object_pointer.syscall_context.last() {
if let Some(Some(syscall_context)) = vm.context_object_pointer.syscall_context.last() {
let trace = syscall_context.trace_log.as_slice();
output_trace(matches, trace, 0, &mut analysis);
}
// the remaining traces are saved in InvokeContext when
// corresponding syscall_contexts are popped
let traces = vm.env.context_object_pointer.get_traces();
let traces = vm.context_object_pointer.get_traces();
for (frame, trace) in traces.iter().filter(|t| !t.is_empty()).enumerate() {
output_trace(matches, trace, frame + 1, &mut analysis);
}
Expand Down
4 changes: 3 additions & 1 deletion program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use {
solana_measure::measure::Measure,
solana_rbpf::{
ebpf::MM_HEAP_START,
elf::SBPFVersion,
memory_region::MemoryMapping,
vm::{BuiltinFunction, Config, ContextObject, ProgramResult},
},
Expand Down Expand Up @@ -744,7 +745,8 @@ impl<'a> InvokeContext<'a> {
stable_log::program_invoke(&logger, &program_id, self.get_stack_height());
let pre_remaining_units = self.get_remaining();
let mock_config = Config::default();
let mut mock_memory_mapping = MemoryMapping::new(Vec::new(), &mock_config).unwrap();
let mut mock_memory_mapping =
MemoryMapping::new(Vec::new(), &mock_config, &SBPFVersion::V2).unwrap();
let mut result = ProgramResult::Ok(0);
process_instruction(
// Removes lifetime tracking
Expand Down
47 changes: 26 additions & 21 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub fn create_vm<'a, 'b>(
invoke_context: &'a mut InvokeContext<'b>,
stack: &mut AlignedMemory<HOST_ALIGN>,
heap: &mut AlignedMemory<HOST_ALIGN>,
) -> Result<EbpfVm<'a, RequisiteVerifier, InvokeContext<'b>>, Box<dyn std::error::Error>> {
) -> Result<EbpfVm<'a, InvokeContext<'b>>, Box<dyn std::error::Error>> {
let stack_size = stack.len();
let heap_size = heap.len();
let accounts = Arc::clone(invoke_context.transaction_context.accounts());
Expand Down Expand Up @@ -309,7 +309,8 @@ pub fn create_vm<'a, 'b>(
trace_log: Vec::new(),
})?;
Ok(EbpfVm::new(
program,
program.get_config(),
program.get_sbpf_version(),
invoke_context,
memory_mapping,
stack_size,
Expand Down Expand Up @@ -370,7 +371,10 @@ macro_rules! mock_create_vm {
solana_rbpf::verifier::TautologyVerifier,
InvokeContext,
>::from_text_bytes(
&[0x95, 0, 0, 0, 0, 0, 0, 0], loader, function_registry
&[0x95, 0, 0, 0, 0, 0, 0, 0],
loader,
SBPFVersion::V2,
function_registry,
)
.unwrap();
let verified_executable = solana_rbpf::elf::Executable::verified(executable).unwrap();
Expand All @@ -392,12 +396,13 @@ fn create_memory_mapping<'a, 'b, C: ContextObject>(
cow_cb: Option<MemoryCowCallback>,
) -> Result<MemoryMapping<'a>, Box<dyn std::error::Error>> {
let config = executable.get_config();
let sbpf_version = executable.get_sbpf_version();
let regions: Vec<MemoryRegion> = vec![
executable.get_ro_region(),
MemoryRegion::new_writable_gapped(
stack.as_slice_mut(),
ebpf::MM_STACK_START,
if !config.dynamic_stack_frames && config.enable_stack_frame_gaps {
if !sbpf_version.dynamic_stack_frames() && config.enable_stack_frame_gaps {
config.stack_frame_size as u64
} else {
0
Expand All @@ -410,9 +415,9 @@ fn create_memory_mapping<'a, 'b, C: ContextObject>(
.collect();

Ok(if let Some(cow_cb) = cow_cb {
MemoryMapping::new_with_cow(regions, cow_cb, config)?
MemoryMapping::new_with_cow(regions, cow_cb, config, sbpf_version)?
} else {
MemoryMapping::new(regions, config)?
MemoryMapping::new(regions, config, sbpf_version)?
})
}

Expand Down Expand Up @@ -1544,6 +1549,11 @@ fn execute<'a, 'b: 'a>(
executable: &'a Executable<RequisiteVerifier, InvokeContext<'static>>,
invoke_context: &'a mut InvokeContext<'b>,
) -> Result<(), Box<dyn std::error::Error>> {
// 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.
let executable = unsafe {
mem::transmute::<_, &'a Executable<RequisiteVerifier, InvokeContext<'b>>>(executable)
};
let log_collector = invoke_context.get_log_collector();
let transaction_context = &invoke_context.transaction_context;
let instruction_context = transaction_context.get_current_instruction_context()?;
Expand Down Expand Up @@ -1580,19 +1590,7 @@ fn execute<'a, 'b: 'a>(
let mut execute_time;
let execution_result = {
let compute_meter_prev = invoke_context.get_remaining();
create_vm!(
vm,
// 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 Executable<RequisiteVerifier, InvokeContext<'b>>>(
executable,
)
},
regions,
account_lengths,
invoke_context,
);
create_vm!(vm, executable, regions, account_lengths, invoke_context,);
let mut vm = match vm {
Ok(info) => info,
Err(e) => {
Expand All @@ -1603,7 +1601,7 @@ fn execute<'a, 'b: 'a>(
create_vm_time.stop();

execute_time = Measure::start("execute");
let (compute_units_consumed, result) = vm.execute_program(!use_jit);
let (compute_units_consumed, result) = vm.execute_program(executable, !use_jit);
drop(vm);
ic_logger_msg!(
log_collector,
Expand Down Expand Up @@ -1761,6 +1759,7 @@ mod tests {
invoke_context::mock_process_instruction, with_mock_invoke_context,
},
solana_rbpf::{
elf::SBPFVersion,
verifier::Verifier,
vm::{Config, ContextObject, FunctionRegistry},
},
Expand Down Expand Up @@ -1833,7 +1832,13 @@ mod tests {
let prog = &[
0x18, 0x00, 0x00, 0x00, 0x88, 0x77, 0x66, 0x55, // first half of lddw
];
RequisiteVerifier::verify(prog, &Config::default(), &FunctionRegistry::default()).unwrap();
RequisiteVerifier::verify(
prog,
&Config::default(),
&SBPFVersion::V2,
&FunctionRegistry::default(),
)
.unwrap();
}

#[test]
Expand Down
47 changes: 34 additions & 13 deletions programs/bpf_loader/src/syscalls/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,9 @@ mod tests {
super::*,
crate::mock_create_vm,
solana_program_runtime::with_mock_invoke_context,
solana_rbpf::{ebpf::MM_INPUT_START, memory_region::MemoryRegion, vm::Config},
solana_rbpf::{
ebpf::MM_INPUT_START, elf::SBPFVersion, memory_region::MemoryRegion, vm::Config,
},
solana_sdk::{
account::{Account, AccountSharedData},
clock::Epoch,
Expand Down Expand Up @@ -1366,7 +1368,8 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping = MemoryMapping::new(vec![region], &config).unwrap();
let mut memory_mapping =
MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap();

let ins = SyscallInvokeSignedRust::translate_instruction(
vm_addr,
Expand Down Expand Up @@ -1402,7 +1405,8 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping = MemoryMapping::new(vec![region], &config).unwrap();
let mut memory_mapping =
MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap();

let signers = SyscallInvokeSignedRust::translate_signers(
&program_id,
Expand Down Expand Up @@ -1437,7 +1441,7 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let memory_mapping = MemoryMapping::new(vec![region], &config).unwrap();
let memory_mapping = MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap();

let account_info = translate_type::<AccountInfo>(&memory_mapping, vm_addr, false).unwrap();

Expand Down Expand Up @@ -1487,8 +1491,12 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping =
MemoryMapping::new(mock_caller_account.regions.split_off(0), &config).unwrap();
let mut memory_mapping = MemoryMapping::new(
mock_caller_account.regions.split_off(0),
&config,
&SBPFVersion::V2,
)
.unwrap();

let mut caller_account = mock_caller_account.caller_account();

Expand Down Expand Up @@ -1541,8 +1549,12 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping =
MemoryMapping::new(mock_caller_account.regions.split_off(0), &config).unwrap();
let mut memory_mapping = MemoryMapping::new(
mock_caller_account.regions.split_off(0),
&config,
&SBPFVersion::V2,
)
.unwrap();

let data_slice = mock_caller_account.data_slice();
let len_ptr = unsafe {
Expand Down Expand Up @@ -1662,8 +1674,12 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping =
MemoryMapping::new(mock_caller_account.regions.split_off(0), &config).unwrap();
let mut memory_mapping = MemoryMapping::new(
mock_caller_account.regions.split_off(0),
&config,
&SBPFVersion::V2,
)
.unwrap();

let data_slice = mock_caller_account.data_slice();
let len_ptr = unsafe {
Expand Down Expand Up @@ -1829,8 +1845,12 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping =
MemoryMapping::new(mock_caller_account.regions.split_off(0), &config).unwrap();
let mut memory_mapping = MemoryMapping::new(
mock_caller_account.regions.split_off(0),
&config,
&SBPFVersion::V2,
)
.unwrap();

let mut caller_account = mock_caller_account.caller_account();

Expand Down Expand Up @@ -2148,7 +2168,8 @@ mod tests {
aligned_memory_mapping: false,
..Config::default()
};
let mut memory_mapping = MemoryMapping::new(vec![region], &config).unwrap();
let mut memory_mapping =
MemoryMapping::new(vec![region], &config, &SBPFVersion::V2).unwrap();

let accounts = SyscallInvokeSignedRust::translate_accounts(
&[
Expand Down
Loading

0 comments on commit 86521cf

Please sign in to comment.