Skip to content

Commit

Permalink
Update to latest rbpf
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ece committed Dec 10, 2024
1 parent 5397067 commit f6eb644
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 140 deletions.
186 changes: 93 additions & 93 deletions Cargo.lock

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ lazy_static = "1.4.0"
prost = "0.13.1"
prost-types = "0.13.1"
libc = "0.2.155"
solana-address-lookup-table-program = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-accounts-db = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-bpf-loader-program = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-compute-budget = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-compute-budget-program = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-config-program = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-ledger = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-loader-v4-program = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-log-collector = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-program = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-program-runtime = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-runtime = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab", features = ["dev-context-only-utils"] }
solana-stake-program = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-system-program = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-svm = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-svm-transaction = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-sdk = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-timings = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-vote-program = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-zk-sdk = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-zk-elgamal-proof-program = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-poseidon = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-runtime-transaction = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-address-lookup-table-program = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-accounts-db = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-bpf-loader-program = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-compute-budget = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-compute-budget-program = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-config-program = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-ledger = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-loader-v4-program = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-log-collector = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-program = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-program-runtime = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-runtime = { git = "https://github.com/firedancer-io/agave", rev = "133d691", features = ["dev-context-only-utils"] }
solana-stake-program = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-system-program = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-svm = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-svm-transaction = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-sdk = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-timings = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-vote-program = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-zk-sdk = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-zk-elgamal-proof-program = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-poseidon = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-runtime-transaction = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solfuzz-agave-macro = { path = "macro" }
thiserror = "1.0.65"

Expand All @@ -48,8 +48,8 @@ prost-build = "0.13.1"


[patch.crates-io]
solana-program = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-zk-token-sdk = { git = "https://github.com/firedancer-io/agave", rev = "f5cde2a07d8276b0839051a9cb243234e43beaab" }
solana-program = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }
solana-zk-token-sdk = { git = "https://github.com/firedancer-io/agave", rev = "133d691" }

