Skip to content

Commit

Permalink
Bump solana_rbpf to version v0.2.14 (solana-labs#18869)
Browse files Browse the repository at this point in the history
* Feature gate for verify_mul64_imm_nonzero as discussed in solana-labs#17520.
  • Loading branch information
Lichtso committed Dec 13, 2021
1 parent 12680ed commit d2d6d9d
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 211 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 cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ solana-config-program = { path = "../programs/config", version = "=1.8.11" }
solana-faucet = { path = "../faucet", version = "=1.8.11" }
solana-logger = { path = "../logger", version = "=1.8.11" }
solana-net-utils = { path = "../net-utils", version = "=1.8.11" }
solana_rbpf = "=0.2.13"
solana_rbpf = "=0.2.14"
solana-remote-wallet = { path = "../remote-wallet", version = "=1.8.11" }
solana-sdk = { path = "../sdk", version = "=1.8.11" }
solana-transaction-status = { path = "../transaction-status", version = "=1.8.11" }
Expand Down
3 changes: 2 additions & 1 deletion cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1992,9 +1992,10 @@ fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::e
// Verify the program
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
&program_data,
Some(|x| verifier::check(x)),
Some(verifier::check),
Config {
reject_unresolved_syscalls: true,
verify_mul64_imm_nonzero: true, // TODO: Remove me after feature gate
..Config::default()
},
register_syscalls(&mut invoke_context).unwrap(),
Expand Down
4 changes: 2 additions & 2 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/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ solana-bpf-loader-program = { path = "../bpf_loader", version = "=1.8.11" }
solana-cli-output = { path = "../../cli-output", version = "=1.8.11" }
solana-logger = { path = "../../logger", version = "=1.8.11" }
solana-measure = { path = "../../measure", version = "=1.8.11" }
solana_rbpf = "=0.2.13"
solana_rbpf = "=0.2.14"
solana-runtime = { path = "../../runtime", version = "=1.8.11" }
solana-sdk = { path = "../../sdk", version = "=1.8.11" }
solana-transaction-status = { path = "../../transaction-status", version = "=1.8.11" }
Expand Down
2 changes: 1 addition & 1 deletion programs/bpf_loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sha3 = "0.9.1"
solana-measure = { path = "../../measure", version = "=1.8.11" }
solana-runtime = { path = "../../runtime", version = "=1.8.11" }
solana-sdk = { path = "../../sdk", version = "=1.8.11" }
solana_rbpf = "=0.2.13"
solana_rbpf = "=0.2.14"
thiserror = "1.0"

[dev-dependencies]
Expand Down
30 changes: 12 additions & 18 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use log::{log_enabled, trace, Level::Trace};
use solana_measure::measure::Measure;
use solana_rbpf::{
aligned_memory::AlignedMemory,
ebpf::{HOST_ALIGN, MM_HEAP_START},
ebpf::HOST_ALIGN,
error::{EbpfError, UserDefinedError},
memory_region::MemoryRegion,
static_analysis::Analysis,
verifier::{self, VerifierError},
vm::{Config, EbpfVm, Executable, InstructionMeter},
Expand All @@ -33,7 +32,8 @@ use solana_sdk::{
entrypoint::{HEAP_LENGTH, SUCCESS},
feature_set::{
add_missing_program_error_mappings, close_upgradeable_program_accounts, fix_write_privs,
reduce_required_deploy_balance, requestable_heap_size, upgradeable_close_instruction,
reduce_required_deploy_balance, requestable_heap_size, stop_verify_mul64_imm_nonzero,
upgradeable_close_instruction,
},
ic_logger_msg, ic_msg,
instruction::{AccountMeta, InstructionError},
Expand Down Expand Up @@ -86,6 +86,8 @@ pub fn create_executor(
max_call_depth: bpf_compute_budget.max_call_depth,
stack_frame_size: bpf_compute_budget.stack_frame_size,
enable_instruction_tracing: log_enabled!(Trace),
verify_mul64_imm_nonzero: !invoke_context
.is_feature_active(&stop_verify_mul64_imm_nonzero::id()), // TODO: Feature gate and then remove me
..Config::default()
};
let mut executable = {
Expand All @@ -101,10 +103,8 @@ pub fn create_executor(
)
}
.map_err(|e| map_ebpf_error(invoke_context, e))?;
let (_, elf_bytes) = executable
.get_text_bytes()
.map_err(|e| map_ebpf_error(invoke_context, e))?;
verifier::check(elf_bytes)
let text_bytes = executable.get_text_bytes().1;
verifier::check(text_bytes, &config)
.map_err(|e| map_ebpf_error(invoke_context, EbpfError::UserError(e.into())))?;
if use_jit {
if let Err(err) = executable.jit_compile() {
Expand Down Expand Up @@ -153,18 +153,11 @@ pub fn create_vm<'a>(
invoke_context: &'a mut dyn InvokeContext,
) -> Result<EbpfVm<'a, BpfError, ThisInstructionMeter>, EbpfError<BpfError>> {
let bpf_compute_budget = invoke_context.get_bpf_compute_budget();
let heap_size = bpf_compute_budget.heap_size.unwrap_or(HEAP_LENGTH);
if invoke_context.is_feature_active(&requestable_heap_size::id()) {
let _ = invoke_context.get_compute_meter().borrow_mut().consume(
(heap_size as u64 / (32 * 1024)).saturating_sub(1) * bpf_compute_budget.heap_cost,
);
}
let heap = AlignedMemory::new_with_size(
let mut heap = AlignedMemory::new_with_size(
bpf_compute_budget.heap_size.unwrap_or(HEAP_LENGTH),
HOST_ALIGN,
);
let heap_region = MemoryRegion::new_from_slice(heap.as_slice(), MM_HEAP_START, 0, true);
let mut vm = EbpfVm::new(program, parameter_bytes, &[heap_region])?;
let mut vm = EbpfVm::new(program, heap.as_slice_mut(), parameter_bytes)?;
syscalls::bind_syscall_context_objects(loader_id, &mut vm, invoke_context, heap)?;
Ok(vm)
}
Expand Down Expand Up @@ -1065,7 +1058,8 @@ mod tests {
)
.unwrap();
let mut vm =
EbpfVm::<BpfError, TestInstructionMeter>::new(program.as_ref(), input, &[]).unwrap();
EbpfVm::<BpfError, TestInstructionMeter>::new(program.as_ref(), &mut [], input)
.unwrap();
let mut instruction_meter = TestInstructionMeter { remaining: 10 };
vm.execute_program_interpreted(&mut instruction_meter)
.unwrap();
Expand All @@ -1077,7 +1071,7 @@ mod tests {
let prog = &[
0x18, 0x00, 0x00, 0x00, 0x88, 0x77, 0x66, 0x55, // first half of lddw
];
verifier::check(prog).unwrap();
verifier::check(prog, &Config::default()).unwrap();
}

#[test]
Expand Down
Loading

0 comments on commit d2d6d9d

Please sign in to comment.