Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Removes the generic parameter "V: Verifier" from Executable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Aug 21, 2023
1 parent 91f8af8 commit 8020fe2
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 160 deletions.
9 changes: 2 additions & 7 deletions benches/elf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ extern crate test_utils;
use solana_rbpf::{
elf::{Executable, FunctionRegistry},
syscalls,
verifier::TautologyVerifier,
vm::{BuiltinFunction, BuiltinProgram, Config, TestContextObject},
};
use std::{fs::File, io::Read, sync::Arc};
Expand All @@ -36,9 +35,7 @@ fn bench_load_sbpfv1(bencher: &mut Bencher) {
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let loader = loader();
bencher.iter(|| {
Executable::<TautologyVerifier, TestContextObject>::from_elf(&elf, loader.clone()).unwrap()
});
bencher.iter(|| Executable::<TestContextObject>::from_elf(&elf, loader.clone()).unwrap());
}

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

use solana_rbpf::{
elf::Executable,
verifier::{RequisiteVerifier, TautologyVerifier},
verifier::RequisiteVerifier,
vm::{BuiltinProgram, TestContextObject},
};
use std::{fs::File, io::Read, sync::Arc};
Expand All @@ -23,13 +23,11 @@ fn bench_init_vm(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/relative_call.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let executable = Executable::<TautologyVerifier, TestContextObject>::from_elf(
&elf,
Arc::new(BuiltinProgram::new_mock()),
)
.unwrap();
let executable =
Executable::<TestContextObject>::from_elf(&elf, Arc::new(BuiltinProgram::new_mock()))
.unwrap();
let verified_executable =
Executable::<RequisiteVerifier, TestContextObject>::verified(executable).unwrap();
Executable::<TestContextObject>::verified::<RequisiteVerifier>(executable).unwrap();
bencher.iter(|| {
let mut context_object = TestContextObject::default();
create_vm!(
Expand All @@ -50,12 +48,10 @@ fn bench_jit_compile(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/relative_call.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let executable = Executable::<TautologyVerifier, TestContextObject>::from_elf(
&elf,
Arc::new(BuiltinProgram::new_mock()),
)
.unwrap();
let executable =
Executable::<TestContextObject>::from_elf(&elf, Arc::new(BuiltinProgram::new_mock()))
.unwrap();
let mut verified_executable =
Executable::<RequisiteVerifier, TestContextObject>::verified(executable).unwrap();
Executable::<TestContextObject>::verified::<RequisiteVerifier>(executable).unwrap();
bencher.iter(|| verified_executable.jit_compile().unwrap());
}
24 changes: 10 additions & 14 deletions benches/vm_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use solana_rbpf::{
ebpf,
elf::{Executable, FunctionRegistry},
memory_region::MemoryRegion,
verifier::{RequisiteVerifier, TautologyVerifier},
verifier::RequisiteVerifier,
vm::{BuiltinProgram, Config, TestContextObject},
};
use std::{fs::File, io::Read, sync::Arc};
Expand All @@ -25,13 +25,11 @@ fn bench_init_interpreter_start(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/rodata_section.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let executable = Executable::<TautologyVerifier, TestContextObject>::from_elf(
&elf,
Arc::new(BuiltinProgram::new_mock()),
)
.unwrap();
let executable =
Executable::<TestContextObject>::from_elf(&elf, Arc::new(BuiltinProgram::new_mock()))
.unwrap();
let verified_executable =
Executable::<RequisiteVerifier, TestContextObject>::verified(executable).unwrap();
Executable::<TestContextObject>::verified::<RequisiteVerifier>(executable).unwrap();
let mut context_object = TestContextObject::default();
create_vm!(
vm,
Expand All @@ -54,13 +52,11 @@ fn bench_init_jit_start(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/rodata_section.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let executable = Executable::<TautologyVerifier, TestContextObject>::from_elf(
&elf,
Arc::new(BuiltinProgram::new_mock()),
)
.unwrap();
let executable =
Executable::<TestContextObject>::from_elf(&elf, Arc::new(BuiltinProgram::new_mock()))
.unwrap();
let mut verified_executable =
Executable::<RequisiteVerifier, TestContextObject>::verified(executable).unwrap();
Executable::<TestContextObject>::verified::<RequisiteVerifier>(executable).unwrap();
verified_executable.jit_compile().unwrap();
let mut context_object = TestContextObject::default();
create_vm!(
Expand Down Expand Up @@ -95,7 +91,7 @@ fn bench_jit_vs_interpreter(
)
.unwrap();
let mut verified_executable =
Executable::<RequisiteVerifier, TestContextObject>::verified(executable).unwrap();
Executable::<TestContextObject>::verified::<RequisiteVerifier>(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
6 changes: 3 additions & 3 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use solana_rbpf::{
elf::{Executable, FunctionRegistry},
memory_region::{MemoryMapping, MemoryRegion},
static_analysis::Analysis,
verifier::{RequisiteVerifier, TautologyVerifier},
verifier::{RequisiteVerifier},
vm::{BuiltinProgram, Config, DynamicAnalysis, EbpfVm, TestContextObject},
};
use std::{fs::File, io::Read, path::Path, sync::Arc};
Expand Down Expand Up @@ -112,15 +112,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::<TautologyVerifier, TestContextObject>::from_elf(&elf, loader)
Executable::<TestContextObject>::from_elf(&elf, loader)
.map_err(|err| format!("Executable constructor failed: {err:?}"))
}
}
.unwrap();

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

let mut mem = match matches.value_of("input").unwrap().parse::<usize>() {
Ok(allocate) => vec![0u8; allocate],
Expand Down
3 changes: 1 addition & 2 deletions examples/disassemble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ extern crate solana_rbpf;
use solana_rbpf::{
elf::{Executable, FunctionRegistry, SBPFVersion},
static_analysis::Analysis,
verifier::TautologyVerifier,
vm::{BuiltinProgram, TestContextObject},
};
use std::sync::Arc;
Expand All @@ -32,7 +31,7 @@ fn main() {
0x00, 0x00, 0x00, 0x00, 0x00,
];
let loader = Arc::new(BuiltinProgram::new_mock());
let executable = Executable::<TautologyVerifier, TestContextObject>::from_text_bytes(
let executable = Executable::<TestContextObject>::from_text_bytes(
program,
loader,
SBPFVersion::V2,
Expand Down
3 changes: 1 addition & 2 deletions examples/to_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extern crate solana_rbpf;
use solana_rbpf::{
elf::{Executable, FunctionRegistry, SBPFVersion},
static_analysis::Analysis,
verifier::TautologyVerifier,
vm::{BuiltinProgram, TestContextObject},
};
use std::sync::Arc;
Expand All @@ -28,7 +27,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::<TautologyVerifier, TestContextObject>::from_text_bytes(
let executable = Executable::<TestContextObject>::from_text_bytes(
program,
Arc::new(BuiltinProgram::new_mock()),
SBPFVersion::V2,
Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/dumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use solana_rbpf::{
ebpf,
elf::{Executable, FunctionRegistry, SBPFVersion},
memory_region::MemoryRegion,
verifier::{RequisiteVerifier, TautologyVerifier, Verifier},
verifier::{RequisiteVerifier, Verifier},
vm::{BuiltinProgram, TestContextObject},
};
use test_utils::create_vm;
Expand All @@ -33,7 +33,7 @@ fuzz_target!(|data: DumbFuzzData| {
return;
}
let mut mem = data.mem;
let executable = Executable::<TautologyVerifier, TestContextObject>::from_text_bytes(
let executable = Executable::<TestContextObject>::from_text_bytes(
&prog,
std::sync::Arc::new(BuiltinProgram::new_loader(config, FunctionRegistry::default())),
SBPFVersion::V2,
Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/smart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use solana_rbpf::{
elf::{Executable, FunctionRegistry, SBPFVersion},
insn_builder::{Arch, IntoBytes},
memory_region::MemoryRegion,
verifier::{RequisiteVerifier, TautologyVerifier, Verifier},
verifier::{RequisiteVerifier, Verifier},
vm::{BuiltinProgram, TestContextObject},
};
use test_utils::create_vm;
Expand All @@ -37,7 +37,7 @@ fuzz_target!(|data: FuzzData| {
return;
}
let mut mem = data.mem;
let executable = Executable::<TautologyVerifier, TestContextObject>::from_text_bytes(
let executable = Executable::<TestContextObject>::from_text_bytes(
prog.into_bytes(),
std::sync::Arc::new(BuiltinProgram::new_loader(config, FunctionRegistry::default())),
SBPFVersion::V2,
Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/smart_jit_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use solana_rbpf::{
elf::{Executable, FunctionRegistry, SBPFVersion},
insn_builder::{Arch, Instruction, IntoBytes},
memory_region::MemoryRegion,
verifier::{RequisiteVerifier, TautologyVerifier, Verifier},
verifier::{RequisiteVerifier, Verifier},
vm::{BuiltinProgram, TestContextObject},
};
use test_utils::create_vm;
Expand Down Expand Up @@ -45,7 +45,7 @@ fuzz_target!(|data: FuzzData| {
}
let mut interp_mem = data.mem.clone();
let mut jit_mem = data.mem;
let mut executable = Executable::<TautologyVerifier, TestContextObject>::from_text_bytes(
let mut executable = Executable::<TestContextObject>::from_text_bytes(
prog.into_bytes(),
std::sync::Arc::new(BuiltinProgram::new_loader(config, FunctionRegistry::default())),
SBPFVersion::V2,
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/smarter_jit_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use solana_rbpf::{
insn_builder::IntoBytes,
memory_region::MemoryRegion,
static_analysis::Analysis,
verifier::{RequisiteVerifier, TautologyVerifier, Verifier},
verifier::{RequisiteVerifier, Verifier},
vm::{
BuiltinProgram, ContextObject, TestContextObject,
},
Expand All @@ -28,7 +28,7 @@ struct FuzzData {
mem: Vec<u8>,
}

fn dump_insns<V: Verifier, C: ContextObject>(verified_executable: &Executable<V, C>) {
fn dump_insns<C: ContextObject>(verified_executable: &Executable<C>) {
let analysis = Analysis::from_executable(verified_executable).unwrap();
eprint!("Using the following disassembly");
analysis.disassemble(&mut std::io::stderr().lock()).unwrap();
Expand All @@ -44,7 +44,7 @@ fuzz_target!(|data: FuzzData| {
}
let mut interp_mem = data.mem.clone();
let mut jit_mem = data.mem;
let mut executable = Executable::<TautologyVerifier, TestContextObject>::from_text_bytes(
let mut executable = Executable::<TestContextObject>::from_text_bytes(
prog.into_bytes(),
std::sync::Arc::new(BuiltinProgram::new_loader(config, FunctionRegistry::default())),
SBPFVersion::V2,
Expand Down
12 changes: 3 additions & 9 deletions src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::{
},
ebpf::{self, Insn},
elf::{Executable, FunctionRegistry, SBPFVersion},
verifier::TautologyVerifier,
vm::{BuiltinProgram, ContextObject},
};
use std::{collections::HashMap, sync::Arc};
Expand Down Expand Up @@ -218,7 +217,7 @@ fn insn(opc: u8, dst: i64, src: i64, off: i64, imm: i64) -> Result<Insn, String>
pub fn assemble<C: ContextObject>(
src: &str,
loader: Arc<BuiltinProgram<C>>,
) -> Result<Executable<TautologyVerifier, C>, String> {
) -> Result<Executable<C>, String> {
let sbpf_version = if loader.get_config().enable_sbpf_v2 {
SBPFVersion::V2
} else {
Expand Down Expand Up @@ -366,11 +365,6 @@ pub fn assemble<C: ContextObject>(
.iter()
.flat_map(|insn| insn.to_vec())
.collect::<Vec<_>>();
Executable::<TautologyVerifier, C>::from_text_bytes(
&program,
loader,
sbpf_version,
function_registry,
)
.map_err(|err| format!("Executable constructor {err:?}"))
Executable::<C>::from_text_bytes(&program, loader, sbpf_version, function_registry)
.map_err(|err| format!("Executable constructor {err:?}"))
}
Loading

0 comments on commit 8020fe2

Please sign in to comment.