[features]
# This feature is used to compile a target with a builtin replaced by a BPF program.
Expand Down
2 changes: 1 addition & 1 deletion src/elf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn load_elf(elf_bytes: &[u8], deploy_checks: bool) -> Option<ElfLoaderEffect
elf_effects.rodata = ro_section.to_vec();
elf_effects.rodata_sz = ro_section.len() as u64;
elf_effects.entry_pc = elf_exec.get_entrypoint_instruction_offset() as u64;
elf_effects.text_off = text_vaddr - ebpf::MM_PROGRAM_START;
elf_effects.text_off = text_vaddr - ebpf::MM_RODATA_START;
elf_effects.text_cnt = (raw_text_sz / 8) as u64;
elf_effects.calldests = calldests.into_iter().collect();
Some(elf_effects)
Expand Down
10 changes: 6 additions & 4 deletions src/vm_cpi_syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub fn execute_vm_cpi_syscall(input: SyscallContext) -> Option<SyscallEffects> {
let mut heap = AlignedMemory::<HOST_ALIGN>::from(&vec![0; vm_ctx.heap_max as usize]);

let mut regions = vec![
MemoryRegion::new_readonly(rodata.as_slice(), ebpf::MM_PROGRAM_START),
MemoryRegion::new_readonly(rodata.as_slice(), ebpf::MM_RODATA_START),
MemoryRegion::new_writable_gapped(
stack.as_slice_mut(),
ebpf::MM_STACK_START,
Expand All @@ -248,7 +248,9 @@ pub fn execute_vm_cpi_syscall(input: SyscallContext) -> Option<SyscallEffects> {
&vm_ctx.input_data_regions,
);

let memory_mapping = match MemoryMapping::new(regions, config, &SBPFVersion::V1) {
let sbpf_version = SBPFVersion::V0;

let memory_mapping = match MemoryMapping::new(regions, config, sbpf_version) {
Ok(mapping) => mapping,
Err(_) => return None,
};
Expand All @@ -257,7 +259,7 @@ pub fn execute_vm_cpi_syscall(input: SyscallContext) -> Option<SyscallEffects> {
let loader = std::sync::Arc::new(BuiltinProgram::new_mock());
let mut vm = EbpfVm::new(
loader,
&SBPFVersion::V1,
sbpf_version,
&mut invoke_context,
memory_mapping,
STACK_SIZE,
Expand All @@ -280,7 +282,7 @@ pub fn execute_vm_cpi_syscall(input: SyscallContext) -> Option<SyscallEffects> {

// Invoke the syscall
let (_, syscall_func) = program_runtime_environment_v1
.get_function_registry()
.get_function_registry(sbpf_version)
.lookup_by_name(syscall_fn_name.as_slice())?;
vm.invoke_function(syscall_func);

Expand Down
34 changes: 22 additions & 12 deletions src/vm_interp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,16 @@ pub fn execute_vm_interp(syscall_context: SyscallContext) -> Option<SyscallEffec
)
.unwrap();

let vm_ctx = syscall_context.vm_ctx.unwrap();
let sbpf_version = match vm_ctx.sbpf_version {
1 => SBPFVersion::V1,
2 => SBPFVersion::V2,
3 => SBPFVersion::V3,
_ => SBPFVersion::V0,
};

// stub syscalls
let syscall_reg = unstubbed_runtime.get_function_registry();
let syscall_reg = unstubbed_runtime.get_function_registry(sbpf_version);
let mut stubbed_syscall_reg = FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();

for (key, (name, _)) in syscall_reg.iter() {
Expand All @@ -119,11 +127,9 @@ pub fn execute_vm_interp(syscall_context: SyscallContext) -> Option<SyscallEffec
.unwrap();
}

//TODO: support SBPF version
let sbpf_version = SBPFVersion::V1;
let config = &Config {
aligned_memory_mapping: true,
enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1,
enabled_sbpf_versions: SBPFVersion::V0..=sbpf_version,
enable_stack_frame_gaps: !feature_set.is_active(&bpf_account_data_direct_mapping::id()),
enable_instruction_tracing: true,
..Config::default()
Expand All @@ -137,7 +143,6 @@ pub fn execute_vm_interp(syscall_context: SyscallContext) -> Option<SyscallEffec
let mut context_obj = TestContextObject::new(instr_ctx.cu_avail);

// setup memory
let vm_ctx = syscall_context.vm_ctx.unwrap();
if vm_ctx.heap_max as usize > HEAP_MAX {
return None;
}
Expand All @@ -152,7 +157,7 @@ pub fn execute_vm_interp(syscall_context: SyscallContext) -> Option<SyscallEffec
let mut heap = AlignedMemory::<HOST_ALIGN>::from(&vec![0; vm_ctx.heap_max as usize]);

let mut regions = vec![
MemoryRegion::new_readonly(rodata.as_slice(), ebpf::MM_PROGRAM_START),
MemoryRegion::new_readonly(rodata.as_slice(), ebpf::MM_RODATA_START),
MemoryRegion::new_writable_gapped(
stack.as_slice_mut(),
ebpf::MM_STACK_START,
Expand All @@ -172,22 +177,27 @@ pub fn execute_vm_interp(syscall_context: SyscallContext) -> Option<SyscallEffec
&vm_ctx.input_data_regions,
);

let memory_mapping = match MemoryMapping::new(regions, config, &sbpf_version) {
let memory_mapping = match MemoryMapping::new(regions, config, sbpf_version) {
Ok(mapping) => mapping,
Err(_) => return None,
};

let mut vm = EbpfVm::new(
loader.clone(),
&sbpf_version,
sbpf_version,
&mut context_obj,
memory_mapping,
STACK_SIZE,
);

// setup registers
// Setup registers.
// r1, r10, r11 are initialized by EbpfVm::new (r10) or EbpfVm::execute_program (r1, r11)
// Modifying them will most like break execution.
// In syscalls we allow override them (especially r1) because that simulates the fact
// that a program partially executed before reaching the syscall.
// Here we want to test what happens when the program starts from the beginning.
vm.registers[0] = vm_ctx.r0;
vm.registers[1] = vm_ctx.r1; // set in vm.execute_program
// vm.registers[1] = vm_ctx.r1; // do not override
vm.registers[2] = vm_ctx.r2;
vm.registers[3] = vm_ctx.r3;
vm.registers[4] = vm_ctx.r4;
Expand All @@ -196,8 +206,8 @@ pub fn execute_vm_interp(syscall_context: SyscallContext) -> Option<SyscallEffec
vm.registers[7] = vm_ctx.r7;
vm.registers[8] = vm_ctx.r8;
vm.registers[9] = vm_ctx.r9;
vm.registers[10] = vm_ctx.r10; // set in vm.execute_program
vm.registers[11] = vm_ctx.r11; // set in vm.execute_program
// vm.registers[10] = vm_ctx.r10; // do not override
// vm.registers[11] = vm_ctx.r11; // do not override

mem_regions::copy_memory_prefix(heap.as_slice_mut(), &syscall_inv.heap_prefix);
mem_regions::copy_memory_prefix(stack.as_slice_mut(), &syscall_inv.stack_prefix);
Expand Down
8 changes: 4 additions & 4 deletions src/vm_syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub fn execute_vm_syscall(input: SyscallContext) -> Option<SyscallEffects> {
})
.unwrap();
// TODO: support different versions
let sbpf_version = &SBPFVersion::V1;
let sbpf_version = SBPFVersion::V0;

// Set up memory mapping
let vm_ctx = input.vm_ctx.unwrap();
Expand Down Expand Up @@ -249,7 +249,7 @@ pub fn execute_vm_syscall(input: SyscallContext) -> Option<SyscallEffects> {
// let mut heap = mempool.get_heap(heap_max); // this would force MIN_HEAP_FRAME_BYTES
let mut heap = AlignedMemory::<HOST_ALIGN>::from(&vec![0; vm_ctx.heap_max as usize]);
let mut regions = vec![
MemoryRegion::new_readonly(rodata.as_slice(), ebpf::MM_PROGRAM_START),
MemoryRegion::new_readonly(rodata.as_slice(), ebpf::MM_RODATA_START),
MemoryRegion::new_writable_gapped(
stack.as_slice_mut(),
ebpf::MM_STACK_START,
Expand Down Expand Up @@ -277,7 +277,7 @@ pub fn execute_vm_syscall(input: SyscallContext) -> Option<SyscallEffects> {
let loader = std::sync::Arc::new(BuiltinProgram::new_mock());
let mut vm = EbpfVm::new(
loader,
&SBPFVersion::V1,
sbpf_version,
&mut invoke_context,
memory_mapping,
STACK_SIZE,
Expand All @@ -304,7 +304,7 @@ pub fn execute_vm_syscall(input: SyscallContext) -> Option<SyscallEffects> {

// Invoke the syscall
let (_, syscall_func) = program_runtime_environment_v1
.get_function_registry()
.get_function_registry(sbpf_version)
.lookup_by_name(&input.syscall_invocation?.function_name)?;
vm.invoke_function(syscall_func);

Expand Down
2 changes: 1 addition & 1 deletion src/vm_validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn validate_vm_text(text_bytes: &[u8], feature_set: &FeatureSet) -> Option<V
let exec = match Executable::new_from_text_bytes(
text_bytes,
std::sync::Arc::new(program_runtime_environment_v1),
solana_program_runtime::solana_rbpf::program::SBPFVersion::V1,
solana_program_runtime::solana_rbpf::program::SBPFVersion::V0,
FunctionRegistry::default(),
) {
Ok(v) => v,
Expand Down

0 comments on commit f6eb644

Please sign in to comment.