Skip to content

Commit

Permalink
Dissolves the wrapper VerifiedExecutable. (#458)
Browse files Browse the repository at this point in the history
Exposes TautologyVerifier to the public interface.
  • Loading branch information
Lichtso authored Apr 10, 2023
1 parent febc1c7 commit f337a6a
Show file tree
Hide file tree
Showing 22 changed files with 203 additions and 273 deletions.
13 changes: 10 additions & 3 deletions benches/elf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern crate test_utils;
use solana_rbpf::{
elf::Executable,
syscalls::bpf_syscall_u64,
verifier::TautologyVerifier,
vm::{BuiltInProgram, Config, TestContextObject},
};
use std::{fs::File, io::Read, sync::Arc};
Expand All @@ -32,7 +33,9 @@ fn bench_load_elf(bencher: &mut Bencher) {
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let loader = loader();
bencher.iter(|| Executable::<TestContextObject>::from_elf(&elf, loader.clone()).unwrap());
bencher.iter(|| {
Executable::<TautologyVerifier, TestContextObject>::from_elf(&elf, loader.clone()).unwrap()
});
}

#[bench]
Expand All @@ -41,7 +44,9 @@ fn bench_load_elf_without_syscall(bencher: &mut Bencher) {
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let loader = loader();
bencher.iter(|| Executable::<TestContextObject>::from_elf(&elf, loader.clone()).unwrap());
bencher.iter(|| {
Executable::<TautologyVerifier, TestContextObject>::from_elf(&elf, loader.clone()).unwrap()
});
}

#[bench]
Expand All @@ -50,5 +55,7 @@ fn bench_load_elf_with_syscall(bencher: &mut Bencher) {
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let loader = loader();
bencher.iter(|| Executable::<TestContextObject>::from_elf(&elf, loader.clone()).unwrap());
bencher.iter(|| {
Executable::<TautologyVerifier, TestContextObject>::from_elf(&elf, loader.clone()).unwrap()
});
}
15 changes: 7 additions & 8 deletions benches/jit_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ extern crate test;

use solana_rbpf::{
elf::Executable,
vm::{BuiltInProgram, Config, TestContextObject, VerifiedExecutable},
verifier::{RequisiteVerifier, TautologyVerifier},
vm::{BuiltInProgram, Config, TestContextObject},
};
use std::{fs::File, io::Read, sync::Arc};
use test::Bencher;
use test_utils::{create_vm, TautologyVerifier};
use test_utils::create_vm;

#[bench]
fn bench_init_vm(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/pass_stack_reference.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let executable = Executable::<TestContextObject>::from_elf(
let executable = Executable::<TautologyVerifier, TestContextObject>::from_elf(
&elf,
Arc::new(BuiltInProgram::new_loader(Config::default())),
)
.unwrap();
let verified_executable =
VerifiedExecutable::<TautologyVerifier, TestContextObject>::from_executable(executable)
.unwrap();
Executable::<RequisiteVerifier, TestContextObject>::verified(executable).unwrap();
bencher.iter(|| {
let mut context_object = TestContextObject::default();
create_vm!(
Expand All @@ -50,13 +50,12 @@ fn bench_jit_compile(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/pass_stack_reference.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let executable = Executable::<TestContextObject>::from_elf(
let executable = Executable::<TautologyVerifier, TestContextObject>::from_elf(
&elf,
Arc::new(BuiltInProgram::new_loader(Config::default())),
)
.unwrap();
let mut verified_executable =
VerifiedExecutable::<TautologyVerifier, TestContextObject>::from_executable(executable)
.unwrap();
Executable::<RequisiteVerifier, TestContextObject>::verified(executable).unwrap();
bencher.iter(|| verified_executable.jit_compile().unwrap());
}
18 changes: 8 additions & 10 deletions benches/vm_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ use solana_rbpf::{
ebpf,
elf::Executable,
memory_region::MemoryRegion,
vm::{BuiltInProgram, Config, TestContextObject, VerifiedExecutable},
verifier::{RequisiteVerifier, TautologyVerifier},
vm::{BuiltInProgram, Config, TestContextObject},
};
use std::{fs::File, io::Read, sync::Arc};
use test::Bencher;
use test_utils::{create_vm, TautologyVerifier};
use test_utils::create_vm;

#[bench]
fn bench_init_interpreter_execution(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/pass_stack_reference.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let executable = Executable::<TestContextObject>::from_elf(
let executable = Executable::<TautologyVerifier, TestContextObject>::from_elf(
&elf,
Arc::new(BuiltInProgram::new_loader(Config::default())),
)
.unwrap();
let verified_executable =
VerifiedExecutable::<TautologyVerifier, TestContextObject>::from_executable(executable)
.unwrap();
Executable::<RequisiteVerifier, TestContextObject>::verified(executable).unwrap();
let mut context_object = TestContextObject::default();
create_vm!(
vm,
Expand All @@ -54,14 +54,13 @@ fn bench_init_jit_execution(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/pass_stack_reference.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let executable = Executable::<TestContextObject>::from_elf(
let executable = Executable::<TautologyVerifier, TestContextObject>::from_elf(
&elf,
Arc::new(BuiltInProgram::new_loader(Config::default())),
)
.unwrap();
let mut verified_executable =
VerifiedExecutable::<TautologyVerifier, TestContextObject>::from_executable(executable)
.unwrap();
Executable::<RequisiteVerifier, TestContextObject>::verified(executable).unwrap();
verified_executable.jit_compile().unwrap();
let mut context_object = TestContextObject::default();
create_vm!(
Expand Down Expand Up @@ -93,8 +92,7 @@ fn bench_jit_vs_interpreter(
)
.unwrap();
let mut verified_executable =
VerifiedExecutable::<TautologyVerifier, TestContextObject>::from_executable(executable)
.unwrap();
Executable::<RequisiteVerifier, TestContextObject>::verified(executable).unwrap();
verified_executable.jit_compile().unwrap();
let mut context_object = TestContextObject::default();
let mem_region = MemoryRegion::new_writable(mem, ebpf::MM_INPUT_START);
Expand Down
17 changes: 8 additions & 9 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use solana_rbpf::{
elf::Executable,
memory_region::{MemoryMapping, MemoryRegion},
static_analysis::Analysis,
verifier::RequisiteVerifier,
vm::{BuiltInProgram, Config, DynamicAnalysis, EbpfVm, TestContextObject, VerifiedExecutable},
verifier::{RequisiteVerifier, TautologyVerifier},
vm::{BuiltInProgram, Config, DynamicAnalysis, EbpfVm, TestContextObject},
};
use std::{fs::File, io::Read, path::Path, sync::Arc};

Expand Down Expand Up @@ -108,16 +108,15 @@ fn main() {
let mut file = File::open(Path::new(matches.value_of("elf").unwrap())).unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
Executable::<TestContextObject>::from_elf(&elf, loader)
Executable::<TautologyVerifier, TestContextObject>::from_elf(&elf, loader)
.map_err(|err| format!("Executable constructor failed: {err:?}"))
}
}
.unwrap();

#[allow(unused_mut)]
let mut verified_executable =
VerifiedExecutable::<RequisiteVerifier, TestContextObject>::from_executable(executable)
.unwrap();
let verified_executable =
Executable::<RequisiteVerifier, TestContextObject>::verified(executable).unwrap();

let mut mem = match matches.value_of("input").unwrap().parse::<usize>() {
Ok(allocate) => vec![0u8; allocate],
Expand All @@ -139,7 +138,7 @@ fn main() {
.parse::<u64>()
.unwrap(),
);
let config = verified_executable.get_executable().get_config();
let config = verified_executable.get_config();
let mut stack = AlignedMemory::<{ ebpf::HOST_ALIGN }>::zero_filled(config.stack_size());
let stack_len = stack.len();
let mut heap = AlignedMemory::<{ ebpf::HOST_ALIGN }>::zero_filled(
Expand All @@ -150,7 +149,7 @@ fn main() {
.unwrap(),
);
let regions: Vec<MemoryRegion> = vec![
verified_executable.get_executable().get_ro_region(),
verified_executable.get_ro_region(),
MemoryRegion::new_writable_gapped(
stack.as_slice_mut(),
ebpf::MM_STACK_START,
Expand Down Expand Up @@ -178,7 +177,7 @@ fn main() {
|| matches.is_present("trace")
|| matches.is_present("profile")
{
Some(Analysis::from_executable(verified_executable.get_executable()).unwrap())
Some(Analysis::from_executable(&verified_executable).unwrap())
} else {
None
};
Expand Down
3 changes: 2 additions & 1 deletion examples/disassemble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern crate solana_rbpf;
use solana_rbpf::{
elf::Executable,
static_analysis::Analysis,
verifier::TautologyVerifier,
vm::{BuiltInProgram, FunctionRegistry, TestContextObject},
};
use std::sync::Arc;
Expand All @@ -31,7 +32,7 @@ fn main() {
0x00, 0x00, 0x00, 0x00, 0x00,
];
let loader = Arc::new(BuiltInProgram::default());
let executable = Executable::<TestContextObject>::from_text_bytes(
let executable = Executable::<TautologyVerifier, TestContextObject>::from_text_bytes(
program,
loader,
FunctionRegistry::default(),
Expand Down
3 changes: 2 additions & 1 deletion examples/to_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern crate solana_rbpf;
use solana_rbpf::{
elf::Executable,
static_analysis::Analysis,
verifier::TautologyVerifier,
vm::{BuiltInProgram, FunctionRegistry, TestContextObject},
};
use std::sync::Arc;
Expand All @@ -27,7 +28,7 @@ use std::sync::Arc;
// * Print integers as integers, and not as strings containing their hexadecimal representation
// (just replace the relevant `format!()` calls by the commented values.
fn to_json(program: &[u8]) -> String {
let executable = Executable::<TestContextObject>::from_text_bytes(
let executable = Executable::<TautologyVerifier, TestContextObject>::from_text_bytes(
program,
Arc::new(BuiltInProgram::default()),
FunctionRegistry::default(),
Expand Down
13 changes: 5 additions & 8 deletions fuzz/fuzz_targets/dumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use solana_rbpf::{
ebpf,
elf::Executable,
memory_region::MemoryRegion,
verifier::{RequisiteVerifier, Verifier},
vm::{BuiltInProgram, FunctionRegistry, TestContextObject, VerifiedExecutable},
verifier::{RequisiteVerifier, TautologyVerifier, Verifier},
vm::{BuiltInProgram, FunctionRegistry, TestContextObject},
};
use test_utils::{create_vm, TautologyVerifier};
use test_utils::create_vm;

use crate::common::ConfigTemplate;

Expand All @@ -33,20 +33,17 @@ fuzz_target!(|data: DumbFuzzData| {
return;
}
let mut mem = data.mem;
let executable = Executable::<TestContextObject>::from_text_bytes(
let executable = Executable::<TautologyVerifier, TestContextObject>::from_text_bytes(
&prog,
std::sync::Arc::new(BuiltInProgram::new_loader(config)),
function_registry,
)
.unwrap();
let verified_executable =
VerifiedExecutable::<TautologyVerifier, TestContextObject>::from_executable(executable)
.unwrap();
let mem_region = MemoryRegion::new_writable(&mut mem, ebpf::MM_INPUT_START);
let mut context_object = TestContextObject::new(29);
create_vm!(
interp_vm,
&verified_executable,
&executable,
&mut context_object,
stack,
heap,
Expand Down
13 changes: 5 additions & 8 deletions fuzz/fuzz_targets/smart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use solana_rbpf::{
elf::Executable,
insn_builder::{Arch, IntoBytes},
memory_region::MemoryRegion,
verifier::{RequisiteVerifier, Verifier},
vm::{BuiltInProgram, FunctionRegistry, TestContextObject, VerifiedExecutable},
verifier::{RequisiteVerifier, TautologyVerifier, Verifier},
vm::{BuiltInProgram, FunctionRegistry, TestContextObject},
};
use test_utils::{create_vm, TautologyVerifier};
use test_utils::create_vm;

use crate::common::ConfigTemplate;

Expand All @@ -37,20 +37,17 @@ fuzz_target!(|data: FuzzData| {
return;
}
let mut mem = data.mem;
let executable = Executable::<TestContextObject>::from_text_bytes(
let executable = Executable::<TautologyVerifier, TestContextObject>::from_text_bytes(
prog.into_bytes(),
std::sync::Arc::new(BuiltInProgram::new_loader(config)),
function_registry,
)
.unwrap();
let verified_executable =
VerifiedExecutable::<TautologyVerifier, TestContextObject>::from_executable(executable)
.unwrap();
let mem_region = MemoryRegion::new_writable(&mut mem, ebpf::MM_INPUT_START);
let mut context_object = TestContextObject::new(1 << 16);
create_vm!(
interp_vm,
&verified_executable,
&executable,
&mut context_object,
stack,
heap,
Expand Down
17 changes: 7 additions & 10 deletions fuzz/fuzz_targets/smart_jit_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use solana_rbpf::{
elf::Executable,
insn_builder::{Arch, Instruction, IntoBytes},
memory_region::MemoryRegion,
verifier::{RequisiteVerifier, Verifier},
vm::{BuiltInProgram, FunctionRegistry, TestContextObject, VerifiedExecutable},
verifier::{RequisiteVerifier, TautologyVerifier, Verifier},
vm::{BuiltInProgram, FunctionRegistry, TestContextObject},
};
use test_utils::{create_vm, TautologyVerifier};
use test_utils::create_vm;

use crate::common::ConfigTemplate;

Expand Down Expand Up @@ -45,21 +45,18 @@ fuzz_target!(|data: FuzzData| {
}
let mut interp_mem = data.mem.clone();
let mut jit_mem = data.mem;
let executable = Executable::<TestContextObject>::from_text_bytes(
let mut executable = Executable::<TautologyVerifier, TestContextObject>::from_text_bytes(
prog.into_bytes(),
std::sync::Arc::new(BuiltInProgram::new_loader(config)),
function_registry,
)
.unwrap();
let mut verified_executable =
VerifiedExecutable::<TautologyVerifier, TestContextObject>::from_executable(executable)
.unwrap();
if verified_executable.jit_compile().is_ok() {
if executable.jit_compile().is_ok() {
let mut interp_context_object = TestContextObject::new(1 << 16);
let interp_mem_region = MemoryRegion::new_writable(&mut interp_mem, ebpf::MM_INPUT_START);
create_vm!(
interp_vm,
&verified_executable,
&executable,
&mut interp_context_object,
interp_stack,
interp_heap,
Expand All @@ -71,7 +68,7 @@ fuzz_target!(|data: FuzzData| {
let jit_mem_region = MemoryRegion::new_writable(&mut jit_mem, ebpf::MM_INPUT_START);
create_vm!(
jit_vm,
&verified_executable,
&executable,
&mut jit_context_object,
jit_stack,
jit_heap,
Expand Down
Loading

0 comments on commit f337a6a

Please sign in to comment.